From 53531f8a7077bf77a7c281d3dc51f71f69a6f108 Mon Sep 17 00:00:00 2001 From: Muhammad Haris Date: Fri, 29 Jul 2016 01:06:41 +0500 Subject: [PATCH 1/4] Calling setter again will exhaust the call stack --- lib/models/billing-info.js | 1 - lib/models/redemption.js | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/models/billing-info.js b/lib/models/billing-info.js index 8fb680a..0edece2 100644 --- a/lib/models/billing-info.js +++ b/lib/models/billing-info.js @@ -45,7 +45,6 @@ class BillingInfo extends RecurlyData { }) this.__defineSetter__('account_code', account_code => { - this.properties.account_code = account_code if (!this.href) { this.href = `${Account.ENDPOINT}/${account_code}/billing_info` } diff --git a/lib/models/redemption.js b/lib/models/redemption.js index 486d99b..69c413b 100644 --- a/lib/models/redemption.js +++ b/lib/models/redemption.js @@ -24,7 +24,6 @@ class Redemption extends RecurlyData { }) this.__defineSetter__('account_code', account_code => { - this.properties.account_code = account_code if (!this.href) { this.href = `${Account.ENDPOINT}/${account_code}/redemption` } From 1db70fb9de43ecaa520ec8121d0e39fcdee0a56c Mon Sep 17 00:00:00 2001 From: Muhammad Haris Date: Fri, 29 Jul 2016 01:19:11 +0500 Subject: [PATCH 2/4] Getter loops getter call stack error fix --- lib/models/billing-info.js | 3 ++- lib/models/redemption.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/models/billing-info.js b/lib/models/billing-info.js index 0edece2..57ba4af 100644 --- a/lib/models/billing-info.js +++ b/lib/models/billing-info.js @@ -41,10 +41,11 @@ class BillingInfo extends RecurlyData { }) this.__defineGetter__('account_code', () => { - return this.account_code + return this._account_code }) this.__defineSetter__('account_code', account_code => { + this.properties._account_code = account_code if (!this.href) { this.href = `${Account.ENDPOINT}/${account_code}/billing_info` } diff --git a/lib/models/redemption.js b/lib/models/redemption.js index 69c413b..6e3be44 100644 --- a/lib/models/redemption.js +++ b/lib/models/redemption.js @@ -20,11 +20,12 @@ class Redemption extends RecurlyData { }) this.__defineGetter__('account_code', () => { - return this.account_code + return this._account_code }) this.__defineSetter__('account_code', account_code => { - if (!this.href) { + this.properties._account_code = account_code + if (!this.href) { this.href = `${Account.ENDPOINT}/${account_code}/redemption` } }) From 97edcc8fc775b0ec332a6b5d073b5a1524493839 Mon Sep 17 00:00:00 2001 From: Muhammad Haris Date: Wed, 24 Aug 2016 18:45:25 +0500 Subject: [PATCH 3/4] Fixed a bug where this.href is not defined in UPDATE call for subscription --- lib/models/subscription.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/models/subscription.js b/lib/models/subscription.js index 66368f4..4af6343 100644 --- a/lib/models/subscription.js +++ b/lib/models/subscription.js @@ -122,13 +122,10 @@ class Subscription extends RecurlyData { if (!options.timeframe) { throw (new Error('subscription update must include "timeframe" parameter')) } - if (!this.href) { - throw (new Error(`cannot update a subscription without an href ${this.id}`)) - } - + const body = data2xml(Subscription.SINGULAR, options) - this.put(this.href, body, (err, response, payload) => { + this.put(Subscription.ENDPOINT, body, (err, response, payload) => { const error = handleRecurlyError(err, response, payload, [ 200, 201 ]) if (error) { return callback(error) From ceb617c3e77f168cdc62a55a357ae1fcf40bee42 Mon Sep 17 00:00:00 2001 From: Muhammad Haris Date: Wed, 24 Aug 2016 18:49:53 +0500 Subject: [PATCH 4/4] Added ID to the update subscription endpoint --- lib/models/subscription.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/models/subscription.js b/lib/models/subscription.js index 4af6343..fd045ec 100644 --- a/lib/models/subscription.js +++ b/lib/models/subscription.js @@ -119,13 +119,16 @@ class Subscription extends RecurlyData { } update(options, callback) { + if (!this.id) { + throw (new Error('cannot update a subscription without a uuid')) + } if (!options.timeframe) { throw (new Error('subscription update must include "timeframe" parameter')) } - + const body = data2xml(Subscription.SINGULAR, options) - this.put(Subscription.ENDPOINT, body, (err, response, payload) => { + this.put(`${Subscription.ENDPOINT}/${this.id}`, body, (err, response, payload) => { const error = handleRecurlyError(err, response, payload, [ 200, 201 ]) if (error) { return callback(error)