recurly tax updates

- get all accounts does get all of them by looping through all pages
- creating coupons requires which plan the coupon is for
- fixed the total price shown to people so it includes tax
This commit is contained in:
Henry Oswald 2015-02-06 13:55:05 +00:00
parent f75376124e
commit 86f963a7ec
2 changed files with 33 additions and 11 deletions

View file

@ -115,14 +115,29 @@ module.exports = RecurlyWrapper =
)
getAccounts: (callback)->
@apiRequest({
url: "accounts"
qs:
per_page:2000
}, (error, response, body) =>
return callback(error) if error?
@_parseXml body, callback
)
allAccounts = []
getPageOfAccounts = (cursor = null)=>
opts =
url: "accounts"
qs:
per_page:200
if cursor?
opts.qs.cursor = cursor
@apiRequest opts, (error, response, body) =>
return callback(error) if error?
@_parseXml body, (err, data)->
if err?
logger.err err:err, "could not get accoutns"
callback(err)
allAccounts = allAccounts.concat(data.accounts)
cursor = response.headers.link?.match(/cursor=([0-9]+)&/)?[1]
if cursor?
getPageOfAccounts(cursor)
else
callback(err, allAccounts)
getPageOfAccounts()
getAccount: (accountId, callback) ->
@apiRequest({
@ -158,7 +173,7 @@ module.exports = RecurlyWrapper =
@_parseSubscriptionXml responseBody, callback
)
createFixedAmmountCoupon: (coupon_code, name, currencyCode, discount_in_cents, callback)->
createFixedAmmountCoupon: (coupon_code, name, currencyCode, discount_in_cents, plan_code, callback)->
requestBody = """
<coupon>
<coupon_code>#{coupon_code}</coupon_code>
@ -167,9 +182,13 @@ module.exports = RecurlyWrapper =
<discount_in_cents>
<#{currencyCode}>#{discount_in_cents}</#{currencyCode}>
</discount_in_cents>
<plan_codes>
<plan_code>#{plan_code}</plan_code>
</plan_codes>
<applies_to_all_plans>false</applies_to_all_plans>
</coupon>
"""
logger.log coupon_code:coupon_code, requestBody:requestBody, "creating coupon"
# logger.log coupon_code:coupon_code, requestBody:requestBody, "creating coupon"
@apiRequest({
url : "coupons"
method : "post"
@ -228,6 +247,8 @@ module.exports = RecurlyWrapper =
_parseSubscriptionXml: (xml, callback) ->
console.log xml, "_parseAccountXml"
@_parseXml xml, (error, data) ->
return callback(error) if error?
if data? and data.subscription?

View file

@ -17,11 +17,12 @@ module.exports =
return callback(error) if error?
plan = PlansLocator.findLocalPlanInSettings(subscription.planCode)
RecurlyWrapper.getSubscription subscription.recurlySubscription_id, (err, recurlySubscription)->
tax = recurlySubscription?.tax_in_cents || 0
callback null, {
name: plan.name
nextPaymentDueAt: SubscriptionFormatters.formatDate(recurlySubscription?.current_period_ends_at)
state: recurlySubscription?.state
price: SubscriptionFormatters.formatPrice recurlySubscription?.unit_amount_in_cents, recurlySubscription?.currency
price: SubscriptionFormatters.formatPrice (recurlySubscription?.unit_amount_in_cents + tax), recurlySubscription?.currency
planCode: subscription.planCode
currency:recurlySubscription?.currency
groupPlan: subscription.groupPlan