Skip to content

Subscription update method mutates items #521

Closed
@jperasmus

Description

Hi there,

Thanks for this awesome library and for Stripe in general. A-grade 👏

Using:

node v10.9.0
stripe v6.15.0

When performing an update of a subscription's items I've discovered that the stripe.subscriptions.update() method mutates the payload provided to it by transforming the items from an array to an object with the array indexes as the object keys. This can lead to very unexpected behaviour when reusing the same payload after the update method was invoked.

I've managed to trace the problem to this utility method:

/**
   * Encodes a particular param of data, whose value is an array, as an
   * object with integer string attributes. Returns the entirety of data
   * with just that param modified.
   */
  encodeParamWithIntegerIndexes: function(param, data) {
    if (data[param] !== undefined) {
      data[param] = utils.arrayToObject(data[param]);
    }
    return data;
},

Ideally a new transformed data object should be returned instead of mutating it. Something like:

const cloneDeep = require('lodash.cloneDeep');

/**
   * Encodes a particular param of data, whose value is an array, as an
   * object with integer string attributes. Returns the entirety of data
   * with just that param modified.
   */
  encodeParamWithIntegerIndexes: function(param, payload) {
    const data = cloneDeep(payload);
    if (data[param] !== undefined) {
      data[param] = utils.arrayToObject(data[param]);
    }
    return data;
},

The problem would be for any of the other methods that use this utility method and not just for stripe.subscriptions.update().

Is this something you would be interested in fixing? I would be happy to create a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions