Bulk Charges Module
This wrapper class facilitates synchronous interaction with Paystack Bulk Charges API. The Bulk Charges API allows you to create and manage multiple recurring payments from your customers.
To access the Bulk Charges API methods, you need to call the bulk_charges instance method from PayStackBase.
- class BulkChargesClientAPI(secret_key: str = None)
Paystack Bulk Charges API Reference: Bulk Charges
- fetch_bulk_charge_batch(id_or_code: str)→ PayStackResponse
Fetch a bulk charge of a specific batch
- Parameters:
id_or_code (str) – An ID or code for the charge whose batches you want to retrieve.
- Returns:
The response from the API.
- Return type:
PayStackResponse object
- fetch_charge_bulk_batch(id_or_code: str, status: str | None = None, per_page: int | None = 50, page: int | None = 1, from_date: date | None = None, to_date: date | None = None)→ PayStackResponse
Fetch a bulk charge of a specific batch
- Parameters:
id_or_code (str) – An ID or code for the charge whose batches you want to retrieve
status (str, optional) – The status of the bulk charge batch. The
STATUSenum value is passed in here.per_page (int, optional) – The number of records to return per page (default: 50).
page (int, optional) – The page to return (default: 1).
from_date (date, optional) – The starting date of the bulk charge batch.
to_date (date, optional) – The ending date of the bulk charge batch.
- Returns:
The response from the API.
- Return type:
PayStackResponse object
- initiate_bulk_charge(objects: BulkChargeListObject)→ PayStackResponse
Initiate a bulk charge
- Parameters:
objects (BulkChargeListObject) – An array of objects with authorization, amount and reference.
- Returns:
The response from the API.
- Return type:
PayStackResponse object
- list_bulk_charge_batches(per_page: int | None = 50, page: int | None = 1, from_date: date | None = None, to_date: date | None = None)→ PayStackResponse
List bulk charge batches
- Parameters:
per_page (int, optional) – The number of records to return per page (default: 50).
page (int, optional) – The page to return (default: 1).
from_date (date, optional) – The starting date of the bulk charge batch.
to_date (date, optional) – The ending date of the bulk charge batch.
- Returns:
The response from the API.
- Return type:
PayStackResponse object
- pause_bulk_charge_batch(batch_code: str)→ PayStackResponse
Pause a bulk charge of a specific batch
- Parameters:
batch_code (str) – The code of the bulk charge batch you want to pause.
- Returns:
The response from the API.
- Return type:
PayStackResponse object
- resume_bulk_charge_batch(batch_code: str)→ PayStackResponse
Resume a bulk charge of a specific batch
- Parameters:
batch_code (str) – The code of the bulk charge batch you want to resume.
- Returns:
The response from the API
- Return type:
PayStackResponse object
When passing the status parameter, you can pass the string value of the
STATUS enum member as the type hint is a string, as seen:
>>> from paystackease import STATUS
>>> status = STATUS.PENDING.value
>>> print(status)
$ python
>>> 'pending'
In initiating a bulk charge, either use BulkChargeItem as a base pydantic data class or BulkChargeListObject class.
The attributes in BulkChargeItem are: authorization, amount and reference.
The attribute in BulkChargeListObject is charges.
You can initiate multiple bulk charge at the same time also. The authorization is gotten after a successful card transaction.
The reference is a unique set of characters you can create as your desired choice.
You can also check to ensure that the amount passed into is in subunit. See the documentation on Convert module.
For example
>>> from paystackease import PayStackBase, BulkChargeListObject
>>> paystack_client = PayStackBase()
>>> valid_data = {
"charges": [
{ "authorization": "AUTH_test1234", "amount": 10000, "reference": "test1234" },
{ "authorization": "AUTH_tester4176", "amount": 2000, "reference": "tester1234" },
]
}
data = BulkChargeListObject(**valid_data)
>>> response = paystack_client.bulk_charges.initiate_bulk_charge(objects=data)
>>> print(response)