Standard QR Flow - Web Button
An embeddable, self-contained JavaScript payment button that lets any merchant website accept Fex wallet payments with a few lines of code.How It Works
- Merchant calls
FexPay.pay()with amount, currency, and optional description. - The widget creates a payment intent on the Fex backend and renders a modal with the QR code.
- The customer opens the Fex mobile app, scans the QR, and approves the payment.
- The widget polls the backend every 5 seconds (up to 5 minutes) and automatically detects when the payment completes.
- On completion, the
onSuccesscallback fires and the success screen is shown.
FexPay.confirm() to resolve the payment immediately without waiting for the next poll cycle.
Installation
window.FexPay.
Quick Start
API Reference
FexPay.init(config)
Must be called once before any pay() call. Typically called on page load.
Error if merchantId is missing.
FexPay.pay(params)
Opens the payment modal, creates a payment intent, and starts polling for completion. Returns a Promise that resolves with the created PaymentIntent object once the modal appears (not when payment completes — use onSuccess for that).
onSuccess(intent)
Called with the completed PaymentIntent object:
onError(error)
Called with an error object:
onCancel()
Called when the customer clicks the × button or the backdrop. No arguments.
Example with all params
FexPay.confirm(paymentIntentId?)
Tells the widget that a payment has been confirmed — typically called from your own webhook handler after the Fex backend notifies your server. Stops polling immediately, fetches the latest intent data, and shows the success screen.
Webhook Integration
UsingcallbackUrl + FexPay.confirm() is the most reliable way to detect payment completion — it avoids waiting for the next 5-second poll cycle.
Recommended flow
Server-side webhook handler (Node.js example)
Client-side with WebSocket
Client-side with Server-Sent Events
Polling Behaviour
When no webhook is used, the widget polls automatically:Modal States
The success screen auto-closes after 3 seconds.
Security Considerations
- The widget sends your Merchant ID as an
X-Merchant-IDheader on every API request. This ID is visible in client-side code — it is a public identifier, not a secret. - Never embed API keys or secrets in the widget configuration. Authentication of payment outcomes should be verified server-side using the webhook.
- The modal is rendered in a Shadow DOM (
mode: closed) so widget styles are fully isolated from your page and vice versa. - All dynamic text inserted into the modal is HTML-escaped to prevent XSS.
Browser Support
Requires:
fetch, Promise, Shadow DOM, Intl.NumberFormat — all standard in modern browsers. No polyfills needed.
Demo
Openwidget/demo.html directly in a browser (or serve it locally) to test the widget interactively:
