【问题标题】:How do you link customer to subscription on Stripe checkout?您如何在 Stripe 结账时将客户链接到订阅?
【发布时间】:2020-12-05 22:40:35
【问题描述】:

我遇到的问题是,每次客户结账时,他们都有一个新的客户 ID,该 ID 与客户的电子邮件相关联。

var stripe = Stripe('pk_test_xxx', {
    betas: ['checkout_beta_4']
});

var checkoutButton = document.getElementById('checkout-button');
checkoutButton.addEventListener('click', function () {
    stripe.redirectToCheckout({
        items: [{
            plan: 'plan_xxx',
            quantity: 1
        }],
        customerEmail: 'test15@xxx.com',
        clientReferenceId: 'cus_xxx',
        successUrl: window.location.protocol + '//domain.test/en/accounts/billing-success',
        cancelUrl: window.location.protocol + '//domain.test/en/accounts/billing-cancel',
    }).then(function (result) {
        if (result.error) {
            var displayError = document.getElementById('error-message');
            displayError.textContent = result.error.message;
        }
    });
});

我认为clientReferenceId 会保留 Stripe 客户 ID。似乎情况并非如此。订阅有一个新的 customer_id。

【问题讨论】:

  • 这是 Stripe Checkout 的限制,它不处理会员管理。如果您希望现有客户能够注册其他产品,我建议在您的应用程序上建立一个会员区。如果用户返回,他们登录到您的网站,您完全跳过结帐表单,您可以简单地使用他们保存的卡收费或开始订阅。 stripe.com/docs/api/charges/create#create_charge-customer

标签: javascript stripe-payments


【解决方案1】:

documentation 中所述,如果签出成功,您传递给clientReferenceId 的值将包含在通过webhook 发送的数据中。

您需要在 Stripe Dashboard 中定义 webhook 地址。结帐完成后,将调用 webhook,因此您可以执行付款成功后所需的所有步骤。

【讨论】:

    【解决方案2】:

    如 Stripe API 文档中所述,您只需将 customer 键设置为您想要的客户 ID,而不是 clientReferenceIdhttps://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer

    在另一个 SO 帖子的答案中也提到了这一点:Stripe Checkout Beta: Avoid creating new customer for every payment

    为了更好的安全性,我还建议您在后端创建一个会话并将sessionID 传递给您的前端,然后仅使用sessionID 调用redirectToCheckout

    【讨论】:

      猜你喜欢
      • 2015-11-28
      • 2016-11-25
      • 1970-01-01
      • 1970-01-01
      • 2016-12-08
      • 1970-01-01
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多