Skip to main content
The LigdiCash Python SDK exposes three main objects — Invoice, Withdrawal, and get_transaction — covering every payment flow. Unlike the other SDKs, initialization uses module-level globals, not a class instance.

Installation

Requirements: Python ≥ 3.0. The requests dependency is installed automatically.

Initialization

Python
Get your api_key and auth_token from the LigdiCash dashboard by creating an API project.

Hosted payin

The customer is redirected to the LigdiCash-hosted payment page. This is the recommended flow for online stores.
Python
Never open payment_url in an iframe — LigdiCash blocks it. Redirect in the same tab, a new tab, or a popup. On native mobile, use a WebView.
Always leave customer empty in hosted payin (this is the default). If you pass a number, LigdiCash filters the payment page to show only the operators tied to that number.

Direct payin

The customer pays directly from your interface. You must collect their phone number and, depending on the operator, their OTP code.
Python
The OTP mode varies by operator. For example, with a USSD operator, the customer generates the OTP on their phone before you submit. For an approval-mode operator (e.g. Moov Africa), send otp="" — the customer approves directly in their app. See the operator page for details.

Payout

Send money to a customer — refund, salary, payout.

To the customer’s LigdiCash wallet

Python

Directly to mobile money

Python
type="client" uses the POST /pay/v01/withdrawal/create endpoint (via the LigdiCash wallet). type="merchant" uses POST /pay/v01/straight/payout (direct mobile money, slower). See Payout — Introduction.

Status verification

Call get_transaction with the token stored at creation (not the callback token, which is different).
Python
Fields available on transaction:
AttributeTypeDescription
statusstr"completed", "pending", "cancelled"
response_codestr"00" success, "01" failure
amountintTransaction amount
operator_idstrOperator identifier
operator_namestrOperator name
customerstrCustomer phone number
tokenstrTransaction token
custom_datadictCustom data sent at creation
wikilistLinks to the endpoint’s error codes
Never deliver an order solely based on an incoming callback. Always call get_transaction with the token stored at creation to confirm the status on the LigdiCash server side. See Callback security.

Error handling

Every error inherits from ligdicash.LigdicashError and exposes .code and .message.
Python
Available error classes:
ClassRaised when
AuthenticationErrorapi_key or auth_token invalid
ApplicationAuthenticationErrorApplication not authenticated
MerchantPayinDisabledErrorPayin not enabled on the project
MerchantPayoutDisabledErrorPayout not enabled on the project
MerchantBalanceLowErrorMerchant balance too low
CustomerDoesNotExistErrorCustomer not registered on the platform
InvalidAmountErrorAmount outside the [20; 1,000,000] range
InvalidTokenErrorInvalid or missing token
InvoiceNotFoundErrorInvoice not found
TransactionAlreadyExistErrorTransaction already created
RecipientOperatorNotIdentifiedErrorRecipient’s operator not identified
FeatureNotTestableErrorFeature unavailable in "test" mode