paystack-gateway 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -2
- data/CHANGELOG.md +57 -0
- data/README.md +88 -105
- data/lib/paystack_gateway/api_error.rb +12 -2
- data/lib/paystack_gateway/apple_pay.rb +92 -0
- data/lib/paystack_gateway/balance.rb +62 -0
- data/lib/paystack_gateway/bank.rb +181 -0
- data/lib/paystack_gateway/bulk_charge.rb +197 -0
- data/lib/paystack_gateway/charge.rb +346 -0
- data/lib/paystack_gateway/configuration.rb +5 -3
- data/lib/paystack_gateway/customer.rb +498 -0
- data/lib/paystack_gateway/customers.rb +1 -42
- data/lib/paystack_gateway/dedicated_virtual_account.rb +353 -0
- data/lib/paystack_gateway/dedicated_virtual_accounts.rb +1 -64
- data/lib/paystack_gateway/direct_debit.rb +64 -0
- data/lib/paystack_gateway/dispute.rb +380 -0
- data/lib/paystack_gateway/extensions/customer_extensions.rb +14 -0
- data/lib/paystack_gateway/extensions/plan_extensions.rb +36 -0
- data/lib/paystack_gateway/extensions/refund_extensions.rb +43 -0
- data/lib/paystack_gateway/extensions/transaction_extensions.rb +40 -0
- data/lib/paystack_gateway/extensions/transaction_response_extension.rb +31 -0
- data/lib/paystack_gateway/extensions/transfer_extensions.rb +34 -0
- data/lib/paystack_gateway/integration.rb +60 -0
- data/lib/paystack_gateway/legacy/customers.rb +48 -0
- data/lib/paystack_gateway/legacy/dedicated_virtual_accounts.rb +70 -0
- data/lib/paystack_gateway/legacy/miscellaneous.rb +30 -0
- data/lib/paystack_gateway/legacy/plans.rb +86 -0
- data/lib/paystack_gateway/legacy/refunds.rb +65 -0
- data/lib/paystack_gateway/legacy/subaccounts.rb +41 -0
- data/lib/paystack_gateway/legacy/transaction_response.rb +37 -0
- data/lib/paystack_gateway/legacy/transactions.rb +91 -0
- data/lib/paystack_gateway/legacy/transfer_recipients.rb +27 -0
- data/lib/paystack_gateway/legacy/transfers.rb +63 -0
- data/lib/paystack_gateway/legacy/verification.rb +37 -0
- data/lib/paystack_gateway/miscellaneous.rb +75 -13
- data/lib/paystack_gateway/order.rb +259 -0
- data/lib/paystack_gateway/page.rb +317 -0
- data/lib/paystack_gateway/payment_request.rb +454 -0
- data/lib/paystack_gateway/plan.rb +247 -0
- data/lib/paystack_gateway/plans.rb +1 -80
- data/lib/paystack_gateway/product.rb +303 -0
- data/lib/paystack_gateway/refund.rb +197 -0
- data/lib/paystack_gateway/refunds.rb +1 -59
- data/lib/paystack_gateway/request_module.rb +20 -15
- data/lib/paystack_gateway/settlement.rb +60 -0
- data/lib/paystack_gateway/split.rb +286 -0
- data/lib/paystack_gateway/storefront.rb +329 -0
- data/lib/paystack_gateway/subaccount.rb +263 -0
- data/lib/paystack_gateway/subaccounts.rb +1 -35
- data/lib/paystack_gateway/subscription.rb +256 -0
- data/lib/paystack_gateway/terminal.rb +236 -0
- data/lib/paystack_gateway/transaction.rb +592 -0
- data/lib/paystack_gateway/transaction_response.rb +1 -33
- data/lib/paystack_gateway/transactions.rb +1 -86
- data/lib/paystack_gateway/transfer.rb +410 -0
- data/lib/paystack_gateway/transfer_recipient.rb +237 -0
- data/lib/paystack_gateway/transfer_recipients.rb +1 -21
- data/lib/paystack_gateway/transfers.rb +1 -57
- data/lib/paystack_gateway/verification.rb +1 -31
- data/lib/paystack_gateway/version.rb +1 -1
- data/lib/paystack_gateway/virtual_terminal.rb +297 -0
- data/lib/paystack_gateway.rb +61 -11
- metadata +50 -7
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PaystackGateway
|
|
4
|
+
# https://paystack.com/docs/api/transferrecipient
|
|
5
|
+
#
|
|
6
|
+
# Transfer Recipients
|
|
7
|
+
# A collection of endpoints for creating and managing beneficiaries that you send money to
|
|
8
|
+
module TransferRecipient
|
|
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/transfer-recipient/#list
|
|
18
|
+
# List Transfer Recipients: GET /transferrecipient
|
|
19
|
+
# List transfer recipients available on your integration
|
|
20
|
+
#
|
|
21
|
+
# @param use_cursor [Boolean]
|
|
22
|
+
# A flag to indicate if cursor based pagination should be used
|
|
23
|
+
# @param next [String]
|
|
24
|
+
# An alphanumeric value returned for every cursor based retrieval, used to retrieve
|
|
25
|
+
# the next set of data
|
|
26
|
+
# @param previous [String]
|
|
27
|
+
# An alphanumeric value returned for every cursor based retrieval, used to retrieve
|
|
28
|
+
# the previous set of data
|
|
29
|
+
# @param per_page [Integer]
|
|
30
|
+
# The number of records to fetch per request
|
|
31
|
+
# @param page [Integer]
|
|
32
|
+
# The offset to retrieve data from
|
|
33
|
+
#
|
|
34
|
+
# @return [ListResponse] successful response
|
|
35
|
+
# @raise [ListError] if the request fails
|
|
36
|
+
api_method def self.list(use_cursor: nil, next: nil, previous: nil, per_page: nil, page: nil)
|
|
37
|
+
use_connection do |connection|
|
|
38
|
+
connection.get(
|
|
39
|
+
'/transferrecipient',
|
|
40
|
+
{ use_cursor:, next:, previous:, per_page:, page: }.compact,
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Successful response from calling #create.
|
|
46
|
+
class CreateResponse < PaystackGateway::Response
|
|
47
|
+
delegate :active,
|
|
48
|
+
:createdAt,
|
|
49
|
+
:currency,
|
|
50
|
+
:description,
|
|
51
|
+
:domain,
|
|
52
|
+
:email,
|
|
53
|
+
:id,
|
|
54
|
+
:integration,
|
|
55
|
+
:name,
|
|
56
|
+
:recipient_code,
|
|
57
|
+
:type,
|
|
58
|
+
:updatedAt,
|
|
59
|
+
:is_deleted,
|
|
60
|
+
:isDeleted,
|
|
61
|
+
:details, to: :data
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Error response from #create.
|
|
65
|
+
class CreateError < ApiError; end
|
|
66
|
+
|
|
67
|
+
# https://paystack.com/docs/api/transfer-recipient/#create
|
|
68
|
+
# Create Transfer Recipient: POST /transferrecipient
|
|
69
|
+
# Creates a new recipient. A duplicate account number will lead to the retrieval of
|
|
70
|
+
# the existing record.
|
|
71
|
+
#
|
|
72
|
+
# @param type ["nuban", "ghipss", "mobile_money", "basa", "authorization"] (required)
|
|
73
|
+
# Recipient Type
|
|
74
|
+
# @param name [String] (required)
|
|
75
|
+
# The recipient's name according to their account registration.
|
|
76
|
+
# @param account_number [String] (required)
|
|
77
|
+
# Recipient's bank account number
|
|
78
|
+
# @param bank_code [String] (required)
|
|
79
|
+
# Recipient's bank code. You can get the list of Bank Codes by calling the List Banks
|
|
80
|
+
# endpoint
|
|
81
|
+
# @param description [String]
|
|
82
|
+
# A description for this recipient
|
|
83
|
+
# @param currency [String]
|
|
84
|
+
# Currency for the account receiving the transfer
|
|
85
|
+
# @param authorization_code [String]
|
|
86
|
+
# An authorization code from a previous transaction
|
|
87
|
+
# @param metadata [Hash]
|
|
88
|
+
# JSON object of custom data
|
|
89
|
+
#
|
|
90
|
+
# @return [CreateResponse] successful response
|
|
91
|
+
# @raise [CreateError] if the request fails
|
|
92
|
+
api_method def self.create(
|
|
93
|
+
type:,
|
|
94
|
+
name:,
|
|
95
|
+
account_number:,
|
|
96
|
+
bank_code:,
|
|
97
|
+
description: nil,
|
|
98
|
+
currency: nil,
|
|
99
|
+
authorization_code: nil,
|
|
100
|
+
metadata: nil
|
|
101
|
+
)
|
|
102
|
+
use_connection do |connection|
|
|
103
|
+
connection.post(
|
|
104
|
+
'/transferrecipient',
|
|
105
|
+
{
|
|
106
|
+
type:,
|
|
107
|
+
name:,
|
|
108
|
+
account_number:,
|
|
109
|
+
bank_code:,
|
|
110
|
+
description:,
|
|
111
|
+
currency:,
|
|
112
|
+
authorization_code:,
|
|
113
|
+
metadata:,
|
|
114
|
+
}.compact,
|
|
115
|
+
)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Successful response from calling #bulk.
|
|
120
|
+
class BulkResponse < PaystackGateway::Response
|
|
121
|
+
delegate :success, :errors, to: :data
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Error response from #bulk.
|
|
125
|
+
class BulkError < ApiError; end
|
|
126
|
+
|
|
127
|
+
# https://paystack.com/docs/api/transfer-recipient/#bulk
|
|
128
|
+
# Bulk Create Transfer Recipient: POST /transferrecipient/bulk
|
|
129
|
+
# Create multiple transfer recipients in batches. A duplicate account number will
|
|
130
|
+
# lead to the retrieval of the existing record.
|
|
131
|
+
#
|
|
132
|
+
# @param batch [Array<Hash>] (required)
|
|
133
|
+
# A list of transfer recipient object.
|
|
134
|
+
#
|
|
135
|
+
# @return [BulkResponse] successful response
|
|
136
|
+
# @raise [BulkError] if the request fails
|
|
137
|
+
api_method def self.bulk(batch:)
|
|
138
|
+
use_connection do |connection|
|
|
139
|
+
connection.post(
|
|
140
|
+
'/transferrecipient/bulk',
|
|
141
|
+
{ batch: }.compact,
|
|
142
|
+
)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Successful response from calling #fetch.
|
|
147
|
+
class FetchResponse < PaystackGateway::Response
|
|
148
|
+
delegate :integration,
|
|
149
|
+
:domain,
|
|
150
|
+
:type,
|
|
151
|
+
:currency,
|
|
152
|
+
:name,
|
|
153
|
+
:details,
|
|
154
|
+
:description,
|
|
155
|
+
:recipient_code,
|
|
156
|
+
:active,
|
|
157
|
+
:recipient_account,
|
|
158
|
+
:institution_code,
|
|
159
|
+
:email,
|
|
160
|
+
:id,
|
|
161
|
+
:isDeleted,
|
|
162
|
+
:createdAt,
|
|
163
|
+
:updatedAt, to: :data
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Error response from #fetch.
|
|
167
|
+
class FetchError < ApiError; end
|
|
168
|
+
|
|
169
|
+
# https://paystack.com/docs/api/transfer-recipient/#fetch
|
|
170
|
+
# Fetch Transfer recipient: GET /transferrecipient/{code}
|
|
171
|
+
# Fetch the details of a transfer recipient
|
|
172
|
+
#
|
|
173
|
+
# @param code [String] (required)
|
|
174
|
+
# Transfer recipient code
|
|
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
|
+
"/transferrecipient/#{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/transfer-recipient/#update
|
|
193
|
+
# Update Transfer Recipient: PUT /transferrecipient/{code}
|
|
194
|
+
# Update the details of a transfer recipient
|
|
195
|
+
#
|
|
196
|
+
# @param code [String] (required)
|
|
197
|
+
# Transfer recipient code
|
|
198
|
+
# @param name [String]
|
|
199
|
+
# Recipient's name
|
|
200
|
+
# @param email [String]
|
|
201
|
+
# Recipient's email address
|
|
202
|
+
#
|
|
203
|
+
# @return [UpdateResponse] successful response
|
|
204
|
+
# @raise [UpdateError] if the request fails
|
|
205
|
+
api_method def self.update(code:, name: nil, email: nil)
|
|
206
|
+
use_connection do |connection|
|
|
207
|
+
connection.put(
|
|
208
|
+
"/transferrecipient/#{code}",
|
|
209
|
+
{ name:, email: }.compact,
|
|
210
|
+
)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Successful response from calling #delete.
|
|
215
|
+
class DeleteResponse < PaystackGateway::Response; end
|
|
216
|
+
|
|
217
|
+
# Error response from #delete.
|
|
218
|
+
class DeleteError < ApiError; end
|
|
219
|
+
|
|
220
|
+
# https://paystack.com/docs/api/transfer-recipient/#delete
|
|
221
|
+
# Delete Transfer Recipient: DELETE /transferrecipient/{code}
|
|
222
|
+
# Delete a transfer recipient (sets the transfer recipient to inactive)
|
|
223
|
+
#
|
|
224
|
+
# @param code [String] (required)
|
|
225
|
+
# Transfer recipient code
|
|
226
|
+
#
|
|
227
|
+
# @return [DeleteResponse] successful response
|
|
228
|
+
# @raise [DeleteError] if the request fails
|
|
229
|
+
api_method def self.delete(code:)
|
|
230
|
+
use_connection do |connection|
|
|
231
|
+
connection.delete(
|
|
232
|
+
"/transferrecipient/#{code}",
|
|
233
|
+
)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
@@ -1,23 +1,3 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# Create and manage beneficiaries that you send money to
|
|
5
|
-
# https://paystack.com/docs/api/#transfer-recipient
|
|
6
|
-
module TransferRecipients
|
|
7
|
-
include PaystackGateway::RequestModule
|
|
8
|
-
|
|
9
|
-
# Response from POST /transferrecipient endpoint.
|
|
10
|
-
class CreateTransferRecipientResponse < PaystackGateway::Response
|
|
11
|
-
delegate :id, :recipient_code, to: :data
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
api_method def self.create_transfer_recipient(name:, account_number:, bank_code:)
|
|
15
|
-
use_connection do |connection|
|
|
16
|
-
connection.post(
|
|
17
|
-
'/transferrecipient',
|
|
18
|
-
{ type: :nuban, name: name, account_number: account_number, bank_code: bank_code, currency: :NGN },
|
|
19
|
-
)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
3
|
+
require 'paystack_gateway/legacy/transfer_recipients'
|
|
@@ -1,59 +1,3 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# Automate sending money https://paystack.com/docs/api/#transfer
|
|
5
|
-
module Transfers
|
|
6
|
-
include PaystackGateway::RequestModule
|
|
7
|
-
|
|
8
|
-
# Response from POST /transfer endpoint.
|
|
9
|
-
class InitiateTransferResponse < PaystackGateway::Response
|
|
10
|
-
include TransactionResponse
|
|
11
|
-
|
|
12
|
-
delegate :transfer_code, :id, :transferred_at, to: :data
|
|
13
|
-
|
|
14
|
-
def transaction_completed_at
|
|
15
|
-
transferred_at || super
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Raised when an error occurs while calling POST /transfer
|
|
20
|
-
class InitiateTransferError < ApiError
|
|
21
|
-
def transaction_failed?
|
|
22
|
-
response_body[:status] == false && http_code == 400
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def failure_reason
|
|
26
|
-
response_body[:message]
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
api_method def self.initiate_transfer(amount:, recipient_code:, reference:, reason: nil)
|
|
31
|
-
response = use_connection do |connection|
|
|
32
|
-
connection.post(
|
|
33
|
-
'/transfer',
|
|
34
|
-
{
|
|
35
|
-
source: :balance, amount: (amount * 100).to_i, recipient: recipient_code,
|
|
36
|
-
reference: reference, reason: reason,
|
|
37
|
-
}.compact,
|
|
38
|
-
)
|
|
39
|
-
end
|
|
40
|
-
response.tap { |r| r.completed_at = Time.current }
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Response from GET /transfer/verify/:reference endpoint.
|
|
44
|
-
class VerifyTransferResponse < InitiateTransferResponse; end
|
|
45
|
-
|
|
46
|
-
# Raised when an error occurs while calling GET /transfer/verify/:reference
|
|
47
|
-
class VerifyTransferError < ApiError
|
|
48
|
-
def transaction_not_found?
|
|
49
|
-
response_body[:status] == false && response_body[:message].match?(/transfer not found/i)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
api_method def self.verify_transfer(reference:)
|
|
54
|
-
use_connection do |connection|
|
|
55
|
-
connection.get("/transfer/verify/#{reference}")
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
3
|
+
require 'paystack_gateway/legacy/transfers'
|
|
@@ -1,33 +1,3 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# Perform KYC processes https://paystack.com/docs/api/#verification
|
|
5
|
-
module Verification
|
|
6
|
-
include PaystackGateway::RequestModule
|
|
7
|
-
|
|
8
|
-
# Response from GET /bank/resolve endpoint.
|
|
9
|
-
class ResolveAccountNumberResponse < PaystackGateway::Response
|
|
10
|
-
delegate :account_name, :bank_id, to: :data
|
|
11
|
-
|
|
12
|
-
def account_valid?
|
|
13
|
-
status && account_name.present?
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Raised when an error occurs while calling /bank/resolve
|
|
18
|
-
class ResolveAccountNumberError < ApiError
|
|
19
|
-
def invalid_account?
|
|
20
|
-
http_code == 422 && response_body[:status] == false
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
api_method def self.resolve_account_number(account_number:, bank_code:)
|
|
25
|
-
use_connection(cache_options: {}) do |connection|
|
|
26
|
-
connection.get(
|
|
27
|
-
'/bank/resolve',
|
|
28
|
-
{ account_number: account_number, bank_code: bank_code },
|
|
29
|
-
)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
3
|
+
require 'paystack_gateway/legacy/verification'
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PaystackGateway
|
|
4
|
+
# https://paystack.com/docs/api/virtualterminal
|
|
5
|
+
#
|
|
6
|
+
# Virtual Terminal
|
|
7
|
+
# A collection of endpoints for building in-person payments without a physical terminal
|
|
8
|
+
module VirtualTerminal
|
|
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/virtual-terminal/#list
|
|
18
|
+
# List Virtual Terminals: GET /virtual_terminal
|
|
19
|
+
# List Virtual Terminals on your integration
|
|
20
|
+
#
|
|
21
|
+
# @param per_page [Integer]
|
|
22
|
+
# The number of records to fetch per request
|
|
23
|
+
# @param page [Integer]
|
|
24
|
+
# The offset to retrieve data from
|
|
25
|
+
#
|
|
26
|
+
# @return [ListResponse] successful response
|
|
27
|
+
# @raise [ListError] if the request fails
|
|
28
|
+
api_method def self.list(per_page: nil, page: nil)
|
|
29
|
+
use_connection do |connection|
|
|
30
|
+
connection.get(
|
|
31
|
+
'/virtual_terminal',
|
|
32
|
+
{ perPage: per_page, page: }.compact,
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Successful response from calling #create.
|
|
38
|
+
class CreateResponse < PaystackGateway::Response
|
|
39
|
+
delegate :id,
|
|
40
|
+
:name,
|
|
41
|
+
:integration,
|
|
42
|
+
:domain,
|
|
43
|
+
:code,
|
|
44
|
+
:paymentMethods,
|
|
45
|
+
:active,
|
|
46
|
+
:metadata,
|
|
47
|
+
:destinations,
|
|
48
|
+
:currency, to: :data
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Error response from #create.
|
|
52
|
+
class CreateError < ApiError; end
|
|
53
|
+
|
|
54
|
+
# https://paystack.com/docs/api/virtual-terminal/#create
|
|
55
|
+
# Create Virtual Terminal: POST /virtual_terminal
|
|
56
|
+
# Create a Virtual Terminal on your integration
|
|
57
|
+
#
|
|
58
|
+
# @param name [String] (required)
|
|
59
|
+
# The name of the virtual terminal
|
|
60
|
+
# @param destinations [Array<Hash>] (required)
|
|
61
|
+
# Array of objects containing recipients for payment notifications for the Virtual
|
|
62
|
+
# Terminal.
|
|
63
|
+
# @param split_code [String]
|
|
64
|
+
# Split code to associate with the virtual terminal
|
|
65
|
+
# @param metadata [Hash]
|
|
66
|
+
# Additional custom data as key-value pairs
|
|
67
|
+
#
|
|
68
|
+
# @return [CreateResponse] successful response
|
|
69
|
+
# @raise [CreateError] if the request fails
|
|
70
|
+
api_method def self.create(name:, destinations:, split_code: nil, metadata: nil)
|
|
71
|
+
use_connection do |connection|
|
|
72
|
+
connection.post(
|
|
73
|
+
'/virtual_terminal',
|
|
74
|
+
{ name:, destinations:, split_code:, metadata: }.compact,
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Successful response from calling #fetch.
|
|
80
|
+
class FetchResponse < PaystackGateway::Response
|
|
81
|
+
delegate :id,
|
|
82
|
+
:code,
|
|
83
|
+
:name,
|
|
84
|
+
:integration,
|
|
85
|
+
:domain,
|
|
86
|
+
:paymentMethods,
|
|
87
|
+
:active,
|
|
88
|
+
:created_at,
|
|
89
|
+
:connect_account_id,
|
|
90
|
+
:destinations,
|
|
91
|
+
:currency, to: :data
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Error response from #fetch.
|
|
95
|
+
class FetchError < ApiError; end
|
|
96
|
+
|
|
97
|
+
# https://paystack.com/docs/api/virtual-terminal/#fetch
|
|
98
|
+
# Fetch Virtual Terminal: GET /virtual_terminal/{code}
|
|
99
|
+
# Fetch a Virtual Terminal on your integration
|
|
100
|
+
#
|
|
101
|
+
# @param code [String] (required)
|
|
102
|
+
# Code of the Virtual Terminal
|
|
103
|
+
#
|
|
104
|
+
# @return [FetchResponse] successful response
|
|
105
|
+
# @raise [FetchError] if the request fails
|
|
106
|
+
api_method def self.fetch(code:)
|
|
107
|
+
use_connection do |connection|
|
|
108
|
+
connection.get(
|
|
109
|
+
"/virtual_terminal/#{code}",
|
|
110
|
+
)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Successful response from calling #update.
|
|
115
|
+
class UpdateResponse < PaystackGateway::Response
|
|
116
|
+
delegate :id,
|
|
117
|
+
:code,
|
|
118
|
+
:name,
|
|
119
|
+
:integration,
|
|
120
|
+
:domain,
|
|
121
|
+
:paymentMethods,
|
|
122
|
+
:active,
|
|
123
|
+
:created_at,
|
|
124
|
+
:connect_account_id,
|
|
125
|
+
:destinations,
|
|
126
|
+
:currency, to: :data
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Error response from #update.
|
|
130
|
+
class UpdateError < ApiError; end
|
|
131
|
+
|
|
132
|
+
# https://paystack.com/docs/api/virtual-terminal/#update
|
|
133
|
+
# Update Virtual Terminal: PUT /virtual_terminal/{code}
|
|
134
|
+
# Update a Virtual Terminal on your integration
|
|
135
|
+
#
|
|
136
|
+
# @param code [String] (required)
|
|
137
|
+
# Code of the Virtual Terminal
|
|
138
|
+
# @param name [String] (required)
|
|
139
|
+
# Name of the virtual terminal
|
|
140
|
+
#
|
|
141
|
+
# @return [UpdateResponse] successful response
|
|
142
|
+
# @raise [UpdateError] if the request fails
|
|
143
|
+
api_method def self.update(code:, name:)
|
|
144
|
+
use_connection do |connection|
|
|
145
|
+
connection.put(
|
|
146
|
+
"/virtual_terminal/#{code}",
|
|
147
|
+
{ name: }.compact,
|
|
148
|
+
)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Successful response from calling #deactivate.
|
|
153
|
+
class DeactivateResponse < PaystackGateway::Response; end
|
|
154
|
+
|
|
155
|
+
# Error response from #deactivate.
|
|
156
|
+
class DeactivateError < ApiError; end
|
|
157
|
+
|
|
158
|
+
# https://paystack.com/docs/api/virtual-terminal/#deactivate
|
|
159
|
+
# Deactivate Virtual Terminal: PUT /virtual_terminal/{code}/deactivate
|
|
160
|
+
# Deactivate a Virtual Terminal on your integration
|
|
161
|
+
#
|
|
162
|
+
# @param code [String] (required)
|
|
163
|
+
# Code of the Virtual Terminal
|
|
164
|
+
#
|
|
165
|
+
# @return [DeactivateResponse] successful response
|
|
166
|
+
# @raise [DeactivateError] if the request fails
|
|
167
|
+
api_method def self.deactivate(code:)
|
|
168
|
+
use_connection do |connection|
|
|
169
|
+
connection.put(
|
|
170
|
+
"/virtual_terminal/#{code}/deactivate",
|
|
171
|
+
)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# Successful response from calling #destination_assign.
|
|
176
|
+
class DestinationAssignResponse < PaystackGateway::Response; end
|
|
177
|
+
|
|
178
|
+
# Error response from #destination_assign.
|
|
179
|
+
class DestinationAssignError < ApiError; end
|
|
180
|
+
|
|
181
|
+
# https://paystack.com/docs/api/virtual-terminal/#destination_assign
|
|
182
|
+
# Assign Destination to Virtual Terminal: POST /virtual_terminal/{code}/destination/assign
|
|
183
|
+
# Add a destination (WhatsApp number) to a Virtual Terminal on your integration
|
|
184
|
+
#
|
|
185
|
+
# @param code [String] (required)
|
|
186
|
+
# Code of the Virtual Terminal
|
|
187
|
+
# @param destinations [Array<Hash>] (required)
|
|
188
|
+
# Array of objects containing recipients for payment notifications for the Virtual
|
|
189
|
+
# Terminal.
|
|
190
|
+
#
|
|
191
|
+
# @return [DestinationAssignResponse] successful response
|
|
192
|
+
# @raise [DestinationAssignError] if the request fails
|
|
193
|
+
api_method def self.destination_assign(code:, destinations:)
|
|
194
|
+
use_connection do |connection|
|
|
195
|
+
connection.post(
|
|
196
|
+
"/virtual_terminal/#{code}/destination/assign",
|
|
197
|
+
{ destinations: }.compact,
|
|
198
|
+
)
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Successful response from calling #destination_unassign.
|
|
203
|
+
class DestinationUnassignResponse < PaystackGateway::Response; end
|
|
204
|
+
|
|
205
|
+
# Error response from #destination_unassign.
|
|
206
|
+
class DestinationUnassignError < ApiError; end
|
|
207
|
+
|
|
208
|
+
# https://paystack.com/docs/api/virtual-terminal/#destination_unassign
|
|
209
|
+
# Unassign Destination from Virtual Terminal: POST /virtual_terminal/{code}/destination/unassign
|
|
210
|
+
# Unassign a destination (WhatsApp Number) from a Virtual Terminal on your integration
|
|
211
|
+
#
|
|
212
|
+
# @param code [String] (required)
|
|
213
|
+
# Code of the Virtual Terminal
|
|
214
|
+
# @param targets [Array<String>] (required)
|
|
215
|
+
# Array of destination targets to unassign
|
|
216
|
+
#
|
|
217
|
+
# @return [DestinationUnassignResponse] successful response
|
|
218
|
+
# @raise [DestinationUnassignError] if the request fails
|
|
219
|
+
api_method def self.destination_unassign(code:, targets:)
|
|
220
|
+
use_connection do |connection|
|
|
221
|
+
connection.post(
|
|
222
|
+
"/virtual_terminal/#{code}/destination/unassign",
|
|
223
|
+
{ targets: }.compact,
|
|
224
|
+
)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# Successful response from calling #add_split_code.
|
|
229
|
+
class AddSplitCodeResponse < PaystackGateway::Response
|
|
230
|
+
delegate :id,
|
|
231
|
+
:name,
|
|
232
|
+
:type,
|
|
233
|
+
:currency,
|
|
234
|
+
:integration,
|
|
235
|
+
:domain,
|
|
236
|
+
:split_code,
|
|
237
|
+
:active,
|
|
238
|
+
:bearer_type,
|
|
239
|
+
:bearer_subaccount,
|
|
240
|
+
:createdAt,
|
|
241
|
+
:updatedAt,
|
|
242
|
+
:is_dynamic,
|
|
243
|
+
:subaccounts,
|
|
244
|
+
:total_subaccounts, to: :data
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Error response from #add_split_code.
|
|
248
|
+
class AddSplitCodeError < ApiError; end
|
|
249
|
+
|
|
250
|
+
# https://paystack.com/docs/api/virtual-terminal/#add_split_code
|
|
251
|
+
# Add Split Code to Virtual Terminal: PUT /virtual_terminal/{code}/split_code
|
|
252
|
+
# Add Split Code to Virtual Terminal
|
|
253
|
+
#
|
|
254
|
+
# @param code [String] (required)
|
|
255
|
+
# Code of the Virtual Terminal
|
|
256
|
+
# @param split_code [String] (required)
|
|
257
|
+
# The split code to assign to the virtual terminal
|
|
258
|
+
#
|
|
259
|
+
# @return [AddSplitCodeResponse] successful response
|
|
260
|
+
# @raise [AddSplitCodeError] if the request fails
|
|
261
|
+
api_method def self.add_split_code(code:, split_code:)
|
|
262
|
+
use_connection do |connection|
|
|
263
|
+
connection.put(
|
|
264
|
+
"/virtual_terminal/#{code}/split_code",
|
|
265
|
+
{ split_code: }.compact,
|
|
266
|
+
)
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
# Successful response from calling #delete_split_code.
|
|
271
|
+
class DeleteSplitCodeResponse < PaystackGateway::Response; end
|
|
272
|
+
|
|
273
|
+
# Error response from #delete_split_code.
|
|
274
|
+
class DeleteSplitCodeError < ApiError; end
|
|
275
|
+
|
|
276
|
+
# https://paystack.com/docs/api/virtual-terminal/#delete_split_code
|
|
277
|
+
# Remove Split Code from Virtual Terminal: DELETE /virtual_terminal/{code}/split_code
|
|
278
|
+
# Remove Split Code from Virtual Terminal
|
|
279
|
+
#
|
|
280
|
+
# @param code [String] (required)
|
|
281
|
+
# Code of the Virtual Terminal
|
|
282
|
+
# @param split_code [String] (required)
|
|
283
|
+
# The split code to assign to the virtual terminal
|
|
284
|
+
#
|
|
285
|
+
# @return [DeleteSplitCodeResponse] successful response
|
|
286
|
+
# @raise [DeleteSplitCodeError] if the request fails
|
|
287
|
+
api_method def self.delete_split_code(code:, split_code:)
|
|
288
|
+
use_connection do |connection|
|
|
289
|
+
connection.delete(
|
|
290
|
+
"/virtual_terminal/#{code}/split_code",
|
|
291
|
+
) do |request|
|
|
292
|
+
request.body = { split_code: }.compact
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
end
|
|
297
|
+
end
|