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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 860924941f63099d74680601ef554e6a8f10f10481381ec04316dec8ea37bff8
|
|
4
|
+
data.tar.gz: 9c74c683a3612bd75d8f03ec2cc2ad4a0d18ec078e085c9693862b1e4eb3bf23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae2df9306e0b22b880347d442e7e7a9bbbc3c76a885f830371022a8cc32a17cd300bbe0619fabee14ab5a674cfd4f8c23c51781081ac82855685fe0feb1184f1
|
|
7
|
+
data.tar.gz: e24f66f685989b6867eb4ca409dc656d853ccf876a6f83f3665828da152227f93dfde8cdc96e19a7c8fc214c9886fff8dc0a08933b853b33748553cd42ab19d0
|
data/.rubocop.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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:
|
|
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
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
Install the gem and add to the application's Gemfile by executing:
|
|
7
7
|
|
|
8
8
|
```bash
|
|
9
|
-
$ bundle add
|
|
9
|
+
$ bundle add paystack-gateway
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
$ gem install
|
|
15
|
+
$ gem install paystack-gateway
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Configuration
|
|
@@ -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
|
|
@@ -31,36 +32,88 @@ The configuration options are
|
|
|
31
32
|
PaystackGateway.configure do |config|
|
|
32
33
|
config.secret_key = Rails.application.credentials.dig(:paystack, :secret_key)
|
|
33
34
|
config.logger = Rails.logger
|
|
34
|
-
config.log_filter =
|
|
35
|
+
config.log_filter = lambda { |params|
|
|
36
|
+
next params if !params || !params.respond_to?(:each)
|
|
37
|
+
|
|
38
|
+
ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters).filter(params)
|
|
39
|
+
}
|
|
35
40
|
end
|
|
36
41
|
```
|
|
37
42
|
|
|
38
43
|
## Usage
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
```
|
|
58
|
+
|
|
59
|
+
### API Organisation
|
|
42
60
|
|
|
43
|
-
|
|
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.
|
|
44
62
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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):
|
|
51
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:
|
|
52
102
|
response.id # => 203316808
|
|
53
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"
|
|
54
108
|
```
|
|
55
109
|
|
|
56
110
|
### Error Handling
|
|
57
|
-
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.
|
|
58
111
|
|
|
59
|
-
|
|
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:
|
|
60
113
|
|
|
61
114
|
```ruby
|
|
62
115
|
begin
|
|
63
|
-
response = PaystackGateway::
|
|
116
|
+
response = PaystackGateway::Transaction.initialize_transaction(
|
|
64
117
|
email: 'test@example.com',
|
|
65
118
|
amount: 1000,
|
|
66
119
|
reference: 'test_reference',
|
|
@@ -83,91 +136,21 @@ Some endpoints currently make use of caching:
|
|
|
83
136
|
- Miscellaneous#list_banks
|
|
84
137
|
- Verifications#resolve_account_number
|
|
85
138
|
|
|
86
|
-
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`.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
- [ ] [List Transactions](https://paystack.com/docs/api/transaction/#list)
|
|
102
|
-
- [ ] [Fetch Transaction](https://paystack.com/docs/api/transaction/#fetch)
|
|
103
|
-
- [x] [Charge Authorization](https://paystack.com/docs/api/transaction/#charge-authorization)
|
|
104
|
-
- [ ] [View Transaction Timeline](https://paystack.com/docs/api/transaction/#view-timeline)
|
|
105
|
-
- [ ] [Transaction Totals](https://paystack.com/docs/api/transaction/#totals)
|
|
106
|
-
- [ ] [Export Transactions](https://paystack.com/docs/api/transaction/#export)
|
|
107
|
-
- [ ] [Partial Debit](https://paystack.com/docs/api/transaction/#partial-debit)
|
|
108
|
-
|
|
109
|
-
- [ ] [Customers](https://paystack.com/docs/api/customer/)
|
|
110
|
-
- [x] [Create Customer](https://paystack.com/docs/api/customer/#create)
|
|
111
|
-
- [ ] [List Customers](https://paystack.com/docs/api/customer/#list)
|
|
112
|
-
- [x] [Fetch Customer](https://paystack.com/docs/api/customer/#fetch)
|
|
113
|
-
- [ ] [Update Customer](https://paystack.com/docs/api/customer/#update)
|
|
114
|
-
- [ ] [Validate Customer](https://paystack.com/docs/api/customer/#validate)
|
|
115
|
-
- [ ] [Whitelist/Blacklist Customer](https://paystack.com/docs/api/customer/#whitelist-blacklist)
|
|
116
|
-
- [ ] [Deactivate Authorization](https://paystack.com/docs/api/customer/#deactivate-authorization)
|
|
117
|
-
|
|
118
|
-
- [x] [Dedicated Virtual Accounts](https://paystack.com/docs/api/dedicated-virtual-account/)
|
|
119
|
-
- [x] [Create Dedicated Virtual Account](https://paystack.com/docs/api/dedicated-virtual-account/#create)
|
|
120
|
-
- [x] [Assign Dedicated Virtual Account](https://paystack.com/docs/api/dedicated-virtual-account/#assign)
|
|
121
|
-
- [ ] [List Dedicated Accounts](https://paystack.com/docs/api/dedicated-virtual-account/#list)
|
|
122
|
-
- [ ] [Fetch Dedicated Account](https://paystack.com/docs/api/dedicated-virtual-account/#fetch)
|
|
123
|
-
- [x] [Requery Dedicated Account](https://paystack.com/docs/api/dedicated-virtual-account/#requery)
|
|
124
|
-
- [ ] [Deactivate Dedicated Account](https://paystack.com/docs/api/dedicated-virtual-account/#deactivate)
|
|
125
|
-
- [x] [Split Dedicated Account Transaction](https://paystack.com/docs/api/dedicated-virtual-account/#add-split)
|
|
126
|
-
- [ ] [Remove Split from Dedicated Account](https://paystack.com/docs/api/dedicated-virtual-account/#remove-split)
|
|
127
|
-
- [ ] [Fetch Bank Providers](https://paystack.com/docs/api/dedicated-virtual-account/#providers)
|
|
128
|
-
|
|
129
|
-
- [ ] [Subaccounts](https://paystack.com/docs/api/subaccount/)
|
|
130
|
-
- [x] [Create Subaccount](https://paystack.com/docs/api/subaccount/#create)
|
|
131
|
-
- [ ] [List Subaccounts](https://paystack.com/docs/api/subaccount/#list)
|
|
132
|
-
- [ ] [Fetch Subaccount](https://paystack.com/docs/api/subaccount/#fetch)
|
|
133
|
-
- [x] [Update Subaccount](https://paystack.com/docs/api/subaccount/#update)
|
|
134
|
-
|
|
135
|
-
- [x] [Plans](https://paystack.com/docs/api/plan/)
|
|
136
|
-
- [x] [Create Plan](https://paystack.com/docs/api/plan/#create)
|
|
137
|
-
- [x] [List Plans](https://paystack.com/docs/api/plan/#list)
|
|
138
|
-
- [x] [Fetch Plan](https://paystack.com/docs/api/plan/#fetch)
|
|
139
|
-
- [x] [Update Plan](https://paystack.com/docs/api/plan/#update)
|
|
140
|
-
|
|
141
|
-
- [x] [Transfer Recipients](https://paystack.com/docs/api/transfer-recipient/)
|
|
142
|
-
- [x] [Create Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#create)
|
|
143
|
-
- [ ] [Bulk Create Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#bulk)
|
|
144
|
-
- [ ] [List Transfer Recipients](https://paystack.com/docs/api/transfer-recipient/#list)
|
|
145
|
-
- [ ] [Fetch Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#fetch)
|
|
146
|
-
- [ ] [Update Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#update)
|
|
147
|
-
- [ ] [Delete Transfer Recipient](https://paystack.com/docs/api/transfer-recipient/#delete)
|
|
148
|
-
|
|
149
|
-
- [x] [Transfers](https://paystack.com/docs/api/transfer/)
|
|
150
|
-
- [x] [Initiate Transfer](https://paystack.com/docs/api/transfer/#initiate)
|
|
151
|
-
- [ ] [Finalize Transfer](https://paystack.com/docs/api/transfer/#finalize)
|
|
152
|
-
- [ ] [Initiate Bulk Transfer](https://paystack.com/docs/api/transfer/#bulk)
|
|
153
|
-
- [ ] [List Transfers](https://paystack.com/docs/api/transfer/#list)
|
|
154
|
-
- [ ] [Fetch Transfer](https://paystack.com/docs/api/transfer/#fetch)
|
|
155
|
-
- [x] [Verify Transfer](https://paystack.com/docs/api/transfer/#verify)
|
|
156
|
-
|
|
157
|
-
- [x] [Refunds](https://paystack.com/docs/api/refund/)
|
|
158
|
-
- [x] [Create Refund](https://paystack.com/docs/api/refund/#create)
|
|
159
|
-
- [x] [List Refunds](https://paystack.com/docs/api/refund/#list)
|
|
160
|
-
- [x] [Fetch Refund](https://paystack.com/docs/api/refund/#fetch)
|
|
161
|
-
|
|
162
|
-
- [x] [Verification](https://paystack.com/docs/api/verification/)
|
|
163
|
-
- [x] [Resolve Account Number](https://paystack.com/docs/api/verification/#resolve-account)
|
|
164
|
-
- [ ] [Validate Account](https://paystack.com/docs/api/verification/#validate-account)
|
|
165
|
-
- [ ] [Resolve Card BIN](https://paystack.com/docs/api/verification/#resolve-card)
|
|
166
|
-
|
|
167
|
-
- [x] [Miscellaneous](https://paystack.com/docs/api/miscellaneous/)
|
|
168
|
-
- [x] [List Banks](https://paystack.com/docs/api/miscellaneous/#bank)
|
|
169
|
-
- [ ] [List/Search Countries](https://paystack.com/docs/api/miscellaneous/#country)
|
|
170
|
-
- [ ] [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).
|
|
171
154
|
|
|
172
155
|
|
|
173
156
|
## Development
|
|
@@ -180,7 +163,7 @@ I invite you to collaborate on this project! If you need to use any of the unimp
|
|
|
180
163
|
|
|
181
164
|
### Setting up
|
|
182
165
|
|
|
183
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
|
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.
|
|
184
167
|
|
|
185
168
|
### Running the tests and linter
|
|
186
169
|
|
|
@@ -189,9 +172,9 @@ Minitest is used for unit tests. Rubocop is used to enforce the ruby style.
|
|
|
189
172
|
To run the complete set of tests and linter run the following:
|
|
190
173
|
|
|
191
174
|
```bash
|
|
192
|
-
$
|
|
193
|
-
$
|
|
194
|
-
$
|
|
175
|
+
$ bin/setup
|
|
176
|
+
$ bin/test
|
|
177
|
+
$ bin/lint
|
|
195
178
|
```
|
|
196
179
|
|
|
197
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
|
|
@@ -41,7 +42,15 @@ module PaystackGateway
|
|
|
41
42
|
@cancellable = cancellable
|
|
42
43
|
end
|
|
43
44
|
|
|
44
|
-
def network_error?
|
|
45
|
+
def network_error?
|
|
46
|
+
return false if !original_error
|
|
47
|
+
|
|
48
|
+
original_error.class.ancestors.any? do |ancestor|
|
|
49
|
+
break if ancestor == Exception
|
|
50
|
+
|
|
51
|
+
CONNECTION_ERROR_CLASSES.include?(ancestor)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
45
54
|
|
|
46
55
|
def method_missing(method_name, *)
|
|
47
56
|
return super unless method_name.to_s.end_with?('_error?', '_error!')
|
|
@@ -64,6 +73,7 @@ module PaystackGateway
|
|
|
64
73
|
private
|
|
65
74
|
|
|
66
75
|
def http_code = original_error.try(:response_status)
|
|
67
|
-
def
|
|
76
|
+
def original_response_body = original_error.try(:response_body)
|
|
77
|
+
def parsed_response_body = original_response_body.try(:with_indifferent_access) || {}
|
|
68
78
|
end
|
|
69
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
|