Search code examples
javascriptamazon-pay

Amazon Payments: Successful auth, fails on wallet display


I'm trying to integrate Amazon Payments (Payment only, not login with Amazon) into my site.

I can successfully display the authentication form for the payment:

<div id="AmazonPayButton" />
          @{
              var callbackurl = string.Format("{0}://{1}/Account/AmazonConfirm", Request.Url.Scheme, Request.Url.Authority);
           }
           <script type="text/javascript">
               OffAmazonPayments.Button("AmazonPayButton", "M_MYSELLERID_1234567", {
                   type: "PwA",
                   size: "medium",
                   authorization: function() {
                      loginOptions =
                           {scope: "payments:widget", popup: true };
                      authRequest = amazon.Login.authorize(loginOptions, "@(callbackurl)");
                   },
                   onError: function(error) {
                        alert('We could not connect to Amazon to process your payment, try again later');
                   }
              });
      </script>
</div>

Amazon successful redirects to my callback URL after authentication. But when I try to display the wallet widget with the Same Seller ID, I get an "invalid seller ID" error:

<div id="walletWidgetDiv">
    </div>
    <script>
        new OffAmazonPayments.Widgets.Wallet({
            sellerId: 'M_MYSELLERID_1234567',
            onReady: function(billingAgreement) {
                var billingAgreementId = billingAgreement.getAmazonBillingAgreementId();
            },
            agreementType: 'BillingAgreement',
            design: {
                size : {width:'400px', height:'260px'}
            },
            onPaymentSelect: function(billingAgreement) {
                // Replace this code with the action that you want to perform
                // after the payment method is selected.
            },
            onError: function(error) {
                alert(error.getErrorMessage());
            }
      }).bind("walletWidgetDiv");
    </script>

enter image description here

Why would the authentication work, only to have the Wallet display rejected?

Update @Brent Douglas in his answer triggered me to recheck my seller ID and I had specified an incorrect ID in one of my script references. Now I get the following error:

"the seller ID is not in the appropriate state to execute the request"

Not sure what that means. I checked my account and the deposit/banking info is specified, and nothing else is flagged on the Integration Settings page. Is there anything else in the account that needs to be added/verified? (Other than the typical, web page URL and other info)


Solution

  • You need to log in to your Seller Central account, make sure "Amazon Payments Advanced" is selected in the drop-down at the top, click "Settings" in the upper right, then "Integration Settings". On this page you will see "Your Merchant ID". This is your Seller ID. Replace M_MYSELLERID_1234567 with this seller ID everywhere.

    Assuming you are using the correct seller ID you also need to make sure you are including the following in your handle login page where you display the wallet widget.

    <!-- since you are using 'popup' -->
    <script type='text/javascript'>
        window.onAmazonLoginReady = function () {
            amazon.Login.setClientId('[YOUR_CLIENT_ID]');
            amazon.Login.setUseCookie(true);
        };
    </script>
    

    You then need to include the Widgets.js file.

    For sandbox mode you would use this.

    <script src='https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js'></script>
    

    For production you would use this.

    <script src='https://static-na.payments-amazon.com/OffAmazonPayments/us/js/Widgets.js'></script>