Checkout Session
Use hosted checkout with a secure backend-created session
Overview
A checkout session is a hosted payment page created by your backend.
You create it with a secret key, get a checkoutUrl, then redirect the customer to that URL.
When to Use It
- You want a hosted checkout page instead of building payment UI yourself.
- You want to keep payment orchestration on backend only.
Create Session (Backend)
Use your secret key only:
import { Moosyl } from "moosyl-sdk";
const moosyl = new Moosyl(process.env.MOOSYL_SECRET_KEY!);
const session = await moosyl.createCheckoutSession({
paymentRequestId: "payment_request_id",
transactionId: "order_123",
amount: 5000,
phoneNumber: "+22212345678",
successUrl: "https://example.com/success",
cancelUrl: "https://example.com/cancel",
expiresInMinutes: 30,
});
console.log(session.checkoutUrl);Required Input Rules
- Provide
paymentRequestId, or providetransactionId. - If
transactionIddoes not match an existing payment request, includeamount. expiresInMinutesmust be between5and1440.
Redirect Customer
From your frontend:
window.location.href = checkoutUrl;Confirm Payment
Do not rely only on frontend redirect. Use webhooks as source of truth for final payment status.
Notes
- Only secret API keys can create checkout sessions.
- Reusing the same open session can happen for the same payment request.
- Expired sessions cannot be paid.