My checkout flow requires multiple authorisations and captures, as described at https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECRelatedAPIOps/#authorization-payment-action-for-express-checkout
I need to make separate auths and captures because the order contains multiple items that may be shipped separately.
First I make a call to SetExpressCheckout
with an action of Authorization
.
cancelUrl=xxxxxxx&
PAYMENTREQUEST_0_PAYMENTACTION=Authorization&
PAYMENTREQUEST_0_CURRENCYCODE=USD&
L_BILLINGAGREEMENTDESCRIPTION0=ClubUsage&
VERSION=204&
PAYMENTREQUEST_0_AMT=30.00&
L_BILLINGTYPE0=MerchantInitiatedBilling&
METHOD=SetExpressCheckout&
USER=xxxxxxx&
PWD=xxxxxxx&
returnUrl=xxxxxxx&
SIGNATURE=xxxxxxx
I get a response with a token;
TOKEN=EC-2EP3671xxxxxxxx&
TIMESTAMP=xxxxxxx&
CORRELATIONID=xxxxxxx&
ACK=Success&
VERSION=204&
BUILD=xxxxxxx
Next I redirect the user to paypal to sign in and agree. When they return I make a call to create a billing agreement as I will be doing reference transactions at a later date. This works OK. Next I make my first auth call;
PAYMENTREQUEST_0_PAYMENTACTION=Authorization&
PAYMENTREQUEST_0_PAYMENTREQUESTID=200001&
PAYERID=xxxxxxx&
VERSION=204&
PAYMENTREQUEST_0_AMT=25.00&
METHOD=DoExpressCheckoutPayment&
USER=xxxxxxx&
PWD=xxxxxxx&
SIGNATURE=xxxxxxx&
TOKEN=EC-2EP3671xxxxxxx
and I get a successful response;
TOKEN=EC-2EP3671xxxxxxx&
SUCCESSPAGEREDIRECTREQUESTED=false&
TIMESTAMP=xxxxxxx&
CORRELATIONID=xxxxxxx&
ACK=Success&
VERSION=204&
BUILD=26126731&
INSURANCEOPTIONSELECTED=false&
SHIPPINGOPTIONISDEFAULT=false&
PAYMENTINFO_0_TRANSACTIONID=0J23486xxxxxxx&
PAYMENTINFO_0_TRANSACTIONTYPE=expresscheckout&
PAYMENTINFO_0_PAYMENTTYPE=instant&
PAYMENTINFO_0_ORDERTIME=xxxxxxx&
PAYMENTINFO_0_AMT=25.00&
PAYMENTINFO_0_TAXAMT=0.00&
PAYMENTINFO_0_CURRENCYCODE=USD&
PAYMENTINFO_0_PAYMENTSTATUS=Pending&
PAYMENTINFO_0_PENDINGREASON=authorization&
PAYMENTINFO_0_REASONCODE=None&
PAYMENTINFO_0_PROTECTIONELIGIBILITY=Eligible&
PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE=ItemNotReceivedEligible,UnauthorizedPaymentEligible&
PAYMENTINFO_0_SELLERPAYPALACCOUNTID=xxxxxxx&
PAYMENTINFO_0_SECUREMERCHANTACCOUNTID=xxxxxxx&
PAYMENTINFO_0_PAYMENTREQUESTID=200001&
PAYMENTINFO_0_ERRORCODE=0&
PAYMENTINFO_0_ACK=Success
All is good so far. But I need to make my second auth now;
PAYMENTREQUEST_0_PAYMENTACTION=Authorization&
PAYMENTREQUEST_0_PAYMENTREQUESTID=200002&
PAYERID=xxxxxxx&
VERSION=204&
PAYMENTREQUEST_0_AMT=5.00&
METHOD=DoExpressCheckoutPayment&
USER=xxxxxxx&
PWD=xxxxxxx&
SIGNATURE=xxxxxxx&
TOKEN=EC-2EP3671xxxxxxx
..but instead of performing the auth, PayPal seems to think its a duplicate of the first auth;
TOKEN=EC-2EP3671xxxxxxx&
SUCCESSPAGEREDIRECTREQUESTED=false&
TIMESTAMP=xxxxxxx&
CORRELATIONID=xxxxxxx&
ACK=SuccessWithWarning&
VERSION=204&
BUILD=26126731&
L_ERRORCODE0=11607&
L_SHORTMESSAGE0=Duplicate Request&
L_LONGMESSAGE0=A successful transaction has already been completed for this token.&
L_SEVERITYCODE0=Warning&
INSURANCEOPTIONSELECTED=false&
SHIPPINGOPTIONISDEFAULT=false&
PAYMENTINFO_0_TRANSACTIONID=0J23486xxxxxxx&
PAYMENTINFO_0_TRANSACTIONTYPE=expresscheckout&
PAYMENTINFO_0_PAYMENTTYPE=instant&
PAYMENTINFO_0_ORDERTIME=xxxxxxx&
PAYMENTINFO_0_AMT=25.00&
PAYMENTINFO_0_TAXAMT=0.00&
PAYMENTINFO_0_CURRENCYCODE=USD&
PAYMENTINFO_0_PAYMENTSTATUS=Pending&
PAYMENTINFO_0_PENDINGREASON=authorization&
PAYMENTINFO_0_REASONCODE=None&
PAYMENTINFO_0_PROTECTIONELIGIBILITY=Eligible&
PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE=ItemNotReceivedEligible,UnauthorizedPaymentEligible&
PAYMENTINFO_0_SELLERPAYPALACCOUNTID=xxxxxxx&
PAYMENTINFO_0_SECUREMERCHANTACCOUNTID=xxxxxxx&
PAYMENTINFO_0_PAYMENTREQUESTID=200001&
PAYMENTINFO_0_ERRORCODE=0&
PAYMENTINFO_0_ACK=Success
The transaction id and amount are the same as those in the response to the first auth. How do I make multiple authorizations without PayPal thinking they're the same one repeated? Is my understanding of the flow incorrect? If so what is the necessary flow?
You can't make multiple calls to DoExpressCheckoutPayment with the same token. You have to start the whole flow again with SetExpressCheckout to get a new token.
Really, though, it sounds like what you're after is an "Order". Instead of using a payment action of Authorization, use Order. When an "order" is completed with PayPal, you can then run multiple auths and captures against that using DoAuthorization and DoCapture.
See PayPal's doc for How to Create and Process an Order Using Express Checkout for more details.
What you're doing with the billing agreement would be for reference transactions. If the user goes through the Authorization you've got setup with a billing agreement, you could then run DoReferenceTransaction at any time to process any amount you need for that person without further approval. This is typically used for things like an "autoship" system or a "one-click checkout" type of system where the person's billing info is saved so they don't have to enter it again every time they order from you. You could also build a recurring payments system with this method if you need to.
Based on what you've said it doesn't sound like you need the billing agreement. You just need to do the Express Checkout Order.