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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -2
  3. data/CHANGELOG.md +57 -0
  4. data/README.md +88 -105
  5. data/lib/paystack_gateway/api_error.rb +12 -2
  6. data/lib/paystack_gateway/apple_pay.rb +92 -0
  7. data/lib/paystack_gateway/balance.rb +62 -0
  8. data/lib/paystack_gateway/bank.rb +181 -0
  9. data/lib/paystack_gateway/bulk_charge.rb +197 -0
  10. data/lib/paystack_gateway/charge.rb +346 -0
  11. data/lib/paystack_gateway/configuration.rb +5 -3
  12. data/lib/paystack_gateway/customer.rb +498 -0
  13. data/lib/paystack_gateway/customers.rb +1 -42
  14. data/lib/paystack_gateway/dedicated_virtual_account.rb +353 -0
  15. data/lib/paystack_gateway/dedicated_virtual_accounts.rb +1 -64
  16. data/lib/paystack_gateway/direct_debit.rb +64 -0
  17. data/lib/paystack_gateway/dispute.rb +380 -0
  18. data/lib/paystack_gateway/extensions/customer_extensions.rb +14 -0
  19. data/lib/paystack_gateway/extensions/plan_extensions.rb +36 -0
  20. data/lib/paystack_gateway/extensions/refund_extensions.rb +43 -0
  21. data/lib/paystack_gateway/extensions/transaction_extensions.rb +40 -0
  22. data/lib/paystack_gateway/extensions/transaction_response_extension.rb +31 -0
  23. data/lib/paystack_gateway/extensions/transfer_extensions.rb +34 -0
  24. data/lib/paystack_gateway/integration.rb +60 -0
  25. data/lib/paystack_gateway/legacy/customers.rb +48 -0
  26. data/lib/paystack_gateway/legacy/dedicated_virtual_accounts.rb +70 -0
  27. data/lib/paystack_gateway/legacy/miscellaneous.rb +30 -0
  28. data/lib/paystack_gateway/legacy/plans.rb +86 -0
  29. data/lib/paystack_gateway/legacy/refunds.rb +65 -0
  30. data/lib/paystack_gateway/legacy/subaccounts.rb +41 -0
  31. data/lib/paystack_gateway/legacy/transaction_response.rb +37 -0
  32. data/lib/paystack_gateway/legacy/transactions.rb +91 -0
  33. data/lib/paystack_gateway/legacy/transfer_recipients.rb +27 -0
  34. data/lib/paystack_gateway/legacy/transfers.rb +63 -0
  35. data/lib/paystack_gateway/legacy/verification.rb +37 -0
  36. data/lib/paystack_gateway/miscellaneous.rb +75 -13
  37. data/lib/paystack_gateway/order.rb +259 -0
  38. data/lib/paystack_gateway/page.rb +317 -0
  39. data/lib/paystack_gateway/payment_request.rb +454 -0
  40. data/lib/paystack_gateway/plan.rb +247 -0
  41. data/lib/paystack_gateway/plans.rb +1 -80
  42. data/lib/paystack_gateway/product.rb +303 -0
  43. data/lib/paystack_gateway/refund.rb +197 -0
  44. data/lib/paystack_gateway/refunds.rb +1 -59
  45. data/lib/paystack_gateway/request_module.rb +20 -15
  46. data/lib/paystack_gateway/settlement.rb +60 -0
  47. data/lib/paystack_gateway/split.rb +286 -0
  48. data/lib/paystack_gateway/storefront.rb +329 -0
  49. data/lib/paystack_gateway/subaccount.rb +263 -0
  50. data/lib/paystack_gateway/subaccounts.rb +1 -35
  51. data/lib/paystack_gateway/subscription.rb +256 -0
  52. data/lib/paystack_gateway/terminal.rb +236 -0
  53. data/lib/paystack_gateway/transaction.rb +592 -0
  54. data/lib/paystack_gateway/transaction_response.rb +1 -33
  55. data/lib/paystack_gateway/transactions.rb +1 -86
  56. data/lib/paystack_gateway/transfer.rb +410 -0
  57. data/lib/paystack_gateway/transfer_recipient.rb +237 -0
  58. data/lib/paystack_gateway/transfer_recipients.rb +1 -21
  59. data/lib/paystack_gateway/transfers.rb +1 -57
  60. data/lib/paystack_gateway/verification.rb +1 -31
  61. data/lib/paystack_gateway/version.rb +1 -1
  62. data/lib/paystack_gateway/virtual_terminal.rb +297 -0
  63. data/lib/paystack_gateway.rb +61 -11
  64. metadata +50 -7
@@ -0,0 +1,353 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaystackGateway
4
+ # https://paystack.com/docs/api/dedicatedvirtualaccount
5
+ #
6
+ # Dedicated Virtual Accounts
7
+ # A collection of endpoints for creating and managing payment accounts for customers
8
+ module DedicatedVirtualAccount
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/dedicated-virtual-account/#list
18
+ # List Dedicated Accounts: GET /dedicated_account
19
+ # List dedicated virtual accounts available on your integration.
20
+ #
21
+ # @param active [Boolean]
22
+ # Status of the dedicated virtual account
23
+ # @param customer [Integer]
24
+ # The customer's ID
25
+ # @param currency ["NGN", "GHS"]
26
+ # The currency of the dedicated virtual account
27
+ # @param provider_slug [String]
28
+ # The bank's slug in lowercase, without spaces
29
+ # @param bank_id [String]
30
+ # The bank's ID
31
+ # @param per_page [Integer]
32
+ # The number of records to fetch per request
33
+ # @param page [Integer]
34
+ # The offset to retrieve data from
35
+ #
36
+ # @return [ListResponse] successful response
37
+ # @raise [ListError] if the request fails
38
+ api_method def self.list(
39
+ active: nil,
40
+ customer: nil,
41
+ currency: nil,
42
+ provider_slug: nil,
43
+ bank_id: nil,
44
+ per_page: nil,
45
+ page: nil
46
+ )
47
+ use_connection do |connection|
48
+ connection.get(
49
+ '/dedicated_account',
50
+ {
51
+ active:,
52
+ customer:,
53
+ currency:,
54
+ provider_slug:,
55
+ bank_id:,
56
+ perPage: per_page,
57
+ page:,
58
+ }.compact,
59
+ )
60
+ end
61
+ end
62
+
63
+ # Successful response from calling #create.
64
+ class CreateResponse < PaystackGateway::Response
65
+ delegate :bank,
66
+ :account_name,
67
+ :account_number,
68
+ :assigned,
69
+ :currency,
70
+ :metadata,
71
+ :active,
72
+ :id,
73
+ :created_at,
74
+ :updated_at,
75
+ :assignment,
76
+ :customer, to: :data
77
+ end
78
+
79
+ # Error response from #create.
80
+ class CreateError < ApiError; end
81
+
82
+ # https://paystack.com/docs/api/dedicated-virtual-account/#create
83
+ # Create Dedicated Account: POST /dedicated_account
84
+ # Create a dedicated virtual account for an existing customer
85
+ #
86
+ # @param customer [String] (required)
87
+ # The code for the previously created customer
88
+ # @param preferred_bank [String]
89
+ # The bank slug for preferred bank. To get a list of available banks, use the List
90
+ # Providers endpoint
91
+ # @param subaccount [String]
92
+ # Subaccount code of the account you want to split the transaction with
93
+ # @param split_code [String]
94
+ # Split code consisting of the lists of accounts you want to split the transaction
95
+ # with
96
+ #
97
+ # @return [CreateResponse] successful response
98
+ # @raise [CreateError] if the request fails
99
+ api_method def self.create(customer:, preferred_bank: nil, subaccount: nil, split_code: nil)
100
+ use_connection do |connection|
101
+ connection.post(
102
+ '/dedicated_account',
103
+ { customer:, preferred_bank:, subaccount:, split_code: }.compact,
104
+ )
105
+ end
106
+ end
107
+
108
+ # Successful response from calling #assign.
109
+ class AssignResponse < PaystackGateway::Response; end
110
+
111
+ # Error response from #assign.
112
+ class AssignError < ApiError; end
113
+
114
+ # https://paystack.com/docs/api/dedicated-virtual-account/#assign
115
+ # Assign Dedicated Account: POST /dedicated_account/assign
116
+ # With this endpoint, you can create a customer, validate the customer, and assign
117
+ # a DVA to the customer.
118
+ #
119
+ # @param email [String] (required)
120
+ # Customer's email address
121
+ # @param first_name [String] (required)
122
+ # Customer's first name
123
+ # @param last_name [String] (required)
124
+ # Customer's last name
125
+ # @param phone [String] (required)
126
+ # Customer's phone name
127
+ # @param preferred_bank [String] (required)
128
+ # The bank slug for preferred bank. To get a list of available banks, use the List
129
+ # Banks endpoint, passing `pay_with_bank_transfer=true` query parameter
130
+ # @param country ["NG", "GH"] (required)
131
+ # The two letter code country
132
+ # @param account_number [String]
133
+ # Customer's account number
134
+ # @param bvn [String]
135
+ # Customer's Bank Verification Number
136
+ # @param bank_code [String]
137
+ # Customer's bank code
138
+ # @param subaccount [String]
139
+ # Subaccount code of the account you want to split the transaction with
140
+ # @param split_code [String]
141
+ # Split code consisting of the lists of accounts you want to split the transaction
142
+ # with
143
+ #
144
+ # @return [AssignResponse] successful response
145
+ # @raise [AssignError] if the request fails
146
+ api_method def self.assign(
147
+ email:,
148
+ first_name:,
149
+ last_name:,
150
+ phone:,
151
+ preferred_bank:,
152
+ country:,
153
+ account_number: nil,
154
+ bvn: nil,
155
+ bank_code: nil,
156
+ subaccount: nil,
157
+ split_code: nil
158
+ )
159
+ use_connection do |connection|
160
+ connection.post(
161
+ '/dedicated_account/assign',
162
+ {
163
+ email:,
164
+ first_name:,
165
+ last_name:,
166
+ phone:,
167
+ preferred_bank:,
168
+ country:,
169
+ account_number:,
170
+ bvn:,
171
+ bank_code:,
172
+ subaccount:,
173
+ split_code:,
174
+ }.compact,
175
+ )
176
+ end
177
+ end
178
+
179
+ # Successful response from calling #fetch.
180
+ class FetchResponse < PaystackGateway::Response
181
+ delegate :customer,
182
+ :bank,
183
+ :id,
184
+ :account_name,
185
+ :account_number,
186
+ :created_at,
187
+ :updated_at,
188
+ :currency,
189
+ :split_config,
190
+ :active,
191
+ :assigned, to: :data
192
+ end
193
+
194
+ # Error response from #fetch.
195
+ class FetchError < ApiError; end
196
+
197
+ # https://paystack.com/docs/api/dedicated-virtual-account/#fetch
198
+ # Fetch Dedicated Account: GET /dedicated_account/{id}
199
+ # Get details of a dedicated virtual account on your integration.
200
+ #
201
+ # @param id [String] (required)
202
+ # ID of dedicated virtual account
203
+ #
204
+ # @return [FetchResponse] successful response
205
+ # @raise [FetchError] if the request fails
206
+ api_method def self.fetch(id:)
207
+ use_connection do |connection|
208
+ connection.get(
209
+ "/dedicated_account/#{id}",
210
+ )
211
+ end
212
+ end
213
+
214
+ # Successful response from calling #deactivate.
215
+ class DeactivateResponse < PaystackGateway::Response
216
+ delegate :bank,
217
+ :account_name,
218
+ :account_number,
219
+ :assigned,
220
+ :currency,
221
+ :metadata,
222
+ :active,
223
+ :id,
224
+ :created_at,
225
+ :updated_at,
226
+ :assignment, to: :data
227
+ end
228
+
229
+ # Error response from #deactivate.
230
+ class DeactivateError < ApiError; end
231
+
232
+ # https://paystack.com/docs/api/dedicated-virtual-account/#deactivate
233
+ # Deactivate Dedicated Account: DELETE /dedicated_account/{id}
234
+ # Deactivate a dedicated virtual account on your integration.
235
+ #
236
+ # @param id [String] (required)
237
+ # ID of dedicated virtual account
238
+ #
239
+ # @return [DeactivateResponse] successful response
240
+ # @raise [DeactivateError] if the request fails
241
+ api_method def self.deactivate(id:)
242
+ use_connection do |connection|
243
+ connection.delete(
244
+ "/dedicated_account/#{id}",
245
+ )
246
+ end
247
+ end
248
+
249
+ # Successful response from calling #requery.
250
+ class RequeryResponse < PaystackGateway::Response; end
251
+
252
+ # Error response from #requery.
253
+ class RequeryError < ApiError; end
254
+
255
+ # https://paystack.com/docs/api/dedicated-virtual-account/#requery
256
+ # Requery Dedicated Account: GET /dedicated_account/requery
257
+ # Requery Dedicated Virtual Account for new transactions
258
+ #
259
+ # @param account_number [String]
260
+ # Virtual account number to requery
261
+ # @param provider_slug [String]
262
+ # The bank's slug in lowercase, without spaces.
263
+ # @param date [Time]
264
+ # The day the transfer was made
265
+ #
266
+ # @return [RequeryResponse] successful response
267
+ # @raise [RequeryError] if the request fails
268
+ api_method def self.requery(account_number: nil, provider_slug: nil, date: nil)
269
+ use_connection do |connection|
270
+ connection.get(
271
+ '/dedicated_account/requery',
272
+ { account_number:, provider_slug:, date: }.compact,
273
+ )
274
+ end
275
+ end
276
+
277
+ # Successful response from calling #add_split.
278
+ class AddSplitResponse < PaystackGateway::Response; end
279
+
280
+ # Error response from #add_split.
281
+ class AddSplitError < ApiError; end
282
+
283
+ # https://paystack.com/docs/api/dedicated-virtual-account/#add_split
284
+ # Split Dedicated Account Transaction: POST /dedicated_account/split
285
+ # Split a dedicated virtual account transaction with one or more accounts
286
+ #
287
+ # @param account_number [String] (required)
288
+ # Valid Dedicated virtual account
289
+ # @param subaccount [String]
290
+ # Subaccount code of the account you want to split the transaction with
291
+ # @param split_code [String]
292
+ # Split code consisting of the lists of accounts you want to split the transaction
293
+ # with
294
+ #
295
+ # @return [AddSplitResponse] successful response
296
+ # @raise [AddSplitError] if the request fails
297
+ api_method def self.add_split(account_number:, subaccount: nil, split_code: nil)
298
+ use_connection do |connection|
299
+ connection.post(
300
+ '/dedicated_account/split',
301
+ { account_number:, subaccount:, split_code: }.compact,
302
+ )
303
+ end
304
+ end
305
+
306
+ # Successful response from calling #remove_split.
307
+ class RemoveSplitResponse < PaystackGateway::Response; end
308
+
309
+ # Error response from #remove_split.
310
+ class RemoveSplitError < ApiError; end
311
+
312
+ # https://paystack.com/docs/api/dedicated-virtual-account/#remove_split
313
+ # Remove Split from Dedicated Account: DELETE /dedicated_account/split
314
+ # If you've previously set up split payment for transactions on a dedicated virtual
315
+ # account, you can remove it with this endpoint
316
+ #
317
+ # @param account_number [String] (required)
318
+ # Valid Dedicated virtual account
319
+ #
320
+ # @return [RemoveSplitResponse] successful response
321
+ # @raise [RemoveSplitError] if the request fails
322
+ api_method def self.remove_split(account_number:)
323
+ use_connection do |connection|
324
+ connection.delete(
325
+ '/dedicated_account/split',
326
+ ) do |request|
327
+ request.body = { account_number: }.compact
328
+ end
329
+ end
330
+ end
331
+
332
+ # Successful response from calling #available_providers.
333
+ class AvailableProvidersResponse < PaystackGateway::Response; end
334
+
335
+ # Error response from #available_providers.
336
+ class AvailableProvidersError < ApiError; end
337
+
338
+ # https://paystack.com/docs/api/dedicated-virtual-account/#available_providers
339
+ # Fetch Bank Providers: GET /dedicated_account/available_providers
340
+ # Get available bank providers for a dedicated virtual account
341
+ #
342
+ #
343
+ # @return [AvailableProvidersResponse] successful response
344
+ # @raise [AvailableProvidersError] if the request fails
345
+ api_method def self.available_providers
346
+ use_connection do |connection|
347
+ connection.get(
348
+ '/dedicated_account/available_providers',
349
+ )
350
+ end
351
+ end
352
+ end
353
+ end
@@ -1,66 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module PaystackGateway
4
- # The Dedicated Virtual Account API enables Nigerian merchants to manage unique
5
- # payment accounts of their customers.
6
- # https://paystack.com/docs/api/dedicated-virtual-account/
7
- module DedicatedVirtualAccounts
8
- include PaystackGateway::RequestModule
9
-
10
- # Response from POST /dedicated_account endpoint.
11
- class CreateDedicatedVirtualAccountResponse < PaystackGateway::Response; end
12
-
13
- api_method def self.create_dedicated_virtual_account(customer_id_or_code:, subaccount_code:, preferred_bank:)
14
- use_connection do |connection|
15
- connection.post(
16
- '/dedicated_account',
17
- {
18
- customer: customer_id_or_code,
19
- preferred_bank:,
20
- subaccount: subaccount_code,
21
- phone: '+2348011111111', # phone number is required by paystack for some reason, use fake phone number
22
- },
23
- )
24
- end
25
- end
26
-
27
- # Response from POST /dedicated_account/assign endpoint.
28
- class AssignDedicatedVirtualAccountResponse < PaystackGateway::Response; end
29
-
30
- api_method def self.assign_dedicated_virtual_account(
31
- email:, first_name:, last_name:, subaccount_code:, preferred_bank:
32
- )
33
- use_connection do |connection|
34
- connection.post(
35
- '/dedicated_account/assign',
36
- {
37
- email:,
38
- first_name:,
39
- last_name:,
40
- preferred_bank:,
41
- country: :NG,
42
- subaccount: subaccount_code,
43
- },
44
- )
45
- end
46
- end
47
-
48
- # Response from POST /dedicated_account/split endpoint
49
- class SplitDedicatedAccountTransactionResponse < PaystackGateway::Response; end
50
-
51
- api_method def self.split_dedicated_account_transaction(customer_id_or_code:, subaccount_code:)
52
- use_connection do |connection|
53
- connection.post('/dedicated_account/split', { customer: customer_id_or_code, subaccount: subaccount_code })
54
- end
55
- end
56
-
57
- # Response from GET /dedicated_account endpoint
58
- class RequeryDedicatedAccountResponse < PaystackGateway::Response; end
59
-
60
- api_method def self.requery_dedicated_account(account_number:, bank:)
61
- use_connection do |connection|
62
- connection.get('/dedicated_account', { account_number:, provider_slug: bank })
63
- end
64
- end
65
- end
66
- end
3
+ require 'paystack_gateway/legacy/dedicated_virtual_accounts'
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaystackGateway
4
+ # https://paystack.com/docs/api/directdebit
5
+ #
6
+ # Direct Debit
7
+ # A collection of endpoints for managing Direct Debit
8
+ module DirectDebit
9
+ include PaystackGateway::RequestModule
10
+
11
+ # Successful response from calling #trigger_activation_charge.
12
+ class TriggerActivationChargeResponse < PaystackGateway::Response; end
13
+
14
+ # Error response from #trigger_activation_charge.
15
+ class TriggerActivationChargeError < ApiError; end
16
+
17
+ # https://paystack.com/docs/api/direct-debit/#trigger_activation_charge
18
+ # Trigger Activation Charge: PUT /directdebit/activation-charge
19
+ # Trigger activation charge for specified customers
20
+ #
21
+ # @param customer_ids [Array<Integer>] (required)
22
+ # Array of customer IDs to trigger activation charge for
23
+ #
24
+ # @return [TriggerActivationChargeResponse] successful response
25
+ # @raise [TriggerActivationChargeError] if the request fails
26
+ api_method def self.trigger_activation_charge(customer_ids:)
27
+ use_connection do |connection|
28
+ connection.put(
29
+ '/directdebit/activation-charge',
30
+ { customer_ids: }.compact,
31
+ )
32
+ end
33
+ end
34
+
35
+ # Successful response from calling #list_mandate_authorizations.
36
+ class ListMandateAuthorizationsResponse < PaystackGateway::Response; end
37
+
38
+ # Error response from #list_mandate_authorizations.
39
+ class ListMandateAuthorizationsError < ApiError; end
40
+
41
+ # https://paystack.com/docs/api/direct-debit/#list_mandate_authorizations
42
+ # List Mandate Authorizations: GET /directdebit/mandate-authorizations
43
+ # Get a list of all the direct debit mandates on your integration
44
+ #
45
+ # @param cursor [String]
46
+ # The cursor value of the next set of authorizations to fetch. You can get this from
47
+ # the meta object of the response
48
+ # @param status ["pending", "active", "revoked"]
49
+ # Filter by the authorization status
50
+ # @param per_page [Integer]
51
+ # The number of authorizations to fetch per request
52
+ #
53
+ # @return [ListMandateAuthorizationsResponse] successful response
54
+ # @raise [ListMandateAuthorizationsError] if the request fails
55
+ api_method def self.list_mandate_authorizations(cursor: nil, status: nil, per_page: nil)
56
+ use_connection do |connection|
57
+ connection.get(
58
+ '/directdebit/mandate-authorizations',
59
+ { cursor:, status:, per_page: }.compact,
60
+ )
61
+ end
62
+ end
63
+ end
64
+ end