Official SDKs

Environment: Live

Server SDKs for Node.js, Python and PHP: install, first call, downloads with SHA-256 checksums, and webhook verification.

# Official SDKs

Server SDKs for Node.js, Python and PHP: install, first call, downloads with SHA-256 checksums, and webhook verification.

## What the SDKs do

The SDKs wrap the Moolre API for server code. They send credentials in headers only, use channel names, attach Idempotency-Key to retries, read meta.requestid and meta.notices, raise typed errors, walk cursors for you and verify webhook signatures. Keep API keys on your server: never ship them to a browser or mobile app.

Each SDK is a thin client over the same HTTP API documented here. Anything the SDK does you can do with plain HTTP.

## Install

The Node.js SDK is on npm, the Python SDK is on PyPI and the PHP SDK is on Packagist: install them with your package manager. Each SDK is also published as a single file you can copy into your project.

For the browser checkout (not a server SDK), use the @moolre/moolrejs package from npm, described on the JavaScript Inline page.

```nodejs
# Node 18+, ESM and CommonJS, TypeScript types included, no runtime dependencies
npm install @moolre/sdk

import { Moolre } from '@moolre/sdk';
const moolre = new Moolre({
  environment: 'sandbox',
  user: process.env.MOOLRE_USER,
  apiKey: process.env.MOOLRE_API_KEY,
  pubKey: process.env.MOOLRE_PUBKEY,
  accountNumber: '1000000000001',
});
```

```python
# Python 3.9+, standard library only
pip install moolre

import os, moolre
client = moolre.Moolre(
    environment="sandbox",
    user=os.environ["MOOLRE_USER"],
    api_key=os.environ["MOOLRE_API_KEY"],
    pub_key=os.environ["MOOLRE_PUBKEY"],
    account_number="1000000000001",
)
```

```php
<?php
// PHP 7.4+, ext-curl, ext-json. From Packagist:
//   composer require moolre/moolre-php:^1.2
require __DIR__ . '/vendor/autoload.php';
// Without Composer, download the single file instead: require __DIR__ . '/moolre-sdk.php';

use Moolre\Moolre;

$moolre = new Moolre([
    'environment'   => 'sandbox',
    'user'          => getenv('MOOLRE_USER'),
    'apiKey'        => getenv('MOOLRE_API_KEY'),
    'pubKey'        => getenv('MOOLRE_PUBKEY'),
    'accountNumber' => '1000000000001',
]);
```

## Step by step: your first SDK call



1. Install the SDK: npm install @moolre/sdk (Node.js), pip install moolre (Python) or composer require moolre/moolre-php (PHP).
2. Create the client with environment "sandbox", your username, the keys you have and a default account number. Keep every credential in environment variables.
3. Make a collection to the test number 0240000111 with an idempotency key. The result object carries ok, code, message, data, requestId, notices and replayed (read from meta.requestid, meta.notices and meta.replayed).
4. If result.otpRequired is true (code TP14), call verifyOtp with 123456 and call initiate once more when it reports TP17.
5. Catch the typed error for status 0 (ApiError and its subclasses) and read code, apiMessage, fields and requestId.
6. Set strictHttpStatus if you want real HTTP status codes, and keep maxRetries low: the SDK retries network errors and 5xx only for reads and for calls that carry an idempotency key.
7. Switch environment to "live" and the credentials to live ones when you go live.

## Versions and the API change of 25 November 2026

Bulk payout status and list now return hooks, page and pages, and webhooks have their own layout. Node.js 0.2.0, Python 0.2.0 and PHP 1.2.0 follow both. Update to them: in older versions iterateItems and iterateBatches find nothing, page cannot be sent, and event and eventId are empty for a webhook.

| SDK | Published | Bulk payouts | Webhooks |
| --- | --- | --- | --- |
| Node.js | 0.2.0 (npm) | bulk.status and bulk.list take page; bulk.iterateHooks and bulk.iterateBatches read every page | event.kind, event.page, event.pages, event.hooks and eventTransactions(event); accounts.updateWebhooks switches webhooks on |
| Python | 0.2.0 (PyPI) | bulk.status and bulk.list take page; bulk.iterate_hooks and bulk.iterate_batches read every page | event.kind, event.page, event.pages, event.hooks and event.transactions(); accounts.update_webhooks switches webhooks on |
| PHP | 1.2.0 (Packagist) | bulk->status and bulk->list take page; bulk->iterateHooks and bulk->iterateBatches read every page | $event->kind, $event->page, $event->pages, $event->hooks and $event->transactions(); accounts->updateWebhooks switches webhooks on |

- [Webhooks](https://docs.moolre.com/guides/webhooks)
- [Bulk payouts](https://docs.moolre.com/guides/bulk-payouts)

## Downloads and checksums

Node.js (npm), Python (PyPI), PHP (Packagist) and the moolrejs browser checkout (npm) install from your package manager. Every SDK can also be downloaded from docs.moolre.com and checked against the published SHA-256 checksum. The same list is published as one file: SHA256SUMS.

Verify a download before you use it: on Linux or macOS run sha256sum -c SHA256SUMS in the folder that holds the files (shasum -a 256 on macOS), on Windows run Get-FileHash -Algorithm SHA256 <file>.

| SDK | Version | Install command | Download | SHA-256 |
| --- | --- | --- | --- | --- |
| Node.js package | 0.2.1 | npm install @moolre/sdk (npm), or npm install ./moolre-sdk-0.2.1.tgz | [moolre-sdk-0.2.1.tgz](/sdk/node/moolre-sdk-0.2.1.tgz) | e73d0592a388394aa095e89cf994afc332b6ca8cbd67e6f7887a8e0edea38980 |
| Node.js single file (ESM) | 0.2.1 | import from ./moolre.bundle.mjs | [moolre.bundle.mjs](/sdk/node/moolre.bundle.mjs) | 02308d9360827afe6fe2a408b8cb75f044a3a59ff338adfa188770ee57557369 |
| Python wheel | 0.2.1 | pip install moolre (PyPI), or pip install ./moolre-0.2.1-py3-none-any.whl | [moolre-0.2.1-py3-none-any.whl](/sdk/python/moolre-0.2.1-py3-none-any.whl) | c46d7a1a3f05d6b4cde99eed8d468a967d630ff061b01d94a21f368025e4ebfe |
| Python source | 0.2.1 | pip install ./moolre-0.2.1.tar.gz | [moolre-0.2.1.tar.gz](/sdk/python/moolre-0.2.1.tar.gz) | 7f2127622daea0d099bd8653ac5bb9617347aeea57d99e6eb0ab7728e42abb0d |
| Python single file | 0.2.1 | copy moolre.py next to your code | [moolre.py](/sdk/python/moolre.py) | 577b2e55982ed633590210880d484f350f78f5acb4088a2c08afb8cbebdddf38 |
| PHP package | 1.2.1 | composer require moolre/moolre-php (Packagist), or unzip | [moolre-php-1.2.1.zip](/sdk/php/moolre-php-1.2.1.zip) | 7eaf29695a56a07762f5416dbb5dc95066cde2b62a29a2afc69323e5e2c482f7 |
| PHP single file | 1.2.1 | require moolre-sdk.php | [moolre-sdk.php](/sdk/php/moolre-sdk.php) | 2005e730adfb2b1473a1eb4b3f624d1aa7638a81660e2883cc985d57a83bd26b |
| Browser checkout (moolrejs) | 1.1.1 | npm install @moolre/moolrejs (npm) | [moolre-moolrejs-1.1.1.tgz](/sdk/moolrejs/moolre-moolrejs-1.1.1.tgz) | 38017f1a640ddf4a38322b7bb57427d8d9f45a8258e3d09e98a51e2d82651872 |
| Webhook test vectors | 2 | JSON test cases for your own verifier | [webhook.json](/sdk/vectors/webhook.json) | 4affe004dc79a239aa0a3c90e495e6131dd75d120b64ae064e47bdec9281bf1e |

- [SHA256SUMS (all checksums)](https://docs.moolre.com/sdk/SHA256SUMS)

## Verify webhooks with an SDK

Every SDK has a constant-time verifier that checks the signature and the timestamp tolerance, and a helper that returns the parsed event. The same helper serves callbacks and webhooks. A callback has event and event_id at the top level and one transaction in data; a webhook has them inside data and lists its transactions in data.hooks. The SDKs read both for you: event.kind is callback or webhook, and one handler serves both.

```nodejs
import { constructEvent, eventTransactions, WebhookSignatureError } from '@moolre/sdk';

app.post('/moolre/webhook', express.raw({ type: '*/*' }), (req, res) => {
  try {
    const event = constructEvent(req.body, req.header('X-Moolre-Signature'), process.env.MOOLRE_WALLET_SECRET);
    // dedupe on event.eventId, then act once per transaction (callbacks and webhooks)
    for (const tx of eventTransactions(event)) queueWork(event.event, tx);   // your own queue
    res.sendStatus(200);
  } catch (e) {
    if (e instanceof WebhookSignatureError) return res.sendStatus(400);
    throw e;
  }
});
```

```python
try:
    event = moolre.construct_event(request.get_data(), request.headers.get("X-Moolre-Signature"), os.environ["MOOLRE_WALLET_SECRET"])
except moolre.WebhookSignatureError:
    return "", 400
# dedupe on event.event_id, then act once per transaction (callbacks and webhooks)
for tx in event.transactions():
    queue_work(event.event, tx)   # your own queue
return "", 200
```

```php
<?php
use Moolre\Webhook;
$event = Webhook::construct(file_get_contents('php://input'), $_SERVER['HTTP_X_MOOLRE_SIGNATURE'] ?? '', getenv('MOOLRE_WALLET_SECRET'));
// dedupe on $event->eventId, then act once per transaction (callbacks and webhooks)
foreach ($event->transactions() as $tx) {
    queue_work($event->event, $tx);   // your own queue
}
```

## Hosted checkout PHP package

The moolre/moolre-php package also contains the hosted checkout client described on the PHP SDK page. It is unchanged.

- [Moolre PHP SDK (hosted checkout)](https://docs.moolre.com/plugins/php)

## What each SDK covers



| Area | Methods |
| --- | --- |
| Collections | payments.initiate, payments.verifyOtp |
| Payouts | transfers.validateName, transfers.create, transfers.status |
| Bulk payouts | bulk.create, bulk.status, bulk.list, bulk.iterateHooks, bulk.iterateBatches (Python: iterate_hooks, iterate_batches) |
| Invoices | invoices.create, invoices.status, invoices.cancel, invoices.iterate |
| Accounts | accounts.iterateTransactions, accounts.updateWebhooks (Python: iterate_transactions, update_webhooks) |
| Sales | sales.airtime |
| Messaging | sms.send, whatsapp.send, whatsapp.iterateTemplates |
| Webhooks and callbacks | webhooks.test, webhooks.resend, webhooks.iterateDeliveries, constructEvent, verifyWebhook, eventTransactions (Python and PHP: event.transactions()) |
| Payment links | paymentLinks.create |

- [ ] Credentials come from environment variables and stay on the server.
- [ ] Retries use an idempotency key.
- [ ] You log requestId and notices.
- [ ] Webhooks and callbacks are verified with constructEvent on the raw body.

Back to the Moolre AI documentation index