mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
feat(payment_link): added display_sdk_only option for displaying only sdk without payment details (#4363)
This commit is contained in:
@ -1065,6 +1065,9 @@ pub struct PaymentLinkConfigRequest {
|
|||||||
/// Custom layout for sdk
|
/// Custom layout for sdk
|
||||||
#[schema(value_type = Option<String>, max_length = 255, example = "accordion")]
|
#[schema(value_type = Option<String>, max_length = 255, example = "accordion")]
|
||||||
pub sdk_layout: Option<String>,
|
pub sdk_layout: Option<String>,
|
||||||
|
/// Display only the sdk for payment link
|
||||||
|
#[schema(default = false, example = true)]
|
||||||
|
pub display_sdk_only: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, ToSchema)]
|
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, ToSchema)]
|
||||||
@ -1077,4 +1080,6 @@ pub struct PaymentLinkConfig {
|
|||||||
pub seller_name: String,
|
pub seller_name: String,
|
||||||
/// Custom layout for sdk
|
/// Custom layout for sdk
|
||||||
pub sdk_layout: String,
|
pub sdk_layout: String,
|
||||||
|
/// Display only the sdk for payment link
|
||||||
|
pub display_sdk_only: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4489,6 +4489,7 @@ pub struct PaymentLinkDetails {
|
|||||||
pub theme: String,
|
pub theme: String,
|
||||||
pub merchant_description: Option<String>,
|
pub merchant_description: Option<String>,
|
||||||
pub sdk_layout: String,
|
pub sdk_layout: String,
|
||||||
|
pub display_sdk_only: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, serde::Serialize)]
|
#[derive(Debug, serde::Serialize)]
|
||||||
|
|||||||
@ -68,3 +68,6 @@ pub const DEFAULT_SDK_LAYOUT: &str = "tabs";
|
|||||||
|
|
||||||
/// Payment intent default client secret expiry (in seconds)
|
/// Payment intent default client secret expiry (in seconds)
|
||||||
pub const DEFAULT_SESSION_EXPIRY: i64 = 15 * 60;
|
pub const DEFAULT_SESSION_EXPIRY: i64 = 15 * 60;
|
||||||
|
|
||||||
|
/// Default bool for Display sdk only
|
||||||
|
pub const DEFAULT_DISPLAY_SDK_ONLY: bool = false;
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
use api_models::{admin as admin_types, payments::PaymentLinkStatusWrap};
|
use api_models::{admin as admin_types, payments::PaymentLinkStatusWrap};
|
||||||
use common_utils::{
|
use common_utils::{
|
||||||
consts::{
|
consts::{
|
||||||
DEFAULT_BACKGROUND_COLOR, DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT,
|
DEFAULT_BACKGROUND_COLOR, DEFAULT_DISPLAY_SDK_ONLY, DEFAULT_MERCHANT_LOGO,
|
||||||
DEFAULT_SESSION_EXPIRY,
|
DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT, DEFAULT_SESSION_EXPIRY,
|
||||||
},
|
},
|
||||||
ext_traits::{OptionExt, ValueExt},
|
ext_traits::{OptionExt, ValueExt},
|
||||||
};
|
};
|
||||||
@ -86,6 +86,7 @@ pub async fn initiate_payment_link_flow(
|
|||||||
logo: DEFAULT_MERCHANT_LOGO.to_string(),
|
logo: DEFAULT_MERCHANT_LOGO.to_string(),
|
||||||
seller_name: merchant_name_from_merchant_account,
|
seller_name: merchant_name_from_merchant_account,
|
||||||
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
|
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
|
||||||
|
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -213,6 +214,7 @@ pub async fn initiate_payment_link_flow(
|
|||||||
theme: payment_link_config.theme.clone(),
|
theme: payment_link_config.theme.clone(),
|
||||||
merchant_description: payment_intent.description,
|
merchant_description: payment_intent.description,
|
||||||
sdk_layout: payment_link_config.sdk_layout.clone(),
|
sdk_layout: payment_link_config.sdk_layout.clone(),
|
||||||
|
display_sdk_only: payment_link_config.display_sdk_only,
|
||||||
};
|
};
|
||||||
|
|
||||||
let js_script = get_js_script(&api_models::payments::PaymentLinkData::PaymentLinkDetails(
|
let js_script = get_js_script(&api_models::payments::PaymentLinkData::PaymentLinkDetails(
|
||||||
@ -440,11 +442,23 @@ pub fn get_payment_link_config_based_on_priority(
|
|||||||
})
|
})
|
||||||
.unwrap_or(DEFAULT_SDK_LAYOUT.to_owned());
|
.unwrap_or(DEFAULT_SDK_LAYOUT.to_owned());
|
||||||
|
|
||||||
|
let display_sdk_only = payment_create_link_config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|pc_config| {
|
||||||
|
pc_config.config.display_sdk_only.or_else(|| {
|
||||||
|
business_config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|business_config| business_config.display_sdk_only)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.unwrap_or(DEFAULT_DISPLAY_SDK_ONLY);
|
||||||
|
|
||||||
let payment_link_config = admin_types::PaymentLinkConfig {
|
let payment_link_config = admin_types::PaymentLinkConfig {
|
||||||
theme,
|
theme,
|
||||||
logo,
|
logo,
|
||||||
seller_name,
|
seller_name,
|
||||||
sdk_layout,
|
sdk_layout,
|
||||||
|
display_sdk_only,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((payment_link_config, domain_name))
|
Ok((payment_link_config, domain_name))
|
||||||
@ -521,6 +535,7 @@ pub async fn get_payment_link_status(
|
|||||||
logo: DEFAULT_MERCHANT_LOGO.to_string(),
|
logo: DEFAULT_MERCHANT_LOGO.to_string(),
|
||||||
seller_name: merchant_name_from_merchant_account,
|
seller_name: merchant_name_from_merchant_account,
|
||||||
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
|
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
|
||||||
|
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -193,7 +193,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="hyper-checkout-status-redirect-message"></div>
|
<div id="hyper-checkout-status-redirect-message"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="main" id="hyper-checkout-details">
|
<div class="main checkout-page" id="hyper-checkout-details">
|
||||||
<div id="hyper-checkout-payment" class="hyper-checkout-payment">
|
<div id="hyper-checkout-payment" class="hyper-checkout-payment">
|
||||||
<div class="hyper-checkout-payment-content-details">
|
<div class="hyper-checkout-payment-content-details">
|
||||||
<div class="content-details-wrap">
|
<div class="content-details-wrap">
|
||||||
|
|||||||
@ -194,38 +194,52 @@ function boot() {
|
|||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
var paymentDetails = window.__PAYMENT_DETAILS;
|
var paymentDetails = window.__PAYMENT_DETAILS;
|
||||||
var orderDetails = paymentDetails.order_details;
|
|
||||||
if (orderDetails!==null) {
|
|
||||||
var charges = 0;
|
|
||||||
|
|
||||||
for (var i = 0; i < orderDetails.length; i++) {
|
if (paymentDetails.display_sdk_only) {
|
||||||
charges += parseFloat(orderDetails[i].amount * orderDetails[i].quantity);
|
hide(".checkout-page")
|
||||||
|
var sdkDisplayWidth = document.querySelector('.hyper-checkout-sdk');
|
||||||
|
sdkDisplayWidth.style.width = '100vw';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var orderDetails = paymentDetails.order_details;
|
||||||
|
if (orderDetails!==null) {
|
||||||
|
var charges = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < orderDetails.length; i++) {
|
||||||
|
charges += parseFloat(orderDetails[i].amount * orderDetails[i].quantity);
|
||||||
|
}
|
||||||
|
orderDetails.push({
|
||||||
|
"amount": (paymentDetails.amount - charges).toFixed(2),
|
||||||
|
"product_img_link": "https://live.hyperswitch.io/payment-link-assets/cart_placeholder.png",
|
||||||
|
"product_name": "Miscellaneous charges\n" +
|
||||||
|
"(includes taxes, shipping, discounts, offers etc.)",
|
||||||
|
"quantity": null
|
||||||
|
});
|
||||||
}
|
}
|
||||||
orderDetails.push({
|
|
||||||
"amount": (paymentDetails.amount - charges).toFixed(2),
|
|
||||||
"product_img_link": "https://live.hyperswitch.io/payment-link-assets/cart_placeholder.png",
|
|
||||||
"product_name": "Miscellaneous charges\n" +
|
|
||||||
"(includes taxes, shipping, discounts, offers etc.)",
|
|
||||||
"quantity": null
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (paymentDetails.merchant_name) {
|
if (paymentDetails.merchant_name) {
|
||||||
document.title = "Payment requested by " + paymentDetails.merchant_name;
|
document.title = "Payment requested by " + paymentDetails.merchant_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paymentDetails.merchant_logo) {
|
if (paymentDetails.merchant_logo) {
|
||||||
var link = document.createElement("link");
|
var link = document.createElement("link");
|
||||||
link.rel = "icon";
|
link.rel = "icon";
|
||||||
link.href = paymentDetails.merchant_logo;
|
link.href = paymentDetails.merchant_logo;
|
||||||
link.type = "image/x-icon";
|
link.type = "image/x-icon";
|
||||||
document.head.appendChild(link);
|
document.head.appendChild(link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render UI
|
// Render UI
|
||||||
renderPaymentDetails(paymentDetails);
|
|
||||||
renderSDKHeader(paymentDetails);
|
if (paymentDetails.display_sdk_only){
|
||||||
renderCart(paymentDetails);
|
renderSDKHeader(paymentDetails);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
renderPaymentDetails(paymentDetails);
|
||||||
|
renderCart(paymentDetails);
|
||||||
|
renderSDKHeader(paymentDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Deal w loaders
|
// Deal w loaders
|
||||||
show("#sdk-spinner");
|
show("#sdk-spinner");
|
||||||
@ -355,9 +369,11 @@ function initializeEventListeners(paymentDetails) {
|
|||||||
* Trigger - post mounting SDK
|
* Trigger - post mounting SDK
|
||||||
* Use - set relevant classes to elements in the doc for showing SDK
|
* Use - set relevant classes to elements in the doc for showing SDK
|
||||||
**/
|
**/
|
||||||
function showSDK() {
|
function showSDK(display_sdk_only) {
|
||||||
|
if (!display_sdk_only) {
|
||||||
|
show("#hyper-checkout-details");
|
||||||
|
}
|
||||||
show("#hyper-checkout-sdk");
|
show("#hyper-checkout-sdk");
|
||||||
show("#hyper-checkout-details");
|
|
||||||
show("#submit");
|
show("#submit");
|
||||||
show("#unified-checkout");
|
show("#unified-checkout");
|
||||||
hide("#sdk-spinner");
|
hide("#sdk-spinner");
|
||||||
@ -420,7 +436,7 @@ function initializeSDK() {
|
|||||||
};
|
};
|
||||||
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
|
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
|
||||||
mountUnifiedCheckout("#unified-checkout");
|
mountUnifiedCheckout("#unified-checkout");
|
||||||
showSDK();
|
showSDK(paymentDetails.display_sdk_only);
|
||||||
|
|
||||||
let shimmer = document.getElementById("payment-details-shimmer");
|
let shimmer = document.getElementById("payment-details-shimmer");
|
||||||
shimmer.classList.add("reduce-opacity")
|
shimmer.classList.add("reduce-opacity")
|
||||||
|
|||||||
@ -12137,7 +12137,8 @@
|
|||||||
"theme",
|
"theme",
|
||||||
"logo",
|
"logo",
|
||||||
"seller_name",
|
"seller_name",
|
||||||
"sdk_layout"
|
"sdk_layout",
|
||||||
|
"display_sdk_only"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"theme": {
|
"theme": {
|
||||||
@ -12155,6 +12156,10 @@
|
|||||||
"sdk_layout": {
|
"sdk_layout": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Custom layout for sdk"
|
"description": "Custom layout for sdk"
|
||||||
|
},
|
||||||
|
"display_sdk_only": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Display only the sdk for payment link"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -12188,6 +12193,13 @@
|
|||||||
"example": "accordion",
|
"example": "accordion",
|
||||||
"nullable": true,
|
"nullable": true,
|
||||||
"maxLength": 255
|
"maxLength": 255
|
||||||
|
},
|
||||||
|
"display_sdk_only": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Display only the sdk for payment link",
|
||||||
|
"default": false,
|
||||||
|
"example": true,
|
||||||
|
"nullable": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user