1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-13 23:48:55 +01:00
fab-manager/lib/stripe/helper.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2022-09-28 12:54:29 +02:00
require 'payment/helper'
# Stripe payement gateway
module Stripe; end
## Provides various methods around the Stripe payment gateway
2022-09-28 12:54:29 +02:00
class Stripe::Helper < Payment::Helper
class << self
## Is the Stripe gateway enabled?
def enabled?
return false unless Setting.get('online_payment_module')
return false unless Setting.get('payment_gateway') == 'stripe'
res = true
%w[stripe_public_key stripe_secret_key stripe_currency].each do |pz_setting|
2022-09-28 12:54:29 +02:00
res = false if Setting.get(pz_setting).blank?
end
res
end
2022-09-28 12:54:29 +02:00
def human_error(error)
message = error.message
case error.code
when 'amount_too_small'
message.match(/\d+\.\d+\s\w+/) do |res|
2023-02-24 17:26:55 +01:00
message = I18n.t('errors.messages.gateway_amount_too_small', **{ AMOUNT: res })
2022-09-28 12:54:29 +02:00
end
when 'amount_too_large'
message.match(/\d+\.\d+\s\w+/) do |res|
2023-02-24 17:26:55 +01:00
message = I18n.t('errors.messages.gateway_amount_too_large', **{ AMOUNT: res })
2022-09-28 12:54:29 +02:00
end
else
2023-02-24 17:26:55 +01:00
message = I18n.t('errors.messages.gateway_error', **{ MESSAGE: message })
2022-09-28 12:54:29 +02:00
end
message
end
end
end