Skip to content

Commit 8b15189

Browse files
feat(router): added merchant custom name support for payment link (#2685)
Co-authored-by: Sahkal Poddar <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent aab8f60 commit 8b15189

File tree

8 files changed

+35
-20
lines changed

8 files changed

+35
-20
lines changed

crates/api_models/src/payments.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,6 +3100,8 @@ pub struct PaymentLinkObject {
31003100
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
31013101
pub link_expiry: Option<PrimitiveDateTime>,
31023102
pub merchant_custom_domain_name: Option<String>,
3103+
/// Custom merchant name for payment link
3104+
pub custom_merchant_name: Option<String>,
31033105
}
31043106

31053107
#[derive(Default, Debug, serde::Deserialize, Clone, ToSchema, serde::Serialize)]
@@ -3143,11 +3145,11 @@ pub struct PaymentLinkDetails {
31433145
pub pub_key: String,
31443146
pub client_secret: String,
31453147
pub payment_id: String,
3146-
#[serde(with = "common_utils::custom_serde::iso8601")]
3147-
pub expiry: PrimitiveDateTime,
3148+
#[serde(with = "common_utils::custom_serde::iso8601::option")]
3149+
pub expiry: Option<PrimitiveDateTime>,
31483150
pub merchant_logo: String,
31493151
pub return_url: String,
3150-
pub merchant_name: crypto::OptionalEncryptableName,
3152+
pub merchant_name: String,
31513153
pub order_details: Vec<pii::SecretSerdeValue>,
31523154
pub max_items_visible_after_collapse: i8,
31533155
}

crates/diesel_models/src/payment_link.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub struct PaymentLink {
2020
pub last_modified_at: PrimitiveDateTime,
2121
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
2222
pub fulfilment_time: Option<PrimitiveDateTime>,
23+
pub custom_merchant_name: Option<String>,
2324
}
24-
2525
#[derive(
2626
Clone,
2727
Debug,
@@ -47,4 +47,5 @@ pub struct PaymentLinkNew {
4747
pub last_modified_at: Option<PrimitiveDateTime>,
4848
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
4949
pub fulfilment_time: Option<PrimitiveDateTime>,
50+
pub custom_merchant_name: Option<String>,
5051
}

crates/diesel_models/src/schema.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@ diesel::table! {
691691
created_at -> Timestamp,
692692
last_modified_at -> Timestamp,
693693
fulfilment_time -> Nullable<Timestamp>,
694+
#[max_length = 64]
695+
custom_merchant_name -> Nullable<Varchar>,
694696
}
695697
}
696698

crates/router/src/core/payment_link.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use api_models::admin as admin_types;
2-
use common_utils::ext_traits::AsyncExt;
32
use error_stack::{IntoReport, ResultExt};
3+
use masking::PeekInterface;
44

55
use super::errors::{self, RouterResult, StorageErrorExt};
66
use crate::{
@@ -43,6 +43,11 @@ pub async fn intiate_payment_link_flow(
4343
.await
4444
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;
4545

46+
let payment_link_id = payment_intent
47+
.payment_link_id
48+
.get_required_value("payment_link_id")
49+
.change_context(errors::ApiErrorResponse::PaymentLinkNotFound)?;
50+
4651
helpers::validate_payment_status_against_not_allowed_statuses(
4752
&payment_intent.status,
4853
&[
@@ -55,20 +60,10 @@ pub async fn intiate_payment_link_flow(
5560
"create payment link",
5661
)?;
5762

58-
let fulfillment_time = payment_intent
59-
.payment_link_id
60-
.as_ref()
61-
.async_and_then(|pli| async move {
62-
db.find_payment_link_by_payment_link_id(pli)
63-
.await
64-
.ok()?
65-
.fulfilment_time
66-
.ok_or(errors::ApiErrorResponse::PaymentNotFound)
67-
.ok()
68-
})
63+
let payment_link = db
64+
.find_payment_link_by_payment_link_id(&payment_link_id)
6965
.await
70-
.get_required_value("fulfillment_time")
71-
.change_context(errors::ApiErrorResponse::PaymentNotFound)?;
66+
.to_not_found_response(errors::ApiErrorResponse::PaymentLinkNotFound)?;
7267

7368
let payment_link_config = merchant_account
7469
.payment_link_config
@@ -108,10 +103,15 @@ pub async fn intiate_payment_link_flow(
108103
amount: payment_intent.amount,
109104
currency,
110105
payment_id: payment_intent.payment_id,
111-
merchant_name: merchant_account.merchant_name,
106+
merchant_name: payment_link.custom_merchant_name.unwrap_or(
107+
merchant_account
108+
.merchant_name
109+
.map(|merchant_name| merchant_name.into_inner().peek().to_owned())
110+
.unwrap_or_default(),
111+
),
112112
order_details,
113113
return_url,
114-
expiry: fulfillment_time,
114+
expiry: payment_link.fulfilment_time,
115115
pub_key,
116116
client_secret,
117117
merchant_logo: payment_link_config

crates/router/src/core/payments/operations/payment_create.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ async fn create_payment_link(
813813
created_at,
814814
last_modified_at,
815815
fulfilment_time: payment_link_object.link_expiry,
816+
custom_merchant_name: payment_link_object.custom_merchant_name,
816817
};
817818
let payment_link_db = db
818819
.insert_payment_link(payment_link_req)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- This file should undo anything in `up.sql`
2+
ALTER TABLE payment_link DROP COLUMN custom_merchant_name;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Your SQL goes here
2+
ALTER TABLE payment_link ADD COLUMN custom_merchant_name VARCHAR(64);

openapi/openapi_spec.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7866,6 +7866,11 @@
78667866
"merchant_custom_domain_name": {
78677867
"type": "string",
78687868
"nullable": true
7869+
},
7870+
"custom_merchant_name": {
7871+
"type": "string",
7872+
"description": "Custom merchant name for payment link",
7873+
"nullable": true
78697874
}
78707875
}
78717876
},

0 commit comments

Comments
 (0)