Skip to content

Server-to-server payments

Create, confirm and track card payments entirely from your backend with the Cardencer REST API.

In a server-to-server (S2S) integration your backend drives the whole payment: it creates the payment, confirms it with a payment method and handles the result. Use it for:

  • charging a saved card when the customer is not present,
  • mail and telephone orders taken by your staff,
  • your own card form, if your organisation is PCI DSS compliant for handling card data.

Sending raw card numbers (payment_method_data.card) from your server puts your systems in full PCI DSS scope (SAQ D). If you are not certified, collect cards with the checkout SDK and use S2S only for saved-card charges.

Prerequisites#

  • A secret key (snd_… in the sandbox) from API keys in the dashboard.
  • A customer_id if you want to save cards or list a customer's payments.

1. Create or reuse a customer#

curl https://sandbox.cardencer.com/customers \
  -H "api-key: $CARDENCER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "cus_58211",
    "name": "Léa Martin",
    "email": "lea@example.com"
  }'

If the customer already exists, reuse their customer_id.

2. Create the payment#

You can create and confirm in one call ("confirm": true) or in two. Two calls are useful when the amount can still change: create early, update with POST /payments/{payment_id}, then confirm.

curl https://sandbox.cardencer.com/payments \
  -H "api-key: $CARDENCER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 6540,
    "currency": "EUR",
    "confirm": false,
    "capture_method": "automatic",
    "customer_id": "cus_58211",
    "description": "Order 58213"
  }'

Store the returned payment_id.

3. Confirm the payment#

With card details (PCI DSS compliant merchants only):

curl https://sandbox.cardencer.com/payments/pay_mbabizu24mvu3mela5njyhpit4/confirm \
  -H "api-key: $CARDENCER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "payment_method": "card",
    "payment_method_type": "credit",
    "return_url": "https://example.com/checkout/complete",
    "payment_method_data": {
      "card": {
        "card_number": "4242424242424242",
        "card_exp_month": "12",
        "card_exp_year": "2030",
        "card_holder_name": "Léa Martin",
        "card_cvc": "123"
      }
    },
    "browser_info": {
      "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/605.1.15",
      "accept_header": "text/html,application/xhtml+xml",
      "language": "fr-FR",
      "color_depth": 24,
      "screen_height": 900,
      "screen_width": 1440,
      "time_zone": -60,
      "java_enabled": false,
      "java_script_enabled": true,
      "ip_address": "203.0.113.10"
    }
  }'

Send browser_info collected from the customer's browser: issuers use it for 3D Secure risk checks, and complete data means fewer challenges.

With a saved card (customer not present):

curl https://sandbox.cardencer.com/payments \
  -H "api-key: $CARDENCER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 1990,
    "currency": "EUR",
    "confirm": true,
    "customer_id": "cus_58211",
    "off_session": true,
    "recurring_details": { "type": "payment_method_id", "data": "pm_lmTnIO5EdCiiOrRqT2RF" }
  }'

See Saved cards & recurring for how to obtain the payment_method_id.

4. Handle the result#

Status What to do
succeeded Fulfil the order.
requires_capture Authorized; capture when ready.
requires_customer_action Redirect the customer to next_action.redirect_to_url to complete 3D Secure.
processing Wait for the webhook or retrieve the payment later.
failed Show error_message and ask for another card.

Idempotency and retries#

Network errors happen. Before retrying a payment creation, list or retrieve to check whether the first attempt went through, or pass your own unique payment_id so a duplicate attempt is rejected with HE_01 instead of charging twice:

json
{ "payment_id": "order_58213_attempt_1", "amount": 6540, "currency": "EUR" }

Keep your secret key on your backend and log payment_id with every order.