Accept a one-time payment
- Create a product or reuse an existing one.
- Create a checkout session.
- Redirect your customer to the checkout URL.
- Handle the
checkout.paidwebhook. - Grant access.
- TypeScript
- Python
- Go
- cURL
const checkout = await accend.checkout.createSession({
mode: "payment",
customerId: "cus_123",
productId: "prod_123",
amount: "97.00",
currency: "BRL",
successUrl: "https://yourapp.com/success",
cancelUrl: "https://yourapp.com/cancel"
});
redirect(checkout.data.checkoutUrl);
checkout = accend.checkout.create_session({
"mode": "payment",
"customerId": "cus_123",
"productId": "prod_123",
"amount": "97.00",
"currency": "BRL",
"successUrl": "https://yourapp.com/success",
"cancelUrl": "https://yourapp.com/cancel",
})
checkout_url = checkout["data"]["checkoutUrl"]
checkout, _ := client.CreateCheckoutSession(ctx, map[string]any{
"mode": "payment",
"customerId": "cus_123",
"productId": "prod_123",
"amount": "97.00",
"currency": "BRL",
"successUrl": "https://yourapp.com/success",
"cancelUrl": "https://yourapp.com/cancel",
})
checkoutData := checkout["data"].(map[string]any)
checkoutURL := checkoutData["checkoutUrl"].(string)
_ = checkoutURL
curl -X POST "https://api.accend.now/v1/checkout/sessions" \
-H "Authorization: Bearer $ACCEND_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"mode": "payment",
"customerId": "cus_123",
"productId": "prod_123",
"amount": "97.00",
"currency": "BRL",
"successUrl": "https://yourapp.com/success",
"cancelUrl": "https://yourapp.com/cancel"
}'
app.post("/webhooks/accend", async (req, res) => {
if (req.body.type === "checkout.paid") {
await grantAccess(req.body.data.customerId, req.body.data.productId);
}
res.sendStatus(200);
});
Use a key with
checkout:write for the service that creates checkout sessions.