iwoca 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/README.md +65 -17
- data/bin/console +9 -0
- data/iwoca.gemspec +1 -0
- data/lib/iwoca/application.rb +60 -0
- data/lib/iwoca/application_generator.rb +30 -0
- data/lib/iwoca/connection.rb +8 -3
- data/lib/iwoca/customer.rb +30 -0
- data/lib/iwoca/customer_generator.rb +28 -35
- data/lib/iwoca/schemas/customer_payload.json +542 -0
- data/lib/iwoca/schemas/last_12_months_turnover.json +15 -0
- data/lib/iwoca/schemas/requested_product.json +80 -0
- data/lib/iwoca/version.rb +1 -1
- data/lib/iwoca/webhooks.rb +102 -0
- data/lib/iwoca.rb +16 -1
- metadata +23 -3
- data/lib/iwoca/quote.rb +0 -43
@@ -0,0 +1,102 @@
|
|
1
|
+
module Iwoca
|
2
|
+
# For more information about webhooks, see:
|
3
|
+
# https://iwoca.stoplight.io/docs/lapi-notifications/branches/2.0.0/ZG9jOjI4NzI5MTI5-webhooks-configuration
|
4
|
+
class Webhooks
|
5
|
+
def self.connection
|
6
|
+
@connection ||= Connection.new('notifications')
|
7
|
+
end
|
8
|
+
|
9
|
+
# Will return a payload that looks like this:
|
10
|
+
#
|
11
|
+
# {
|
12
|
+
# "data": {
|
13
|
+
# "webhook_url": "https://app.finpoint.co.uk/fast_lender_webhooks/iwoca_event",
|
14
|
+
# "webhook_secret_token": "cddafc72e1bca9b33d7ee922a95ae3fdcdf4f37c",
|
15
|
+
# "encryption_method": "sha256"
|
16
|
+
# }
|
17
|
+
# }
|
18
|
+
def self.configuration
|
19
|
+
connection.get('configuration/')
|
20
|
+
end
|
21
|
+
|
22
|
+
# Setup a webhook, the params is a payload that looks like this:
|
23
|
+
#
|
24
|
+
# {
|
25
|
+
# "data": {
|
26
|
+
# "regenerate_webhook_secret_token": true,
|
27
|
+
# "webhook_url": "string"
|
28
|
+
# }
|
29
|
+
# }
|
30
|
+
def self.update(config:)
|
31
|
+
connection.put('configuration/', config)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Get a list of the possible event types
|
35
|
+
#
|
36
|
+
# {
|
37
|
+
# "data": {
|
38
|
+
# "webhook_event_types": [
|
39
|
+
# "approval_status_changed",
|
40
|
+
# "customer_funded",
|
41
|
+
# "application_offered",
|
42
|
+
# "application_declined",
|
43
|
+
# "application_deferred",
|
44
|
+
# "cashflow_added",
|
45
|
+
# "mca_context_changed",
|
46
|
+
# "bank_account_setup",
|
47
|
+
# "application_status_changed",
|
48
|
+
# "application_attributed"
|
49
|
+
# ]
|
50
|
+
# }
|
51
|
+
# }
|
52
|
+
def self.event_types
|
53
|
+
connection.get('webhook_event_types/')
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.subscribe(event_types:)
|
57
|
+
json = { data: { subscriptions: [] }}
|
58
|
+
|
59
|
+
subscriptions = event_types.map do |event_type|
|
60
|
+
{ webhook_event_type: event_type }
|
61
|
+
end
|
62
|
+
|
63
|
+
json[:data][:subscriptions] = subscriptions
|
64
|
+
|
65
|
+
connection.post('subscriptions/', json)
|
66
|
+
end
|
67
|
+
|
68
|
+
{
|
69
|
+
"data": {
|
70
|
+
"webhook_event_types": [
|
71
|
+
"approval_status_changed"
|
72
|
+
]
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
def self.unsubscribe(event_types:)
|
77
|
+
json = {}
|
78
|
+
connection.delete('subscriptions/', json)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Returns the active subscriptions in a payload like this:
|
82
|
+
# {
|
83
|
+
# "data": {
|
84
|
+
# "subscriptions": [
|
85
|
+
# { "webhook_event_type": "approval_status_changed", "url": null, "subscribed": true },
|
86
|
+
# { "webhook_event_type": "customer_funded", "url": null, "subscribed": true },
|
87
|
+
# { "webhook_event_type": "application_offered", "url": null, "subscribed": true },
|
88
|
+
# { "webhook_event_type": "application_declined", "url": null, "subscribed": true },
|
89
|
+
# { "webhook_event_type": "application_deferred", "url": null, "subscribed": true },
|
90
|
+
# { "webhook_event_type": "cashflow_added", "url": null, "subscribed": true },
|
91
|
+
# { "webhook_event_type": "mca_context_changed", "url": null, "subscribed": true },
|
92
|
+
# { "webhook_event_type": "bank_account_setup", "url": null, "subscribed": true },
|
93
|
+
# { "webhook_event_type": "application_status_changed", "url": null, "subscribed": true },
|
94
|
+
# { "webhook_event_type": "application_attributed", "url": null, "subscribed": true }
|
95
|
+
# ]
|
96
|
+
# }
|
97
|
+
# }
|
98
|
+
def self.subscriptions
|
99
|
+
connection.get('subscriptions/')
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/iwoca.rb
CHANGED
@@ -4,7 +4,10 @@ require 'iwoca/version'
|
|
4
4
|
require 'iwoca/path_sanitizer'
|
5
5
|
require 'iwoca/configuration'
|
6
6
|
require 'iwoca/connection'
|
7
|
-
require 'iwoca/
|
7
|
+
require 'iwoca/customer'
|
8
|
+
require 'iwoca/application'
|
9
|
+
require 'iwoca/webhooks'
|
10
|
+
require 'rainbow'
|
8
11
|
|
9
12
|
module Iwoca
|
10
13
|
module_function
|
@@ -17,6 +20,18 @@ module Iwoca
|
|
17
20
|
@connection ||= Connection.new
|
18
21
|
end
|
19
22
|
|
23
|
+
def authentication_check
|
24
|
+
response = connection.get('/authentication_check/')
|
25
|
+
|
26
|
+
if response.success?
|
27
|
+
puts Rainbow("Authentication check successful: #{response.body.to_json}").green.bright
|
28
|
+
else
|
29
|
+
puts Rainbow("Authentication check failed: #{response.body.to_json}").red.bright
|
30
|
+
end
|
31
|
+
|
32
|
+
response.success?
|
33
|
+
end
|
34
|
+
|
20
35
|
def configure
|
21
36
|
yield(configuration)
|
22
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iwoca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rikas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json-schema
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Iwoca API wrapper
|
56
70
|
email:
|
57
71
|
- oterosantos@gmail.com
|
@@ -72,13 +86,19 @@ files:
|
|
72
86
|
- bin/setup
|
73
87
|
- iwoca.gemspec
|
74
88
|
- lib/iwoca.rb
|
89
|
+
- lib/iwoca/application.rb
|
90
|
+
- lib/iwoca/application_generator.rb
|
75
91
|
- lib/iwoca/configuration.rb
|
76
92
|
- lib/iwoca/connection.rb
|
93
|
+
- lib/iwoca/customer.rb
|
77
94
|
- lib/iwoca/customer_generator.rb
|
78
95
|
- lib/iwoca/path_sanitizer.rb
|
79
|
-
- lib/iwoca/quote.rb
|
80
96
|
- lib/iwoca/response.rb
|
97
|
+
- lib/iwoca/schemas/customer_payload.json
|
98
|
+
- lib/iwoca/schemas/last_12_months_turnover.json
|
99
|
+
- lib/iwoca/schemas/requested_product.json
|
81
100
|
- lib/iwoca/version.rb
|
101
|
+
- lib/iwoca/webhooks.rb
|
82
102
|
- vcr_cassettes/approval_invalid.yml
|
83
103
|
- vcr_cassettes/approval_valid.yml
|
84
104
|
- vcr_cassettes/create_customer_invalid.yml
|
data/lib/iwoca/quote.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Iwoca
|
4
|
-
class Quote
|
5
|
-
# The POST request should be used to create an iwoca account for the customer. It's always the
|
6
|
-
# first endpoint and method you should call when submitting a new customer. It returns a
|
7
|
-
# state_key used to identify the customer in all future requests. Almost all fields in the
|
8
|
-
# State are optional since you can submit a partial application initially, then add or update
|
9
|
-
# data over time (through the PUT method). Your iwoca contact will be able to give you details
|
10
|
-
# on which fields are recommended to help us make a lending decision.
|
11
|
-
def self.create_customer(params)
|
12
|
-
Iwoca.connection.post('state/', params)
|
13
|
-
end
|
14
|
-
|
15
|
-
# The PUT request should be used to add or update data for a customer. Note that the entire
|
16
|
-
# State should be submitted each time you use this endpoint, even if you are just updating a
|
17
|
-
# few fields.
|
18
|
-
def self.update_customer(state_key, params)
|
19
|
-
Iwoca.connection.put("state/#{state_key}/", params)
|
20
|
-
end
|
21
|
-
|
22
|
-
# This method should be used when a decision needs to be made for a customer. It doesn't expect
|
23
|
-
# any payload, all needed information should have been provided in the state of the customer.
|
24
|
-
def self.approval(state_key)
|
25
|
-
Iwoca.connection.post("approval_request/#{state_key}/")
|
26
|
-
end
|
27
|
-
|
28
|
-
# The GET request will return a one-time login link that the user can follow to get into
|
29
|
-
# their iwoca account (on iwoca.co.uk) without entering a password.
|
30
|
-
# You can generate multiple login links which will be active simultaneously. However, all
|
31
|
-
# links will expire when the user next logs into their iwoca account (either by following one
|
32
|
-
# of the links or by entering their username and password).
|
33
|
-
def self.login_link(state_key)
|
34
|
-
Iwoca.connection.get("login_link/#{state_key}/")
|
35
|
-
end
|
36
|
-
|
37
|
-
# The data returned contains information like approval status, loan status, repayments,
|
38
|
-
# cashflows, ...
|
39
|
-
def self.credit_facility_status(state_key)
|
40
|
-
Iwoca.connection.get("credit_facility_status/#{state_key}")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|