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

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

Merged
merged 4 commits into from
Aug 12, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -617,29 +617,37 @@ function renderDynamicMerchantDetails(paymentDetails) {
}

function appendMerchantDetails(paymentDetails, merchantDynamicDetails) {
if (Object.keys(paymentDetails.transaction_details).length === 0) {
if (!(typeof paymentDetails.transaction_details === "string" && paymentDetails.transaction_details.length > 0)) {
return;
}

// render a horizontal line above dynamic merchant details
let horizontalLineContainer = document.getElementById("hyper-checkout-payment-horizontal-line-container");
let horizontalLine = document.createElement("hr");
horizontalLine.className = "hyper-checkout-payment-horizontal-line";
horizontalLineContainer.append(horizontalLine);
try {
let merchantDetailsObject = JSON.parse(paymentDetails.transaction_details);

// max number of items to show in the merchant details
let maxItemsInDetails = 5;
let merchantDetailsObject = JSON.parse(paymentDetails.transaction_details);
for(const key in merchantDetailsObject) {
var merchantData = document.createElement("div");
merchantData.className = "hyper-checkout-payment-merchant-dynamic-data";
merchantData.innerHTML = key+": "+merchantDetailsObject[key].bold();
if (Object.keys(merchantDetailsObject).length > 0) {
// render a horizontal line above dynamic merchant details
var horizontalLineContainer = document.getElementById("hyper-checkout-payment-horizontal-line-container");
var horizontalLine = document.createElement("hr");
horizontalLine.className = "hyper-checkout-payment-horizontal-line";
horizontalLineContainer.append(horizontalLine);

merchantDynamicDetails.append(merchantData);
if(--maxItemsInDetails === 0) {
break;
// max number of items to show in the merchant details
let maxItemsInDetails = 5;
for (var key in merchantDetailsObject) {
var merchantData = document.createElement("div");
merchantData.className = "hyper-checkout-payment-merchant-dynamic-data";
merchantData.innerHTML = key+": "+merchantDetailsObject[key].bold();

merchantDynamicDetails.append(merchantData);
if (--maxItemsInDetails === 0) {
break;
}
}
}
}
catch (error) {
console.error("Error parsing merchant details", error);
}
}

/**
Expand Down
Loading