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:, errors: nil) ⇒ PaymentMethod

Returns a new instance of PaymentMethod.



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

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

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/mp_api/payment_method.rb', line 5

def errors
  @errors
end

#installmentsObject (readonly)

Returns the value of attribute installments.



5
6
7
# File 'lib/mp_api/payment_method.rb', line 5

def installments
  @installments
end

#issuer_idObject (readonly)

Returns the value of attribute issuer_id.



5
6
7
# File 'lib/mp_api/payment_method.rb', line 5

def issuer_id
  @issuer_id
end

#payment_method_idObject (readonly)

Returns the value of attribute payment_method_id.



5
6
7
# File 'lib/mp_api/payment_method.rb', line 5

def payment_method_id
  @payment_method_id
end

Class Method Details

.build_hash(response, credit) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/mp_api/payment_method.rb', line 26

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'),
    errors: response.dig('message')
  }
end

.build_query(first_six_digits) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/mp_api/payment_method.rb', line 18

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



13
14
15
16
# File 'lib/mp_api/payment_method.rb', line 13

def self.find_by_first_six_digits(first_six_digits, credit: true)
  response = Client.new.search_payment_methods(build_query(first_six_digits))
  new(**build_hash(response.json, credit))
end