paystack-gateway 0.1.1 → 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 +81 -102
  5. data/lib/paystack_gateway/api_error.rb +3 -1
  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 +13 -2
  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 +12 -11
  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 +50 -18
  64. metadata +50 -7
@@ -0,0 +1,454 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaystackGateway
4
+ # https://paystack.com/docs/api/paymentrequest
5
+ #
6
+ # Payment Requests
7
+ # A collection of endpoints for managing invoices for the payment of goods and services
8
+ module PaymentRequest
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/payment-request/#list
18
+ # List Payment Request: GET /paymentrequest
19
+ # List all previously created payment requests to your customers
20
+ #
21
+ # @param per_page [Integer]
22
+ # Number of records to fetch per page
23
+ # @param page [Integer]
24
+ # The section to retrieve
25
+ # @param customer [String]
26
+ # Customer ID
27
+ # @param status ["draft", "pending", "success", "failed"]
28
+ # Invoice status to filter
29
+ # @param currency [String]
30
+ # If your integration supports more than one currency, choose the one to filter
31
+ # @param from [Time]
32
+ # The start date
33
+ # @param to [Time]
34
+ # The end date
35
+ #
36
+ # @return [ListResponse] successful response
37
+ # @raise [ListError] if the request fails
38
+ api_method def self.list(
39
+ per_page: nil,
40
+ page: nil,
41
+ customer: nil,
42
+ status: nil,
43
+ currency: nil,
44
+ from: nil,
45
+ to: nil
46
+ )
47
+ use_connection do |connection|
48
+ connection.get(
49
+ '/paymentrequest',
50
+ {
51
+ perPage: per_page,
52
+ page:,
53
+ customer:,
54
+ status:,
55
+ currency:,
56
+ from:,
57
+ to:,
58
+ }.compact,
59
+ )
60
+ end
61
+ end
62
+
63
+ # Successful response from calling #create.
64
+ class CreateResponse < PaystackGateway::Response
65
+ delegate :id,
66
+ :integration,
67
+ :domain,
68
+ :amount,
69
+ :currency,
70
+ :due_date,
71
+ :has_invoice,
72
+ :invoice_number,
73
+ :description,
74
+ :line_items,
75
+ :tax,
76
+ :request_code,
77
+ :paid,
78
+ :metadata,
79
+ :notifications,
80
+ :offline_reference,
81
+ :customer,
82
+ :created_at,
83
+ :discount,
84
+ :split_code, to: :data
85
+ end
86
+
87
+ # Error response from #create.
88
+ class CreateError < ApiError; end
89
+
90
+ # https://paystack.com/docs/api/payment-request/#create
91
+ # Create Payment Request: POST /paymentrequest
92
+ # Create a new payment request by issuing an invoice to a customer
93
+ #
94
+ # @param customer [String] (required)
95
+ # Customer id or code
96
+ # @param amount [Integer] (required)
97
+ # Payment request amount. Only useful if line items and tax values are ignored. The
98
+ # endpoint will throw a friendly warning if neither is available.
99
+ # @param currency [String]
100
+ # Specify the currency of the invoice. Allowed values are NGN, GHS, ZAR and USD. Defaults
101
+ # to NGN
102
+ # @param due_date [Time]
103
+ # ISO 8601 representation of request due date
104
+ # @param description [String]
105
+ # A short description of the payment request
106
+ # @param line_items [Array<Hash>]
107
+ # Array of line items
108
+ # @param tax [Array<Hash>]
109
+ # Array of taxes
110
+ # @param send_notification [Boolean]
111
+ # Indicates whether Paystack sends an email notification to customer. Defaults to
112
+ # true
113
+ # @param draft [Boolean]
114
+ # Indicate if request should be saved as draft. Defaults to false and overrides send_notification
115
+ # @param has_invoice [Boolean]
116
+ # Set to true to create a draft invoice (adds an auto incrementing invoice number
117
+ # if none is provided) even if there are no line_items or tax passed
118
+ # @param invoice_number [Integer]
119
+ # Numeric value of invoice. Invoice will start from 1 and auto increment from there.
120
+ # This field is to help override whatever value Paystack decides. Auto increment for
121
+ # subsequent invoices continue from this point.
122
+ # @param split_code [String]
123
+ # The split code of the transaction split.
124
+ #
125
+ # @return [CreateResponse] successful response
126
+ # @raise [CreateError] if the request fails
127
+ api_method def self.create(
128
+ customer:,
129
+ amount:,
130
+ currency: nil,
131
+ due_date: nil,
132
+ description: nil,
133
+ line_items: nil,
134
+ tax: nil,
135
+ send_notification: nil,
136
+ draft: nil,
137
+ has_invoice: nil,
138
+ invoice_number: nil,
139
+ split_code: nil
140
+ )
141
+ use_connection do |connection|
142
+ connection.post(
143
+ '/paymentrequest',
144
+ {
145
+ customer:,
146
+ amount:,
147
+ currency:,
148
+ due_date:,
149
+ description:,
150
+ line_items:,
151
+ tax:,
152
+ send_notification:,
153
+ draft:,
154
+ has_invoice:,
155
+ invoice_number:,
156
+ split_code:,
157
+ }.compact,
158
+ )
159
+ end
160
+ end
161
+
162
+ # Successful response from calling #fetch.
163
+ class FetchResponse < PaystackGateway::Response; end
164
+
165
+ # Error response from #fetch.
166
+ class FetchError < ApiError; end
167
+
168
+ # https://paystack.com/docs/api/payment-request/#fetch
169
+ # Fetch Payment Request: GET /paymentrequest/{id}
170
+ # Fetch a previously created payment request
171
+ #
172
+ # @param id [Integer] (required)
173
+ # The unique identifier of a previously created payment request
174
+ #
175
+ # @return [FetchResponse] successful response
176
+ # @raise [FetchError] if the request fails
177
+ api_method def self.fetch(id:)
178
+ use_connection do |connection|
179
+ connection.get(
180
+ "/paymentrequest/#{id}",
181
+ )
182
+ end
183
+ end
184
+
185
+ # Successful response from calling #update.
186
+ class UpdateResponse < PaystackGateway::Response
187
+ delegate :id,
188
+ :integration,
189
+ :domain,
190
+ :amount,
191
+ :currency,
192
+ :due_date,
193
+ :has_invoice,
194
+ :invoice_number,
195
+ :description,
196
+ :pdf_url,
197
+ :line_items,
198
+ :tax,
199
+ :request_code,
200
+ :paid,
201
+ :paid_at,
202
+ :metadata,
203
+ :notifications,
204
+ :offline_reference,
205
+ :customer,
206
+ :created_at,
207
+ :discount,
208
+ :split_code, to: :data
209
+ end
210
+
211
+ # Error response from #update.
212
+ class UpdateError < ApiError; end
213
+
214
+ # https://paystack.com/docs/api/payment-request/#update
215
+ # Update Payment Request: PUT /paymentrequest/{id}
216
+ # Update a previously created payment request
217
+ #
218
+ # @param id [Integer] (required)
219
+ # The unique identifier of a previously created payment request
220
+ # @param customer [String]
221
+ # Customer id or code
222
+ # @param amount [Integer]
223
+ # Payment request amount. Only useful if line items and tax values are ignored. The
224
+ # endpoint will throw a friendly warning if neither is available.
225
+ # @param currency [String]
226
+ # Specify the currency of the invoice. Allowed values are NGN, GHS, ZAR and USD. Defaults
227
+ # to NGN
228
+ # @param due_date [Time]
229
+ # ISO 8601 representation of request due date
230
+ # @param description [String]
231
+ # A short description of the payment request
232
+ # @param line_items [Array<Hash>]
233
+ # Array of line items
234
+ # @param tax [Array<Hash>]
235
+ # Array of taxes
236
+ # @param send_notification [Boolean]
237
+ # Indicates whether Paystack sends an email notification to customer. Defaults to
238
+ # true
239
+ # @param draft [Boolean]
240
+ # Indicate if request should be saved as draft. Defaults to false and overrides send_notification
241
+ # @param has_invoice [Boolean]
242
+ # Set to true to create a draft invoice (adds an auto incrementing invoice number
243
+ # if none is provided) even if there are no line_items or tax passed
244
+ # @param invoice_number [Integer]
245
+ # Numeric value of invoice. Invoice will start from 1 and auto increment from there.
246
+ # This field is to help override whatever value Paystack decides. Auto increment for
247
+ # subsequent invoices continue from this point.
248
+ # @param split_code [String]
249
+ # The split code of the transaction split.
250
+ #
251
+ # @return [UpdateResponse] successful response
252
+ # @raise [UpdateError] if the request fails
253
+ api_method def self.update(
254
+ id:,
255
+ customer: nil,
256
+ amount: nil,
257
+ currency: nil,
258
+ due_date: nil,
259
+ description: nil,
260
+ line_items: nil,
261
+ tax: nil,
262
+ send_notification: nil,
263
+ draft: nil,
264
+ has_invoice: nil,
265
+ invoice_number: nil,
266
+ split_code: nil
267
+ )
268
+ use_connection do |connection|
269
+ connection.put(
270
+ "/paymentrequest/#{id}",
271
+ {
272
+ customer:,
273
+ amount:,
274
+ currency:,
275
+ due_date:,
276
+ description:,
277
+ line_items:,
278
+ tax:,
279
+ send_notification:,
280
+ draft:,
281
+ has_invoice:,
282
+ invoice_number:,
283
+ split_code:,
284
+ }.compact,
285
+ )
286
+ end
287
+ end
288
+
289
+ # Successful response from calling #verify.
290
+ class VerifyResponse < PaystackGateway::Response
291
+ delegate :id,
292
+ :integration,
293
+ :domain,
294
+ :amount,
295
+ :currency,
296
+ :due_date,
297
+ :has_invoice,
298
+ :invoice_number,
299
+ :description,
300
+ :pdf_url,
301
+ :line_items,
302
+ :tax,
303
+ :request_code,
304
+ :paid,
305
+ :paid_at,
306
+ :metadata,
307
+ :notifications,
308
+ :offline_reference,
309
+ :customer,
310
+ :created_at,
311
+ :discount,
312
+ :split_code,
313
+ :pending_amount, to: :data
314
+ end
315
+
316
+ # Error response from #verify.
317
+ class VerifyError < ApiError; end
318
+
319
+ # https://paystack.com/docs/api/payment-request/#verify
320
+ # Verify Payment Request: GET /paymentrequest/verify/{id}
321
+ # Verify the status of a previously created payment request
322
+ #
323
+ # @param id [Integer] (required)
324
+ # The unique identifier of a previously created payment request
325
+ #
326
+ # @return [VerifyResponse] successful response
327
+ # @raise [VerifyError] if the request fails
328
+ api_method def self.verify(id:)
329
+ use_connection do |connection|
330
+ connection.get(
331
+ "/paymentrequest/verify/#{id}",
332
+ )
333
+ end
334
+ end
335
+
336
+ # Successful response from calling #notify.
337
+ class NotifyResponse < PaystackGateway::Response; end
338
+
339
+ # Error response from #notify.
340
+ class NotifyError < ApiError; end
341
+
342
+ # https://paystack.com/docs/api/payment-request/#notify
343
+ # Send Notification: POST /paymentrequest/notify/{id}
344
+ # Trigger an email reminder to a customer for a previously created payment request
345
+ #
346
+ # @param id [Integer] (required)
347
+ # The unique identifier of a previously created payment request
348
+ #
349
+ # @return [NotifyResponse] successful response
350
+ # @raise [NotifyError] if the request fails
351
+ api_method def self.notify(id:)
352
+ use_connection do |connection|
353
+ connection.post(
354
+ "/paymentrequest/notify/#{id}",
355
+ )
356
+ end
357
+ end
358
+
359
+ # Successful response from calling #totals.
360
+ class TotalsResponse < PaystackGateway::Response
361
+ delegate :pending, :successful, :total, to: :data
362
+ end
363
+
364
+ # Error response from #totals.
365
+ class TotalsError < ApiError; end
366
+
367
+ # https://paystack.com/docs/api/payment-request/#totals
368
+ # Payment Request Total: GET /paymentrequest/totals
369
+ # Get the metric of all pending and successful payment requests
370
+ #
371
+ #
372
+ # @return [TotalsResponse] successful response
373
+ # @raise [TotalsError] if the request fails
374
+ api_method def self.totals
375
+ use_connection do |connection|
376
+ connection.get(
377
+ '/paymentrequest/totals',
378
+ )
379
+ end
380
+ end
381
+
382
+ # Successful response from calling #finalize.
383
+ class FinalizeResponse < PaystackGateway::Response
384
+ delegate :id,
385
+ :integration,
386
+ :domain,
387
+ :amount,
388
+ :currency,
389
+ :due_date,
390
+ :has_invoice,
391
+ :invoice_number,
392
+ :description,
393
+ :pdf_url,
394
+ :line_items,
395
+ :tax,
396
+ :request_code,
397
+ :paid,
398
+ :paid_at,
399
+ :metadata,
400
+ :notifications,
401
+ :offline_reference,
402
+ :customer,
403
+ :created_at,
404
+ :discount,
405
+ :split_code,
406
+ :pending_amount, to: :data
407
+ end
408
+
409
+ # Error response from #finalize.
410
+ class FinalizeError < ApiError; end
411
+
412
+ # https://paystack.com/docs/api/payment-request/#finalize
413
+ # Finalize Payment Request: POST /paymentrequest/finalize/{id}
414
+ # Finalise the creation of a draft payment request for a customer
415
+ #
416
+ # @param id [Integer] (required)
417
+ # The unique identifier of a draft payment request
418
+ #
419
+ # @return [FinalizeResponse] successful response
420
+ # @raise [FinalizeError] if the request fails
421
+ api_method def self.finalize(id:)
422
+ use_connection do |connection|
423
+ connection.post(
424
+ "/paymentrequest/finalize/#{id}",
425
+ )
426
+ end
427
+ end
428
+
429
+ # Successful response from calling #archive.
430
+ class ArchiveResponse < PaystackGateway::Response; end
431
+
432
+ # Error response from #archive.
433
+ class ArchiveError < ApiError; end
434
+
435
+ # https://paystack.com/docs/api/payment-request/#archive
436
+ # Archive Payment Request: POST /paymentrequest/archive/{id}
437
+ # Archive a payment request to clean up your records. An archived payment request
438
+ # cannot be verified and will not be returned when listing all previously created
439
+ # payment requests.
440
+ #
441
+ # @param id [Integer] (required)
442
+ # The unique identifier of a previously created payment request
443
+ #
444
+ # @return [ArchiveResponse] successful response
445
+ # @raise [ArchiveError] if the request fails
446
+ api_method def self.archive(id:)
447
+ use_connection do |connection|
448
+ connection.post(
449
+ "/paymentrequest/archive/#{id}",
450
+ )
451
+ end
452
+ end
453
+ end
454
+ end
@@ -0,0 +1,247 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaystackGateway
4
+ # https://paystack.com/docs/api/plan
5
+ #
6
+ # Plans
7
+ # A collection of endpoints for creating and managing recurring payment configuration
8
+ module Plan
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/plan/#list
18
+ # List Plans: GET /plan
19
+ # List all recurring payment plans
20
+ #
21
+ # @param per_page [Integer]
22
+ # Number of records to fetch per page
23
+ # @param page [Integer]
24
+ # The section to retrieve
25
+ # @param interval ["daily", "weekly", "monthly", "biannually", "annually"]
26
+ # Specify interval of the plan
27
+ # @param amount [Integer]
28
+ # The amount on the plans to retrieve
29
+ # @param from [Time]
30
+ # The start date
31
+ # @param to [Time]
32
+ # The end date
33
+ #
34
+ # @return [ListResponse] successful response
35
+ # @raise [ListError] if the request fails
36
+ api_method def self.list(
37
+ per_page: nil,
38
+ page: nil,
39
+ interval: nil,
40
+ amount: nil,
41
+ from: nil,
42
+ to: nil
43
+ )
44
+ use_connection do |connection|
45
+ connection.get(
46
+ '/plan',
47
+ {
48
+ perPage: per_page,
49
+ page:,
50
+ interval:,
51
+ amount:,
52
+ from:,
53
+ to:,
54
+ }.compact,
55
+ )
56
+ end
57
+ end
58
+
59
+ # Successful response from calling #create.
60
+ class CreateResponse < PaystackGateway::Response
61
+ delegate :currency,
62
+ :name,
63
+ :amount,
64
+ :interval,
65
+ :integration,
66
+ :domain,
67
+ :plan_code,
68
+ :invoice_limit,
69
+ :send_invoices,
70
+ :send_sms,
71
+ :hosted_page,
72
+ :migrate,
73
+ :is_archived,
74
+ :id,
75
+ :createdAt,
76
+ :updatedAt, to: :data
77
+ end
78
+
79
+ # Error response from #create.
80
+ class CreateError < ApiError; end
81
+
82
+ # https://paystack.com/docs/api/plan/#create
83
+ # Create Plan: POST /plan
84
+ # Create a plan for recurring payments
85
+ #
86
+ # @param name [String] (required)
87
+ # Name of plan
88
+ # @param amount [Integer] (required)
89
+ # Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents,
90
+ # if currency is ZAR
91
+ # @param interval ["daily", "weekly", "monthly", "biannually", "annually"] (required)
92
+ # Payment interval
93
+ # @param description [String]
94
+ # A description for this plan
95
+ # @param send_invoices [Boolean]
96
+ # Set to false if you don't want invoices to be sent to your customers
97
+ # @param send_sms [Boolean]
98
+ # Set to false if you don't want text messages to be sent to your customers
99
+ # @param currency [String]
100
+ # Currency in which amount is set. Allowed values are NGN, GHS, ZAR or USD
101
+ # @param invoice_limit [Integer]
102
+ # Number of invoices to raise during subscription to this plan. Can be overridden
103
+ # by specifying an invoice_limit while subscribing.
104
+ #
105
+ # @return [CreateResponse] successful response
106
+ # @raise [CreateError] if the request fails
107
+ api_method def self.create(
108
+ name:,
109
+ amount:,
110
+ interval:,
111
+ description: nil,
112
+ send_invoices: nil,
113
+ send_sms: nil,
114
+ currency: nil,
115
+ invoice_limit: nil
116
+ )
117
+ use_connection do |connection|
118
+ connection.post(
119
+ '/plan',
120
+ {
121
+ name:,
122
+ amount:,
123
+ interval:,
124
+ description:,
125
+ send_invoices:,
126
+ send_sms:,
127
+ currency:,
128
+ invoice_limit:,
129
+ }.compact,
130
+ )
131
+ end
132
+ end
133
+
134
+ # Successful response from calling #fetch.
135
+ class FetchResponse < PaystackGateway::Response
136
+ delegate :subscriptions,
137
+ :pages,
138
+ :domain,
139
+ :name,
140
+ :plan_code,
141
+ :description,
142
+ :amount,
143
+ :interval,
144
+ :invoice_limit,
145
+ :send_invoices,
146
+ :send_sms,
147
+ :hosted_page,
148
+ :hosted_page_url,
149
+ :hosted_page_summary,
150
+ :currency,
151
+ :migrate,
152
+ :is_deleted,
153
+ :is_archived,
154
+ :id,
155
+ :integration,
156
+ :createdAt,
157
+ :updatedAt,
158
+ :pages_count,
159
+ :subscribers_count,
160
+ :subscriptions_count,
161
+ :active_subscriptions_count,
162
+ :total_revenue,
163
+ :subscribers, to: :data
164
+ end
165
+
166
+ # Error response from #fetch.
167
+ class FetchError < ApiError; end
168
+
169
+ # https://paystack.com/docs/api/plan/#fetch
170
+ # Fetch Plan: GET /plan/{code}
171
+ # Get the details of a payment plan
172
+ #
173
+ # @param code [String] (required)
174
+ # The plan code you want to fetch
175
+ #
176
+ # @return [FetchResponse] successful response
177
+ # @raise [FetchError] if the request fails
178
+ api_method def self.fetch(code:)
179
+ use_connection do |connection|
180
+ connection.get(
181
+ "/plan/#{code}",
182
+ )
183
+ end
184
+ end
185
+
186
+ # Successful response from calling #update.
187
+ class UpdateResponse < PaystackGateway::Response; end
188
+
189
+ # Error response from #update.
190
+ class UpdateError < ApiError; end
191
+
192
+ # https://paystack.com/docs/api/plan/#update
193
+ # Update Plan: PUT /plan/{code}
194
+ # Update a plan details on your integration
195
+ #
196
+ # @param code [String] (required)
197
+ # The plan code you want to fetch
198
+ # @param name [String]
199
+ # Name of plan
200
+ # @param amount [Integer]
201
+ # Amount should be in kobo if currency is NGN, pesewas, if currency is GHS, and cents,
202
+ # if currency is ZAR
203
+ # @param interval ["daily", "weekly", "monthly", "biannually", "annually"]
204
+ # Payment interval
205
+ # @param description [Boolean]
206
+ # A description for this plan
207
+ # @param send_invoices [Boolean]
208
+ # Set to false if you don't want invoices to be sent to your customers
209
+ # @param send_sms [Boolean]
210
+ # Set to false if you don't want text messages to be sent to your customers
211
+ # @param currency [String]
212
+ # Currency in which amount is set. Allowed values are NGN, GHS, ZAR or USD
213
+ # @param invoice_limit [Integer]
214
+ # Number of invoices to raise during subscription to this plan. Can be overridden
215
+ # by specifying an invoice_limit while subscribing.
216
+ #
217
+ # @return [UpdateResponse] successful response
218
+ # @raise [UpdateError] if the request fails
219
+ api_method def self.update(
220
+ code:,
221
+ name: nil,
222
+ amount: nil,
223
+ interval: nil,
224
+ description: nil,
225
+ send_invoices: nil,
226
+ send_sms: nil,
227
+ currency: nil,
228
+ invoice_limit: nil
229
+ )
230
+ use_connection do |connection|
231
+ connection.put(
232
+ "/plan/#{code}",
233
+ {
234
+ name:,
235
+ amount:,
236
+ interval:,
237
+ description:,
238
+ send_invoices:,
239
+ send_sms:,
240
+ currency:,
241
+ invoice_limit:,
242
+ }.compact,
243
+ )
244
+ end
245
+ end
246
+ end
247
+ end