Skip to main content

Sample App: Python

A working Python integration against the PayKore sandbox. Sync and async patterns both covered — the quickstart uses sync, the webhook server uses the stdlib http.server.

Source: samples/python/ in the PayKore repo.


What it covers

StepFlow
1Create two wallets
2Fund wallet A (sandbox only)
3P2P transfer: A → B
4Bank transfer from A (async, settles via webhook)
5QR payment: merchant creates intent, payer pays
6USSD payment: initiate + simulate confirmation
7KYC: submit BVN (async, result via webhook)

Prerequisites


Setup

cd samples/python
pip install -r requirements.txt

Run the quickstart

export PAYKORE_API_KEY=sk_test_YOUR_KEY_HERE
python quickstart.py

You'll see a line printed for each step. The full run takes under 10 seconds.

═══════════════════════════════════════
PayKore Python Quickstart
Environment: sandbox
═══════════════════════════════════════

── Step 1: Create wallets ──

✅ Wallet A created
{
"id": "wlt_9f3kA2mXpQ",
"status": "pending",
"nuban": "0123456789"
}
...
✅ P2P transfer completed
✅ Bank transfer accepted (202)
✅ QR payment completed (payer)
✅ USSD simulation: confirm sent
✅ BVN submitted

═══════════════════════════════════════
All steps completed successfully.
Run webhook_server.py to test async event delivery.
═══════════════════════════════════════

Run the webhook server

Steps 4 (bank transfer) and 7 (KYC) produce async results. The webhook server captures and prints them.

Terminal 1 — start the server:

export PAYKORE_WEBHOOK_SECRET=whsec_YOUR_SECRET_HERE
python webhook_server.py

Terminal 2 — expose it via ngrok:

ngrok http 8080

Register the ngrok URL with PayKore:

curl -X POST https://sandbox.paykore.com/v1/webhooks \
-H "Authorization: Bearer $PAYKORE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://YOUR_NGROK_URL/webhooks",
"events": ["transaction.completed","transaction.failed","wallet.activated","kyc.verified","kyc.failed"]
}'

Save the secret from the response and export it as PAYKORE_WEBHOOK_SECRET.

Terminal 3 — run the quickstart again:

python quickstart.py

You'll see events arrive in Terminal 1:

── 2025-06-01T10:03:24+00:00 ──
Event: transaction.completed
✅ Transaction completed
ID: tx_8wXyZ1aBcD
Type: bank_transfer
Reference: py_bank_f47ac10b-...
Amount: ₦1000.00

── 2025-06-01T10:03:26+00:00 ──
Event: kyc.verified
✅ KYC verified
User ref: py_user_a_1717200000
Type: bvn
Verified at: 2025-06-01T10:03:25Z

Key files

FileWhat it is
quickstart.pyThe runnable script — one block per flow
webhook_server.pyThe HTTP server — signature verification + event handlers
requirements.txtSingle dependency: paykore

Next steps