【问题标题】:PayPal subscription and webhooksPayPal 订阅和 webhook
【发布时间】:2020-12-05 03:50:46
【问题描述】:

我创建了一个网站,其中包含我要收费的服务。我想创建一个 PayPal 订阅。我需要将该订阅与我的后端(firebase 函数 - node.js)连接起来,这样我就可以更改数据库中的一些数据,以便为我的用户提供不同的内容,具体取决于他们是否付费。我想为我的订阅使用 PayPal 按钮,但我找不到将该按钮与我的后端连接的方法,因此 PayPal 按钮似乎不是解决我的问题的最佳选择。我无法使用 Stripe,因为我所在的国家/地区不支持它。您能否为我的订阅付款提供不同的解决方案或说明如何使用 PayPal?

【问题讨论】:

    标签: node.js paypal paypal-subscriptions


    【解决方案1】:

    您可以将Paypal Node SDK 用于您的用例,而不是依赖可嵌入的 Paypal 订阅按钮。 SDK 将为您提供与 NodeJs 更好的集成。

    基本上有两个步骤可以做到这一点: 1.) 定义计费方案对象 计费计划对象定义订阅计划,包括周期数、支付频率、任何设置费用等。

    var billingPlanAttribs = {
      name: 'Food of the World Club Membership: Standard',
      description: 'Monthly plan for getting the t-shirt of the month.',
      type: 'fixed',
      payment_definitions: [{
        name: 'Standard Plan',
        type: 'REGULAR',
        frequency_interval: '1',
        frequency: 'MONTH',
        cycles: '11',
        amount: {
          currency: 'USD',
          value: '19.99'
        }
      }],
      merchant_preferences: {
        setup_fee: {
          currency: 'USD',
          value: '1'
        },
        cancel_url: 'http://localhost:3000/cancel',
        return_url: 'http://localhost:3000/processagreement',
        max_fail_attempts: '0',
        auto_bill_amount: 'YES',
        initial_fail_amount_action: 'CONTINUE'
      }
    };
    

    当然,您需要将 cancel_url 和 return_url 更改为您的实际 Firebase 函数端点(或 localhost,如果您出于开发目的在 localhost 中运行您的函数)

    2.) 创建和激活计费计划,因此一旦您创建或定义了计费 - 您将需要创建该对象并激活计费计划,如下所示:

    paypal.billingPlan.create(billingPlanAttribs, function (error, billingPlan){
      var billingPlanUpdateAttributes;
    
      if (error){
        console.error(JSON.stringify(error));
        throw error;
      } else {
        // Create billing plan patch object
        billingPlanUpdateAttributes = [{
          op: 'replace',
          path: '/',
          value: {
            state: 'ACTIVE'
          }
        }];
    
        // Activate the plan by changing status to active
        paypal.billingPlan.update(billingPlan.id, billingPlanUpdateAttributes, function(error, response){
          if (error){
            console.error(JSON.stringify(error));
            throw error;
          } else {
            console.log('Billing plan created under ID: ' + billingPlan.id);
          }
        });
      }
    });
    

    同样,所有这些都记录在 Paypal's Developer Section 中。

    Here's also a link to their github example using NodeJs(与 Firebase 函数相同的底层后端)

    【讨论】:

    • 如果我没有预定义的周期数我只是希望它是无限的,应该将“周期”设置为多少? @乌鸦
    • 为什么 PayPal-node-SDK 存储库被归档?有那么老旧不可靠吗?
    • 我如何将我的 Firebase 用户与付款联系起来?我现在如何知道哪些付款/订阅来自哪些用户?
    • @PyFran 周期是用户订阅时支付的频率。 PayPal 节点 SDK 可能已存档,因为它已被更新的 SDK 替换。最后,正如 Raven 指出的,PayPal 网站上的所有内容都有文档;您可以使用从 PayPal 订阅调用的事件注册和存储所需的任何数据。
    猜你喜欢
    • 2019-05-28
    • 2020-10-06
    • 2018-06-11
    • 2020-08-15
    • 2017-08-11
    • 2016-10-18
    • 2016-06-17
    • 2021-09-23
    • 2018-11-29
    相关资源
    最近更新 更多