简体   繁体   English

PayPal REST API订单工作流程:付款 - >销售 - > Webhook?

[英]PayPal REST API order workflow: Payment -> Sale -> Webhook?

I am trying to integrate the PayPal REST API into my Symfony 2 web app but I find hard to understand how exactly the complete workflow looks like: 我正在尝试将PayPal REST API集成到我的Symfony 2 Web应用程序中,但我发现很难理解完整的工作流程到底是什么样的:

The PayPal docs describe the following steps to accept a payment. PayPal文档描述了接受付款的以下步骤。 One can use the PayPal Playground to simulate these steps: 可以使用PayPal Playground来模拟这些步骤:

  1. Get an access token 获取访问令牌
  2. Create a Payment object by querying the API 通过查询API 创建 Payment对象
  3. Redirect the user to the approval url received in the Payment response 将用户重定向到Payment响应中收到的approval url
  4. After the user approved the payment on the PayPal page, he is redirected back to my page, using the success-link defined in the Payment object. 用户在PayPal页面上批准付款后,使用Payment对象中定义的success-link将其重定向回我的页面。 Use the received information to execute the payment. 使用收到的信息执行付款。
  5. Payment is completed with status approved 付款已完成,状态approved

From the docs: Once a payment is complete, it is referred to as a sale . 从文档: 付款完成后,它被称为销售 You can then look up the sale and refund it. 然后,您可以查找销售并退款。

So far so good. 到现在为止还挺好。 BUT: Where are Webhooks used/fired in this workflow? 但是:在这个工作流程中,Webhooks在哪里使用/解雇? I have defined a wildcard Webhook (accepting all possible events) in the PayPal Developer Dashboard. 我在PayPal开发人员仪表板中定义了一个通配符Webhook(接受所有可能的事件)。

My observation is, that my system receives the Webhook event 1-2 Minutes (!) after the user was redirected back to the success-link and after the payment was executed (Step 4) . 我的观察是,我的系统接收网络挂接事件1-2分钟(!)用户被重定向到成功链接, 并执行付款后(步骤4) 之后

Beside this long delay between executing the payment and receiving the Webhook, this workflow means, that I only receive the Webhook AFTER handling the success-link. 除了执行付款和接收Webhook之间的这个长时间延迟之外,这个工作流程意味着我只接收处理成功链接的Webhook。 This means, handling the success-link is absolutly necessary for the payment to be completed. 这意味着,处理成功链接绝对是完成付款所必需的。 Is this correct? 它是否正确?

Do I need to use Webhooks? 我需要使用Webhooks吗?

I already asked this question a few days before and the answer by nifr is quite reasonable: One cannot trust the user to follow any redirect URL but should only rely on the Webhook events. 我已经在几天前问过这个问题了,nifr的答案是非常合理的:人们不能相信用户遵循任何重定向URL,但应该只依赖于Webhook事件。

However this collides with the observations I described before, since I will never receive the Webhook without handling the redirect URL... 然而,这与我之前描述的观察结果相冲突,因为如果不处理重定向URL,我将永远不会收到Webhook ...

So, handling the PAYMENT.SALE.COMPLETED webhook event does not make a lot of sense, since this should already be done in when handling the redirect URL. 因此,处理PAYMENT.SALE.COMPLETED webhook事件没有多大意义,因为这应该在处理重定向URL时完成。 Correct? 正确?

However, to handle updates on pending payments, handle refunds or reversed payments, etc. are only possible by listening on those events. 但是,要处理待处理付款的更新,只能通过收听这些事件来处理退款或撤销付款等。

So the answer is: Only use Webhooks to get updates on payments made before. 所以答案是:只使用Webhooks获取之前付款的更新。 Correct? 正确?

So, the main questions are: 所以,主要问题是:

  1. The 5-step process to accept payments does not say anything about using Webhooks. 接受付款的5个步骤没有说明使用Webhooks。 This does not seem to make a lot of sense, because without Webhooks one would miss update events, etc.? 这似乎没有多大意义,因为没有Webhooks会错过更新事件等等? So, is it really possible to implement the complete payment workflow without Webhooks? 那么,没有Webhooks真的可以实现完整的支付工作流程吗?
  2. If yes, how are updates (refunds, pending, etc) handled in this case? 如果是, 在这种情况下如何处理更新(退款,待处理等)?
  3. If no, what is the right strategy/time to fulfill the order since it take quite a long time to completly receive and handle the webhook? 如果不是, 那么完成订单的正确策略/时间是什么, 因为完全接收和处理webhook需要相当长的时间?

i am still a newbie in PayPal world, but few days ago i integrated PayPal Plus REST API in an online Shop, and from my understanding i can tell that the workflow looks like: 我仍然是PayPal世界的新手,但几天前我在一个在线商店中集成了PayPal Plus REST API,根据我的理解,我可以看出工作流程如下:

  1. create a Payment 创建付款
  2. redirect to PayPal 重定向到PayPal
  3. Payer could pay using PayPal account OR (using Bank Direct debit or Credit Card Payment without PayPal Account) 付款人可以使用PayPal账户支付使用银行直接付款或没有PayPal账户的信用卡付款
  4. After completing the process on PayPal side, PayPal redirect the user back to your success URL. 在PayPal端完成此过程后,PayPal会将用户重定向回您的成功URL。
  5. till now the user is still not charged(you got no money). 到目前为止,用户仍然没有收费(你没有钱)。 At the moment where you (in your success URL) do $payment->execute($paymentExecution,$api); 在您(在您的成功URL中)执行$payment->execute($paymentExecution,$api);的那一刻$payment->execute($paymentExecution,$api); , you ask Paypal to charge the amount from user. ,您要求Paypal向用户收取金额。 BUT also after this, you got no Money. 但在此之后,你没有钱。 Paypal have first to process the charging and notify you later via WebhookEvents. Paypal首先处理收费并稍后通过WebhookEvents通知您。

the Webhook Notification (with that nasty delay) is especially important when the user pays per direct debit or Credit Card etc. Processing such Payments takes few seconds/minutes. 当用户按每笔直接付款或信用卡等付款时,Webhook通知(带有令人讨厌的延迟)尤其重要。处理此类付款需要几秒钟/分钟。

the redirectUrl ist absolutly necessary for charging/executing the Payment. redirectUrl绝对是收费/执行付款所必需的。 here on execution succeed, just to tell the user, that he finished his Job, and you can here save/capture the PaymentID/Transaction id for later usage/update via WebhookEvent Listener. 这里执行成功,只是告诉用户,他完成了他的Job,你可以在这里保存/捕获PaymentID / Transaction id,以便以后使用/更新通过WebhookEvent Listener。

so i would recommend you to update your Database(Payment completed) only after receiving notofications via WebhookEvent Listener and not in the success RedirectUrl. 所以我建议你只有在通过WebhookEvent Listener接收到通知后才更新你的数据库(付款已完成),而不是成功的Red​​irectUrl。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM