mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
[bug] payzen amount for non 2-decimals currencies
This commit is contained in:
parent
1237870450
commit
d0eebddcee
@ -6,6 +6,7 @@
|
||||
- The upgrade script will check and report the ability to access the hub API
|
||||
- Fix a bug: missing translations
|
||||
- Fix a bug: the upgrade script report an invalid version to upgrade to
|
||||
- Fix a bug: invalid amount provided to the PayZen payment gateway when using a currency with anything else than 2 decimals
|
||||
- Updated @rails/webpacker to 5.4.3
|
||||
- Updated react-refresh-webpack-plugin to 0.5.1
|
||||
- Updated react-refresh to 0.10.0
|
||||
|
@ -25,7 +25,7 @@ class API::PayzenController < API::PaymentsController
|
||||
@id = PayZen::Helper.generate_ref(params[:cart_items], params[:customer_id])
|
||||
|
||||
client = PayZen::Charge.new
|
||||
@result = client.create_payment(amount: amount[:amount],
|
||||
@result = client.create_payment(amount: PayZen::Service.new.payzen_amount(amount[:amount]),
|
||||
order_id: @id,
|
||||
customer: PayZen::Helper.generate_customer(params[:customer_id], current_user.id, params[:cart_items]))
|
||||
rescue PayzenError => e
|
||||
|
@ -18,14 +18,14 @@ class PayZen::Service < Payment::Service
|
||||
token_id = order['answer']['transactions'].first['paymentMethodToken']
|
||||
|
||||
params = {
|
||||
amount: first_item.details['recurring'].to_i,
|
||||
amount: payzen_amount(first_item.details['recurring'].to_i),
|
||||
effect_date: first_item.due_date.iso8601,
|
||||
payment_method_token: token_id,
|
||||
rrule: rrule(payment_schedule),
|
||||
order_id: order_id
|
||||
}
|
||||
unless first_item.details['adjustment']&.zero? && first_item.details['other_items']&.zero?
|
||||
params[:initial_amount] = first_item.amount
|
||||
params[:initial_amount] = payzen_amount(first_item.amount)
|
||||
params[:initial_amount_number] = 1
|
||||
end
|
||||
pz_subscription = client.create_subscription(params)
|
||||
@ -81,6 +81,14 @@ class PayZen::Service < Payment::Service
|
||||
end
|
||||
end
|
||||
|
||||
def payzen_amount(amount)
|
||||
currency = Setting.get('payzen_currency')
|
||||
return amount / 100 if zero_decimal_currencies.any? { |s| s.casecmp(currency).zero? }
|
||||
return amount * 10 if three_decimal_currencies.any? { |s| s.casecmp(currency).zero? }
|
||||
|
||||
amount
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rrule(payment_schedule)
|
||||
@ -96,4 +104,13 @@ class PayZen::Service < Payment::Service
|
||||
transaction_date >= payment_schedule_item.due_date.to_date &&
|
||||
transaction_date <= payment_schedule_item.due_date.to_date + 7.days
|
||||
end
|
||||
|
||||
# @see https://payzen.io/en-EN/payment-file/ips/list-of-supported-currencies.html
|
||||
def zero_decimal_currencies
|
||||
%w[KHR JPY KRW XOF XPF]
|
||||
end
|
||||
|
||||
def three_decimal_currencies
|
||||
%w[KWD TND]
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user