Module: Dfcapi

Defined in:
lib/dfcapi.rb

Constant Summary collapse

@@api_url_checkkey =
"https://api.debitfinance.co.uk/checkkey"
@@api_url_viewdd =
"https://api.debitfinance.co.uk/viewdd"
@@api_url_viewddbreakdown =
"https://api.debitfinance.co.uk/viewddbreakdown"
@@api_url_setupdd =
"https://api.debitfinance.co.uk/setupdd"
@@api_url_updatedd =
"https://api.debitfinance.co.uk/updatedd"
@@api_url_canceldd =
"https://api.debitfinance.co.uk/canceldd"
@@errors =
{}
@@response_code =
false
@@body =
false
@@raw_body =
false
@@headers =
{}

Class Method Summary collapse

Class Method Details

.cancelDirectDebit(api_key, api_secret, dfc_reference, cancel_date) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/dfcapi.rb', line 276

def self.cancelDirectDebit(api_key, api_secret, dfc_reference, cancel_date)
  self.clearStoredResponse

  response = Unirest.post @@api_url_canceldd,
                          headers: {
                            "Content-Type" => "application/json",
                            "Accept" => "application/json"
                          },
                          parameters: {
                            :authentication => {
                              :apikey => api_key,
                              :apisecret => api_secret,
                              :dfc_ref => dfc_reference
                            },
                            :cancel => {
                              :apply_from => cancel_date
                            }
                          }.to_json

  self.setStoredResponse response

  if(response.code === 200 && response.body['status'] === 'ok')
    return true
  end

  return false

end

.checkApiKey(api_key, api_secret) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/dfcapi.rb', line 103

def self.checkApiKey(api_key, api_secret)
  self.clearStoredResponse

  response = Unirest.get @@api_url_checkkey, auth:{:user=>api_key, :password=>api_secret}

  self.setStoredResponse response

  if(response.code === 200 && response.body['status'] === 'ok')
    return true
  end


  return false

end

.clearStoredResponseObject



67
68
69
70
71
72
73
# File 'lib/dfcapi.rb', line 67

def self.clearStoredResponse
    @@errors = {}
    @@response_code = false
    @@body = false
    @@raw_body = false
    @@headers = {}
end

.createDirectDebit(api_key, api_secret, client_reference, reference, title, first_name, last_name, address1, address2, address3, town, county, postcode, amounts, email, account_number, sort_code, start_from, installments, frequency_unit, frequency_type, roll_status, birth_date, mobile_number, phone_number, no_email, service_description, bacs_reference, skip_check) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/dfcapi.rb', line 150

def self.createDirectDebit(api_key, api_secret, client_reference, reference, title, first_name, last_name, address1, address2, address3, town, county, postcode, amounts, email, , sort_code, start_from, installments, frequency_unit, frequency_type, roll_status, birth_date, mobile_number, phone_number, no_email, service_description, bacs_reference, skip_check)

  self.clearStoredResponse

  response = Unirest.post @@api_url_setupdd,
                          headers: {
                            "Content-Type" => "application/json",
                            "Accept" => "application/json"
                          },
                          parameters: {
                            :authentication => {
                              :apikey => api_key,
                              :apisecret => api_secret,
                              :client_ref => client_reference
                            },
                            :payer => {
                              :title => title,
                              :first_name => first_name,
                              :last_name => last_name,
                              :birth_date => birth_date
                            },
                            :address => {
                              :address1 => address1,
                              :address2 => address2,
                              :address3 => address3,
                              :town => town,
                              :county => county,
                              :postcode => postcode,
                              :skip_check => skip_check
                            },
                            :contact => {
                              :phone => phone_number,
                              :mobile => mobile_number,
                              :email => email,
                              :no_email => no_email
                            },
                            :bank => {
                              :account_number => ,
                              :sort_code => sort_code
                            },
                            :subscription => {
                              :reference => reference,
                              :description => service_description,
                              :amounts => amounts,
                              :interval => {
                                :unit => frequency_unit,
                                :frequency => frequency_type
                              },
                              :start_from => start_from,
                              :installments => installments,
                              :bacs_reference => bacs_reference,
                              :roll_status => roll_status
                            }
                          }.to_json

  self.setStoredResponse response

  if(response.code === 200 && response.body['status'] === 'ok')
    return true
  end

  return false

end

.getErrorsObject



75
76
77
# File 'lib/dfcapi.rb', line 75

def self.getErrors
    return @@errors
end

.getResponseBodyObject



83
84
85
# File 'lib/dfcapi.rb', line 83

def self.getResponseBody
    return @@body
end

.getResponseBodyRawObject



87
88
89
# File 'lib/dfcapi.rb', line 87

def self.getResponseBodyRaw
    return @@raw_body
end

.getResponseCodeObject



79
80
81
# File 'lib/dfcapi.rb', line 79

def self.getResponseCode
    return @@response_code
end

.getResponseHeadersObject



91
92
93
# File 'lib/dfcapi.rb', line 91

def self.getResponseHeaders
    return @@headers
end

.setCancelDirectDebitUrl(canceldd_url) ⇒ Object



63
64
65
# File 'lib/dfcapi.rb', line 63

def self.setCancelDirectDebitUrl(canceldd_url)
    @@api_url_canceldd = canceldd_url
end

.setCheckKeyUrl(checkkey_url) ⇒ Object



43
44
45
# File 'lib/dfcapi.rb', line 43

def self.setCheckKeyUrl(checkkey_url)
  @@api_url_checkkey = checkkey_url
end

.setCreateDirectDebitUrl(setupdd_url) ⇒ Object



55
56
57
# File 'lib/dfcapi.rb', line 55

def self.setCreateDirectDebitUrl(setupdd_url)
    @@api_url_setupdd = setupdd_url
end

.setStoredResponse(response) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/dfcapi.rb', line 95

def self.setStoredResponse(response)
    @@errors = response.body['errors']
    @@response_code = response.code
    @@body = response.body
    @@raw_body = response.raw_body
    @@headers = response.headers
end

.setUpdateDirectDebitUrl(updatedd_url) ⇒ Object



59
60
61
# File 'lib/dfcapi.rb', line 59

def self.setUpdateDirectDebitUrl(updatedd_url)
    @@api_url_updatedd = updatedd_url
end

.setViewDirectDebitBreakdownUrl(viewddbreakdown_url) ⇒ Object



51
52
53
# File 'lib/dfcapi.rb', line 51

def self.setViewDirectDebitBreakdownUrl(viewddbreakdown_url)
    @@api_url_viewddbreakdown = viewddbreakdown_url
end

.setViewDirectDebitUrl(viewdd_url) ⇒ Object



47
48
49
# File 'lib/dfcapi.rb', line 47

def self.setViewDirectDebitUrl(viewdd_url)
    @@api_url_viewdd = viewdd_url
end

.updateDirectDebit(api_key, api_secret, dfc_reference, reference, title, first_name, last_name, address1, address2, address3, town, county, postcode, email, account_number, sort_code, birth_date, mobile_number, phone_number, paymentdate, applyfrom_paydate, installmentduedate, installmentamount, latepayment, applyfrom, newamount) ⇒ Object



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/dfcapi.rb', line 216

def self.updateDirectDebit(api_key, api_secret, dfc_reference, reference, title, first_name, last_name, address1, address2, address3, town, county, postcode, email, , sort_code, birth_date, mobile_number, phone_number, paymentdate, applyfrom_paydate, installmentduedate, installmentamount, latepayment, applyfrom, newamount)
  self.clearStoredResponse

  response = Unirest.post @@api_url_updatedd,
                          headers: {
                            "Content-Type" => "application/json",
                            "Accept" => "application/json"
                          },
                          parameters: {
                            :authentication => {
                              :apikey => api_key,
                              :apisecret => api_secret,
                              :dfc_ref => dfc_reference
                            },
                            :payer => {
                              :title => title,
                              :first_name => first_name,
                              :last_name => last_name,
                              :birth_date => birth_date
                            },
                            :address => {
                              :address1 => address1,
                              :address2 => address2,
                              :address3 => address3,
                              :town => town,
                              :county => county,
                              :postcode => postcode
                            },
                            :contact => {
                              :phone => phone_number,
                              :mobile => mobile_number,
                              :email => email
                            },
                            :bank => {
                              :account_number => ,
                              :sort_code => sort_code
                            },
                            :general => {
                              :yourref => reference,
                              :paymentdate => paymentdate,
                              :installmentduedate => installmentduedate,
                              :installmentamount => installmentamount,
                              :latepayment => latepayment,
                              :applyfrom => applyfrom,
                              :applyfrom_paydate => applyfrom_paydate,
                              :newamount => newamount
                            }
                          }.to_json

  self.setStoredResponse response

  if(response.code === 200 && response.body['status'] === 'ok')
    return true
  end

  return false

end

.viewDirectDebit(api_key, api_secret, dfc_reference) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/dfcapi.rb', line 119

def self.viewDirectDebit(api_key, api_secret, dfc_reference)
    self.clearStoredResponse

    response = Unirest.get @@api_url_viewdd, auth:{:user=>api_key, :password=>api_secret}, parameters:{ :dfc_reference => dfc_reference }

    self.setStoredResponse response

    if(response.code === 200 && response.body['status'] === 'ok')
      return response.body
    end


    return false
end

.viewDirectDebitBreakdown(api_key, api_secret, dfc_reference) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/dfcapi.rb', line 134

def self.viewDirectDebitBreakdown(api_key, api_secret, dfc_reference)
    self.clearStoredResponse

    response = Unirest.get @@api_url_viewddbreakdown, auth:{:user=>api_key, :password=>api_secret}, parameters:{ :dfc_reference => dfc_reference }

    self.setStoredResponse response

    if(response.code === 200 && response.body['status'] === 'ok')
      return response.body
    end


    return false
end