Skip to content

Commit

Permalink
add subscription methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Sep 26, 2012
1 parent bb3db2a commit df299ce
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/charged.js
Expand Up @@ -131,6 +131,35 @@ Charged.prototype.getSubscriptionTransactions = function(name, callback) {
return this.get(path, callback, 'transaction');
};

Charged.prototype.getSubscriptionsByCustomer =
Charged.prototype.getSubscriptionsByCustomerId = function(customer, callback) {
var path = '/customers/' + customer + '/subscriptions';
return this.get(path, callback, 'subscription');
};

Charged.prototype.getSubscriptionsByCustomerRef = function(customer, callback) {
var self = this;
return this.getCustomerByRef(customer, function (err, customer) {
if (err) return callback(err);
return self.getSubscriptionsByCustomer(customer.id, callback);
});
};

// http://docs.chargify.com/api-subscriptions#api-usage-json-subscriptions-delayed-cancel
Charged.prototype.delayedCancelSubscription = function(name, options, callback) {
if (!callback) {
callback = options;
options = { cancel_at_end_of_period: 1 };
}
var path = '/subscriptions/' + name;
return this.put(path, options, callback, 'subscription');
};

Charged.prototype.resetSubscriptionBalance = function(name, callback) {
var path = '/subscriptions/' + name + '/reset_balance';
return this.put(path, callback, 'subscription');
};

/**
* Statements
*/
Expand Down

0 comments on commit df299ce

Please sign in to comment.