createOrder() is the server-side operation used to start a Universal Payment Gateway checkout. It creates a provider-neutral payment session from an available payment method and returns the checkout instructions for that gateway.
The integration rules on this page apply to every AvraAPI SDK. Laravel 1.2.0 uses AvraAPI::payment() and Node.js SDK 1.2.0 uses client.payment() with the same typed payment options and server-only safety boundary.
The safe initiation flow
- Your backend creates a unique pending order.
- Your server checks
availability()and selects one returned method. - Your server calls
createOrder(). - Your server stores the returned
completionContextagainst that pending order. - Your browser receives only the public checkout instructions and follows the supported checkout mode.
1. Choose a GatewayCode from availability
Do not accept a gateway name from an untrusted browser request without checking it against the current server-side availability result. A method can become unavailable when the project is paused, its UPG slot is released, its configuration is disabled, or the selected origin is not allowed.
- PHP
- Laravel
- Node.js
payhere, marxpay, directpay, payplus, webxpay, koko, onepay, and stripe. Recognition is not entitlement: availability() is the source of truth for what this project can use now.
2. Choose the CheckoutMode
Use the mode returned by availability for the chosen gateway. Do not invent a mode because a provider supports another style outside AvraAPI.
- PHP
- Laravel
- Node.js
3. Set order details
orderId, items, amount, and currency are required. Use an order ID that is unique in your merchant system. Pass money as a positive decimal string with at most two decimal places; never calculate or serialize money as a floating-point value.
- PHP
- Laravel
- Node.js
4. Provide the customer object
The SDK requiresfirst_name, last_name, email, phone, address, city, and country. You may provide address_line_1 and address_line_2 instead of address; the SDK combines the non-empty lines into the required address value.
- PHP
- Laravel
- Node.js
5. Set trusted return, cancel, and webhook URLs
Build URLs in your backend from registered configuration. One shared completion handler or controller can serve every gateway when its gateway-scoped callback and return routes dispatch safely. Do not copy a return URL, webhook URL, or host name from a buyer request.- PHP
- Laravel
- Node.js
completePayment() in your backend. Use the exact configured URL where a gateway requires it; for example, Stripe requires the configured Success Return URL and Dashboard webhook URL.
6. Optional: set merchantDomain
merchantDomain identifies the configured domain for method discovery and origin policy checks. It is optional. When you omit it, AvraAPI resolves the configured project default. Supply it when your checkout uses a specific registered host.
- PHP
- Laravel
- Node.js
Origin rules are provider-specific. Do not assume that an allowed domain rule for one gateway automatically applies to every other gateway.
7. Optional: pass providerOptions
providerOptions holds gateway-specific, non-secret checkout options. It is optional; keep it empty for the common flow. Add only values documented for the selected gateway in Gateway-wise Functions; never put API keys, gateway secrets, signing secrets, or buyer-controlled arbitrary data here.
- PHP
- Laravel
- Node.js
8. Optional: select the gateway environment
Gateway environment selects the vaulted Sandbox or Production profile. It is separate from your AvraAPI client environment and must stay server-side.Configure a default environment in PHP or Laravel
For one common environment across all gateways, this is enough:- PHP
- Laravel
- Node.js
Override selected gateways in PHP or Laravel
UseAPIX_PAYMENT_GATEWAY_ENV_OVERRIDES only when one or more gateways need a different environment from the default. The format is a comma-separated gateway:sandbox or gateway:production list.
- PHP
- Laravel
- Node.js
Override an environment for one order
You can also select a gateway environment for one server-side order. This is optional and takes priority over the configured default and override list. Never let browser input select it.- PHP
- Laravel
- Node.js
9. Call createOrder()
Bring the required and optional options together with one named-argument call. Omit optional named arguments when you do not need them.
- PHP
- Laravel
- Node.js
Store the PaymentSession correctly
PaymentSession contains gateway, mode, status, expiresAt, checkout, requestId, flow, binding, verification, and completionContext.
Store the completionContext with the pending merchant order before responding to the browser. It binds future provider evidence to this payment session.
- PHP
- Laravel
- Node.js
Return only public checkout instructions
Your frontend normally needs the gateway, mode, expiry, andcheckout object. Keep the server-side completion data in your own order record.
- PHP
- Laravel
- Node.js
checkout is gateway- and mode-specific. Pass it unchanged to the supported browser handoff; do not attempt to construct provider checkout instructions yourself.
Continue with Payment Response & Completion.