Create your first payment
Process a test card payment in the sandbox using a payment session and Pay.com.js.
This quickstart walks through one successful card payment in the sandbox. Your server creates a payment session, your page renders Universal checkout with Pay.com.js, you pay with a test card, and your server confirms the result. No real money moves.
This quickstart covers the happy path. For server-to-server charges, error handling, and 3D Secure, see Create a charge.
Prerequisites
Before you start, make sure you have:
- A Pay.com sandbox account (set up your account if you don't have one yet).
- Your sandbox key (
sk-pay-com-sandbox-), which works only againsthttps://api.sandbox.pay.com/v1. See API keys and Environments. - Your merchant ID from the Developers tab of the Pay.com dashboard.
Process a test payment
Follow these five steps to take a card payment in the sandbox.
- 1
Create a payment session (server-side)
From your backend, create a payment session with
POST /v1/sessions/payment. The session holds the amount and currency, and returns aclient_secretthat your page passes to Pay.com.js.amountis in minor units, the smallest unit of the currency. For example,1000is $10.00.currencyis a lowercase ISO 4217 code, such asusd.customer_reference_idis required. Pass your own identifier for the customer, and Pay.com creates or reuses a customer with that reference.payment_method_types: ["card"]limits this walkthrough to cards. Omit it to offer every payment method enabled on your account.
curl -X POST https://api.sandbox.pay.com/v1/sessions/payment \ -u ':sk-pay-com-sandbox-…' \ -H "Content-Type: application/json" \ -H "idempotency-key: $(uuidgen)" \ -d '{ "amount": 1000, "currency": "usd", "customer_reference_id": "cust-quickstart-001", "billing_details": { "email": "test@example.com" }, "payment_method_types": ["card"], "payment_method_options": { "card": { "duplicate_card_check": false } } }'Return
client_secretto your page. Keep your API key on the server and never send it to the browser. Theclient_secretis returned only when you create the session and expires after the session'sduration(60 minutes by default). If you lose it, refresh the session to get a new one.duplicate_card_check: falsestops the sandbox from declining a test card number that was already used (decline_code: duplicate_card). Use it only in the sandbox. In live, keep duplicate card detection enabled so the same card can't be used across multiple customers. - 2
Load and initialize Pay.com.js (client-side)
Load Pay.com.js and initialize it with your merchant ID. Both options below work in the sandbox. The npm package loads the script asynchronously (
await Pay.com(...)), while the script tag exposeswindow.Pay.com(...)synchronously once loaded.npm install @pay-com/jsimport Pay from '@pay-com/js' // In live, add `live: true`. const pay = await Pay.com({ identifier: 'YOUR_MERCHANT_ID' })identifieris your Pay.com merchant ID, not the payment session ID. The session is identified by theclient_secretyou pass in the next step. See Install and initialize for more installation options. - 3
Render the checkout
Add a container to your page:
<div id="payment-element"></div>Create a checkout with the
client_secretfrom step 1, then render the Universal checkout form into the container:const checkout = pay.checkout({ clientSecret: 'CLIENT_SECRET_FROM_STEP_1', // fetched from your server onSuccess: (payment) => { // payment.transaction is the charge ID, for example chrg_686511195653406720 console.log('Payment succeeded', payment.transaction, payment.status) }, onPending: (payment) => { // The result isn't final yet. Wait for the webhook in step 5. console.log('Payment pending', payment.transaction) }, onFailure: (error) => { console.log('Payment failed', error.message) }, }) checkout.universal({ container: '#payment-element' })The Universal checkout form collects card details and handles 3D Secure when the issuer requires it. When an attempt is declined,
onFailurefires so you can displayerror.messageto the customer. To have the form show the message instead, passtoggles: { displayFailureMessages: true }topay.checkout(). Browser callbacks are for updating your page only. Confirm every payment on your server (step 5) before fulfilling the order. - 4
Pay with a test card
Enter the test card
4242 4242 4242 4242with any future expiration date (for example,12/28) and a 3-digit CVV such as123, then submit the form.onSuccessfires with the new charge.To try a decline, use
4000 0053 5708 6322(insufficient funds).onFailurefires, and the customer can try again in the same form, up to the session'smax_attempts(5 by default). See test cards for more decline and 3DS scenarios. - 5
Confirm the payment on your server
Use either of these to confirm the result server-side:
- Webhook (recommended): Subscribe to
charge.succeededandcharge.failed, or topayment_session.completedandpayment_session.failed. See webhooks, and verify the signature of every event before you act on it. - API: Retrieve the charge with the charge ID from
onSuccess(payment.transaction). You can also retrieve the session. Itschargefield holds the charge ID once a payment succeeds.
curl https://api.sandbox.pay.com/v1/charges/chrg_686511195653406720 \ -u ':sk-pay-com-sandbox-…'status: "succeeded"means the charge was approved and the funds captured.paidstaysfalseuntil the funds are settled to your bank account later. The charge also appears in your Pay.com dashboard under the sandbox. - Webhook (recommended): Subscribe to
Try the API directly (server-to-server)
If you only want to see a charge in the sandbox from the command line, you can create a charge with POST /v1/charges and a test card, with no session or Pay.com.js.
curl -X POST https://api.sandbox.pay.com/v1/charges \
-u ':sk-pay-com-sandbox-…' \
-H "Content-Type: application/json" \
-H "idempotency-key: $(uuidgen)" \
-d '{
"amount": 1000,
"currency": "usd",
"customer_reference_id": "cust-quickstart-001",
"source_data": {
"type": "card",
"card": {
"number": "4242424242424242",
"expiry_month": "12",
"expiry_year": "2028",
"cvv": "123",
"name": "Test User"
}
},
"payment_method_options": {
"card": {
"duplicate_card_check": false
}
}
}'Go live
When Pay.com has turned on live for your account, change three things:
- Call
https://api.pay.com/v1with yoursk-pay-com-live-API key. - Create your sessions with the live API. Pay.com.js works in the environment of the session you give it. With
@pay-com/js, also passlive: truetoPay.com(). - Remove
duplicate_card_check: false.
See Go live for everything that changes in live and a checklist.
Next steps
Extend this payment flow with the full charge guide, webhooks, holds, and more testing.
- Create a charge: Server-to-server charges, error handling, and 3D Secure.
- Set up webhooks: Receive real-time notifications for payment events.
- Hold and capture: Authorize now and capture later.
- Test your integration: Test cards, simulate endpoints, and webhooks in the sandbox.