iwoca 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faker'
4
+
5
+ module Iwoca
6
+ # This class can be used to generate fake customers for test purposes
7
+ class CustomerGenerator
8
+ attr_accessor :id, :first_name, :last_name, :email, :phone, :address, :date_of_birth, :city
9
+ attr_accessor :postcode
10
+
11
+ DEFAULTS = {
12
+ id: SecureRandom.hex(4),
13
+ first_name: Faker::Name.first_name,
14
+ last_name: Faker::Name.last_name,
15
+ email: Faker::Internet.email,
16
+ phone: Faker::PhoneNumber.phone_number,
17
+ address: Faker::Address.street_address,
18
+ date_of_birth: Faker::Date.birthday(min_age: 23, max_age: 65),
19
+ city: Faker::Address.city,
20
+ postcode: Faker::Address.postcode
21
+ }.freeze
22
+
23
+ def self.generate(params = {})
24
+ new(params).generate
25
+ end
26
+
27
+ def initialize(params = {})
28
+ Faker::Config.locale = 'en-GB'
29
+
30
+ DEFAULTS.each do |key, default_value|
31
+ send("#{key}=", params[key] || default_value)
32
+ end
33
+ end
34
+
35
+ def generate
36
+ {
37
+ data: {
38
+ application: {
39
+ company: company_information,
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
+ }
51
+ }
52
+ }
53
+ end
54
+
55
+ def company_information
56
+ {
57
+ last_12_months_turnover: {
58
+ amount: 0.0
59
+ },
60
+ registered_company_name: 'HOKO LTD',
61
+ industry: 'B | Mining and Quarrying',
62
+ company_number: '09525857',
63
+ type: 'limited_liability_company',
64
+ trading_from_date: '2015-05-22',
65
+ registered_address: {
66
+ postcode: 'W1T 3NF',
67
+ street_line_1: 'Berners House',
68
+ street_line_2: '47-48 Berners Street',
69
+ town: 'London',
70
+ country: 'GB'
71
+ },
72
+ vat_status: {
73
+ is_vat_registered: true
74
+ }
75
+ }
76
+ end
77
+
78
+ def user_information
79
+ {
80
+ uid: SecureRandom.uuid,
81
+ first_name: first_name,
82
+ last_name: last_name,
83
+ date_of_birth: date_of_birth,
84
+ roles: %w[applicant shareholder guarantor director],
85
+ phones: phones,
86
+ emails: emails,
87
+ residential_addresses: residential_addresses,
88
+ privacy_policy: {
89
+ agreed: true,
90
+ datetime: DateTime.now
91
+ }
92
+ }
93
+ end
94
+
95
+ def phones
96
+ [
97
+ {
98
+ uid: SecureRandom.uuid,
99
+ number: phone,
100
+ type: 'primary'
101
+ }
102
+ ]
103
+ end
104
+
105
+ def emails
106
+ [
107
+ {
108
+ uid: SecureRandom.uuid,
109
+ email: email,
110
+ type: 'primary'
111
+ }
112
+ ]
113
+ end
114
+
115
+ def residential_addresses
116
+ [
117
+ {
118
+ uid: SecureRandom.uuid,
119
+ town: city,
120
+ street_line_1: address,
121
+ street_line_2: '',
122
+ country: 'GB',
123
+ postcode: postcode,
124
+ house_number: '10',
125
+ residential_status: 'owner_no_mortgage'
126
+ }
127
+ ]
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iwoca
4
+ class PathSanitizer
5
+ # Removes any leading '/' and guarantees an ending '/'
6
+ def self.sanitize(path)
7
+ parts = path.split('/').reject(&:empty?)
8
+ new_path = parts.join('/')
9
+
10
+ [new_path, '/'].join
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,43 @@
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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Iwoca
6
+ class Response
7
+ extend Forwardable
8
+
9
+ def_delegators :@http_response, :body, :status, :success?
10
+
11
+ def initialize(http_response)
12
+ @http_response = http_response
13
+ end
14
+
15
+ def errors
16
+ @http_response.body&.dig(:errors) || []
17
+ end
18
+
19
+ def data
20
+ @http_response.body&.dig(:data) || {}
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iwoca
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,65 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://stage.iwoca-dev.co.uk/api/lending/v1/approval_request/00000000-df68-421a-8108-f7cec4902c00/
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ Authorization:
11
+ - Token <TOKEN>
12
+ Content-Type:
13
+ - application/json
14
+ User-Agent:
15
+ - ruby-iwoca-0.1.0
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 404
23
+ message: Not Found
24
+ headers:
25
+ Date:
26
+ - Fri, 24 Jan 2020 14:29:12 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '91'
31
+ Connection:
32
+ - keep-alive
33
+ Server:
34
+ - nginx/1.15.12
35
+ X-State-Key:
36
+ - 00000000-df68-421a-8108-f7cec4902c00
37
+ Expires:
38
+ - Fri, 24 Jan 2020 14:29:12 GMT
39
+ Cache-Control:
40
+ - max-age=0, no-cache, no-store, must-revalidate
41
+ X-Partner:
42
+ - finpoint-dev
43
+ X-Content-Type-Options:
44
+ - nosniff
45
+ X-Xss-Protection:
46
+ - 1; mode=block
47
+ X-Frame-Options:
48
+ - SAMEORIGIN
49
+ Vary:
50
+ - Cookie
51
+ Set-Cookie:
52
+ - isLoggedIn=True; Path=/
53
+ - sessionid_access=18ae56d0-de8c-4506-8571-397982b2faca; expires=Sat, 23-Jan-2021
54
+ 14:29:12 GMT; HttpOnly; Max-Age=31536000; Path=/
55
+ - uid=rBEABF4q/zgZzAAlAwYyAg==; expires=Thu, 31-Dec-37 23:55:55 GMT; domain=.iwoca-dev.co.uk;
56
+ path=/
57
+ Strict-Transport-Security:
58
+ - max-age=31536000; includeSubDomains
59
+ body:
60
+ encoding: UTF-8
61
+ string: '{"errors": [{"code": "NotFound", "detail": "No \"state key\" found
62
+ matching that query."}]}'
63
+ http_version:
64
+ recorded_at: Fri, 24 Jan 2020 14:29:12 GMT
65
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,65 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://stage.iwoca-dev.co.uk/api/lending/v1/approval_request/1acd6198-df68-421a-8108-f7cec4902c00/
6
+ body:
7
+ encoding: UTF-8
8
+ string: "{}"
9
+ headers:
10
+ Authorization:
11
+ - Token <TOKEN>
12
+ Content-Type:
13
+ - application/json
14
+ User-Agent:
15
+ - ruby-iwoca-0.1.0
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Date:
26
+ - Fri, 24 Jan 2020 14:29:12 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '0'
31
+ Connection:
32
+ - keep-alive
33
+ Server:
34
+ - nginx/1.15.12
35
+ X-State-Key:
36
+ - 1acd6198-df68-421a-8108-f7cec4902c00
37
+ Expires:
38
+ - Fri, 24 Jan 2020 14:29:12 GMT
39
+ Cache-Control:
40
+ - max-age=0, no-cache, no-store, must-revalidate
41
+ - public, max-age=0, must-revalidate
42
+ X-Partner:
43
+ - finpoint-dev
44
+ X-Content-Type-Options:
45
+ - nosniff
46
+ X-Xss-Protection:
47
+ - 1; mode=block
48
+ X-Frame-Options:
49
+ - SAMEORIGIN
50
+ Vary:
51
+ - Cookie
52
+ Set-Cookie:
53
+ - isLoggedIn=True; Path=/
54
+ - sessionid_access=9983ffac-63a0-4299-b144-eb6a09d2811d; expires=Sat, 23-Jan-2021
55
+ 14:29:12 GMT; HttpOnly; Max-Age=31536000; Path=/
56
+ - uid=rBEABF4q/zgZzAAlAwYxAg==; expires=Thu, 31-Dec-37 23:55:55 GMT; domain=.iwoca-dev.co.uk;
57
+ path=/
58
+ Strict-Transport-Security:
59
+ - max-age=31536000; includeSubDomains
60
+ body:
61
+ encoding: UTF-8
62
+ string: ''
63
+ http_version:
64
+ recorded_at: Fri, 24 Jan 2020 14:29:12 GMT
65
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,71 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://stage.iwoca-dev.co.uk/api/lending/v1/state/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"data":{"application":{"company":{"last_12_months_turnover":{"amount":0.0},"registered_company_name":"HOKO
9
+ LTD","industry":"B | Mining and Quarrying","company_number":"09525857","type":"limited_liability_company","trading_from_date":"2015-05-22","registered_address":{"postcode":"W1T
10
+ 3NF","street_line_1":"Berners House","street_line_2":"47-48 Berners Street","town":"London","country":"GB"},"vat_status":{"is_vat_registered":true}},"people":[{"uid":"5923c880-9253-4504-84f2-5fcd4f1b3955","first_name":"Gemma","last_name":"Pfannerstill","date_of_birth":"1956-12-14","roles":["applicant","shareholder","guarantor","director"],"phones":[{"uid":"4e9233ca-7026-47c7-9979-39abeae7db9f","number":"+236
11
+ 056 3766 7778","type":"primary"}],"emails":[{"uid":"e7970175-08d3-4a68-9c03-b3175b0de37b","email":"reynaldo@larsonnolan.info","type":"primary"}],"residential_addresses":[{"uid":"8119834a-f89e-4efc-98cf-2498593fa524","town":"West
12
+ Dominiqueville","street_line_1":"51900 Tom Manor","street_line_2":"","country":"GB","postcode":"WG4
13
+ 3LE","house_number":"10","residential_status":"owner_no_mortgage"}],"privacy_policy":{"agreed":true,"datetime":"2020-01-23T18:57:16+00:00"}}],"requested_products":{"credit_facility":{"approval":{"amount":123123,"duration":12,"detailed_purpose":"business
14
+ loan"}}}}},"email":""}'
15
+ headers:
16
+ Authorization:
17
+ - Token <TOKEN>
18
+ Content-Type:
19
+ - application/json
20
+ User-Agent:
21
+ - ruby-iwoca-0.1.0
22
+ Accept-Encoding:
23
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
24
+ Accept:
25
+ - "*/*"
26
+ response:
27
+ status:
28
+ code: 400
29
+ message: Bad Request
30
+ headers:
31
+ Date:
32
+ - Thu, 23 Jan 2020 18:57:18 GMT
33
+ Content-Type:
34
+ - application/json; charset=utf-8
35
+ Content-Length:
36
+ - '128'
37
+ Connection:
38
+ - keep-alive
39
+ Server:
40
+ - nginx/1.15.12
41
+ X-State-Key:
42
+ - ''
43
+ Expires:
44
+ - Thu, 23 Jan 2020 18:57:18 GMT
45
+ Cache-Control:
46
+ - max-age=0, no-cache, no-store, must-revalidate
47
+ X-Partner:
48
+ - finpoint-dev
49
+ X-Content-Type-Options:
50
+ - nosniff
51
+ X-Xss-Protection:
52
+ - 1; mode=block
53
+ X-Frame-Options:
54
+ - SAMEORIGIN
55
+ Vary:
56
+ - Cookie
57
+ Set-Cookie:
58
+ - isLoggedIn=True; Path=/
59
+ - sessionid_access=03ccce87-8b7b-4847-9967-a2a84b79bd73; expires=Fri, 22-Jan-2021
60
+ 18:57:18 GMT; HttpOnly; Max-Age=31536000; Path=/
61
+ - uid=rBEABV4p7I6R4QAhAw2MAg==; expires=Thu, 31-Dec-37 23:55:55 GMT; domain=.iwoca-dev.co.uk;
62
+ path=/
63
+ Strict-Transport-Security:
64
+ - max-age=31536000; includeSubDomains
65
+ body:
66
+ encoding: UTF-8
67
+ string: '{"errors": [{"source": {"pointer": ""}, "detail": "There are properties
68
+ not defined by the schema", "code": "ValidationError"}]}'
69
+ http_version:
70
+ recorded_at: Thu, 23 Jan 2020 18:57:18 GMT
71
+ recorded_with: VCR 5.0.0
@@ -0,0 +1,71 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://stage.iwoca-dev.co.uk/api/lending/v1/state/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"data":{"application":{"company":{"last_12_months_turnover":{"amount":0.0},"registered_company_name":"HOKO
9
+ LTD","industry":"B | Mining and Quarrying","company_number":"09525857","type":"limited_liability_company","trading_from_date":"2015-05-22","registered_address":{"postcode":"W1T
10
+ 3NF","street_line_1":"Berners House","street_line_2":"47-48 Berners Street","town":"London","country":"GB"},"vat_status":{"is_vat_registered":true}},"people":[{"uid":"8cf91c8d-7dad-4028-9871-739de9723943","first_name":"Jeremiah","last_name":"DuBuque","date_of_birth":"1982-03-04","roles":["applicant","shareholder","guarantor","director"],"phones":[{"uid":"1ade87a2-8845-4f1d-9441-29adda5f7cb7","number":"+423
11
+ 01929 32251","type":"primary"}],"emails":[{"uid":"46cc012c-c034-46a8-9bff-10ae92d8a2a2","email":"judith.abernathy@becker.io","type":"primary"}],"residential_addresses":[{"uid":"20304bd8-1425-4c15-87b5-332f2ad1bd97","town":"Port
12
+ Suzanne","street_line_1":"4581 Kurt Manors","street_line_2":"","country":"GB","postcode":"ZF2
13
+ 0XR","house_number":"10","residential_status":"owner_no_mortgage"}],"privacy_policy":{"agreed":true,"datetime":"2020-01-23T18:16:33+00:00"}}],"requested_products":{"credit_facility":{"approval":{"amount":123123,"duration":12,"detailed_purpose":"business
14
+ loan"}}}}}}'
15
+ headers:
16
+ Authorization:
17
+ - Token NOT VALID
18
+ Content-Type:
19
+ - application/json
20
+ User-Agent:
21
+ - ruby-iwoca-0.1.0
22
+ Accept-Encoding:
23
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
24
+ Accept:
25
+ - "*/*"
26
+ response:
27
+ status:
28
+ code: 403
29
+ message: Forbidden
30
+ headers:
31
+ Date:
32
+ - Thu, 23 Jan 2020 18:16:33 GMT
33
+ Content-Type:
34
+ - application/json; charset=utf-8
35
+ Content-Length:
36
+ - '106'
37
+ Connection:
38
+ - keep-alive
39
+ Server:
40
+ - nginx/1.15.12
41
+ X-State-Key:
42
+ - ''
43
+ Expires:
44
+ - Thu, 23 Jan 2020 18:16:33 GMT
45
+ Cache-Control:
46
+ - max-age=0, no-cache, no-store, must-revalidate
47
+ X-Partner:
48
+ - None
49
+ X-Content-Type-Options:
50
+ - nosniff
51
+ X-Xss-Protection:
52
+ - 1; mode=block
53
+ X-Frame-Options:
54
+ - SAMEORIGIN
55
+ Vary:
56
+ - Cookie
57
+ Set-Cookie:
58
+ - isLoggedIn=False; Path=/
59
+ - sessionid_access=2be3e052-e602-4739-8b59-587c4e6da88c; expires=Fri, 22-Jan-2021
60
+ 18:16:33 GMT; HttpOnly; Max-Age=31536000; Path=/
61
+ - uid=rBEABV4p4wGR4QAhAwwiAg==; expires=Thu, 31-Dec-37 23:55:55 GMT; domain=.iwoca-dev.co.uk;
62
+ path=/
63
+ Strict-Transport-Security:
64
+ - max-age=31536000; includeSubDomains
65
+ body:
66
+ encoding: UTF-8
67
+ string: '{"errors": [{"code": "PermissionDenied", "detail": "You do not have
68
+ permission to perform this action."}]}'
69
+ http_version:
70
+ recorded_at: Thu, 23 Jan 2020 18:16:33 GMT
71
+ recorded_with: VCR 5.0.0