Skip to content

Commit 4d99098

Browse files
authored
feat(payment_link): added display_sdk_only option for displaying only sdk without payment details (#4363)
1 parent c9e5cf4 commit 4d99098

File tree

7 files changed

+84
-32
lines changed

7 files changed

+84
-32
lines changed

crates/api_models/src/admin.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,9 @@ pub struct PaymentLinkConfigRequest {
10651065
/// Custom layout for sdk
10661066
#[schema(value_type = Option<String>, max_length = 255, example = "accordion")]
10671067
pub sdk_layout: Option<String>,
1068+
/// Display only the sdk for payment link
1069+
#[schema(default = false, example = true)]
1070+
pub display_sdk_only: Option<bool>,
10681071
}
10691072

10701073
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq, ToSchema)]
@@ -1077,4 +1080,6 @@ pub struct PaymentLinkConfig {
10771080
pub seller_name: String,
10781081
/// Custom layout for sdk
10791082
pub sdk_layout: String,
1083+
/// Display only the sdk for payment link
1084+
pub display_sdk_only: bool,
10801085
}

crates/api_models/src/payments.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,6 +4489,7 @@ pub struct PaymentLinkDetails {
44894489
pub theme: String,
44904490
pub merchant_description: Option<String>,
44914491
pub sdk_layout: String,
4492+
pub display_sdk_only: bool,
44924493
}
44934494

44944495
#[derive(Debug, serde::Serialize)]

crates/common_utils/src/consts.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ pub const DEFAULT_SDK_LAYOUT: &str = "tabs";
6868

6969
/// Payment intent default client secret expiry (in seconds)
7070
pub const DEFAULT_SESSION_EXPIRY: i64 = 15 * 60;
71+
72+
/// Default bool for Display sdk only
73+
pub const DEFAULT_DISPLAY_SDK_ONLY: bool = false;

crates/router/src/core/payment_link.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use api_models::{admin as admin_types, payments::PaymentLinkStatusWrap};
22
use common_utils::{
33
consts::{
4-
DEFAULT_BACKGROUND_COLOR, DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT,
5-
DEFAULT_SESSION_EXPIRY,
4+
DEFAULT_BACKGROUND_COLOR, DEFAULT_DISPLAY_SDK_ONLY, DEFAULT_MERCHANT_LOGO,
5+
DEFAULT_PRODUCT_IMG, DEFAULT_SDK_LAYOUT, DEFAULT_SESSION_EXPIRY,
66
},
77
ext_traits::{OptionExt, ValueExt},
88
};
@@ -86,6 +86,7 @@ pub async fn initiate_payment_link_flow(
8686
logo: DEFAULT_MERCHANT_LOGO.to_string(),
8787
seller_name: merchant_name_from_merchant_account,
8888
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
89+
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
8990
}
9091
};
9192

@@ -213,6 +214,7 @@ pub async fn initiate_payment_link_flow(
213214
theme: payment_link_config.theme.clone(),
214215
merchant_description: payment_intent.description,
215216
sdk_layout: payment_link_config.sdk_layout.clone(),
217+
display_sdk_only: payment_link_config.display_sdk_only,
216218
};
217219

218220
let js_script = get_js_script(&api_models::payments::PaymentLinkData::PaymentLinkDetails(
@@ -440,11 +442,23 @@ pub fn get_payment_link_config_based_on_priority(
440442
})
441443
.unwrap_or(DEFAULT_SDK_LAYOUT.to_owned());
442444

445+
let display_sdk_only = payment_create_link_config
446+
.as_ref()
447+
.and_then(|pc_config| {
448+
pc_config.config.display_sdk_only.or_else(|| {
449+
business_config
450+
.as_ref()
451+
.and_then(|business_config| business_config.display_sdk_only)
452+
})
453+
})
454+
.unwrap_or(DEFAULT_DISPLAY_SDK_ONLY);
455+
443456
let payment_link_config = admin_types::PaymentLinkConfig {
444457
theme,
445458
logo,
446459
seller_name,
447460
sdk_layout,
461+
display_sdk_only,
448462
};
449463

450464
Ok((payment_link_config, domain_name))
@@ -521,6 +535,7 @@ pub async fn get_payment_link_status(
521535
logo: DEFAULT_MERCHANT_LOGO.to_string(),
522536
seller_name: merchant_name_from_merchant_account,
523537
sdk_layout: DEFAULT_SDK_LAYOUT.to_owned(),
538+
display_sdk_only: DEFAULT_DISPLAY_SDK_ONLY,
524539
}
525540
};
526541

crates/router/src/core/payment_link/payment_link_initiate/payment_link.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
</div>
194194
<div id="hyper-checkout-status-redirect-message"></div>
195195
</div>
196-
<div class="main" id="hyper-checkout-details">
196+
<div class="main checkout-page" id="hyper-checkout-details">
197197
<div id="hyper-checkout-payment" class="hyper-checkout-payment">
198198
<div class="hyper-checkout-payment-content-details">
199199
<div class="content-details-wrap">

crates/router/src/core/payment_link/payment_link_initiate/payment_link.js

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -194,38 +194,52 @@ function boot() {
194194

195195
// @ts-ignore
196196
var paymentDetails = window.__PAYMENT_DETAILS;
197-
var orderDetails = paymentDetails.order_details;
198-
if (orderDetails!==null) {
199-
var charges = 0;
200197

201-
for (var i = 0; i < orderDetails.length; i++) {
202-
charges += parseFloat(orderDetails[i].amount * orderDetails[i].quantity);
203-
}
204-
orderDetails.push({
205-
"amount": (paymentDetails.amount - charges).toFixed(2),
206-
"product_img_link": "https://live.hyperswitch.io/payment-link-assets/cart_placeholder.png",
207-
"product_name": "Miscellaneous charges\n" +
208-
"(includes taxes, shipping, discounts, offers etc.)",
209-
"quantity": null
210-
});
198+
if (paymentDetails.display_sdk_only) {
199+
hide(".checkout-page")
200+
var sdkDisplayWidth = document.querySelector('.hyper-checkout-sdk');
201+
sdkDisplayWidth.style.width = '100vw';
211202
}
203+
else {
204+
var orderDetails = paymentDetails.order_details;
205+
if (orderDetails!==null) {
206+
var charges = 0;
207+
208+
for (var i = 0; i < orderDetails.length; i++) {
209+
charges += parseFloat(orderDetails[i].amount * orderDetails[i].quantity);
210+
}
211+
orderDetails.push({
212+
"amount": (paymentDetails.amount - charges).toFixed(2),
213+
"product_img_link": "https://live.hyperswitch.io/payment-link-assets/cart_placeholder.png",
214+
"product_name": "Miscellaneous charges\n" +
215+
"(includes taxes, shipping, discounts, offers etc.)",
216+
"quantity": null
217+
});
218+
}
212219

213-
if (paymentDetails.merchant_name) {
214-
document.title = "Payment requested by " + paymentDetails.merchant_name;
220+
if (paymentDetails.merchant_name) {
221+
document.title = "Payment requested by " + paymentDetails.merchant_name;
222+
}
223+
224+
if (paymentDetails.merchant_logo) {
225+
var link = document.createElement("link");
226+
link.rel = "icon";
227+
link.href = paymentDetails.merchant_logo;
228+
link.type = "image/x-icon";
229+
document.head.appendChild(link);
230+
}
215231
}
232+
// Render UI
216233

217-
if (paymentDetails.merchant_logo) {
218-
var link = document.createElement("link");
219-
link.rel = "icon";
220-
link.href = paymentDetails.merchant_logo;
221-
link.type = "image/x-icon";
222-
document.head.appendChild(link);
234+
if (paymentDetails.display_sdk_only){
235+
renderSDKHeader(paymentDetails);
236+
}
237+
else{
238+
renderPaymentDetails(paymentDetails);
239+
renderCart(paymentDetails);
240+
renderSDKHeader(paymentDetails);
223241
}
224242

225-
// Render UI
226-
renderPaymentDetails(paymentDetails);
227-
renderSDKHeader(paymentDetails);
228-
renderCart(paymentDetails);
229243

230244
// Deal w loaders
231245
show("#sdk-spinner");
@@ -355,9 +369,11 @@ function initializeEventListeners(paymentDetails) {
355369
* Trigger - post mounting SDK
356370
* Use - set relevant classes to elements in the doc for showing SDK
357371
**/
358-
function showSDK() {
372+
function showSDK(display_sdk_only) {
373+
if (!display_sdk_only) {
374+
show("#hyper-checkout-details");
375+
}
359376
show("#hyper-checkout-sdk");
360-
show("#hyper-checkout-details");
361377
show("#submit");
362378
show("#unified-checkout");
363379
hide("#sdk-spinner");
@@ -420,7 +436,7 @@ function initializeSDK() {
420436
};
421437
unifiedCheckout = widgets.create("payment", unifiedCheckoutOptions);
422438
mountUnifiedCheckout("#unified-checkout");
423-
showSDK();
439+
showSDK(paymentDetails.display_sdk_only);
424440

425441
let shimmer = document.getElementById("payment-details-shimmer");
426442
shimmer.classList.add("reduce-opacity")

openapi/openapi_spec.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12137,7 +12137,8 @@
1213712137
"theme",
1213812138
"logo",
1213912139
"seller_name",
12140-
"sdk_layout"
12140+
"sdk_layout",
12141+
"display_sdk_only"
1214112142
],
1214212143
"properties": {
1214312144
"theme": {
@@ -12155,6 +12156,10 @@
1215512156
"sdk_layout": {
1215612157
"type": "string",
1215712158
"description": "Custom layout for sdk"
12159+
},
12160+
"display_sdk_only": {
12161+
"type": "boolean",
12162+
"description": "Display only the sdk for payment link"
1215812163
}
1215912164
}
1216012165
},
@@ -12188,6 +12193,13 @@
1218812193
"example": "accordion",
1218912194
"nullable": true,
1219012195
"maxLength": 255
12196+
},
12197+
"display_sdk_only": {
12198+
"type": "boolean",
12199+
"description": "Display only the sdk for payment link",
12200+
"default": false,
12201+
"example": true,
12202+
"nullable": true
1219112203
}
1219212204
}
1219312205
},

0 commit comments

Comments
 (0)