Search Documentation
Search across all documentation pages, APIs and guides.
OnePay API Integration Guide
This guide provides the foundational steps for integrating with the OnePay platform securely and efficiently, whether you are utilizing direct API calls, our frontend JavaScript library, or our pre-built e-commerce plugins.
1. Authentication
All API requests require authentication using an API key. You can obtain your API key from the developer dashboard.
Include your API key or App Token in the Authorization header of all requests:
Authorization: YOUR_APP_TOKEN
2. Error Handling
The OnePay API uses conventional HTTP response codes to indicate the success or failure of a request.
| HTTP Code | Description |
|---|---|
200 | The checkout link has been successfully created. |
400 | The request body is invalid. Detailed error information will be included in the response (e.g., Invalid app id, Invalid amount, Invalid app state, Currency type not available for app). |
401 | The Authorization header is either missing, contains an invalid application token, or includes an incorrect hash. |
429 | Too many requests have been made within a one-second period. |
3. API Implementation (Direct REST APIs)
If you are building a custom server-side integration, follow these standard steps to process a payment:
- Create Items (Optional): Use the Create Item API to register specific products and store the returned
item_id. You can verify and update these items using the Get Item and Update Item APIs. - Generate Hash Key: Concatenate the following string exactly:
app_id + currency + amount + <<YOUR HASH SALT>>. Apply the SHA-256 algorithm to this string to generate your secure hash. - Create Payment Request: Call the Create Transaction API with your data and hash. This will return a URL to redirect customers to the payment gateway.
- Track Payment Status: Poll the Get Transaction API endpoint periodically to check the payment's completion status.
- Callback Response: Configure your callback URL in the OnePay portal APP section. OnePay will send a POST request with a JSON payload containing
transaction_id,status,status_message, andadditional_dataupon transaction completion.
4. OnePayJS Integration
OnePayJS is a lightweight JavaScript library that enables an on-site payment gateway overlay, eliminating the need for page redirections.
Steps to Implement:
- Import the script into your HTML head or body:<script src="https://storage.googleapis.com/onepayjs/onepayv2.js"></script>
- Retrieve your
appid,hashToken, andapptokenfrom the OnePay Dashboard. - Configure the
window.onePayDataobject with your transaction details. - Set up event listeners for
onePaySuccessandonePayFailto handle the payment outcome.
JavaScript Configuration Example:
window.onePayData = {appid: "80NR1189D04CD635D8ACD",hashToken: "GR2P1189D04CD635D8AFD",amount: 100.00,orderReference: "7Q1M1187AE",customerFirstName: "Johe",customerLastName: "Dohe",customerPhoneNumber: "+94771234567",customerEmail: "test@gmail.com",transactionRedirectUrl: "https://www.google.com.au",additionalData: "returndata",apptoken: "ca00d67bf74d77b01fa26dc6780d7ff9522d8f82d30ff813d4c605f2662cea9ad332054cc66aff68.EYAW1189D04CD635D8B20",currency: "LKR"};window.addEventListener("onePaySuccess", function (e) {const successData = e.detail;console.log("Payment SUCCESS ", successData);});window.addEventListener("onePayFail", function (e) {const failData = e.detail;console.log("Payment FAIL", failData);});
5. Platform Plugins
OnePay offers pre-built integrations for popular frameworks and e-commerce platforms.
- Prerequisite: Ensure WooCommerce is installed.
- Installation: Search for "Onepay Payment Gateway" in the WordPress Plugin Directory, install, and activate.
- Configuration: Enter your App ID, App Token, and Hash Salt from the merchant portal.
- Installation: Install the "Onepay Payment Gateway" app from the Shopify App Store.
- Configuration: Enter your Shopify domain, grant permissions, and configure the App ID, App Token, and Hash Salt.
- Installation: Unzip the provided WHMCS plugin files. Copy files to
modules/gatewaysandgateways/callback. - Configuration: Enable OnePay in the WHMCS admin panel and input your credentials.
- Installation: Add
ipg_flutter: ^1.1.3to yourpubspec.yaml. - Android: Add INTERNET permission to
AndroidManifest.xml. - Usage: Initialize using
Ipg.init()and trigger payment methods.
6. Test Card Details
Use the following test card credentials for testing your integration in sandbox mode:
| Card Type | Card Number | Expiration Date | CVV |
|---|---|---|---|
Visa | 4508750015741019 | 01/39 | 100 |
Visa | 4012000033330026 | 01/39 | 100 |
Master | 5123450000000008 | 01/39 | 100 |
Master | 5111111111111118 | 01/39 | 100 |
On This Page