mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
fix cash coupon creation on stripe + store amount in centimes
This commit is contained in:
parent
2a029255c9
commit
cc06bcab85
@ -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
|
||||
|
@ -92,8 +92,6 @@
|
||||
plan_file_attributes: [:id, :attachment, :_destroy],
|
||||
prices_attributes: [:id, :amount]
|
||||
)
|
||||
|
||||
@parameters
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -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
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user