Class: Iwoca::Webhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/iwoca/webhooks.rb

Overview

Class Method Summary collapse

Class Method Details

.configurationObject

Will return a payload that looks like this:

{

"data": {
  "webhook_url": "https://app.finpoint.co.uk/fast_lender_webhooks/iwoca_event",
  "webhook_secret_token": "cddafc72e1bca9b33d7ee922a95ae3fdcdf4f37c",
  "encryption_method": "sha256"
}

}



18
19
20
# File 'lib/iwoca/webhooks.rb', line 18

def self.configuration
  connection.get('configuration/')
end

.connectionObject



5
6
7
# File 'lib/iwoca/webhooks.rb', line 5

def self.connection
  @connection ||= Connection.new('notifications')
end

.event_typesObject

Get a list of the possible event types

{

"data": {
  "webhook_event_types": [
    "approval_status_changed",
    "customer_funded",
    "application_offered",
    "application_declined",
    "application_deferred",
    "cashflow_added",
    "mca_context_changed",
    "bank_account_setup",
    "application_status_changed",
    "application_attributed"
  ]
}

}



52
53
54
# File 'lib/iwoca/webhooks.rb', line 52

def self.event_types
  connection.get('webhook_event_types/')
end

.subscribe(event_types:) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/iwoca/webhooks.rb', line 56

def self.subscribe(event_types:)
  json = { data: { subscriptions: [] }}

  subscriptions = event_types.map do |event_type|
    { webhook_event_type: event_type }
  end

  json[:data][:subscriptions] = subscriptions

  connection.post('subscriptions/', json)
end

.subscriptionsObject

Returns the active subscriptions in a payload like this: {

"data": {
  "subscriptions": [
    { "webhook_event_type": "approval_status_changed", "url": null, "subscribed": true },
    { "webhook_event_type": "customer_funded", "url": null, "subscribed": true },
    { "webhook_event_type": "application_offered", "url": null, "subscribed": true },
    { "webhook_event_type": "application_declined", "url": null, "subscribed": true },
    { "webhook_event_type": "application_deferred", "url": null, "subscribed": true },
    { "webhook_event_type": "cashflow_added", "url": null, "subscribed": true },
    { "webhook_event_type": "mca_context_changed", "url": null, "subscribed": true },
    { "webhook_event_type": "bank_account_setup", "url": null, "subscribed": true },
    { "webhook_event_type": "application_status_changed", "url": null, "subscribed": true },
    { "webhook_event_type": "application_attributed", "url": null, "subscribed": true }
  ]
}

}



90
91
92
# File 'lib/iwoca/webhooks.rb', line 90

def self.subscriptions
  connection.get('subscriptions/')
end

.unsubscribe(event_types:) ⇒ Object



68
69
70
71
# File 'lib/iwoca/webhooks.rb', line 68

def self.unsubscribe(event_types:)
  json = {}
  connection.delete('subscriptions/', json)
end

.update(config:) ⇒ Object

Setup a webhook, the params is a payload that looks like this:

{

"data": {
  "regenerate_webhook_secret_token": true,
  "webhook_url": "string"
}

}



30
31
32
# File 'lib/iwoca/webhooks.rb', line 30

def self.update(config:)
  connection.put('configuration/', config)
end