From 8a68445d2e1a4ddf535964773e1b0f9ce4698675 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 10 Aug 2016 17:48:34 +0200 Subject: [PATCH] fix stripe coupon creation --- app/workers/stripe_worker.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/workers/stripe_worker.rb b/app/workers/stripe_worker.rb index 9dc090438..ff659b98f 100644 --- a/app/workers/stripe_worker.rb +++ b/app/workers/stripe_worker.rb @@ -17,13 +17,20 @@ class StripeWorker def create_stripe_coupon(coupon_id) coupon = Coupon.find(coupon_id) - Stripe::Coupon.create( + stp_coupon = { id: coupon.code, duration: coupon.validity_per_user, percent_off: coupon.percent_off, - redeem_by: coupon.valid_until.to_i, - max_redemptions: coupon.max_usages, - ) + } + unless coupon.valid_until.nil? + stp_coupon[:redeem_by] = coupon.valid_until.to_i + end + stp_coupon + unless coupon.max_usages.nil? + stp_coupon[max_redemptions] = coupon.max_usages + end + + Stripe::Coupon.create(stp_coupon) end def delete_stripe_coupon(coupon_code)