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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 198e9be11e22df1a0eeaaf7aeadf91a8d915890c83c034232f6c4f6bdf950d6b
|
4
|
+
data.tar.gz: 36a2b9b54228c00b077e2bb8a4f4be34e3f71b32631ae90a23fbc5a1d88c32a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9551708a25561b0ea8355ad4372e6fb65161d9e2b0ad418d48938fab648efe07b26d5191d8b80b99151f206873bef71662c7ad96485dd864629e03ac9f6ae446
|
7
|
+
data.tar.gz: 4683b1b27606c672d0feecc6c1160ec51218b223f57c253f4e4a266544587dba07393f6465752a916b0bf6788d2e24050d4252d7a410d0c55ad952bd96d46cbe
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iwoca (1.0
|
4
|
+
iwoca (1.1.0)
|
5
5
|
addressable
|
6
6
|
faraday (~> 2.7)
|
7
|
+
json-schema
|
7
8
|
rainbow
|
8
9
|
|
9
10
|
GEM
|
@@ -30,6 +31,8 @@ GEM
|
|
30
31
|
i18n (1.12.0)
|
31
32
|
concurrent-ruby (~> 1.0)
|
32
33
|
json (2.6.3)
|
34
|
+
json-schema (4.0.0)
|
35
|
+
addressable (>= 2.8)
|
33
36
|
method_source (1.0.0)
|
34
37
|
parallel (1.22.1)
|
35
38
|
parser (3.2.1.0)
|
data/README.md
CHANGED
@@ -36,28 +36,68 @@ Iwoca.configure do |config|
|
|
36
36
|
end
|
37
37
|
```
|
38
38
|
|
39
|
-
###
|
39
|
+
### Check authentication
|
40
40
|
|
41
|
-
|
41
|
+
To check if you're using a good API Key you can invoke the `authentication_check` endpoint by
|
42
|
+
running:
|
42
43
|
|
43
44
|
```ruby
|
44
|
-
Iwoca.
|
45
|
+
Iwoca.authentication_check
|
46
|
+
# => Authentication check successful: {"version":"v2.1"}
|
47
|
+
```
|
48
|
+
|
49
|
+
### Customer
|
50
|
+
|
51
|
+
First thing you want to do is to create a customer:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
customer_json = Iwoca::CustomerGenerator.generate # for test purposes
|
55
|
+
response = Iwoca::Customer.create(data: customer_json)
|
45
56
|
# => This will return a state_key, if the JSON is valid. You need this key to call other methods.
|
46
57
|
|
47
|
-
|
58
|
+
customer_id = response.data[:customer_id]
|
59
|
+
```
|
60
|
+
|
61
|
+
Then you can update it, if you keep track of the customer_id that is returned:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
Iwoca::Customer.update(customer_id: customer_id, data: customer_json)
|
65
|
+
```
|
66
|
+
|
67
|
+
And finally you can get a login link:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
Iwoca::Customer.login_link(customer_id: customer_id)
|
71
|
+
```
|
72
|
+
|
73
|
+
### Application
|
48
74
|
|
49
|
-
|
75
|
+
After the customer is correctly created you can create an application:
|
50
76
|
|
51
|
-
|
77
|
+
```ruby
|
78
|
+
app_json = Iwoca::ApplicationGenerator.generate # for test purposes
|
79
|
+
response = Iwoca::Application.create(customer_id: customer_id, data: app_json)
|
80
|
+
|
81
|
+
application_id = response.data[:application_id]
|
82
|
+
```
|
83
|
+
|
84
|
+
This can then be used to check the status of the latest application for a customer:
|
52
85
|
|
53
|
-
|
86
|
+
```ruby
|
87
|
+
Iwoca::Application.latest(customer_id: customer_id)
|
88
|
+
```
|
89
|
+
|
90
|
+
Or, equally important, to check the offers:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
Iwoca::Application.offers(application_id: application_id)
|
54
94
|
```
|
55
95
|
|
56
96
|
Every call will return a `Iwoca::Response` instance, that you can use to get all the information
|
57
97
|
you need:
|
58
98
|
|
59
99
|
```ruby
|
60
|
-
response = Iwoca.login_link(
|
100
|
+
response = Iwoca::Customer.login_link(customer_id: customer_id)
|
61
101
|
|
62
102
|
response.status #=> 200
|
63
103
|
response.success? #=> true
|
@@ -65,6 +105,19 @@ response.errors #=> []
|
|
65
105
|
response.data #=> { login_link: 'http://login_link' }
|
66
106
|
```
|
67
107
|
|
108
|
+
### Webhooks
|
109
|
+
|
110
|
+
Newest iwoca version has a nice way to manage the webhooks, so we can change and check the status of
|
111
|
+
webhooks at any point.
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
Iwoca::Webhooks.configuration # what's the webook url and the secret token
|
115
|
+
Iwoca::Webhooks.update(config: {}) # update webhook configuration
|
116
|
+
Iwoca::Webhooks.event_types # list the webhook event types
|
117
|
+
Iwoca::Webhooks.subscribe(event_types: []) # subscribe to an event
|
118
|
+
Iwoca::Webhooks.subscriptions # list subscriptions
|
119
|
+
```
|
120
|
+
|
68
121
|
## Development
|
69
122
|
|
70
123
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run
|
@@ -78,9 +131,9 @@ https://developer.iwoca.co.uk/lending-api-v1/testing-your-integration/core-test-
|
|
78
131
|
In `spec/data` we have the stored customer data that will return a 'approved' state. Use this to
|
79
132
|
generate valid state keys and follow their instructions to generate the other states.
|
80
133
|
|
81
|
-
###
|
134
|
+
### Webhooks
|
82
135
|
|
83
|
-
|
136
|
+
To test webhooks you may find it easier to use a test endpoint like:
|
84
137
|
https://dev-finpointdev.pagekite.me/fast_lender_webhooks/iwoca_event
|
85
138
|
|
86
139
|
How to install:
|
@@ -95,10 +148,5 @@ How to run:
|
|
95
148
|
|
96
149
|
pagekite.net details:
|
97
150
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new
|
102
|
-
version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
|
103
|
-
will create a git tag for the version, push git commits and tags, and push the `.gem` file
|
104
|
-
to [rubygems.org](https://rubygems.org).
|
151
|
+
- u: hello@finpoint.co.uk
|
152
|
+
- p: fckx7989
|
data/bin/console
CHANGED
@@ -15,8 +15,17 @@ end
|
|
15
15
|
|
16
16
|
# Useful if we need to do some tests
|
17
17
|
require 'iwoca/customer_generator'
|
18
|
+
require 'iwoca/application_generator'
|
18
19
|
|
19
20
|
send(:include, Iwoca)
|
20
21
|
|
22
|
+
def generate_customer
|
23
|
+
CustomerGenerator.generate
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate_app
|
27
|
+
ApplicationGenerator.generate
|
28
|
+
end
|
29
|
+
|
21
30
|
require 'pry'
|
22
31
|
Pry.start
|
data/iwoca.gemspec
CHANGED
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Iwoca
|
4
|
+
class Application
|
5
|
+
# This needs to be used after the customer has been created. It returns an application_id that
|
6
|
+
# can be used to identify the application in all future requests.
|
7
|
+
# The params argument needs to have the following structure:
|
8
|
+
# {
|
9
|
+
# data: {
|
10
|
+
# requests: [
|
11
|
+
# {
|
12
|
+
# amount: 15000,
|
13
|
+
# duration: {
|
14
|
+
# amount: 12,
|
15
|
+
# unit: "months"
|
16
|
+
# },
|
17
|
+
# product_type: "flexi_loan", # check the schema JSON for more options
|
18
|
+
# purpose: "equipment_purchase", # check the schema JSON for more options
|
19
|
+
# urgency: "asap"
|
20
|
+
# }
|
21
|
+
# ]
|
22
|
+
# }
|
23
|
+
# }
|
24
|
+
def self.create(customer_id:, data: {})
|
25
|
+
requests = (data.dig(:data, :requests) || []).first.to_json
|
26
|
+
|
27
|
+
# # Add the introducer so we can get a login link later
|
28
|
+
# data[:data][:introducer] = {
|
29
|
+
# entity_to_contact: 'customer',
|
30
|
+
# introducer_id: customer_id
|
31
|
+
# }
|
32
|
+
|
33
|
+
JSON::Validator.validate!('lib/iwoca/schemas/requested_product.json', requests)
|
34
|
+
|
35
|
+
Iwoca.connection.post("customers/#{customer_id}/applications/", data)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Sending across the customer_id in the URL - you will receive back an object with the latest
|
39
|
+
# application information that we have.
|
40
|
+
#
|
41
|
+
# This will include a status field that can be one of the following options:
|
42
|
+
# open, deferred, declined, offered, conditional_offer, customer_to_link_open_banking,
|
43
|
+
# action_required, awaiting_underwriter, in_underwriting, expired, funded, offer_revoked,
|
44
|
+
# talking_to_customer.
|
45
|
+
#
|
46
|
+
# Check more info in the docs:
|
47
|
+
# https://iwoca.stoplight.io/docs/lapi-uk/branches/2.1.0/84660933e0b17-get-user-latest-application
|
48
|
+
def self.latest(customer_id:)
|
49
|
+
Iwoca.connection.get("customers/#{customer_id}/applications/latest/")
|
50
|
+
end
|
51
|
+
|
52
|
+
# Use this endpoint after creating an application to generate offers that your customer is
|
53
|
+
# eligible for.
|
54
|
+
# Offers are associated with the Application, so are retrieved using the customer's current
|
55
|
+
# application_id that you would have received in the previous request.
|
56
|
+
def self.offers(application_id:)
|
57
|
+
Iwoca.connection.get("applications/#{application_id}/offers/")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal
|
2
|
+
|
3
|
+
module Iwoca
|
4
|
+
class ApplicationGenerator
|
5
|
+
def self.generate(params: {})
|
6
|
+
new(params:).generate
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(params: {})
|
10
|
+
@params = params
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate
|
14
|
+
{
|
15
|
+
data: {
|
16
|
+
last_12_months_turnover: { amount: 700000, valid_from: '2019-08-24T14:15:22Z' },
|
17
|
+
requests: [
|
18
|
+
{
|
19
|
+
amount: 15000,
|
20
|
+
product_type: 'flexi_loan',
|
21
|
+
duration: { amount: 12, unit: "months" },
|
22
|
+
purpose: 'equipment_purchase',
|
23
|
+
urgency: 'asap'
|
24
|
+
}
|
25
|
+
]
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/iwoca/connection.rb
CHANGED
@@ -8,7 +8,12 @@ require 'iwoca/response'
|
|
8
8
|
|
9
9
|
module Iwoca
|
10
10
|
class Connection
|
11
|
-
BASE_PATH = '/api/lending/
|
11
|
+
BASE_PATH = '/api/lending/v2.1'
|
12
|
+
BASE_NOTIFICATIONS_PATH = '/api/notifications/v1'
|
13
|
+
|
14
|
+
def initialize(type = 'base')
|
15
|
+
@base_path = type == 'notifications' ? BASE_NOTIFICATIONS_PATH : BASE_PATH
|
16
|
+
end
|
12
17
|
|
13
18
|
def get(path, params = {})
|
14
19
|
log "GET #{path} with #{params}"
|
@@ -49,14 +54,14 @@ module Iwoca
|
|
49
54
|
end
|
50
55
|
|
51
56
|
def base_url
|
52
|
-
Addressable::URI.join(Iwoca.configuration.api_domain,
|
57
|
+
Addressable::URI.join(Iwoca.configuration.api_domain, @base_path).to_s
|
53
58
|
end
|
54
59
|
|
55
60
|
def adapter
|
56
61
|
token = Iwoca.configuration.api_key
|
57
62
|
|
58
63
|
Faraday.new(url: base_url) do |conn|
|
59
|
-
conn.headers['Authorization'] = "
|
64
|
+
conn.headers['Authorization'] = "Bearer #{token}" unless token.to_s.empty?
|
60
65
|
conn.headers['Content-Type'] = 'application/json'
|
61
66
|
conn.headers['User-Agent'] = "ruby-iwoca-#{VERSION}"
|
62
67
|
conn.response :json, parser_options: { symbolize_names: true }
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Iwoca
|
4
|
+
class Customer
|
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
|
+
# customer_id used to identify the customer in all future requests.
|
8
|
+
#
|
9
|
+
# Successful request will return a 201 status code and a JSON response containing a customer_id:
|
10
|
+
# Example: { data: { customer_id: "fd48781e-3ad3-4a94-b4a6-60fafeebab0b" } }
|
11
|
+
def self.create(data: {})
|
12
|
+
# Validate the schema first, to avoid making a request with invalid data.
|
13
|
+
JSON::Validator.validate!('lib/iwoca/schemas/customer_payload.json', data.to_json)
|
14
|
+
|
15
|
+
Iwoca.connection.post('customers/', data)
|
16
|
+
end
|
17
|
+
|
18
|
+
# The PUT request should be used to add or update data for a customer. Note that the entire
|
19
|
+
# State should be submitted each time you use this endpoint, even if you are just updating a
|
20
|
+
# few fields.
|
21
|
+
def self.update(customer_id:, data: {})
|
22
|
+
Iwoca.connection.put("customers/#{customer_id}/", data)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get a login link for a customer from a given customer_id
|
26
|
+
def self.login_link(customer_id:)
|
27
|
+
Iwoca.connection.get("customers/#{customer_id}/login_link/")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -3,7 +3,9 @@
|
|
3
3
|
require 'faker'
|
4
4
|
|
5
5
|
module Iwoca
|
6
|
-
# This class can be used to generate fake customers for test purposes
|
6
|
+
# This class can be used to generate fake customers for test purposes.
|
7
|
+
# It is based on the minimum data requirements described here:
|
8
|
+
# https://iwoca.stoplight.io/docs/lapi-uk/branches/2.1.0/2c44db4bf20fb-meeting-minimum-data-requirements
|
7
9
|
class CustomerGenerator
|
8
10
|
attr_accessor :id, :first_name, :last_name, :email, :phone, :address, :date_of_birth, :city
|
9
11
|
attr_accessor :postcode
|
@@ -13,7 +15,7 @@ module Iwoca
|
|
13
15
|
first_name: Faker::Name.first_name,
|
14
16
|
last_name: Faker::Name.last_name,
|
15
17
|
email: Faker::Internet.email,
|
16
|
-
phone: Faker::PhoneNumber.
|
18
|
+
phone: Faker::PhoneNumber.cell_phone_in_e164,
|
17
19
|
address: Faker::Address.street_address,
|
18
20
|
date_of_birth: Faker::Date.birthday(min_age: 23, max_age: 65),
|
19
21
|
city: Faker::Address.city,
|
@@ -21,7 +23,7 @@ module Iwoca
|
|
21
23
|
}.freeze
|
22
24
|
|
23
25
|
def self.generate(params = {})
|
24
|
-
new(params).generate
|
26
|
+
new(DEFAULTS.merge(params)).generate
|
25
27
|
end
|
26
28
|
|
27
29
|
def initialize(params = {})
|
@@ -35,59 +37,50 @@ module Iwoca
|
|
35
37
|
def generate
|
36
38
|
{
|
37
39
|
data: {
|
38
|
-
|
39
|
-
|
40
|
-
people: [user_information],
|
41
|
-
requested_products: {
|
42
|
-
credit_facility: {
|
43
|
-
approval: {
|
44
|
-
amount: 123_123,
|
45
|
-
duration: 12,
|
46
|
-
detailed_purpose: 'business loan'
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}
|
40
|
+
company: company_information,
|
41
|
+
people: [user_information]
|
51
42
|
}
|
52
43
|
}
|
53
44
|
end
|
54
45
|
|
55
46
|
def company_information
|
56
47
|
{
|
48
|
+
company_number: '09525857',
|
57
49
|
last_12_months_turnover: {
|
58
|
-
amount:
|
50
|
+
amount: 70_000,
|
51
|
+
valid_from: "2019-08-24T14:15:22Z"
|
59
52
|
},
|
60
53
|
registered_company_name: 'HOKO LTD',
|
61
|
-
industry: 'B | Mining and Quarrying',
|
62
|
-
company_number: '09525857',
|
63
|
-
type: 'limited_liability_company',
|
64
54
|
trading_from_date: '2015-05-22',
|
55
|
+
type: 'limited_liability_company',
|
56
|
+
industry: 'B | Mining and Quarrying',
|
57
|
+
vat_status: {
|
58
|
+
is_vat_registered: true,
|
59
|
+
registered_over_3_months: true,
|
60
|
+
},
|
65
61
|
registered_address: {
|
66
62
|
postcode: 'W1T 3NF',
|
67
63
|
street_line_1: 'Berners House',
|
68
64
|
street_line_2: '47-48 Berners Street',
|
69
65
|
town: 'London',
|
70
66
|
country: 'GB'
|
71
|
-
},
|
72
|
-
vat_status: {
|
73
|
-
is_vat_registered: true
|
74
67
|
}
|
75
68
|
}
|
76
69
|
end
|
77
70
|
|
78
71
|
def user_information
|
79
72
|
{
|
73
|
+
date_of_birth: date_of_birth,
|
74
|
+
emails: emails,
|
80
75
|
uid: SecureRandom.uuid,
|
81
76
|
first_name: first_name,
|
82
77
|
last_name: last_name,
|
83
|
-
date_of_birth: date_of_birth,
|
84
|
-
roles: %w[applicant shareholder guarantor director],
|
85
78
|
phones: phones,
|
86
|
-
|
79
|
+
roles: %w[applicant shareholder guarantor director],
|
87
80
|
residential_addresses: residential_addresses,
|
88
81
|
privacy_policy: {
|
89
82
|
agreed: true,
|
90
|
-
|
83
|
+
valid_from: DateTime.now - 1
|
91
84
|
}
|
92
85
|
}
|
93
86
|
end
|
@@ -95,7 +88,6 @@ module Iwoca
|
|
95
88
|
def phones
|
96
89
|
[
|
97
90
|
{
|
98
|
-
uid: SecureRandom.uuid,
|
99
91
|
number: phone,
|
100
92
|
type: 'primary'
|
101
93
|
}
|
@@ -105,8 +97,11 @@ module Iwoca
|
|
105
97
|
def emails
|
106
98
|
[
|
107
99
|
{
|
108
|
-
uid: SecureRandom.uuid,
|
109
100
|
email: email,
|
101
|
+
marketing_opt_in: {
|
102
|
+
agreed: true,
|
103
|
+
valid_from: DateTime.now
|
104
|
+
},
|
110
105
|
type: 'primary'
|
111
106
|
}
|
112
107
|
]
|
@@ -115,14 +110,12 @@ module Iwoca
|
|
115
110
|
def residential_addresses
|
116
111
|
[
|
117
112
|
{
|
118
|
-
|
119
|
-
|
113
|
+
country: 'GB',
|
114
|
+
residential_status: 'owner_no_mortgage',
|
120
115
|
street_line_1: address,
|
121
116
|
street_line_2: '',
|
122
|
-
|
123
|
-
postcode: postcode
|
124
|
-
house_number: '10',
|
125
|
-
residential_status: 'owner_no_mortgage'
|
117
|
+
town: city,
|
118
|
+
postcode: postcode
|
126
119
|
}
|
127
120
|
]
|
128
121
|
end
|