在Laravel中处理两个第三方API时如何处理异常

问题描述

我正在使用Laravel构建Saas应用程序,对此事我感到担心。

我正在集成Namecheap域购买API和Paypal付款网关API。

我的逻辑就是这样

-Show Available Domains:
-Customer picks one:
-Customer pays with paypal (redirect to paypal page):
-If payment is success,I will call domain register API.
-If success,then I will show success message.

上面是完美的案例,表明一切正常。

但这是我的担忧。

...
-Customer pays with paypal (redirect to paypal page):
-Payment was success,I will call domain register API.
-Domain register API is not success: (maybe i need to refund?)

其他选项:

-Customer pays with paypal (redirect to paypal page):
-Before do actual payment on my side,I will call domain register API.
-If domain register AIP is success,I will do actual payment process.

在这种情况下,如果实际付款过程失败,那么客户将能够免费获得域名。

有人可以给我一些解决这些问题的建议吗?

谢谢

解决方法

我确定您正在预先检查可用性,但是在注册域之前,您应该始终处理付款。如果注册失败,您可以立即退款或选择其他域名或任何可行的方式。

对于付款批准,最佳的贝宝批准流程为:https://developer.paypal.com/demo/checkout/#/pattern/server

这会在您的服务器上调用两条路由,一条用于“设置交易”,一条用于“捕获交易”,记录在这里:https://developer.paypal.com/docs/checkout/reference/server-integration/

  • 如果在服务器上成功捕获,则将在该位置进行 注册域并成功响应。如果注册 失败,那是您可以退款或提供其他选择的地方。

  • 如果捕获未成功,则将在其中传播 失败消息应得到适当处理。