创建订阅时,如果用户未输入promotion_code,则代码将失败并显示错误:
You passed an empty string for 'promotion_code'. We assume empty values are an attempt to unset a parameter; however 'promotion_code' cannot be unset. You should remove 'promotion_code' from your request or supply a non-empty value.
promo是从前端获取的(否则为空值)。我尝试使用一个if else语句 Package promotion_code,但也失败了-我如何向this传递null或空白值,或者如果没有输入促销代码,则省略此行?
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ price: "price_1N1TKrGxUje7SlyIeNldQvLT" }],
payment_settings: {
payment_method_options: {
card: {
request_three_d_secure: "any",
},
},
payment_method_types: ["card"],
save_default_payment_method: "on_subscription",
},
promotion_code: promo,
expand: ["latest_invoice.payment_intent"],
});
1条答案
按热度按时间ocebsuys1#
作为@cmgchess“,外部有params对象,没有升级代码。然后执行if(promo)并在内部设置params.promotion_code=promo。then after that await stripe.sub.create(params)”