From aaaf28f91688d36f7fa94e9048eb2fa69d1812e7 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 7 Jan 2015 12:02:07 +0000 Subject: [PATCH] added some helper methods into recurly wrapper which can be used by our one time scripts --- .../Subscription/RecurlyWrapper.coffee | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee b/services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee index d6c7fe272d..126a08c881 100644 --- a/services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee +++ b/services/web/app/coffee/Features/Subscription/RecurlyWrapper.coffee @@ -49,6 +49,16 @@ module.exports = RecurlyWrapper = callback null, signature + + getSubscriptions: (accountId, callback)-> + @apiRequest({ + url: "accounts/#{accountId}/subscriptions" + }, (error, response, body) => + return callback(error) if error? + @_parseXml body, callback + ) + + getSubscription: (subscriptionId, options, callback) -> callback = options unless callback? options ||= {} @@ -79,6 +89,16 @@ module.exports = RecurlyWrapper = callback null, recurlySubscription ) + getAccounts: (callback)-> + @apiRequest({ + url: "accounts" + qs: + per_page:2000 + }, (error, response, body) => + return callback(error) if error? + @_parseXml body, callback + ) + getAccount: (accountId, callback) -> @apiRequest({ url: "accounts/#{accountId}" @@ -86,7 +106,16 @@ module.exports = RecurlyWrapper = return callback(error) if error? @_parseAccountXml body, callback ) - + + getBillingInfo: (accountId, callback)-> + @apiRequest({ + url: "accounts/#{accountId}/billing_info" + }, (error, response, body) => + return callback(error) if error? + @_parseXml body, callback + ) + + updateSubscription: (subscriptionId, options, callback) -> logger.log subscriptionId:subscriptionId, options:options, "telling recurly to update subscription" requestBody = """ @@ -104,6 +133,37 @@ module.exports = RecurlyWrapper = @_parseSubscriptionXml responseBody, callback ) + createFixedAmmountCoupon: (coupon_code, name, currencyCode, discount_in_cents, callback)-> + requestBody = """ + + #{coupon_code} + #{name} + dollars + + <#{currencyCode}>#{discount_in_cents} + + + """ + logger.log coupon_code:coupon_code, requestBody:requestBody, "creating coupon" + @apiRequest({ + url : "coupons" + method : "post" + body : requestBody + }, (error, response, responseBody) => + if error? + logger.err err:error, coupon_code:coupon_code, "error creating coupon" + callback(error) + ) + + + lookupCoupon: (coupon_code, callback)-> + @apiRequest({ + url: "coupons/#{coupon_code}" + }, (error, response, body) => + return callback(error) if error? + @_parseXml body, callback + ) + cancelSubscription: (subscriptionId, callback) -> logger.log subscriptionId:subscriptionId, "telling recurly to cancel subscription" @apiRequest({