diff --git a/app/controllers/api/coupons_controller.rb b/app/controllers/api/coupons_controller.rb index ee9e4afce..425a2cc9f 100644 --- a/app/controllers/api/coupons_controller.rb +++ b/app/controllers/api/coupons_controller.rb @@ -78,7 +78,14 @@ class API::CouponsController < API::ApiController end def coupon_params - params.require(:coupon).permit(:name, :code, :percent_off, :amount_off, :validity_per_user, :valid_until, :max_usages, :active) + if @parameters + @parameters + else + @parameters = params + @parameters[:coupon][:amount_off] = @parameters[:coupon][:amount_off].to_i * 100.0 if @parameters[:coupon][:amount_off] + + @parameters = @parameters.require(:coupon).permit(:name, :code, :percent_off, :amount_off, :validity_per_user, :valid_until, :max_usages, :active) + end end def coupon_editable_params diff --git a/app/controllers/api/plans_controller.rb b/app/controllers/api/plans_controller.rb index 7b7f0d203..968875df3 100644 --- a/app/controllers/api/plans_controller.rb +++ b/app/controllers/api/plans_controller.rb @@ -92,8 +92,6 @@ plan_file_attributes: [:id, :attachment, :_destroy], prices_attributes: [:id, :amount] ) - - @parameters end end end diff --git a/app/views/api/coupons/_coupon.json.jbuilder b/app/views/api/coupons/_coupon.json.jbuilder index 919d15b5d..d4dd4cd82 100644 --- a/app/views/api/coupons/_coupon.json.jbuilder +++ b/app/views/api/coupons/_coupon.json.jbuilder @@ -1,3 +1,4 @@ -json.extract! coupon, :id, :name, :code, :type, :percent_off, :amount_off, :valid_until, :validity_per_user, :max_usages, :active, :created_at +json.extract! coupon, :id, :name, :code, :type, :percent_off, :valid_until, :validity_per_user, :max_usages, :active, :created_at +json.amount_off (coupon.amount_off / 100.00) unless coupon.amount_off.nil? json.usages coupon.invoices.count json.status coupon.status \ No newline at end of file diff --git a/app/workers/stripe_worker.rb b/app/workers/stripe_worker.rb index d40bed32c..d3b8d0d5e 100644 --- a/app/workers/stripe_worker.rb +++ b/app/workers/stripe_worker.rb @@ -20,10 +20,14 @@ class StripeWorker stp_coupon = { id: coupon.code, duration: coupon.validity_per_user, - percent_off: coupon.percent_off, - amount_off: coupon.amount_off, - currency: Rails.application.secrets.stripe_currency, } + if coupon.type == 'percent_off' + stp_coupon[:percent_off] = coupon.percent_off + elsif coupon.type == 'amount_off' + stp_coupon[:amount_off] = coupon.amount_off + stp_coupon[:currency] = Rails.application.secrets.stripe_currency + end + unless coupon.valid_until.nil? stp_coupon[:redeem_by] = coupon.valid_until.to_i end