我使用React。当用户更改订阅计划时,我希望删除旧的订阅。这是我的代码。
导入{loadStripe,useStripe} from'@stripe/stripe-js'
导入{loadStripe,useStripe} from'@stripe/stripe-js'
const loadCheckout = async (priceId) =>{
const docRef = await db
.collection('customers')
.doc(user.uid)
.collection('checkout_sessions')
.add({
price:priceId,
success_url:window.location.origin,
cancel_url: window.location.origin,
})
docRef.onSnapshot(async (snap) =>{
const {error, sessionId} = snap.data();
if(error){
alert(`an error occured ${error.message}`)
}
if(sessionId){
const stripe = await loadStripe("pk_test_51JG0BKLXYmn2IpSgISeCDbsCNllISGA3PvEbSzBz5bpo8WTvmqI6UKCbzpxX92LKiN0hftRrobm1J6wJZPCOWSTs0081pmQFJE")
const deleted = await stripe.subscriptions.del(
subscription.id
);
console.log(deleted)
stripe.redirectToCheckout({sessionId});
}
})
}
我的代码出现错误,提示stripe.subscriptions.del不是一个函数。如果我删除这行代码,付款就成功了。在stripe API文档中,建议使用.del(),但在这里却无法正常工作。