Aller au contenu

Référence — base.py

Ce module définit le contrat commun à tous les providers.

Protocol Transaction

Décrit l'interface attendue pour l'objet transaction passé à initiate_payment. Grâce à @runtime_checkable, la conformité peut être vérifiée à l'exécution.

from paygate_africa.base import Transaction

isinstance(my_obj, Transaction)  # True si tous les attributs sont présents

paygate_africa.base.Transaction

Bases: Protocol

Protocol defining the required interface for a transaction object. Any object that implements these attributes can be used as a transaction.

Source code in src/paygate_africa/base.py
@runtime_checkable
class Transaction(Protocol):
    """
    Protocol defining the required interface for a transaction object.
    Any object that implements these attributes can be used as a transaction.
    """
    id: str
    amount: float
    currency: str
    description: str | None
    user_name: str | None
    user_email: str
    user_phone: str | None

Classe abstraite PaymentProvider

Tout provider doit hériter de cette classe et implémenter les deux méthodes.

paygate_africa.base.PaymentProvider

Bases: ABC

Abstract base class for payment providers.

Source code in src/paygate_africa/base.py
class PaymentProvider(ABC):
    """
    Abstract base class for payment providers.
    """

    @abstractmethod
    async def initiate_payment(self, tx: Transaction) -> str:
        """
        Initiate a payment and return the checkout or redirection URL.
        """
        pass

    @abstractmethod
    async def verify_payment(self, transaction_id: str) -> dict[str, Any]:
        """
        Verify the status of a transaction.
        Returns a dictionary with:
        - "status": "SUCCESS", "FAILED", or "PENDING"
        - "raw_data": The original response from the provider's API
        """
        pass

initiate_payment(tx) abstractmethod async

Initiate a payment and return the checkout or redirection URL.

Source code in src/paygate_africa/base.py
@abstractmethod
async def initiate_payment(self, tx: Transaction) -> str:
    """
    Initiate a payment and return the checkout or redirection URL.
    """
    pass

verify_payment(transaction_id) abstractmethod async

Verify the status of a transaction. Returns a dictionary with: - "status": "SUCCESS", "FAILED", or "PENDING" - "raw_data": The original response from the provider's API

Source code in src/paygate_africa/base.py
@abstractmethod
async def verify_payment(self, transaction_id: str) -> dict[str, Any]:
    """
    Verify the status of a transaction.
    Returns a dictionary with:
    - "status": "SUCCESS", "FAILED", or "PENDING"
    - "raw_data": The original response from the provider's API
    """
    pass