Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
refactor(payment_link): add Miscellaneous charges in cart (#3645)
Sahkal Poddar15b367eb7924
diff --git a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.htmlindex be4369be1d..35fd540b30 100644--- a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html+++ b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.html@@ -29,10 +29,32 @@<image href="https://live.hyperswitch.io/payment-link-assets/icons/powered-by-hyperswitch.svg" opacity="0.4"/></symbol><symbol id="arrow-down">- <image href="https://live.hyperswitch.io/payment-link-assets/icons/arrow-down.svg"/>+ <svg+ width="16"+ height="16"+ viewBox="0 0 16 16"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M8.20573 11.0351C8.33593 11.0351 8.45573 10.9831 8.54948 10.8841L12.5911 6.75911C12.6797 6.66536 12.7266 6.55078 12.7266 6.41536C12.7266 6.14974 12.5234 5.94141 12.2526 5.94141C12.1224 5.94141 12.0026 5.99349 11.9141 6.07682L8.20573 9.86848L4.4974 6.07682C4.40887 5.99349 4.29429 5.94141 4.15882 5.94141C3.88798 5.94141 3.68486 6.14974 3.68486 6.41536C3.68486 6.55078 3.7318 6.66536 3.82549 6.75911L7.86198 10.8841C7.96094 10.9831 8.07551 11.0351 8.20573 11.0351Z"+ fill="#333333"+ ></path>+ </svg></symbol><symbol id="arrow-up">- <image href="https://live.hyperswitch.io/payment-link-assets/icons/arrow-up.svg"/>+ <svg+ width="16"+ height="16"+ viewBox="0 0 16 16"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ d="M7.79427 4.96485C7.66407 4.96485 7.54427 5.01694 7.45052 5.11587L3.40886 9.24089C3.32032 9.33464 3.27344 9.44922 3.27344 9.58464C3.27344 9.85026 3.47657 10.0586 3.7474 10.0586C3.87761 10.0586 3.9974 10.0065 4.08594 9.92318L7.79427 6.13152L11.5026 9.92318C11.5911 10.0065 11.7057 10.0586 11.8412 10.0586C12.112 10.0586 12.3151 9.85026 12.3151 9.58464C12.3151 9.44922 12.2682 9.33464 12.1745 9.24089L8.13802 5.11587C8.03906 5.01694 7.92449 4.96485 7.79427 4.96485Z"+ fill="#333333"+ ></path>+ </svg></symbol></defs></svg>diff --git a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.jsindex 068247bad8..2831e77100 100644--- a/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js+++ b/crates/router/src/core/payment_link/payment_link_initiate/payment_link.js@@ -1,4 +1,4 @@-// @ts-check+// @ts-nocheck/*** UTIL FUNCTIONS@@ -162,6 +162,7 @@ function invert(color, bw) {* UTIL FUNCTIONS END HERE*/+// @ts-ignore{{ payment_details_js_script }}// @ts-ignore@@ -190,6 +191,21 @@ var hyper = null;function boot() {// @ts-ignorevar paymentDetails = window.__PAYMENT_DETAILS;+ 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+ });+ }if (paymentDetails.merchant_name) {document.title = "Payment requested by " + paymentDetails.merchant_name;@@ -283,6 +299,7 @@ function initializeEventListeners(paymentDetails) {}}+ // @ts-ignorewindow.addEventListener("resize", function (event) {var currentHeight = window.innerHeight;var currentWidth = window.innerWidth;@@ -420,6 +437,7 @@ function mountUnifiedCheckout(id) {* - Handle errors and redirect to status page* @param {Event} e*/+// @ts-ignorefunction handleSubmit(e) {// @ts-ignorevar paymentDetails = window.__PAYMENT_DETAILS;@@ -526,6 +544,7 @@ function formatDate(date) {var hours = date.getHours();var minutes = date.getMinutes();+ // @ts-ignoreminutes = minutes < 10 ? "0" + minutes : minutes;var suffix = hours > 11 ? "PM" : "AM";hours = hours % 12;@@ -651,6 +670,7 @@ function renderCart(paymentDetails) {item,paymentDetails,index !== 0 && index < MAX_ITEMS_VISIBLE_AFTER_COLLAPSE,+ // @ts-ignorecartItemsNode);});@@ -714,7 +734,7 @@ function renderCartItem(item,paymentDetails,shouldAddDividerNode,- cartItemsNode+ cartItemsNode,) {// Wrappersvar itemWrapperNode = document.createElement("div");@@ -730,20 +750,29 @@ function renderCartItem(productNameNode.className = "hyper-checkout-card-item-name";productNameNode.innerText = item.product_name;// Product quantity- var quantityNode = document.createElement("div");- quantityNode.className = "hyper-checkout-card-item-quantity";- quantityNode.innerText = "Qty: " + item.quantity;+ if (item.quantity !== null) {+ var quantityNode = document.createElement("div");+ quantityNode.className = "hyper-checkout-card-item-quantity";+ quantityNode.innerText = "Qty: " + item.quantity;+ }// Product pricevar priceNode = document.createElement("div");priceNode.className = "hyper-checkout-card-item-price";priceNode.innerText = paymentDetails.currency + " " + item.amount;// Append items- nameAndQuantityWrapperNode.append(productNameNode, quantityNode);++ nameAndQuantityWrapperNode.append(productNameNode);+ if (item.quantity !== null) {+ // @ts-ignore+ nameAndQuantityWrapperNode.append(quantityNode);+ }+itemWrapperNode.append(productImageNode,nameAndQuantityWrapperNode,priceNode);+if (shouldAddDividerNode) {var dividerNode = document.createElement("div");dividerNode.className = "hyper-checkout-cart-item-divider";@@ -792,13 +821,16 @@ function handleCartView(paymentDetails) {);});}- if (cartItemsNode instanceof HTMLDivElement) {+ if (cartItemsNode instanceof HTMLDivElement){cartItemsNode.style.maxHeight = cartItemsNode.scrollHeight + "px";+cartItemsNode.style.height = cartItemsNode.scrollHeight + "px";}- if (cartButtonTextNode instanceof HTMLButtonElement) {++ if (cartButtonTextNode instanceof HTMLSpanElement) {cartButtonTextNode.innerText = "Show Less";}+var arrowUpImage = document.getElementById("arrow-up");if (cartButtonImageNode instanceof Object &&@@ -833,7 +865,7 @@ function handleCartView(paymentDetails) {setTimeout(function () {var hiddenItemsCount =orderDetails.length - MAX_ITEMS_VISIBLE_AFTER_COLLAPSE;- if (cartButtonTextNode instanceof HTMLButtonElement) {+ if (cartButtonTextNode instanceof HTMLSpanElement) {cartButtonTextNode.innerText = "Show More (" + hiddenItemsCount + ")";}var arrowDownImage = document.getElementById("arrow-down");