iwoca API wrapper

This is a simple gem to interact with iwoca's API.

The API documentation can be found here: https://developer.iwoca.co.uk/introduction/introduction

Installation

Add this line to your application's Gemfile:

gem 'iwoca'

And then execute:

$ bundle

Or install it yourself as:

$ gem install iwoca

Usage

You need to have an api key to use the API. Every request will be authenticated with that key in the header.

Configuration

You can configure Iwoca by providing a configuration block, before you do any call:

Iwoca.configure do |config|
  config.api_key = YOUR_API_KEY_HERE
  config.webhook_signature = YOUR_WEBHOOK_SIGNATURE
  # config.debug = true # This is false by default, keep in mind it will ve VERY verbose
end

Check authentication

To check if you're using a good API Key you can invoke the authentication_check endpoint by running:

Iwoca.authentication_check
# => Authentication check successful: {"version":"v2.1"}

Customer

First thing you want to do is to create a customer:

customer_json = Iwoca::CustomerGenerator.generate # for test purposes
response = Iwoca::Customer.create(data: customer_json)
# => This will return a state_key, if the JSON is valid. You need this key to call other methods.

customer_id = response.data[:customer_id]

Then you can update it, if you keep track of the customer_id that is returned:

Iwoca::Customer.update(customer_id: customer_id, data: customer_json)

And finally you can get a login link:

Iwoca::Customer.(customer_id: customer_id)

Application

After the customer is correctly created you can create an application:

app_json = Iwoca::ApplicationGenerator.generate # for test purposes
response = Iwoca::Application.create(customer_id: customer_id, data: app_json)

application_id = response.data[:application_id]

This can then be used to check the status of the latest application for a customer:

Iwoca::Application.latest(customer_id: customer_id)

Or, equally important, to check the offers:

Iwoca::Application.offers(application_id: application_id)

Every call will return a Iwoca::Response instance, that you can use to get all the information you need:

response = Iwoca::Customer.(customer_id: customer_id)

response.status     #=> 200
response.success?   #=> true
response.errors     #=> []
response.data       #=> { login_link: 'http://login_link' }

Webhooks

Newest iwoca version has a nice way to manage the webhooks, so we can change and check the status of webhooks at any point.

Iwoca::Webhooks.configuration # what's the webook url and the secret token
Iwoca::Webhooks.update(config: {}) # update webhook configuration
Iwoca::Webhooks.event_types # list the webhook event types
Iwoca::Webhooks.subscribe(event_types: []) # subscribe to an event
Iwoca::Webhooks.subscriptions # list subscriptions

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Please refer to iwoca's documentation on how to test different states (we do have recorded VCR responses, but if something changes on their side we need to update). The documentation is here: https://developer.iwoca.co.uk/lending-api-v1/testing-your-integration/core-test-data.

In spec/data we have the stored customer data that will return a 'approved' state. Use this to generate valid state keys and follow their instructions to generate the other states.

Webhooks

To test webhooks you may find it easier to use a test endpoint like: https://dev-finpointdev.pagekite.me/fast_lender_webhooks/iwoca_event

How to install:

$ curl -O https://pagekite.net/pk/pagekite.py
$ chmod +x pagekite.py
$ sudo mv -f pagekite.py /usr/local/bin (replace with the name of your directory)

How to run:

./pagekite.py 3000 dev-finpointdev.pagekite.me

pagekite.net details: