Class: InstantQuote::DecisionParsers::IwocaV1

Inherits:
InstantQuote::DecisionParser show all
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

#data

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ IwocaV1

iwoca sends an extra “data” key, that is removed here, to avoid having to do data because it’s silly :)



70
71
72
73
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 70

def initialize(data = {})
  @data = super
  @data = @data[:data] if @data.key?(:data)
end

Instance Method Details

#amountObject



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_unformattedObject

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

Returns:

  • (Boolean)


79
80
81
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 79

def approved?
  status == STATUSES[:approved]
end

#credit_durationObject



110
111
112
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 110

def credit_duration
  status_hash.dig(:approved, :duration)
end

#credit_intervalObject



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

Returns:

  • (Boolean)


83
84
85
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 83

def declined?
  status == STATUSES[:declined]
end

#loan_started?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


87
88
89
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 87

def manual_review?
  status == STATUSES[:pending]
end

#monthly_interest_rateObject



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

Returns:

  • (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

Returns:

  • (Boolean)


75
76
77
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 75

def pending?
  status == STATUSES[:not_defined]
end

#statusObject



130
131
132
# File 'lib/instant_quote/decision_parsers/iwoca_v1.rb', line 130

def status
  status_hash[:status] || STATUSES[:not_defined]
end