【问题标题】:Stripe Payment Element with subscription and trial period带有订阅和试用期的条纹支付元素
【发布时间】:2021-12-16 08:52:35
【问题描述】:

我正在将 Stripe 卡元素迁移到带有订阅的 Stripe 支付元素,遵循本指南 https://stripe.com/docs/billing/subscriptions/build-subscription?ui=elements,但是当我将试用期添加到订阅时,api 不会返回“已用”发票的付款意图让 client_secret 与 js elements.create 方法一起使用。
所以我按照本指南https://stripe.com/docs/payments/payment-element/migration?integration-path=future 使用设置意图而不是支付意图,但是在使用此代码实例化元素后调用elements.create("payment")

const elements = stripe.elements({
    clientSecret: client_secret
});

我从条带收到以下错误:
Uncaught IntegrationError: Missing value for elements.create('payment'): clientSecret should be a client_secret string.
client_secret 变量包含一个类似于 seti_1Jr36EGwrHzEL7YxdKlo86JF_secret_KW5G5nr6Dv1i9fnFhlQk9iA7yhe5tgP 的字符串,取自设置意图。

我哪里错了?
如何在有试用期的订阅中使用 Stripe Payment Element?

感谢 ENx

【问题讨论】:

  • 在哪里可以找到解决方案?我目前遇到同样的问题

标签: stripe-payments


【解决方案1】:

要设置带有试用期的描述,请使用pending_setup_intent 对象中的client_secret,该对象需要扩展。

这是我开始工作的一个例子:

export const createStripeSubscription = async (customerId, priceId, trial_period) => {

  try {
    const subscription = await stripe.subscriptions.create({
        customer: customerId,
        items: [{
          price: priceId,
        }],
        trial_period_days: trial_period,
        expand: ['pending_setup_intent'],
      });
      return {
          subscriptionId: subscription.id,
          clientSecret: subscription.pending_setup_intent.client_secret,
      }
  } catch (error) {
      return null
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-07
    • 2020-07-06
    • 2023-04-10
    • 2021-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    相关资源
    最近更新 更多