Search code examples
node.jsrecurly

Create subscription with addon using node-recurly


Using node-recurly, I can create a subscription object and pass it to recurly.subscriptions.create call:

const subscription = {
      plan_code: plan.code,
      currency: 'USD',
      account: {
        account_code: activationCode,
        first_name: billingInfo.first_name,
        last_name: billingInfo.last_name,
        email: billingInfo.email,
        billing_info: {
          token_id: paymentToken,
        },
      },
    };

I would also like to add subscription_add_ons property, which, looking at the documentation, supposed to be an array of add-ons. I tried passing it like this:

subscription_add_ons: [
        {
            add_on_code: shippingMethod.servicelevel_token,
            unit_amount_in_cents: parseFloat(shippingMethod.amount) * 100,
        },
      ],

The server returned an error:

Tag <subscription_add_ons> must consist only of sub-tags named <subscription_add_on>

I attempted this:

subscription_add_ons: [
        {
          subscription_add_on: {
            add_on_code: shippingMethod.servicelevel_token,
            unit_amount_in_cents: parseFloat(shippingMethod.amount) * 100,
          },
        },
      ],

Got back this error: enter image description here

What's the proper format to pass subscription add on in this scenario?


Solution

  • The proper format is:

    subscription_add_ons: {
            subscription_add_on: [{
              add_on_code: shippingMethod.servicelevel_token,
              unit_amount_in_cents: parseFloat(shippingMethod.amount) * 100,
            }],
          },