您如何知道用户是否已支付订阅费用 [英] How do you know if a user has paid for a subscription

查看:99
本文介绍了您如何知道用户是否已支付订阅费用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看这个教程来创建我自己的贝宝订阅网关我以前从未对 API 如此困惑和迷失.

因此,当我们创建计划时,我们会设置商家偏好,特别是返回 URL

$merchantPreferences->setReturnUrl(mysite.com/subscription?success=true")

然后在教程结束时,当用户为服务付费后,它会将用户重定向到 mysite.com/subscription?success=true.

然后是获取最重要的东西的代码,即来自返回 URL $token = $_GET['token']; 的令牌,它允许我们使用 获取协议 ID$agreement->execute($token, $apiContext);.我的问题是,用户支付订阅费用然后关闭他们的选项卡并且没有被重定向的可能性很大.那时,即使他们已经支付了订阅费用,我的系统还没有识别出他们的付款并在我这边激活了他们的订阅.

我在这里错了,误解了 Paypal API 中发生的事情,还是 Paypal 系统有缺陷?

解决方案

该教程使用已弃用的 SDK,该 SDK 仅适用于先前版本的 PayPal Subscriptions.不要遵循该教程中的任何内容,这是不好的.


对于当前版本的 PayPal 订阅,此处描述的按钮将激活订阅在客户端.

您可以改为设置您的按钮并使用 REST API 调用来从您的服务器批准后立即.从服务器激活可为您提供可靠的服务器端通知,表明订阅已启动.这些调用没有 SDK,您必须首先通过 HTTPS 获取 API 访问令牌并自己执行调用.

但是,要收到订阅实际付款的通知(通常从第二天开始并在其周期重复),您需要一个用于事件 PAYMENT.SALE.COMPLETED.没有支持 webhooks 的 SDK,因此您必须设置自己的监听代码,并对自己收到的 webhooks 消息执行任何所需的验证(验证可以通过检查签名或 API 回调到 PayPal 来完成)

如果您需要在订阅开始的那一刻(而不是第二天)收到付款,请在常规计费周期开始之前使用 setup_fee 和一个周期的试用期对其进行配置.

I am looking at this tutorial to create my own paypal subscription gateway and I have never been so confused and lost about an API before.

So when we create the plan we set merchant preferences, specifically the return URL

$merchantPreferences->setReturnUrl("mysite.com/subscription?success=true")

Then at the end of the tutorial, when a user has paid for the service it redirects the user to mysite.com/subscription?success=true.

Then there is code which grabs the MOST important thing, the token from the return URL $token = $_GET['token']; which allows us to get the agreement ID using $agreement->execute($token, $apiContext);. My question is, there is a huge possibility that the user pays for the subscription and then closes their tab and doesn't get redirected. At that point, my system hasn't recognized their payment and activated their subscription on my end even though they paid for their subscription already.

Am I wrong here and misunderstanding whats happening in the Paypal API or is the paypal system flawed?

解决方案

That tutorial uses a deprecated SDK that only works with the previous version of PayPal Subscriptions. Do not follow anything in that tutorial, it is no good.


For the current version of PayPal Subscriptions, the button described there will activate the subscription on the client side.

You can instead set up your button and use a REST API call to activate a subscription from your server immediately after approval. Activating from the server gives you a reliable server-side notification that a subscription is started. There is no SDK for these calls, you must first get the API access token and perform the call yourself, via HTTPS.

However, to be notified of actual payments for the subscription -- which typically start the following day and repeat on its cycle -- you need a webhook listener for the event PAYMENT.SALE.COMPLETED. There is no supported SDK for webhooks, so you must set up your own listening code and also perform any desired verification of webhooks messages received yourself (verification can be done by checking the signature, or an API call back to PayPal)

If you need to receive a payment the moment a subscription starts (instead of the following day), configure it with a setup_fee and a one cycle trial period before the regular billing cycle begins.

这篇关于您如何知道用户是否已支付订阅费用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆