Skip to content

Commit

Permalink
Fixes coupon validity method safety
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Rogers <chrissrogers@gmail.com>
  • Loading branch information
chrissrogers committed Nov 7, 2017
1 parent 31a01ed commit fbb652c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/recurly/pricing/subscription/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ export default class SubscriptionPricing extends Pricing {

const receiveCoupon = (err, coupon) => {
if (err && err.code === 'not-found') unsetCoupon();
if (!this.couponIsValidForSubscription(coupon)) {
return this.error('invalid-coupon-for-subscription', reject, 'coupon');
}
if (err) {
return this.error(err, reject, 'coupon');
}
if (!this.couponIsValidForSubscription(coupon)) {
return this.error('invalid-coupon-for-subscription', reject, 'coupon');
} else {
debug('set.coupon');
this.items.coupon = coupon;
Expand Down Expand Up @@ -354,6 +354,7 @@ export default class SubscriptionPricing extends Pricing {
* @return {Boolean}
*/
couponIsValidForSubscription (coupon) {
if (!coupon) return false;
if (!coupon.applies_to_plans) return false;
if (coupon.applies_to_all_plans) return true;
if (~coupon.plans.indexOf(this.items.plan.code)) return true;
Expand Down

0 comments on commit fbb652c

Please sign in to comment.