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

Update subscription price #19

Open
Santinell opened this issue Dec 16, 2020 · 2 comments
Open

Update subscription price #19

Santinell opened this issue Dec 16, 2020 · 2 comments

Comments

@Santinell
Copy link

Santinell commented Dec 16, 2020

What do you think about adding feature for updating subscription price?

This is how it could be:

 /**
   * Update subscription price
   *
   * @method
   * @param {number} subscriptionID
   * @param {number} price
   * @param {string} currency
   * @param {boolean} immediately
   * @returns {Promise}
   * @fulfill {object} - The result of the operation
   *
   * @example
   * const result = await client.updateSubscriptionPrice(123, 44, 'USD');
   */
  updateSubscriptionPrice (subscriptionID, price, currency, immediately = true) {
    return this._request('/subscription/users/update', {
      body: {
        subscription_id: subscriptionID,
	bill_immediately: immediately,
	prorate: immediately,
      	quantity: 1,
      	recurring_price: price,
      	currency
      }
    });
  }
@avaly
Copy link
Owner

avaly commented Dec 16, 2020

Please submit this code as a PR.

@Santinell
Copy link
Author

By the way - we can put extra options to separate object for both methods updateSubscriptionPrice and updateSubscriptionPlan
Like this:

  updateSubscriptionPlan (subscriptionID, planID, options = {prorate: false}) {
    // for backward compability:
    if (typeof options === "boolean") {
      options = {prorate: options};
    }
    return this._request('/subscription/users/update', {
      body: {
        subscription_id: subscriptionID,
        plan_id: planID,
        ...options
      }
    });
  }

and

  updateSubscriptionPrice (subscriptionID, price, currency, options) {
    return this._request('/subscription/users/update', {
      body: {
        subscription_id: subscriptionID,
      	recurring_price: price,
      	currency,
	...options
      }
    });
  }

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