Adyen / adyen-magento2-express-checkout

Adyen Magento 2 Express Checkout Module
MIT License
8 stars 2 forks source link

use consistent country code from config model in callback payment req… #1

Closed josh-carter closed 1 year ago

josh-carter commented 1 year ago

Summary

Fixes unexpected developer error when the customers' address is from a different country to the configured "Default Country" for the store. When Google Pay is initialised we have to provide the countryCode as part of GooglePays "PaymentRequest", countryCode is optional but required for EAA countries. We use the stores' Default Country, but in our onPaymentDataChanged callback function we resolve it by returning a new updated "PaymentRequest: object like below:

...
{
    newShippingOptionParameters: {
        defaultSelectedOptionId: ...,
        shippingOptions: [{...}]
    },
    newTransactionInfo: {
        displayItems: [
            {
                label: 'Shipping',
                type: 'LINE_ITEM',
                price: xx,
                status: 'FINAL'
            }
        ],
            currencyCode: ...,
            totalPriceStatus: 'FINAL',
            totalPrice: xx,
            totalPriceLabel: 'Total',
            countryCode: ...
    }
...

The countryCode in the newTransactionInfo object here was being set from the customers shipping address rather than the stores countryCode, and hence we were getting the error reported around the initial paymentRequest having a different countryCode to the callback paymentRequest object. I've updated this callback country code so that it uses the same countryCode used when initialising (from the configModel)

The countryCode should be (taken from Google Pays docs):

The ISO 3166-1 alpha-2 country code where the transaction is processed. This property is required for merchants who process transactions in European Economic Area (EEA) countries and any other countries that are subject to Strong Customer Authentication (SCA). Merchants must specify the acquirer bank country code.

So I'd say it makes sense to use the stores' country for the countryCode and this update making it consistent fixes the error reported because we use a consistent countryCode in the PaymentRequest throughout the Google Pay flow.

Tested scenarios

Fixed issue: Unexpected Developer Error when using GooglePay as a Customer with a different shipping address country than the stores' configured "Default Country"