cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple payments with AcceptJS called async

Hi

 

I have an app that has products from multiple vendors.  Each vendor can setup their own payment gateway ( Authorize or Paypal).

 

When a user checkouts, they may have products in their cart from multiple vendors.  The cart displays how their payment will be split and so sets user expectation.

 

I have a JS controller which loops through the cart and requests payment according to the vendor's gateway.

 

It's quite possible therefore that I would need to get a token using AcceptJS for more than 1 checkout occurence.

 

I have isolated my code similar to in your demo for each vendor by using namespace objects each with a unique name

 

eg: 

var ANAJSManagerVV2G = new function() {
         //     ^^^^ randomized unique code
            this.orderId = '';
            this.submitted=false;
                    
            this.makePayment = function(orderId) {
              // this contains the code as in your demo....
             // and i works fine where there is only 1 item in the cart
            }
this.responseHandler = function(response) {
console.log(response.messages);
if (response.messages.resultCode === "Error") {
for (var i = 0; i < response.messages.message.length; i++) {
console.log(response.messages.message[i].code + ": " + response.messages.message[i].text);
}
alert("acceptJS library error!")
} else {
console.log(response.opaqueData.dataDescriptor);
console.log(response.opaqueData.dataValue);
ANAJSManagerVV2G.processTransaction(response.opaqueData);
// ^^^ callback using namespace
} }

note that the namespace object has a 4char randomized ending AND the callback uses the namespace identifier.

 

The namespace object contains an order-id which identifies the relevant line item, so that on the callback, I can then process the appropriate transaction in my backend.

 

When I look at my network tab in chrome, I see 2 calls to request.api as expected, each call uses the credentials of the appropriate vendor.  However, I get the same token string back for both, plus it looks like ONLY the second namespace callback is being called.

 

Perhaps I should use a deferred object to call in a loop syncronously (or jQuery queue) rather than calling async.

 

How does this look your end?  Are you overlaying the two calls into one, perhaps as they come from the same IP address?

 

It works fine when there is only one item in the cart, so my logic is OK.

 

 Thanks

Chris

sudwebdesign77
Contributor
1 ACCEPTED SOLUTION

Accepted Solutions

Hi

 

I noticed that I was passing this.responseHandler rather than namespace-name.responseHandler to Accept.dispatchData

 

Changed and works perfectly!

View solution in original post

sudwebdesign77
Contributor
1 REPLY 1

Hi

 

I noticed that I was passing this.responseHandler rather than namespace-name.responseHandler to Accept.dispatchData

 

Changed and works perfectly!

sudwebdesign77
Contributor