From 790887b41d4f34924cf2a327a1d7e867152d12b1 Mon Sep 17 00:00:00 2001 From: khushboos Date: Thu, 2 Jan 2025 16:40:29 +0100 Subject: [PATCH 1/2] Introducing correct formatting of decimal points based on the currency --- .../web/js/actions/updatePaypalOrder.js | 14 ++- view/frontend/web/js/applepay/button.js | 104 ++++++++++-------- view/frontend/web/js/paypal_express/button.js | 14 ++- 3 files changed, 78 insertions(+), 54 deletions(-) diff --git a/view/frontend/web/js/actions/updatePaypalOrder.js b/view/frontend/web/js/actions/updatePaypalOrder.js index 6d59ac8..8ea4b86 100755 --- a/view/frontend/web/js/actions/updatePaypalOrder.js +++ b/view/frontend/web/js/actions/updatePaypalOrder.js @@ -4,12 +4,14 @@ define([ 'Adyen_ExpressCheckout/js/helpers/getIsLoggedIn', 'Adyen_ExpressCheckout/js/model/maskedId', 'Adyen_ExpressCheckout/js/helpers/getMaskedIdFromCart', + 'Adyen_Payment/js/helper/currencyHelper' ], function ( storage, urlBuilder, getIsLoggedIn, maskedIdModel, - getMaskedIdFromCart + getMaskedIdFromCart, + currencyHelper ) { 'use strict'; @@ -36,7 +38,10 @@ define([ type: 'Shipping', amount: { currency: currency, - value: Math.round(selectedShippingMethod.amount.value * 100) + value: currencyHelper.formatAmount( + Math.round(selectedShippingMethod.amount.value), + currency + ) }, selected: true }; @@ -51,7 +56,10 @@ define([ type: 'Shipping', amount: { currency: currency, - value: Math.round(shippingMethods[i].amount * 100) + value: currencyHelper.formatAmount( + Math.round(shippingMethods[i].amount), + currency + ) }, selected: i === 0 }; diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index ce49183..6ece20c 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -1,37 +1,38 @@ define([ - 'uiComponent', - 'mage/translate', - 'Magento_Customer/js/customer-data', - 'Adyen_Payment/js/model/adyen-configuration', - 'Adyen_Payment/js/adyen', - 'Adyen_ExpressCheckout/js/actions/activateCart', - 'Adyen_ExpressCheckout/js/actions/cancelCart', - 'Adyen_ExpressCheckout/js/actions/createPayment', - 'Adyen_ExpressCheckout/js/actions/getShippingMethods', - 'Adyen_ExpressCheckout/js/actions/getExpressMethods', - 'Adyen_ExpressCheckout/js/actions/setShippingInformation', - 'Adyen_ExpressCheckout/js/actions/setBillingAddress', - 'Adyen_ExpressCheckout/js/actions/setTotalsInfo', - 'Adyen_ExpressCheckout/js/helpers/formatAmount', - 'Adyen_ExpressCheckout/js/helpers/getApplePayStyles', - 'Adyen_ExpressCheckout/js/helpers/getCartSubtotal', - 'Adyen_ExpressCheckout/js/helpers/getExtensionAttributes', - 'Adyen_ExpressCheckout/js/helpers/getPaymentMethod', - 'Adyen_ExpressCheckout/js/helpers/getPdpForm', - 'Adyen_ExpressCheckout/js/helpers/getPdpPriceBox', - 'Adyen_ExpressCheckout/js/helpers/getSupportedNetworks', - 'Adyen_ExpressCheckout/js/helpers/isConfigSet', - 'Adyen_ExpressCheckout/js/helpers/getRegionId', - 'Adyen_ExpressCheckout/js/helpers/redirectToSuccess', - 'Adyen_ExpressCheckout/js/helpers/setExpressMethods', - 'Adyen_ExpressCheckout/js/helpers/validatePdpForm', - 'Adyen_ExpressCheckout/js/model/config', - 'Adyen_ExpressCheckout/js/model/countries', - 'Adyen_ExpressCheckout/js/model/totals', - 'Adyen_ExpressCheckout/js/model/currency', - 'Adyen_ExpressCheckout/js/helpers/getCurrentPage', - 'Adyen_ExpressCheckout/js/model/virtualQuote' -], + 'uiComponent', + 'mage/translate', + 'Magento_Customer/js/customer-data', + 'Adyen_Payment/js/model/adyen-configuration', + 'Adyen_Payment/js/adyen', + 'Adyen_ExpressCheckout/js/actions/activateCart', + 'Adyen_ExpressCheckout/js/actions/cancelCart', + 'Adyen_ExpressCheckout/js/actions/createPayment', + 'Adyen_ExpressCheckout/js/actions/getShippingMethods', + 'Adyen_ExpressCheckout/js/actions/getExpressMethods', + 'Adyen_ExpressCheckout/js/actions/setShippingInformation', + 'Adyen_ExpressCheckout/js/actions/setBillingAddress', + 'Adyen_ExpressCheckout/js/actions/setTotalsInfo', + 'Adyen_ExpressCheckout/js/helpers/formatAmount', + 'Adyen_ExpressCheckout/js/helpers/getApplePayStyles', + 'Adyen_ExpressCheckout/js/helpers/getCartSubtotal', + 'Adyen_ExpressCheckout/js/helpers/getExtensionAttributes', + 'Adyen_ExpressCheckout/js/helpers/getPaymentMethod', + 'Adyen_ExpressCheckout/js/helpers/getPdpForm', + 'Adyen_ExpressCheckout/js/helpers/getPdpPriceBox', + 'Adyen_ExpressCheckout/js/helpers/getSupportedNetworks', + 'Adyen_ExpressCheckout/js/helpers/isConfigSet', + 'Adyen_ExpressCheckout/js/helpers/getRegionId', + 'Adyen_ExpressCheckout/js/helpers/redirectToSuccess', + 'Adyen_ExpressCheckout/js/helpers/setExpressMethods', + 'Adyen_ExpressCheckout/js/helpers/validatePdpForm', + 'Adyen_ExpressCheckout/js/model/config', + 'Adyen_ExpressCheckout/js/model/countries', + 'Adyen_ExpressCheckout/js/model/totals', + 'Adyen_ExpressCheckout/js/model/currency', + 'Adyen_ExpressCheckout/js/helpers/getCurrentPage', + 'Adyen_ExpressCheckout/js/model/virtualQuote', + 'Adyen_Payment/js/helper/currencyHelper' + ], function ( Component, $t, @@ -64,7 +65,8 @@ define([ totalsModel, currencyModel, getCurrentPage, - virtualQuoteModel + virtualQuoteModel, + currencyHelper ) { 'use strict'; @@ -265,8 +267,14 @@ define([ }, amount: { value: this.isProductView - ? formatAmount(totalsModel().getTotal() * 100) - : formatAmount(getCartSubtotal() * 100), + ? currencyHelper.formatAmount( + totalsModel().getTotal(), + currency + ) + : currencyHelper.formatAmount( + getCartSubtotal(), + currency + ), currency: currency }, isExpress: true, @@ -295,16 +303,16 @@ define([ // Get the address. let address = event.shippingContact, - // Create a payload. + // Create a payload. payload = { - address: { - city: address.locality, - region: address.administrativeArea, - country_id: address.countryCode.toUpperCase(), - postcode: address.postalCode, - save_in_address_book: 0 - } - }; + address: { + city: address.locality, + region: address.administrativeArea, + country_id: address.countryCode.toUpperCase(), + postcode: address.postalCode, + save_in_address_book: 0 + } + }; self.shippingAddress = payload.address; @@ -406,9 +414,9 @@ define([ .done((response) => { self.afterSetTotalsInfo(response, shippingMethod, self.isProductView, resolve); }).fail((e) => { - console.error('Adyen ApplePay: Unable to get totals', e); - reject($t('We\'re unable to fetch the cart totals for you. Please try an alternative payment method.')); - }); + console.error('Adyen ApplePay: Unable to get totals', e); + reject($t('We\'re unable to fetch the cart totals for you. Please try an alternative payment method.')); + }); }); }, diff --git a/view/frontend/web/js/paypal_express/button.js b/view/frontend/web/js/paypal_express/button.js index cbff53c..acac067 100755 --- a/view/frontend/web/js/paypal_express/button.js +++ b/view/frontend/web/js/paypal_express/button.js @@ -38,6 +38,7 @@ define([ 'Adyen_ExpressCheckout/js/model/maskedId', 'Adyen_ExpressCheckout/js/helpers/getCurrentPage', 'Adyen_ExpressCheckout/js/helpers/getMaskedIdFromCart', + 'Adyen_Payment/js/helper/currencyHelper' ], function ( Component, $t, @@ -77,7 +78,8 @@ define([ virtualQuoteModel, maskedIdModel, getCurrentPage, - getMaskedIdFromCart + getMaskedIdFromCart, + currencyHelper ) { 'use strict'; @@ -300,8 +302,14 @@ define([ amount: { currency: currency, value: this.isProductView - ? formatAmount(totalsModel().getTotal() * 100) - : formatAmount(getCartSubtotal() * 100) + ? currencyHelper.formatAmount( + totalsModel().getTotal(), + currency + ) + : currencyHelper.formatAmount( + getCartSubtotal(), + currency + ) }, onSubmit: (state, component) => { const paymentData = state.data; From fa6d87f28cf0918708c53486f65484e5ef0f8c47 Mon Sep 17 00:00:00 2001 From: khushboos Date: Thu, 2 Jan 2025 16:47:26 +0100 Subject: [PATCH 2/2] Formatting --- view/frontend/web/js/applepay/button.js | 66 ++++++++++++------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index 6ece20c..2a5625b 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -1,37 +1,37 @@ define([ - 'uiComponent', - 'mage/translate', - 'Magento_Customer/js/customer-data', - 'Adyen_Payment/js/model/adyen-configuration', - 'Adyen_Payment/js/adyen', - 'Adyen_ExpressCheckout/js/actions/activateCart', - 'Adyen_ExpressCheckout/js/actions/cancelCart', - 'Adyen_ExpressCheckout/js/actions/createPayment', - 'Adyen_ExpressCheckout/js/actions/getShippingMethods', - 'Adyen_ExpressCheckout/js/actions/getExpressMethods', - 'Adyen_ExpressCheckout/js/actions/setShippingInformation', - 'Adyen_ExpressCheckout/js/actions/setBillingAddress', - 'Adyen_ExpressCheckout/js/actions/setTotalsInfo', - 'Adyen_ExpressCheckout/js/helpers/formatAmount', - 'Adyen_ExpressCheckout/js/helpers/getApplePayStyles', - 'Adyen_ExpressCheckout/js/helpers/getCartSubtotal', - 'Adyen_ExpressCheckout/js/helpers/getExtensionAttributes', - 'Adyen_ExpressCheckout/js/helpers/getPaymentMethod', - 'Adyen_ExpressCheckout/js/helpers/getPdpForm', - 'Adyen_ExpressCheckout/js/helpers/getPdpPriceBox', - 'Adyen_ExpressCheckout/js/helpers/getSupportedNetworks', - 'Adyen_ExpressCheckout/js/helpers/isConfigSet', - 'Adyen_ExpressCheckout/js/helpers/getRegionId', - 'Adyen_ExpressCheckout/js/helpers/redirectToSuccess', - 'Adyen_ExpressCheckout/js/helpers/setExpressMethods', - 'Adyen_ExpressCheckout/js/helpers/validatePdpForm', - 'Adyen_ExpressCheckout/js/model/config', - 'Adyen_ExpressCheckout/js/model/countries', - 'Adyen_ExpressCheckout/js/model/totals', - 'Adyen_ExpressCheckout/js/model/currency', - 'Adyen_ExpressCheckout/js/helpers/getCurrentPage', - 'Adyen_ExpressCheckout/js/model/virtualQuote', - 'Adyen_Payment/js/helper/currencyHelper' + 'uiComponent', + 'mage/translate', + 'Magento_Customer/js/customer-data', + 'Adyen_Payment/js/model/adyen-configuration', + 'Adyen_Payment/js/adyen', + 'Adyen_ExpressCheckout/js/actions/activateCart', + 'Adyen_ExpressCheckout/js/actions/cancelCart', + 'Adyen_ExpressCheckout/js/actions/createPayment', + 'Adyen_ExpressCheckout/js/actions/getShippingMethods', + 'Adyen_ExpressCheckout/js/actions/getExpressMethods', + 'Adyen_ExpressCheckout/js/actions/setShippingInformation', + 'Adyen_ExpressCheckout/js/actions/setBillingAddress', + 'Adyen_ExpressCheckout/js/actions/setTotalsInfo', + 'Adyen_ExpressCheckout/js/helpers/formatAmount', + 'Adyen_ExpressCheckout/js/helpers/getApplePayStyles', + 'Adyen_ExpressCheckout/js/helpers/getCartSubtotal', + 'Adyen_ExpressCheckout/js/helpers/getExtensionAttributes', + 'Adyen_ExpressCheckout/js/helpers/getPaymentMethod', + 'Adyen_ExpressCheckout/js/helpers/getPdpForm', + 'Adyen_ExpressCheckout/js/helpers/getPdpPriceBox', + 'Adyen_ExpressCheckout/js/helpers/getSupportedNetworks', + 'Adyen_ExpressCheckout/js/helpers/isConfigSet', + 'Adyen_ExpressCheckout/js/helpers/getRegionId', + 'Adyen_ExpressCheckout/js/helpers/redirectToSuccess', + 'Adyen_ExpressCheckout/js/helpers/setExpressMethods', + 'Adyen_ExpressCheckout/js/helpers/validatePdpForm', + 'Adyen_ExpressCheckout/js/model/config', + 'Adyen_ExpressCheckout/js/model/countries', + 'Adyen_ExpressCheckout/js/model/totals', + 'Adyen_ExpressCheckout/js/model/currency', + 'Adyen_ExpressCheckout/js/helpers/getCurrentPage', + 'Adyen_ExpressCheckout/js/model/virtualQuote', + 'Adyen_Payment/js/helper/currencyHelper' ], function ( Component,