diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index c1880d58ad..196dd10833 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -3100,6 +3100,8 @@ pub struct PaymentLinkObject { #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub link_expiry: Option, pub merchant_custom_domain_name: Option, + /// Custom merchant name for payment link + pub custom_merchant_name: Option, } #[derive(Default, Debug, serde::Deserialize, Clone, ToSchema, serde::Serialize)] @@ -3143,11 +3145,11 @@ pub struct PaymentLinkDetails { pub pub_key: String, pub client_secret: String, pub payment_id: String, - #[serde(with = "common_utils::custom_serde::iso8601")] - pub expiry: PrimitiveDateTime, + #[serde(with = "common_utils::custom_serde::iso8601::option")] + pub expiry: Option, pub merchant_logo: String, pub return_url: String, - pub merchant_name: crypto::OptionalEncryptableName, + pub merchant_name: String, pub order_details: Vec, pub max_items_visible_after_collapse: i8, } diff --git a/crates/diesel_models/src/payment_link.rs b/crates/diesel_models/src/payment_link.rs index 4b182a8155..50cc5e89ce 100644 --- a/crates/diesel_models/src/payment_link.rs +++ b/crates/diesel_models/src/payment_link.rs @@ -20,8 +20,8 @@ pub struct PaymentLink { pub last_modified_at: PrimitiveDateTime, #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub fulfilment_time: Option, + pub custom_merchant_name: Option, } - #[derive( Clone, Debug, @@ -47,4 +47,5 @@ pub struct PaymentLinkNew { pub last_modified_at: Option, #[serde(default, with = "common_utils::custom_serde::iso8601::option")] pub fulfilment_time: Option, + pub custom_merchant_name: Option, } diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index 50531e432a..9933bf90a5 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -691,6 +691,8 @@ diesel::table! { created_at -> Timestamp, last_modified_at -> Timestamp, fulfilment_time -> Nullable, + #[max_length = 64] + custom_merchant_name -> Nullable, } } diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rs index 2c51fa0c3c..0012efc86c 100644 --- a/crates/router/src/core/payment_link.rs +++ b/crates/router/src/core/payment_link.rs @@ -1,6 +1,6 @@ use api_models::admin as admin_types; -use common_utils::ext_traits::AsyncExt; use error_stack::{IntoReport, ResultExt}; +use masking::PeekInterface; use super::errors::{self, RouterResult, StorageErrorExt}; use crate::{ @@ -43,6 +43,11 @@ pub async fn intiate_payment_link_flow( .await .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; + let payment_link_id = payment_intent + .payment_link_id + .get_required_value("payment_link_id") + .change_context(errors::ApiErrorResponse::PaymentLinkNotFound)?; + helpers::validate_payment_status_against_not_allowed_statuses( &payment_intent.status, &[ @@ -55,20 +60,10 @@ pub async fn intiate_payment_link_flow( "create payment link", )?; - let fulfillment_time = payment_intent - .payment_link_id - .as_ref() - .async_and_then(|pli| async move { - db.find_payment_link_by_payment_link_id(pli) - .await - .ok()? - .fulfilment_time - .ok_or(errors::ApiErrorResponse::PaymentNotFound) - .ok() - }) + let payment_link = db + .find_payment_link_by_payment_link_id(&payment_link_id) .await - .get_required_value("fulfillment_time") - .change_context(errors::ApiErrorResponse::PaymentNotFound)?; + .to_not_found_response(errors::ApiErrorResponse::PaymentLinkNotFound)?; let payment_link_config = merchant_account .payment_link_config @@ -108,10 +103,15 @@ pub async fn intiate_payment_link_flow( amount: payment_intent.amount, currency, payment_id: payment_intent.payment_id, - merchant_name: merchant_account.merchant_name, + merchant_name: payment_link.custom_merchant_name.unwrap_or( + merchant_account + .merchant_name + .map(|merchant_name| merchant_name.into_inner().peek().to_owned()) + .unwrap_or_default(), + ), order_details, return_url, - expiry: fulfillment_time, + expiry: payment_link.fulfilment_time, pub_key, client_secret, merchant_logo: payment_link_config diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 909f4d4565..adb3c41553 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -813,6 +813,7 @@ async fn create_payment_link( created_at, last_modified_at, fulfilment_time: payment_link_object.link_expiry, + custom_merchant_name: payment_link_object.custom_merchant_name, }; let payment_link_db = db .insert_payment_link(payment_link_req) diff --git a/migrations/2023-10-25-070909_add_merchant_custom_name_payment_link/down.sql b/migrations/2023-10-25-070909_add_merchant_custom_name_payment_link/down.sql new file mode 100644 index 0000000000..84f009021d --- /dev/null +++ b/migrations/2023-10-25-070909_add_merchant_custom_name_payment_link/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE payment_link DROP COLUMN custom_merchant_name; diff --git a/migrations/2023-10-25-070909_add_merchant_custom_name_payment_link/up.sql b/migrations/2023-10-25-070909_add_merchant_custom_name_payment_link/up.sql new file mode 100644 index 0000000000..c4fa756e57 --- /dev/null +++ b/migrations/2023-10-25-070909_add_merchant_custom_name_payment_link/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE payment_link ADD COLUMN custom_merchant_name VARCHAR(64); \ No newline at end of file diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index 5af67e4992..6e61f2eb61 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -7866,6 +7866,11 @@ "merchant_custom_domain_name": { "type": "string", "nullable": true + }, + "custom_merchant_name": { + "type": "string", + "description": "Custom merchant name for payment link", + "nullable": true } } },