fix(payment_link): remove dynamic section if no fields are present (#5579)

This commit is contained in:
Sakil Mostak
2024-08-12 18:18:47 +05:30
committed by GitHub
parent 74fcc910e9
commit 78d9906ebb

View File

@ -617,20 +617,23 @@ function renderDynamicMerchantDetails(paymentDetails) {
} }
function appendMerchantDetails(paymentDetails, merchantDynamicDetails) { function appendMerchantDetails(paymentDetails, merchantDynamicDetails) {
if (Object.keys(paymentDetails.transaction_details).length === 0) { if (!(typeof paymentDetails.transaction_details === "string" && paymentDetails.transaction_details.length > 0)) {
return; return;
} }
try {
let merchantDetailsObject = JSON.parse(paymentDetails.transaction_details);
if (Object.keys(merchantDetailsObject).length > 0) {
// render a horizontal line above dynamic merchant details // render a horizontal line above dynamic merchant details
let horizontalLineContainer = document.getElementById("hyper-checkout-payment-horizontal-line-container"); var horizontalLineContainer = document.getElementById("hyper-checkout-payment-horizontal-line-container");
let horizontalLine = document.createElement("hr"); var horizontalLine = document.createElement("hr");
horizontalLine.className = "hyper-checkout-payment-horizontal-line"; horizontalLine.className = "hyper-checkout-payment-horizontal-line";
horizontalLineContainer.append(horizontalLine); horizontalLineContainer.append(horizontalLine);
// max number of items to show in the merchant details // max number of items to show in the merchant details
let maxItemsInDetails = 5; let maxItemsInDetails = 5;
let merchantDetailsObject = JSON.parse(paymentDetails.transaction_details); for (var key in merchantDetailsObject) {
for(const key in merchantDetailsObject) {
var merchantData = document.createElement("div"); var merchantData = document.createElement("div");
merchantData.className = "hyper-checkout-payment-merchant-dynamic-data"; merchantData.className = "hyper-checkout-payment-merchant-dynamic-data";
merchantData.innerHTML = key+": "+merchantDetailsObject[key].bold(); merchantData.innerHTML = key+": "+merchantDetailsObject[key].bold();
@ -641,6 +644,11 @@ function appendMerchantDetails(paymentDetails, merchantDynamicDetails) {
} }
} }
} }
}
catch (error) {
console.error("Error parsing merchant details", error);
}
}
/** /**
* Trigger - on boot * Trigger - on boot