javascriptphpamazon-pay

Integration of Amazon Payments with Javascript and PHP - PaymentPlanNotSet


Currently I try to integrate amazon payment. I want to display the button, created with the function:

OffAmazonPayments.Button("AmazonPayButton", myAmznMerchantID

and after the User has logged in, I want to display the AdressBook Widget and the Payment Widget on the same Page. The Button and the Widgets are displayed correctly, but when I try to confirm the Payment, I'm getting the Error-Constrains Message:

PaymentPlanNotSet The buyer has not been able to select a Payment method for the given Order Reference.

But the Payment was selected.

I hope you can help me, to find my failure in this Javascript code:

window.onAmazonLoginReady = function () {
    amazon.Login.setClientId(myAmznClientID);
};
window.onAmazonPaymentsReady = function() {
    var __accessToken       = 0;
    var __orderReferenceId  = 0;

    show_amazon_Button();

    function show_amazon_Button() {
        OffAmazonPayments.Button("AmazonPayButton", ibuiAmazonPaymentsInfos.ibAmznMerchantID, {
            type: "PwA",
            color: "Gold",
            size: "small", // "medium",
            language: "de-DE",
            authorization: function () {
                loginOptions = { scope: "profile:user_id", popup: true };
                authRequest = amazon.Login.authorize(loginOptions, function(response) {
                    if (response.error) {
                        //show Error
                        return;
                    } else {
                        __accessToken = response.access_token;
                        show_Adress_Widget();
                    }
                });
            },
            onError: function(error) {
                //handleError
            }
        }); 
    }

    function show_Adress_Widget() {
        new OffAmazonPayments.Widgets.AddressBook({
            sellerId: ibuiAmazonPaymentsInfos.ibAmznMerchantID,
            onOrderReferenceCreate: function (orderReference) {
                __orderReferenceId = orderReference.getAmazonOrderReferenceId();
                //do Stuff
            },
            onAddressSelect: function (orderReference) { 
                show_Amazon_Wallet();
            },
            design: {
                designMode: 'responsive'
            },
            onError: function (error) {
                //handle Error
            }
        }).bind("readOnlyAddressBookWidgetDiv");                
    }

    function show_Amazon_Wallet() {
        new OffAmazonPayments.Widgets.Wallet({
            sellerId: myAmznMerchantID,
            onOrderReferenceCreate: function(orderReference) {
                //do Stuff
            },
            design: {
                designMode: 'responsive'
            },
            onPaymentSelect: function(orderReference) {
                //activate buy button
            },
            onError: function(error) {
                //handle error
            }
        }).bind('AmazonWalletWidgetDiv');               
    }
} //onAmazonPaymentsReady

In PHP I create the OrderReference over:

$params = array(
    'order_reference_id' => $orderReferenceId,
    'amount'            => $amount,
    'seller_order_id'   => $buchungsKopf->getBuchung_nr(),
);
$responseObject = $client->setOrderReferenceDetails($params);

And even if I had selected a payment method before, I'm getting the "PaymentPlanNotSet" in the responseObject. Same error, when I try to confirm the orderReference

$responseObject2    = $client->confirmOrderReference($params);

Before I had integrate the AdressWidget, I was able to do the payment. Can you see what I'm doing wrong?


Solution

  • It seems I have found my failure. When I want to display both Widgets (Adress and Wallet) on the same page, then I can not use the onOrderReferenceCreate-Method in the OffAmazonPayments.Widget.Wallet. It seems like then it create a new order reference wich is not the same as the orderreference created by the AdressBook Widget.

    Now I have delete this part of the Wallet Widget and everything seems to work fine.