Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does one form the data to create a subscription with add-ons? #7

Open
erichjrusch opened this issue Jul 9, 2014 · 1 comment
Open

Comments

@erichjrusch
Copy link

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?

@williamhaley
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants