Class: Moneytree::PaymentGateway

Inherits:
ApplicationRecord show all
Defined in:
app/models/moneytree/payment_gateway.rb

Instance Method Summary collapse

Instance Method Details

#needs_oauth?Boolean

Returns:

  • (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)
  .send(:moneytree_oauth_callback) if .respond_to?(:moneytree_oauth_callback, true)
end

#payment_providerObject



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

Returns:

  • (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

Returns:

  • (Boolean)


26
27
28
# File 'app/models/moneytree/payment_gateway.rb', line 26

def scope_correct?
  psp_credentials[:scope] == payment_provider.scope
end