Stripe:在网络上使用 Apple Pay 进行订阅

Stripe: Use apple pay on the web for a subscription

在使用 Stripe 设置 Apple pay 的 documentation 中,步骤告诉您创建带有 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';
  }
});

使用信用卡的流程完全不同。它不需要任何付款请求,您只需从条纹元素卡表单中创建令牌即可创建客户。

使用 Apple Pay 进行定期付款 的 Stripe support page 只是说“apple pay 将创建一个令牌”,但没有提供如何设置它的线索一次性收费。

如何在不请求付款的情况下让 stripe 显示 apple pay 按钮?如果我必须要求付款,是否只是订阅的一个间隔期,这笔金额是否可以定期计费?

您使用 Stripe.js 提出的付款请求实际上并未处理付款。它只是确认用户的浏览器支持 Apple/Google 支付,并显示带有提供的支付详细信息的支付 sheet。用户授权支付sheet上描述的支付后,Stripe会产生一个支付方式。此时,如果您结束集成,则永远不会向用户收费——您只需要一个 Stripe 支付方式 ID。此时您需要做的是:

  1. 将付款方式 ID 保存给客户:https://stripe.com/docs/api/payment_methods/attach
  2. 将付款方式设置为订阅发票的默认付款方式:https://stripe.com/docs/api/customers/update (by setting 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
});