代码之家  ›  专栏  ›  技术社区  ›  inorganik

条带:使用apple pay on the web订阅

  •  0
  • inorganik  · 技术社区  · 4 年前

    documentation 要设置Apple pay with Stripe,步骤会告诉您创建一个带有Stripe元素的付款请求,以便显示Apple pay按钮—示例请求是一次性直接收费。您必须有一个付款请求才能显示按钮-那么我如何才能为订阅创建付款请求?付款请求对象是条带元素,在条带api中没有描述。

    var elements = stripe.elements();
    var prButton = elements.create('paymentRequestButton', {
      paymentRequest: paymentRequest,
    });
    
    // Check the availability of the Payment Request API first.
    paymentRequest.canMakePayment().then(function(result) {
      if (result) {
        prButton.mount('#payment-request-button');
      } else {
        document.getElementById('payment-request-button').style.display = 'none';
      }
    });
    

    使用信用卡的流程完全不同。它不需要任何付款请求,您只需从stripe elements card表单创建一个令牌即可创建一个客户。

    条纹 support page 对于 只是说“苹果支付将创建一个代币”,但没有提供线索,你将如何设置它没有一次性收费。

    0 回复  |  直到 4 年前
        1
  •  2
  •   ttmarek    4 年前

    您使用Stripe.js发出的付款请求实际上并不处理付款。它只是确认用户的浏览器支持Apple/googlepay,并显示带有提供的支付详细信息的支付表。用户授权付款单上描述的付款后,Stripe将生成一个付款方法。在这一点上,如果你结束了你的集成,用户将永远不会被收取费用-你只需要一个条带支付方式ID。在这一点上你需要做的是:

    1. 将付款方式ID保存到客户: https://stripe.com/docs/api/payment_methods/attach
    2. 将付款方式设置为订阅发票的默认付款方式: https://stripe.com/docs/api/customers/update (通过设置 invoice_settings.default_payment_method )
    3. 向客户订阅一个经常性的价格(例如。, https://stripe.com/docs/billing/subscriptions/fixed-price )

    从付款请求接收付款方式后,您将触发上述所有逻辑:

    paymentRequest.on('paymentmethod', function(ev) {
      const paymentMethodId = ev.paymentMethod.id;
    
      // Send ID to your server to:
      //  a) attach it to a Customer
      //  b) set it as the default for subscription invoices
      //  c) create the subscription
    });