Skip to content

Transactions

TransactionClient

Bases: BaseAPIClient

Provides a wrapper for paystack Transactions API

The Transactions API allows you to create and manage payments on your integration. see https://paystack.com/docs/api/transaction/

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
class TransactionClient(BaseAPIClient):
    """Provides a wrapper for paystack Transactions API

    The Transactions API allows you to create and manage payments on your integration.
    see https://paystack.com/docs/api/transaction/
    """

    def initialize(
        self,
        amount: int,
        email: str,
        currency: Currency | None = None,
        reference: str | None = None,
        callback_url: str | None = None,
        plan: str | None = None,
        invoice_limit: int | None = None,
        metadata: dict[str, Any] | None = None,
        channels: list[Channel] | None = None,
        split_code: str | None = None,
        subaccount: str | None = None,
        transfer_charge: int | None = None,
        bearer: Bearer | None = None,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[InitTransaction] | Response[PaystackDataModel]:
        """Initialize a transaction from your backend

        Args:
            amount: Amount should be in kobo if currency is ``Currency.NGN``, pesewas,
                if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
            email: Customer's email address
            currency: Any value from the ``Currency`` enum.
            reference: Unique transaction reference. Only ``-, ., =`` and alphanumeric characters allowed.
            callback_url: Fully qualified url, e.g. ``https://example.com/`` . Use this to override the callback url
                provided on the dashboard for this transaction
            plan: If transaction is to create a subscription to a predefined plan, provide plan code here.
                This would invalidate the value provided in ``amount``
            invoice_limit: Number of times to charge customer during subscription to plan
            metadata: A dictionary of additional info. check out this link
                for more information. https://paystack.com/docs/payments/metadata
            channels: A list of ``Channel`` enum values to control what channels you want to make available
                to the user to make a payment with
            split_code: The split code of the transaction split. e.g. SPL_98WF13Eb3w
            subaccount: The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj
            transfer_charge: An amount used to override the split configuration for a single split payment. If set,
                the amount specified goes to the main account regardless of the split configuration.
            bearer: Any value from the ``Bearer`` enum. Who bears Paystack charges?
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.

        Raises:
            InvalidDataError: When email is not provided.
        """

        if not email:
            raise ValueError("Customer's Email is required for initialization")

        url = self._full_url("/transaction/initialize")
        payload = {
            "email": email,
            "amount": amount,
        }

        optional_params = [
            ("currency", currency),
            ("reference", reference),
            ("callback_url", callback_url),
            ("plan", plan),
            ("invoice_limit", invoice_limit),
            ("metadata", metadata),
            ("channels", channels),
            ("split_code", split_code),
            ("subaccount", subaccount),
            ("transfer_charge", transfer_charge),
            ("bearer", bearer),
        ]
        payload = add_to_payload(optional_params, payload)

        return self._handle_request(  # type: ignore
            HTTPMethod.POST,
            url,
            payload,
            response_data_model_class=alternate_model_class or InitTransaction,
        )

    def verify(
        self,
        reference: str,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[Transaction] | Response[PaystackDataModel]:
        """Confirm the status of a transaction

        Args:
            reference: The transaction reference used to initiate the transaction
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        reference = str(reference)
        url = self._full_url(f"/transaction/verify/{reference}")
        return self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or Transaction,
        )

    def get_transactions(
        self,
        customer: int | str | None = None,
        start_date: str | None = None,
        end_date: str | None = None,
        status: TransactionStatus | None = None,
        page: int | None = None,
        amount: int | None = None,
        pagination: int = 50,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[list[Transaction]] | Response[PaystackDataModel]:
        """Fetch transactions carried out on your integration.

        Args:
            customer: Specify an ID for the customer whose transactions you want to retrieve
            start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            status: Filter transactions by status. any value from the ``TransactionStatus`` enum
            page: Specify exactly what page you want to retrieve.
                If not specified, we use a default value of 1.
            amount: Optional[int]
                Filter transactions by amount. Specify the amount (in kobo if currency is
                ``Currency.NGN``, pesewas, if currency is ``Currency.GHS``, and cents, if
                currency is ``Currency.ZAR``)
            pagination: Specifies how many records you want to retrieve per page. If not specified, we
                use a default value of 50.
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/?perPage={pagination}")
        query_params = [
            ("page", page),
            ("customer", customer),
            ("status", status),
            ("from", start_date),
            ("to", end_date),
            ("amount", amount),
        ]
        url = append_query_params(query_params, url)

        return self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or Transaction,
        )

    def get_transaction(
        self,
        id_: int | str,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[Transaction] | Response[PaystackDataModel]:
        """Get details of a transaction carried out on your integration.

        Args:
            id_: An ID for the transaction to fetch
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/{id_}/")
        return self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or Transaction,
        )

    def charge(
        self,
        amount: int,
        email: str,
        auth_code: str,
        reference: str | None = None,
        currency: Currency | None = None,
        metadata: dict[str, Any] | None = None,
        channels: list[Channel] | None = None,
        subaccount: str | None = None,
        transaction_charge: int | None = None,
        bearer: Bearer | None = None,
        queue: bool = False,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[Transaction] | Response[PaystackDataModel]:
        """
        All authorizations marked as reusable can be charged with this
        endpoint whenever you need to receive payments.

        Args:
            amount: amount to charge.
            email: Customer's email address
            auth_code: Valid authorization code to charge
            reference: Unique transaction reference. Only ``-, ., =`` and alphanumeric
                characters allowed.
            currency: Currency in which amount should be charged. Any value from the
                ``Currency`` enum.
            metadata: Add a custom_fields attribute which has an array of objects if
                you would like the fields to be added to your transaction when
                displayed on the dashboard.
                Sample: ``{"custom_fields":[{"display_name":"Cart ID",
                "variable_name": "cart_id","value": "8393"}]}``
            channels: A list of ``Channel`` enum values to control what channels you want to make available
                to the user to make a payment with
            subaccount: The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj
            transaction_charge: A flat fee to charge the subaccount for this transaction (in kobo if currency is NGN,
                pesewas, if currency is GHS, and cents, if currency is ZAR). This overrides the split
                percentage set when the subaccount was created. Ideally, you will need to use this if
                you are splitting in flat rates (since subaccount creation only allows for percentage split).
                e.g., 7000 for a 70 naira
            bearer: Who bears Paystack charges? any value from the ``Beaer`` enum
            queue: 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. Set ``queue=True`` to
                take advantage of our queued charging.
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        if not email:
            raise ValueError("Customer's Email is required to charge")

        if not auth_code:
            raise ValueError("Customer's Auth code is required to charge")

        url = self._full_url("/transaction/charge_authorization")
        payload = {
            "authorization_code": auth_code,
            "email": email,
            "amount": amount,
        }
        optional_params = [
            ("reference", reference),
            ("currency", currency),
            ("metadata", metadata),
            ("channels", channels),
            ("subaccount", subaccount),
            ("transaction_charge", transaction_charge),
            ("bearer", bearer),
            ("queue", queue),
        ]
        payload = add_to_payload(optional_params, payload)

        return self._handle_request(  # type: ignore
            HTTPMethod.POST,
            url,
            payload,
            response_data_model_class=alternate_model_class or Transaction,
        )

    def get_timeline(
        self,
        id_or_ref: int | str,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[TransactionLog] | Response[PaystackDataModel]:
        """View the timeline of a transaction

        Args:
            id_or_ref: The ID or the reference of the transaction
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/timeline/{id_or_ref}")
        return self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or TransactionLog,
        )

    def totals(
        self,
        page: int | None = None,
        start_date: str | None = None,
        end_date: str | None = None,
        pagination: int = 50,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[TransactionTotal] | Response[PaystackDataModel]:
        """Total amount received on your account

        Args:
            page: Specifies exactly what page you want to retrieve.
                If not specified, we use a default value of 1.
            start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            pagination: Specifies how many records you want to retrieve per page.
                If not specified, we use a default value of 50.
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/totals/?perPage={pagination}")
        query_params = [
            ("page", page),
            ("from", start_date),
            ("to", end_date),
        ]
        url = append_query_params(query_params, url)
        return self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or TransactionTotal,
        )

    def export(
        self,
        page: int | None = None,
        start_date: str | None = None,
        end_date: str | None = None,
        customer: str | int | None = None,
        status: TransactionStatus | None = None,
        currency: Currency | None = None,
        amount: int | None = None,
        settled: bool | None = None,
        settlement: str | None = None,
        payment_page: str | None = None,
        pagination: int = 50,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[TransactionExport] | Response[PaystackDataModel]:
        """Fetch transactions carried out on your integration.

        Args:
            page: Specifies exactly what page you want to retrieve.
                If not specified, we use a default value of 1.
            start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            customer: Specify an ID for the customer whose transactions you want to retrieve
            status: Filter transactions by status. Any value from the ``TransactionStatus`` enum
            currency: Specify the transaction currency to export. Any value from the ``Currency`` enum
            amount: Filter transactions by amount. Specify the amount, in
                kobo if currency is ``Currency.NGN``, pesewas, if currency
                is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
            settled: Set to ``True`` to export only settled transactions. ``False`` for
                pending transactions. Leave undefined to export all transaction
            settlement: An ID for the settlement whose transactions we should export
            payment_page: Optional[int]
                Specify a payment page's id to export only transactions conducted on said page
            pagination: int
                Specifies how many records you want to retrieve per page.
                If not specified, we use a default value of 50.
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/export/?perPage={pagination}")
        query_params = [
            ("page", page),
            ("from", start_date),
            ("to", end_date),
            ("customer", customer),
            ("status", status),
            ("currency", currency),
            ("amount", amount),
            ("settled", settled),
            ("settlement", settlement),
            ("payment_page", payment_page),
        ]
        url = append_query_params(query_params, url)
        return self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or TransactionExport,
        )

    def partial_debit(
        self,
        auth_code: str,
        currency: Currency,
        amount: int,
        email: str,
        reference: str | None = None,
        at_least: int | None = None,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[Transaction] | Response[PaystackDataModel]:
        """Retrieve part of a payment from a customer

        Args:
            auth_code: Authorization Code
            currency: Specify the currency you want to debit. Any value
                from the ``Currency`` enum.
            amount: Amount should be in kobo if currency is ``Currency.NGN``, pesewas,
                if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
            email: Customer's email address (attached to the authorization code)
            reference: Unique transaction reference. Only `-, ., =`
                 and alphanumeric characters allowed.
            at_least: Minimum amount to charge
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.

        Raises:
            InvalidDataError: When Customer's email is not provided. When Customer's auth code is not provided.
        """

        if not email:
            raise ValueError("Customer's Email is required to charge")

        if not auth_code:
            raise ValueError("Customer's Auth code is required to charge")

        url = self._full_url("/transaction/partial_debit")
        payload = {
            "authorization_code": auth_code,
            "currency": currency,
            "amount": amount,
            "email": email,
        }
        optional_params = [("reference", reference), ("at_least", at_least)]
        payload = add_to_payload(optional_params, payload)

        return self._handle_request(  # type: ignore
            HTTPMethod.POST,
            url,
            payload,
            response_data_model_class=alternate_model_class or Transaction,
        )

charge(amount, email, auth_code, reference=None, currency=None, metadata=None, channels=None, subaccount=None, transaction_charge=None, bearer=None, queue=False, alternate_model_class=None)

All authorizations marked as reusable can be charged with this endpoint whenever you need to receive payments.

Parameters:

Name Type Description Default
amount int

amount to charge.

required
email str

Customer's email address

required
auth_code str

Valid authorization code to charge

required
reference str | None

Unique transaction reference. Only -, ., = and alphanumeric characters allowed.

None
currency Currency | None

Currency in which amount should be charged. Any value from the Currency enum.

None
metadata dict[str, Any] | None

Add a custom_fields attribute which has an array of objects if you would like the fields to be added to your transaction when displayed on the dashboard. Sample: {"custom_fields":[{"display_name":"Cart ID", "variable_name": "cart_id","value": "8393"}]}

None
channels list[Channel] | None

A list of Channel enum values to control what channels you want to make available to the user to make a payment with

None
subaccount str | None

The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj

None
transaction_charge int | None

A flat fee to charge the subaccount for this transaction (in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR). This overrides the split percentage set when the subaccount was created. Ideally, you will need to use this if you are splitting in flat rates (since subaccount creation only allows for percentage split). e.g., 7000 for a 70 naira

None
bearer Bearer | None

Who bears Paystack charges? any value from the Beaer enum

None
queue bool

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. Set queue=True to take advantage of our queued charging.

False
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[Transaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
def charge(
    self,
    amount: int,
    email: str,
    auth_code: str,
    reference: str | None = None,
    currency: Currency | None = None,
    metadata: dict[str, Any] | None = None,
    channels: list[Channel] | None = None,
    subaccount: str | None = None,
    transaction_charge: int | None = None,
    bearer: Bearer | None = None,
    queue: bool = False,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[Transaction] | Response[PaystackDataModel]:
    """
    All authorizations marked as reusable can be charged with this
    endpoint whenever you need to receive payments.

    Args:
        amount: amount to charge.
        email: Customer's email address
        auth_code: Valid authorization code to charge
        reference: Unique transaction reference. Only ``-, ., =`` and alphanumeric
            characters allowed.
        currency: Currency in which amount should be charged. Any value from the
            ``Currency`` enum.
        metadata: Add a custom_fields attribute which has an array of objects if
            you would like the fields to be added to your transaction when
            displayed on the dashboard.
            Sample: ``{"custom_fields":[{"display_name":"Cart ID",
            "variable_name": "cart_id","value": "8393"}]}``
        channels: A list of ``Channel`` enum values to control what channels you want to make available
            to the user to make a payment with
        subaccount: The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj
        transaction_charge: A flat fee to charge the subaccount for this transaction (in kobo if currency is NGN,
            pesewas, if currency is GHS, and cents, if currency is ZAR). This overrides the split
            percentage set when the subaccount was created. Ideally, you will need to use this if
            you are splitting in flat rates (since subaccount creation only allows for percentage split).
            e.g., 7000 for a 70 naira
        bearer: Who bears Paystack charges? any value from the ``Beaer`` enum
        queue: 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. Set ``queue=True`` to
            take advantage of our queued charging.
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    if not email:
        raise ValueError("Customer's Email is required to charge")

    if not auth_code:
        raise ValueError("Customer's Auth code is required to charge")

    url = self._full_url("/transaction/charge_authorization")
    payload = {
        "authorization_code": auth_code,
        "email": email,
        "amount": amount,
    }
    optional_params = [
        ("reference", reference),
        ("currency", currency),
        ("metadata", metadata),
        ("channels", channels),
        ("subaccount", subaccount),
        ("transaction_charge", transaction_charge),
        ("bearer", bearer),
        ("queue", queue),
    ]
    payload = add_to_payload(optional_params, payload)

    return self._handle_request(  # type: ignore
        HTTPMethod.POST,
        url,
        payload,
        response_data_model_class=alternate_model_class or Transaction,
    )

export(page=None, start_date=None, end_date=None, customer=None, status=None, currency=None, amount=None, settled=None, settlement=None, payment_page=None, pagination=50, alternate_model_class=None)

Fetch transactions carried out on your integration.

Parameters:

Name Type Description Default
page int | None

Specifies exactly what page you want to retrieve. If not specified, we use a default value of 1.

None
start_date str | None

A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
end_date str | None

A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
customer str | int | None

Specify an ID for the customer whose transactions you want to retrieve

None
status TransactionStatus | None

Filter transactions by status. Any value from the TransactionStatus enum

None
currency Currency | None

Specify the transaction currency to export. Any value from the Currency enum

None
amount int | None

Filter transactions by amount. Specify the amount, in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR

None
settled bool | None

Set to True to export only settled transactions. False for pending transactions. Leave undefined to export all transaction

None
settlement str | None

An ID for the settlement whose transactions we should export

None
payment_page str | None

Optional[int] Specify a payment page's id to export only transactions conducted on said page

None
pagination int

int Specifies how many records you want to retrieve per page. If not specified, we use a default value of 50.

50
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[TransactionExport] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
def export(
    self,
    page: int | None = None,
    start_date: str | None = None,
    end_date: str | None = None,
    customer: str | int | None = None,
    status: TransactionStatus | None = None,
    currency: Currency | None = None,
    amount: int | None = None,
    settled: bool | None = None,
    settlement: str | None = None,
    payment_page: str | None = None,
    pagination: int = 50,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[TransactionExport] | Response[PaystackDataModel]:
    """Fetch transactions carried out on your integration.

    Args:
        page: Specifies exactly what page you want to retrieve.
            If not specified, we use a default value of 1.
        start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        customer: Specify an ID for the customer whose transactions you want to retrieve
        status: Filter transactions by status. Any value from the ``TransactionStatus`` enum
        currency: Specify the transaction currency to export. Any value from the ``Currency`` enum
        amount: Filter transactions by amount. Specify the amount, in
            kobo if currency is ``Currency.NGN``, pesewas, if currency
            is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
        settled: Set to ``True`` to export only settled transactions. ``False`` for
            pending transactions. Leave undefined to export all transaction
        settlement: An ID for the settlement whose transactions we should export
        payment_page: Optional[int]
            Specify a payment page's id to export only transactions conducted on said page
        pagination: int
            Specifies how many records you want to retrieve per page.
            If not specified, we use a default value of 50.
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/export/?perPage={pagination}")
    query_params = [
        ("page", page),
        ("from", start_date),
        ("to", end_date),
        ("customer", customer),
        ("status", status),
        ("currency", currency),
        ("amount", amount),
        ("settled", settled),
        ("settlement", settlement),
        ("payment_page", payment_page),
    ]
    url = append_query_params(query_params, url)
    return self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or TransactionExport,
    )

get_timeline(id_or_ref, alternate_model_class=None)

View the timeline of a transaction

Parameters:

Name Type Description Default
id_or_ref int | str

The ID or the reference of the transaction

required
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[TransactionLog] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
def get_timeline(
    self,
    id_or_ref: int | str,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[TransactionLog] | Response[PaystackDataModel]:
    """View the timeline of a transaction

    Args:
        id_or_ref: The ID or the reference of the transaction
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/timeline/{id_or_ref}")
    return self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or TransactionLog,
    )

get_transaction(id_, alternate_model_class=None)

Get details of a transaction carried out on your integration.

Parameters:

Name Type Description Default
id_ int | str

An ID for the transaction to fetch

required
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[Transaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
def get_transaction(
    self,
    id_: int | str,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[Transaction] | Response[PaystackDataModel]:
    """Get details of a transaction carried out on your integration.

    Args:
        id_: An ID for the transaction to fetch
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/{id_}/")
    return self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or Transaction,
    )

get_transactions(customer=None, start_date=None, end_date=None, status=None, page=None, amount=None, pagination=50, alternate_model_class=None)

Fetch transactions carried out on your integration.

Parameters:

Name Type Description Default
customer int | str | None

Specify an ID for the customer whose transactions you want to retrieve

None
start_date str | None

A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
end_date str | None

A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
status TransactionStatus | None

Filter transactions by status. any value from the TransactionStatus enum

None
page int | None

Specify exactly what page you want to retrieve. If not specified, we use a default value of 1.

None
amount int | None

Optional[int] Filter transactions by amount. Specify the amount (in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR)

None
pagination int

Specifies how many records you want to retrieve per page. If not specified, we use a default value of 50.

50
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[list[Transaction]] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
def get_transactions(
    self,
    customer: int | str | None = None,
    start_date: str | None = None,
    end_date: str | None = None,
    status: TransactionStatus | None = None,
    page: int | None = None,
    amount: int | None = None,
    pagination: int = 50,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[list[Transaction]] | Response[PaystackDataModel]:
    """Fetch transactions carried out on your integration.

    Args:
        customer: Specify an ID for the customer whose transactions you want to retrieve
        start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        status: Filter transactions by status. any value from the ``TransactionStatus`` enum
        page: Specify exactly what page you want to retrieve.
            If not specified, we use a default value of 1.
        amount: Optional[int]
            Filter transactions by amount. Specify the amount (in kobo if currency is
            ``Currency.NGN``, pesewas, if currency is ``Currency.GHS``, and cents, if
            currency is ``Currency.ZAR``)
        pagination: Specifies how many records you want to retrieve per page. If not specified, we
            use a default value of 50.
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/?perPage={pagination}")
    query_params = [
        ("page", page),
        ("customer", customer),
        ("status", status),
        ("from", start_date),
        ("to", end_date),
        ("amount", amount),
    ]
    url = append_query_params(query_params, url)

    return self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or Transaction,
    )

initialize(amount, email, currency=None, reference=None, callback_url=None, plan=None, invoice_limit=None, metadata=None, channels=None, split_code=None, subaccount=None, transfer_charge=None, bearer=None, alternate_model_class=None)

Initialize a transaction from your backend

Parameters:

Name Type Description Default
amount int

Amount should be in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR

required
email str

Customer's email address

required
currency Currency | None

Any value from the Currency enum.

None
reference str | None

Unique transaction reference. Only -, ., = and alphanumeric characters allowed.

None
callback_url str | None

Fully qualified url, e.g. https://example.com/ . Use this to override the callback url provided on the dashboard for this transaction

None
plan str | None

If transaction is to create a subscription to a predefined plan, provide plan code here. This would invalidate the value provided in amount

None
invoice_limit int | None

Number of times to charge customer during subscription to plan

None
metadata dict[str, Any] | None

A dictionary of additional info. check out this link for more information. https://paystack.com/docs/payments/metadata

None
channels list[Channel] | None

A list of Channel enum values to control what channels you want to make available to the user to make a payment with

None
split_code str | None

The split code of the transaction split. e.g. SPL_98WF13Eb3w

None
subaccount str | None

The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj

None
transfer_charge int | None

An amount used to override the split configuration for a single split payment. If set, the amount specified goes to the main account regardless of the split configuration.

None
bearer Bearer | None

Any value from the Bearer enum. Who bears Paystack charges?

None
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[InitTransaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Raises:

Type Description
InvalidDataError

When email is not provided.

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
def initialize(
    self,
    amount: int,
    email: str,
    currency: Currency | None = None,
    reference: str | None = None,
    callback_url: str | None = None,
    plan: str | None = None,
    invoice_limit: int | None = None,
    metadata: dict[str, Any] | None = None,
    channels: list[Channel] | None = None,
    split_code: str | None = None,
    subaccount: str | None = None,
    transfer_charge: int | None = None,
    bearer: Bearer | None = None,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[InitTransaction] | Response[PaystackDataModel]:
    """Initialize a transaction from your backend

    Args:
        amount: Amount should be in kobo if currency is ``Currency.NGN``, pesewas,
            if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
        email: Customer's email address
        currency: Any value from the ``Currency`` enum.
        reference: Unique transaction reference. Only ``-, ., =`` and alphanumeric characters allowed.
        callback_url: Fully qualified url, e.g. ``https://example.com/`` . Use this to override the callback url
            provided on the dashboard for this transaction
        plan: If transaction is to create a subscription to a predefined plan, provide plan code here.
            This would invalidate the value provided in ``amount``
        invoice_limit: Number of times to charge customer during subscription to plan
        metadata: A dictionary of additional info. check out this link
            for more information. https://paystack.com/docs/payments/metadata
        channels: A list of ``Channel`` enum values to control what channels you want to make available
            to the user to make a payment with
        split_code: The split code of the transaction split. e.g. SPL_98WF13Eb3w
        subaccount: The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj
        transfer_charge: An amount used to override the split configuration for a single split payment. If set,
            the amount specified goes to the main account regardless of the split configuration.
        bearer: Any value from the ``Bearer`` enum. Who bears Paystack charges?
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.

    Raises:
        InvalidDataError: When email is not provided.
    """

    if not email:
        raise ValueError("Customer's Email is required for initialization")

    url = self._full_url("/transaction/initialize")
    payload = {
        "email": email,
        "amount": amount,
    }

    optional_params = [
        ("currency", currency),
        ("reference", reference),
        ("callback_url", callback_url),
        ("plan", plan),
        ("invoice_limit", invoice_limit),
        ("metadata", metadata),
        ("channels", channels),
        ("split_code", split_code),
        ("subaccount", subaccount),
        ("transfer_charge", transfer_charge),
        ("bearer", bearer),
    ]
    payload = add_to_payload(optional_params, payload)

    return self._handle_request(  # type: ignore
        HTTPMethod.POST,
        url,
        payload,
        response_data_model_class=alternate_model_class or InitTransaction,
    )

partial_debit(auth_code, currency, amount, email, reference=None, at_least=None, alternate_model_class=None)

Retrieve part of a payment from a customer

Parameters:

Name Type Description Default
auth_code str

Authorization Code

required
currency Currency

Specify the currency you want to debit. Any value from the Currency enum.

required
amount int

Amount should be in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR

required
email str

Customer's email address (attached to the authorization code)

required
reference str | None

Unique transaction reference. Only -, ., = and alphanumeric characters allowed.

None
at_least int | None

Minimum amount to charge

None
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[Transaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Raises:

Type Description
InvalidDataError

When Customer's email is not provided. When Customer's auth code is not provided.

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
def partial_debit(
    self,
    auth_code: str,
    currency: Currency,
    amount: int,
    email: str,
    reference: str | None = None,
    at_least: int | None = None,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[Transaction] | Response[PaystackDataModel]:
    """Retrieve part of a payment from a customer

    Args:
        auth_code: Authorization Code
        currency: Specify the currency you want to debit. Any value
            from the ``Currency`` enum.
        amount: Amount should be in kobo if currency is ``Currency.NGN``, pesewas,
            if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
        email: Customer's email address (attached to the authorization code)
        reference: Unique transaction reference. Only `-, ., =`
             and alphanumeric characters allowed.
        at_least: Minimum amount to charge
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.

    Raises:
        InvalidDataError: When Customer's email is not provided. When Customer's auth code is not provided.
    """

    if not email:
        raise ValueError("Customer's Email is required to charge")

    if not auth_code:
        raise ValueError("Customer's Auth code is required to charge")

    url = self._full_url("/transaction/partial_debit")
    payload = {
        "authorization_code": auth_code,
        "currency": currency,
        "amount": amount,
        "email": email,
    }
    optional_params = [("reference", reference), ("at_least", at_least)]
    payload = add_to_payload(optional_params, payload)

    return self._handle_request(  # type: ignore
        HTTPMethod.POST,
        url,
        payload,
        response_data_model_class=alternate_model_class or Transaction,
    )

totals(page=None, start_date=None, end_date=None, pagination=50, alternate_model_class=None)

Total amount received on your account

Parameters:

Name Type Description Default
page int | None

Specifies exactly what page you want to retrieve. If not specified, we use a default value of 1.

None
start_date str | None

A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
end_date str | None

A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
pagination int

Specifies how many records you want to retrieve per page. If not specified, we use a default value of 50.

50
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[TransactionTotal] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
def totals(
    self,
    page: int | None = None,
    start_date: str | None = None,
    end_date: str | None = None,
    pagination: int = 50,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[TransactionTotal] | Response[PaystackDataModel]:
    """Total amount received on your account

    Args:
        page: Specifies exactly what page you want to retrieve.
            If not specified, we use a default value of 1.
        start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        pagination: Specifies how many records you want to retrieve per page.
            If not specified, we use a default value of 50.
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/totals/?perPage={pagination}")
    query_params = [
        ("page", page),
        ("from", start_date),
        ("to", end_date),
    ]
    url = append_query_params(query_params, url)
    return self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or TransactionTotal,
    )

verify(reference, alternate_model_class=None)

Confirm the status of a transaction

Parameters:

Name Type Description Default
reference str

The transaction reference used to initiate the transaction

required
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[Transaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/sync_clients/transactions.py
def verify(
    self,
    reference: str,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[Transaction] | Response[PaystackDataModel]:
    """Confirm the status of a transaction

    Args:
        reference: The transaction reference used to initiate the transaction
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    reference = str(reference)
    url = self._full_url(f"/transaction/verify/{reference}")
    return self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or Transaction,
    )

AsyncTransactionClient

Bases: BaseAsyncAPIClient

Provides a wrapper for paystack Transactions API

The Transactions API allows you to create and manage payments on your integration. https://paystack.com/docs/api/transaction/

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
class AsyncTransactionClient(BaseAsyncAPIClient):
    """Provides a wrapper for paystack Transactions API

    The Transactions API allows you to create and manage payments on your integration.
    https://paystack.com/docs/api/transaction/
    """

    async def initialize(
        self,
        amount: int,
        email: str,
        currency: Currency | None = None,
        reference: str | None = None,
        callback_url: str | None = None,
        plan: str | None = None,
        invoice_limit: int | None = None,
        metadata: dict[str, Any] | None = None,
        channels: list[Channel] | None = None,
        split_code: str | None = None,
        subaccount: str | None = None,
        transfer_charge: int | None = None,
        bearer: Bearer | None = None,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[InitTransaction] | Response[PaystackDataModel]:
        """Initialize a transaction from your backend

        Args:
            amount: Amount should be in kobo if currency is ``Currency.NGN``, pesewas,
                if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
            email: Customer's email address
            currency: Any value from the ``Currency`` enum.
            reference: Unique transaction reference. Only ``-, ., =`` and alphanumeric characters allowed.
            callback_url: Fully qualified url, e.g. ``https://example.com/`` . Use this to override the callback url
                provided on the dashboard for this transaction
            plan: If transaction is to create a subscription to a predefined plan, provide plan code here.
                This would invalidate the value provided in ``amount``
            invoice_limit: Number of times to charge customer during subscription to plan
            metadata: A dictionary of additional info. check out this link
                for more information. https://paystack.com/docs/payments/metadata
            channels: A list of ``Channel`` enum values to control what channels you want to make available
                to the user to make a payment with
            split_code: The split code of the transaction split. e.g. SPL_98WF13Eb3w
            subaccount: The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj
            transfer_charge: An amount used to override the split configuration for a single split payment. If set,
                the amount specified goes to the main account regardless of the split configuration.
            bearer: Any value from the ``Bearer`` enum. Who bears Paystack charges?
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.

        Raises:
            InvalidDataError: When email is not provided.
        """

        if not email:
            raise ValueError("Customer's Email is required for initialization")

        url = self._full_url("/transaction/initialize")
        payload = {
            "email": email,
            "amount": amount,
        }

        optional_params = [
            ("currency", currency),
            ("reference", reference),
            ("callback_url", callback_url),
            ("plan", plan),
            ("invoice_limit", invoice_limit),
            ("metadata", metadata),
            ("channels", channels),
            ("split_code", split_code),
            ("subaccount", subaccount),
            ("transfer_charge", transfer_charge),
            ("bearer", bearer),
        ]
        payload = add_to_payload(
            optional_params,
            payload,
        )

        return await self._handle_request(
            HTTPMethod.POST,
            url,
            payload,  # type: ignore
            response_data_model_class=alternate_model_class or InitTransaction,
        )

    async def verify(
        self,
        reference: str,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[Transaction] | Response[PaystackDataModel]:
        """Confirm the status of a transaction

        Args:
            reference: The transaction reference used to initiate the transaction
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        reference = str(reference)
        url = self._full_url(f"/transaction/verify/{reference}")
        return await self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or Transaction,
        )

    async def get_transactions(
        self,
        customer: int | str | None = None,
        start_date: str | None = None,
        end_date: str | None = None,
        status: TransactionStatus | None = None,
        page: int | None = None,
        amount: int | None = None,
        pagination: int = 50,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[list[Transaction]] | Response[PaystackDataModel]:
        """Fetch transactions carried out on your integration.

        Args:
            customer: Specify an ID for the customer whose transactions you want to retrieve
            start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            status: Filter transactions by status. any value from the ``TransactionStatus`` enum
            page: Specify exactly what page you want to retrieve.
                If not specified, we use a default value of 1.
            amount: Optional[int]
                Filter transactions by amount. Specify the amount (in kobo if currency is
                ``Currency.NGN``, pesewas, if currency is ``Currency.GHS``, and cents, if
                currency is ``Currency.ZAR``)
            pagination: Specifies how many records you want to retrieve per page. If not specified, we
                use a default value of 50.
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/?perPage={pagination}")
        query_params = [
            ("page", page),
            ("customer", customer),
            ("status", status),
            ("from", start_date),
            ("to", end_date),
            ("amount", amount),
        ]
        url = append_query_params(query_params, url)

        return await self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or Transaction,
        )

    async def get_transaction(
        self,
        id_: str,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[Transaction] | Response[PaystackDataModel]:
        """Get details of a transaction carried out on your integration.

        Args:
            id_: An ID for the transaction to fetch
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/{id_}/")
        return await self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or Transaction,
        )

    async def charge(
        self,
        amount: int,
        email: str,
        auth_code: str,
        reference: str | None = None,
        currency: Currency | None = None,
        metadata: dict[str, Any] | None = None,
        channels: list[Channel] | None = None,
        subaccount: str | None = None,
        transaction_charge: int | None = None,
        bearer: Bearer | None = None,
        queue: bool = False,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[Transaction] | Response[PaystackDataModel]:
        """
        All authorizations marked as reusable can be charged with this
        endpoint whenever you need to receive payments.

        Args:
            amount: amount to charge.
            email: Customer's email address
            auth_code: Valid authorization code to charge
            reference: Unique transaction reference. Only ``-, ., =`` and alphanumeric
                characters allowed.
            currency: Currency in which amount should be charged. Any value from the
                ``Currency`` enum.
            metadata: Add a custom_fields attribute which has an array of objects if
                you would like the fields to be added to your transaction when
                displayed on the dashboard.
                Sample: ``{"custom_fields":[{"display_name":"Cart ID",
                "variable_name": "cart_id","value": "8393"}]}``
            channels: A list of ``Channel`` enum values to control what channels you want to make available
                to the user to make a payment with
            subaccount: The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj
            transaction_charge: A flat fee to charge the subaccount for this transaction (in kobo if currency is NGN,
                pesewas, if currency is GHS, and cents, if currency is ZAR). This overrides the split
                percentage set when the subaccount was created. Ideally, you will need to use this if
                you are splitting in flat rates (since subaccount creation only allows for percentage split).
                e.g., 7000 for a 70 naira
            bearer: Who bears Paystack charges? any value from the ``Beaer`` enum
            queue: 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. Set ``queue=True`` to
                take advantage of our queued charging.
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        if not email:
            raise ValueError("Customer's Email is required to charge")

        if not auth_code:
            raise ValueError("Customer's Auth code is required to charge")

        url = self._full_url("/transaction/charge_authorization")
        payload = {
            "authorization_code": auth_code,
            "email": email,
            "amount": amount,
        }
        optional_params = [
            ("reference", reference),
            ("currency", currency),
            ("metadata", metadata),
            ("channels", channels),
            ("subaccount", subaccount),
            ("transaction_charge", transaction_charge),
            ("bearer", bearer),
            ("queue", queue),
        ]
        payload = add_to_payload(optional_params, payload)

        return await self._handle_request(  # type: ignore
            HTTPMethod.POST,
            url,
            payload,
            response_data_model_class=alternate_model_class or Transaction,
        )

    async def get_timeline(
        self,
        id_or_ref: int | str,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[TransactionLog] | Response[PaystackDataModel]:
        """View the timeline of a transaction

        Args:
            id_or_ref: The ID or the reference of the transaction
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/timeline/{id_or_ref}")
        return await self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or TransactionLog,
        )

    async def totals(
        self,
        page: int | None = None,
        start_date: str | None = None,
        end_date: str | None = None,
        pagination: int = 50,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[TransactionTotal] | Response[PaystackDataModel]:
        """Total amount received on your account

        Args:
            page: Specifies exactly what page you want to retrieve.
                If not specified, we use a default value of 1.
            start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            pagination: Specifies how many records you want to retrieve per page.
                If not specified, we use a default value of 50.
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/totals/?perPage={pagination}")
        query_params = [
            ("page", page),
            ("from", start_date),
            ("to", end_date),
        ]
        url = append_query_params(query_params, url)
        return await self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or TransactionTotal,
        )

    async def export(
        self,
        page: int | None = None,
        start_date: str | None = None,
        end_date: str | None = None,
        customer: str | int | None = None,
        status: TransactionStatus | None = None,
        currency: Currency | None = None,
        amount: int | None = None,
        settled: bool | None = None,
        settlement: str | None = None,
        payment_page: str | None = None,
        pagination: int = 50,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[TransactionExport] | Response[PaystackDataModel]:
        """Fetch transactions carried out on your integration.

        Args:
            page: Specifies exactly what page you want to retrieve.
                If not specified, we use a default value of 1.
            start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
            customer: Specify an ID for the customer whose transactions you want to retrieve
            status: Filter transactions by status. Any value from the ``TransactionStatus`` enum
            currency: Specify the transaction currency to export. Any value from the ``Currency`` enum
            amount: Filter transactions by amount. Specify the amount, in
                kobo if currency is ``Currency.NGN``, pesewas, if currency
                is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
            settled: Set to ``True`` to export only settled transactions. ``False`` for
                pending transactions. Leave undefined to export all transaction
            settlement: An ID for the settlement whose transactions we should export
            payment_page: Optional[int]
                Specify a payment page's id to export only transactions conducted on said page
            pagination: int
                Specifies how many records you want to retrieve per page.
                If not specified, we use a default value of 50.
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.
        """

        url = self._full_url(f"/transaction/export/?perPage={pagination}")
        query_params = [
            ("page", page),
            ("from", start_date),
            ("to", end_date),
            ("customer", customer),
            ("status", status),
            ("currency", currency),
            ("amount", amount),
            ("settled", settled),
            ("settlement", settlement),
            ("payment_page", payment_page),
        ]
        url = append_query_params(query_params, url)
        return await self._handle_request(  # type: ignore
            HTTPMethod.GET,
            url,
            response_data_model_class=alternate_model_class or TransactionExport,
        )

    async def partial_debit(
        self,
        auth_code: str,
        currency: Currency,
        amount: int,
        email: str,
        reference: str | None = None,
        at_least: int | None = None,
        alternate_model_class: type[PaystackDataModel] | None = None,
    ) -> Response[Transaction] | Response[PaystackDataModel]:
        """Retrieve part of a payment from a customer

        Args:
            auth_code: Authorization Code
            currency: Specify the currency you want to debit. Any value
                from the ``Currency`` enum.
            amount: Amount should be in kobo if currency is ``Currency.NGN``, pesewas,
                if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
            email: Customer's email address (attached to the authorization code)
            reference: Unique transaction reference. Only `-, ., =`
                 and alphanumeric characters allowed.
            at_least: Minimum amount to charge
            alternate_model_class: A pydantic model class to use instead of the
                default pydantic model used by the library to present the data in
                the `Response.data`. The default behaviour of the library is to
                set  `Response.data` to `None` if it fails to serialize the data
                returned from paystack with the model provided in the library.
                Providing a pydantic model class via this parameter overrides
                the library default model with the model class you provide.
                This can come in handy when the models in the library do not
                accurately represent the data returned, and you prefer working with the
                data as a pydantic model instead of as a dict of the response returned
                by  paystack before it is serialized with pydantic models, The original
                data can be accessed via `Response.raw`.

        Returns:
            A pydantic model containing the response gotten from paystack's server.

        Raises:
            InvalidDataError: When Customer's email is not provided. When Customer's auth code is not provided.
        """

        if not email:
            raise ValueError("Customer's Email is required to charge")

        if not auth_code:
            raise ValueError("Customer's Auth code is required to charge")

        url = self._full_url("/transaction/partial_debit")
        payload = {
            "authorization_code": auth_code,
            "currency": currency,
            "amount": amount,
            "email": email,
        }
        optional_params = [("reference", reference), ("at_least", at_least)]
        payload = add_to_payload(optional_params, payload)

        return await self._handle_request(  # type: ignore
            HTTPMethod.POST,
            url,
            payload,
            response_data_model_class=alternate_model_class or Transaction,
        )

charge(amount, email, auth_code, reference=None, currency=None, metadata=None, channels=None, subaccount=None, transaction_charge=None, bearer=None, queue=False, alternate_model_class=None) async

All authorizations marked as reusable can be charged with this endpoint whenever you need to receive payments.

Parameters:

Name Type Description Default
amount int

amount to charge.

required
email str

Customer's email address

required
auth_code str

Valid authorization code to charge

required
reference str | None

Unique transaction reference. Only -, ., = and alphanumeric characters allowed.

None
currency Currency | None

Currency in which amount should be charged. Any value from the Currency enum.

None
metadata dict[str, Any] | None

Add a custom_fields attribute which has an array of objects if you would like the fields to be added to your transaction when displayed on the dashboard. Sample: {"custom_fields":[{"display_name":"Cart ID", "variable_name": "cart_id","value": "8393"}]}

None
channels list[Channel] | None

A list of Channel enum values to control what channels you want to make available to the user to make a payment with

None
subaccount str | None

The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj

None
transaction_charge int | None

A flat fee to charge the subaccount for this transaction (in kobo if currency is NGN, pesewas, if currency is GHS, and cents, if currency is ZAR). This overrides the split percentage set when the subaccount was created. Ideally, you will need to use this if you are splitting in flat rates (since subaccount creation only allows for percentage split). e.g., 7000 for a 70 naira

None
bearer Bearer | None

Who bears Paystack charges? any value from the Beaer enum

None
queue bool

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. Set queue=True to take advantage of our queued charging.

False
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[Transaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
async def charge(
    self,
    amount: int,
    email: str,
    auth_code: str,
    reference: str | None = None,
    currency: Currency | None = None,
    metadata: dict[str, Any] | None = None,
    channels: list[Channel] | None = None,
    subaccount: str | None = None,
    transaction_charge: int | None = None,
    bearer: Bearer | None = None,
    queue: bool = False,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[Transaction] | Response[PaystackDataModel]:
    """
    All authorizations marked as reusable can be charged with this
    endpoint whenever you need to receive payments.

    Args:
        amount: amount to charge.
        email: Customer's email address
        auth_code: Valid authorization code to charge
        reference: Unique transaction reference. Only ``-, ., =`` and alphanumeric
            characters allowed.
        currency: Currency in which amount should be charged. Any value from the
            ``Currency`` enum.
        metadata: Add a custom_fields attribute which has an array of objects if
            you would like the fields to be added to your transaction when
            displayed on the dashboard.
            Sample: ``{"custom_fields":[{"display_name":"Cart ID",
            "variable_name": "cart_id","value": "8393"}]}``
        channels: A list of ``Channel`` enum values to control what channels you want to make available
            to the user to make a payment with
        subaccount: The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj
        transaction_charge: A flat fee to charge the subaccount for this transaction (in kobo if currency is NGN,
            pesewas, if currency is GHS, and cents, if currency is ZAR). This overrides the split
            percentage set when the subaccount was created. Ideally, you will need to use this if
            you are splitting in flat rates (since subaccount creation only allows for percentage split).
            e.g., 7000 for a 70 naira
        bearer: Who bears Paystack charges? any value from the ``Beaer`` enum
        queue: 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. Set ``queue=True`` to
            take advantage of our queued charging.
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    if not email:
        raise ValueError("Customer's Email is required to charge")

    if not auth_code:
        raise ValueError("Customer's Auth code is required to charge")

    url = self._full_url("/transaction/charge_authorization")
    payload = {
        "authorization_code": auth_code,
        "email": email,
        "amount": amount,
    }
    optional_params = [
        ("reference", reference),
        ("currency", currency),
        ("metadata", metadata),
        ("channels", channels),
        ("subaccount", subaccount),
        ("transaction_charge", transaction_charge),
        ("bearer", bearer),
        ("queue", queue),
    ]
    payload = add_to_payload(optional_params, payload)

    return await self._handle_request(  # type: ignore
        HTTPMethod.POST,
        url,
        payload,
        response_data_model_class=alternate_model_class or Transaction,
    )

export(page=None, start_date=None, end_date=None, customer=None, status=None, currency=None, amount=None, settled=None, settlement=None, payment_page=None, pagination=50, alternate_model_class=None) async

Fetch transactions carried out on your integration.

Parameters:

Name Type Description Default
page int | None

Specifies exactly what page you want to retrieve. If not specified, we use a default value of 1.

None
start_date str | None

A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
end_date str | None

A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
customer str | int | None

Specify an ID for the customer whose transactions you want to retrieve

None
status TransactionStatus | None

Filter transactions by status. Any value from the TransactionStatus enum

None
currency Currency | None

Specify the transaction currency to export. Any value from the Currency enum

None
amount int | None

Filter transactions by amount. Specify the amount, in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR

None
settled bool | None

Set to True to export only settled transactions. False for pending transactions. Leave undefined to export all transaction

None
settlement str | None

An ID for the settlement whose transactions we should export

None
payment_page str | None

Optional[int] Specify a payment page's id to export only transactions conducted on said page

None
pagination int

int Specifies how many records you want to retrieve per page. If not specified, we use a default value of 50.

50
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[TransactionExport] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
async def export(
    self,
    page: int | None = None,
    start_date: str | None = None,
    end_date: str | None = None,
    customer: str | int | None = None,
    status: TransactionStatus | None = None,
    currency: Currency | None = None,
    amount: int | None = None,
    settled: bool | None = None,
    settlement: str | None = None,
    payment_page: str | None = None,
    pagination: int = 50,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[TransactionExport] | Response[PaystackDataModel]:
    """Fetch transactions carried out on your integration.

    Args:
        page: Specifies exactly what page you want to retrieve.
            If not specified, we use a default value of 1.
        start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        customer: Specify an ID for the customer whose transactions you want to retrieve
        status: Filter transactions by status. Any value from the ``TransactionStatus`` enum
        currency: Specify the transaction currency to export. Any value from the ``Currency`` enum
        amount: Filter transactions by amount. Specify the amount, in
            kobo if currency is ``Currency.NGN``, pesewas, if currency
            is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
        settled: Set to ``True`` to export only settled transactions. ``False`` for
            pending transactions. Leave undefined to export all transaction
        settlement: An ID for the settlement whose transactions we should export
        payment_page: Optional[int]
            Specify a payment page's id to export only transactions conducted on said page
        pagination: int
            Specifies how many records you want to retrieve per page.
            If not specified, we use a default value of 50.
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/export/?perPage={pagination}")
    query_params = [
        ("page", page),
        ("from", start_date),
        ("to", end_date),
        ("customer", customer),
        ("status", status),
        ("currency", currency),
        ("amount", amount),
        ("settled", settled),
        ("settlement", settlement),
        ("payment_page", payment_page),
    ]
    url = append_query_params(query_params, url)
    return await self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or TransactionExport,
    )

get_timeline(id_or_ref, alternate_model_class=None) async

View the timeline of a transaction

Parameters:

Name Type Description Default
id_or_ref int | str

The ID or the reference of the transaction

required
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[TransactionLog] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
async def get_timeline(
    self,
    id_or_ref: int | str,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[TransactionLog] | Response[PaystackDataModel]:
    """View the timeline of a transaction

    Args:
        id_or_ref: The ID or the reference of the transaction
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/timeline/{id_or_ref}")
    return await self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or TransactionLog,
    )

get_transaction(id_, alternate_model_class=None) async

Get details of a transaction carried out on your integration.

Parameters:

Name Type Description Default
id_ str

An ID for the transaction to fetch

required
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[Transaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
async def get_transaction(
    self,
    id_: str,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[Transaction] | Response[PaystackDataModel]:
    """Get details of a transaction carried out on your integration.

    Args:
        id_: An ID for the transaction to fetch
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/{id_}/")
    return await self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or Transaction,
    )

get_transactions(customer=None, start_date=None, end_date=None, status=None, page=None, amount=None, pagination=50, alternate_model_class=None) async

Fetch transactions carried out on your integration.

Parameters:

Name Type Description Default
customer int | str | None

Specify an ID for the customer whose transactions you want to retrieve

None
start_date str | None

A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
end_date str | None

A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
status TransactionStatus | None

Filter transactions by status. any value from the TransactionStatus enum

None
page int | None

Specify exactly what page you want to retrieve. If not specified, we use a default value of 1.

None
amount int | None

Optional[int] Filter transactions by amount. Specify the amount (in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR)

None
pagination int

Specifies how many records you want to retrieve per page. If not specified, we use a default value of 50.

50
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[list[Transaction]] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
async def get_transactions(
    self,
    customer: int | str | None = None,
    start_date: str | None = None,
    end_date: str | None = None,
    status: TransactionStatus | None = None,
    page: int | None = None,
    amount: int | None = None,
    pagination: int = 50,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[list[Transaction]] | Response[PaystackDataModel]:
    """Fetch transactions carried out on your integration.

    Args:
        customer: Specify an ID for the customer whose transactions you want to retrieve
        start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        status: Filter transactions by status. any value from the ``TransactionStatus`` enum
        page: Specify exactly what page you want to retrieve.
            If not specified, we use a default value of 1.
        amount: Optional[int]
            Filter transactions by amount. Specify the amount (in kobo if currency is
            ``Currency.NGN``, pesewas, if currency is ``Currency.GHS``, and cents, if
            currency is ``Currency.ZAR``)
        pagination: Specifies how many records you want to retrieve per page. If not specified, we
            use a default value of 50.
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/?perPage={pagination}")
    query_params = [
        ("page", page),
        ("customer", customer),
        ("status", status),
        ("from", start_date),
        ("to", end_date),
        ("amount", amount),
    ]
    url = append_query_params(query_params, url)

    return await self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or Transaction,
    )

initialize(amount, email, currency=None, reference=None, callback_url=None, plan=None, invoice_limit=None, metadata=None, channels=None, split_code=None, subaccount=None, transfer_charge=None, bearer=None, alternate_model_class=None) async

Initialize a transaction from your backend

Parameters:

Name Type Description Default
amount int

Amount should be in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR

required
email str

Customer's email address

required
currency Currency | None

Any value from the Currency enum.

None
reference str | None

Unique transaction reference. Only -, ., = and alphanumeric characters allowed.

None
callback_url str | None

Fully qualified url, e.g. https://example.com/ . Use this to override the callback url provided on the dashboard for this transaction

None
plan str | None

If transaction is to create a subscription to a predefined plan, provide plan code here. This would invalidate the value provided in amount

None
invoice_limit int | None

Number of times to charge customer during subscription to plan

None
metadata dict[str, Any] | None

A dictionary of additional info. check out this link for more information. https://paystack.com/docs/payments/metadata

None
channels list[Channel] | None

A list of Channel enum values to control what channels you want to make available to the user to make a payment with

None
split_code str | None

The split code of the transaction split. e.g. SPL_98WF13Eb3w

None
subaccount str | None

The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj

None
transfer_charge int | None

An amount used to override the split configuration for a single split payment. If set, the amount specified goes to the main account regardless of the split configuration.

None
bearer Bearer | None

Any value from the Bearer enum. Who bears Paystack charges?

None
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[InitTransaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Raises:

Type Description
InvalidDataError

When email is not provided.

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
async def initialize(
    self,
    amount: int,
    email: str,
    currency: Currency | None = None,
    reference: str | None = None,
    callback_url: str | None = None,
    plan: str | None = None,
    invoice_limit: int | None = None,
    metadata: dict[str, Any] | None = None,
    channels: list[Channel] | None = None,
    split_code: str | None = None,
    subaccount: str | None = None,
    transfer_charge: int | None = None,
    bearer: Bearer | None = None,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[InitTransaction] | Response[PaystackDataModel]:
    """Initialize a transaction from your backend

    Args:
        amount: Amount should be in kobo if currency is ``Currency.NGN``, pesewas,
            if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
        email: Customer's email address
        currency: Any value from the ``Currency`` enum.
        reference: Unique transaction reference. Only ``-, ., =`` and alphanumeric characters allowed.
        callback_url: Fully qualified url, e.g. ``https://example.com/`` . Use this to override the callback url
            provided on the dashboard for this transaction
        plan: If transaction is to create a subscription to a predefined plan, provide plan code here.
            This would invalidate the value provided in ``amount``
        invoice_limit: Number of times to charge customer during subscription to plan
        metadata: A dictionary of additional info. check out this link
            for more information. https://paystack.com/docs/payments/metadata
        channels: A list of ``Channel`` enum values to control what channels you want to make available
            to the user to make a payment with
        split_code: The split code of the transaction split. e.g. SPL_98WF13Eb3w
        subaccount: The code for the subaccount that owns the payment. e.g. ACCT_8f4s1eq7ml6rlzj
        transfer_charge: An amount used to override the split configuration for a single split payment. If set,
            the amount specified goes to the main account regardless of the split configuration.
        bearer: Any value from the ``Bearer`` enum. Who bears Paystack charges?
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.

    Raises:
        InvalidDataError: When email is not provided.
    """

    if not email:
        raise ValueError("Customer's Email is required for initialization")

    url = self._full_url("/transaction/initialize")
    payload = {
        "email": email,
        "amount": amount,
    }

    optional_params = [
        ("currency", currency),
        ("reference", reference),
        ("callback_url", callback_url),
        ("plan", plan),
        ("invoice_limit", invoice_limit),
        ("metadata", metadata),
        ("channels", channels),
        ("split_code", split_code),
        ("subaccount", subaccount),
        ("transfer_charge", transfer_charge),
        ("bearer", bearer),
    ]
    payload = add_to_payload(
        optional_params,
        payload,
    )

    return await self._handle_request(
        HTTPMethod.POST,
        url,
        payload,  # type: ignore
        response_data_model_class=alternate_model_class or InitTransaction,
    )

partial_debit(auth_code, currency, amount, email, reference=None, at_least=None, alternate_model_class=None) async

Retrieve part of a payment from a customer

Parameters:

Name Type Description Default
auth_code str

Authorization Code

required
currency Currency

Specify the currency you want to debit. Any value from the Currency enum.

required
amount int

Amount should be in kobo if currency is Currency.NGN, pesewas, if currency is Currency.GHS, and cents, if currency is Currency.ZAR

required
email str

Customer's email address (attached to the authorization code)

required
reference str | None

Unique transaction reference. Only -, ., = and alphanumeric characters allowed.

None
at_least int | None

Minimum amount to charge

None
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[Transaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Raises:

Type Description
InvalidDataError

When Customer's email is not provided. When Customer's auth code is not provided.

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
async def partial_debit(
    self,
    auth_code: str,
    currency: Currency,
    amount: int,
    email: str,
    reference: str | None = None,
    at_least: int | None = None,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[Transaction] | Response[PaystackDataModel]:
    """Retrieve part of a payment from a customer

    Args:
        auth_code: Authorization Code
        currency: Specify the currency you want to debit. Any value
            from the ``Currency`` enum.
        amount: Amount should be in kobo if currency is ``Currency.NGN``, pesewas,
            if currency is ``Currency.GHS``, and cents, if currency is ``Currency.ZAR``
        email: Customer's email address (attached to the authorization code)
        reference: Unique transaction reference. Only `-, ., =`
             and alphanumeric characters allowed.
        at_least: Minimum amount to charge
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.

    Raises:
        InvalidDataError: When Customer's email is not provided. When Customer's auth code is not provided.
    """

    if not email:
        raise ValueError("Customer's Email is required to charge")

    if not auth_code:
        raise ValueError("Customer's Auth code is required to charge")

    url = self._full_url("/transaction/partial_debit")
    payload = {
        "authorization_code": auth_code,
        "currency": currency,
        "amount": amount,
        "email": email,
    }
    optional_params = [("reference", reference), ("at_least", at_least)]
    payload = add_to_payload(optional_params, payload)

    return await self._handle_request(  # type: ignore
        HTTPMethod.POST,
        url,
        payload,
        response_data_model_class=alternate_model_class or Transaction,
    )

totals(page=None, start_date=None, end_date=None, pagination=50, alternate_model_class=None) async

Total amount received on your account

Parameters:

Name Type Description Default
page int | None

Specifies exactly what page you want to retrieve. If not specified, we use a default value of 1.

None
start_date str | None

A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
end_date str | None

A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21

None
pagination int

Specifies how many records you want to retrieve per page. If not specified, we use a default value of 50.

50
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[TransactionTotal] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
async def totals(
    self,
    page: int | None = None,
    start_date: str | None = None,
    end_date: str | None = None,
    pagination: int = 50,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[TransactionTotal] | Response[PaystackDataModel]:
    """Total amount received on your account

    Args:
        page: Specifies exactly what page you want to retrieve.
            If not specified, we use a default value of 1.
        start_date: A timestamp from which to start listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        end_date: A timestamp at which to stop listing transaction e.g. 2016-09-24T00:00:05.000Z, 2016-09-21
        pagination: Specifies how many records you want to retrieve per page.
            If not specified, we use a default value of 50.
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    url = self._full_url(f"/transaction/totals/?perPage={pagination}")
    query_params = [
        ("page", page),
        ("from", start_date),
        ("to", end_date),
    ]
    url = append_query_params(query_params, url)
    return await self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or TransactionTotal,
    )

verify(reference, alternate_model_class=None) async

Confirm the status of a transaction

Parameters:

Name Type Description Default
reference str

The transaction reference used to initiate the transaction

required
alternate_model_class type[PaystackDataModel] | None

A pydantic model class to use instead of the default pydantic model used by the library to present the data in the Response.data. The default behaviour of the library is to set Response.data to None if it fails to serialize the data returned from paystack with the model provided in the library. Providing a pydantic model class via this parameter overrides the library default model with the model class you provide. This can come in handy when the models in the library do not accurately represent the data returned, and you prefer working with the data as a pydantic model instead of as a dict of the response returned by paystack before it is serialized with pydantic models, The original data can be accessed via Response.raw.

None

Returns:

Type Description
Response[Transaction] | Response[PaystackDataModel]

A pydantic model containing the response gotten from paystack's server.

Source code in src/pypaystack2/sub_clients/async_clients/transactions.py
async def verify(
    self,
    reference: str,
    alternate_model_class: type[PaystackDataModel] | None = None,
) -> Response[Transaction] | Response[PaystackDataModel]:
    """Confirm the status of a transaction

    Args:
        reference: The transaction reference used to initiate the transaction
        alternate_model_class: A pydantic model class to use instead of the
            default pydantic model used by the library to present the data in
            the `Response.data`. The default behaviour of the library is to
            set  `Response.data` to `None` if it fails to serialize the data
            returned from paystack with the model provided in the library.
            Providing a pydantic model class via this parameter overrides
            the library default model with the model class you provide.
            This can come in handy when the models in the library do not
            accurately represent the data returned, and you prefer working with the
            data as a pydantic model instead of as a dict of the response returned
            by  paystack before it is serialized with pydantic models, The original
            data can be accessed via `Response.raw`.

    Returns:
        A pydantic model containing the response gotten from paystack's server.
    """

    reference = str(reference)
    url = self._full_url(f"/transaction/verify/{reference}")
    return await self._handle_request(  # type: ignore
        HTTPMethod.GET,
        url,
        response_data_model_class=alternate_model_class or Transaction,
    )