Skip to content

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#

  1. Your backend calls POST /payments with "capture_method": "automatic".
  2. Cardencer returns the payment with a client_secret.
  3. Your frontend passes the client_secret to the checkout SDK, which renders the payment form.
  4. The customer enters their card and clicks pay; the SDK confirms the payment.
  5. 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"
  }'

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:

js
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.