Class: MpApi::PaymentMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/mp_api/payment_method.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payment_method_id:, issuer_id:, installments:) ⇒ PaymentMethod

Returns a new instance of PaymentMethod.



33
34
35
36
37
# File 'lib/mp_api/payment_method.rb', line 33

def initialize(payment_method_id: , issuer_id: , installments:)
  @payment_method_id = payment_method_id
  @issuer_id = issuer_id
  @installments = installments
end

Instance Attribute Details

#installmentsObject (readonly)

Returns the value of attribute installments.



32
33
34
# File 'lib/mp_api/payment_method.rb', line 32

def installments
  @installments
end

#issuer_idObject (readonly)

Returns the value of attribute issuer_id.



32
33
34
# File 'lib/mp_api/payment_method.rb', line 32

def issuer_id
  @issuer_id
end

#payment_method_idObject (readonly)

Returns the value of attribute payment_method_id.



32
33
34
# File 'lib/mp_api/payment_method.rb', line 32

def payment_method_id
  @payment_method_id
end

Class Method Details

.build_hash(response, credit) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/mp_api/payment_method.rb', line 22

def self.build_hash(response, credit)
  payment_type_id = credit ? 'credit_card' : 'debit_card'
  payment_method = response.dig('results').find {|pm| pm['payment_type_id'] == payment_type_id}
  {
    payment_method_id: payment_method.dig('id'),
    issuer_id: payment_method.dig('issuer', 'id'),
    installments: payment_method.dig('payer_costs')
  }
end

.build_query(first_six_digits) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/mp_api/payment_method.rb', line 14

def self.build_query(first_six_digits)
  {
    marketplace: 'NONE',
    status: 'active',
    bins: first_six_digits
  }
end

.find_by_first_six_digits(first_six_digits, credit: true) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/mp_api/payment_method.rb', line 5

def self.find_by_first_six_digits(first_six_digits, credit: true)
  begin
    response = Client.new.search_payment_methods(build_query(first_six_digits))
  rescue RuntimeError => e
    e.message == 'Too many retries' ? raise(TooManyRequestsError) : raise(e)
  end
  new(**build_hash(response, credit))
end