phpamazon-pay

Amazon Pay allow only specific country for shipping


I'd like to implement amazon pay. The button works fine, but I would like to restric every country EXCEPT e.g. germany

Here is my code snippet. I tried several addressRestriction formats:

$client = new Client($amazonPayConfig);
$amazonPayPayload['storeId'] = $amazonPayStoreId;
$amazonPayPayload['webCheckoutDetails']['checkoutReviewReturnUrl'] = $checkoutReviewReturnUrl;
$amazonPayPayload['deliverySpecifications']['addressRestrictions']['type'] = 'Allowed';
$amazonPayPayload['deliverySpecifications']['addressRestrictions']['restrictions'][] = ['DE'];
$amazonPayPayloadJson = json_encode($amazonPayPayload);
$amazonPaySignature = $client->generateButtonSignature($amazonPayPayloadJson);

I receive the error Error Code: InvalidRequestFormat Error Message: Invalid request format, check fields are in correct format. when clicking on the button. If I remove the lines:

$amazonPayPayload['deliverySpecifications']['addressRestrictions']['type'] = 'Allowed';
$amazonPayPayload['deliverySpecifications']['addressRestrictions']['restrictions'][] = ['DE'];

It works...

Any hints?


Solution

  • The address restrictions have a format that is a little different from what one would expect. You might want to try this:

    $amazonPayPayload['deliverySpecifications']['addressRestrictions']['restrictions'] = ['DE'=>new \stdClass()];
    

    The country is not the array value but the array key.