Skip to Content
Docs

Add to checkout

Integrate Neosurf payments using Pay.com.js or the REST API.

You can accept Neosurf payments in three ways:

  • Universal checkout: Pay.com.js displays Neosurf in its payment form.
  • Headless checkout: You build your own checkout UI, and Pay.com.js starts the Neosurf payment when the customer selects it.
  • Server-to-server: You create the charge from your server and redirect the customer to Neosurf.

Before you start, ask your account manager to enable Neosurf for your account, then turn it on in the Pay.com dashboard.

Universal checkout

Universal checkout displays Neosurf in its payment form when the payment session includes it.

  1. 1

    Create a payment session

    On your server, create a payment session with POST /v1/sessions/payment and include "neosurf" in payment_method_types.

    {
      "amount": 5000,
      "currency": "eur",
      "customer_reference_id": "cust-001",
      "payment_method_types": ["card", "neosurf"]
    }

    Amounts are in the currency's minor unit, so 5000 is €50.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. No method-specific configuration is required.

  3. 3

    Handle the result

    When the customer selects Neosurf and clicks Pay, Pay.com.js opens Neosurf in a new tab. Meanwhile, 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.

Headless checkout

With Headless checkout, you build your own checkout UI, and Pay.com.js starts the Neosurf payment when the customer selects it.

  1. 1

    Create a payment session

    Create the payment session on your server as in Universal checkout, with "neosurf" in payment_method_types, and initialize Pay.com.js with its client_secret.

  2. 2

    Check that Neosurf is available

    Call checkout.getPaymentMethods(), and show your Neosurf button only when the list includes it. Don't use checkout.canMakePayments() for this, because it reports only Apple Pay and Google Pay.

    const methods = await checkout.getPaymentMethods()
    const neosurf = methods.find((method) => method.paymentMethodType === 'neosurf')
  3. 3

    Start the payment

    When the customer selects Neosurf, call checkout.headless() with 'neosurf'.

    try {
      await checkout.headless('neosurf')
    } catch (error) {
      // onFailure receives the error details too.
    }

    Pay.com.js opens Neosurf in a new tab. Meanwhile, 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.

Server-to-server

From your server, a Neosurf payment takes three steps: create the charge, create a linked authentication session to obtain the redirect URL, and redirect the customer to Neosurf.

  1. 1

    Create the charge

    Send POST /v1/charges with source_data.type set to "neosurf". Pay.com passes source_data.billing_details to Neosurf to prefill its page for the customer.

    {
      "amount": 5000,
      "currency": "eur",
      "source_data": {
        "type": "neosurf",
        "billing_details": {
          "address": {
            "country": "FR"
          }
        }
      },
      "customer_reference_id": "cust-001",
      "reference": "order-12345",
      "description": "Order #12345"
    }

    The charge's status is requires_authentication until the customer approves the payment.

  2. 2

    Create a linked authentication session

    Send POST /v1/sessions/authentication/linked with the charge's id as resource and the return_url to return the customer to. confirm defaults to true, 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"
    }
  3. 3

    Redirect the customer

    Send the customer to the session's url with a full-page redirect. After they approve or cancel the payment, Neosurf redirects them back to your return_url. Fulfill the order when you receive the charge.succeeded webhook event, and handle charge.failed as a canceled, declined, or abandoned payment.

    If the customer doesn't finish, the charge stays requires_authentication until the authentication session expires (60 minutes by default). It then moves to failed, and the charge.failed event fires.

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.

Pay.com provides the test PINs you need to simulate each scenario below. Contact your Pay.com account manager if you haven't received them.

Test scenarios

Each scenario uses one of the test PINs from your account manager.

ScenarioTest actionExpected result
Successful paymentEnter a valid test PIN with sufficient balanceCharge status: "succeeded". charge.succeeded webhook fires. SDK onSuccess callback fires.
Insufficient balanceEnter a test PIN whose balance is lower than the charge amountCharge status: "failed" and charge.failed webhook fires. SDK onFailure callback fires.
Invalid PINEnter an incorrect or malformed PINCharge status: "failed" and charge.failed webhook fires. SDK onFailure callback fires.
Expired voucherEnter a test PIN for an expired voucherCharge status: "failed" and charge.failed webhook fires. SDK onFailure callback fires.
Was this page helpful?