Class: RestfulKashflow::Services::Customer

Inherits:
BaseService
  • Object
show all
Defined in:
lib/restful_kashflow/services/customer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_service, customer_id) ⇒ Customer

Returns a new instance of Customer.



6
7
8
9
10
11
12
13
# File 'lib/restful_kashflow/services/customer.rb', line 6

def initialize(api_service, customer_id)
  @url = "/customers/#{customer_id}"
  @api_service = api_service

  response = Customer::call_url(@api_service, @url)

  @customer = JSON.parse(response.body)
end

Class Method Details

.create(api_service, name, email, first_name, last_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/restful_kashflow/services/customer.rb', line 19

def self.create(api_service, name, email, first_name, last_name)
  url = "/customers"

  body = {
    "name": name,
    "contacts": [
      {
        "email": email,
        "firstname": first_name,
        "lastname": last_name
      }
    ]
  }.to_json

  response = call_url(api_service, url, 'post', body)

  @customer = JSON.parse(response.body)
end

.create_mandate(api_service:, code:, email:) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/restful_kashflow/services/customer.rb', line 46

def self.create_mandate(api_service:, code:, email:)
  url = "/customers/#{code}/mandates"

  body = {
    "Amount": 2000,
    "Email": {
      "To": email,
      "Subject": "Butterware Direct Debit Mandate",
      "Body": "Butterware Direct Debit Mandate",
      "IsHtml": true,
      "SenderAddress": "[email protected]",
      "SenderName": "Butterware"
    },
    "Description": "Butterware Direct Debit Mandate",
    "AmountValidity": "Monthly",
    "CustomerCode": code
  }.to_json

  response = call_url(api_service, url, 'post', body)

  @customer_mandate = JSON.parse(response.body)
end

.get_mandate(api_service:, code:) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/restful_kashflow/services/customer.rb', line 38

def self.get_mandate(api_service:, code:)
  url = "/customers/#{code}/mandates"

  response = call_url(api_service, url, 'get')

  @customer_mandate = JSON.parse(response.body)
end

Instance Method Details

#has_signed_mandate?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/restful_kashflow/services/customer.rb', line 15

def has_signed_mandate?
  !!@customer["IsGoCardlessMandateSet"]
end