Class: Moneytree::PaymentGateway
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Moneytree::PaymentGateway
- Defined in:
- app/models/moneytree/payment_gateway.rb
Instance Method Summary collapse
- #needs_oauth? ⇒ Boolean
- #oauth_callback(params) ⇒ Object
- #payment_provider ⇒ Object
- #psp_connected? ⇒ Boolean
- #scope_correct? ⇒ Boolean
Instance Method Details
#needs_oauth? ⇒ Boolean
22 23 24 |
# File 'app/models/moneytree/payment_gateway.rb', line 22 def needs_oauth? !psp_connected? || !scope_correct? end |
#oauth_callback(params) ⇒ Object
13 14 15 16 |
# File 'app/models/moneytree/payment_gateway.rb', line 13 def oauth_callback(params) update! psp_credentials: payment_provider.get_access_token(params) account.send(:moneytree_oauth_callback) if account.respond_to?(:moneytree_oauth_callback, true) end |
#payment_provider ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/moneytree/payment_gateway.rb', line 30 def payment_provider @payment_provider ||= case psp when 'stripe' # TODO: see if we only need to pass credentials Moneytree::PaymentProvider::Stripe.new(self) # when 'square' # Moneytree::PaymentProvider::Square.new(self) else raise 'BOOM' end end |
#psp_connected? ⇒ Boolean
18 19 20 |
# File 'app/models/moneytree/payment_gateway.rb', line 18 def psp_connected? psp.present? && psp_credentials.present? end |
#scope_correct? ⇒ Boolean
26 27 28 |
# File 'app/models/moneytree/payment_gateway.rb', line 26 def scope_correct? psp_credentials[:scope] == payment_provider.scope end |