我遇到的问题是每次客户结帐时,他们都会有一个链接到客户电子邮件的新客户 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。
最佳答案
如 documentation 中所述,如果结帐成功,您传递给 clientReferenceId
的值将包含在通过 webhook 发送的数据中。
您需要在 Stripe 控制面板中定义 webhook 地址。结帐完成后,将调用 webhook,因此您可以在付款成功后执行所需的所有步骤。
关于javascript - 您如何将客户链接到 Stripe 结账上的订阅?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55071905/