Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(payments): [Payment links] add hide card nickname field config for secure payment links #6554

Merged
merged 8 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -11960,7 +11960,8 @@
"seller_name",
"sdk_layout",
"display_sdk_only",
"enabled_saved_payment_method"
"enabled_saved_payment_method",
"hide_card_nickname_field"
],
"properties": {
"theme": {
Expand All @@ -11987,6 +11988,10 @@
"type": "boolean",
"description": "Enable saved payment method option for payment link"
},
"hide_card_nickname_field": {
"type": "boolean",
"description": "Hide card nickname field option for payment link"
},
"allowed_domains": {
"type": "array",
"items": {
Expand Down Expand Up @@ -12051,6 +12056,13 @@
"example": true,
"nullable": true
},
"hide_card_nickname_field": {
"type": "boolean",
"description": "Hide card nickname field option for payment link",
"default": false,
"example": true,
"nullable": true
},
"transaction_details": {
"type": "array",
"items": {
Expand Down
14 changes: 13 additions & 1 deletion api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -15086,7 +15086,8 @@
"seller_name",
"sdk_layout",
"display_sdk_only",
"enabled_saved_payment_method"
"enabled_saved_payment_method",
"hide_card_nickname_field"
],
"properties": {
"theme": {
Expand All @@ -15113,6 +15114,10 @@
"type": "boolean",
"description": "Enable saved payment method option for payment link"
},
"hide_card_nickname_field": {
"type": "boolean",
"description": "Hide card nickname field option for payment link"
},
"allowed_domains": {
"type": "array",
"items": {
Expand Down Expand Up @@ -15177,6 +15182,13 @@
"example": true,
"nullable": true
},
"hide_card_nickname_field": {
"type": "boolean",
"description": "Hide card nickname field option for payment link",
"default": false,
"example": true,
"nullable": true
},
"transaction_details": {
"type": "array",
"items": {
Expand Down
5 changes: 5 additions & 0 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2692,6 +2692,9 @@ pub struct PaymentLinkConfigRequest {
/// Enable saved payment method option for payment link
#[schema(default = false, example = true)]
pub enabled_saved_payment_method: Option<bool>,
/// Hide card nickname field option for payment link
#[schema(default = false, example = true)]
pub hide_card_nickname_field: Option<bool>,
/// Dynamic details related to merchant to be rendered in payment link
pub transaction_details: Option<Vec<PaymentLinkTransactionDetails>>,
}
Expand Down Expand Up @@ -2735,6 +2738,8 @@ pub struct PaymentLinkConfig {
pub display_sdk_only: bool,
/// Enable saved payment method option for payment link
pub enabled_saved_payment_method: bool,
/// Hide card nickname field option for payment link
pub hide_card_nickname_field: bool,
/// A list of allowed domains (glob patterns) where this link can be embedded / opened from
pub allowed_domains: Option<HashSet<String>>,
/// Dynamic details related to merchant to be rendered in payment link
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6544,13 +6544,15 @@ pub struct PaymentLinkDetails {
pub merchant_description: Option<String>,
pub sdk_layout: String,
pub display_sdk_only: bool,
pub hide_card_nickname_field: bool,
pub locale: Option<String>,
pub transaction_details: Option<Vec<admin::PaymentLinkTransactionDetails>>,
}

#[derive(Debug, serde::Serialize, Clone)]
pub struct SecurePaymentLinkDetails {
pub enabled_saved_payment_method: bool,
pub hide_card_nickname_field: bool,
#[serde(flatten)]
pub payment_link_details: PaymentLinkDetails,
}
Expand Down
25 changes: 0 additions & 25 deletions crates/common_utils/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Commonly used constants

use std::collections::HashSet;

/// Number of characters in a generated ID
pub const ID_LENGTH: usize = 20;

Expand Down Expand Up @@ -51,26 +49,12 @@ pub const SURCHARGE_PERCENTAGE_PRECISION_LENGTH: u8 = 2;
/// Header Key for application overhead of a request
pub const X_HS_LATENCY: &str = "x-hs-latency";

/// Default Payment Link Background color
pub const DEFAULT_BACKGROUND_COLOR: &str = "#212E46";

/// Default product Img Link
pub const DEFAULT_PRODUCT_IMG: &str =
"https://live.hyperswitch.io/payment-link-assets/cart_placeholder.png";

/// Default Merchant Logo Link
pub const DEFAULT_MERCHANT_LOGO: &str =
"https://live.hyperswitch.io/payment-link-assets/Merchant_placeholder.png";

/// Redirect url for Prophetpay
pub const PROPHETPAY_REDIRECT_URL: &str = "https://ccm-thirdparty.cps.golf/hp/tokenize/";

/// Variable which store the card token for Prophetpay
pub const PROPHETPAY_TOKEN: &str = "cctoken";

/// 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;

Expand All @@ -80,15 +64,6 @@ pub const DEFAULT_INTENT_FULFILLMENT_TIME: i64 = 15 * 60;
/// Payment order fulfillment time (in seconds)
pub const DEFAULT_ORDER_FULFILLMENT_TIME: 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;

/// Default allowed domains for payment links
pub const DEFAULT_ALLOWED_DOMAINS: Option<HashSet<String>> = None;

/// Default ttl for Extended card info in redis (in seconds)
pub const DEFAULT_TTL_FOR_EXTENDED_CARD_INFO: u16 = 15 * 60;

Expand Down
1 change: 1 addition & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ pub struct PaymentLinkConfigRequest {
pub sdk_layout: Option<String>,
pub display_sdk_only: Option<bool>,
pub enabled_saved_payment_method: Option<bool>,
pub hide_card_nickname_field: Option<bool>,
}

common_utils::impl_to_sql_from_sql_json!(BusinessPaymentLinkConfig);
Expand Down
2 changes: 2 additions & 0 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ pub struct PaymentLinkConfigRequestForPayments {
pub display_sdk_only: Option<bool>,
/// Enable saved payment method option for payment link
pub enabled_saved_payment_method: Option<bool>,
/// Hide card nickname field option for payment link
pub hide_card_nickname_field: Option<bool>,
/// Dynamic details related to merchant to be rendered in payment link
pub transaction_details: Option<Vec<PaymentLinkTransactionDetails>>,
}
Expand Down
3 changes: 3 additions & 0 deletions crates/hyperswitch_domain_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
sdk_layout: item.sdk_layout,
display_sdk_only: item.display_sdk_only,
enabled_saved_payment_method: item.enabled_saved_payment_method,
hide_card_nickname_field: item.hide_card_nickname_field,
transaction_details: item.transaction_details.map(|transaction_details| {
transaction_details
.into_iter()
Expand All @@ -210,6 +211,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
sdk_layout,
display_sdk_only,
enabled_saved_payment_method,
hide_card_nickname_field,
transaction_details,
} = self;
api_models::admin::PaymentLinkConfigRequest {
Expand All @@ -219,6 +221,7 @@ impl ApiModelToDieselModelConvertor<api_models::admin::PaymentLinkConfigRequest>
sdk_layout,
display_sdk_only,
enabled_saved_payment_method,
hide_card_nickname_field,
transaction_details: transaction_details.map(|transaction_details| {
transaction_details
.into_iter()
Expand Down
28 changes: 28 additions & 0 deletions crates/router/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pub mod opensearch;
pub mod user;
pub mod user_role;

use std::collections::HashSet;

use common_utils::consts;
pub use hyperswitch_interfaces::consts::{NO_ERROR_CODE, NO_ERROR_MESSAGE};
// ID generation
Expand Down Expand Up @@ -145,6 +147,32 @@ pub const RECON_FEATURE_TAG: &str = "RECONCILIATION AND SETTLEMENT";
// Length of the unique reference ID generated for connector mandate requests
pub const CONNECTOR_MANDATE_REQUEST_REFERENCE_ID_LENGTH: usize = 18;

/// Default allowed domains for payment links
pub const DEFAULT_ALLOWED_DOMAINS: Option<HashSet<String>> = None;

/// Default hide card nickname field
pub const DEFAULT_HIDE_CARD_NICKNAME_FIELD: bool = false;

/// 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;

/// Default Merchant Logo Link
pub const DEFAULT_MERCHANT_LOGO: &str =
"https://live.hyperswitch.io/payment-link-assets/Merchant_placeholder.png";

/// Default Payment Link Background color
pub const DEFAULT_BACKGROUND_COLOR: &str = "#212E46";

/// Default product Img Link
pub const DEFAULT_PRODUCT_IMG: &str =
"https://live.hyperswitch.io/payment-link-assets/cart_placeholder.png";

/// Default SDK Layout
pub const DEFAULT_SDK_LAYOUT: &str = "tabs";

/// Vault Add request url
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
pub const ADD_VAULT_REQUEST_URL: &str = "/vault/add";
Expand Down
30 changes: 22 additions & 8 deletions crates/router/src/core/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ use api_models::{
payments::{PaymentLinkData, PaymentLinkStatusWrap},
};
use common_utils::{
consts::{
DEFAULT_ALLOWED_DOMAINS, DEFAULT_BACKGROUND_COLOR, DEFAULT_DISPLAY_SDK_ONLY,
DEFAULT_ENABLE_SAVED_PAYMENT_METHOD, DEFAULT_LOCALE, DEFAULT_MERCHANT_LOGO,
DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT, DEFAULT_SESSION_EXPIRY,
},
consts::{DEFAULT_LOCALE, DEFAULT_SESSION_EXPIRY},
ext_traits::{AsyncExt, OptionExt, ValueExt},
types::{AmountConvertor, StringMajorUnitForCore},
};
Expand All @@ -25,7 +21,11 @@ use super::{
payments::helpers,
};
use crate::{
consts,
consts::{
self, DEFAULT_ALLOWED_DOMAINS, DEFAULT_BACKGROUND_COLOR, DEFAULT_DISPLAY_SDK_ONLY,
DEFAULT_ENABLE_SAVED_PAYMENT_METHOD, DEFAULT_HIDE_CARD_NICKNAME_FIELD,
DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT,
},
errors::RouterResponse,
get_payment_link_config_value, get_payment_link_config_value_based_on_priority,
headers::ACCEPT_LANGUAGE,
Expand Down Expand Up @@ -125,6 +125,7 @@ pub async fn form_payment_link_data(
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
enabled_saved_payment_method: DEFAULT_ENABLE_SAVED_PAYMENT_METHOD,
hide_card_nickname_field: DEFAULT_HIDE_CARD_NICKNAME_FIELD,
allowed_domains: DEFAULT_ALLOWED_DOMAINS,
transaction_details: None,
}
Expand Down Expand Up @@ -265,6 +266,7 @@ pub async fn form_payment_link_data(
merchant_description: payment_intent.description,
sdk_layout: payment_link_config.sdk_layout.clone(),
display_sdk_only: payment_link_config.display_sdk_only,
hide_card_nickname_field: payment_link_config.hide_card_nickname_field,
locale,
transaction_details: payment_link_config.transaction_details.clone(),
};
Expand Down Expand Up @@ -322,6 +324,7 @@ pub async fn initiate_secure_payment_link_flow(
PaymentLinkData::PaymentLinkDetails(link_details) => {
let secure_payment_link_details = api_models::payments::SecurePaymentLinkDetails {
enabled_saved_payment_method: payment_link_config.enabled_saved_payment_method,
hide_card_nickname_field: payment_link_config.hide_card_nickname_field,
payment_link_details: *link_details.to_owned(),
};
let js_script = format!(
Expand Down Expand Up @@ -607,7 +610,15 @@ pub fn get_payment_link_config_based_on_priority(
(default_domain_name, None, None)
};

let (theme, logo, seller_name, sdk_layout, display_sdk_only, enabled_saved_payment_method) = get_payment_link_config_value!(
let (
theme,
logo,
seller_name,
sdk_layout,
display_sdk_only,
enabled_saved_payment_method,
hide_card_nickname_field,
) = get_payment_link_config_value!(
payment_create_link_config,
business_theme_configs,
(theme, DEFAULT_BACKGROUND_COLOR.to_string()),
Expand All @@ -618,7 +629,8 @@ pub fn get_payment_link_config_based_on_priority(
(
enabled_saved_payment_method,
DEFAULT_ENABLE_SAVED_PAYMENT_METHOD
)
),
(hide_card_nickname_field, DEFAULT_HIDE_CARD_NICKNAME_FIELD)
);
let payment_link_config = PaymentLinkConfig {
theme,
Expand All @@ -627,6 +639,7 @@ pub fn get_payment_link_config_based_on_priority(
sdk_layout,
display_sdk_only,
enabled_saved_payment_method,
hide_card_nickname_field,
allowed_domains,
transaction_details: payment_create_link_config
.and_then(|payment_link_config| payment_link_config.theme_config.transaction_details),
Expand Down Expand Up @@ -729,6 +742,7 @@ pub async fn get_payment_link_status(
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
enabled_saved_payment_method: DEFAULT_ENABLE_SAVED_PAYMENT_METHOD,
hide_card_nickname_field: DEFAULT_HIDE_CARD_NICKNAME_FIELD,
allowed_domains: DEFAULT_ALLOWED_DOMAINS,
transaction_details: None,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function initializeSDK() {
height: 55,
},
},
hideCardNicknameField: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use what was configured in the payment link config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since displaySavedPaymentMethodsCheckbox is set to false for open payment links, it doesn't matter whether we hide the card nick name field or not. So i mapped it to it's default value in SDK, which is false.

};
// @ts-ignore
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ if (!isFramed) {
: paymentDetails.sdk_layout;

var enableSavedPaymentMethod = paymentDetails.enabled_saved_payment_method;
var hideCardNicknameField = paymentDetails.hide_card_nickname_field;
var unifiedCheckoutOptions = {
displaySavedPaymentMethodsCheckbox: enableSavedPaymentMethod,
displaySavedPaymentMethods: enableSavedPaymentMethod,
Expand All @@ -79,6 +80,7 @@ if (!isFramed) {
height: 55,
},
},
hideCardNicknameField: hideCardNicknameField,
};
// @ts-ignore
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3518,6 +3518,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
sdk_layout: config.sdk_layout,
display_sdk_only: config.display_sdk_only,
enabled_saved_payment_method: config.enabled_saved_payment_method,
hide_card_nickname_field: config.hide_card_nickname_field,
transaction_details: config.transaction_details.map(|transaction_details| {
transaction_details
.iter()
Expand Down Expand Up @@ -3570,6 +3571,7 @@ impl ForeignFrom<diesel_models::PaymentLinkConfigRequestForPayments>
sdk_layout: config.sdk_layout,
display_sdk_only: config.display_sdk_only,
enabled_saved_payment_method: config.enabled_saved_payment_method,
hide_card_nickname_field: config.hide_card_nickname_field,
transaction_details: config.transaction_details.map(|transaction_details| {
transaction_details
.iter()
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/types/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,7 @@ impl ForeignFrom<api_models::admin::PaymentLinkConfigRequest>
sdk_layout: item.sdk_layout,
display_sdk_only: item.display_sdk_only,
enabled_saved_payment_method: item.enabled_saved_payment_method,
hide_card_nickname_field: item.hide_card_nickname_field,
}
}
}
Expand All @@ -2002,6 +2003,7 @@ impl ForeignFrom<diesel_models::business_profile::PaymentLinkConfigRequest>
sdk_layout: item.sdk_layout,
display_sdk_only: item.display_sdk_only,
enabled_saved_payment_method: item.enabled_saved_payment_method,
hide_card_nickname_field: item.hide_card_nickname_field,
transaction_details: None,
}
}
Expand Down
Loading