Skip to Content
Docs

Hybrid checkout

Combine Universal checkout and Headless checkout on the same page to use hosted wallet buttons with your own card form.

A hybrid checkout combines Universal checkout and Headless checkout on the same page. checkout.universal() renders the wallet buttons and alternative payment method buttons. Your own card form submits card details through checkout.headless(), so you fully control it.

Use a hybrid checkout when you want wallet buttons (Apple Pay, Google Pay) and a fully custom card form, without registering your own developer accounts with Apple or Google. Pay.com handles merchant validation.

How the zones split

Both zones share a single checkout instance and a single payment session.

ZoneMethodWhat it handles
Universalcheckout.universal()Apple Pay, Google Pay, and APMs
Headlesscheckout.headless()Custom card form only

In this setup, the universal zone renders the wallet and APM buttons, so your headless zone only submits cards. checkout.headless() itself isn't limited to cards. It also takes wallets and APMs, as in Headless checkout.

Requirements

Before you begin:

Build the hybrid checkout

Create the session on your server, then set up Pay.com.js and both zones in the browser.

  1. 1

    Create a payment session

    Create a payment session on your server. amount is in minor units (5000 is €50.00), and customer_reference_id (your own identifier for the customer) is required. Include card and any alternative payment methods you want to offer. Apple Pay and Google Pay are included automatically when card is present.

    curl -X POST https://api.sandbox.pay.com/v1/sessions/payment \
      -u ':sk-pay-com-sandbox-…' \
      -H "content-type: application/json" \
      -d '{
        "currency": "eur",
        "amount": 5000,
        "customer_reference_id": "cust-jane-smith-001",
        "payment_method_types": ["card", "paypal", "paysafecard"],
        "return_url": "https://example.com/checkout/complete",
        "billing_details": {
          "name": "Jane Smith",
          "address": { "country": "IT" }
        }
      }'

    Always include a return_url. Wallet and APM payments may redirect the customer to an external page. The return_url tells Pay.com where to send the customer after the payment completes.

  2. 2

    Initialize the SDK

    Pass your Pay.com merchant ID (from the Developers tab of the Pay.com dashboard) to Pay.com() to create a pay instance. Don't pass the session ID. The session is identified by its client_secret in the next step.

    const pay = await Pay.com({
      identifier: 'YOUR_MERCHANT_ID',
    })

    In the live environment, create the session on https://api.pay.com/v1 with an sk-pay-com-live- key. With @pay-com/js, also pass live: true to Pay.com().

  3. 3

    Create a checkout instance

    Create a single checkout instance. Both the universal and headless zones use this same instance.

    const checkout = pay.checkout({
      clientSecret: CLIENT_SECRET,
      onSuccess: (payment) => {
        console.log('Payment succeeded:', payment)
      },
      onPending: (payment) => {
        console.log('Payment pending:', payment)
      },
      onFailure: (error) => {
        console.log('Payment failed:', error)
      },
    })

    onSuccess, onPending, and onFailure fire regardless of whether the customer paid with a wallet, an APM, or the card form. onPending fires when the result isn't final yet, for example with some APMs. Wait for the webhook before you fulfill the order.

  4. 4

    Render wallets and APMs in the universal zone

    Call checkout.universal() with a paymentMethods array that includes wallets and any alternative payment methods. Exclude card, since your own card form handles cards in the headless zone.

    checkout.universal({
      container: '#universal-zone',
      paymentMethods: ['applepay', 'googlepay', 'paypal', 'paysafecard'],
      toggles: { submitButton: false },
    })
    <div id="universal-zone"></div>

    Set toggles.submitButton to false because each wallet and APM button handles submission on its own.

  5. 5

    Build your card form in the headless zone

    Create your own card form with standard HTML inputs. When the customer submits the form, call checkout.headless() with the card data. checkout.headless() also rejects when the payment fails, so wrap it in try/catch.

    async function handleCardPayment() {
      try {
        await checkout.headless('card', {
          number: '4242424242424242',
          name: 'Jane Smith',
          expirationMonth: '12',
          expirationYear: '28',
          cvv: '123',
        })
      } catch (error) {
        // onFailure has also been called. Let the customer try again.
      }
    }

Listen for webhooks

Hybrid checkout payments use the same webhook events as any other payment. Subscribe to payment_session.completed (paid) and payment_session.failed (ended without a successful charge) on your backend to confirm the outcome independently of the browser.

Verify each event's signature with the Pay-Signature header and your endpoint's signing secret (HMAC SHA-256) before you act on it. See Webhooks for setup instructions and verify webhook signatures for the steps.

Next steps

Was this page helpful?