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. One can use the PayPal Playground to simulate these steps:
贝宝文档描述了以下接受支付的步骤。可以使用PayPal游乐场来模拟这些步骤:
- Get an access token
- 得到一个访问令牌
-
Create a
Payment
object by querying the API - 通过查询API创建支付对象
- Redirect the user to the
approval url
received in thePayment
response - 将用户重定向到付款响应中收到的批准url
- 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. Use the received information to execute the payment. - 用户在PayPal页面上批准付款后,将使用付款对象中定义的success-link重定向回我的页面。使用接收到的信息执行支付。
- Payment is completed with status
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? I have defined a wildcard Webhook (accepting all possible events) in the PayPal Developer Dashboard.
目前为止一切都很顺利。但是:在这个工作流中,Webhooks在哪里使用?我在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).
我的观察是,我的系统在用户被重定向回success-link并在支付执行之后(步骤4),收到Webhook事件1-2分钟(!)。
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. This means, handling the success-link is absolutly necessary for the payment to be completed. Is this correct?
除了执行支付和接收Webhook之间的长时间延迟之外,这个工作流意味着,我只在处理成功链接之后才接收Webhook。这意味着,处理成功链接对于完成支付是绝对必要的。这是正确的吗?
Do I need to use Webhooks?
我需要使用webhook吗?
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...
然而,这与我之前描述的观察结果相冲突,因为我将永远不会接收Webhook而不处理重定向URL…
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. Correct?
因此,处理PAYMENT.SALE。完成的webhook事件没有多大意义,因为在处理重定向URL时应该已经这样做了。正确吗?
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. Correct?
所以答案是:只使用webhook来获取以前支付的更新。正确吗?
So, the main questions are:
所以,主要的问题是:
- The 5-step process to accept payments does not say anything about using Webhooks. This does not seem to make a lot of sense, because without Webhooks one would miss update events, etc.? So, is it really possible to implement the complete payment workflow without Webhooks?
- 接受支付的5个步骤过程并没有说明使用webhook。这似乎没有多大意义,因为没有webhook,就会错过更新事件,等等。那么,真的有可能实现没有webhook的完整支付工作流吗?
- If yes, how are updates (refunds, pending, etc) handled in this case?
- 如果是,在这种情况下如何处理更新(退款、等待等)?
- 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需要相当长的时间?
1 个解决方案
#1
1
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:
我还是贝宝世界的新手,但是几天前我在网上商店整合了贝宝+ REST API,根据我的理解,我可以看到工作流程如下:
- create a Payment
- 创建一个付款
- redirect to PayPal
- 重定向到贝宝
- Payer could pay using PayPal account OR (using Bank Direct debit or Credit Card Payment without PayPal Account)
- 支付人可使用贝宝账户或(使用银行直接借记卡或无贝宝账户的信用卡支付)
- After completing the process on PayPal side, PayPal redirect the user back to your success URL.
- 在完成贝宝方面的过程后,贝宝将用户重定向回您的成功URL。
- 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);
, you ask Paypal to charge the amount from user. BUT also after this, you got no Money. Paypal have first to process the charging and notify you later via WebhookEvents. - 直到现在,用户仍然没有被指控(你没有钱)。此时,您(在您的成功URL中)执行$payment->执行($paymentExecution,$api);,你要求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. 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.
对于收取/执行付款,redirecl是绝对必要的。这里的执行成功,只是告诉用户,他完成了他的工作,您可以在这里保存/捕获PaymentID/事务id,以便以后通过WebhookEvent监听器进行使用/更新。
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接收到notoations之后,而不是在success RedirectUrl中更新您的数据库(支付完成)。
#1
1
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:
我还是贝宝世界的新手,但是几天前我在网上商店整合了贝宝+ REST API,根据我的理解,我可以看到工作流程如下:
- create a Payment
- 创建一个付款
- redirect to PayPal
- 重定向到贝宝
- Payer could pay using PayPal account OR (using Bank Direct debit or Credit Card Payment without PayPal Account)
- 支付人可使用贝宝账户或(使用银行直接借记卡或无贝宝账户的信用卡支付)
- After completing the process on PayPal side, PayPal redirect the user back to your success URL.
- 在完成贝宝方面的过程后,贝宝将用户重定向回您的成功URL。
- 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);
, you ask Paypal to charge the amount from user. BUT also after this, you got no Money. Paypal have first to process the charging and notify you later via WebhookEvents. - 直到现在,用户仍然没有被指控(你没有钱)。此时,您(在您的成功URL中)执行$payment->执行($paymentExecution,$api);,你要求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. 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.
对于收取/执行付款,redirecl是绝对必要的。这里的执行成功,只是告诉用户,他完成了他的工作,您可以在这里保存/捕获PaymentID/事务id,以便以后通过WebhookEvent监听器进行使用/更新。
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接收到notoations之后,而不是在success RedirectUrl中更新您的数据库(支付完成)。