Add to checkout
Integrate PayPal payments using Pay.com.js or the REST API.
You can accept PayPal payments in three ways:
- Universal checkout: Pay.com.js displays PayPal in its payment form.
- Headless checkout: You build your own checkout UI, and Pay.com.js starts the PayPal payment when the customer selects it.
- Server-to-server: You create the charge from your server and redirect the customer to PayPal.
Before you start, ask your account manager to enable PayPal for your account, then turn it on in the Pay.com dashboard.
Universal checkout
Universal checkout displays PayPal in its payment form when the payment session includes it.
- 1
Create a payment session
On your server, create a payment session with
POST /v1/sessions/paymentand include"paypal"inpayment_method_types.{ "amount": 5000, "currency": "usd", "customer_reference_id": "cust-001", "payment_method_types": ["card", "paypal"] }Amounts are in the currency's minor unit, so
5000is $50.00.customer_reference_idis your own ID for the customer, and it's required. Return the session'sclient_secretto your page. - 2
Display the checkout
On your page, initialize Pay.com.js with the
client_secretand mount Universal checkout, as in Universal checkout. No method-specific configuration is required. - 3
Handle the result
When the customer selects PayPal and clicks Pay, Pay.com.js opens PayPal in a window over your page or in a new tab, depending on your account configuration.
- In a window over your page: if the customer closes it, Pay.com.js calls
onFailure. - In a new tab: your page asks the customer to finish there. If they close the tab, Pay.com.js keeps waiting for the payment's outcome.
When the customer finishes, Pay.com.js calls
onSuccessif the payment succeeded,onPendingif its result isn't final yet, oronFailureif it failed. Fulfill the order when you receive thecharge.succeededwebhook event. - In a window over your page: if the customer closes it, Pay.com.js calls
Headless checkout
With Headless checkout, you build your own checkout UI, and Pay.com.js starts the PayPal payment when the customer selects it.
- 1
Create a payment session
Create the payment session on your server as in Universal checkout, with
"paypal"inpayment_method_types, and initialize Pay.com.js with itsclient_secret. - 2
Check that PayPal is available
Call
checkout.getPaymentMethods(), and show your PayPal button only when the list includes it. Don't usecheckout.canMakePayments()for this, because it reports only Apple Pay and Google Pay.const methods = await checkout.getPaymentMethods() const paypal = methods.find((method) => method.paymentMethodType === 'paypal') - 3
Start the payment
When the customer selects PayPal, call
checkout.headless()with'paypal'.try { await checkout.headless('paypal') } catch (error) { // onFailure receives the error details too. }Pay.com.js opens PayPal in a window over your page or in a new tab, depending on your account configuration.
- In a window over your page: if the customer closes it, Pay.com.js calls
onFailure. - In a new tab: your page asks the customer to finish there. If they close the tab, Pay.com.js keeps waiting for the payment's outcome.
When the customer finishes, Pay.com.js calls
onSuccessif the payment succeeded,onPendingif its result isn't final yet, oronFailureif it failed. Fulfill the order when you receive thecharge.succeededwebhook event. - In a window over your page: if the customer closes it, Pay.com.js calls
Server-to-server
From your server, a PayPal payment takes three steps: create the charge, create a linked authentication session to obtain the redirect URL, and redirect the customer to PayPal.
- 1
Create the charge
Send
POST /v1/chargeswithsource_data.typeset to"paypal". Pay.com passessource_data.billing_detailsto PayPal to prefill its page for the customer.{ "amount": 5000, "currency": "usd", "source_data": { "type": "paypal", "billing_details": { "name": "Jane Smith", "email": "jane.smith@example.com", "address": { "country": "US" } } }, "customer_reference_id": "cust-001", "reference": "order-12345", "description": "Order #12345" }{ "id": "chrg_702172227948251136", "resource": "charge", "amount": 5000, "currency": "usd", "status": "requires_authentication", "payment_method_details": { "type": "paypal" }, "reference": "order-12345", "test_mode": true }The charge's
statusisrequires_authenticationuntil the customer approves the payment. - 2
Create a linked authentication session
Send
POST /v1/sessions/authentication/linkedwith the charge'sidasresourceand thereturn_urlto return the customer to.confirmdefaults totrue, so Pay.com completes the charge when the customer approves it. Each charge supports one linked authentication session.{ "resource": "chrg_702172227948251136", "return_url": "https://your-site.com/payment/complete" }{ "id": "sca_702172392511768576", "resource": "authentication_session", "status": "open", "return_url": "https://your-site.com/payment/complete", "url": "https://alternatives.sandbox.pay.com/authenticate?client_secret=...", "test_mode": true } - 3
Redirect the customer
Send the customer to the session's
urlwith a full-page redirect. After they approve or cancel the payment, PayPal redirects them back to yourreturn_url. Fulfill the order when you receive thecharge.succeededwebhook event, and handlecharge.failedas a canceled, declined, or abandoned payment.If the customer doesn't finish, the charge stays
requires_authenticationuntil the authentication session expires (60 minutes by default). It then moves tofailed, and thecharge.failedevent fires.
PayPal options
Set these in payment_method_options.paypal on the payment session or the charge.
| Option | Type | Description |
|---|---|---|
name_verification | boolean | Whether to perform customer name verification. |
More PayPal options
These options change the server-to-server flow.
| Option | Effect |
|---|---|
| Authorize only (hold) | POST /v1/charges has no capture field. Send the same body to POST /v1/holds instead, and create the linked authentication session with the hld_… ID. After approval, capture with POST /v1/holds/{id}/capture (optionally with amount_to_capture) or void with POST /v1/holds/{id}/cancel. |
source_data.setup_future_usage: "off_session" | Saves the customer's PayPal account as a reusable pm_paypal_… payment method on approval. On the SDK path, set setup_future_usage on the payment session instead. |
Testing
Test against https://api.sandbox.pay.com/v1 with your sk-pay-com-sandbox- API key.
Test transactions never move real funds. See
Environments.
PayPal sandbox account
In the sandbox, PayPal payments complete in PayPal's own sandbox, so you need a PayPal sandbox personal account. Create one in the PayPal Developer Dashboard under PayPal's Testing tools → Sandbox accounts, or ask your Pay.com account manager for the personal account set up for your sandbox merchant.
Sandbox behavior
In the sandbox, Pay.com redirects to the PayPal sandbox environment
(PayPal's sandbox.paypal.com site) instead of the live PayPal site.
PayPal's sandbox is a full replica of the PayPal checkout experience,
including the login page, funding source selection, and payment
confirmation.
- SDK integration: the PayPal sandbox login opens in a window over your page or in a new tab, depending on your account configuration.
- Server-to-server integration: the linked authentication session
returns a redirect
url. Opening this URL in a browser redirects to the PayPal sandbox login page.
Log in with your PayPal sandbox personal account, select PayPal balance
as the funding source, and click Complete Purchase to complete the
test payment. After approval, PayPal redirects back to your
return_url and the charge moves to succeeded.
Test scenarios
Run each scenario against the PayPal sandbox.
| Scenario | Test action | Expected result |
|---|---|---|
| Successful payment | Log in to the PayPal sandbox, select PayPal balance, and click Complete Purchase | Charge status: "succeeded". charge.succeeded webhook fires. SDK onSuccess callback fires. |
| Customer abandons | Close the PayPal sandbox window or click Cancel and return to store | Charge stays in requires_authentication until the authentication session expires (60 minutes by default), then moves to failed. charge.failed webhook fires. |
| Hold and capture | Create a hold with POST /v1/holds, complete the PayPal sandbox flow, then capture the hld_… ID with POST /v1/holds/{id}/capture | The hold is captured and hold.succeeded fires. |
| Save payment method | Create a charge with source_data.setup_future_usage: "off_session" and complete the PayPal sandbox flow | A reusable pm_paypal_… payment method is saved. |