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.
| Zone | Method | What it handles |
|---|---|---|
| Universal | checkout.universal() | Apple Pay, Google Pay, and APMs |
| Headless | checkout.headless() | Custom card form only |
Requirements
Before you begin:
- Install and initialize Pay.com.js.
- Apple Pay and Google Pay must be activated on your Pay.com merchant account. Check the Payment methods section of the Pay.com dashboard to confirm availability.
- For Apple Pay, you must still register every domain that shows the Apple Pay button with Pay.com. See the Apple Pay requirements.
Build the hybrid checkout
Create the session on your server, then set up Pay.com.js and both zones in the browser.
- 1
Create a payment session
Create a payment session on your server.
amountis in minor units (5000is €50.00), andcustomer_reference_id(your own identifier for the customer) is required. Includecardand any alternative payment methods you want to offer. Apple Pay and Google Pay are included automatically whencardis 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" } } }'{ "id": "ps_773506178498954240", "resource": "payment_session", "amount": 5000, "currency": "eur", "customer_reference_id": "cust-jane-smith-001", "payment_method_types": [ "card", "paypal", "paysafecard", "applepay", "googlepay" ], "client_secret": "eyJhbG...", "status": "open" } - 2
Initialize the SDK
Pass your Pay.com merchant ID (from the Developers tab of the Pay.com dashboard) to
Pay.com()to create apayinstance. Don't pass the session ID. The session is identified by itsclient_secretin the next step.const pay = await Pay.com({ identifier: 'YOUR_MERCHANT_ID', })In the live environment, create the session on
https://api.pay.com/v1with ansk-pay-com-live-key. With@pay-com/js, also passlive: truetoPay.com(). - 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, andonFailurefire regardless of whether the customer paid with a wallet, an APM, or the card form.onPendingfires when the result isn't final yet, for example with some APMs. Wait for the webhook before you fulfill the order. - 4
Render wallets and APMs in the universal zone
Call
checkout.universal()with apaymentMethodsarray that includes wallets and any alternative payment methods. Excludecard, 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.submitButtontofalsebecause each wallet and APM button handles submission on its own. - 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 intry/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
- Render the checkout form:
All
checkout.universal()options. - Submit a headless payment:
All
checkout.headless()options.