Module: Accountability::ActiveMerchantInterface::StripeInterface

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/accountability/active_merchant_interface/stripe_interface.rb

Instance Method Summary collapse

Instance Method Details

#charge(amount) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/concerns/accountability/active_merchant_interface/stripe_interface.rb', line 17

def charge(amount)
  gateway = initialize_payment_gateway
  amount_in_cents = (amount * 100).round
  card_id = active_merchant_data['authorization']

  response = gateway.purchase(amount_in_cents, card_id)

  return true if response.success?

  error_code = response.error_code || I18n.t('accountability.gateway.errors.unknown_gateway_error')
  stripe_api_errors.append(error_code)
  false
end

#store_active_merchant_data(**options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/concerns/accountability/active_merchant_interface/stripe_interface.rb', line 31

def store_active_merchant_data(**options)
  response = store_card_in_gateway

  unless response.success?
    error_code = response.error_code || I18n.t('accountability.gateway.errors.unknown_gateway_error')
    stripe_api_errors.append(error_code)
    return
  end

  active_merchant_data = extract_active_merchant_data(response)
  validate_chargeable(**active_merchant_data) if options.fetch(:verify_card)

  self.active_merchant_data = active_merchant_data
end