Skip to content

msflib.payments

Public modules of the msflib-payments package.

msflib.payments.actions

msflib.payments.config

msflib.payments.models

msflib.payments.router

router(get_session: Callable, get_current_account: Callable, settings: SettingsBase, prefix: str = '/payments', tags: list[str] | None = None)

Create and return a FastAPI router for all payment-related endpoints. Handles DB sessions, authentication, and signing logic internally.

Parameters:

Name Type Description Default
get_session Callable

Dependency that returns a database session.

required
get_current_account Callable

Auth dependency for the current user/account.

required
settings SettingsBase

Host settings object; the router reads the payments settings from it.

required
prefix str

Optional URL prefix for mounting the router.

'/payments'
tags list[str] | None

Optional list of documentation tags.

None

msflib.payments.service

base_gateway

BasePaymentGateway(settings: SettingsBase)

Bases: ABC

convert_amount(amount: float | str | Decimal) -> int

Convert a currency amount into its smallest unit (e.g. cents for USD, kobo for NGN).

Examples:

100 -> 10000 99.99 -> 9999 "250.50" -> 25050

initiate(account: AccountType, data: PaymentData) abstractmethod async

Start a payment transaction

verify(reference: str) abstractmethod async

Verify a payment transaction

error

PaymentError(message: str, cause: Exception | None = None)

Bases: Exception

Base exception for ingestion failures.

PaymentConnectionError(message: str, cause: Exception | None = None)

Bases: PaymentError

Raised when we can't connect to Payment.

PaymentResponseError(message: str, cause: Exception | None = None)

Bases: PaymentError

Raised when Payment returns an unexpected status code.

PaymentStatusError(message: str, cause: Exception | None = None)

Bases: PaymentError

Raised when Payment status is not successful.

PaymentAmountError(message: str, cause: Exception | None = None)

Bases: PaymentError

Raised when Payment amount is invalid

paystack_gateway

PaystackGateway(settings: SettingsBase)

Bases: BasePaymentGateway

initiate(account: AccountType, data: PaymentData) -> PaymentInfo async

Intialize paystack transaction

stripe_gateway

StripeGateway(settings: SettingsBase)

Bases: BasePaymentGateway

initiate(account: AccountType, data: PaymentData, payment_method: list[StripePaymentMethod] | None = None, ui_mode: Literal['embedded', 'hosted'] = 'embedded') -> PaymentInfo async

Initialize Stripe Checkout Session for one-time payment