简体   繁体   English

PayPal 订阅 API onApprove

[英]PayPal subscription API onApprove

I'm trying to implement the PayPal Subscription API but I'm not sure about the process flow.我正在尝试实施 PayPal 订阅 API 但我不确定流程。
I use the react-paypal-js package to generate the subscription button.我使用react-paypal-js package 生成订阅按钮。
The way the users are created on my website is only through the Paypal subscription.在我的网站上创建用户的方式仅通过 Paypal 订阅。

The process is as follow:过程如下:

  1. The user choose a plan and click on the subscribe button用户选择一个计划并点击订阅按钮
  2. The PayPal window open and the user follows the subscription process on Paypal PayPal window开通,用户按照Paypal的订阅流程
  3. The user is redirected to my website用户被重定向到我的网站
  4. Using webhooks or with the onApprove callback, I receive the newly created subscription, create a user on my website with the Paypal email address associated with the subscription.使用 webhook 或onApprove回调,我收到新创建的订阅,在我的网站上创建一个用户,地址为 Paypal email 与订阅关联。

It all works.一切正常。 My problem is that I need to check, before accepting the subscription, if I already have a local user with given email and in this case, I don't want to accept the subscription (as I would then have 2 subscriptions for the same user) and display a message saying that their is already an active (or suspended) subscription associated with the given email.我的问题是我需要在接受订阅之前检查我是否已经有给定 email 的本地用户,在这种情况下,我不想接受订阅(因为我会为同一用户提供 2 个订阅) 并显示一条消息,说明他们已经是与给定 email 关联的活动(或暂停)订阅。

As far as I can tell, when the onApprove is called or the webhook is called, the subscription has already been processed and activated.据我所知,当调用onApprove或调用 webhook 时,订阅已经被处理并激活。

Thanks!谢谢!

You don't have to design a system in which the PayPal email used to make the payment, and the email of the user used to log into your site, have a 1:1 relationship.您不必设计一个系统,其中用于付款的 PayPal email 和用于登录您网站的用户的 email 具有 1:1 的关系。 Instead you can have the user log and create their account with you first (as they will always need that to manage something subscription-based) and then you will know there is no subscription associated with that user before displaying the PayPal Subscribe button.相反,您可以先让用户登录并与您一起创建他们的帐户(因为他们总是需要它来管理基于订阅的内容),然后您会知道在显示 PayPal 订阅按钮之前没有与该用户关联的订阅。 Then they can pay with any PayPal account (might be the same email, might be different)然后他们可以使用任何 PayPal 帐户付款(可能是相同的 email,可能不同)


As far as I can tell, when the onApprove is called or the webhook is called, the subscription has already been processed and activated.据我所知,当调用 onApprove 或调用 webhook 时,订阅已经被处理并激活。

That is the default behavior, yes.这是默认行为,是的。 Per the above it shouldn't be ncessary, but you can change the subscription to start in an inactive state, and show a final review step on your site that will activate it via API. This is controlled by setting application_context -> user_action -> CONTINUE (vs default SUBSCRIBE_NOW).根据以上所述,它不是必需的,但您可以将订阅更改为从非活动 state 开始,并在您的网站上显示最终审核步骤,该步骤将通过 API 激活它。这是通过设置application_context -> user_action -> 来控制的继续(与默认 SUBSCRIBE_NOW 相比)。 See the API reference for subscription create , and you would of course need to use the subscription activate API call as a final step after confirmation.请参阅订阅创建的 API 参考,您当然需要使用订阅激活 API 调用作为确认后的最后一步。

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

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