You need a secret key. Use your own
sk_test_ key from the dashboard, or the public key from the Playground to follow along.Choose how the buyer pays
Redirect
Send the buyer to KetaPay’s checkout. They pay by card or bank transfer and come back to your site. The quickest integration.
On your page
Open the same checkout over your page with
@ketapay/checkout or @ketapay/react. The buyer never leaves your site.Your own screen
Show a one-time account number in your own UI and let the buyer pay by transfer.
1. Create a checkout session
Create the session on your server, when the buyer clicks pay. The price, the milestones and the parties always come from your server, never from the browser.
The response is the session. Keep its
id with your order.
2. Send the buyer to pay
Redirect the buyer tosession.url.
return_url with ?checkout_session_id=<id> added. If they leave, they go to cancel_url.
To keep the buyer on your page instead, send session.url to the browser and open it there (see Checkout on your page):
3. Confirm the payment
Never mark an order paid because the buyer came back to yourreturn_url: anyone can open that URL. Confirm it one of two ways, and ideally both:
- Webhook: KetaPay sends
escrow.fundedto your endpoint the moment the buyer pays. See Webhooks. - Fetch the session when the buyer lands on your
return_url, and check itsstatusiscomplete.
4. After payment
The session’sescrow_id is now set. The escrow follows its own lifecycle: the seller delivers, the buyer releases, and the seller is paid. See Escrow lifecycle.
Cancel an unpaid session
POST /checkout_sessions/{id}/cancel closes a session nobody has paid, for example when the order changes. A paid session can’t be cancelled; cancel the escrow instead.