1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

[bug] zero-decimal currencies w/ stripe

This commit is contained in:
Sylvain 2021-05-26 13:38:16 +02:00
parent 4e601b672a
commit 413bb57c38
3 changed files with 16 additions and 3 deletions

View File

@ -2,6 +2,7 @@
- Updated ffi to 1.15.1
- Updated GitHub issue templates
- Fix a bug: zero-decimal currencies were charged multiplied by 100
- Fix a bug: fablab:fix_invoices task fails to recreate the data if the date is in english
## v4.7.10 2021 May 25

View File

@ -26,7 +26,7 @@ class API::PaymentsController < API::ApiController
intent = Stripe::PaymentIntent.create(
{
payment_method: params[:payment_method_id],
amount: amount[:amount],
amount: StripeService.stripe_amount(amount[:amount]),
currency: Setting.get('stripe_currency'),
confirmation_method: 'manual',
confirm: true,

View File

@ -50,7 +50,7 @@ class StripeService
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[:amount_off] = stripe_amount(coupon.amount_off)
stp_coupon[:currency] = Setting.get('stripe_currency')
end
@ -61,6 +61,13 @@ class StripeService
Stripe::Coupon.create(stp_coupon, api_key: Setting.get('stripe_secret_key'))
end
def stripe_amount(amount)
currency = Setting.get('stripe_currency')
return amount / 100 if zero_decimal_currencies.any? { |s| s.casecmp(currency).zero? }
amount
end
private
def subscription_invoice_items(payment_schedule, subscription, first_item, reservable_stp_id)
@ -91,7 +98,7 @@ class StripeService
def create_price(amount, stp_product_id, name, monthly: false)
params = {
unit_amount: amount,
unit_amount: stripe_amount(amount),
currency: Setting.get('stripe_currency'),
product: stp_product_id,
nickname: name
@ -107,5 +114,10 @@ class StripeService
customer_id = payment_schedule.invoicing_profile.user.stp_customer_id
Stripe::Customer.update(customer_id, { balance: -payment_schedule.wallet_amount }, { api_key: Setting.get('stripe_secret_key') })
end
# @see https://stripe.com/docs/currencies#zero-decimal
def zero_decimal_currencies
%w[BIF CLP DJF GNF JPY KMF KRW MGA PYG RWF UGX VND VUV XAF XOF XPF]
end
end
end