Module: Od::Payments

Defined in:
lib/od/payments.rb,
lib/od/payments/errors.rb,
lib/od/payments/version.rb,
lib/od/payments/resources/charge.rb,
lib/od/payments/resources/customer.rb,
lib/od/payments/resources/payment_method.rb

Defined Under Namespace

Modules: Charge, Customer, PaymentMethod Classes: APIError, AuthenticationError, CardError, OdPaymentsError

Constant Summary collapse

ADAPTERS =
%i[stripe square].freeze
VERSION =
"0.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.access_token_squareObject

Returns the value of attribute access_token_square.



11
12
13
# File 'lib/od/payments.rb', line 11

def access_token_square
  @access_token_square
end

.api_key_stripeObject

Returns the value of attribute api_key_stripe.



10
11
12
# File 'lib/od/payments.rb', line 10

def api_key_stripe
  @api_key_stripe
end

.client_squareObject

Returns the value of attribute client_square.



13
14
15
# File 'lib/od/payments.rb', line 13

def client_square
  @client_square
end

.environment_squareObject

Returns the value of attribute environment_square.



12
13
14
# File 'lib/od/payments.rb', line 12

def environment_square
  @environment_square
end

.productionObject

Returns the value of attribute production.



14
15
16
# File 'lib/od/payments.rb', line 14

def production
  @production
end

Class Method Details

.adapterObject



45
46
47
48
49
50
# File 'lib/od/payments.rb', line 45

def adapter
  return @adapter if @adapter

  self.adapter = :stripe
  @adapter
end

.adapter=(adapter) ⇒ Object



52
53
54
55
56
# File 'lib/od/payments.rb', line 52

def adapter=(adapter)
  raise Od::Payments::APIError, 'Invalid Adapter' if adapter.class != Symbol || !ADAPTERS.include?(adapter)

  @adapter = adapter
end

.configure(adapter, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/od/payments.rb', line 16

def configure(adapter, options = {})
  self.adapter = adapter
  @api_key_stripe = options[:api_key_stripe]
  @access_token_square = options[:access_token_square]
  @environment_square = options[:environment_square]
  @production = options[:production]
  initializate_stripe if validate_stripe
  initializate_square if validate_square
end

.initializate_squareObject



38
39
40
41
42
43
# File 'lib/od/payments.rb', line 38

def initializate_square
  @client_square = Square::Client.new(
    access_token: access_token_square,
    environment: production ? 'production' : 'sandbox'
)
end

.initializate_stripeObject



34
35
36
# File 'lib/od/payments.rb', line 34

def initializate_stripe
  Stripe.api_key = api_key_stripe
end

.validate_squareObject



30
31
32
# File 'lib/od/payments.rb', line 30

def validate_square
  !access_token_square.nil? || !access_token_square&.strip&.empty?
end

.validate_stripeObject



26
27
28
# File 'lib/od/payments.rb', line 26

def validate_stripe
  !api_key_stripe.nil? && !api_key_stripe&.strip&.empty?
end