使用 PayPal Express Checkout 进行多次授权

Multiple authorizations with PayPal Express Checkout

我的结帐流程需要多次授权和捕获,如 https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECRelatedAPIOps/#authorization-payment-action-for-express-checkout

中所述

我需要进行单独的身份验证和捕获,因为订单包含多个可能会单独发货的项目。

首先,我通过 Authorization 的操作调用 SetExpressCheckout

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

我收到带有令牌的响应;

TOKEN=EC-2EP3671xxxxxxxx&
TIMESTAMP=xxxxxxx&
CORRELATIONID=xxxxxxx&
ACK=Success&
VERSION=204&
BUILD=xxxxxxx

接下来我将用户重定向到 paypal 以登录并同意。当他们 return 时,我会打电话创建一个计费协议,因为我将在晚些时候进行参考交易。这工作正常。接下来我进行第一次身份验证调用;

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

我得到了成功的回复;

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

到目前为止一切都很好。但我现在需要进行第二次授权;

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

..但 PayPal 似乎认为它是第一个身份验证的副本,而不是执行身份验证;

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

交易id和金额与第一次授权时的响应相同。我如何在 PayPal 不认为它们是重复的情况下进行多次授权?我对流程的理解不正确吗?如果是这样, 需要什么流程?

您不能使用同一个令牌多次调用 DoExpressCheckoutPayment。您必须使用 SetExpressCheckout 重新启动整个流程才能获得新令牌。

不过,听起来您真正想要的是 "Order"。不使用授权的付款操作,而是使用订单。使用 PayPal 完成 "order" 后,您可以 运行 使用 DoAuthorization 和 DoCapture 对其进行多次身份验证和捕获。

有关详细信息,请参阅 How to Create and Process an Order Using Express Checkout 的 PayPal 文档。

您对结算协议所做的操作将用于参考交易。如果用户通过了您已通过计费协议设置的授权,则您可以随时 运行 DoReferenceTransaction 处理您需要的任何金额,而无需进一步批准。这通常用于 "autoship" 系统或 "one-click checkout" 类型的系统,其中保存了此人的账单信息,这样他们就不必在每次向您订购时再次输入。如果需要,您也可以使用此方法构建一个循环支付系统。

根据您所说的,您似乎不需要结算协议。您只需要执行快速结账订单。