iwoca 1.0.1 → 1.1.1

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: ce9c1834255a98ef839610f8ccff91efab04f9942b219470de6c769e7bb52a20
4
- data.tar.gz: 37479cab8d5dfefd64be30fd339d7dad18ac8d039b985ffeb3fb7ebe36c3b48b
3
+ metadata.gz: 68021cd07077c3fc000c9a81f8f6016847a9f7e57df374df12648470d86f4e5a
4
+ data.tar.gz: 4a27fec8ceba11a0a424dd4543aeeabaf67c4f604bb44f90e6957da199def42e
5
5
  SHA512:
6
- metadata.gz: d645e2d9948fe267fcce8e6f706de979b8a17127dd66b9e2acb5f77262b9ba77f7d99556f86bf0b10939ec19a24b61d6728502bca53a63d822c2b008c72fd647
7
- data.tar.gz: d7ab10d7dbcc0c792c68e2b03cccae40c9ff6e71d3fa23d3fe556ce886f66c8618e40407eb4e27ab2aabb976787e07f51094936898972521a82376815481d998
6
+ metadata.gz: 38da9126aef94769799ad02fd8ea79f102a36d9185907d1028b0aec11380f18b109456d4ee471ef27e3618cb536b5f50cceb2ff3c2d34ac46550ae4e011131a8
7
+ data.tar.gz: c36ab903f2341614df679c4e6e2d1851624a15a17d981699b75c08918a2a5a0e5e6dafff3e9ea90245e96b8da9d93f189ec7a7b573c65779af85e73337890d25
data/Gemfile.lock CHANGED
@@ -1,9 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iwoca (1.0.1)
4
+ iwoca (1.1.1)
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
- ### Quote
39
+ ### Check authentication
40
40
 
41
- All the available methods are encapsulated in the `Quote` class. The available methods are:
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.create_customer(CUSTOMER_JSON)
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
- Iwoca.update_customer(state_key, CUSTOMER_JSON)
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
- Iwoca.approval(state_key)
75
+ After the customer is correctly created you can create an application:
50
76
 
51
- Iwoca.login_link(state_key)
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
- Iwoca.credit_facility_status(state_key)
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(state_key)
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
- ### Webhook
134
+ ### Webhooks
82
135
 
83
- Iwoca webhook will target this address:
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
- * u: hello@finpoint.co.uk
99
- * p: fckx7989
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
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency 'addressable'
30
30
  spec.add_dependency 'faraday', '~> 2.7'
31
31
  spec.add_dependency 'rainbow'
32
+ spec.add_dependency 'json-schema'
32
33
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json-schema'
4
+
5
+ module Iwoca
6
+ class Application
7
+ # This needs to be used after the customer has been created. It returns an application_id that
8
+ # can be used to identify the application in all future requests.
9
+ # The params argument needs to have the following structure:
10
+ # {
11
+ # data: {
12
+ # requests: [
13
+ # {
14
+ # amount: 15000,
15
+ # duration: {
16
+ # amount: 12,
17
+ # unit: "months"
18
+ # },
19
+ # product_type: "flexi_loan", # check the schema JSON for more options
20
+ # purpose: "equipment_purchase", # check the schema JSON for more options
21
+ # urgency: "asap"
22
+ # }
23
+ # ]
24
+ # }
25
+ # }
26
+ def self.create(customer_id:, data: {})
27
+ requests = (data.dig(:data, :requests) || []).first.to_json
28
+
29
+ # # Add the introducer so we can get a login link later
30
+ # data[:data][:introducer] = {
31
+ # entity_to_contact: 'customer',
32
+ # introducer_id: customer_id
33
+ # }
34
+
35
+ JSON::Validator.validate!('lib/iwoca/schemas/requested_product.json', requests)
36
+
37
+ Iwoca.connection.post("customers/#{customer_id}/applications/", data)
38
+ end
39
+
40
+ # Sending across the customer_id in the URL - you will receive back an object with the latest
41
+ # application information that we have.
42
+ #
43
+ # This will include a status field that can be one of the following options:
44
+ # open, deferred, declined, offered, conditional_offer, customer_to_link_open_banking,
45
+ # action_required, awaiting_underwriter, in_underwriting, expired, funded, offer_revoked,
46
+ # talking_to_customer.
47
+ #
48
+ # Check more info in the docs:
49
+ # https://iwoca.stoplight.io/docs/lapi-uk/branches/2.1.0/84660933e0b17-get-user-latest-application
50
+ def self.latest(customer_id:)
51
+ Iwoca.connection.get("customers/#{customer_id}/applications/latest/")
52
+ end
53
+
54
+ # Use this endpoint after creating an application to generate offers that your customer is
55
+ # eligible for.
56
+ # Offers are associated with the Application, so are retrieved using the customer's current
57
+ # application_id that you would have received in the previous request.
58
+ def self.offers(application_id:)
59
+ Iwoca.connection.get("applications/#{application_id}/offers/")
60
+ end
61
+ end
62
+ 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
@@ -8,7 +8,12 @@ require 'iwoca/response'
8
8
 
9
9
  module Iwoca
10
10
  class Connection
11
- BASE_PATH = '/api/lending/v1'
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, BASE_PATH).to_s
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'] = "Token #{token}" unless token.to_s.empty?
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,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json-schema'
4
+
5
+ module Iwoca
6
+ class Customer
7
+ # The POST request should be used to create an iwoca account for the customer. It's always the
8
+ # first endpoint and method you should call when submitting a new customer. It returns a
9
+ # customer_id used to identify the customer in all future requests.
10
+ #
11
+ # Successful request will return a 201 status code and a JSON response containing a customer_id:
12
+ # Example: { data: { customer_id: "fd48781e-3ad3-4a94-b4a6-60fafeebab0b" } }
13
+ def self.create(data: {})
14
+ # Validate the schema first, to avoid making a request with invalid data.
15
+ JSON::Validator.validate!('lib/iwoca/schemas/customer_payload.json', data.to_json)
16
+
17
+ Iwoca.connection.post('customers/', data)
18
+ end
19
+
20
+ # The PUT request should be used to add or update data for a customer. Note that the entire
21
+ # State should be submitted each time you use this endpoint, even if you are just updating a
22
+ # few fields.
23
+ def self.update(customer_id:, data: {})
24
+ Iwoca.connection.put("customers/#{customer_id}/", data)
25
+ end
26
+
27
+ # Get a login link for a customer from a given customer_id
28
+ def self.login_link(customer_id:)
29
+ Iwoca.connection.get("customers/#{customer_id}/login_link/")
30
+ end
31
+ end
32
+ 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.phone_number,
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
- 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
- }
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: 0.0
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
- emails: emails,
79
+ roles: %w[applicant shareholder guarantor director],
87
80
  residential_addresses: residential_addresses,
88
81
  privacy_policy: {
89
82
  agreed: true,
90
- datetime: DateTime.now
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
- uid: SecureRandom.uuid,
119
- town: city,
113
+ country: 'GB',
114
+ residential_status: 'owner_no_mortgage',
120
115
  street_line_1: address,
121
116
  street_line_2: '',
122
- country: 'GB',
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