Chargebee TypeError:无法创建订阅 chargebee

问题描述 投票:0回答:1

当我尝试向 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');
    }
}

enter image description here

我的代码遇到了一个问题,涉及使用 Chargebee 创建订阅。该代码之前工作正常两年多没有任何问题,但今天突然停止工作。该错误似乎与以下行有关:

const subscriptionResult = await chargebee.subscription.create_with_items(customerId, options).request();
  • 在执行此行之前,“customerId”和“options”变量已正确填充有效数据。
  • 最近这部分代码或环境没有发生可以解释这个突然问题的变化。
  • 该代码已经可靠运行了两年多。
  • 现在,有时代码会成功执行,而有时则会失败,并在上述行中出现错误。
  • 故障似乎是随机的,并且在特定条件下并不总是发生。

如果您能就可能导致此问题的原因或如何进一步解决该问题提供任何见解或建议,我将不胜感激。如果有人遇到过类似的问题或有解决此问题的想法,请告诉我。

预先感谢您的帮助!

javascript node.js chargebee
1个回答
0
投票

您正在尝试向没有关联付款方式的帐户添加订阅,而您的 Chargebee 的自动收款功能已开启。

在尝试收费之前,您必须检查正确该帐户是否有付款方式,如果没有,请停止该功能并向客户显示一条消息,表明他们没有付款方式。

如果您的业务用例是从 Chargebee 收取付款,那么您应该关闭自动收款

来源Chargebee

© www.soinside.com 2019 - 2024. All rights reserved.