Create a PaymentIntent from the merchant backend to initialize a payment and obtain the values required by XPay Element.
Before you begin
Configure XPay API authentication. Keep the API key and API signature secret on the merchant backend.
Create the PaymentIntent
Send an authenticated request to:
POST {{base_url}}/public/v1/payment/intentThe following request contains the minimum fields used by the card-payment flow:
{
"amount": 500,
"currency": "PKR",
"payment_method_types": "card",
"customer": {
"name": "Ayesha Khan",
"email": "ayesha@example.com",
"phone": "{{customer_phone}}"
},
"metadata": {
"order_reference": "order-1001"
}
}The amount is expressed in the unit required by the XPay API. Confirm the applicable unit, precision, and optional fields in the Create Payment Intent API before using production amounts.
Use the response
The response below is shortened to the fields needed by the next integration step:
{
"success": true,
"data": {
"_id": "xpay_pi_example",
"pi_client_secret": "xpay_pi_example_cs_example",
"pi_status": "requires_payment_method",
"encryptionKey": "{{encryption_key}}"
}
}On the merchant backend:
- Store
data._idagainstmetadata.order_reference. - Keep the complete API response out of frontend logs.
- Return
data.pi_client_secretanddata.encryptionKeyto the trusted checkout frontend. - Use the PaymentIntent ID to reconcile later webhook notifications.
Choose the capture method
By default, XPay captures a successful payment automatically. To authorize an amount and capture it later, include:
{
"capture_method": "manual"
}A successfully authorized manual-capture payment moves to requires_capture. Continue with Capture a payment later.
Next steps
- Collect payment details with XPay Element.
- Confirm the payment.
- See all supported fields in the Create Payment Intent API.