SDK na Libraries

Unganisha tovuti, app au mfumo wako na PigaPay kwa dakika chache.

Maktaba ya PHP Node.js Python cURL

Plugin ya WooCommerce

Duka la WordPress linapokea M-Pesa, Mixx by Yas, Airtel Money na HaloPesa bila kuandika code: wateja wanalipa kwenye ukurasa wa PigaPay na oda zinawekwa kuwa zimelipwa zenyewe.

Pakua plugin (.zip)
Version 1.0.0WordPress 6.0+WooCommerce 7.0+Checkout ya kawaida na ya blockKurejesha Pesa

Weka kwa hatua 3

  1. WordPress: Plugins > Add New > Upload Plugin, choose pigapay-woocommerce.zip, then Washa.
  2. PigaPay: API Keys > Create key with "Create payments" (and "Refund customers"). Copy the API key and the webhook secret.
  3. WordPress: WooCommerce > Settings > Payments > PigaPay: paste both, tick Enable, Save. The shop currency must be TZS. Try with a pp_test_ key first.

Maktaba ya PHP ya PigaPay

Faili moja, bila vifurushi vingine. Tengeneza malipo na kurasa za malipo, na hakiki saini za webhook.

Pakua PigaPay.php
Toleo 2.0.0PHP 7.4+curlKey za majaribio na halisi

1. Mpeleke mteja kwenye ukurasa wa malipo wa PigaPay

Njia rahisi zaidi: PigaPay inaomba namba ya simu, inatuma ombi la malipo na kumrudisha mteja kwenye tovuti yako.

<?php
require __DIR__ . '/PigaPay.php';

$pigapay  = new PigaPay\Client(getenv('PIGAPAY_KEY'));   // pp_test_... while building
$checkout = $pigapay->createCheckout([
    'amount'      => 25000,
    'reference'   => 'ORDER-1001',
    'description' => 'School fees, term 1',
    'success_url' => 'https://yourshop.co.tz/paid',
    'cancel_url'  => 'https://yourshop.co.tz/cart',
]);
header('Location: ' . $checkout['url']);

2. Au tuma ombi la malipo kutoka skrini yako mwenyewe

$payment = $pigapay->createPayment([
    'amount'    => 5000,
    'customer'  => ['phone' => '0712345678', 'name' => 'Asha Juma'],
    'reference' => 'ORDER-1002',
]);
// $payment['status'] === 'forwarded': the customer has the prompt on the phone

3. Pokea matokeo

try {
    $event = PigaPay\Webhook::fromRequest(getenv('PIGAPAY_WEBHOOK_SECRET'));
} catch (UnexpectedValueException $e) {
    http_response_code(401);   // not from PigaPay, or too old
    exit;
}
if ($event['event'] === 'payment.completed') {
    // mark $event['reference'] as paid (once per $event['event_id'])
}
http_response_code(200);

Lugha nyingine

REST API inafanya kazi kwa lugha yoyote. Nakili mifano hii; maktaba rasmi za lugha nyingine ziko kwenye mpango wetu.

// Node.js 18+ (built-in fetch)
const res = await fetch('https://pay.pigatech.com/api/v1/checkout', {
  method: 'POST',
  headers: { 'Authorization': `Bearer ${process.env.PIGAPAY_KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({ amount: 25000, reference: 'ORDER-1001', success_url: 'https://yourshop.co.tz/paid' }),
});
const { data } = await res.json();
// redirect the customer to data.url
# Python 3 with requests (pip install requests)
import os, requests

r = requests.post('https://pay.pigatech.com/api/v1/checkout',
    headers={'Authorization': 'Bearer ' + os.environ['PIGAPAY_KEY']},
    json={'amount': 25000, 'reference': 'ORDER-1001', 'success_url': 'https://yourshop.co.tz/paid'},
    timeout=30)
data = r.json()['data']
# redirect the customer to data['url']
curl -X POST https://pay.pigatech.com/api/v1/checkout \
  -H "Authorization: Bearer $PIGAPAY_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount": 25000, "reference": "ORDER-1001", "success_url": "https://yourshop.co.tz/paid"}'

Hakiki saini ya webhook

Kichwa cha saini: PigaPay-Signature: t=<time>,v1=<HMAC-SHA256 of "t.body" with your webhook secret>. Kataa matukio yaliyopita dakika 5.

const crypto = require('crypto');

// Express: app.post('/pigapay/webhook', express.raw({ type: 'application/json' }), handler)
function verifyPigaPay(rawBody, header, secret) {
  const parts = Object.fromEntries(String(header).split(',').map(p => p.split('=')));
  if (!parts.t || !parts.v1 || Math.abs(Date.now() / 1000 - Number(parts.t)) > 300) return false;
  const expected = crypto.createHmac('sha256', secret).update(parts.t + '.' + rawBody).digest('hex');
  const a = Buffer.from(expected), b = Buffer.from(parts.v1);
  return a.length === b.length && crypto.timingSafeEqual(a, b);   // a wrong length is a wrong signature
}
import hmac, hashlib, time

def verify_pigapay(raw_body: bytes, header: str, secret: str) -> bool:
    parts = dict(p.split('=', 1) for p in header.split(',') if '=' in p)
    if 't' not in parts or 'v1' not in parts or abs(time.time() - int(parts['t'])) > 300:
        return False
    expected = hmac.new(secret.encode(), parts['t'].encode() + b'.' + raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts['v1'])

Mwongozo wa API

Kila endpoint, sehemu, kosa na kikomo.

Bado

Mwongozo wa wasanidi

Mwongozo kamili wa hatua kwa hatua wa PHP, Node.js, Python, Java na C#, kwenye dashibodi yako.

Ingia kufungua

Mafunzo

Hatua kwa hatua: malipo yako ya kwanza, malipo kwenye tovuti yako, webhook, kuanza rasmi.

Bado

Pata key zako

Tengeneza key ya majaribio kwenye dashibodi yako (API Keys) na uanze kujenga.

API Keys
Kiingereza Ripoti tatizo la malipo

Ongea nasi

Piga simu+255 678 520 538
Barua pepepay@pigatech.com