feat(router): added merchant custom name support for payment link (#2685)

Co-authored-by: Sahkal Poddar <sahkal.poddar@juspay.in>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Sahkal Poddar
2023-11-09 16:28:52 +05:30
committed by GitHub
parent aab8f6035c
commit 8b151898dc
8 changed files with 35 additions and 20 deletions

View File

@ -3100,6 +3100,8 @@ pub struct PaymentLinkObject {
#[serde(default, with = "common_utils::custom_serde::iso8601::option")] #[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub link_expiry: Option<PrimitiveDateTime>, pub link_expiry: Option<PrimitiveDateTime>,
pub merchant_custom_domain_name: Option<String>, pub merchant_custom_domain_name: Option<String>,
/// Custom merchant name for payment link
pub custom_merchant_name: Option<String>,
} }
#[derive(Default, Debug, serde::Deserialize, Clone, ToSchema, serde::Serialize)] #[derive(Default, Debug, serde::Deserialize, Clone, ToSchema, serde::Serialize)]
@ -3143,11 +3145,11 @@ pub struct PaymentLinkDetails {
pub pub_key: String, pub pub_key: String,
pub client_secret: String, pub client_secret: String,
pub payment_id: String, pub payment_id: String,
#[serde(with = "common_utils::custom_serde::iso8601")] #[serde(with = "common_utils::custom_serde::iso8601::option")]
pub expiry: PrimitiveDateTime, pub expiry: Option<PrimitiveDateTime>,
pub merchant_logo: String, pub merchant_logo: String,
pub return_url: String, pub return_url: String,
pub merchant_name: crypto::OptionalEncryptableName, pub merchant_name: String,
pub order_details: Vec<pii::SecretSerdeValue>, pub order_details: Vec<pii::SecretSerdeValue>,
pub max_items_visible_after_collapse: i8, pub max_items_visible_after_collapse: i8,
} }

View File

@ -20,8 +20,8 @@ pub struct PaymentLink {
pub last_modified_at: PrimitiveDateTime, pub last_modified_at: PrimitiveDateTime,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")] #[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub fulfilment_time: Option<PrimitiveDateTime>, pub fulfilment_time: Option<PrimitiveDateTime>,
pub custom_merchant_name: Option<String>,
} }
#[derive( #[derive(
Clone, Clone,
Debug, Debug,
@ -47,4 +47,5 @@ pub struct PaymentLinkNew {
pub last_modified_at: Option<PrimitiveDateTime>, pub last_modified_at: Option<PrimitiveDateTime>,
#[serde(default, with = "common_utils::custom_serde::iso8601::option")] #[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub fulfilment_time: Option<PrimitiveDateTime>, pub fulfilment_time: Option<PrimitiveDateTime>,
pub custom_merchant_name: Option<String>,
} }

View File

@ -691,6 +691,8 @@ diesel::table! {
created_at -> Timestamp, created_at -> Timestamp,
last_modified_at -> Timestamp, last_modified_at -> Timestamp,
fulfilment_time -> Nullable<Timestamp>, fulfilment_time -> Nullable<Timestamp>,
#[max_length = 64]
custom_merchant_name -> Nullable<Varchar>,
} }
} }

View File

@ -1,6 +1,6 @@
use api_models::admin as admin_types; use api_models::admin as admin_types;
use common_utils::ext_traits::AsyncExt;
use error_stack::{IntoReport, ResultExt}; use error_stack::{IntoReport, ResultExt};
use masking::PeekInterface;
use super::errors::{self, RouterResult, StorageErrorExt}; use super::errors::{self, RouterResult, StorageErrorExt};
use crate::{ use crate::{
@ -43,6 +43,11 @@ pub async fn intiate_payment_link_flow(
.await .await
.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?; .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( helpers::validate_payment_status_against_not_allowed_statuses(
&payment_intent.status, &payment_intent.status,
&[ &[
@ -55,20 +60,10 @@ pub async fn intiate_payment_link_flow(
"create payment link", "create payment link",
)?; )?;
let fulfillment_time = payment_intent let payment_link = db
.payment_link_id .find_payment_link_by_payment_link_id(&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()
})
.await .await
.get_required_value("fulfillment_time") .to_not_found_response(errors::ApiErrorResponse::PaymentLinkNotFound)?;
.change_context(errors::ApiErrorResponse::PaymentNotFound)?;
let payment_link_config = merchant_account let payment_link_config = merchant_account
.payment_link_config .payment_link_config
@ -108,10 +103,15 @@ pub async fn intiate_payment_link_flow(
amount: payment_intent.amount, amount: payment_intent.amount,
currency, currency,
payment_id: payment_intent.payment_id, 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, order_details,
return_url, return_url,
expiry: fulfillment_time, expiry: payment_link.fulfilment_time,
pub_key, pub_key,
client_secret, client_secret,
merchant_logo: payment_link_config merchant_logo: payment_link_config

View File

@ -813,6 +813,7 @@ async fn create_payment_link(
created_at, created_at,
last_modified_at, last_modified_at,
fulfilment_time: payment_link_object.link_expiry, fulfilment_time: payment_link_object.link_expiry,
custom_merchant_name: payment_link_object.custom_merchant_name,
}; };
let payment_link_db = db let payment_link_db = db
.insert_payment_link(payment_link_req) .insert_payment_link(payment_link_req)

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
ALTER TABLE payment_link DROP COLUMN custom_merchant_name;

View File

@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TABLE payment_link ADD COLUMN custom_merchant_name VARCHAR(64);

View File

@ -7866,6 +7866,11 @@
"merchant_custom_domain_name": { "merchant_custom_domain_name": {
"type": "string", "type": "string",
"nullable": true "nullable": true
},
"custom_merchant_name": {
"type": "string",
"description": "Custom merchant name for payment link",
"nullable": true
} }
} }
}, },