<%= ob.polyT('purchase.receipt.summary') %> <% const viewingCurrency = ob.currencyMod.getCurrencyValidity(ob.displayCurrency) === 'VALID' ? ob.displayCurrency : ob.listingCurrency; ob.prices.forEach((priceObj, i) => { // convert the prices here, to prevent rounding errors in the display let basePrice; if (!ob.isCrypto) { basePrice = ob.currencyMod.convertCurrency(priceObj.price, ob.listingCurrency, viewingCurrency); } else { basePrice = ob.currencyMod.convertCurrency(priceObj.price, ob.listingCurrency, viewingCurrency); } const shippingPrice = ob.currencyMod.convertCurrency(priceObj.sPrice, ob.listingCurrency, viewingCurrency); const additionalShippingPrice = ob.currencyMod.convertCurrency(priceObj.aPrice, ob.listingCurrency, viewingCurrency); const surcharge = ob.currencyMod.convertCurrency(priceObj.vPrice, ob.listingCurrency, viewingCurrency); let quantity = Number.isInteger(priceObj.quantity) && priceObj.quantity > 0 ? priceObj.quantity : 1; if (ob.isCrypto) { quantity = typeof priceObj.quantity === 'number' && priceObj.quantity > 0 ? priceObj.quantity : 0; } let itemTotal = basePrice + surcharge; const preCouponPrice = itemTotal; ob.coupons.forEach((coupon) => { if (coupon.percentDiscount) { itemTotal -= itemTotal * 0.01 * coupon.percentDiscount; } else if (coupon.priceDiscount) { itemTotal -= ob.currencyMod.convertCurrency(coupon.priceDiscount, ob.listingCurrency, viewingCurrency); } }); const subTotal = itemTotal * quantity; const shippingTotal = shippingPrice + additionalShippingPrice * (quantity -1); const formattedQuantity = new Intl.NumberFormat(ob.displayCurrency, { minimumFractionDigits: 0, maximumFractionDigits: 8, }).format(quantity); %>
<%= ob.polyT('purchase.receipt.listing') %>
<%= ob.currencyMod.formatCurrency(preCouponPrice, viewingCurrency) %>
<% ob.coupons.forEach((coupon) => { %>
<%= ob.polyT('purchase.receipt.coupon') %>
<% if (coupon.percentDiscount) { print(`-${coupon.percentDiscount}%`); } else if (coupon.priceDiscount) { print(`-${ob.currencyMod.convertAndFormatCurrency(Number(coupon.priceDiscount), ob.listingCurrency, viewingCurrency)}`); } %>
<% }); %> <% if (ob.listing.shippingOptions && ob.listing.shippingOptions.length && shippingPrice !== additionalShippingPrice && quantity > 1) { %>
<%= ob.polyT('purchase.receipt.shipping') %>
<%= ob.polyT('purchase.receipt.firstItem') %>
<%= ob.currencyMod.formatCurrency(shippingPrice, viewingCurrency) %>
<%= ob.polyT('purchase.receipt.additionalItems') %>
<%= ob.currencyMod.formatCurrency(additionalShippingPrice, viewingCurrency) %>
<% } else if (ob.listing.shippingOptions && ob.listing.shippingOptions.length) { %>
<%= ob.polyT('purchase.receipt.shipping') %>
<%= ob.currencyMod.formatCurrency(shippingPrice, viewingCurrency) %>
<% } %>
<% if (quantity) { %>
<%= ob.polyT('purchase.receipt.subtotal', { quantity: formattedQuantity }) %>
<%= ob.currencyMod.formatCurrency(subTotal, viewingCurrency) %>
<% if (ob.listing.shippingOptions && ob.listing.shippingOptions.length && shippingTotal) { %>
<%= ob.polyT('purchase.receipt.shippingTotal') %>
<%= ob.currencyMod.formatCurrency(shippingTotal, viewingCurrency) %>
<% } %> <% } %>
<%= ob.polyT('purchase.receipt.total') %>
<%= ob.currencyMod.formatCurrency(subTotal + shippingTotal, viewingCurrency) %>
<% }); %>