Class: InstantQuote::DecisionParsers::IwocaV1
- Inherits:
-
InstantQuote::DecisionParser
- Object
- InstantQuote::DecisionParser
- InstantQuote::DecisionParsers::IwocaV1
- Defined in:
- lib/instant_quote/decision_parsers/iwoca_v1.rb
Overview
Example responses:
{
"data": {
"state_key": "[FILTERED]",
"approval_requirements": [
{ "type": "enhanced_security_check", "status": "pending" }
],
"approval_status": { "status": "declined" },
"latest_approval_request": { "status": "decision_made" }
}
}
{
"data": {
"state_key": "[FILTERED]",
"approval_requirements": [
{ "type": "cc", "status": "required" },
{ "type": "enhanced_security_check", "status": "pending" }
],
"approval_status": { "status": "declined" },
"latest_approval_request": { "status": "decision_made" }
}
}
{
"data": {
"state_key": "[FILTERED]",
"approval_status": {
"approved": {
"duration": 24,
"interval": "1m",
"max_credit": 21000.0,
"min_credit": 1.0,
"rate_structures": [
{ "effective_on_day": 0, "rates": [{ "max_principal": 21000.0, "rate": 0.0515 }] }
],
"time_out": "2023-09-24T00:00:00Z",
"top_up_allowed": false
},
"status": "approved"
},
"latest_approval_request": { "status": "decision_made" }
}
}
Constant Summary collapse
- STATUSES =
{ pending: 'pending', approved: 'approved', declined: 'declined', no_decision: 'no_decision_possible', not_defined: 'not_defined' }.freeze
- LOAN_STATES =
{ ongoing: 'ongoing', ended: 'ended', topup: 'topup', pending: 'pending', overdue: 'overdue', duetoday: 'duetoday' }.freeze
Instance Attribute Summary
Attributes inherited from InstantQuote::DecisionParser
Instance Method Summary collapse
- #amount ⇒ Object
-
#amount_unformatted ⇒ Object
Only used by the new iwoca2 translator.
- #approved? ⇒ Boolean
- #credit_duration ⇒ Object
- #credit_interval ⇒ Object
- #declined? ⇒ Boolean
-
#initialize(data = {}) ⇒ IwocaV1
constructor
iwoca sends an extra “data” key, that is removed here, to avoid having to do data because it’s silly :).
- #loan_started? ⇒ Boolean
- #manual_review? ⇒ Boolean
- #monthly_interest_rate ⇒ Object
- #no_decision_possible? ⇒ Boolean
- #pending? ⇒ Boolean
- #status ⇒ Object
Constructor Details
Instance Method Details
#amount ⇒ Object
99 100 101 102 103 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 99 def amount amount_approved = status_hash.dig(:approved, :max_credit) || 0 Money.new(amount_approved * 100).format end |
#amount_unformatted ⇒ Object
Only used by the new iwoca2 translator
106 107 108 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 106 def amount_unformatted status_hash.dig(:approved, :max_credit) || 0 end |
#approved? ⇒ Boolean
79 80 81 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 79 def approved? status == STATUSES[:approved] end |
#credit_duration ⇒ Object
110 111 112 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 110 def credit_duration status_hash.dig(:approved, :duration) end |
#credit_interval ⇒ Object
114 115 116 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 114 def credit_interval status_hash.dig(:approved, :interval) end |
#declined? ⇒ Boolean
83 84 85 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 83 def declined? status == STATUSES[:declined] end |
#loan_started? ⇒ Boolean
95 96 97 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 95 def loan_started? data[:loan_status] == LOAN_STATES[:ongoing] end |
#manual_review? ⇒ Boolean
87 88 89 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 87 def manual_review? status == STATUSES[:pending] end |
#monthly_interest_rate ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 118 def monthly_interest_rate rates = status_hash.dig(:approved, :rate_structures) return 0 unless rates&.any? rate_info = rates.first[:rates]&.first return 0 unless rate_info rate_info[:rate] end |
#no_decision_possible? ⇒ Boolean
91 92 93 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 91 def no_decision_possible? status == STATUSES[:no_decision] end |
#pending? ⇒ Boolean
75 76 77 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 75 def pending? status == STATUSES[:not_defined] end |
#status ⇒ Object
130 131 132 |
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 130 def status status_hash[:status] || STATUSES[:not_defined] end |