Instant payment (auto capture)
Authorize and capture a card payment in a single step, the simplest and most common one-time payment pattern.
An instant payment charges the card as soon as the customer confirms. Authorization and capture happen together and no further call is needed from your backend. This is the right pattern for most checkouts.
How it works#
- Your backend calls
POST /paymentswith"capture_method": "automatic". - Cardencer returns the payment with a
client_secret. - Your frontend passes the
client_secretto the checkout SDK, which renders the payment form. - The customer enters their card and clicks pay; the SDK confirms the payment.
- Cardencer authorizes and captures with the acquirer and returns
succeeded.
1. Create the payment on your server#
curl https://sandbox.cardencer.com/payments \
-H "api-key: $CARDENCER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"amount": 4900,
"currency": "EUR",
"capture_method": "automatic",
"customer_id": "cus_58211",
"description": "Order 58211",
"return_url": "https://example.com/checkout/complete"
}'import express from "express";
const app = express();
app.use(express.json());
app.post("/create-payment", async (req, res) => {
const response = await fetch("https://sandbox.cardencer.com/payments", {
method: "POST",
headers: { "api-key": process.env.CARDENCER_API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({
amount: 4900,
currency: "EUR",
capture_method: "automatic",
description: "Order 58211",
return_url: "https://example.com/checkout/complete",
}),
});
const payment = await response.json();
if (payment.error) return res.status(400).json({ error: payment.error.message });
res.json({ clientSecret: payment.client_secret });
});
app.listen(4242);import os, requests
from flask import Flask, jsonify
app = Flask(__name__)
@app.post("/create-payment")
def create_payment():
payment = requests.post(
"https://sandbox.cardencer.com/payments",
headers={"api-key": os.environ["CARDENCER_API_KEY"]},
json={
"amount": 4900,
"currency": "EUR",
"capture_method": "automatic",
"description": "Order 58211",
"return_url": "https://example.com/checkout/complete",
},
).json()
if "error" in payment:
return jsonify(error=payment["error"]["message"]), 400
return jsonify(clientSecret=payment["client_secret"])The payment starts in requires_payment_method. Calculate the amount on your server; never trust an amount sent by the browser.
2. Collect the card and confirm#
Render the checkout with the client_secret and your publishable key. Follow React or HTML/JS for the full frontend code; the core is:
const hyper = window.Hyper(
{ publishableKey: "pk_snd_REPLACE_WITH_YOUR_KEY", profileId: "pro_REPLACE_WITH_YOUR_PROFILE_ID" },
{ customBackendUrl: "https://sandbox.cardencer.com" },
);
const widgets = hyper.widgets({ clientSecret });
widgets.create("payment").mount("#payment-element");
const { error } = await hyper.confirmPayment({
confirmParams: { return_url: "https://example.com/checkout/complete" },
redirect: "if_required",
});3. Confirm the result on your server#
When the customer returns, or when your webhook receives payment_succeeded, retrieve the payment and fulfil the order only if status is succeeded and the amount matches.
curl https://sandbox.cardencer.com/payments/pay_mbabizu24mvu3mela5njyhpit4 \
-H "api-key: $CARDENCER_API_KEY"Server-only alternative#
If you collect cards yourself under PCI DSS, create and confirm in one call by adding "confirm": true and payment_method_data, as in the quickstart. See Server-to-server payments.