Check plan, return error if not valid.

This prevents a crash later when we refer to properties
of the plan object, which can end up being `null` when
the `planCode` is either missing, or not a valid code.
This commit is contained in:
Shane Kilkelly 2016-08-31 10:18:53 +01:00
parent 1b29e0e8ec
commit f59d5d836d

View file

@ -16,6 +16,9 @@ module.exports =
if subscription?
return callback(error) if error?
plan = PlansLocator.findLocalPlanInSettings(subscription.planCode)
if !plan?
err = new Error('No plan found for planCode "#{subscription.planCode}"')
return callback(err)
RecurlyWrapper.getSubscription subscription.recurlySubscription_id, (err, recurlySubscription)->
tax = recurlySubscription?.tax_in_cents || 0
callback null, {