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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 960e45b01e324553500b07374aa199876b404c5926192a96f52247287dde5c68
4
- data.tar.gz: 191204e218673752ccc91c7ea1e08ad43b085e698eebf487bd77cbbce196f6f2
3
+ metadata.gz: 860924941f63099d74680601ef554e6a8f10f10481381ec04316dec8ea37bff8
4
+ data.tar.gz: 9c74c683a3612bd75d8f03ec2cc2ad4a0d18ec078e085c9693862b1e4eb3bf23
5
5
  SHA512:
6
- metadata.gz: ab9e8ad8ed05816b07dc34e67099f80109f4ec20ae34b39ab3905c7b1bcb32fb5278913ffa5e6e85ac4486ca8417208849a091fff828e04eeed282227f19e704
7
- data.tar.gz: 8bb3746cc29c83352555a60567193c1e8a82b99711681e9730325e25279341b4d30e9724b4fdd54bf9e63e300418d1ee4f767474afa5c23c0f68c54492dbb384
6
+ metadata.gz: ae2df9306e0b22b880347d442e7e7a9bbbc3c76a885f830371022a8cc32a17cd300bbe0619fabee14ab5a674cfd4f8c23c51781081ac82855685fe0feb1184f1
7
+ data.tar.gz: e24f66f685989b6867eb4ca409dc656d853ccf876a6f83f3665828da152227f93dfde8cdc96e19a7c8fc214c9886fff8dc0a08933b853b33748553cd42ab19d0
data/.rubocop.yml CHANGED
@@ -1,4 +1,4 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-minitest
3
3
  - rubocop-rake
4
4
 
@@ -6,10 +6,20 @@ AllCops:
6
6
  TargetRubyVersion: 3.3
7
7
  NewCops: enable
8
8
 
9
+ Layout/MultilineMethodCallIndentation:
10
+ EnforcedStyle: indented_relative_to_receiver
9
11
  Metrics/AbcSize:
10
- Max: 25
12
+ Max: 28
13
+ Metrics/CyclomaticComplexity:
14
+ Max: 10
11
15
  Metrics/MethodLength:
12
16
  Max: 25
17
+ Metrics/ModuleLength:
18
+ Max: 250
19
+ Metrics/ParameterLists:
20
+ Enabled: false
21
+ Metrics/PerceivedComplexity:
22
+ Max: 10
13
23
  Minitest/MultipleAssertions:
14
24
  Enabled: false
15
25
  Naming/FileName:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2026-10-04
4
+
5
+ ### Added
6
+
7
+ - Generate API modules, methods, response classes, and errors from Paystack's
8
+ OpenAPI specification.
9
+ - Cover 163 generated operations across 27 API groups, including Direct Debit
10
+ and Virtual Terminal.
11
+ - Add opt-out response and error extensions for common transaction, transfer,
12
+ refund, customer, and plan workflows.
13
+ - Generate per-operation happy-path VCR tests for response-class selection and
14
+ response data parsing, with recording inputs directly in each test.
15
+ - Add 126 successful canonical endpoint recordings and document prerequisites
16
+ for 37 intentionally skipped endpoint tests.
17
+ - Add isolated regression tests for DELETE request bodies.
18
+
19
+ ### Changed
20
+
21
+ - Update the Paystack OpenAPI submodule to `07c5abc` and generate from its
22
+ bundled `dist/paystack.yaml` specification.
23
+ - Prefer the generated singular API modules while retaining the original plural
24
+ modules as deprecated, backwards-compatible entry points.
25
+ - Organize deprecated implementations under `paystack_gateway/legacy` while
26
+ preserving their original require paths.
27
+ - Log full failed-response details at debug level and use lazy logger blocks.
28
+ - Preserve manually maintained API tests when regenerating the SDK.
29
+
30
+ ### Fixed
31
+
32
+ - Include path-item parameters when generating method signatures and URLs.
33
+ - Preserve OpenAPI enum options and Ruby-style keyword names in generated API
34
+ documentation.
35
+ - Treat request properties as optional unless the OpenAPI schema marks them as
36
+ required.
37
+ - Support top-level array request bodies such as bulk charges.
38
+ - Preserve the legacy `Miscellaneous.list_banks` API across regeneration.
39
+ - Apply refund extensions to the generated refund response classes.
40
+ - Keep decorated API methods compatible with temporary method stubs.
41
+ - Correct the generated customer fetch endpoint and camel-cased request keys.
42
+ - Send DELETE request-body properties as JSON rather than query parameters.
43
+ - Handle string and missing API error response bodies safely.
44
+
45
+ ## [0.1.1] - 2025-01-24
46
+
47
+ ### Fixed
48
+
49
+ - Correct the dedicated virtual account requery endpoint.
50
+ - Recognize subclasses of Faraday connection errors as network errors.
51
+ - Handle non-JSON request bodies and optional log filtering more gracefully.
52
+ - Defer API method decoration until all API modules are loaded.
53
+ - Correct the gem's placeholder name.
54
+
3
55
  ## [0.1.0] - 2024-10-27
4
56
 
5
57
  - Initial release
58
+
59
+ [Unreleased]: https://github.com/darthrighteous/paystack-gateway/compare/v0.2.0...HEAD
60
+ [0.2.0]: https://github.com/darthrighteous/paystack-gateway/compare/v0.1.1...v0.2.0
61
+ [0.1.1]: https://github.com/darthrighteous/paystack-gateway/compare/v0.1.0...v0.1.1
62
+ [0.1.0]: https://github.com/darthrighteous/paystack-gateway/releases/tag/v0.1.0
data/README.md CHANGED
@@ -21,9 +21,10 @@ To use the PaystackGateway gem, you need to configure it with your Paystack secr
21
21
 
22
22
  The configuration options are
23
23
  - `secret_key`: Your paystack api key used to authorize requests
24
- - `logger`: Your ruby Logger. Default is Logger.new($stdout)
24
+ - `logger`: Your ruby Logger. Default is `Logger.new($stdout)`
25
25
  - `logging_options`: Options passed to [Faraday logger middleware](https://github.com/lostisland/faraday/blob/main/lib/faraday/response/logger.rb). Default is `{ headers: false }`
26
26
  - `log_filter`: Filter used when logging headers and body.
27
+ - `use_extensions`: Enable extension modules that add useful helper methods to response and error objects. Default is `true`.
27
28
 
28
29
  ```ruby
29
30
  # config/initializers/paystack_gateway.rb
@@ -41,30 +42,78 @@ end
41
42
 
42
43
  ## Usage
43
44
 
44
- ### Calling API endpoints
45
- Once configured, you can start using the various API modules and methods provided by the gem. They are designed to mirror how the api methods are grouped and listed on the [Paystack API](https://paystack.com/docs/api/).
45
+ Once configured, you can begin utilising the various API modules and methods provided by the gem.
46
+ ```irb
47
+ :001 > r = PaystackGateway::Customer.fetch(code: 'test@example.com')
48
+ I, [2025-03-30T19:53:06.951015 #29623] INFO -- : request: GET https://api.paystack.co/customer/test@example.com
49
+ I, [2025-03-30T19:53:07.486206 #29623] INFO -- : response: Status 200
50
+ =>
51
+ {:status=>true,
52
+ ...
53
+ :002 > r.class
54
+ => PaystackGateway::Customer::FetchResponse
55
+ :003 > r.customer_code
56
+ => "CUS_xsrozmbt8g1oear"
57
+ ```
46
58
 
47
- Here's an example creating a customer using the [/customer/create endpoint](https://paystack.com/docs/api/customer/#create).
59
+ ### API Organisation
48
60
 
49
- ```ruby
50
- response = PaystackGateway::Customers.create_customer(
51
- email: 'test@example.com',
52
- first_name: 'Test',
53
- last_name: 'User',
54
- )
61
+ The code is generated directly from [Paystack's OpenAPI specification](https://github.com/PaystackOSS/openapi), ensuring that it mirrors Paystack’s API organisation accurately. Refer to the API documentation for detailed schemas and available options for each endpoint.
62
+
63
+ - **API Modules**: Each API tag in the Paystack documentation becomes a module under `PaystackGateway`. For example, the Transaction API is accessible via `PaystackGateway::Transaction`.
64
+ - **API Methods**: Each operation within a tag is implemented as a method in the corresponding module. For instance, to verify a transaction, you call `PaystackGateway::Transaction.verify`.
65
+
66
+ ### Parameters
67
+
68
+ All API parameters are implemented as method arguments:
69
+
70
+ - **Path parameters**: Required parameters in the URL path (e.g., `reference` in `/transaction/verify/{reference}`)
71
+ - **Query parameters**: Optional parameters for GET requests (e.g., `from`, `to` in `/transaction/totals`)
72
+ - **Request body parameters**: Parameters sent in the request body for POST/PUT requests
73
+
74
+ Required parameters are clearly marked in the method signatures, while optional parameters typically default to `nil`.
75
+
76
+ ### Responses
77
+
78
+ Each API method returns a specific response object. For example, when you call `PaystackGateway::Transaction.verify`, you will receive either:
79
+
80
+ - `PaystackGateway::Transaction::VerifyResponse`, which indicates a successful call.
81
+ - `PaystackGateway::Transaction::VerifyError`, which is raised if the call fails.
82
+
83
+ Paystack responses usually include the main payload nested in the `data` field of the response body. To simplify access, the response objects automatically delegate known attributes from this field, allowing you to reference them directly.
84
+
85
+ For instance, here’s how you can fetch a customer using the [/customer/{code} endpoint](https://paystack.com/docs/api/customer/#fetch):
55
86
 
87
+
88
+ ```ruby
89
+ response = PaystackGateway::Customer.fetch(code: 'CUS_xsrozmbt8g1oear')
90
+
91
+ # An example of the original response body:
92
+ # {:status=>true,
93
+ # :message=>"Customer retrieved",
94
+ # :data=>
95
+ # {"email"=>"test@example.com",
96
+ # "phone"=>"+2348011111111",
97
+ # "customer_code"=>"CUS_xsrozmbt8g1oear",
98
+ # "id"=>203316808,
99
+ # ...
100
+
101
+ # You can access the attributes directly:
56
102
  response.id # => 203316808
57
103
  response.customer_code # => "CUS_xsrozmbt8g1oear"
104
+
105
+ # Alternatively, you can access them via the data field:
106
+ response.data.id # => 203316808
107
+ response.data.customer_code # => "CUS_xsrozmbt8g1oear"
58
108
  ```
59
109
 
60
110
  ### Error Handling
61
- Whenever a network error occurs or the called endpoint responds with an error response, a `PaystackGateway::ApiError`(or a subclass of it) is raised that can be handled in your calling code.
62
111
 
63
- Here's an example initializing a transaction using the [/transaction/initialize endpoint](https://paystack.com/docs/api/transaction/#initialize)
112
+ Whenever a network error occurs or the called endpoint returns an error response, a `PaystackGateway::ApiError` (or one of its subclasses) is raised, which you can handle in your code. For example, initialising a transaction using the [/transaction/initialize endpoint](https://paystack.com/docs/api/transaction/#initialize) might be done as follows:
64
113
 
65
114
  ```ruby
66
115
  begin
67
- response = PaystackGateway::Transactions.initialize_transaction(
116
+ response = PaystackGateway::Transaction.initialize_transaction(
68
117
  email: 'test@example.com',
69
118
  amount: 1000,
70
119
  reference: 'test_reference',
@@ -87,91 +136,21 @@ Some endpoints currently make use of caching:
87
136
  - Miscellaneous#list_banks
88
137
  - Verifications#resolve_account_number
89
138
 
90
- Caching works using an [ActiveSupport::Cache::FileStore](https://api.rubyonrails.org/classes/ActiveSupport/Cache/FileStore.html) cache. The default caching period is 7 days and the cache data is stored on the file system at `ENV['TMPDIR']` or `/tmp/cache`.
91
-
92
-
93
- ## API Modules and Methods
94
- > Refer to the [Paystack API documentation](https://paystack.com/docs/api) for details on all the available endpoints and their usage.
95
-
96
- ### Implemented Modules and Methods
97
-
98
- Below is a complete list of the API modules and methods that are currently implemented.
99
-
100
- I invite you to collaborate on this project! If you need to use any of the unimplemented API methods or modules, or if you want to make modifications to the defaults or the level of configuration available in the currently implemented API methods, please feel free to raise a pull request (PR). See [Contributing](#contributing) and [Code of Conduct](#code-of-conduct) below
101
-
102
- - [x] [Transactions](https://paystack.com/docs/api/transaction/)
103
- - [x] [Initialize Transaction](https://paystack.com/docs/api/transaction/#initialize)
104
- - [x] [Verify Transaction](https://paystack.com/docs/api/transaction/#verify)
105
- - [ ] [List Transactions](https://paystack.com/docs/api/transaction/#list)
106
- - [ ] [Fetch Transaction](https://paystack.com/docs/api/transaction/#fetch)
107
- - [x] [Charge Authorization](https://paystack.com/docs/api/transaction/#charge-authorization)
108
- - [ ] [View Transaction Timeline](https://paystack.com/docs/api/transaction/#view-timeline)
109
- - [ ] [Transaction Totals](https://paystack.com/docs/api/transaction/#totals)
110
- - [ ] [Export Transactions](https://paystack.com/docs/api/transaction/#export)
111
- - [ ] [Partial Debit](https://paystack.com/docs/api/transaction/#partial-debit)
112
-
113
- - [ ] [Customers](https://paystack.com/docs/api/customer/)
114
- - [x] [Create Customer](https://paystack.com/docs/api/customer/#create)
115
- - [ ] [List Customers](https://paystack.com/docs/api/customer/#list)
116
- - [x] [Fetch Customer](https://paystack.com/docs/api/customer/#fetch)
117
- - [ ] [Update Customer](https://paystack.com/docs/api/customer/#update)
118
- - [ ] [Validate Customer](https://paystack.com/docs/api/customer/#validate)
119
- - [ ] [Whitelist/Blacklist Customer](https://paystack.com/docs/api/customer/#whitelist-blacklist)
120
- - [ ] [Deactivate Authorization](https://paystack.com/docs/api/customer/#deactivate-authorization)
121
-
122
- - [x] [Dedicated Virtual Accounts](https://paystack.com/docs/api/dedicated-virtual-account/)
123
- - [x] [Create Dedicated Virtual Account](https://paystack.com/docs/api/dedicated-virtual-account/#create)
124
- - [x] [Assign Dedicated Virtual Account](https://paystack.com/docs/api/dedicated-virtual-account/#assign)
125
- - [ ] [List Dedicated Accounts](https://paystack.com/docs/api/dedicated-virtual-account/#list)
126
- - [ ] [Fetch Dedicated Account](https://paystack.com/docs/api/dedicated-virtual-account/#fetch)
127
- - [x] [Requery Dedicated Account](https://paystack.com/docs/api/dedicated-virtual-account/#requery)
128
- - [ ] [Deactivate Dedicated Account](https://paystack.com/docs/api/dedicated-virtual-account/#deactivate)
129
- - [x] [Split Dedicated Account Transaction](https://paystack.com/docs/api/dedicated-virtual-account/#add-split)
130
- - [ ] [Remove Split from Dedicated Account](https://paystack.com/docs/api/dedicated-virtual-account/#remove-split)
131
- - [ ] [Fetch Bank Providers](https://paystack.com/docs/api/dedicated-virtual-account/#providers)
132
-
133
- - [ ] [Subaccounts](https://paystack.com/docs/api/subaccount/)
134
- - [x] [Create Subaccount](https://paystack.com/docs/api/subaccount/#create)
135
- - [ ] [List Subaccounts](https://paystack.com/docs/api/subaccount/#list)
136
- - [ ] [Fetch Subaccount](https://paystack.com/docs/api/subaccount/#fetch)
137
- - [x] [Update Subaccount](https://paystack.com/docs/api/subaccount/#update)
138
-
139
- - [x] [Plans](https://paystack.com/docs/api/plan/)
140
- - [x] [Create Plan](https://paystack.com/docs/api/plan/#create)
141
- - [x] [List Plans](https://paystack.com/docs/api/plan/#list)
142
- - [x] [Fetch Plan](https://paystack.com/docs/api/plan/#fetch)
143
- - [x] [Update Plan](https://paystack.com/docs/api/plan/#update)
144
-
145
- - [x] [Transfer Recipients](https://paystack.com/docs/api/transfer-recipient/)
146
- - [x] [Create Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#create)
147
- - [ ] [Bulk Create Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#bulk)
148
- - [ ] [List Transfer Recipients](https://paystack.com/docs/api/transfer-recipient/#list)
149
- - [ ] [Fetch Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#fetch)
150
- - [ ] [Update Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#update)
151
- - [ ] [Delete Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#delete)
152
-
153
- - [x] [Transfers](https://paystack.com/docs/api/transfer/)
154
- - [x] [Initiate Transfer](https://paystack.com/docs/api/transfer/#initiate)
155
- - [ ] [Finalize Transfer](https://paystack.com/docs/api/transfer/#finalize)
156
- - [ ] [Initiate Bulk Transfer](https://paystack.com/docs/api/transfer/#bulk)
157
- - [ ] [List Transfers](https://paystack.com/docs/api/transfer/#list)
158
- - [ ] [Fetch Transfer](https://paystack.com/docs/api/transfer/#fetch)
159
- - [x] [Verify Transfer](https://paystack.com/docs/api/transfer/#verify)
160
-
161
- - [x] [Refunds](https://paystack.com/docs/api/refund/)
162
- - [x] [Create Refund](https://paystack.com/docs/api/refund/#create)
163
- - [x] [List Refunds](https://paystack.com/docs/api/refund/#list)
164
- - [x] [Fetch Refund](https://paystack.com/docs/api/refund/#fetch)
165
-
166
- - [x] [Verification](https://paystack.com/docs/api/verification/)
167
- - [x] [Resolve Account Number](https://paystack.com/docs/api/verification/#resolve-account)
168
- - [ ] [Validate Account](https://paystack.com/docs/api/verification/#validate-account)
169
- - [ ] [Resolve Card BIN](https://paystack.com/docs/api/verification/#resolve-card)
170
-
171
- - [x] [Miscellaneous](https://paystack.com/docs/api/miscellaneous/)
172
- - [x] [List Banks](https://paystack.com/docs/api/miscellaneous/#bank)
173
- - [ ] [List/Search Countries](https://paystack.com/docs/api/miscellaneous/#country)
174
- - [ ] [List States (AVS)](https://paystack.com/docs/api/miscellaneous/#avs-states)
139
+ Caching works using an [ActiveSupport::Cache::FileStore](https://api.rubyonrails.org/classes/ActiveSupport/Cache/FileStore.html) cache. The default caching period is 7 days and the cache data is stored on the file system at `ENV['TMPDIR']` or `/tmp/cache`.
140
+
141
+ ### Extensions
142
+
143
+ PaystackGateway includes extension modules that offer additional helper methods on both response and error objects. These modules are enabled by default, so you can immediately benefit from simpler data access and enhanced error handling.
144
+
145
+ If you prefer to opt out of these enhancements, you can update your configuration as follows:
146
+
147
+ ```ruby
148
+ PaystackGateway.configure do |config|
149
+ config.use_extensions = false
150
+ end
151
+ ```
152
+
153
+ For additional details on the available extensions and helper methods, please refer directly to the source code in the [extensions directory](https://github.com/darthrighteous/paystack-gateway/tree/main/lib/paystack_gateway/extensions).
175
154
 
176
155
 
177
156
  ## Development
@@ -184,7 +163,7 @@ I invite you to collaborate on this project! If you need to use any of the unimp
184
163
 
185
164
  ### Setting up
186
165
 
187
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
166
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
188
167
 
189
168
  ### Running the tests and linter
190
169
 
@@ -193,9 +172,9 @@ Minitest is used for unit tests. Rubocop is used to enforce the ruby style.
193
172
  To run the complete set of tests and linter run the following:
194
173
 
195
174
  ```bash
196
- $ bundle install
197
- $ bundle exec rake test
198
- $ bundle exec rubocop
175
+ $ bin/setup
176
+ $ bin/test
177
+ $ bin/lint
199
178
  ```
200
179
 
201
180
  ## Contributing
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday/error'
4
+ require 'active_support/core_ext/hash/indifferent_access'
4
5
 
5
6
  module PaystackGateway
6
7
  # This error is raised when an exception occurs in the process of fulfilling
@@ -72,6 +73,7 @@ module PaystackGateway
72
73
  private
73
74
 
74
75
  def http_code = original_error.try(:response_status)
75
- def response_body = original_error.try(:response_body)&.with_indifferent_access
76
+ def original_response_body = original_error.try(:response_body)
77
+ def parsed_response_body = original_response_body.try(:with_indifferent_access) || {}
76
78
  end
77
79
  end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaystackGateway
4
+ # https://paystack.com/docs/api/applepay
5
+ #
6
+ # Apple Pay
7
+ # A collection of endpoints for managing application's top-level domain or subdomain accepting payment via Apple Pay
8
+ module ApplePay
9
+ include PaystackGateway::RequestModule
10
+
11
+ # Successful response from calling #list_domain.
12
+ class ListDomainResponse < PaystackGateway::Response; end
13
+
14
+ # Error response from #list_domain.
15
+ class ListDomainError < ApiError; end
16
+
17
+ # https://paystack.com/docs/api/apple-pay/#list_domain
18
+ # List Domains: GET /apple-pay/domain
19
+ # Lists all registered domains on your integration. Returns an empty array if no domains
20
+ # have been added.
21
+ #
22
+ # @param use_cursor [Boolean]
23
+ # A flag to indicate if cursor based pagination should be used
24
+ # @param next [String]
25
+ # An alphanumeric value returned for every cursor based retrieval, used to retrieve
26
+ # the next set of data
27
+ # @param previous [String]
28
+ # An alphanumeric value returned for every cursor based retrieval, used to retrieve
29
+ # the previous set of data
30
+ #
31
+ # @return [ListDomainResponse] successful response
32
+ # @raise [ListDomainError] if the request fails
33
+ api_method def self.list_domain(use_cursor: nil, next: nil, previous: nil)
34
+ use_connection do |connection|
35
+ connection.get(
36
+ '/apple-pay/domain',
37
+ { use_cursor:, next:, previous: }.compact,
38
+ )
39
+ end
40
+ end
41
+
42
+ # Successful response from calling #register_domain.
43
+ class RegisterDomainResponse < PaystackGateway::Response; end
44
+
45
+ # Error response from #register_domain.
46
+ class RegisterDomainError < ApiError; end
47
+
48
+ # https://paystack.com/docs/api/apple-pay/#register_domain
49
+ # Register Domain: POST /apple-pay/domain
50
+ # Register a top-level domain or subdomain for your Apple Pay integration. > This
51
+ # endpoint can only be called with one domain or subdomain at a time.
52
+ #
53
+ # @param domain_name [String] (required)
54
+ # The domain or subdomain for your application
55
+ #
56
+ # @return [RegisterDomainResponse] successful response
57
+ # @raise [RegisterDomainError] if the request fails
58
+ api_method def self.register_domain(domain_name:)
59
+ use_connection do |connection|
60
+ connection.post(
61
+ '/apple-pay/domain',
62
+ { domainName: domain_name }.compact,
63
+ )
64
+ end
65
+ end
66
+
67
+ # Successful response from calling #unregister_domain.
68
+ class UnregisterDomainResponse < PaystackGateway::Response; end
69
+
70
+ # Error response from #unregister_domain.
71
+ class UnregisterDomainError < ApiError; end
72
+
73
+ # https://paystack.com/docs/api/apple-pay/#unregister_domain
74
+ # Unregister Domain: DELETE /apple-pay/domain
75
+ # Unregister a top-level domain or subdomain previously used for your Apple Pay integration.
76
+ #
77
+ # @param domain_name [String] (required)
78
+ # The domain or subdomain for your application
79
+ #
80
+ # @return [UnregisterDomainResponse] successful response
81
+ # @raise [UnregisterDomainError] if the request fails
82
+ api_method def self.unregister_domain(domain_name:)
83
+ use_connection do |connection|
84
+ connection.delete(
85
+ '/apple-pay/domain',
86
+ ) do |request|
87
+ request.body = { domainName: domain_name }.compact
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaystackGateway
4
+ # https://paystack.com/docs/api/balance
5
+ #
6
+ # Balance
7
+ # A collection of endpoints gaining insights into the amount on an integration
8
+ module Balance
9
+ include PaystackGateway::RequestModule
10
+
11
+ # Successful response from calling #fetch.
12
+ class FetchResponse < PaystackGateway::Response; end
13
+
14
+ # Error response from #fetch.
15
+ class FetchError < ApiError; end
16
+
17
+ # https://paystack.com/docs/api/balance/#fetch
18
+ # Fetch Balance: GET /balance
19
+ # Fetch the available balance on your integration
20
+ #
21
+ #
22
+ # @return [FetchResponse] successful response
23
+ # @raise [FetchError] if the request fails
24
+ api_method def self.fetch
25
+ use_connection do |connection|
26
+ connection.get(
27
+ '/balance',
28
+ )
29
+ end
30
+ end
31
+
32
+ # Successful response from calling #ledger.
33
+ class LedgerResponse < PaystackGateway::Response; end
34
+
35
+ # Error response from #ledger.
36
+ class LedgerError < ApiError; end
37
+
38
+ # https://paystack.com/docs/api/balance/#ledger
39
+ # Balance Ledger: GET /balance/ledger
40
+ # Fetch all pay-ins and pay-outs that occured on your integration
41
+ #
42
+ # @param per_page [Integer]
43
+ # Number of records to fetch per page
44
+ # @param page [Integer]
45
+ # The section to retrieve
46
+ # @param from [Time]
47
+ # The start date
48
+ # @param to [Time]
49
+ # The end date
50
+ #
51
+ # @return [LedgerResponse] successful response
52
+ # @raise [LedgerError] if the request fails
53
+ api_method def self.ledger(per_page: nil, page: nil, from: nil, to: nil)
54
+ use_connection do |connection|
55
+ connection.get(
56
+ '/balance/ledger',
57
+ { perPage: per_page, page:, from:, to: }.compact,
58
+ )
59
+ end
60
+ end
61
+ end
62
+ end