Accept APMs with Universal checkout
Display alternative payment methods in Universal checkout's payment form, and handle each payment's result in the browser and on your server.
Universal checkout displays each alternative payment method in its payment form when the payment session includes it. The customer selects a method and clicks Pay, and Pay.com.js takes them to the method to approve the payment.
Requirements
Before you start, make sure you have:
- The methods enabled on your account and turned on in the Pay.com dashboard.
- A Universal checkout integration on your page.
- A webhook endpoint that receives charge events. See Webhooks.
Accept an APM payment
An APM payment with Universal checkout takes three steps.
- 1
Create a payment session
On your server, create a payment session with
POST /v1/sessions/payment, and add each method's type topayment_method_typesnext to"card". Each method's page lists its type, such as"ideal"for iDEAL.{ "amount": 10000, "currency": "eur", "customer_reference_id": "cust-001", "payment_method_types": ["card", "ideal", "skrill"] }Amounts are in the currency's minor unit, so
10000is €100.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.alternativessets how the form lists APMs. The default,'button', shows a button for each method that has one. A method without a button, and a method that asks the customer for details, such as iDEAL's bank, appear only in the radio layout. When the session includes one, setalternativesto'radio'.checkout.universal({ container: '#pay-com-checkout', alternatives: 'radio', })When the customer selects a method that asks for details, the form also displays its fields. Each method's page says whether it needs
'radio'and which fields it displays. - 3
Handle the result
When the customer selects a method and clicks Pay, Pay.com.js opens the method in a window over your page or in a new tab, depending on the method.
- 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. See Listen for webhooks. - In a window over your page: if the customer closes it, Pay.com.js calls
Test in the sandbox
Test with your sandbox API key (sk-pay-com-sandbox-...) and a payment session
created against https://api.sandbox.pay.com/v1. Sandbox payments never move
real funds. See Environments.
In the sandbox, a payment session with a method in payment_method_types
displays that method in the form. Some methods open a payment simulator in
place of the method's page, where you choose the payment's outcome. Each
method's Add to checkout page describes how to test it.
Next steps
- Universal checkout: Configure the payment form, its callbacks, and its style.
- Headless checkout for APMs: Build your own payment method selector instead.
- Payment methods: Find each method's type, fields, and options.