Skip to Content
Docs

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. 1

    Create a payment session

    On your server, create a payment session with POST /v1/sessions/payment, and add each method's type to payment_method_types next 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 10000 is €100.00. customer_reference_id is your own ID for the customer, and it's required. Return the session's client_secret to your page.

  2. 2

    Display the checkout

    On your page, initialize Pay.com.js with the client_secret and mount Universal checkout, as in Universal checkout.

    alternatives sets 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, set alternatives to '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. 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 onSuccess if the payment succeeded, onPending if its result isn't final yet, or onFailure if it failed. Fulfill the order when you receive the charge.succeeded webhook event. See Listen for webhooks.

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

Was this page helpful?