mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
do not run StripeWorker tasks is the gateway is not enabled
This commit is contained in:
parent
e7059cca5b
commit
4d3ead310d
@ -2,6 +2,7 @@
|
||||
|
||||
# API Controller for handling the payments process in the front-end, using the Stripe gateway
|
||||
class API::StripeController < API::PaymentsController
|
||||
require 'stripe/helper'
|
||||
|
||||
##
|
||||
# Client requests to confirm a card payment will ask this endpoint.
|
||||
@ -9,7 +10,7 @@ class API::StripeController < API::PaymentsController
|
||||
# was successfully made. After the payment was made, the reservation/subscription will be created
|
||||
##
|
||||
def confirm_payment
|
||||
render(json: { error: 'Online payment is disabled' }, status: :unauthorized) and return unless Setting.get('online_payment_module')
|
||||
render(json: { error: 'Bad gateway or online payment is disabled' }, status: :bad_gateway) and return unless Stripe::Helper.enabled?
|
||||
|
||||
amount = nil # will contains the amount and the details of each invoice lines
|
||||
intent = nil # stripe's payment intent
|
||||
|
@ -2,10 +2,13 @@
|
||||
|
||||
# This worker perform various requests to the Stripe API (payment service)
|
||||
class StripeWorker
|
||||
require 'stripe/helper'
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options queue: :stripe
|
||||
|
||||
def perform(action, *params)
|
||||
return false unless Stripe::Helper.enabled?
|
||||
|
||||
send(action, *params)
|
||||
end
|
||||
|
||||
|
21
lib/stripe/helper.rb
Normal file
21
lib/stripe/helper.rb
Normal file
@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Stripe payement gateway
|
||||
module Stripe; end
|
||||
|
||||
## Provides various methods around the Stripe payment gateway
|
||||
class Stripe::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|
|
||||
res = false unless Setting.get(pz_setting).present?
|
||||
end
|
||||
res
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user