0

I'm integrating amazon-pay-SDK-python for the web.

I have done reading all documentation of amazon-pay, but I didn't get any idea about how to give or create a button signature in Frontend/backend code. Here is my code of frontend to create a button of amazon-pay One-time-checkout.

If anyone implemented this, give your valuable answer..

<body>
      <div id="AmazonPayButton"></div>
      <script src="https://static-na.payments-amazon.com/checkout.js"></script>
      <script type="text/javascript" charset="utf-8">
          amazon.Pay.renderButton('#AmazonPayButton', {
              // set checkout environment
              merchantId: 'merchant_id',
              publicKeyId: 'SANDBOX-xxxxxxxxxx',
              ledgerCurrency: 'USD',         
              // customize the buyer experience
              checkoutLanguage: 'en_US',
              productType: 'PayAndShip',
              placement: 'Cart',
              buttonColor: 'Gold',
              // configure Create Checkout Session request
              createCheckoutSessionConfig: {                     
                  payloadJSON: 'payload', // string generated in step 2
                  signature: 'xxxx' // signature generated in step 3
              }   
          });
      </script>
  </body>
  • I guess, the best way for is to adapt the code from a language, that has an SDK offered, e.g. the PHP SDK: https://github.com/amzn/amazon-pay-api-sdk-php/blob/560909f87fbd18b9d07ed02735cebc36128f3c7c/Amazon/Pay/API/Client.php#L392 – marcus.kreusch Dec 16 '21 at 14:39

1 Answers1

0

Based on your button configuration, I can see you are using the Amazon Pay checkout V2 experience (recommended), however the python SDK you reference is for the V1 experience and is not compatible with V2. There is not yet a Python SDK for V2, however there is an example here for how to generate the signature:

https://github.com/amazonpay-labs/amazonpay-sample-python-v2

I'd also recommend leveraging the developer scratchpad tool for Checkout V2: https://pay-api.amazon.com/tools/scratchpad/index.html

You can combine the sample python code above with these instructions on how to create the checkout session payload: https://developer.amazon.com/docs/amazon-pay-checkout/add-the-amazon-pay-button.html#2-generate-the-create-checkout-session-payload

  • After implementing. I am getting this error: Something went wrong Signature validation failed. Please reach out to the merchant. When contacting Amazon Pay customer service, provide the following information: Session ID: 132-2375683-9726907 Error Code: InvalidSignatureError Error Message: Signature iwFuumlFjzybeDYSToxxxx does not match signedString AMZN-PAY-RSASSA-PSS c201f728eaa1d4dbc48d3d31daxxxx for merchant A2S6OA5xxxxx – Shubham Agrawal Dec 22 '21 at 10:54
  • I am using this canonical_uri = '/sandbox/v2/checkoutSessions' – Shubham Agrawal Dec 22 '21 at 11:02
  • Have you tried walking through configuring the same request in the developer scratchpad tool linked above? It will break down the full canonical request based on parameters configured as well as show the resulting string to sign. This should help narrow down where your code is incorrect in the signature generation steps. – Debbie Martindale Dec 23 '21 at 17:31