Add to checkout
Integrate Fonix pay-by-mobile payments using Pay.com.js.
Fonix is available through Pay.com.js only. You can let Universal checkout render it, or build your own button with Headless checkout.
The server-to-server API (POST /v1/charges) does not accept Fonix as a
payment method.
Before starting, make sure Fonix is enabled on your Pay.com account. See the Fonix overview for prerequisites and dashboard configuration.
Create a payment session
Create a payment session on your server with
POST /v1/sessions/payment
and include "fonix" in the payment_method_types array.
{
"amount": 500,
"currency": "gbp",
"customer_reference_id": "cust-001",
"payment_method_types": ["card", "fonix"]
}Amounts are in minor units (the smallest currency unit). For example, 500
is £5.00. Fonix has a maximum of £40 per transaction and £240 per month per
customer. customer_reference_id is required and is your own identifier for
the customer.
Pass the client_secret from the response to your frontend to
initialize the SDK. Pay.com renders the Fonix option automatically
once the session is loaded.
Universal checkout
Fonix renders automatically in Universal checkout when it
is in the session's payment_method_types. No additional code is needed
beyond the standard SDK initialization. See
Universal checkout
for setup instructions.
Headless checkout
Use Headless checkout when you want to control the user interface and collect the customer's mobile number yourself.
Check whether Fonix is available for the current session after
initializing the checkout instance.
checkout.getPaymentMethods()
returns the session's payment methods as objects
({ paymentMethodType, name, redirect?, fields? }):
const methods = await checkout.getPaymentMethods()
const fonix = methods.find((m) => m.paymentMethodType === 'fonix')
if (fonix) {
// Show your Fonix payment option.
// fonix.fields, when present, lists the inputs to collect.
}Attach handleFonix to your Fonix button's click handler. Pass the
values you collected as the second argument, keyed by each field's
id:
async function handleFonix(phone) {
try {
await checkout.headless('fonix', { phone })
} catch (error) {
console.log('Payment failed:', error.message)
}
}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.
Sandbox behavior
In the sandbox, Pay.com uses an Alternate Payments Redirect Simulator instead of a real mobile operator. The simulator displays a pre-filled Payment ID and lets you choose a Payment Status and Result Code before submitting.
In the live environment (sessions and API calls on https://api.pay.com/v1 with
an sk-pay-com-live- key), the customer confirms the payment on their real
mobile phone.
Base your tests on the charge status and webhook events, not on SDK callbacks.
Simulator payment statuses
The simulator provides four payment statuses to test different outcomes:
| Payment status | Expected result |
|---|---|
COMPLETED | Charge moves to succeeded. charge.succeeded webhook fires. |
PROCESSING | Charge is not final yet. Wait for charge.succeeded or charge.failed. |
FAILED | Charge moves to failed. charge.failed webhook fires. |
ERROR | Charge moves to failed. charge.failed webhook fires. |
Test scenarios
Run each scenario in the sandbox and check the charge status and the webhook event.
| Scenario | Test action | Expected result |
|---|---|---|
| Successful payment | Select COMPLETED in the simulator and click Submit | Charge status: "succeeded". charge.succeeded webhook fires. |
| Failed payment | Select FAILED or ERROR in the simulator and click Submit | Charge status: "failed". charge.failed webhook fires. |
| Customer abandons | Close the simulator without submitting | The charge doesn't succeed. When the payment session expires (60 minutes by default), the charge fails and charge.failed fires. |