SendPesa
Pay with SendPesa button
One script tag adds a SendPesa checkout button to any website. Your server creates the checkout session with your secret key; the button only ever receives the session url.
Try it
Demo only — no money moves. This page has no merchant key, so the demo endpoint returns a checkout that doesn't exist: the button opens SendPesa and you'll see “This checkout doesn't exist”.
Dark theme
Light theme
Blocked redirect
The endpoint answers with a non-SendPesa url; the button refuses it and shows an error.
Payment link (not a real link)
Add it to your site
1. Declarative button (recommended)
<script src="https://pesa.wizegorilla.com/v1/checkout.js" async></script>
<div data-sendpesa-button
data-session-endpoint="/create-sendpesa-session"
data-amount="25000"
data-order-id="ORDER-1042"
data-label="Pay with SendPesa"></div>2. Your server: create the session (Node / Express)
// server.js — your secret key stays here, never in the browser.
import express from "express";
const app = express();
app.use(express.json());
app.post("/create-sendpesa-session", async (req, res) => {
const order = await findOrder(req.body.orderId); // price from YOUR database, not the browser
const r = await fetch("https://pesa.wizegorilla.com/api/v1/checkout-sessions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SENDPESA_SECRET_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": order.id,
},
body: JSON.stringify({
amount: order.total,
orderId: order.id,
successUrl: "https://yourshop.example/thanks",
cancelUrl: "https://yourshop.example/cart",
}),
});
if (!r.ok) return res.status(502).json({ error: "checkout unavailable" });
const session = await r.json();
res.json({ url: session.url }); // only the url goes back to the button
});2. Your server: create the session (PHP)
<?php
// create-sendpesa-session.php — your secret key stays here, never in the browser.
$in = json_decode(file_get_contents('php://input'), true);
$order = find_order($in['orderId'] ?? ''); // price from YOUR database
$ch = curl_init('https://pesa.wizegorilla.com/api/v1/checkout-sessions');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SENDPESA_SECRET_KEY'),
'Content-Type: application/json',
'Idempotency-Key: ' . $order['id'],
],
CURLOPT_POSTFIELDS => json_encode([
'amount' => $order['total'],
'orderId' => $order['id'],
'successUrl' => 'https://yourshop.example/thanks',
'cancelUrl' => 'https://yourshop.example/cart',
]),
]);
$session = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
header('Content-Type: application/json');
if ($status >= 300 || empty($session['url'])) { http_response_code(502); echo '{"error":"checkout unavailable"}'; exit; }
echo json_encode(['url' => $session['url']]); // only the url goes back to the buttonProgrammatic
<div id="pay"></div>
<script src="https://pesa.wizegorilla.com/v1/checkout.js"></script>
<script>
SendPesa.mount(document.getElementById("pay"), {
sessionEndpoint: "/create-sendpesa-session",
body: { amount: 25000, orderId: "ORDER-1042" },
label: "Pay with SendPesa",
theme: "light", // "dark" (default) or "light"
onError: (err) => console.warn(err),
});
// Already have a session url from your server? Skip the button:
// SendPesa.redirectToCheckout({ url });
</script>Payment link (no server)
<script src="https://pesa.wizegorilla.com/v1/checkout.js" async></script>
<!-- Fixed-price item, no server code: paste a payment link from your dashboard -->
<div data-sendpesa-button
data-link="https://pesa.wizegorilla.com/pay/YOUR_LINK_TOKEN"
data-networks="false"></div>