paystack_sdk 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.
@@ -1,296 +1,423 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Generated by bin/paystack-scaffold from Paystack's OpenAPI spec (PaystackOSS/openapi@d9d444d).
4
+ # Do not edit by hand: regenerate it with `bin/paystack-scaffold Transaction`. Hand-written extras go in lib/paystack_sdk/resources/extensions/transactions.rb.
5
+ # scaffold-digest: c0b49a40a718c09c83eb9a496eb40d1f7cd4c1387b54efa3cfe360906be89f0e
6
+
3
7
  require_relative "base"
4
8
 
5
9
  module PaystackSdk
6
10
  module Resources
7
- # The `Transactions` class provides methods for interacting with the Paystack
8
- # Transactions API.
9
- # It allows you to initialize transactions, verify payments, list transactions, and fetch transaction details.
10
- # The Transactions class provides methods to interact with the Paystack API for managing transactions.
11
- # It includes functionalities for initializing, verifying, listing, fetching, and retrieving transaction totals.
12
- #
13
- # Example usage:
14
- # ```ruby
15
- # transactions = PaystackSdk::Resources::Transactions.new(secret_key:)
16
- #
17
- # # Initialize a transaction
18
- # payload = { email: "customer@email.com", amount: 10000, currency: "GHS" }
19
- # response = transactions.initiate(payload)
20
- # if response.success?
21
- # puts "Transaction initialized successfully."
22
- # puts "Authorization URL: #{response.authorization_url}"
23
- # else
24
- # puts "Error initializing transaction: #{response.error_message}"
25
- # end
26
- #
27
- # # Verify a transaction
28
- # response = transactions.verify(reference: "transaction_reference")
29
- # if response.status == "success"
30
- # puts "The payment with reference '#{response.reference}' is verified"
31
- # else
32
- # puts "Current status: #{response.status}"
33
- # end
34
- #
35
- # # List transactions
36
- # response = transactions.list(per_page: 50, page: 1)
37
- #
38
- # # Fetch a single transaction
39
- # response = transactions.fetch(transaction_id: 12345)
40
- #
41
- # # Get transaction totals
42
- # response = transactions.totals
43
- # ```
11
+ # Transaction operations.
44
12
  class Transactions < PaystackSdk::Resources::Base
45
- # Initializes a new transaction.
13
+ # Ruby keyword => the parameter name Paystack documents.
14
+ WIRE_NAMES = {next_cursor: "next", per_page: "perPage", terminal_id: "terminalid", customer_id: "customer"}.freeze
15
+
16
+ # Initialize Transaction.
46
17
  #
47
- # @param payload [Hash] The payload containing transaction details (e.g., email, amount, currency).
48
- # @return [PaystackSdk::Response] The response from the Paystack API.
49
- # @raise [PaystackSdk::Error] If the payload is invalid or the API request fails.
18
+ # Create a new transaction
50
19
  #
51
- # @example
52
- # ```ruby
53
- # payload = { email: "customer@email.com", amount: 10000, currency: "GHS" }
54
- # response = transactions.initiate(payload)
55
- # ```
56
- def initiate(payload)
57
- validate_fields!(
58
- payload: payload,
59
- validations: {
60
- email: {type: :email, required: true},
61
- amount: {type: :positive_integer, required: true},
62
- currency: {type: :currency, required: false},
63
- reference: {type: :reference, required: false},
64
- callback_url: {required: false}
65
- }
20
+ # @param email [String] Customer's email address
21
+ # @param amount [Integer] Amount should be in smallest denomination of the currency.
22
+ # @param currency [String] List of all support currencies One of: GHS, KES, NGN, ZAR, USD.
23
+ # @param reference [String] Unique transaction reference.
24
+ # @param channels [Array] An array of payment channels to control what channels you want to make available to the user to make a payment with
25
+ # @param callback_url [String] Fully qualified url, e.g.
26
+ # @param plan [String] If transaction is to create a subscription to a predefined plan, provide plan code here.
27
+ # @param invoice_limit [Integer] Number of times to charge customer during subscription to plan
28
+ # @param split_code [String] The split code of the transaction split
29
+ # @param split [Hash] Split configuration for transactions
30
+ # @param subaccount [String] The code for the subaccount that owns the payment
31
+ # @param transaction_charge [String] A flat fee to charge the subaccount for a transaction.
32
+ # @param bearer [String] The bearer of the transaction charge One of: account, subaccount.
33
+ # @param label [String] Used to replace the email address shown on the Checkout
34
+ # @param metadata [Hash] JSON object of custom data
35
+ # @return [PaystackSdk::Response] The response from the Paystack API.
36
+ # @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
37
+ # @see https://paystack.com/docs/api/transaction/#initialize
38
+ def initiate(
39
+ email:,
40
+ amount:,
41
+ currency: nil,
42
+ reference: nil,
43
+ channels: nil,
44
+ callback_url: nil,
45
+ plan: nil,
46
+ invoice_limit: nil,
47
+ split_code: nil,
48
+ split: nil,
49
+ subaccount: nil,
50
+ transaction_charge: nil,
51
+ bearer: nil,
52
+ label: nil,
53
+ metadata: nil
54
+ )
55
+ validate_presence!(value: email, name: "email")
56
+ validate_email!(email: email, name: "email")
57
+ validate_presence!(value: amount, name: "amount")
58
+ validate_positive_integer!(value: amount, name: "amount")
59
+ validate_allowed_values!(
60
+ value: currency,
61
+ allowed_values: %w[GHS KES NGN ZAR USD],
62
+ name: "currency"
63
+ )
64
+ validate_reference_format!(reference: reference, name: "reference") unless reference.nil?
65
+ validate_allowed_values!(
66
+ value: bearer,
67
+ allowed_values: %w[account subaccount],
68
+ name: "bearer"
66
69
  )
67
70
 
68
- response = @connection.post("/transaction/initialize", payload)
69
- handle_response(response)
71
+ wire_body = to_wire(
72
+ {
73
+ email:,
74
+ amount:,
75
+ currency:,
76
+ reference:,
77
+ channels:,
78
+ callback_url:,
79
+ plan:,
80
+ invoice_limit:,
81
+ split_code:,
82
+ split:,
83
+ subaccount:,
84
+ transaction_charge:,
85
+ bearer:,
86
+ label:,
87
+ metadata:
88
+ },
89
+ WIRE_NAMES
90
+ )
91
+
92
+ handle_response(@connection.post("/transaction/initialize", wire_body))
70
93
  end
71
94
 
72
- # Verifies a transaction using its reference.
95
+ # Charge Authorization.
73
96
  #
74
- # @param reference [String] The unique reference for the transaction.
75
- # @return [PaystackSdk::Response] The response from the Paystack API.
76
- # @raise [PaystackSdk::Error] If the API request fails.
97
+ # Charge all authorizations marked as reusable with this endpoint whenever you need to receive payments
77
98
  #
78
- # @example
79
- # response = transactions.verify(reference: "transaction_reference")
80
- def verify(reference:)
81
- validate_presence!(value: reference, name: "Reference")
99
+ # @param email [String] Customer's email address
100
+ # @param amount [Integer] Amount in the lower denomination of your currency
101
+ # @param authorization_code [String] Valid authorization code to charge
102
+ # @param reference [String] Unique transaction reference.
103
+ # @param currency [String] List of all support currencies One of: GHS, KES, NGN, ZAR, USD.
104
+ # @param split_code [String] The split code of the transaction split
105
+ # @param split [Hash] Split configuration for transactions
106
+ # @param subaccount [String] The code for the subaccount that owns the payment
107
+ # @param transaction_charge [String] A flat fee to charge the subaccount for a transaction.
108
+ # @param bearer [String] The bearer of the transaction charge One of: account, subaccount.
109
+ # @param metadata [String] Stringified JSON object of custom data
110
+ # @param queue [Boolean] If you are making a scheduled charge call, it is a good idea to queue them so the processing system does not get overloaded causing transaction processing errors.
111
+ # @return [PaystackSdk::Response] The response from the Paystack API.
112
+ # @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
113
+ # @see https://paystack.com/docs/api/transaction/#charge-authorization
114
+ def charge_authorization(
115
+ email:,
116
+ amount:,
117
+ authorization_code:,
118
+ reference: nil,
119
+ currency: nil,
120
+ split_code: nil,
121
+ split: nil,
122
+ subaccount: nil,
123
+ transaction_charge: nil,
124
+ bearer: nil,
125
+ metadata: nil,
126
+ queue: nil
127
+ )
128
+ validate_presence!(value: email, name: "email")
129
+ validate_email!(email: email, name: "email")
130
+ validate_presence!(value: amount, name: "amount")
131
+ validate_positive_integer!(value: amount, name: "amount")
132
+ validate_presence!(value: authorization_code, name: "authorization_code")
133
+ validate_reference_format!(reference: reference, name: "reference") unless reference.nil?
134
+ validate_allowed_values!(
135
+ value: currency,
136
+ allowed_values: %w[GHS KES NGN ZAR USD],
137
+ name: "currency"
138
+ )
139
+ validate_allowed_values!(
140
+ value: bearer,
141
+ allowed_values: %w[account subaccount],
142
+ name: "bearer"
143
+ )
144
+
145
+ wire_body = to_wire(
146
+ {
147
+ email:,
148
+ amount:,
149
+ authorization_code:,
150
+ reference:,
151
+ currency:,
152
+ split_code:,
153
+ split:,
154
+ subaccount:,
155
+ transaction_charge:,
156
+ bearer:,
157
+ metadata: stringify_json(metadata),
158
+ queue:
159
+ },
160
+ WIRE_NAMES
161
+ )
82
162
 
83
- response = @connection.get("/transaction/verify/#{reference}")
84
- handle_response(response)
163
+ handle_response(@connection.post("/transaction/charge_authorization", wire_body))
85
164
  end
86
165
 
87
- # Lists all transactions.
166
+ # Partial Debit.
88
167
  #
89
- # @param per_page [Integer] Number of records per page (default: 50)
90
- # @param page [Integer] Page number to retrieve (default: 1)
91
- # @param from [String] A timestamp from which to start listing transactions e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
92
- # @param to [String] A timestamp at which to stop listing transactions e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
93
- # @param status [String] Filter transactions by status ('failed', 'success', 'abandoned')
94
- # @param customer [Integer] Specify an ID for the customer whose transactions you want to retrieve
95
- # @param currency [String] Specify the transaction currency to filter
96
- # @param amount [Integer] Filter by transaction amount
97
- # @return [PaystackSdk::Response] The response from the Paystack API containing a
98
- # list of transactions.
99
- # @raise [PaystackSdk::Error] If the API request fails.
168
+ # Retrieve part of a payment from a customer
100
169
  #
101
- # @example
102
- # response = transactions.list(per_page: 20, page: 2)
103
- # # With filters
104
- # response = transactions.list(per_page: 10, from: "2023-01-01", to: "2023-12-31", status: "success")
105
- def list(per_page: 50, page: 1, **params)
106
- # Create a combined parameter hash for validation
107
- all_params = {per_page: per_page, page: page}.merge(params)
170
+ # @param email [String] Customer's email address
171
+ # @param amount [Integer] Specified in the lowest denomination of your currency
172
+ # @param authorization_code [String] Valid authorization code to charge
173
+ # @param currency [String] List of all support currencies One of: GHS, KES, NGN, ZAR, USD.
174
+ # @param at_least [String] Minimum amount to charge
175
+ # @param reference [String] Unique transaction reference.
176
+ # @return [PaystackSdk::Response] The response from the Paystack API.
177
+ # @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
178
+ # @see https://paystack.com/docs/api/transaction/#partial-debit
179
+ def partial_debit(
180
+ email:,
181
+ amount:,
182
+ authorization_code:,
183
+ currency:,
184
+ at_least: nil,
185
+ reference: nil
186
+ )
187
+ validate_presence!(value: email, name: "email")
188
+ validate_email!(email: email, name: "email")
189
+ validate_presence!(value: amount, name: "amount")
190
+ validate_positive_integer!(value: amount, name: "amount")
191
+ validate_presence!(value: authorization_code, name: "authorization_code")
192
+ validate_presence!(value: currency, name: "currency")
193
+ validate_allowed_values!(
194
+ value: currency,
195
+ allowed_values: %w[GHS KES NGN ZAR USD],
196
+ name: "currency"
197
+ )
198
+ validate_reference_format!(reference: reference, name: "reference") unless reference.nil?
108
199
 
109
- # Validate parameters
110
- validate_fields!(
111
- payload: all_params,
112
- validations: {
113
- per_page: {type: :positive_integer, required: false},
114
- page: {type: :positive_integer, required: false},
115
- from: {type: :date, required: false},
116
- to: {type: :date, required: false},
117
- status: {type: :inclusion, allowed_values: %w[failed success abandoned], required: false},
118
- customer: {type: :positive_integer, required: false},
119
- amount: {type: :positive_integer, required: false},
120
- currency: {type: :currency, required: false}
121
- }
200
+ wire_body = to_wire(
201
+ {
202
+ email:,
203
+ amount:,
204
+ authorization_code:,
205
+ currency:,
206
+ at_least:,
207
+ reference:
208
+ },
209
+ WIRE_NAMES
122
210
  )
123
211
 
124
- # Prepare request parameters
125
- request_params = {perPage: per_page, page: page}.merge(params)
126
- response = @connection.get("/transaction", request_params)
127
- handle_response(response)
212
+ handle_response(@connection.post("/transaction/partial_debit", wire_body))
128
213
  end
129
214
 
130
- # Fetches details of a single transaction by its ID.
215
+ # Verify Transaction.
131
216
  #
132
- # @param transaction_id [String, Integer] The ID of the transaction to fetch.
133
- # @return [PaystackSdk::Response] The response from the Paystack API containing transaction details.
134
- # @raise [PaystackSdk::Error] If the API request fails.
217
+ # Verify a previously initiated transaction using it's reference
135
218
  #
136
- # @example
137
- # response = transactions.fetch("12345")
138
- def fetch(transaction_id)
139
- validate_presence!(value: transaction_id, name: "Transaction ID")
219
+ # @param reference [String] The transaction reference to verify
220
+ # @return [PaystackSdk::Response] The response from the Paystack API.
221
+ # @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
222
+ # @see https://paystack.com/docs/api/transaction/#verify
223
+ def verify(reference:)
224
+ validate_presence!(value: reference, name: "reference")
140
225
 
141
- response = @connection.get("/transaction/#{transaction_id}")
142
- handle_response(response)
226
+ handle_response(
227
+ @connection.get("/transaction/verify/#{escape_path(reference, name: "reference")}")
228
+ )
143
229
  end
144
230
 
145
- # Fetches the totals of all transactions.
231
+ # List Transactions.
146
232
  #
147
- # @param from [String] A timestamp from which to start listing transaction totals e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
148
- # @param to [String] A timestamp at which to stop listing transaction totals e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
149
- # @return [PaystackSdk::Response] The response from the Paystack API containing transaction totals.
150
- # @raise [PaystackSdk::Error] If the API request fails.
233
+ # List transactions that has occurred on your integration
151
234
  #
152
- # @example
153
- # response = transactions.totals
154
- # # With date filters
155
- # response = transactions.totals(from: "2023-01-01", to: "2023-12-31")
156
- def totals(**params)
157
- validate_fields!(
158
- payload: params,
159
- validations: {
160
- from: {type: :date, required: false},
161
- to: {type: :date, required: false}
162
- }
235
+ # @param use_cursor [Boolean] A flag to indicate if cursor based pagination should be used
236
+ # @param next_cursor [String] An alphanumeric value returned for every cursor based retrieval, used to retrieve the next set of data
237
+ # @param previous [String] An alphanumeric value returned for every cursor based retrieval, used to retrieve the previous set of data
238
+ # @param per_page [Integer] The number of records to fetch per request
239
+ # @param page [Integer] The offset to retrieve data from
240
+ # @param from [String] The start date
241
+ # @param to [String] The end date
242
+ # @param status [String] Filter transaction by status One of: success, failed, abandoned, reversed.
243
+ # @param source [String] The origin of the payment One of: merchantApi, checkout, pos, virtualTerminal.
244
+ # @param terminal_id [String] Filter transactions by a terminal ID
245
+ # @param virtual_account_number [String] Filter transactions by a virtual account number
246
+ # @param customer_id [Integer] Filter transactions by a customer code
247
+ # @param amount [Integer] Filter transactions by a specific amount
248
+ # @param settlement [Integer] The settlement ID to filter for settled transactions
249
+ # @param channel [String] The payment method the customer used to complete the transaction One of: card, pos, bank, dedicated_nuban, ussd, bank_transfer.
250
+ # @param subaccount_code [String] Filter transaction by subaccount code
251
+ # @param split_code [String] Filter transaction by split code
252
+ # @return [PaystackSdk::Response] The response from the Paystack API.
253
+ # @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
254
+ # @see https://paystack.com/docs/api/transaction/#list
255
+ def list(
256
+ use_cursor: nil,
257
+ next_cursor: nil,
258
+ previous: nil,
259
+ per_page: nil,
260
+ page: nil,
261
+ from: nil,
262
+ to: nil,
263
+ status: nil,
264
+ source: nil,
265
+ terminal_id: nil,
266
+ virtual_account_number: nil,
267
+ customer_id: nil,
268
+ amount: nil,
269
+ settlement: nil,
270
+ channel: nil,
271
+ subaccount_code: nil,
272
+ split_code: nil
273
+ )
274
+ validate_positive_integer!(value: per_page, name: "perPage")
275
+ validate_positive_integer!(value: page, name: "page")
276
+ validate_allowed_values!(
277
+ value: status,
278
+ allowed_values: %w[success failed abandoned reversed],
279
+ name: "status"
280
+ )
281
+ validate_allowed_values!(
282
+ value: source,
283
+ allowed_values: %w[merchantApi checkout pos virtualTerminal],
284
+ name: "source"
285
+ )
286
+ validate_positive_integer!(value: amount, name: "amount")
287
+ validate_allowed_values!(
288
+ value: channel,
289
+ allowed_values: %w[card pos bank dedicated_nuban ussd bank_transfer],
290
+ name: "channel"
163
291
  )
164
292
 
165
- response = @connection.get("/transaction/totals", params)
166
- handle_response(response)
293
+ wire_query = to_wire(
294
+ {
295
+ use_cursor:,
296
+ next_cursor:,
297
+ previous:,
298
+ per_page:,
299
+ page:,
300
+ from: format_datetime(from, name: "from"),
301
+ to: format_datetime(to, name: "to"),
302
+ status:,
303
+ source:,
304
+ terminal_id:,
305
+ virtual_account_number:,
306
+ customer_id:,
307
+ amount:,
308
+ settlement:,
309
+ channel:,
310
+ subaccount_code:,
311
+ split_code:
312
+ },
313
+ WIRE_NAMES
314
+ )
315
+
316
+ handle_response(@connection.get("/transaction", wire_query))
167
317
  end
168
318
 
169
- # Exports transactions as a downloadable file.
319
+ # Fetch Transaction.
170
320
  #
171
- # @param from [String] A timestamp from which to start the export e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
172
- # @param to [String] A timestamp at which to stop the export e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
173
- # @param status [String] Export only transactions with a specific status ('failed', 'success', 'abandoned')
174
- # @param currency [String] Specify the transaction currency to export
175
- # @param amount [Integer] Filter by transaction amount
176
- # @param settled [Boolean] Set to true to export only settled transactions
177
- # @param payment_page [Integer] Specify a payment page ID to export only transactions conducted through the page
178
- # @param customer [Integer] Specify an ID for the customer whose transactions you want to export
179
- # @param settlement [Integer] Specify a settlement ID to export only transactions in the settlement
180
- # @return [PaystackSdk::Response] The response from the Paystack API containing the export details.
181
- # @raise [PaystackSdk::Error] If the API request fails.
321
+ # Fetch a transaction to get its details
182
322
  #
183
- # @example
184
- # response = transactions.export
185
- # # With filters
186
- # response = transactions.export(from: "2023-01-01", to: "2023-12-31", status: "success", currency: "NGN")
187
- def export(**params)
188
- validate_fields!(
189
- payload: params,
190
- validations: {
191
- from: {type: :date, required: false},
192
- to: {type: :date, required: false},
193
- status: {type: :inclusion, allowed_values: %w[failed success abandoned], required: false},
194
- currency: {type: :currency, required: false},
195
- amount: {type: :positive_integer, required: false},
196
- payment_page: {type: :positive_integer, required: false},
197
- customer: {type: :positive_integer, required: false},
198
- settlement: {type: :positive_integer, required: false}
199
- }
200
- )
323
+ # @param id [Integer] The ID of the transaction to fetch
324
+ # @return [PaystackSdk::Response] The response from the Paystack API.
325
+ # @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
326
+ # @see https://paystack.com/docs/api/transaction/#fetch
327
+ def fetch(id:)
328
+ validate_presence!(value: id, name: "id")
201
329
 
202
- response = @connection.get("/transaction/export", params)
203
- handle_response(response)
330
+ handle_response(@connection.get("/transaction/#{escape_path(id, name: "id")}"))
204
331
  end
205
332
 
206
- # Charges an authorization code for subsequent payments.
333
+ # Fetch Transaction Timeline.
207
334
  #
208
- # @param payload [Hash] The payload containing charge details.
209
- # @option payload [String] :authorization_code Authorization code for the transaction (required)
210
- # @option payload [String] :email Customer's email address (required)
211
- # @option payload [Integer] :amount Amount in kobo, pesewas, or cents to charge (required)
212
- # @option payload [String] :reference Unique transaction reference. Only -, ., = and alphanumeric characters allowed
213
- # @option payload [String] :currency Currency in which amount should be charged (default: NGN)
214
- # @option payload [Hash] :metadata Additional transaction information
215
- # @option payload [Array<Hash>] :split_code Split payment among multiple accounts
216
- # @return [PaystackSdk::Response] The response from the Paystack API.
217
- # @raise [PaystackSdk::Error] If the payload is invalid or the API request fails.
335
+ # Fetch the steps taken from the initiation to the completion of a transaction
218
336
  #
219
- # @example
220
- # payload = {
221
- # authorization_code: "AUTH_72btv547",
222
- # email: "customer@email.com",
223
- # amount: 10000
224
- # }
225
- # response = transactions.charge_authorization(payload)
226
- def charge_authorization(payload)
227
- validate_fields!(
228
- payload: payload,
229
- validations: {
230
- authorization_code: {required: true},
231
- email: {type: :email, required: true},
232
- amount: {type: :positive_integer, required: true},
233
- reference: {type: :reference, required: false},
234
- currency: {type: :currency, required: false}
235
- }
236
- )
337
+ # @param id [Integer] The ID of the transaction to fetch
338
+ # @return [PaystackSdk::Response] The response from the Paystack API.
339
+ # @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
340
+ # @see https://paystack.com/docs/api/transaction/#view-timeline
341
+ def timeline(id:)
342
+ validate_presence!(value: id, name: "id")
237
343
 
238
- response = @connection.post("/transaction/charge_authorization", payload)
239
- handle_response(response)
344
+ handle_response(@connection.get("/transaction/timeline/#{escape_path(id, name: "id")}"))
240
345
  end
241
346
 
242
- # Performs a partial debit on a customer's account.
347
+ # Transaction Totals.
243
348
  #
244
- # @param payload [Hash] The payload containing partial debit details.
245
- # @option payload [String] :authorization_code Authorization code for the transaction (required)
246
- # @option payload [String] :currency Currency in which amount should be charged (required)
247
- # @option payload [Integer] :amount Amount in kobo, pesewas, or cents to charge (required)
248
- # @option payload [String] :email Customer's email address (required)
249
- # @option payload [String] :reference Unique transaction reference. Only -, ., = and alphanumeric characters allowed
250
- # @option payload [Hash] :metadata Additional transaction information
251
- # @option payload [Array<Hash>] :split_code Split payment among multiple accounts
252
- # @return [PaystackSdk::Response] The response from the Paystack API.
253
- # @raise [PaystackSdk::Error] If the payload is invalid or the API request fails.
349
+ # Get the total amount of all transactions
254
350
  #
255
- # @example
256
- # payload = {
257
- # authorization_code: "AUTH_72btv547",
258
- # currency: "NGN",
259
- # amount: 10000,
260
- # email: "customer@email.com"
261
- # }
262
- # response = transactions.partial_debit(payload)
263
- def partial_debit(payload)
264
- validate_fields!(
265
- payload: payload,
266
- validations: {
267
- authorization_code: {required: true},
268
- currency: {type: :currency, required: true},
269
- amount: {type: :positive_integer, required: true},
270
- email: {type: :email, required: true},
271
- reference: {type: :reference, required: false}
272
- }
351
+ # @param from [String] The start date
352
+ # @param to [String] The end date
353
+ # @return [PaystackSdk::Response] The response from the Paystack API.
354
+ # @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
355
+ # @see https://paystack.com/docs/api/transaction/#totals
356
+ def totals(from: nil, to: nil)
357
+ wire_query = to_wire(
358
+ {
359
+ from: format_datetime(from, name: "from"),
360
+ to: format_datetime(to, name: "to")
361
+ },
362
+ WIRE_NAMES
273
363
  )
274
364
 
275
- response = @connection.post("/transaction/partial_debit", payload)
276
- handle_response(response)
365
+ handle_response(@connection.get("/transaction/totals", wire_query))
277
366
  end
278
367
 
279
- # View the timeline of a transaction
368
+ # Export Transactions.
280
369
  #
281
- # @param id_or_reference [String] The ID or reference of the transaction
282
- # @return [PaystackSdk::Response] The response from the Paystack API containing timeline details.
283
- # @raise [PaystackSdk::Error] If the API request fails.
370
+ # Download transactions that occurred on your integration for a specific timeframe
284
371
  #
285
- # @example
286
- # response = transactions.timeline("12345")
287
- # # OR
288
- # response = transactions.timeline("ref_123456789")
289
- def timeline(id_or_reference)
290
- validate_presence!(value: id_or_reference, name: "Transaction ID or Reference")
372
+ # @param from [String] The start date
373
+ # @param to [String] The end date
374
+ # @param status [String] Filter by the status of the transaction One of: success, failed, abandoned, reversed, all.
375
+ # @param customer_id [Numeric] Filter by customer ID
376
+ # @param subaccount_code [String] Filter by subaccount code
377
+ # @param settlement [Integer] Filter by the settlement ID
378
+ # @param currency [String] Specify the transaction currency to export.
379
+ # @param amount [Integer] Filter transactions by amount, using the supported currency subunit.
380
+ # @param settled [Boolean] Set to true to export only settled transactions, false for pending transactions.
381
+ # @param payment_page [Integer] Specify a payment page's id to export only transactions conducted on said page.
382
+ # @return [PaystackSdk::Response] The response from the Paystack API.
383
+ # @raise [PaystackSdk::Error] If a parameter is invalid or the API request fails.
384
+ # @see https://paystack.com/docs/api/transaction/#export
385
+ def export(
386
+ from: nil,
387
+ to: nil,
388
+ status: nil,
389
+ customer_id: nil,
390
+ subaccount_code: nil,
391
+ settlement: nil,
392
+ currency: nil,
393
+ amount: nil,
394
+ settled: nil,
395
+ payment_page: nil
396
+ )
397
+ validate_allowed_values!(
398
+ value: status,
399
+ allowed_values: %w[success failed abandoned reversed all],
400
+ name: "status"
401
+ )
402
+ validate_positive_integer!(value: amount, name: "amount")
403
+
404
+ wire_query = to_wire(
405
+ {
406
+ from: format_datetime(from, name: "from"),
407
+ to: format_datetime(to, name: "to"),
408
+ status:,
409
+ customer_id:,
410
+ subaccount_code:,
411
+ settlement:,
412
+ currency:,
413
+ amount:,
414
+ settled:,
415
+ payment_page:
416
+ },
417
+ WIRE_NAMES
418
+ )
291
419
 
292
- response = @connection.get("/transaction/timeline/#{id_or_reference}")
293
- handle_response(response)
420
+ handle_response(@connection.get("/transaction/export", wire_query))
294
421
  end
295
422
  end
296
423
  end