node-recurly
node-recurly copied to clipboard
How does one form the data to create a subscription with add-ons?
For example,
I am trying to create a plan with multiple add-ons using node-recurly:
var subscriptionData = {
plan_code : planCode,
account : {
account_code : organizationId,
email : accountInfo.email,
first_name : accountInfo.first_name,
last_name : accountInfo.last_name,
},
currency : "USD",
subscription_add_ons : [
{
subscription_add_on : {
add_on_code : "sfd-pack0001"
}
},
{
subscription_add_on : {
add_on_code : "bmi-pack0001"
}
}
]
};
However it looks like js2xml treats the child nodes of subscription_add_ons as anonymous so the appear like so in the request:
<subscription_add_ons>
<item>
<subscription_add_on></subscription_add_on>
</item>
<item>
<subscription_add_on></subscription_add_on>
</item>
</subscription_add_ons>
I can make this work with one add-on only by doing a hash of hashes, but I'm not entirely sure what the correct way to do this is.
Any ideas? Are multiple add-ons not supported with this package?
I just ran into this same issue while trying to update a subscription to add additional add-ons.
var update = {
subscription_add_ons: [{
subscription_add_on: {
add_on_code: 'my_add_on'
}
}]
};
Ends up with the same XML as @ruschie mentioned, and Recurly rejects it as invalid.
The proper way to form the object so that it can be consumed by JS2XML is just as a hash.
var update = {
subscription_add_ons: {
subscription_add_on: {
add_on_code: 'my_add_on'
}
}
};
We need multiple subscription_add_on
objects for multiple add-ons, but since you can't have multiple values with the same exact key in a JS object, it's impossible to set multiple add-ons using this library in it's current state.