Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(payment_link): Add support for saved payment method option for payment link (#4373)
Sahkal Poddar14341cad27c6
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex f9ebbc3360..88d584b6a7 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -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 linkpub display_sdk_only: bool,+ /// Enable saved payment method option for payment link+ pub enabled_saved_payment_method: bool,}diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex ad88288016..919f057d55 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -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)]diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rsindex c9caa1ea62..74fdabecf1 100644--- a/crates/common_utils/src/consts.rs+++ b/crates/common_utils/src/consts.rs@@ -71,3 +71,6 @@ pub const DEFAULT_SESSION_EXPIRY: i64 = 15 * 60;/// Default bool for Display sdk onlypub const DEFAULT_DISPLAY_SDK_ONLY: bool = false;++/// Default bool to enable saved payment method+pub const DEFAULT_ENABLE_SAVED_PAYMENT_METHOD: bool = false;diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rsindex f00c878096..3f9f5f017a 100644--- a/crates/router/src/core/payment_link.rs+++ b/crates/router/src/core/payment_link.rs@@ -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,}};diff --git a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.jsindex e6d1feb8c2..f53312f74f 100644--- a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js+++ b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js@@ -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 accordionspacedAccordionItems: paymentDetails.sdk_layout === "spaced_accordion",diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex 3d953f3f46..f646ba8b8d 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -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}}},