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): Added sdk layout option payment link (#3207)
Sahkal Poddar61176524ca0c
diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex c588bb8718..134beacd22 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -1175,6 +1175,9 @@ pub struct PaymentLinkConfigRequest {/// Custom merchant name for payment link#[schema(value_type = Option<String>, max_length = 255, example = "hyperswitch")]pub seller_name: Option<String>,+ /// Custom layout for sdk+ #[schema(value_type = Option<String>, max_length = 255, example = "accordion")]+ pub sdk_layout: Option<String>,}#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, ToSchema)]@@ -1185,4 +1188,6 @@ pub struct PaymentLinkConfig {pub logo: String,/// Custom merchant name for payment linkpub seller_name: String,+ /// Custom layout for sdk+ pub sdk_layout: String,}diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 4ef0c540b5..45611a9145 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -3381,6 +3381,7 @@ pub struct PaymentLinkDetails {pub max_items_visible_after_collapse: i8,pub theme: String,pub merchant_description: Option<String>,+ pub sdk_layout: String,}#[derive(Debug, serde::Serialize)]diff --git a/crates/common_utils/src/consts.rs b/crates/common_utils/src/consts.rsindex 169cb972c0..cd24e430b7 100644--- a/crates/common_utils/src/consts.rs+++ b/crates/common_utils/src/consts.rs@@ -48,8 +48,8 @@ pub const PROPHETPAY_REDIRECT_URL: &str = "https://ccm-thirdparty.cps.golf/hp/to/// Variable which store the card token for Prophetpaypub const PROPHETPAY_TOKEN: &str = "cctoken";-/// Payment intent fulfillment default timeout (in seconds)-pub const DEFAULT_FULFILLMENT_TIME: i64 = 15 * 60;+/// Default SDK Layout+pub const DEFAULT_SDK_LAYOUT: &str = "tabs";/// Payment intent default client secret expiry (in seconds)pub const DEFAULT_SESSION_EXPIRY: i64 = 15 * 60;diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rsindex 6b546f9078..17784bc565 100644--- a/crates/diesel_models/src/payment_intent.rs+++ b/crates/diesel_models/src/payment_intent.rs@@ -291,7 +291,7 @@ impl PaymentIntentUpdate {incremental_authorization_allowed: incremental_authorization_allowed.or(source.incremental_authorization_allowed),authorization_count: authorization_count.or(source.authorization_count),- session_expiry,+ session_expiry: session_expiry.or(source.session_expiry),..source}}diff --git a/crates/router/src/connector/utils.rs b/crates/router/src/connector/utils.rsindex 39b404d0f5..55173f9b33 100644--- a/crates/router/src/connector/utils.rs+++ b/crates/router/src/connector/utils.rs@@ -1723,6 +1723,45 @@ impl FrmTransactionRouterDataRequest for fraud_check::FrmTransactionRouterData {}}+pub fn is_payment_failure(status: enums::AttemptStatus) -> bool {+ match status {+ common_enums::AttemptStatus::AuthenticationFailed+ | common_enums::AttemptStatus::AuthorizationFailed+ | common_enums::AttemptStatus::CaptureFailed+ | common_enums::AttemptStatus::VoidFailed+ | common_enums::AttemptStatus::Failure => true,+ common_enums::AttemptStatus::Started+ | common_enums::AttemptStatus::RouterDeclined+ | common_enums::AttemptStatus::AuthenticationPending+ | common_enums::AttemptStatus::AuthenticationSuccessful+ | common_enums::AttemptStatus::Authorized+ | common_enums::AttemptStatus::Charged+ | common_enums::AttemptStatus::Authorizing+ | common_enums::AttemptStatus::CodInitiated+ | common_enums::AttemptStatus::Voided+ | common_enums::AttemptStatus::VoidInitiated+ | common_enums::AttemptStatus::CaptureInitiated+ | common_enums::AttemptStatus::AutoRefunded+ | common_enums::AttemptStatus::PartialCharged+ | common_enums::AttemptStatus::PartialChargedAndChargeable+ | common_enums::AttemptStatus::Unresolved+ | common_enums::AttemptStatus::Pending+ | common_enums::AttemptStatus::PaymentMethodAwaited+ | common_enums::AttemptStatus::ConfirmationAwaited+ | common_enums::AttemptStatus::DeviceDataCollectionPending => false,+ }+}++pub fn is_refund_failure(status: enums::RefundStatus) -> bool {+ match status {+ common_enums::RefundStatus::Failure | common_enums::RefundStatus::TransactionFailure => {+ true+ }+ common_enums::RefundStatus::ManualReview+ | common_enums::RefundStatus::Pending+ | common_enums::RefundStatus::Success => false,+ }+}#[cfg(test)]mod error_code_error_message_tests {#![allow(clippy::unwrap_used)]@@ -1802,43 +1841,3 @@ mod error_code_error_message_tests {assert_eq!(error_code_error_message_none, None);}}--pub fn is_payment_failure(status: enums::AttemptStatus) -> bool {- match status {- common_enums::AttemptStatus::AuthenticationFailed- | common_enums::AttemptStatus::AuthorizationFailed- | common_enums::AttemptStatus::CaptureFailed- | common_enums::AttemptStatus::VoidFailed- | common_enums::AttemptStatus::Failure => true,- common_enums::AttemptStatus::Started- | common_enums::AttemptStatus::RouterDeclined- | common_enums::AttemptStatus::AuthenticationPending- | common_enums::AttemptStatus::AuthenticationSuccessful- | common_enums::AttemptStatus::Authorized- | common_enums::AttemptStatus::Charged- | common_enums::AttemptStatus::Authorizing- | common_enums::AttemptStatus::CodInitiated- | common_enums::AttemptStatus::Voided- | common_enums::AttemptStatus::VoidInitiated- | common_enums::AttemptStatus::CaptureInitiated- | common_enums::AttemptStatus::AutoRefunded- | common_enums::AttemptStatus::PartialCharged- | common_enums::AttemptStatus::PartialChargedAndChargeable- | common_enums::AttemptStatus::Unresolved- | common_enums::AttemptStatus::Pending- | common_enums::AttemptStatus::PaymentMethodAwaited- | common_enums::AttemptStatus::ConfirmationAwaited- | common_enums::AttemptStatus::DeviceDataCollectionPending => false,- }-}--pub fn is_refund_failure(status: enums::RefundStatus) -> bool {- match status {- common_enums::RefundStatus::Failure | common_enums::RefundStatus::TransactionFailure => {- true- }- common_enums::RefundStatus::ManualReview- | common_enums::RefundStatus::Pending- | common_enums::RefundStatus::Success => false,- }-}diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rsindex 9adf903179..84cd726a7e 100644--- a/crates/router/src/core/payment_link.rs+++ b/crates/router/src/core/payment_link.rs@@ -1,7 +1,7 @@use api_models::admin as admin_types;use common_utils::{consts::{- DEFAULT_BACKGROUND_COLOR, DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG,+ DEFAULT_BACKGROUND_COLOR, DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT,DEFAULT_SESSION_EXPIRY,},ext_traits::{OptionExt, ValueExt},@@ -85,6 +85,7 @@ pub async fn intiate_payment_link_flow(theme: DEFAULT_BACKGROUND_COLOR.to_string(),logo: DEFAULT_MERCHANT_LOGO.to_string(),seller_name: merchant_name_from_merchant_account,+ sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),}};@@ -180,6 +181,7 @@ pub async fn intiate_payment_link_flow(max_items_visible_after_collapse: 3,theme: payment_link_config.clone().theme,merchant_description: payment_intent.description,+ sdk_layout: payment_link_config.clone().sdk_layout,};let js_script = get_js_script(api_models::payments::PaymentLinkData::PaymentLinkDetails(@@ -384,10 +386,21 @@ pub fn get_payment_link_config_based_on_priority(}).unwrap_or(merchant_name.clone());+ let sdk_layout = payment_create_link_config+ .as_ref()+ .and_then(|pc_config| pc_config.config.sdk_layout.clone())+ .or_else(|| {+ business_config+ .as_ref()+ .and_then(|business_config| business_config.sdk_layout.clone())+ })+ .unwrap_or(DEFAULT_SDK_LAYOUT.to_owned());+let payment_link_config = admin_types::PaymentLinkConfig {theme,logo,seller_name,+ sdk_layout,};Ok((payment_link_config, domain_name))diff --git a/crates/router/src/core/payment_link/payment_link.html b/crates/router/src/core/payment_link/payment_link.htmlindex 3a3ed4fffe..f6e62f8bdc 100644--- a/crates/router/src/core/payment_link/payment_link.html+++ b/crates/router/src/core/payment_link/payment_link.html@@ -1269,8 +1269,15 @@appearance: appearance,clientSecret: client_secret,});+ var type = (paymentDetails.sdk_layout === "spaced_accordion" || paymentDetails.sdk_layout === "accordion")+ ? "accordion"+ : paymentDetails.sdk_layout;+var unifiedCheckoutOptions = {- layout: "tabs",+ layout: {+ type: type, //accordion , tabs, spaced accordion+ spacedAccordionItems: paymentDetails.sdk_layout === "spaced_accordion"+ },branding: "never",wallets: {walletReturnUrl: paymentDetails.return_url,diff --git a/crates/router/src/macros.rs b/crates/router/src/macros.rsindex e6c9dba7d6..efe71e49bb 100644--- a/crates/router/src/macros.rs+++ b/crates/router/src/macros.rs@@ -1,4 +1 @@-pub use common_utils::{- async_spawn, collect_missing_value_keys, fallback_reverse_lookup_not_found, newtype,- newtype_impl,-};+pub use common_utils::{collect_missing_value_keys, newtype};diff --git a/migrations/2023-11-24-112541_add_payment_config_business_profile/up.sql b/migrations/2023-11-24-112541_add_payment_config_business_profile/up.sqlindex 19fbedccbb..40e65c149f 100644--- a/migrations/2023-11-24-112541_add_payment_config_business_profile/up.sql+++ b/migrations/2023-11-24-112541_add_payment_config_business_profile/up.sql@@ -1,3 +1,3 @@-- Your SQL goes hereALTER TABLE business_profile-ADD COLUMN IF NOT EXISTS payment_link_config JSONB DEFAULT NULL;\ No newline at end of file+ADD COLUMN IF NOT EXISTS payment_link_config JSONB DEFAULT NULL;diff --git a/migrations/2023-11-24-115538_add_profile_id_payment_link/up.sql b/migrations/2023-11-24-115538_add_profile_id_payment_link/up.sqlindex b48346c763..207fdc8817 100644--- a/migrations/2023-11-24-115538_add_profile_id_payment_link/up.sql+++ b/migrations/2023-11-24-115538_add_profile_id_payment_link/up.sql@@ -1,2 +1,2 @@-- Your SQL goes here-ALTER TABLE payment_link ADD COLUMN IF NOT EXISTS profile_id VARCHAR(64) DEFAULT NULL;\ No newline at end of file+ALTER TABLE payment_link ADD COLUMN IF NOT EXISTS profile_id VARCHAR(64) DEFAULT NULL;diff --git a/migrations/2023-12-06-112810_add_intent_fullfilment_time_payment_intent/down.sql b/migrations/2023-12-06-112810_add_intent_fullfilment_time_payment_intent/down.sqlindex 2801a68c67..6af3e1e7f3 100644--- a/migrations/2023-12-06-112810_add_intent_fullfilment_time_payment_intent/down.sql+++ b/migrations/2023-12-06-112810_add_intent_fullfilment_time_payment_intent/down.sql@@ -1,2 +1,2 @@-- This file should undo anything in `up.sql`-ALTER TABLE payment_intent DROP COLUMN IF EXISTS session_expiry;\ No newline at end of file+ALTER TABLE payment_intent DROP COLUMN IF EXISTS session_expiry;diff --git a/migrations/2023-12-06-112810_add_intent_fullfilment_time_payment_intent/up.sql b/migrations/2023-12-06-112810_add_intent_fullfilment_time_payment_intent/up.sqlindex f2ee81e847..e6ad0a728d 100644--- a/migrations/2023-12-06-112810_add_intent_fullfilment_time_payment_intent/up.sql+++ b/migrations/2023-12-06-112810_add_intent_fullfilment_time_payment_intent/up.sql@@ -1,2 +1,2 @@-- Your SQL goes here-ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS session_expiry TIMESTAMP DEFAULT NULL;\ No newline at end of file+ALTER TABLE payment_intent ADD COLUMN IF NOT EXISTS session_expiry TIMESTAMP DEFAULT NULL;diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.jsonindex df5b944897..dd27b5d609 100644--- a/openapi/openapi_spec.json+++ b/openapi/openapi_spec.json@@ -8686,7 +8686,8 @@"required": ["theme","logo",- "seller_name"+ "seller_name",+ "sdk_layout"],"properties": {"theme": {@@ -8700,6 +8701,10 @@"seller_name": {"type": "string","description": "Custom merchant name for payment link"+ },+ "sdk_layout": {+ "type": "string",+ "description": "Custom layout for sdk"}}},@@ -8726,6 +8731,13 @@"example": "hyperswitch","nullable": true,"maxLength": 255+ },+ "sdk_layout": {+ "type": "string",+ "description": "Custom layout for sdk",+ "example": "accordion",+ "nullable": true,+ "maxLength": 255}}},