Payment links by API
Create shareable payment pages with an API key: fixed or chosen amounts, single use, limits and expiry.
A payment link is a page you share anywhere (WhatsApp, SMS, an invoice, Instagram, a printed QR code) without building anything. Whoever opens it sees your business, what it's for and the amount, presses Continue and pays by M-Pesa on the hosted checkout. Endpoint details are in the Payment links reference.
These are links you create with an API key (
payment_links:write). Links people make in the AutoPayKe app are covered in Payment links.Creating one
curl -X POST "https://api.autopayke.com/api/v1/payment-links" \
-H "Authorization: Bearer $AUTOPAYKE_API_KEY" \
-H "Idempotency-Key: invoice-2041-link" \
-H "Content-Type: application/json" \
-d '{
"amount": 500000,
"description": "Invoice 2041: October deliveries",
"reference": "INV-2041",
"single_use": true,
"after_payment_url": "https://example.com/paid"
}'Kinds of link
| You send | What the payer sees |
|---|---|
amount | A fixed price, like an invoice or a product. |
min_amount and max_amount | An amount box: they choose how much, within your range. Good for donations, tips or topping up. |
single_use: true | One payment, then the link closes. Only one person can be paying at a time, so it can never be paid twice. |
max_payments | Closes after that many payments, like a limited number of tickets. |
expires_at | Closes at that time (5 minutes to 365 days away). |
Getting paid
- Each payer who presses Continue gets their own checkout session.
- When they pay, you get
checkout.session.completedandpayment_link.paid. The link'spayments_countandamount_collectedgo up. - If you set
after_payment_url, we send the payer there with?session_id=cs_…added. Otherwise they see a "paid" screen.
List a link's payments with GET /api/v1/payment-links/{id}/payments, or close it any time with POST /api/v1/payment-links/{id}/deactivate.
Treat a payment as received only on the webhook (or a GET), never on the payer reaching your after-payment page.
Testing
Create the link with an apk_test_ key, open its url, press Continue and use the collection sandbox numbers: 0700000001 pays.