当我尝试向 Chargebee 发出请求时,出现错误
错误:创建订阅失败
async createSubscriptionForTeamMember(customerId, options) {
try {
// Proceed with subscription creation using Chargebee API
console.log(customerId); // 16CMrdUBRD3oj1Wy5
console.log(options); // {subscription_items: [ { item_price_id: 'monthly', quantity: 1 } ]}
const subscriptionResult = await chargebee.subscription.create_with_items(customerId, options).request();
const subscription = subscriptionResult.subscription;
console.log('subscription', subscription.status);
// Retrieve customer information including payment method
const customerResult = await chargebee.customer.retrieve(customerId).request();
const customer = customerResult.customer;
console.log('customer.payment_method', customer.id);
// Parse subscription details
const nextBillingTimestamp = parseInt(subscription.next_billing_at) * 1000;
const nextBilling = new Date(nextBillingTimestamp);
const billingInterval = subscription.billing_period_unit === 'year' ? 'annual' : 'monthly';
// Return subscription details
return {
nextBilling,
subscriptionStatus: subscription.status,
customerId: customer.id,
subscriptionId: subscription.id,
billingInterval
};
} catch (error) {
console.error('Error creating subscription:', error);
throw new Error('Failed to create subscription');
}
}
我的代码遇到了一个问题,涉及使用 Chargebee 创建订阅。该代码之前工作正常两年多没有任何问题,但今天突然停止工作。该错误似乎与以下行有关:
const subscriptionResult = await chargebee.subscription.create_with_items(customerId, options).request();
如果您能就可能导致此问题的原因或如何进一步解决该问题提供任何见解或建议,我将不胜感激。如果有人遇到过类似的问题或有解决此问题的想法,请告诉我。
预先感谢您的帮助!
您正在尝试向没有关联付款方式的帐户添加订阅,而您的 Chargebee 的自动收款功能已开启。
在尝试收费之前,您必须检查正确该帐户是否有付款方式,如果没有,请停止该功能并向客户显示一条消息,表明他们没有付款方式。
如果您的业务用例是从 Chargebee 收取付款,那么您应该关闭自动收款