Class: MpApi::PaymentError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_response:) ⇒ PaymentError

Returns a new instance of PaymentError.



4
5
6
# File 'lib/mp_api/payment_error.rb', line 4

def initialize(json_response:)
  @json_response = json_response
end

Instance Attribute Details

#json_responseObject (readonly)

Returns the value of attribute json_response.



3
4
5
# File 'lib/mp_api/payment_error.rb', line 3

def json_response
  @json_response
end

Instance Method Details

#errorObject



8
9
10
11
# File 'lib/mp_api/payment_error.rb', line 8

def error
  return nil unless json_response["error"] || ["rejected"].include?(json_response["status"])
  rejected_payment_error || failed_payment_error || "Pagamento recusado."
end

#internal_errorObject



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

def internal_error
  return nil unless json_response["error"]
  json_response["cause"]&.first["description"]
end