1

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?

Alex Polkhovsky
  • 3,340
  • 5
  • 29
  • 37

2 Answers2

2

The proper format is:

subscription_add_ons: {
        subscription_add_on: [{
          add_on_code: shippingMethod.servicelevel_token,
          unit_amount_in_cents: parseFloat(shippingMethod.amount) * 100,
        }],
      },
Alex Polkhovsky
  • 3,340
  • 5
  • 29
  • 37
0

I ended up doing this which works whether you have 1 add-on or multiple add-ons. subscription_add_ons is an array which can contain 1 or more subscription add ons. I then send over the details (along with other info) in the subscription update call. This is similar to what you attempted in your original post so I'm not sure why that didn't work for you.

details.subscription_add_ons = [
    { subscription_add_on: {add_on_code: "stream", quantity: 3} },
    { subscription_add_on: {add_on_code: "hold", quantity: 2} }
];
Rk220
  • 181
  • 2
  • 10