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.
- checksums.yaml +4 -4
- data/.rubocop.yml +12 -2
- data/CHANGELOG.md +57 -0
- data/README.md +81 -102
- data/lib/paystack_gateway/api_error.rb +3 -1
- 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 +13 -2
- 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 +12 -11
- 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 +50 -18
- metadata +50 -7
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PaystackGateway
|
|
4
|
+
# https://paystack.com/docs/api/transaction
|
|
5
|
+
#
|
|
6
|
+
# Transactions
|
|
7
|
+
# A collection of endpoints for managing payments
|
|
8
|
+
module Transaction
|
|
9
|
+
include PaystackGateway::RequestModule
|
|
10
|
+
|
|
11
|
+
# Successful response from calling #initialize_transaction.
|
|
12
|
+
class InitializeTransactionResponse < PaystackGateway::Response
|
|
13
|
+
delegate :authorization_url, :access_code, :reference, to: :data
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Error response from #initialize_transaction.
|
|
17
|
+
class InitializeTransactionError < ApiError; end
|
|
18
|
+
|
|
19
|
+
# https://paystack.com/docs/api/transaction/#initialize_transaction
|
|
20
|
+
# Initialize Transaction: POST /transaction/initialize
|
|
21
|
+
# Create a new transaction
|
|
22
|
+
#
|
|
23
|
+
# @param email [String] (required)
|
|
24
|
+
# Customer's email address
|
|
25
|
+
# @param amount [Integer] (required)
|
|
26
|
+
# Amount should be in smallest denomination of the currency.
|
|
27
|
+
# @param currency ["GHS", "KES", "NGN", "ZAR", "USD"]
|
|
28
|
+
# List of all support currencies
|
|
29
|
+
# @param reference [String]
|
|
30
|
+
# Unique transaction reference. Only -, ., = and alphanumeric characters allowed.
|
|
31
|
+
# @param channels [Array<String>]
|
|
32
|
+
# An array of payment channels to control what channels you want to make available
|
|
33
|
+
# to the user to make a payment with
|
|
34
|
+
# Allowed values: "apple_pay", "bank", "bank_transfer", "capitec_pay", "card", "eft",
|
|
35
|
+
# "mobile_money", "payattitude", "qr", "ussd"
|
|
36
|
+
# @param callback_url [String]
|
|
37
|
+
# Fully qualified url, e.g. https://example.com/ to redirect your customers to after
|
|
38
|
+
# a successful payment. Use this to override the callback url provided on the dashboard
|
|
39
|
+
# for this transaction
|
|
40
|
+
# @param plan [String]
|
|
41
|
+
# If transaction is to create a subscription to a predefined plan, provide plan code
|
|
42
|
+
# here. This would invalidate the value provided in amount
|
|
43
|
+
# @param invoice_limit [Integer]
|
|
44
|
+
# Number of times to charge customer during subscription to plan
|
|
45
|
+
# @param split_code [String]
|
|
46
|
+
# The split code of the transaction split
|
|
47
|
+
# @param split [Hash]
|
|
48
|
+
# Split configuration for transactions
|
|
49
|
+
# @option split [String] :name
|
|
50
|
+
# Name of the transaction split
|
|
51
|
+
# @option split ["percentage", "flat"] :type
|
|
52
|
+
# The type of transaction split you want to create.
|
|
53
|
+
# @option split [Array<Hash>] :subaccounts
|
|
54
|
+
# A list of object containing subaccount code and number of shares
|
|
55
|
+
# @option split ["NGN", "GHS", "ZAR", "USD"] :currency
|
|
56
|
+
# The transaction currency
|
|
57
|
+
# @option split ["subaccount", "account", "all-proportional", "all"] :bearer_type
|
|
58
|
+
# This allows you specify how the transaction charge should be processed
|
|
59
|
+
# @option split [String] :bearer_subaccount
|
|
60
|
+
# This is the subaccount code of the customer or partner that would bear the transaction
|
|
61
|
+
# charge if you specified subaccount as the bearer type
|
|
62
|
+
# @param subaccount [String]
|
|
63
|
+
# The code for the subaccount that owns the payment
|
|
64
|
+
# @param transaction_charge [String]
|
|
65
|
+
# A flat fee to charge the subaccount for a transaction. This overrides the split
|
|
66
|
+
# percentage set when the subaccount was created
|
|
67
|
+
# @param bearer ["account", "subaccount"]
|
|
68
|
+
# The bearer of the transaction charge
|
|
69
|
+
# @param label [String]
|
|
70
|
+
# Used to replace the email address shown on the Checkout
|
|
71
|
+
# @param metadata [Hash]
|
|
72
|
+
# JSON object of custom data
|
|
73
|
+
#
|
|
74
|
+
# @return [InitializeTransactionResponse] successful response
|
|
75
|
+
# @raise [InitializeTransactionError] if the request fails
|
|
76
|
+
api_method def self.initialize_transaction(
|
|
77
|
+
email:,
|
|
78
|
+
amount:,
|
|
79
|
+
currency: nil,
|
|
80
|
+
reference: nil,
|
|
81
|
+
channels: nil,
|
|
82
|
+
callback_url: nil,
|
|
83
|
+
plan: nil,
|
|
84
|
+
invoice_limit: nil,
|
|
85
|
+
split_code: nil,
|
|
86
|
+
split: nil,
|
|
87
|
+
subaccount: nil,
|
|
88
|
+
transaction_charge: nil,
|
|
89
|
+
bearer: nil,
|
|
90
|
+
label: nil,
|
|
91
|
+
metadata: nil
|
|
92
|
+
)
|
|
93
|
+
use_connection do |connection|
|
|
94
|
+
connection.post(
|
|
95
|
+
'/transaction/initialize',
|
|
96
|
+
{
|
|
97
|
+
email:,
|
|
98
|
+
amount:,
|
|
99
|
+
currency:,
|
|
100
|
+
reference:,
|
|
101
|
+
channels:,
|
|
102
|
+
callback_url:,
|
|
103
|
+
plan:,
|
|
104
|
+
invoice_limit:,
|
|
105
|
+
split_code:,
|
|
106
|
+
split:,
|
|
107
|
+
subaccount:,
|
|
108
|
+
transaction_charge:,
|
|
109
|
+
bearer:,
|
|
110
|
+
label:,
|
|
111
|
+
metadata:,
|
|
112
|
+
}.compact,
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Successful response from calling #charge_authorization.
|
|
118
|
+
class ChargeAuthorizationResponse < PaystackGateway::Response
|
|
119
|
+
delegate :amount,
|
|
120
|
+
:currency,
|
|
121
|
+
:transaction_date,
|
|
122
|
+
:reference,
|
|
123
|
+
:domain,
|
|
124
|
+
:metadata,
|
|
125
|
+
:gateway_response,
|
|
126
|
+
:channel,
|
|
127
|
+
:ip_address,
|
|
128
|
+
:log,
|
|
129
|
+
:fees,
|
|
130
|
+
:authorization,
|
|
131
|
+
:customer,
|
|
132
|
+
:plan,
|
|
133
|
+
:id, to: :data
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Error response from #charge_authorization.
|
|
137
|
+
class ChargeAuthorizationError < ApiError; end
|
|
138
|
+
|
|
139
|
+
# https://paystack.com/docs/api/transaction/#charge_authorization
|
|
140
|
+
# Charge Authorization: POST /transaction/charge_authorization
|
|
141
|
+
# Charge all authorizations marked as reusable with this endpoint whenever you need
|
|
142
|
+
# to receive payments
|
|
143
|
+
#
|
|
144
|
+
# @param email [String] (required)
|
|
145
|
+
# Customer's email address
|
|
146
|
+
# @param amount [Integer] (required)
|
|
147
|
+
# Amount in the lower denomination of your currency
|
|
148
|
+
# @param authorization_code [String] (required)
|
|
149
|
+
# Valid authorization code to charge
|
|
150
|
+
# @param reference [String]
|
|
151
|
+
# Unique transaction reference. Only -, ., = and alphanumeric characters allowed.
|
|
152
|
+
# @param currency ["GHS", "KES", "NGN", "ZAR", "USD"]
|
|
153
|
+
# List of all support currencies
|
|
154
|
+
# @param split_code [String]
|
|
155
|
+
# The split code of the transaction split
|
|
156
|
+
# @param split [Hash]
|
|
157
|
+
# Split configuration for transactions
|
|
158
|
+
# @option split [String] :name
|
|
159
|
+
# Name of the transaction split
|
|
160
|
+
# @option split ["percentage", "flat"] :type
|
|
161
|
+
# The type of transaction split you want to create.
|
|
162
|
+
# @option split [Array<Hash>] :subaccounts
|
|
163
|
+
# A list of object containing subaccount code and number of shares
|
|
164
|
+
# @option split ["NGN", "GHS", "ZAR", "USD"] :currency
|
|
165
|
+
# The transaction currency
|
|
166
|
+
# @option split ["subaccount", "account", "all-proportional", "all"] :bearer_type
|
|
167
|
+
# This allows you specify how the transaction charge should be processed
|
|
168
|
+
# @option split [String] :bearer_subaccount
|
|
169
|
+
# This is the subaccount code of the customer or partner that would bear the transaction
|
|
170
|
+
# charge if you specified subaccount as the bearer type
|
|
171
|
+
# @param subaccount [String]
|
|
172
|
+
# The code for the subaccount that owns the payment
|
|
173
|
+
# @param transaction_charge [String]
|
|
174
|
+
# A flat fee to charge the subaccount for a transaction. This overrides the split
|
|
175
|
+
# percentage set when the subaccount was created
|
|
176
|
+
# @param bearer ["account", "subaccount"]
|
|
177
|
+
# The bearer of the transaction charge
|
|
178
|
+
# @param metadata [String]
|
|
179
|
+
# Stringified JSON object of custom data
|
|
180
|
+
# @param queue [Boolean]
|
|
181
|
+
# If you are making a scheduled charge call, it is a good idea to queue them so the
|
|
182
|
+
# processing system does not get overloaded causing transaction processing errors.
|
|
183
|
+
#
|
|
184
|
+
# @return [ChargeAuthorizationResponse] successful response
|
|
185
|
+
# @raise [ChargeAuthorizationError] if the request fails
|
|
186
|
+
api_method def self.charge_authorization(
|
|
187
|
+
email:,
|
|
188
|
+
amount:,
|
|
189
|
+
authorization_code:,
|
|
190
|
+
reference: nil,
|
|
191
|
+
currency: nil,
|
|
192
|
+
split_code: nil,
|
|
193
|
+
split: nil,
|
|
194
|
+
subaccount: nil,
|
|
195
|
+
transaction_charge: nil,
|
|
196
|
+
bearer: nil,
|
|
197
|
+
metadata: nil,
|
|
198
|
+
queue: nil
|
|
199
|
+
)
|
|
200
|
+
use_connection do |connection|
|
|
201
|
+
connection.post(
|
|
202
|
+
'/transaction/charge_authorization',
|
|
203
|
+
{
|
|
204
|
+
email:,
|
|
205
|
+
amount:,
|
|
206
|
+
authorization_code:,
|
|
207
|
+
reference:,
|
|
208
|
+
currency:,
|
|
209
|
+
split_code:,
|
|
210
|
+
split:,
|
|
211
|
+
subaccount:,
|
|
212
|
+
transaction_charge:,
|
|
213
|
+
bearer:,
|
|
214
|
+
metadata:,
|
|
215
|
+
queue:,
|
|
216
|
+
}.compact,
|
|
217
|
+
)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# Successful response from calling #partial_debit.
|
|
222
|
+
class PartialDebitResponse < PaystackGateway::Response
|
|
223
|
+
delegate :amount,
|
|
224
|
+
:currency,
|
|
225
|
+
:transaction_date,
|
|
226
|
+
:reference,
|
|
227
|
+
:domain,
|
|
228
|
+
:gateway_response,
|
|
229
|
+
:channel,
|
|
230
|
+
:ip_address,
|
|
231
|
+
:log,
|
|
232
|
+
:fees,
|
|
233
|
+
:authorization,
|
|
234
|
+
:customer,
|
|
235
|
+
:metadata,
|
|
236
|
+
:plan,
|
|
237
|
+
:requested_amount,
|
|
238
|
+
:id, to: :data
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# Error response from #partial_debit.
|
|
242
|
+
class PartialDebitError < ApiError; end
|
|
243
|
+
|
|
244
|
+
# https://paystack.com/docs/api/transaction/#partial_debit
|
|
245
|
+
# Partial Debit: POST /transaction/partial_debit
|
|
246
|
+
# Retrieve part of a payment from a customer
|
|
247
|
+
#
|
|
248
|
+
# @param email [String] (required)
|
|
249
|
+
# Customer's email address
|
|
250
|
+
# @param amount [Integer] (required)
|
|
251
|
+
# Specified in the lowest denomination of your currency
|
|
252
|
+
# @param authorization_code [String] (required)
|
|
253
|
+
# Valid authorization code to charge
|
|
254
|
+
# @param currency ["GHS", "KES", "NGN", "ZAR", "USD"] (required)
|
|
255
|
+
# List of all support currencies
|
|
256
|
+
# @param at_least [String]
|
|
257
|
+
# Minimum amount to charge
|
|
258
|
+
# @param reference [String]
|
|
259
|
+
# Unique transaction reference. Only -, ., = and alphanumeric characters allowed.
|
|
260
|
+
#
|
|
261
|
+
# @return [PartialDebitResponse] successful response
|
|
262
|
+
# @raise [PartialDebitError] if the request fails
|
|
263
|
+
api_method def self.partial_debit(
|
|
264
|
+
email:,
|
|
265
|
+
amount:,
|
|
266
|
+
authorization_code:,
|
|
267
|
+
currency:,
|
|
268
|
+
at_least: nil,
|
|
269
|
+
reference: nil
|
|
270
|
+
)
|
|
271
|
+
use_connection do |connection|
|
|
272
|
+
connection.post(
|
|
273
|
+
'/transaction/partial_debit',
|
|
274
|
+
{
|
|
275
|
+
email:,
|
|
276
|
+
amount:,
|
|
277
|
+
authorization_code:,
|
|
278
|
+
currency:,
|
|
279
|
+
at_least:,
|
|
280
|
+
reference:,
|
|
281
|
+
}.compact,
|
|
282
|
+
)
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
# Successful response from calling #verify.
|
|
287
|
+
class VerifyResponse < PaystackGateway::Response
|
|
288
|
+
delegate :id,
|
|
289
|
+
:domain,
|
|
290
|
+
:reference,
|
|
291
|
+
:receipt_number,
|
|
292
|
+
:amount,
|
|
293
|
+
:gateway_response,
|
|
294
|
+
:paid_at,
|
|
295
|
+
:created_at,
|
|
296
|
+
:channel,
|
|
297
|
+
:currency,
|
|
298
|
+
:ip_address,
|
|
299
|
+
:metadata,
|
|
300
|
+
:log,
|
|
301
|
+
:fees,
|
|
302
|
+
:fees_split,
|
|
303
|
+
:authorization,
|
|
304
|
+
:customer,
|
|
305
|
+
:plan,
|
|
306
|
+
:split,
|
|
307
|
+
:order_id,
|
|
308
|
+
:paidAt,
|
|
309
|
+
:createdAt,
|
|
310
|
+
:requested_amount,
|
|
311
|
+
:pos_transaction_data,
|
|
312
|
+
:source,
|
|
313
|
+
:fees_breakdown,
|
|
314
|
+
:connect,
|
|
315
|
+
:transaction_date,
|
|
316
|
+
:plan_object,
|
|
317
|
+
:subaccount, to: :data
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
# Error response from #verify.
|
|
321
|
+
class VerifyError < ApiError; end
|
|
322
|
+
|
|
323
|
+
# https://paystack.com/docs/api/transaction/#verify
|
|
324
|
+
# Verify Transaction: GET /transaction/verify/{reference}
|
|
325
|
+
# Verify a previously initiated transaction using it's reference
|
|
326
|
+
#
|
|
327
|
+
# @param reference [String] (required)
|
|
328
|
+
# The transaction reference to verify
|
|
329
|
+
#
|
|
330
|
+
# @return [VerifyResponse] successful response
|
|
331
|
+
# @raise [VerifyError] if the request fails
|
|
332
|
+
api_method def self.verify(reference:)
|
|
333
|
+
use_connection do |connection|
|
|
334
|
+
connection.get(
|
|
335
|
+
"/transaction/verify/#{reference}",
|
|
336
|
+
)
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
# Successful response from calling #list.
|
|
341
|
+
class ListResponse < PaystackGateway::Response; end
|
|
342
|
+
|
|
343
|
+
# Error response from #list.
|
|
344
|
+
class ListError < ApiError; end
|
|
345
|
+
|
|
346
|
+
# https://paystack.com/docs/api/transaction/#list
|
|
347
|
+
# List Transactions: GET /transaction
|
|
348
|
+
# List transactions that has occurred on your integration
|
|
349
|
+
#
|
|
350
|
+
# @param use_cursor [Boolean]
|
|
351
|
+
# A flag to indicate if cursor based pagination should be used
|
|
352
|
+
# @param next [String]
|
|
353
|
+
# An alphanumeric value returned for every cursor based retrieval, used to retrieve
|
|
354
|
+
# the next set of data
|
|
355
|
+
# @param previous [String]
|
|
356
|
+
# An alphanumeric value returned for every cursor based retrieval, used to retrieve
|
|
357
|
+
# the previous set of data
|
|
358
|
+
# @param per_page [Integer]
|
|
359
|
+
# The number of records to fetch per request
|
|
360
|
+
# @param page [Integer]
|
|
361
|
+
# The offset to retrieve data from
|
|
362
|
+
# @param from [Time]
|
|
363
|
+
# The start date
|
|
364
|
+
# @param to [Time]
|
|
365
|
+
# The end date
|
|
366
|
+
# @param status ["success", "failed", "abandoned", "reversed"]
|
|
367
|
+
# Filter transaction by status
|
|
368
|
+
# @param source ["merchantApi", "checkout", "pos", "virtualTerminal"]
|
|
369
|
+
# The origin of the payment
|
|
370
|
+
# @param terminal_id [String]
|
|
371
|
+
# Filter transactions by a terminal ID
|
|
372
|
+
# @param virtual_account_number [String]
|
|
373
|
+
# Filter transactions by a virtual account number
|
|
374
|
+
# @param customer_code [String]
|
|
375
|
+
# Filter transactions by a customer code
|
|
376
|
+
# @param amount [Integer]
|
|
377
|
+
# Filter transactions by a specific amount
|
|
378
|
+
# @param settlement [Integer]
|
|
379
|
+
# The settlement ID to filter for settled transactions
|
|
380
|
+
# @param channel ["card", "pos", "bank", "dedicated_nuban", "ussd", "bank_transfer"]
|
|
381
|
+
# The payment method the customer used to complete the transaction
|
|
382
|
+
# @param subaccount_code [String]
|
|
383
|
+
# Filter transaction by subaccount code
|
|
384
|
+
# @param split_code [String]
|
|
385
|
+
# Filter transaction by split code
|
|
386
|
+
#
|
|
387
|
+
# @return [ListResponse] successful response
|
|
388
|
+
# @raise [ListError] if the request fails
|
|
389
|
+
api_method def self.list(
|
|
390
|
+
use_cursor: nil,
|
|
391
|
+
next: nil,
|
|
392
|
+
previous: nil,
|
|
393
|
+
per_page: nil,
|
|
394
|
+
page: nil,
|
|
395
|
+
from: nil,
|
|
396
|
+
to: nil,
|
|
397
|
+
status: nil,
|
|
398
|
+
source: nil,
|
|
399
|
+
terminal_id: nil,
|
|
400
|
+
virtual_account_number: nil,
|
|
401
|
+
customer_code: nil,
|
|
402
|
+
amount: nil,
|
|
403
|
+
settlement: nil,
|
|
404
|
+
channel: nil,
|
|
405
|
+
subaccount_code: nil,
|
|
406
|
+
split_code: nil
|
|
407
|
+
)
|
|
408
|
+
use_connection do |connection|
|
|
409
|
+
connection.get(
|
|
410
|
+
'/transaction',
|
|
411
|
+
{
|
|
412
|
+
use_cursor:,
|
|
413
|
+
next:,
|
|
414
|
+
previous:,
|
|
415
|
+
per_page:,
|
|
416
|
+
page:,
|
|
417
|
+
from:,
|
|
418
|
+
to:,
|
|
419
|
+
status:,
|
|
420
|
+
source:,
|
|
421
|
+
terminal_id:,
|
|
422
|
+
virtual_account_number:,
|
|
423
|
+
customer_code:,
|
|
424
|
+
amount:,
|
|
425
|
+
settlement:,
|
|
426
|
+
channel:,
|
|
427
|
+
subaccount_code:,
|
|
428
|
+
split_code:,
|
|
429
|
+
}.compact,
|
|
430
|
+
)
|
|
431
|
+
end
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
# Successful response from calling #fetch.
|
|
435
|
+
class FetchResponse < PaystackGateway::Response
|
|
436
|
+
delegate :id,
|
|
437
|
+
:domain,
|
|
438
|
+
:reference,
|
|
439
|
+
:receipt_number,
|
|
440
|
+
:amount,
|
|
441
|
+
:gateway_response,
|
|
442
|
+
:helpdesk_link,
|
|
443
|
+
:paid_at,
|
|
444
|
+
:created_at,
|
|
445
|
+
:channel,
|
|
446
|
+
:currency,
|
|
447
|
+
:ip_address,
|
|
448
|
+
:metadata,
|
|
449
|
+
:log,
|
|
450
|
+
:fees,
|
|
451
|
+
:fees_split,
|
|
452
|
+
:authorization,
|
|
453
|
+
:customer,
|
|
454
|
+
:plan,
|
|
455
|
+
:subaccount,
|
|
456
|
+
:split,
|
|
457
|
+
:order_id,
|
|
458
|
+
:paidAt,
|
|
459
|
+
:createdAt,
|
|
460
|
+
:requested_amount,
|
|
461
|
+
:pos_transaction_data,
|
|
462
|
+
:source,
|
|
463
|
+
:fees_breakdown,
|
|
464
|
+
:connect, to: :data
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
# Error response from #fetch.
|
|
468
|
+
class FetchError < ApiError; end
|
|
469
|
+
|
|
470
|
+
# https://paystack.com/docs/api/transaction/#fetch
|
|
471
|
+
# Fetch Transaction: GET /transaction/{id}
|
|
472
|
+
# Fetch a transaction to get its details
|
|
473
|
+
#
|
|
474
|
+
# @param id [Integer] (required)
|
|
475
|
+
# The ID of the transaction to fetch
|
|
476
|
+
#
|
|
477
|
+
# @return [FetchResponse] successful response
|
|
478
|
+
# @raise [FetchError] if the request fails
|
|
479
|
+
api_method def self.fetch(id:)
|
|
480
|
+
use_connection do |connection|
|
|
481
|
+
connection.get(
|
|
482
|
+
"/transaction/#{id}",
|
|
483
|
+
)
|
|
484
|
+
end
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
# Successful response from calling #timeline.
|
|
488
|
+
class TimelineResponse < PaystackGateway::Response; end
|
|
489
|
+
|
|
490
|
+
# Error response from #timeline.
|
|
491
|
+
class TimelineError < ApiError; end
|
|
492
|
+
|
|
493
|
+
# https://paystack.com/docs/api/transaction/#timeline
|
|
494
|
+
# Fetch Transaction Timeline: GET /transaction/timeline/{id}
|
|
495
|
+
# Fetch the steps taken from the initiation to the completion of a transaction
|
|
496
|
+
#
|
|
497
|
+
# @param id [Integer] (required)
|
|
498
|
+
# The ID of the transaction to fetch
|
|
499
|
+
#
|
|
500
|
+
# @return [TimelineResponse] successful response
|
|
501
|
+
# @raise [TimelineError] if the request fails
|
|
502
|
+
api_method def self.timeline(id:)
|
|
503
|
+
use_connection do |connection|
|
|
504
|
+
connection.get(
|
|
505
|
+
"/transaction/timeline/#{id}",
|
|
506
|
+
)
|
|
507
|
+
end
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
# Successful response from calling #totals.
|
|
511
|
+
class TotalsResponse < PaystackGateway::Response
|
|
512
|
+
delegate :total_transactions,
|
|
513
|
+
:total_volume,
|
|
514
|
+
:total_volume_by_currency,
|
|
515
|
+
:pending_transfers,
|
|
516
|
+
:pending_transfers_by_currency, to: :data
|
|
517
|
+
end
|
|
518
|
+
|
|
519
|
+
# Error response from #totals.
|
|
520
|
+
class TotalsError < ApiError; end
|
|
521
|
+
|
|
522
|
+
# https://paystack.com/docs/api/transaction/#totals
|
|
523
|
+
# Transaction Totals: GET /transaction/totals
|
|
524
|
+
# Get the total amount of all transactions
|
|
525
|
+
#
|
|
526
|
+
# @param from [Time]
|
|
527
|
+
# The start date
|
|
528
|
+
# @param to [Time]
|
|
529
|
+
# The end date
|
|
530
|
+
#
|
|
531
|
+
# @return [TotalsResponse] successful response
|
|
532
|
+
# @raise [TotalsError] if the request fails
|
|
533
|
+
api_method def self.totals(from: nil, to: nil)
|
|
534
|
+
use_connection do |connection|
|
|
535
|
+
connection.get(
|
|
536
|
+
'/transaction/totals',
|
|
537
|
+
{ from:, to: }.compact,
|
|
538
|
+
)
|
|
539
|
+
end
|
|
540
|
+
end
|
|
541
|
+
|
|
542
|
+
# Successful response from calling #export.
|
|
543
|
+
class ExportResponse < PaystackGateway::Response
|
|
544
|
+
delegate :path, :expiresAt, to: :data
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
# Error response from #export.
|
|
548
|
+
class ExportError < ApiError; end
|
|
549
|
+
|
|
550
|
+
# https://paystack.com/docs/api/transaction/#export
|
|
551
|
+
# Export Transactions: GET /transaction/export
|
|
552
|
+
# Download transactions that occurred on your integration for a specific timeframe
|
|
553
|
+
#
|
|
554
|
+
# @param from [Time]
|
|
555
|
+
# The start date
|
|
556
|
+
# @param to [Time]
|
|
557
|
+
# The end date
|
|
558
|
+
# @param status ["success", "failed", "abandoned", "reversed", "all"]
|
|
559
|
+
# Filter by the status of the transaction
|
|
560
|
+
# @param customer [Number]
|
|
561
|
+
# Filter by customer ID
|
|
562
|
+
# @param subaccount_code [String]
|
|
563
|
+
# Filter by subaccount code
|
|
564
|
+
# @param settlement [Integer]
|
|
565
|
+
# Filter by the settlement ID
|
|
566
|
+
#
|
|
567
|
+
# @return [ExportResponse] successful response
|
|
568
|
+
# @raise [ExportError] if the request fails
|
|
569
|
+
api_method def self.export(
|
|
570
|
+
from: nil,
|
|
571
|
+
to: nil,
|
|
572
|
+
status: nil,
|
|
573
|
+
customer: nil,
|
|
574
|
+
subaccount_code: nil,
|
|
575
|
+
settlement: nil
|
|
576
|
+
)
|
|
577
|
+
use_connection do |connection|
|
|
578
|
+
connection.get(
|
|
579
|
+
'/transaction/export',
|
|
580
|
+
{
|
|
581
|
+
from:,
|
|
582
|
+
to:,
|
|
583
|
+
status:,
|
|
584
|
+
customer:,
|
|
585
|
+
subaccount_code:,
|
|
586
|
+
settlement:,
|
|
587
|
+
}.compact,
|
|
588
|
+
)
|
|
589
|
+
end
|
|
590
|
+
end
|
|
591
|
+
end
|
|
592
|
+
end
|
|
@@ -1,35 +1,3 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
# Common helpers for responses from transaction endpoints
|
|
5
|
-
module TransactionResponse
|
|
6
|
-
extend ActiveSupport::Concern
|
|
7
|
-
|
|
8
|
-
included do
|
|
9
|
-
delegate :id, :amount, :subaccount, :fees_split, to: :data
|
|
10
|
-
|
|
11
|
-
attr_writer :completed_at
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def transaction_success? = transaction_status.in?(%i[success reversed reversal_pending])
|
|
15
|
-
def transaction_abandoned? = transaction_status == :abandoned
|
|
16
|
-
def transaction_failed? = transaction_status == :failed
|
|
17
|
-
def transaction_pending? = transaction_status.in?(%i[pending ongoing])
|
|
18
|
-
|
|
19
|
-
def transaction_status = data.status.to_sym
|
|
20
|
-
def transaction_amount = amount / BigDecimal('100')
|
|
21
|
-
def transaction_completed_at = data[:updatedAt] || @completed_at
|
|
22
|
-
|
|
23
|
-
def subaccount_amount
|
|
24
|
-
return if !subaccount || !fees_split
|
|
25
|
-
|
|
26
|
-
fees_split.subaccount / BigDecimal('100')
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def failure_reason
|
|
30
|
-
return if !transaction_failed? && !transaction_abandoned?
|
|
31
|
-
|
|
32
|
-
data.gateway_response || transaction_status || message
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
3
|
+
require 'paystack_gateway/legacy/transaction_response'
|