Class: Iwoca::Customer

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

Class Method Summary collapse

Class Method Details

.create(data: {}) ⇒ Object

The POST request should be used to create an iwoca account for the customer. It’s always the first endpoint and method you should call when submitting a new customer. It returns a customer_id used to identify the customer in all future requests.

Successful request will return a 201 status code and a JSON response containing a customer_id: Example: { data: { customer_id: “fd48781e-3ad3-4a94-b4a6-60fafeebab0b” } }



13
14
15
16
17
18
19
20
# File 'lib/iwoca/customer.rb', line 13

def self.create(data: {})
  schema = File.join(Iwoca.root, 'lib/iwoca/schemas/customer_payload.json')

  # Validate the schema first, to avoid making a request with invalid data.
  JSON::Validator.validate!(schema, data.to_json)

  Iwoca.connection.post('customers/', data)
end

Get a login link for a customer from a given customer_id



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

def self.(customer_id:)
  Iwoca.connection.get("customers/#{customer_id}/login_link/")
end

.update(customer_id:, data: {}) ⇒ Object

The PUT request should be used to add or update data for a customer. Note that the entire State should be submitted each time you use this endpoint, even if you are just updating a few fields.



25
26
27
# File 'lib/iwoca/customer.rb', line 25

def self.update(customer_id:, data: {})
  Iwoca.connection.put("customers/#{customer_id}/", data)
end