amzn / amazon-payments-magento-2-plugin

Extension to enable Amazon Pay on Magento 2
https://amzn.github.io/amazon-payments-magento-2-plugin/
Apache License 2.0
106 stars 76 forks source link

Region data with translated region not loaded with express checkout #1226

Open dimitriBouteille opened 9 months ago

dimitriBouteille commented 9 months ago

Hi,

I am setting up Amazon Pay on a Japanese store. When I load the information via the graphQl checkoutSessionDetails query, I see that when the region is translated, the region information is not returned.

Here is a result of the query checkoutSessionDetails:

{
    "data": {
        "amazonPayCheckoutSessionDetailsV2": {
            "payment": "Visa ****1111 (Amazon Pay)",
            "shipping": {
                "city": "目黒区下目黒",
                "firstname": "テスト姓名二",
                "lastname": " ",
                "street": [
                    "1-8-1"
                ],
                "company": "",
                "telephone": "0312345678",
                "region": "Tokyo",
                "region_id": 621,
                "region_code": "13",
                "email": "XXX",
                "postcode": "1530064",
                "country_id": "JP"
            },
            "billing": {
                "city": "サンプル",
                "firstname": "東京太郎",
                "lastname": " ",
                "street": [
                    "目黒区下目黒1-8-1 テスト住所2"
                ],
                "company": "",
                "telephone": "0312345678",
                "region": "東京都",
                "region_id": null,
                "region_code": null,
                "email": "XXX",
                "postcode": "153-0064",
                "country_id": "JP"
            }
        }
    }
}

For the delivery address no problem, because Tokyo is the default translation. For the billing address, the region 東 京 都 exits well but this is the translated version of Tokyo.

Default translation in directory_country_region table :

Capture d’écran du 2023-11-06 17-41-31

These are the addresses configured in Amazon :

Capture d’écran du 2023-11-06 17-54-52

What happened instead

Region information is not loaded and an error occurs when saving the billing address (regionIdは必須項目です。)

Steps to reproduce the issue

:warning: To reproduce the bug, you must import the translations for the JP store in table directory_country_region_name : region_names.csv

Normally the billing address has no region_id / region_code.

Your setup

Fix proposal

This function should be improved \Amazon\Pay\Helper\Address::getRegionData() :

sgabhart22 commented 8 months ago

Hi @dimitriBouteille ,

Does your store have any Japanese language packs or similar extensions installed, or simply the CSV data you provided in the directory_country_region_name table? I think your proposed solution seems very sound, but I would like to test it out locally and make sure there are no other areas where the prefecture/region translation should be addressed.

Thanks, Spencer