Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions paystackease/apis/sync_apis/Model_bulkcharge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pydantic import BaseModel

class BulkChargeItem(BaseModel):
authorization: str # A string for the authorization code
amount: int # An integer for the amount
reference: str # A string for the reference
42 changes: 24 additions & 18 deletions paystackease/apis/sync_apis/bulk_charges.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,36 @@

from paystackease.core import PayStackResponse, SyncRequestAPI
from paystackease.helpers import STATUS


class BulkChargesClientAPI(SyncRequestAPI):
"""
Paystack Bulk Charges API
Reference: https://paystack.com/docs/api/bulk-charge/
"""

def initiate_bulk_charge(self, objects: List[Dict[str, Any]]) -> PayStackResponse:
from paystackease.apis.sync_apis.Model_bulkcharge import BulkChargeItem
class BulkChargesSyncAPI:

def __init__(self):
# Initialize the class if needed (e.g., for API authentication)
pass

def initiate_bulk_charge(self, objects: Union[List[Dict[str, Any]], List[BulkChargeItem]]) -> PayStackResponse:
"""
Send an array of objects with authorization codes and amount

:param: objects

note::

A list of dictionary with authorization codes, amount and reference as keys
[{"authorization": "123456", "amount": 1000, "reference": "123456" }]
Initiates a bulk charge with a list of authorization codes, amounts, and references.

:param objects: A list of BulkChargeItem instances or dictionaries
:return: The PayStackResponse from the API
:rtype: PayStackResponse object
"""
if not objects:
raise ValueError("Objects parameter cannot be empty")

if isinstance(objects[0], BulkChargeItem):
# If the input is a list of BulkChargeItem instances, convert them to dictionaries
objects = [item.dict() for item in objects] # Convert Pydantic models to dictionaries
elif isinstance(objects[0], dict):
# If the input is already a list of dictionaries, no conversion is needed
pass
else:
raise ValueError("Input must be a list of dictionaries or BulkChargeItem instances.")

# Send the request to the Paystack API
return self._post_request("/bulkcharge", data=objects)


def list_bulk_charge_batches(
self,
per_page: Optional[Union[int, None]] = 50,
Expand Down
Loading