Amazon Pay Payload Signature generation

405 Views Asked by At

When using the examples from amazon pay integration- where does the generate payload signature php go and how does the value it returns get to the js code in the body?

I know this sounds ridiculous but I haven't done any coding in a very very long time.

When I run in browser the console just says "payload is not in correct JSON format" I am only guessing that this has something to do with the signature.


`<?php include 'vendor/autoload.php';

    $amazonpay_config = array(
        'public_key_id' => 'MY_PUBLIC_KEY_ID',
        'private_key'   => 'keys/private.pem',
        'region'        => 'US',
        'sandbox'       => true
    );

    $client = new Amazon\Pay\API\Client($amazonpay_config);
    $payload = '{"storeId":"amzn1.application-oa2-client.xxxxx","webCheckoutDetails":{"checkoutReviewReturnUrl":"https://example.com/review.html"}}';
    $signature = $client->generateButtonSignature($payload);
    echo $signature . "\n";
?>


   

 <div id="AmazonPayButton"></div>
      <script src="https://static-na.payments-amazon.com/checkout.js"></script>
      <script type="text/javascript" charset="utf-8">
          const amazonPayButton = amazon.Pay.renderButton('#AmazonPayButton', {
              // set checkout environment
              merchantId: 'ABCDEFGHIJK',
              publicKeyId: 'SANDBOX-ABCDEFGHIJKLMNOP',
              ledgerCurrency: 'USD',         
              // customize the buyer experience
              checkoutLanguage: 'en_US',
              productType: 'PayOnly',
              placement: 'Cart',
              buttonColor: 'Gold',
              estimatedOrderAmount: { "amount": "109.99", "currencyCode": "USD"},
              // configure Create Checkout Session request
              createCheckoutSessionConfig: {                     
                  payloadJSON: 'payload', // string generated in step 2
                  signature: 'xxxx' // signature generated in step 3
              }   
          });
      </script>

` 
1

There are 1 best solutions below

0
Michal On

You're getting this message in console because you didn't pass payload and signature to createCheckoutSessionConfig. This is mandatory and even emphasized in comment ;)