mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
added some helper methods into recurly wrapper which can be used by
our one time scripts
This commit is contained in:
parent
7e64b88fcf
commit
aaaf28f916
1 changed files with 61 additions and 1 deletions
|
@ -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>
|
||||
<coupon_code>#{coupon_code}</coupon_code>
|
||||
<name>#{name}</name>
|
||||
<discount_type>dollars</discount_type>
|
||||
<discount_in_cents>
|
||||
<#{currencyCode}>#{discount_in_cents}</#{currencyCode}>
|
||||
</discount_in_cents>
|
||||
</coupon>
|
||||
"""
|
||||
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({
|
||||
|
|
Loading…
Reference in a new issue