Fix references to the RecurlyWrapper object.

This commit is contained in:
Shane Kilkelly 2016-06-27 12:14:43 +01:00
parent eb92cfe8e0
commit 401565ba23

View file

@ -191,13 +191,13 @@ module.exports = RecurlyWrapper =
</account> </account>
</subscription> </subscription>
""" """
@apiRequest({ RecurlyWrapper.apiRequest({
url : "subscriptions" url : "subscriptions"
method : "POST" method : "POST"
body : requestBody body : requestBody
}, (error, response, responseBody) => }, (error, response, responseBody) =>
return callback(error) if error? return callback(error) if error?
@_parseSubscriptionXml responseBody, callback RecurlyWrapper._parseSubscriptionXml responseBody, callback
) )
createSubscription: (user, subscriptionDetails, recurly_token_id, callback)-> createSubscription: (user, subscriptionDetails, recurly_token_id, callback)->
@ -207,7 +207,7 @@ module.exports = RecurlyWrapper =
fn user, subscriptionDetails, recurly_token_id, callback fn user, subscriptionDetails, recurly_token_id, callback
apiRequest : (options, callback) -> apiRequest : (options, callback) ->
options.url = @apiUrl + "/" + options.url options.url = RecurlyWrapper.apiUrl + "/" + options.url
options.headers = options.headers =
"Authorization" : "Basic " + new Buffer(Settings.apis.recurly.apiKey).toString("base64") "Authorization" : "Basic " + new Buffer(Settings.apis.recurly.apiKey).toString("base64")
"Accept" : "application/xml" "Accept" : "application/xml"
@ -249,11 +249,11 @@ module.exports = RecurlyWrapper =
getSubscriptions: (accountId, callback)-> getSubscriptions: (accountId, callback)->
@apiRequest({ RecurlyWrapper.apiRequest({
url: "accounts/#{accountId}/subscriptions" url: "accounts/#{accountId}/subscriptions"
}, (error, response, body) => }, (error, response, body) =>
return callback(error) if error? return callback(error) if error?
@_parseXml body, callback RecurlyWrapper._parseXml body, callback
) )
@ -266,11 +266,11 @@ module.exports = RecurlyWrapper =
else else
url = "subscriptions/#{subscriptionId}" url = "subscriptions/#{subscriptionId}"
@apiRequest({ RecurlyWrapper.apiRequest({
url: url url: url
}, (error, response, body) => }, (error, response, body) =>
return callback(error) if error? return callback(error) if error?
@_parseSubscriptionXml body, (error, recurlySubscription) => RecurlyWrapper._parseSubscriptionXml body, (error, recurlySubscription) =>
return callback(error) if error? return callback(error) if error?
if options.includeAccount if options.includeAccount
if recurlySubscription.account? and recurlySubscription.account.url? if recurlySubscription.account? and recurlySubscription.account.url?
@ -278,7 +278,7 @@ module.exports = RecurlyWrapper =
else else
return callback "I don't understand the response from Recurly" return callback "I don't understand the response from Recurly"
@getAccount accountId, (error, account) -> RecurlyWrapper.getAccount accountId, (error, account) ->
return callback(error) if error? return callback(error) if error?
recurlySubscription.account = account recurlySubscription.account = account
callback null, recurlySubscription callback null, recurlySubscription
@ -296,9 +296,9 @@ module.exports = RecurlyWrapper =
per_page:200 per_page:200
if cursor? if cursor?
opts.qs.cursor = cursor opts.qs.cursor = cursor
@apiRequest opts, (error, response, body) => RecurlyWrapper.apiRequest opts, (error, response, body) =>
return callback(error) if error? return callback(error) if error?
@_parseXml body, (err, data)-> RecurlyWrapper._parseXml body, (err, data)->
if err? if err?
logger.err err:err, "could not get accoutns" logger.err err:err, "could not get accoutns"
callback(err) callback(err)
@ -314,19 +314,19 @@ module.exports = RecurlyWrapper =
getAccount: (accountId, callback) -> getAccount: (accountId, callback) ->
@apiRequest({ RecurlyWrapper.apiRequest({
url: "accounts/#{accountId}" url: "accounts/#{accountId}"
}, (error, response, body) => }, (error, response, body) =>
return callback(error) if error? return callback(error) if error?
@_parseAccountXml body, callback RecurlyWrapper._parseAccountXml body, callback
) )
getBillingInfo: (accountId, callback)-> getBillingInfo: (accountId, callback)->
@apiRequest({ RecurlyWrapper.apiRequest({
url: "accounts/#{accountId}/billing_info" url: "accounts/#{accountId}/billing_info"
}, (error, response, body) => }, (error, response, body) =>
return callback(error) if error? return callback(error) if error?
@_parseXml body, callback RecurlyWrapper._parseXml body, callback
) )
@ -338,13 +338,13 @@ module.exports = RecurlyWrapper =
<timeframe>#{options.timeframe}</timeframe> <timeframe>#{options.timeframe}</timeframe>
</subscription> </subscription>
""" """
@apiRequest({ RecurlyWrapper.apiRequest({
url : "subscriptions/#{subscriptionId}" url : "subscriptions/#{subscriptionId}"
method : "put" method : "put"
body : requestBody body : requestBody
}, (error, response, responseBody) => }, (error, response, responseBody) =>
return callback(error) if error? return callback(error) if error?
@_parseSubscriptionXml responseBody, callback RecurlyWrapper._parseSubscriptionXml responseBody, callback
) )
createFixedAmmountCoupon: (coupon_code, name, currencyCode, discount_in_cents, plan_code, callback)-> createFixedAmmountCoupon: (coupon_code, name, currencyCode, discount_in_cents, plan_code, callback)->
@ -363,7 +363,7 @@ module.exports = RecurlyWrapper =
</coupon> </coupon>
""" """
logger.log coupon_code:coupon_code, requestBody:requestBody, "creating coupon" logger.log coupon_code:coupon_code, requestBody:requestBody, "creating coupon"
@apiRequest({ RecurlyWrapper.apiRequest({
url : "coupons" url : "coupons"
method : "post" method : "post"
body : requestBody body : requestBody
@ -375,16 +375,16 @@ module.exports = RecurlyWrapper =
lookupCoupon: (coupon_code, callback)-> lookupCoupon: (coupon_code, callback)->
@apiRequest({ RecurlyWrapper.apiRequest({
url: "coupons/#{coupon_code}" url: "coupons/#{coupon_code}"
}, (error, response, body) => }, (error, response, body) =>
return callback(error) if error? return callback(error) if error?
@_parseXml body, callback RecurlyWrapper._parseXml body, callback
) )
cancelSubscription: (subscriptionId, callback) -> cancelSubscription: (subscriptionId, callback) ->
logger.log subscriptionId:subscriptionId, "telling recurly to cancel subscription" logger.log subscriptionId:subscriptionId, "telling recurly to cancel subscription"
@apiRequest({ RecurlyWrapper.apiRequest({
url: "subscriptions/#{subscriptionId}/cancel", url: "subscriptions/#{subscriptionId}/cancel",
method: "put" method: "put"
}, (error, response, body) -> }, (error, response, body) ->
@ -393,7 +393,7 @@ module.exports = RecurlyWrapper =
reactivateSubscription: (subscriptionId, callback) -> reactivateSubscription: (subscriptionId, callback) ->
logger.log subscriptionId:subscriptionId, "telling recurly to reactivating subscription" logger.log subscriptionId:subscriptionId, "telling recurly to reactivating subscription"
@apiRequest({ RecurlyWrapper.apiRequest({
url: "subscriptions/#{subscriptionId}/reactivate", url: "subscriptions/#{subscriptionId}/reactivate",
method: "put" method: "put"
}, (error, response, body) -> }, (error, response, body) ->
@ -409,7 +409,7 @@ module.exports = RecurlyWrapper =
</redemption> </redemption>
""" """
logger.log account_code:account_code, coupon_code:coupon_code, requestBody:requestBody, "redeeming coupon for user" logger.log account_code:account_code, coupon_code:coupon_code, requestBody:requestBody, "redeeming coupon for user"
@apiRequest({ RecurlyWrapper.apiRequest({
url : "coupons/#{coupon_code}/redeem" url : "coupons/#{coupon_code}/redeem"
method : "post" method : "post"
body : requestBody body : requestBody
@ -423,7 +423,7 @@ module.exports = RecurlyWrapper =
next_renewal_date = new Date() next_renewal_date = new Date()
next_renewal_date.setDate(next_renewal_date.getDate() + daysUntilExpire) next_renewal_date.setDate(next_renewal_date.getDate() + daysUntilExpire)
logger.log subscriptionId:subscriptionId, daysUntilExpire:daysUntilExpire, "Exending Free trial for user" logger.log subscriptionId:subscriptionId, daysUntilExpire:daysUntilExpire, "Exending Free trial for user"
@apiRequest({ RecurlyWrapper.apiRequest({
url : "/subscriptions/#{subscriptionId}/postpone?next_renewal_date=#{next_renewal_date}&bulk=false" url : "/subscriptions/#{subscriptionId}/postpone?next_renewal_date=#{next_renewal_date}&bulk=false"
method : "put" method : "put"
}, (error, response, responseBody) => }, (error, response, responseBody) =>
@ -433,7 +433,7 @@ module.exports = RecurlyWrapper =
) )
_parseSubscriptionXml: (xml, callback) -> _parseSubscriptionXml: (xml, callback) ->
@_parseXml xml, (error, data) -> RecurlyWrapper._parseXml xml, (error, data) ->
return callback(error) if error? return callback(error) if error?
if data? and data.subscription? if data? and data.subscription?
recurlySubscription = data.subscription recurlySubscription = data.subscription
@ -442,7 +442,7 @@ module.exports = RecurlyWrapper =
callback null, recurlySubscription callback null, recurlySubscription
_parseAccountXml: (xml, callback) -> _parseAccountXml: (xml, callback) ->
@_parseXml xml, (error, data) -> RecurlyWrapper._parseXml xml, (error, data) ->
return callback(error) if error? return callback(error) if error?
if data? and data.account? if data? and data.account?
account = data.account account = data.account
@ -451,7 +451,7 @@ module.exports = RecurlyWrapper =
callback null, account callback null, account
_parseBillingInfoXml: (xml, callback) -> _parseBillingInfoXml: (xml, callback) ->
@_parseXml xml, (error, data) -> RecurlyWrapper._parseXml xml, (error, data) ->
return callback(error) if error? return callback(error) if error?
if data? and data.account? if data? and data.account?
billingInfo = data.billing_info billingInfo = data.billing_info