feat(payment_link): Add support for saved payment method option for payment link (#4373)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Sahkal Poddar
2024-04-17 17:07:33 +05:30
committed by GitHub
parent ca47ea9b13
commit 14341cad27
6 changed files with 43 additions and 5 deletions

View File

@ -1068,6 +1068,9 @@ pub struct PaymentLinkConfigRequest {
/// Display only the sdk for payment link
#[schema(default = false, example = true)]
pub display_sdk_only: Option<bool>,
/// Enable saved payment method option for payment link
#[schema(default = false, example = true)]
pub enabled_saved_payment_method: Option<bool>,
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, ToSchema)]
@ -1082,4 +1085,6 @@ pub struct PaymentLinkConfig {
pub sdk_layout: String,
/// Display only the sdk for payment link
pub display_sdk_only: bool,
/// Enable saved payment method option for payment link
pub enabled_saved_payment_method: bool,
}

View File

@ -4490,6 +4490,7 @@ pub struct PaymentLinkDetails {
pub merchant_description: Option<String>,
pub sdk_layout: String,
pub display_sdk_only: bool,
pub enabled_saved_payment_method: bool,
}
#[derive(Debug, serde::Serialize)]

View File

@ -71,3 +71,6 @@ pub const DEFAULT_SESSION_EXPIRY: i64 = 15 * 60;
/// Default bool for Display sdk only
pub const DEFAULT_DISPLAY_SDK_ONLY: bool = false;
/// Default bool to enable saved payment method
pub const DEFAULT_ENABLE_SAVED_PAYMENT_METHOD: bool = false;

View File

@ -1,8 +1,8 @@
use api_models::{admin as admin_types, payments::PaymentLinkStatusWrap};
use common_utils::{
consts::{
DEFAULT_BACKGROUND_COLOR, DEFAULT_DISPLAY_SDK_ONLY, DEFAULT_MERCHANT_LOGO,
DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT, DEFAULT_SESSION_EXPIRY,
DEFAULT_BACKGROUND_COLOR, DEFAULT_DISPLAY_SDK_ONLY, DEFAULT_ENABLE_SAVED_PAYMENT_METHOD,
DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT, DEFAULT_SESSION_EXPIRY,
},
ext_traits::{OptionExt, ValueExt},
};
@ -87,6 +87,7 @@ pub async fn initiate_payment_link_flow(
seller_name: merchant_name_from_merchant_account,
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
enabled_saved_payment_method: DEFAULT_ENABLE_SAVED_PAYMENT_METHOD,
}
};
@ -215,6 +216,7 @@ pub async fn initiate_payment_link_flow(
merchant_description: payment_intent.description,
sdk_layout: payment_link_config.sdk_layout.clone(),
display_sdk_only: payment_link_config.display_sdk_only,
enabled_saved_payment_method: payment_link_config.enabled_saved_payment_method,
};
let js_script = get_js_script(&api_models::payments::PaymentLinkData::PaymentLinkDetails(
@ -453,12 +455,24 @@ pub fn get_payment_link_config_based_on_priority(
})
.unwrap_or(DEFAULT_DISPLAY_SDK_ONLY);
let enabled_saved_payment_method = payment_create_link_config
.as_ref()
.and_then(|pc_config| {
pc_config.config.enabled_saved_payment_method.or_else(|| {
business_config
.as_ref()
.and_then(|business_config| business_config.enabled_saved_payment_method)
})
})
.unwrap_or(DEFAULT_ENABLE_SAVED_PAYMENT_METHOD);
let payment_link_config = admin_types::PaymentLinkConfig {
theme,
logo,
seller_name,
sdk_layout,
display_sdk_only,
enabled_saved_payment_method,
};
Ok((payment_link_config, domain_name))
@ -536,6 +550,7 @@ pub async fn get_payment_link_status(
seller_name: merchant_name_from_merchant_account,
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
enabled_saved_payment_method: DEFAULT_ENABLE_SAVED_PAYMENT_METHOD,
}
};

View File

@ -417,9 +417,11 @@ function initializeSDK() {
? "accordion"
: paymentDetails.sdk_layout;
var enabledSavedPaymentMethod = paymentDetails.enabledSavedPaymentMethod;
var unifiedCheckoutOptions = {
displaySavedPaymentMethodsCheckbox: false,
displaySavedPaymentMethods: false,
displaySavedPaymentMethodsCheckbox: enabledSavedPaymentMethod,
displaySavedPaymentMethods: enabledSavedPaymentMethod,
layout: {
type: type, //accordion , tabs, spaced accordion
spacedAccordionItems: paymentDetails.sdk_layout === "spaced_accordion",

View File

@ -12208,7 +12208,8 @@
"logo",
"seller_name",
"sdk_layout",
"display_sdk_only"
"display_sdk_only",
"enabled_saved_payment_method"
],
"properties": {
"theme": {
@ -12230,6 +12231,10 @@
"display_sdk_only": {
"type": "boolean",
"description": "Display only the sdk for payment link"
},
"enabled_saved_payment_method": {
"type": "boolean",
"description": "Enable saved payment method option for payment link"
}
}
},
@ -12270,6 +12275,13 @@
"default": false,
"example": true,
"nullable": true
},
"enabled_saved_payment_method": {
"type": "boolean",
"description": "Enable saved payment method option for payment link",
"default": false,
"example": true,
"nullable": true
}
}
},