Skip to content

Pypaystack2 Package Reference

This is the package-level documentation for the pypaystack2 package.

The pypaystack2 package provides clients for interacting with Paystack's API in your python project it provides PaystackClient and AsyncPaystackClient. The former for working in synchronous contexts and the latter for working in asynchronous contexts. These two classes are considered the main clients and provide bindings to other sub-clients as class attributes. E.g. PaystackClient.apple_pay

Subpackages
  • pypaystack2.sub_clients: A package containing clients for interacting with specific Paystack's API
  • pypaystack2.models: A package containing pydantic model representations of payload and response data the individual models may also be referred to as generic type called PaystackDataModel which serves as a placeholder for the models.
Module
  • pypaystack2.enum: A module containing enums used package wide.

Example usage:

from pypaystack2 import PaystackClient
from pypaystack2.enums import Country

client = PaystackClient() # Assumes your secret key is set in your environmental variables
# as PAYSTACK_SECRET_KEY. you may also choose to pass the secret key explicitly on instantiation
# of the client. `client = PaystackClient(secret_key='<your-secret-key>')`

# Initializing a transaction
response = client.transactions.initialize(amount=10_000,email="johndoe@example.com")
print(repr(response))

# Get banks
response = client.miscellaneous.get_banks(country=Country.NIGERIA)
print(repr(response))

For more details, refer to the documentation.

AsyncPaystackClient

Bases: BaseAsyncAPIClient

An asynchronous Paystack API client class with all the sub clients supported by pypaystack2.

This class has all the individual sub clients classes like AsyncApplePayClient, AsyncBulkChargeClient as bindings to it.

Attributes:

Name Type Description
apple_pay

A binding to AsyncApplePayClient providing methods for interacting Paystack's Apple Pay API e.g. PaystackClient.apple_pay.get_domains.

bulk_charges

A binding to AsyncBulkChargeClient providing methods for interacting Paystack's Bulk charge API e.g. PaystackClient.bulk_charges.initiate.

charge

A binding to AsyncChargeClient providing methods for interacting Paystack's Charge API e.g. PaystackClient.charge.charge.

integration

A binding to AsyncIntegrationClient providing methods for interacting Paystack's Integration API e.g. PaystackClient.integration.get_payment_session_timeout.

customers

A binding to AsyncCustomerClient providing methods for interacting Paystack's Customer API e.g. PaystackClient.customers.create.

dedicated_accounts

A binding to AsyncDedicatedAccountClient providing methods for interacting Paystack's Dedicated account API e.g. PaystackClient.dedicated_accounts.create.

disputes

A binding to AsyncDisputeClient providing methods for interacting Paystack's Dispute API e.g. PaystackClient.disputes..

payment_requests

A binding to AsyncPaymentRequestClient providing methods for interacting Paystack's Payment request API e.g. PaystackClient.payment_requests.create.

miscellaneous

A binding to AsyncApplePayClient providing methods for interacting Paystack's Apple Pay API e.g. PaystackClient.miscellaneous.get_banks.

payment_pages

A binding to AsyncPaymentPageClient providing methods for interacting Paystack's Payment Page API e.g. PaystackClient.payment_pages.create.

plans

A binding to AsyncPlanClient providing methods for interacting Paystack's Plan API e.g. PaystackClient.plans.get_plans.

products

A binding to AsyncProductClient providing methods for interacting Paystack's Product API e.g. PaystackClient.products.get_product.

refunds

A binding to AsyncRefundClient providing methods for interacting Paystack's Refund API e.g. PaystackClient.refunds.create.

settlements

A binding to AsyncSettlementClient providing methods for interacting Paystack's Settlement API e.g. PaystackClient.settlements.get_settlements.

splits

A binding to AsyncTransactionSplitClient providing methods for interacting Paystack's Transaction split API e.g. PaystackClient.splits.create.

subaccounts

A binding to AsyncSubAccountClient providing methods for interacting Paystack's subaccount API e.g. PaystackClient.subaccounts.create.

subscriptions

A binding to AsyncSubscriptionClient providing methods for interacting Paystack's Subscription API e.g. PaystackClient.subscriptions.create.

terminals

A binding to AsyncTerminalClient providing methods for interacting Paystack's Terminal API e.g. PaystackClient.terminals.send_event.

transactions

A binding to AsyncTransactionClient providing methods for interacting Paystack's Transaction API e.g. PaystackClient.transactions.initiate.

transfer_recipients

A binding to AsyncTransferRecipientClient providing methods for interacting Paystack's Transfer recipients API e.g. PaystackClient.transfer_recipients.create.

transfers

A binding to AsyncTransferClient providing methods for interacting Paystack's Transfer API e.g. PaystackClient.transfers.finalize.

transfer_control

A binding to AsyncTransferControlClient providing methods for interacting Paystack's Transfers control API e.g. PaystackClient.transfer_control.check_balance.

verification

A binding to AsyncVerificationClient providing methods for interacting Paystack's Verification API e.g. PaystackClient.verification.resolve_account_number.

Source code in src/pypaystack2/main_clients.py
class AsyncPaystackClient(BaseAsyncAPIClient):
    """An asynchronous Paystack API client class with all the sub clients supported by pypaystack2.

    This class has all the individual sub clients classes like `AsyncApplePayClient`, `AsyncBulkChargeClient`
    as bindings to it.

    Attributes:
        apple_pay: A binding to `AsyncApplePayClient` providing methods for interacting Paystack's Apple Pay API
            e.g. `PaystackClient.apple_pay.get_domains`.
        bulk_charges: A binding to `AsyncBulkChargeClient` providing methods for interacting Paystack's Bulk charge API
            e.g. `PaystackClient.bulk_charges.initiate`.
        charge: A binding to `AsyncChargeClient` providing methods for interacting Paystack's Charge API
            e.g. `PaystackClient.charge.charge`.
        integration: A binding to `AsyncIntegrationClient` providing methods for interacting Paystack's Integration API
            e.g. `PaystackClient.integration.get_payment_session_timeout`.
        customers: A binding to `AsyncCustomerClient` providing methods for interacting Paystack's Customer API
            e.g. `PaystackClient.customers.create`.
        dedicated_accounts: A binding to `AsyncDedicatedAccountClient` providing methods for interacting
            Paystack's Dedicated account API e.g. `PaystackClient.dedicated_accounts.create`.
        disputes: A binding to `AsyncDisputeClient` providing methods for interacting Paystack's Dispute API
            e.g. `PaystackClient.disputes.`.
        payment_requests: A binding to `AsyncPaymentRequestClient` providing methods for interacting Paystack's Payment
            request API e.g. `PaystackClient.payment_requests.create`.
        miscellaneous: A binding to `AsyncApplePayClient` providing methods for interacting Paystack's Apple Pay API
            e.g. `PaystackClient.miscellaneous.get_banks`.
        payment_pages: A binding to `AsyncPaymentPageClient` providing methods for interacting Paystack's Payment Page
            API e.g. `PaystackClient.payment_pages.create`.
        plans: A binding to `AsyncPlanClient` providing methods for interacting Paystack's Plan API
            e.g. `PaystackClient.plans.get_plans`.
        products: A binding to `AsyncProductClient` providing methods for interacting Paystack's Product API
            e.g. `PaystackClient.products.get_product`.
        refunds: A binding to `AsyncRefundClient` providing methods for interacting Paystack's Refund API
            e.g. `PaystackClient.refunds.create`.
        settlements: A binding to `AsyncSettlementClient` providing methods for interacting Paystack's Settlement API
            e.g. `PaystackClient.settlements.get_settlements`.
        splits: A binding to `AsyncTransactionSplitClient` providing methods for interacting Paystack's Transaction
            split API e.g. `PaystackClient.splits.create`.
        subaccounts: A binding to `AsyncSubAccountClient` providing methods for interacting Paystack's subaccount API
            e.g. `PaystackClient.subaccounts.create`.
        subscriptions: A binding to `AsyncSubscriptionClient` providing methods for interacting Paystack's Subscription
            API e.g. `PaystackClient.subscriptions.create`.
        terminals: A binding to `AsyncTerminalClient` providing methods for interacting Paystack's Terminal API
            e.g. `PaystackClient.terminals.send_event`.
        transactions: A binding to `AsyncTransactionClient` providing methods for interacting Paystack's Transaction
            API e.g. `PaystackClient.transactions.initiate`.
        transfer_recipients: A binding to `AsyncTransferRecipientClient` providing methods for interacting Paystack's
            Transfer recipients API e.g. `PaystackClient.transfer_recipients.create`.
        transfers: A binding to `AsyncTransferClient` providing methods for interacting Paystack's Transfer API
            e.g. `PaystackClient.transfers.finalize`.
        transfer_control: A binding to `AsyncTransferControlClient` providing methods for interacting Paystack's
            Transfers control API e.g. `PaystackClient.transfer_control.check_balance`.
        verification: A binding to `AsyncVerificationClient` providing methods for interacting Paystack's Verification
            API e.g. `PaystackClient.verification.resolve_account_number`.
    """

    def __init__(self, secret_key: str | None = None):
        super().__init__(secret_key=secret_key)
        self.apple_pay = AsyncApplePayClient(secret_key=self._secret_key)
        self.bulk_charges = AsyncBulkChargeClient(secret_key=self._secret_key)
        self.charge = AsyncChargeClient(secret_key=self._secret_key)
        self.integration = AsyncIntegrationClient(secret_key=self._secret_key)
        self.customers = AsyncCustomerClient(secret_key=self._secret_key)
        self.dedicated_accounts = AsyncDedicatedAccountClient(
            secret_key=self._secret_key
        )
        self.disputes = AsyncDisputeClient(secret_key=self._secret_key)
        self.payment_requests = AsyncPaymentRequestClient(secret_key=self._secret_key)
        self.miscellaneous = AsyncMiscellaneousClient(secret_key=self._secret_key)
        self.payment_pages = AsyncPaymentPageClient(secret_key=self._secret_key)
        self.plans = AsyncPlanClient(secret_key=self._secret_key)
        self.products = AsyncProductClient(secret_key=self._secret_key)
        self.refunds = AsyncRefundClient(secret_key=self._secret_key)
        self.settlements = AsyncSettlementClient(secret_key=self._secret_key)
        self.splits = AsyncTransactionSplitClient(secret_key=self._secret_key)
        self.subaccounts = AsyncSubAccountClient(secret_key=self._secret_key)
        self.subscriptions = AsyncSubscriptionClient(secret_key=self._secret_key)
        self.terminals = AsyncTerminalClient(secret_key=self._secret_key)
        self.transactions = AsyncTransactionClient(secret_key=self._secret_key)
        self.transfer_recipients = AsyncTransferRecipientClient(
            secret_key=self._secret_key
        )
        self.transfers = AsyncTransferClient(secret_key=self._secret_key)
        self.transfer_control = AsyncTransferControlClient(secret_key=self._secret_key)
        self.verification = AsyncVerificationClient(secret_key=self._secret_key)

PaystackClient

Bases: BaseAPIClient

A Paystack API client class with all the sub clients supported by pypaystack2.

This class has all the individual sub clients classes like ApplePayClient, BulkChargeClient as bindings to it.

Attributes:

Name Type Description
apple_pay ApplePayClient

A binding to ApplePayClient providing methods for interacting Paystack's Apple Pay API e.g. PaystackClient.apple_pay.get_domains.

bulk_charges BulkChargeClient

A binding to BulkChargeClient providing methods for interacting Paystack's Bulk charge API e.g. PaystackClient.bulk_charges.initiate.

charge ChargeClient

A binding to ChargeClient providing methods for interacting Paystack's Charge API e.g. PaystackClient.charge.charge.

integration IntegrationClient

A binding to IntegrationClient providing methods for interacting Paystack's Integration API e.g. PaystackClient.integration.get_payment_session_timeout.

customers CustomerClient

A binding to CustomerClient providing methods for interacting Paystack's Customer API e.g. PaystackClient.customers.create.

dedicated_accounts DedicatedAccountClient

A binding to DedicatedAccountClient providing methods for interacting Paystack's Dedicated account API e.g. PaystackClient.dedicated_accounts.create.

disputes DisputeClient

A binding to DisputeClient providing methods for interacting Paystack's Dispute API e.g. PaystackClient.disputes..

payment_requests PaymentRequestClient

A binding to PaymentRequestClient providing methods for interacting Paystack's Payment request API e.g. PaystackClient.payment_requests.create.

miscellaneous MiscellaneousClient

A binding to ApplePayClient providing methods for interacting Paystack's Apple Pay API e.g. PaystackClient.miscellaneous.get_banks.

payment_pages PaymentPageClient

A binding to PaymentPageClient providing methods for interacting Paystack's Payment Page API e.g. PaystackClient.payment_pages.create.

plans PlanClient

A binding to PlanClient providing methods for interacting Paystack's Plan API e.g. PaystackClient.plans.get_plans.

products ProductClient

A binding to ProductClient providing methods for interacting Paystack's Product API e.g. PaystackClient.products.get_product.

refunds RefundClient

A binding to RefundClient providing methods for interacting Paystack's Refund API e.g. PaystackClient.refunds.create.

settlements SettlementClient

A binding to SettlementClient providing methods for interacting Paystack's Settlement API e.g. PaystackClient.settlements.get_settlements.

splits TransactionSplitClient

A binding to TransactionSplitClient providing methods for interacting Paystack's Transaction split API e.g. PaystackClient.splits.create.

subaccounts SubAccountClient

A binding to SubAccountClient providing methods for interacting Paystack's subaccount API e.g. PaystackClient.subaccounts.create.

subscriptions SubscriptionClient

A binding to SubscriptionClient providing methods for interacting Paystack's Subscription API e.g. PaystackClient.subscriptions.create.

terminals TerminalClient

A binding to TerminalClient providing methods for interacting Paystack's Terminal API e.g. PaystackClient.terminals.send_event.

transactions TransactionClient

A binding to TransactionClient providing methods for interacting Paystack's Transaction API e.g. PaystackClient.transactions.initiate.

transfer_recipients TransferRecipientClient

A binding to TransferRecipientClient providing methods for interacting Paystack's Transfer recipients API e.g. PaystackClient.transfer_recipients.create.

transfers TransferClient

A binding to TransferClient providing methods for interacting Paystack's Transfer API e.g. PaystackClient.transfers.finalize.

transfer_control TransferControlClient

A binding to TransferControlClient providing methods for interacting Paystack's Transfers control API e.g. PaystackClient.transfer_control.check_balance.

verification VerificationClient

A binding to VerificationClient providing methods for interacting Paystack's Verification API e.g. PaystackClient.verification.resolve_account_number.

Source code in src/pypaystack2/main_clients.py
class PaystackClient(BaseAPIClient):
    """A Paystack API client class with all the sub clients supported by pypaystack2.

    This class has all the individual sub clients classes like `ApplePayClient`, `BulkChargeClient`
    as bindings to it.

    Attributes:
        apple_pay: A binding to `ApplePayClient` providing methods for interacting Paystack's Apple Pay API
            e.g. `PaystackClient.apple_pay.get_domains`.
        bulk_charges: A binding to `BulkChargeClient` providing methods for interacting Paystack's Bulk charge API
            e.g. `PaystackClient.bulk_charges.initiate`.
        charge: A binding to `ChargeClient` providing methods for interacting Paystack's Charge API
            e.g. `PaystackClient.charge.charge`.
        integration: A binding to `IntegrationClient` providing methods for interacting Paystack's Integration API
            e.g. `PaystackClient.integration.get_payment_session_timeout`.
        customers: A binding to `CustomerClient` providing methods for interacting Paystack's Customer API
            e.g. `PaystackClient.customers.create`.
        dedicated_accounts: A binding to `DedicatedAccountClient` providing methods for interacting
            Paystack's Dedicated account API e.g. `PaystackClient.dedicated_accounts.create`.
        disputes: A binding to `DisputeClient` providing methods for interacting Paystack's Dispute API
            e.g. `PaystackClient.disputes.`.
        payment_requests: A binding to `PaymentRequestClient` providing methods for interacting Paystack's Payment
            request API e.g. `PaystackClient.payment_requests.create`.
        miscellaneous: A binding to `ApplePayClient` providing methods for interacting Paystack's Apple Pay API
            e.g. `PaystackClient.miscellaneous.get_banks`.
        payment_pages: A binding to `PaymentPageClient` providing methods for interacting Paystack's Payment Page API
            e.g. `PaystackClient.payment_pages.create`.
        plans: A binding to `PlanClient` providing methods for interacting Paystack's Plan API
            e.g. `PaystackClient.plans.get_plans`.
        products: A binding to `ProductClient` providing methods for interacting Paystack's Product API
            e.g. `PaystackClient.products.get_product`.
        refunds: A binding to `RefundClient` providing methods for interacting Paystack's Refund API
            e.g. `PaystackClient.refunds.create`.
        settlements: A binding to `SettlementClient` providing methods for interacting Paystack's Settlement API
            e.g. `PaystackClient.settlements.get_settlements`.
        splits: A binding to `TransactionSplitClient` providing methods for interacting Paystack's Transaction split API
            e.g. `PaystackClient.splits.create`.
        subaccounts: A binding to `SubAccountClient` providing methods for interacting Paystack's subaccount API
            e.g. `PaystackClient.subaccounts.create`.
        subscriptions: A binding to `SubscriptionClient` providing methods for interacting Paystack's Subscription API
            e.g. `PaystackClient.subscriptions.create`.
        terminals: A binding to `TerminalClient` providing methods for interacting Paystack's Terminal API
            e.g. `PaystackClient.terminals.send_event`.
        transactions: A binding to `TransactionClient` providing methods for interacting Paystack's Transaction API
            e.g. `PaystackClient.transactions.initiate`.
        transfer_recipients: A binding to `TransferRecipientClient` providing methods for interacting Paystack's
            Transfer recipients API e.g. `PaystackClient.transfer_recipients.create`.
        transfers: A binding to `TransferClient` providing methods for interacting Paystack's Transfer API
            e.g. `PaystackClient.transfers.finalize`.
        transfer_control: A binding to `TransferControlClient` providing methods for interacting Paystack's
            Transfers control API e.g. `PaystackClient.transfer_control.check_balance`.
        verification: A binding to `VerificationClient` providing methods for interacting Paystack's Verification API
            e.g. `PaystackClient.verification.resolve_account_number`.
    """

    def __init__(self, secret_key: str | None = None):
        super().__init__(secret_key=secret_key)
        self.apple_pay: ApplePayClient = ApplePayClient(secret_key=self._secret_key)
        self.bulk_charges: BulkChargeClient = BulkChargeClient(
            secret_key=self._secret_key
        )
        self.charge: ChargeClient = ChargeClient(secret_key=self._secret_key)
        self.integration: IntegrationClient = IntegrationClient(
            secret_key=self._secret_key
        )
        self.customers: CustomerClient = CustomerClient(secret_key=self._secret_key)
        self.dedicated_accounts: DedicatedAccountClient = DedicatedAccountClient(
            secret_key=self._secret_key
        )
        self.disputes: DisputeClient = DisputeClient(secret_key=self._secret_key)
        self.payment_requests: PaymentRequestClient = PaymentRequestClient(
            secret_key=self._secret_key
        )
        self.miscellaneous: MiscellaneousClient = MiscellaneousClient(
            secret_key=self._secret_key
        )
        self.payment_pages: PaymentPageClient = PaymentPageClient(
            secret_key=self._secret_key
        )
        self.plans: PlanClient = PlanClient(secret_key=self._secret_key)
        self.products: ProductClient = ProductClient(secret_key=self._secret_key)
        self.refunds: RefundClient = RefundClient(secret_key=self._secret_key)
        self.settlements: SettlementClient = SettlementClient(
            secret_key=self._secret_key
        )
        self.splits: TransactionSplitClient = TransactionSplitClient(
            secret_key=self._secret_key
        )
        self.subaccounts: SubAccountClient = SubAccountClient(
            secret_key=self._secret_key
        )
        self.subscriptions: SubscriptionClient = SubscriptionClient(
            secret_key=self._secret_key
        )
        self.terminals: TerminalClient = TerminalClient(secret_key=self._secret_key)
        self.transactions: TransactionClient = TransactionClient(
            secret_key=self._secret_key
        )
        self.transfer_recipients: TransferRecipientClient = TransferRecipientClient(
            secret_key=self._secret_key
        )
        self.transfers: TransferClient = TransferClient(secret_key=self._secret_key)
        self.transfer_control: TransferControlClient = TransferControlClient(
            secret_key=self._secret_key
        )
        self.verification: VerificationClient = VerificationClient(
            secret_key=self._secret_key
        )

sub-clients pypaystack2.sub_clients

pypaystack2.enums

AccountType

Bases: StrEnum

Enum of Account types supported by paystack

Source code in src/pypaystack2/enums.py
class AccountType(StrEnum):
    """Enum of Account types supported by paystack"""

    PERSONAL = "personal"
    BUSINESS = "business"

BankType

Bases: StrEnum

Enum of bank types

Source code in src/pypaystack2/enums.py
class BankType(StrEnum):
    """Enum of bank types"""

    GHIPPS = "ghipps"
    MOBILE_MONEY = "mobile_money"

Bearer

Bases: StrEnum

Enum for who bears paystack charges

Source code in src/pypaystack2/enums.py
class Bearer(StrEnum):
    """Enum for who bears paystack charges"""

    ACCOUNT = "account"
    SUB_ACCOUNT = "subaccount"
    ALL_PROPORTIONAL = "all-proportional"
    ALL = "all"

Channel

Bases: StrEnum

Enum of payment channels supported by paystack

Source code in src/pypaystack2/enums.py
class Channel(StrEnum):
    """Enum of payment channels supported by paystack"""

    CARD = "card"
    BANK = "bank"
    USSD = "ussd"
    QR = "qr"
    MOBILE_MONEY = "mobile_money"
    BANK_TRANSFER = "bank_transfer"

Country

Bases: StrEnum

Enum of countries supported by paystack

Source code in src/pypaystack2/enums.py
class Country(StrEnum):
    """Enum of countries supported by paystack"""

    NIGERIA = "NG"
    GHANA = "GH"
    SOUTH_AFRICA = "ZA"
    KENYA = "KE"
    COTE_D_IVOIRE = "CI"
    EGYPT = "EG"
    RWANDA = "RW"

    @staticmethod
    def get_full(value: str) -> str | None:
        """Returns paystack supported country name in full lowercase

        Args:
            value: The two-digit iso name of the country.

        Returns:
            The name of the country in lowercase if it is supported by
            paystack or none.
        """
        value = value.lower()
        return {
            "ng": "nigeria",
            "gh": "ghana",
            "za": "south africa",
            "ke": "kenya",
            "ci": "côte d'ivoire",
            "eg": "egypt",
            "rw": "rwanda",
        }.get(value)

get_full(value) staticmethod

Returns paystack supported country name in full lowercase

Parameters:

Name Type Description Default
value str

The two-digit iso name of the country.

required

Returns:

Type Description
str | None

The name of the country in lowercase if it is supported by

str | None

paystack or none.

Source code in src/pypaystack2/enums.py
@staticmethod
def get_full(value: str) -> str | None:
    """Returns paystack supported country name in full lowercase

    Args:
        value: The two-digit iso name of the country.

    Returns:
        The name of the country in lowercase if it is supported by
        paystack or none.
    """
    value = value.lower()
    return {
        "ng": "nigeria",
        "gh": "ghana",
        "za": "south africa",
        "ke": "kenya",
        "ci": "côte d'ivoire",
        "eg": "egypt",
        "rw": "rwanda",
    }.get(value)

Currency

Bases: StrEnum

Enum of currencies supported by paystack.

Source code in src/pypaystack2/enums.py
class Currency(StrEnum):
    """Enum of currencies supported by paystack."""

    NGN = "NGN"
    GHS = "GHS"
    ZAR = "ZAR"
    USD = "USD"
    KES = "KES"
    XOF = "XOF"
    EGP = "EGP"
    RWF = "RWF"

DisputeStatus

Bases: StrEnum

Enum of dispute status supported by paystack

Source code in src/pypaystack2/enums.py
class DisputeStatus(StrEnum):
    """Enum of dispute status supported by paystack"""

    PENDING = "pending"
    RESOLVED = "resolved"
    AWAITING_BANK_FEEDBACK = "awaiting-bank-feedback"
    AWAITING_MERCHANT_FEEDBACK = "awaiting-merchant-feedback"
    ARCHIVED = "archived"

Document

Bases: StrEnum

Enum of Document types supported by paystack

Source code in src/pypaystack2/enums.py
class Document(StrEnum):
    """Enum of Document types supported by paystack"""

    IDENTITY_NUMBER = "identityNumber"
    PASSPORT_NUMBER = "passportNumber"
    BUSINESS_REGISTRATION_NUMBER = "businessRegistrationNumber"

Gateway

Bases: StrEnum

Enum of bank gateways supported by paystack

Source code in src/pypaystack2/enums.py
class Gateway(StrEnum):
    """Enum of bank gateways supported by paystack"""

    EMANDATE = "emandate"
    DIGITALBANKMANDATE = "digitalbankmandate"

Identification

Bases: StrEnum

Enum of Identification methods supported by paystack

Source code in src/pypaystack2/enums.py
class Identification(StrEnum):
    """Enum of Identification methods supported by paystack"""

    BVN = "bvn"
    BANK_ACCOUNT = "bank_account"

Interval

Bases: StrEnum

Enum of intervals supported by paystack.

Source code in src/pypaystack2/enums.py
class Interval(StrEnum):
    """Enum of intervals supported by paystack."""

    HOURLY = "hourly"
    DAILY = "daily"
    WEEKLY = "weekly"
    MONTHLY = "monthly"
    QUARTERLY = "quarterly"
    BIANNUALLY = "biannually"
    ANNUALLY = "annually"

Reason

Bases: StrEnum

Enum of Reset OTP options

Source code in src/pypaystack2/enums.py
class Reason(StrEnum):
    """Enum of Reset OTP options"""

    RESEND_OTP = "resend_otp"
    TRANSFER = "transfer"
    DISABLE_OTP = "disable_otp"

RecipientType

Bases: StrEnum

Enum of Transfer Recipient types

Source code in src/pypaystack2/enums.py
class RecipientType(StrEnum):
    """Enum of Transfer Recipient types"""

    NUBAN = "nuban"
    MOBILE_MONEY = "mobile_money"
    BASA = "basa"

Resolution

Bases: StrEnum

Enum of Resolutions supported by paystack

Source code in src/pypaystack2/enums.py
class Resolution(StrEnum):
    """Enum of Resolutions supported by paystack"""

    MERCHANT_ACCEPTED = "merchant-accepted"
    DECLINED = "declined"

RiskAction

Bases: StrEnum

Enum of RiskActions supported by paystack

Source code in src/pypaystack2/enums.py
class RiskAction(StrEnum):
    """Enum of RiskActions supported by paystack"""

    DEFAULT = "default"
    WHITELIST = "allow"
    BLACKLIST = "deny"

Schedule

Bases: StrEnum

Enum of settlement schedules supported by paystack

Source code in src/pypaystack2/enums.py
class Schedule(StrEnum):
    """Enum of settlement schedules supported by paystack"""

    AUTO = "auto"
    WEEKLY = "weekly"
    MONTHLY = "monthly"
    MANUAL = "manual"

Split

Bases: StrEnum

Enum of split types

Source code in src/pypaystack2/enums.py
class Split(StrEnum):
    """Enum of split types"""

    PERCENTAGE = "percentage"
    FLAT = "flat"

Status

Bases: StrEnum

Enum of statuses supported by paystack, used by Invoice, Charge & Plan

Source code in src/pypaystack2/enums.py
class Status(StrEnum):
    """Enum of statuses supported by paystack, used by Invoice, Charge & Plan"""

    PENDING = "pending"
    SUCCESS = "success"
    FAILED = "failed"

TerminalEvent

Bases: StrEnum

Enum of the types of events supported by Terminal API

Source code in src/pypaystack2/enums.py
4
5
6
7
8
class TerminalEvent(StrEnum):
    """Enum of the types of events supported by Terminal API"""

    TRANSACTION = "transaction"
    INVOICE = "invoice"

TransactionStatus

Bases: StrEnum

Enum of transaction status

Source code in src/pypaystack2/enums.py
class TransactionStatus(StrEnum):
    """Enum of transaction status"""

    FAILED = "failed"
    SUCCESS = "success"
    ABANDONED = "abandoned"

pypaystack2.models

BulkChargeInstruction

Bases: BaseModel

A dataclass for bulk charge instruction.

Attributes:

Name Type Description
authorization str

The authorization code of the customer you want to charge.

amount int

The amount you want to charge.

reference str

The transaction reference.

Source code in src/pypaystack2/models/payload_models.py
class BulkChargeInstruction(BaseModel):
    """A dataclass for bulk charge instruction.

    Attributes:
        authorization: The authorization code of the customer you want to charge.
        amount: The amount you want to charge.
        reference: The transaction reference.
    """

    authorization: str
    amount: int
    reference: str

LineItem

Bases: BaseModel

A dataclass for LineItem.

Attributes:

Name Type Description
name str

The name of the product.

amount int

The price of the product.

quantity int

The quantity.

Source code in src/pypaystack2/models/payload_models.py
class LineItem(BaseModel):
    """A dataclass for LineItem.

    Attributes:
        name: The name of the product.
        amount: The price of the product.
        quantity: The quantity.
    """

    name: str
    amount: int
    quantity: int

Recipient

Bases: BaseModel

A model for representing Transfer Recipients.

Attributes:

Name Type Description
type RecipientType

Recipient Type. any value from the RecipientType enum

name str

A name for the recipient

account_number str

Required if type is RecipientType.NUBAN or RecipientType.BASA

bank_code str | None

Required if type is RecipientType.NUBAN or RecipientType.BASA. You can get the list of Bank Codes by calling the PaystackClient.get_banks.

description str | None

description

currency Currency | None

currency

auth_code str | None

auth code

metadata dict[str, Any] | None

metadata

Source code in src/pypaystack2/models/payload_models.py
class Recipient(BaseModel):
    """A model for representing Transfer Recipients.

    Attributes:
        type: Recipient Type. any value from the `RecipientType` enum
        name: A name for the recipient
        account_number: Required if `type` is `RecipientType.NUBAN` or `RecipientType.BASA`
        bank_code: Required if `type` is `RecipientType.NUBAN` or `RecipientType.BASA`.
            You can get the list of Bank Codes by calling the `PaystackClient.get_banks`.
        description: description
        currency: currency
        auth_code: auth code
        metadata: metadata
    """

    type: RecipientType
    name: str
    account_number: str
    bank_code: str | None = None
    description: str | None = None
    currency: Currency | None = None
    auth_code: str | None = None
    metadata: dict[str, Any] | None = None

Response

Bases: BaseModel, Generic[PaystackResponseData]

A pydantic model containing the data gotten from making a request to paystack's API endpoints.

All client methods that make API calls to paystack returns an instance of Response

Attributes:

Name Type Description
status_code HTTPStatus

The response status code

status bool

A flag for the response status

message str

Paystack response message

data PaystackResponseData

Data sent from paystack's server if any. This data is of a generic type called PaystackDataModel indicating that data can either be a pydantic model instance, a list of pydantic model instances or None. The exact type of the data can be determined by looking at the return type of the client method that you called that returns a Response. E.g. PaystackClient.bulk_charges.get_batches method has its return type as Response[list[BulkCharge]], hence, if you called this method and got a Response, even though Response.data is type hinted as PaystackDataModel, you should expect Response.data to be list[BulkCharge] which is a list of BulkCharge pydantic model instances which is a valid PaystackDataModel. A client method with a return type of Response[None] indicates that no data is expected to be returned from paystack by calling that method, hence, Response.data is None. If Response.data is None when the client method does not explicitly specify that the return type of the method at Response[None], this is an indicator that the library has failed to serialize the data returned from paystack into the PaystackDataModel (pydantic model) defined by the library. The data that failed to be serialized is still available via Response.raw. You may choose to override the type of Response.data by specifying a custom pydantic model class implemented by you or inheriting the model from the library and overriding the faulty fields and passing the custom class via the alternate_response_model parameter of the client methods that return a Response. As a result of this, they type of data is either an instance or a list of instances of the custom pydantic model depending on if the client method is supposed to return a list or a single resource.

meta dict[str, Any] | None

Additional information about the response.

type str | None

In cases where the response has a status of False or the status code is an error status code. the type field indicates the type of error e.g. api_error

code str | None

In cases where the response has a status of False or the status code is an error status code. the type field indicates the type of error e.g. api_error

raw dict[str, Any] | list[dict[str, Any]] | bytes | None

The original data returned by paystack in native python types i.e. the JSON data returned from paystack REST APIs have only been converted to dicts or list. This is the same data that is further extracted into individual fields such as status, message, data e.t.c and also serialized to pydantic models in the case of Response.data.

Source code in src/pypaystack2/models/response_models.py
class Response(BaseModel, Generic[PaystackResponseData]):
    """
    A pydantic model containing the data gotten from making a request to paystack's API endpoints.

    All client methods that make API calls to paystack returns an instance of `Response`

    Attributes:
        status_code: The response status code
        status: A flag for the response status
        message: Paystack response message
        data: Data sent from paystack's server if any. This data is of a generic type called `PaystackDataModel`
            indicating that data can either be a pydantic model instance, a list of pydantic model instances or
            `None`. The exact type of the data can be determined by looking at the return type of the client method
            that you called that returns a `Response`. E.g. `PaystackClient.bulk_charges.get_batches` method has
            its return type as `Response[list[BulkCharge]]`, hence, if you called this method and got a `Response`,
            even though `Response.data` is type hinted as `PaystackDataModel`, you should expect `Response.data` to
            be `list[BulkCharge]` which is a list of `BulkCharge` pydantic model instances which is a valid
            `PaystackDataModel`. A client method with a return type of `Response[None]` indicates that no data is
            expected to be returned from paystack by calling that method, hence, `Response.data` is `None`. If
            `Response.data` is `None` when the client method does not explicitly specify that the return type of
            the method at `Response[None]`, this is an indicator that the library has failed to serialize the
            data returned from paystack into the `PaystackDataModel` (pydantic model) defined by the library.
            The data that failed to be serialized is still available via `Response.raw`. You may choose to override
            the type of `Response.data` by specifying a custom pydantic model class implemented by you or inheriting
            the model from the library and overriding the faulty fields and passing the custom class via the
            `alternate_response_model` parameter of the client methods that return a Response.
            As a result of this, they type of data is either an instance  or a list of instances of the custom
            pydantic model depending on if the client method is supposed to return a list or a single resource.
        meta: Additional information about the response.
        type: In cases where the response has a status of `False` or the status code
            is an error status code. the `type` field indicates the type of error e.g. `api_error`
        code: In cases where the response has a status of `False` or the status code
            is an error status code. the `type` field indicates the type of error e.g. `api_error`
        raw: The original data returned by paystack in native python types i.e. the JSON data returned
            from paystack REST APIs have only been converted to dicts or list. This is the same data
            that is further extracted into individual fields such as `status`, `message`, `data` e.t.c
            and also serialized to pydantic models in the case of `Response.data`.
    """

    status_code: HTTPStatus
    status: bool
    message: str
    data: PaystackResponseData
    meta: dict[str, Any] | None
    type: str | None
    code: str | None
    raw: dict[str, Any] | list[dict[str, Any]] | bytes | None

SplitAccount

Bases: BaseModel

A dataclass for SplitAccount.

Attributes:

Name Type Description
subaccount str

The id of the sub account.

share int | float

The share of the split account the sub account should have.

Source code in src/pypaystack2/models/payload_models.py
class SplitAccount(BaseModel):
    """A dataclass for SplitAccount.

    Attributes:
        subaccount: The id of the sub account.
        share: The share of the split account the sub account should have.
    """

    subaccount: str
    share: int | float

Tax

Bases: BaseModel

A dataclass for Tax.

Attributes:

Name Type Description
name str

The name of the tax.

amount int

The price of the tax.

Source code in src/pypaystack2/models/payload_models.py
class Tax(BaseModel):
    """A dataclass for Tax.

    Attributes:
        name: The name of the tax.
        amount: The price of the tax.
    """

    name: str
    amount: int

TransferInstruction

Bases: BaseModel

A dataclass for TransferInstruction.

Attributes:

Name Type Description
amount int

The amount to be transferred.

recipient str

The beneficiary of the transaction.

reference Optional[str]

The reference for the transaction.

reason Optional[str]

The narration of the transaction.

Source code in src/pypaystack2/models/payload_models.py
class TransferInstruction(BaseModel):
    """A dataclass for TransferInstruction.

    Attributes:
        amount: The amount to be transferred.
        recipient: The beneficiary of the transaction.
        reference: The reference for the transaction.
        reason: The narration of the transaction.
    """

    amount: int
    recipient: str
    reference: Optional[str]
    reason: Optional[str]

pypaystack2.exceptions

ClientNetworkError

Bases: Exception

Custom exception for wrapping httpx-related errors.

Source code in src/pypaystack2/exceptions.py
class ClientNetworkError(Exception):
    """Custom exception for wrapping httpx-related errors."""

    def __init__(self, message: str, original_exception: Exception | None = None):
        super().__init__(message)
        self.original_exception = (
            original_exception  # Store the original exception for debugging
        )

MissingSecretKeyException

Bases: Exception

Custom exception raised when we can't find the secret key

Source code in src/pypaystack2/exceptions.py
1
2
3
4
class MissingSecretKeyException(Exception):
    """Custom exception raised when we can't find the secret key"""

    ...