Class: MpApi::PaymentMethod
- Inherits:
-
Object
- Object
- MpApi::PaymentMethod
- Defined in:
- lib/mp_api/payment_method.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#installments ⇒ Object
readonly
Returns the value of attribute installments.
-
#issuer_id ⇒ Object
readonly
Returns the value of attribute issuer_id.
-
#payment_method_id ⇒ Object
readonly
Returns the value of attribute payment_method_id.
Class Method Summary collapse
- .build_hash(response, credit) ⇒ Object
- .build_query(first_six_digits) ⇒ Object
- .find_by_first_six_digits(first_six_digits, credit: true) ⇒ Object
Instance Method Summary collapse
-
#initialize(payment_method_id:, issuer_id:, installments:, errors: nil) ⇒ PaymentMethod
constructor
A new instance of PaymentMethod.
Constructor Details
#initialize(payment_method_id:, issuer_id:, installments:, errors: nil) ⇒ PaymentMethod
Returns a new instance of PaymentMethod.
4 5 6 7 8 9 |
# File 'lib/mp_api/payment_method.rb', line 4 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
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
3 4 5 |
# File 'lib/mp_api/payment_method.rb', line 3 def errors @errors end |
#installments ⇒ Object (readonly)
Returns the value of attribute installments.
3 4 5 |
# File 'lib/mp_api/payment_method.rb', line 3 def installments @installments end |
#issuer_id ⇒ Object (readonly)
Returns the value of attribute issuer_id.
3 4 5 |
# File 'lib/mp_api/payment_method.rb', line 3 def issuer_id @issuer_id end |
#payment_method_id ⇒ Object (readonly)
Returns the value of attribute payment_method_id.
3 4 5 |
# File 'lib/mp_api/payment_method.rb', line 3 def payment_method_id @payment_method_id end |
Class Method Details
.build_hash(response, credit) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mp_api/payment_method.rb', line 24 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
16 17 18 19 20 21 22 |
# File 'lib/mp_api/payment_method.rb', line 16 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
11 12 13 14 |
# File 'lib/mp_api/payment_method.rb', line 11 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 |