Skip to main content
The LigdiCash JavaScript SDK works in Node.js and TypeScript environments. Every network call is asynchronous (async/await). TypeScript types are bundled with the package.

Installation

Requirements: Node.js. The cross-fetch dependency is installed automatically.

Initialization

Get your apiKey and authToken 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.
TypeScript
Every network call (payWithRedirection, payWithoutRedirection, send, getTransaction) returns a Promise. A missing await causes a silent comparison against a Promise object instead of the real result.
Never open paymentUrl in an iframe — LigdiCash blocks it. Redirect in the same tab, a new tab, or a popup. On native mobile, use a WebView.
Popup pattern that bypasses blockers: open window.open("about:blank") on the user click (before the await), then navigate to paymentUrl once the response is received. This sidesteps browser popup blockers.

Direct payin

The customer pays directly from your interface. You must collect their phone number and, depending on the operator, their OTP code.
TypeScript
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

TypeScript

Directly to mobile money

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

Status verification

Call getTransaction with the token stored at creation (not the callback token, which is different).
TypeScript
Fields available on transaction:
PropertyTypeDescription
statusstring"completed", "pending", "cancelled"
response_codestring"00" success, "01" failure
amountnumberTransaction amount
operator_idstringOperator identifier
operator_namestringOperator name
customerstringCustomer phone number
tokenstringTransaction token
custom_dataobjectCustom data sent at creation
wikistring[]Links to the endpoint’s error codes
Never deliver an order solely based on an incoming callback. Always call getTransaction with the token stored at creation to confirm the status on the LigdiCash server side. See Callback security.

TypeScript types

The SDK exports the following types for your function signatures and interfaces:
TypeScript
TypeUse
InvoiceParamParameters of the Invoice constructor
InvoiceItemParamParameters of addItem
PayWithRedirectionParamParameters of payWithRedirection
PayWithoutRedirectionParamParameters of payWithoutRedirection
BaseResponseTypeResponse returned by payin/payout calls

Error handling

TypeScript
Also check response.response_code after every call: "00" indicates success, "01" an error. On error, read response.wiki to get the URL with sub-code details.