paystack-gateway 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -2
- data/CHANGELOG.md +57 -0
- data/README.md +88 -105
- data/lib/paystack_gateway/api_error.rb +12 -2
- data/lib/paystack_gateway/apple_pay.rb +92 -0
- data/lib/paystack_gateway/balance.rb +62 -0
- data/lib/paystack_gateway/bank.rb +181 -0
- data/lib/paystack_gateway/bulk_charge.rb +197 -0
- data/lib/paystack_gateway/charge.rb +346 -0
- data/lib/paystack_gateway/configuration.rb +5 -3
- data/lib/paystack_gateway/customer.rb +498 -0
- data/lib/paystack_gateway/customers.rb +1 -42
- data/lib/paystack_gateway/dedicated_virtual_account.rb +353 -0
- data/lib/paystack_gateway/dedicated_virtual_accounts.rb +1 -64
- data/lib/paystack_gateway/direct_debit.rb +64 -0
- data/lib/paystack_gateway/dispute.rb +380 -0
- data/lib/paystack_gateway/extensions/customer_extensions.rb +14 -0
- data/lib/paystack_gateway/extensions/plan_extensions.rb +36 -0
- data/lib/paystack_gateway/extensions/refund_extensions.rb +43 -0
- data/lib/paystack_gateway/extensions/transaction_extensions.rb +40 -0
- data/lib/paystack_gateway/extensions/transaction_response_extension.rb +31 -0
- data/lib/paystack_gateway/extensions/transfer_extensions.rb +34 -0
- data/lib/paystack_gateway/integration.rb +60 -0
- data/lib/paystack_gateway/legacy/customers.rb +48 -0
- data/lib/paystack_gateway/legacy/dedicated_virtual_accounts.rb +70 -0
- data/lib/paystack_gateway/legacy/miscellaneous.rb +30 -0
- data/lib/paystack_gateway/legacy/plans.rb +86 -0
- data/lib/paystack_gateway/legacy/refunds.rb +65 -0
- data/lib/paystack_gateway/legacy/subaccounts.rb +41 -0
- data/lib/paystack_gateway/legacy/transaction_response.rb +37 -0
- data/lib/paystack_gateway/legacy/transactions.rb +91 -0
- data/lib/paystack_gateway/legacy/transfer_recipients.rb +27 -0
- data/lib/paystack_gateway/legacy/transfers.rb +63 -0
- data/lib/paystack_gateway/legacy/verification.rb +37 -0
- data/lib/paystack_gateway/miscellaneous.rb +75 -13
- data/lib/paystack_gateway/order.rb +259 -0
- data/lib/paystack_gateway/page.rb +317 -0
- data/lib/paystack_gateway/payment_request.rb +454 -0
- data/lib/paystack_gateway/plan.rb +247 -0
- data/lib/paystack_gateway/plans.rb +1 -80
- data/lib/paystack_gateway/product.rb +303 -0
- data/lib/paystack_gateway/refund.rb +197 -0
- data/lib/paystack_gateway/refunds.rb +1 -59
- data/lib/paystack_gateway/request_module.rb +20 -15
- data/lib/paystack_gateway/settlement.rb +60 -0
- data/lib/paystack_gateway/split.rb +286 -0
- data/lib/paystack_gateway/storefront.rb +329 -0
- data/lib/paystack_gateway/subaccount.rb +263 -0
- data/lib/paystack_gateway/subaccounts.rb +1 -35
- data/lib/paystack_gateway/subscription.rb +256 -0
- data/lib/paystack_gateway/terminal.rb +236 -0
- data/lib/paystack_gateway/transaction.rb +592 -0
- data/lib/paystack_gateway/transaction_response.rb +1 -33
- data/lib/paystack_gateway/transactions.rb +1 -86
- data/lib/paystack_gateway/transfer.rb +410 -0
- data/lib/paystack_gateway/transfer_recipient.rb +237 -0
- data/lib/paystack_gateway/transfer_recipients.rb +1 -21
- data/lib/paystack_gateway/transfers.rb +1 -57
- data/lib/paystack_gateway/verification.rb +1 -31
- data/lib/paystack_gateway/version.rb +1 -1
- data/lib/paystack_gateway/virtual_terminal.rb +297 -0
- data/lib/paystack_gateway.rb +61 -11
- metadata +50 -7
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PaystackGateway
|
|
4
|
+
# https://paystack.com/docs/api/customer
|
|
5
|
+
#
|
|
6
|
+
# Customers
|
|
7
|
+
# A collection of endpoints for creating and managing customers on an integration
|
|
8
|
+
module Customer
|
|
9
|
+
include PaystackGateway::RequestModule
|
|
10
|
+
|
|
11
|
+
# Successful response from calling #list.
|
|
12
|
+
class ListResponse < PaystackGateway::Response; end
|
|
13
|
+
|
|
14
|
+
# Error response from #list.
|
|
15
|
+
class ListError < ApiError; end
|
|
16
|
+
|
|
17
|
+
# https://paystack.com/docs/api/customer/#list
|
|
18
|
+
# List Customers: GET /customer
|
|
19
|
+
# List customers on your integration
|
|
20
|
+
#
|
|
21
|
+
# @param use_cursor [Boolean]
|
|
22
|
+
# A flag to indicate if cursor based pagination should be used
|
|
23
|
+
# @param next [String]
|
|
24
|
+
# An alphanumeric value returned for every cursor based retrieval, used to retrieve
|
|
25
|
+
# the next set of data
|
|
26
|
+
# @param previous [String]
|
|
27
|
+
# An alphanumeric value returned for every cursor based retrieval, used to retrieve
|
|
28
|
+
# the previous set of data
|
|
29
|
+
# @param from [Time]
|
|
30
|
+
# The start date
|
|
31
|
+
# @param to [Time]
|
|
32
|
+
# The end date
|
|
33
|
+
# @param per_page [String]
|
|
34
|
+
# The number of records to fetch per request
|
|
35
|
+
# @param page [String]
|
|
36
|
+
# The offset to retrieve data from
|
|
37
|
+
#
|
|
38
|
+
# @return [ListResponse] successful response
|
|
39
|
+
# @raise [ListError] if the request fails
|
|
40
|
+
api_method def self.list(
|
|
41
|
+
use_cursor: nil,
|
|
42
|
+
next: nil,
|
|
43
|
+
previous: nil,
|
|
44
|
+
from: nil,
|
|
45
|
+
to: nil,
|
|
46
|
+
per_page: nil,
|
|
47
|
+
page: nil
|
|
48
|
+
)
|
|
49
|
+
use_connection do |connection|
|
|
50
|
+
connection.get(
|
|
51
|
+
'/customer',
|
|
52
|
+
{
|
|
53
|
+
use_cursor:,
|
|
54
|
+
next:,
|
|
55
|
+
previous:,
|
|
56
|
+
from:,
|
|
57
|
+
to:,
|
|
58
|
+
perPage: per_page,
|
|
59
|
+
page:,
|
|
60
|
+
}.compact,
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Successful response from calling #create.
|
|
66
|
+
class CreateResponse < PaystackGateway::Response
|
|
67
|
+
delegate :transactions,
|
|
68
|
+
:subscriptions,
|
|
69
|
+
:authorizations,
|
|
70
|
+
:email,
|
|
71
|
+
:first_name,
|
|
72
|
+
:last_name,
|
|
73
|
+
:phone,
|
|
74
|
+
:integration,
|
|
75
|
+
:domain,
|
|
76
|
+
:metadata,
|
|
77
|
+
:customer_code,
|
|
78
|
+
:risk_action,
|
|
79
|
+
:id,
|
|
80
|
+
:createdAt,
|
|
81
|
+
:updatedAt,
|
|
82
|
+
:identified,
|
|
83
|
+
:identifications, to: :data
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Error response from #create.
|
|
87
|
+
class CreateError < ApiError; end
|
|
88
|
+
|
|
89
|
+
# https://paystack.com/docs/api/customer/#create
|
|
90
|
+
# Create Customer: POST /customer
|
|
91
|
+
# Create a customer on your integration
|
|
92
|
+
#
|
|
93
|
+
# @param email [String] (required)
|
|
94
|
+
# Customer's email address
|
|
95
|
+
# @param first_name [String]
|
|
96
|
+
# Customer's first name
|
|
97
|
+
# @param last_name [String]
|
|
98
|
+
# Customer's last name
|
|
99
|
+
# @param phone [String]
|
|
100
|
+
# Customer's phone number
|
|
101
|
+
# @param metadata [String]
|
|
102
|
+
# Stringified JSON object of custom data
|
|
103
|
+
#
|
|
104
|
+
# @return [CreateResponse] successful response
|
|
105
|
+
# @raise [CreateError] if the request fails
|
|
106
|
+
api_method def self.create(email:, first_name: nil, last_name: nil, phone: nil, metadata: nil)
|
|
107
|
+
use_connection do |connection|
|
|
108
|
+
connection.post(
|
|
109
|
+
'/customer',
|
|
110
|
+
{ email:, first_name:, last_name:, phone:, metadata: }.compact,
|
|
111
|
+
)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Successful response from calling #fetch.
|
|
116
|
+
class FetchResponse < PaystackGateway::Response
|
|
117
|
+
delegate :transactions,
|
|
118
|
+
:subscriptions,
|
|
119
|
+
:authorizations,
|
|
120
|
+
:first_name,
|
|
121
|
+
:last_name,
|
|
122
|
+
:email,
|
|
123
|
+
:phone,
|
|
124
|
+
:metadata,
|
|
125
|
+
:domain,
|
|
126
|
+
:customer_code,
|
|
127
|
+
:risk_action,
|
|
128
|
+
:id,
|
|
129
|
+
:integration,
|
|
130
|
+
:createdAt,
|
|
131
|
+
:updatedAt,
|
|
132
|
+
:created_at,
|
|
133
|
+
:updated_at,
|
|
134
|
+
:total_transactions,
|
|
135
|
+
:total_transaction_value,
|
|
136
|
+
:dedicated_account,
|
|
137
|
+
:dedicated_accounts,
|
|
138
|
+
:identified,
|
|
139
|
+
:identifications, to: :data
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Error response from #fetch.
|
|
143
|
+
class FetchError < ApiError; end
|
|
144
|
+
|
|
145
|
+
# https://paystack.com/docs/api/customer/#fetch
|
|
146
|
+
# Fetch Customer: GET /customer/{code}
|
|
147
|
+
# Get details of a customer on your integration.
|
|
148
|
+
#
|
|
149
|
+
# @param code [String] (required)
|
|
150
|
+
# The code for the customer gotten from the response of the customer creation
|
|
151
|
+
#
|
|
152
|
+
# @return [FetchResponse] successful response
|
|
153
|
+
# @raise [FetchError] if the request fails
|
|
154
|
+
api_method def self.fetch(code:)
|
|
155
|
+
use_connection do |connection|
|
|
156
|
+
connection.get(
|
|
157
|
+
"/customer/#{code}",
|
|
158
|
+
)
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Successful response from calling #update.
|
|
163
|
+
class UpdateResponse < PaystackGateway::Response
|
|
164
|
+
delegate :first_name,
|
|
165
|
+
:last_name,
|
|
166
|
+
:email,
|
|
167
|
+
:phone,
|
|
168
|
+
:metadata,
|
|
169
|
+
:domain,
|
|
170
|
+
:customer_code,
|
|
171
|
+
:risk_action,
|
|
172
|
+
:id,
|
|
173
|
+
:integration,
|
|
174
|
+
:createdAt,
|
|
175
|
+
:updatedAt,
|
|
176
|
+
:identified,
|
|
177
|
+
:identifications, to: :data
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Error response from #update.
|
|
181
|
+
class UpdateError < ApiError; end
|
|
182
|
+
|
|
183
|
+
# https://paystack.com/docs/api/customer/#update
|
|
184
|
+
# Update Customer: PUT /customer/{code}
|
|
185
|
+
# Update a customer's details on your integration
|
|
186
|
+
#
|
|
187
|
+
# @param code [String] (required)
|
|
188
|
+
# The code for the customer gotten from the response of the customer creation
|
|
189
|
+
# @param first_name [String]
|
|
190
|
+
# Customer's first name
|
|
191
|
+
# @param last_name [String]
|
|
192
|
+
# Customer's last name
|
|
193
|
+
# @param phone [String]
|
|
194
|
+
# Customer's phone number
|
|
195
|
+
# @param metadata [String]
|
|
196
|
+
# Stringified JSON object of custom data
|
|
197
|
+
#
|
|
198
|
+
# @return [UpdateResponse] successful response
|
|
199
|
+
# @raise [UpdateError] if the request fails
|
|
200
|
+
api_method def self.update(code:, first_name: nil, last_name: nil, phone: nil, metadata: nil)
|
|
201
|
+
use_connection do |connection|
|
|
202
|
+
connection.put(
|
|
203
|
+
"/customer/#{code}",
|
|
204
|
+
{ first_name:, last_name:, phone:, metadata: }.compact,
|
|
205
|
+
)
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# Successful response from calling #risk_action.
|
|
210
|
+
class RiskActionResponse < PaystackGateway::Response
|
|
211
|
+
delegate :transactions,
|
|
212
|
+
:subscriptions,
|
|
213
|
+
:authorizations,
|
|
214
|
+
:first_name,
|
|
215
|
+
:last_name,
|
|
216
|
+
:email,
|
|
217
|
+
:phone,
|
|
218
|
+
:metadata,
|
|
219
|
+
:domain,
|
|
220
|
+
:customer_code,
|
|
221
|
+
:risk_action,
|
|
222
|
+
:id,
|
|
223
|
+
:integration,
|
|
224
|
+
:createdAt,
|
|
225
|
+
:updatedAt,
|
|
226
|
+
:identified,
|
|
227
|
+
:identifications, to: :data
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# Error response from #risk_action.
|
|
231
|
+
class RiskActionError < ApiError; end
|
|
232
|
+
|
|
233
|
+
# https://paystack.com/docs/api/customer/#risk_action
|
|
234
|
+
# Set Risk Action: POST /customer/set_risk_action
|
|
235
|
+
# Set customer's risk action by whitelisting or blacklisting the customer
|
|
236
|
+
#
|
|
237
|
+
# @param customer [String] (required)
|
|
238
|
+
# The customer code from the response of the customer creation
|
|
239
|
+
# @param risk_action ["allow", "deny", "default"]
|
|
240
|
+
# This determines the fraud rules that should be applied to the customer
|
|
241
|
+
#
|
|
242
|
+
# @return [RiskActionResponse] successful response
|
|
243
|
+
# @raise [RiskActionError] if the request fails
|
|
244
|
+
api_method def self.risk_action(customer:, risk_action: nil)
|
|
245
|
+
use_connection do |connection|
|
|
246
|
+
connection.post(
|
|
247
|
+
'/customer/set_risk_action',
|
|
248
|
+
{ customer:, risk_action: }.compact,
|
|
249
|
+
)
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
# Successful response from calling #validate.
|
|
254
|
+
class ValidateResponse < PaystackGateway::Response; end
|
|
255
|
+
|
|
256
|
+
# Error response from #validate.
|
|
257
|
+
class ValidateError < ApiError; end
|
|
258
|
+
|
|
259
|
+
# https://paystack.com/docs/api/customer/#validate
|
|
260
|
+
# Validate Customer: POST /customer/{code}/identification
|
|
261
|
+
# Validate a customer's identity
|
|
262
|
+
#
|
|
263
|
+
# @param code [String] (required)
|
|
264
|
+
# The code for the customer gotten from the response of the customer creation
|
|
265
|
+
# @param first_name [String] (required)
|
|
266
|
+
# Customer's first name
|
|
267
|
+
# @param last_name [String] (required)
|
|
268
|
+
# Customer's last name
|
|
269
|
+
# @param type [String] (required)
|
|
270
|
+
# Predefined types of identification.
|
|
271
|
+
# @param country [String] (required)
|
|
272
|
+
# Two-letter country code of identification issuer
|
|
273
|
+
# @param bvn [String] (required)
|
|
274
|
+
# Customer's Bank Verification Number
|
|
275
|
+
# @param bank_code [String] (required)
|
|
276
|
+
# You can get the list of bank codes by calling the List Banks endpoint (https://api.paystack.co/bank).
|
|
277
|
+
# @param account_number [String] (required)
|
|
278
|
+
# Customer's bank account number.
|
|
279
|
+
# @param middle_name [String]
|
|
280
|
+
# Customer's middle name
|
|
281
|
+
# @param value [String]
|
|
282
|
+
# Customer's identification number.
|
|
283
|
+
#
|
|
284
|
+
# @return [ValidateResponse] successful response
|
|
285
|
+
# @raise [ValidateError] if the request fails
|
|
286
|
+
api_method def self.validate(
|
|
287
|
+
code:,
|
|
288
|
+
first_name:,
|
|
289
|
+
last_name:,
|
|
290
|
+
type:,
|
|
291
|
+
country:,
|
|
292
|
+
bvn:,
|
|
293
|
+
bank_code:,
|
|
294
|
+
account_number:,
|
|
295
|
+
middle_name: nil,
|
|
296
|
+
value: nil
|
|
297
|
+
)
|
|
298
|
+
use_connection do |connection|
|
|
299
|
+
connection.post(
|
|
300
|
+
"/customer/#{code}/identification",
|
|
301
|
+
{
|
|
302
|
+
first_name:,
|
|
303
|
+
last_name:,
|
|
304
|
+
type:,
|
|
305
|
+
country:,
|
|
306
|
+
bvn:,
|
|
307
|
+
bank_code:,
|
|
308
|
+
account_number:,
|
|
309
|
+
middle_name:,
|
|
310
|
+
value:,
|
|
311
|
+
}.compact,
|
|
312
|
+
)
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# Successful response from calling #initialize_authorization.
|
|
317
|
+
class InitializeAuthorizationResponse < PaystackGateway::Response
|
|
318
|
+
delegate :redirect_url, :access_code, :reference, to: :data
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# Error response from #initialize_authorization.
|
|
322
|
+
class InitializeAuthorizationError < ApiError; end
|
|
323
|
+
|
|
324
|
+
# https://paystack.com/docs/api/customer/#initialize_authorization
|
|
325
|
+
# Initialize Authorization: POST /customer/authorization/initialize
|
|
326
|
+
# Initiate a request to create a reusable authorization code for recurring transactions
|
|
327
|
+
#
|
|
328
|
+
# @param email [String] (required)
|
|
329
|
+
# Customer's email address
|
|
330
|
+
# @param channel ["direct_debit"] (required)
|
|
331
|
+
# direct_debit is the only supported option for now
|
|
332
|
+
# @param callback_url [String]
|
|
333
|
+
# Fully qualified url (e.g. https://example.com/) to redirect your customer to
|
|
334
|
+
# @param account [Hash]
|
|
335
|
+
# @option account [String] :number
|
|
336
|
+
# The customer's account number
|
|
337
|
+
# @option account [String] :bank_code
|
|
338
|
+
# The code representing the customer's bank
|
|
339
|
+
# @param address [Hash]
|
|
340
|
+
# @option address [String] :street
|
|
341
|
+
# The customer's street
|
|
342
|
+
# @option address [String] :city
|
|
343
|
+
# The customer's city
|
|
344
|
+
# @option address [String] :state
|
|
345
|
+
# The customer's state
|
|
346
|
+
#
|
|
347
|
+
# @return [InitializeAuthorizationResponse] successful response
|
|
348
|
+
# @raise [InitializeAuthorizationError] if the request fails
|
|
349
|
+
api_method def self.initialize_authorization(email:, channel:, callback_url: nil, account: nil, address: nil)
|
|
350
|
+
use_connection do |connection|
|
|
351
|
+
connection.post(
|
|
352
|
+
'/customer/authorization/initialize',
|
|
353
|
+
{ email:, channel:, callback_url:, account:, address: }.compact,
|
|
354
|
+
)
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
# Successful response from calling #verify_authorization.
|
|
359
|
+
class VerifyAuthorizationResponse < PaystackGateway::Response
|
|
360
|
+
delegate :authorization_code,
|
|
361
|
+
:channel,
|
|
362
|
+
:bank,
|
|
363
|
+
:active,
|
|
364
|
+
:customer, to: :data
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
# Error response from #verify_authorization.
|
|
368
|
+
class VerifyAuthorizationError < ApiError; end
|
|
369
|
+
|
|
370
|
+
# https://paystack.com/docs/api/customer/#verify_authorization
|
|
371
|
+
# Verify Authorization: GET /customer/authorization/verify/{reference}
|
|
372
|
+
# Check the status of an authorization request
|
|
373
|
+
#
|
|
374
|
+
# @param reference [String] (required)
|
|
375
|
+
# The reference returned in the initialization response
|
|
376
|
+
#
|
|
377
|
+
# @return [VerifyAuthorizationResponse] successful response
|
|
378
|
+
# @raise [VerifyAuthorizationError] if the request fails
|
|
379
|
+
api_method def self.verify_authorization(reference:)
|
|
380
|
+
use_connection do |connection|
|
|
381
|
+
connection.get(
|
|
382
|
+
"/customer/authorization/verify/#{reference}",
|
|
383
|
+
)
|
|
384
|
+
end
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
# Successful response from calling #deactivate_authorization.
|
|
388
|
+
class DeactivateAuthorizationResponse < PaystackGateway::Response; end
|
|
389
|
+
|
|
390
|
+
# Error response from #deactivate_authorization.
|
|
391
|
+
class DeactivateAuthorizationError < ApiError; end
|
|
392
|
+
|
|
393
|
+
# https://paystack.com/docs/api/customer/#deactivate_authorization
|
|
394
|
+
# Deactivate Authorization: POST /customer/authorization/deactivate
|
|
395
|
+
# Deactivate an authorization for any payment channel.
|
|
396
|
+
#
|
|
397
|
+
# @param authorization_code [String] (required)
|
|
398
|
+
# Authorization code to be deactivated
|
|
399
|
+
#
|
|
400
|
+
# @return [DeactivateAuthorizationResponse] successful response
|
|
401
|
+
# @raise [DeactivateAuthorizationError] if the request fails
|
|
402
|
+
api_method def self.deactivate_authorization(authorization_code:)
|
|
403
|
+
use_connection do |connection|
|
|
404
|
+
connection.post(
|
|
405
|
+
'/customer/authorization/deactivate',
|
|
406
|
+
{ authorization_code: }.compact,
|
|
407
|
+
)
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
# Successful response from calling #initialize_direct_debit.
|
|
412
|
+
class InitializeDirectDebitResponse < PaystackGateway::Response
|
|
413
|
+
delegate :redirect_url, :access_code, :reference, to: :data
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
# Error response from #initialize_direct_debit.
|
|
417
|
+
class InitializeDirectDebitError < ApiError; end
|
|
418
|
+
|
|
419
|
+
# https://paystack.com/docs/api/customer/#initialize_direct_debit
|
|
420
|
+
# Initialize Direct Debit: POST /customer/{id}/initialize-direct-debit
|
|
421
|
+
# Initialize the process of linking an account to a customer for Direct Debit transactions
|
|
422
|
+
#
|
|
423
|
+
# @param id [Integer] (required)
|
|
424
|
+
# The ID of the customer to initialize the direct debit for
|
|
425
|
+
# @param account [Hash] (required)
|
|
426
|
+
# @option account [String] :number
|
|
427
|
+
# The customer's account number
|
|
428
|
+
# @option account [String] :bank_code
|
|
429
|
+
# The code representing the customer's bank
|
|
430
|
+
# @param address [Hash] (required)
|
|
431
|
+
# @option address [String] :street
|
|
432
|
+
# The customer's street
|
|
433
|
+
# @option address [String] :city
|
|
434
|
+
# The customer's city
|
|
435
|
+
# @option address [String] :state
|
|
436
|
+
# The customer's state
|
|
437
|
+
#
|
|
438
|
+
# @return [InitializeDirectDebitResponse] successful response
|
|
439
|
+
# @raise [InitializeDirectDebitError] if the request fails
|
|
440
|
+
api_method def self.initialize_direct_debit(id:, account:, address:)
|
|
441
|
+
use_connection do |connection|
|
|
442
|
+
connection.post(
|
|
443
|
+
"/customer/#{id}/initialize-direct-debit",
|
|
444
|
+
{ account:, address: }.compact,
|
|
445
|
+
)
|
|
446
|
+
end
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
# Successful response from calling #direct_debit_activation_charge.
|
|
450
|
+
class DirectDebitActivationChargeResponse < PaystackGateway::Response; end
|
|
451
|
+
|
|
452
|
+
# Error response from #direct_debit_activation_charge.
|
|
453
|
+
class DirectDebitActivationChargeError < ApiError; end
|
|
454
|
+
|
|
455
|
+
# https://paystack.com/docs/api/customer/#direct_debit_activation_charge
|
|
456
|
+
# Direct Debit Activation Charge: PUT /customer/{id}/directdebit-activation-charge
|
|
457
|
+
# Trigger an activation charge on an inactive mandate on behalf of your customer
|
|
458
|
+
#
|
|
459
|
+
# @param id [Integer] (required)
|
|
460
|
+
# The customer ID attached to the authorization
|
|
461
|
+
# @param authorization_id [Integer] (required)
|
|
462
|
+
# The authorization ID gotten from the initiation response
|
|
463
|
+
#
|
|
464
|
+
# @return [DirectDebitActivationChargeResponse] successful response
|
|
465
|
+
# @raise [DirectDebitActivationChargeError] if the request fails
|
|
466
|
+
api_method def self.direct_debit_activation_charge(id:, authorization_id:)
|
|
467
|
+
use_connection do |connection|
|
|
468
|
+
connection.put(
|
|
469
|
+
"/customer/#{id}/directdebit-activation-charge",
|
|
470
|
+
{ authorization_id: }.compact,
|
|
471
|
+
)
|
|
472
|
+
end
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
# Successful response from calling #fetch_mandate_authorizations.
|
|
476
|
+
class FetchMandateAuthorizationsResponse < PaystackGateway::Response; end
|
|
477
|
+
|
|
478
|
+
# Error response from #fetch_mandate_authorizations.
|
|
479
|
+
class FetchMandateAuthorizationsError < ApiError; end
|
|
480
|
+
|
|
481
|
+
# https://paystack.com/docs/api/customer/#fetch_mandate_authorizations
|
|
482
|
+
# Fetch Mandate Authorizations: GET /customer/{id}/directdebit-mandate-authorizations
|
|
483
|
+
# Get the list of direct debit mandates associated with a customer
|
|
484
|
+
#
|
|
485
|
+
# @param id [Integer] (required)
|
|
486
|
+
# The customer ID for the authorizations to fetch
|
|
487
|
+
#
|
|
488
|
+
# @return [FetchMandateAuthorizationsResponse] successful response
|
|
489
|
+
# @raise [FetchMandateAuthorizationsError] if the request fails
|
|
490
|
+
api_method def self.fetch_mandate_authorizations(id:)
|
|
491
|
+
use_connection do |connection|
|
|
492
|
+
connection.get(
|
|
493
|
+
"/customer/#{id}/directdebit-mandate-authorizations",
|
|
494
|
+
)
|
|
495
|
+
end
|
|
496
|
+
end
|
|
497
|
+
end
|
|
498
|
+
end
|
|
@@ -1,44 +1,3 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# Create and manage customers https://paystack.com/docs/api/customer/
|
|
5
|
-
module Customers
|
|
6
|
-
include PaystackGateway::RequestModule
|
|
7
|
-
|
|
8
|
-
# Common helpers for response from customer endpoints
|
|
9
|
-
module CustomerResponse
|
|
10
|
-
extend ActiveSupport::Concern
|
|
11
|
-
|
|
12
|
-
included do
|
|
13
|
-
delegate :id, :customer_code, to: :data
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
class CreateCustomerResponse < PaystackGateway::Response
|
|
18
|
-
include CustomerResponse
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
api_method def self.create_customer(email:, first_name:, last_name:)
|
|
22
|
-
use_connection do |connection|
|
|
23
|
-
connection.post('/customer', { email:, first_name:, last_name: })
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Response from GET /customer/:email_or_id
|
|
28
|
-
class FetchCustomerResponse < PaystackGateway::Response
|
|
29
|
-
include CustomerResponse
|
|
30
|
-
|
|
31
|
-
delegate :subscriptions, :authorizations, to: :data
|
|
32
|
-
|
|
33
|
-
def active_subscriptions = subscriptions.select { _1.status == 'active' }
|
|
34
|
-
def active_subscription_codes = active_subscriptions.map(&:subscription_code)
|
|
35
|
-
def reusable_authorizations = authorizations.select(&:reusable)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
api_method def self.fetch_customer(email:)
|
|
39
|
-
use_connection do |connection|
|
|
40
|
-
connection.get("/customer/#{email}")
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
3
|
+
require 'paystack_gateway/legacy/customers'
|