instant_quote 1.7.18 → 1.7.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea32f26600ebacbcea2bbb802e81cfdfdbc6f3fd8a63c5114450bd757aa7bcfe
4
- data.tar.gz: 3690d3afa1a8bef07787712907ae74e68141ff948191aec6dc15515ef56733eb
3
+ metadata.gz: 2b94c442934e40507587cd652e9ec9683419ce66c75d2166e7ac8c5aef42fc52
4
+ data.tar.gz: 3f58db1c317c52cf60ab2b8ab18b7f70964621698eb867484c5cc9bca9270c63
5
5
  SHA512:
6
- metadata.gz: a6ae792406151bc13bbd707f7bcc70f1baeb45a3e3c358fed1a528be3b0099e747c976ef056307170e636fcbe0d28e09cef9b0e79480e690c9aed95889fc1672
7
- data.tar.gz: 5ed602cde2830a7a84225605a44bd68f6573fddaaf905617130b0da9d931c9a752edfab2880e07e64ba95d6dab6638160cb95679a565c5d6d2469f54d42351e0
6
+ metadata.gz: 5e8d155b93561766d13ff661689591bdd6e76da37b3843e7e46bc800e7adfe6c662c6bd2cbe268b62d917e0bb8e150df9fede107d6252060bce2a860553a1fb5
7
+ data.tar.gz: 1d703f56473a6c3b3b851725ca36494c0e5c6fb1185d2460fcbd4f45f07403eb894c6807a97d9b474d553499d7b864f68726c7241859985a33b2504e1c9878bf
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- instant_quote (1.7.18)
4
+ instant_quote (1.7.19)
5
5
  activesupport
6
6
  capital_on_tap (~> 1.0.1)
7
7
  iwoca (~> 1.1.0)
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InstantQuote
4
+ module DecisionParsers
5
+ # Example response:
6
+ #
7
+ # { data:
8
+ # {
9
+ # balance: {
10
+ # principal: 0.0, interest: 0.0, product_fees: 0.0, other_fees: 0.0, total: 0.0
11
+ # },
12
+ # latest_approval_request: { status: "no_decision_possible" },
13
+ # approval_requirements: [
14
+ # { type: "cc", status: "required" },
15
+ # { type: "bus_cc", status: "required" },
16
+ # { type: "dir_guarantor", status: "required" },
17
+ # { type: "enhanced_security_check", status: "pending" }
18
+ # ],
19
+ # funding_requirements: [
20
+ # { status: "required", type: "fraud" },
21
+ # { type: "docs", status: "required" },
22
+ # { type: "enhanced_security_check", status: "pending" }
23
+ # ]
24
+ # }
25
+ # }
26
+ class IwocaWebhook < DecisionParser
27
+ STATUSES = {
28
+ pending: 'pending',
29
+ approved: 'approved',
30
+ declined: 'declined',
31
+ no_decision: 'no_decision_possible',
32
+ not_defined: 'not_defined'
33
+ }.freeze
34
+
35
+ LOAN_STATES = {
36
+ ongoing: 'ongoing',
37
+ ended: 'ended',
38
+ topup: 'topup',
39
+ pending: 'pending',
40
+ overdue: 'overdue',
41
+ duetoday: 'duetoday'
42
+ }.freeze
43
+
44
+ # iwoca sends an extra "data" key, that is removed here, to avoid having to do data[:data]
45
+ # because it's silly :)
46
+ def initialize(data = {})
47
+ @data = super
48
+ @data = @data[:data] if @data.key?(:data)
49
+ end
50
+
51
+ def pending?
52
+ status == STATUSES[:not_defined]
53
+ end
54
+
55
+ def approved?
56
+ status == STATUSES[:approved]
57
+ end
58
+
59
+ def declined?
60
+ status == STATUSES[:declined]
61
+ end
62
+
63
+ def manual_review?
64
+ status == STATUSES[:pending]
65
+ end
66
+
67
+ def no_decision_possible?
68
+ status == STATUSES[:no_decision]
69
+ end
70
+
71
+ def loan_started?
72
+ data[:loan_status] == LOAN_STATES[:ongoing]
73
+ end
74
+
75
+ def amount
76
+ amount_approved = status_hash.dig(:approved, :max_credit) || 0
77
+
78
+ Money.new(amount_approved * 100).format
79
+ end
80
+
81
+ def credit_duration
82
+ status_hash.dig(:approved, :duration)
83
+ end
84
+
85
+ def credit_interval
86
+ status_hash.dig(:approved, :interval)
87
+ end
88
+
89
+ def monthly_interest_rate
90
+ rates = status_hash.dig(:approved, :rate_structures)
91
+
92
+ return 0 unless rates&.any?
93
+
94
+ rate_info = rates.first[:rates]&.first
95
+
96
+ return 0 unless rate_info
97
+
98
+ rate_info[:rate]
99
+ end
100
+
101
+ def status
102
+ status_hash[:status] || STATUSES[:not_defined]
103
+ end
104
+
105
+ private
106
+
107
+ def status_hash
108
+ data[:approval_status] || data[:latest_approval_request] || {}
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module InstantQuote
4
- VERSION = '1.7.18'
4
+ VERSION = '1.7.19'
5
5
  end
@@ -42,6 +42,24 @@ module InstantQuote
42
42
  request.headers[SIGNATURE_HEADER]
43
43
  end
44
44
 
45
+ # The list of possible event types is:
46
+ # approval_status_changed
47
+ # customer_funded
48
+ # application_offered
49
+ # application_declined
50
+ # application_deferred
51
+ # cashflow_added
52
+ # mca_context_changed
53
+ # bank_account_setup
54
+ # application_status_changed
55
+ # application_attributed
56
+ # indicative_offer_created
57
+ # shopify_payment_resolve
58
+ # shopify_payment_reject
59
+ # shopify_refund_resolve
60
+ #
61
+ # More info:
62
+ # https://iwoca.stoplight.io/docs/lapi-notifications/b59ca8c181611-get-available-webhook-event-types
45
63
  def iwoca_event_type
46
64
  # Allowed Values: approval_status_changed, instruct_payments, customer_funded
47
65
  request.headers[EVENT_TYPE_HEADER]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instant_quote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.18
4
+ version: 1.7.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - rikas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-24 00:00:00.000000000 Z
11
+ date: 2023-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -158,6 +158,7 @@ files:
158
158
  - lib/instant_quote/decision_parsers/iwoca_flexi24.rb
159
159
  - lib/instant_quote/decision_parsers/iwoca_recovery_loans.rb
160
160
  - lib/instant_quote/decision_parsers/iwoca_revenue_based_loans.rb
161
+ - lib/instant_quote/decision_parsers/iwoca_webhook.rb
161
162
  - lib/instant_quote/decision_parsers/optimum.rb
162
163
  - lib/instant_quote/decision_parsers/youlend.rb
163
164
  - lib/instant_quote/version.rb