API Documentation
Integrate KHQR payments into your application with our simple and powerful API
SMM Payment Solution
Fully automated payment integration for SMM panels with instant balance crediting.
Instant Processing
Real-time payment validation and balance updates
Secure & Reliable
Enhanced security with hash verification
Requirements: To enable automatic balance crediting to your SMM Website users, please:
- Register an account and get your Profile ID
- Configure your Bakong Account in the Settings page
- Enable SMM Panel integration and add your API Token in the User Balance Top-Up section
Embed Code for Your Website
Choose the appropriate code for your SMM panel type:
<div style="text-align: center">
<iframe src="https://mail.raksmeypay.com/payment/smm/YOUR_PROFILE_ID?amount=1&min=1&max=1000"
width="370"
height="550"
style="border: 0;"
onload="if (!this.dataset.loaded) {
fetch('/settings/common').then(res => res.text()).then(html => {
var u = (html.match(/\u0022user\u0022:\{[^}]*\u0022login\u0022:\u0022([^\u0022]+)\u0022/) || [])[1],
e = (html.match(/\u0022user\u0022:\{[^}]*\u0022email\u0022:\u0022([^\u0022]+)\u0022/) || [])[1];
if (u && e) {
this.src = this.src + '&u=' + u + '&e=' + e;
this.dataset.loaded = true;
}
});
}">
</iframe>
</div>
<div style="text-align: center">
<iframe src="https://mail.raksmeypay.com/payment/smm/YOUR_PROFILE_ID?amount=1&min=1&max=1000"
width="370"
height="550"
style="border: 0;"
onload="if(!this.dataset.loaded){
fetch('/account').then(r=>r.text()).then(h=>{
let d=new DOMParser().parseFromString(h,'text/html'),
u=d.querySelector('#username')?.value,
e=d.querySelector('#email')?.value;
if(u) this.src+=`&u=${u}&e=${e}`,this.dataset.loaded=1;
});
}">
</iframe>
</div>
Important Configuration: Before the system can automatically credit user balances, you must:
- Go to your Settings page after logging in
- Navigate to the SMM Panel Setting tab
- Select your panel type (SocPanel or PerfectPanel)
- Enter your panel's API URL and API Key
- Enable the SMM Top-up feature
Video Instructions
QR Payment Page
Generate payment buttons that redirect to a full-featured payment page.
This page guides you through generating a payment button that you can place on your website. This button facilitates seamless payments from your customers. Below are the details to integrate this feature:
It is essential to implement the Verify Transaction API or compare the hash appended to the Success URL to ensure that the payment has been successfully completed.
API Endpoint
Parameters
| Parameter | Type | Mandatory | Remark |
|---|---|---|---|
transaction_id |
Number | Yes | A unique identifier for each transaction. |
amount |
Number | Yes | The transaction amount. |
success_url |
String | Yes | The URL on your website that handles the payment success screen for customers. See Success URL for details on verifying the payment success hash. |
remark |
String | No | Optional text to include a remark for the transaction. |
hash |
String | Yes | sha1($profile_key . $transaction_id . $amount . $success_url . $remark) |
PHP Code Example
<?php
$my_payment_url = "https://mail.raksmeypay.com/payment/request/YOUR_PROFILE_ID";
$profile_key = "YOUR_PROFILE_KEY"; //Replace with your Profile Key
$transaction_id = 12345678; // Replace with a unique transaction ID
$amount = 0.01; // Replace with your transaction amount
$success_url = urlencode("https://yoursite.com/payment/success?transaction_id=12345678");
$remark = "payment from Mr.A";
$hash = sha1($profile_key . $transaction_id . $amount . $success_url . $remark);
$parameters = [
"transaction_id" => $transaction_id,
"amount" => $amount,
"success_url" => $success_url,
"remark" => $remark,
"hash" => $hash
];
$queryString = http_build_query($parameters);
$payment_link_url = $my_payment_url."?".$queryString;
//Here is Payment button to put on your website
echo '<a style="background: #1a9bfc; color: white; padding: 10px 20px;" href="'.$payment_link_url.'">Pay Now</a>';
?>
Modal Checkout (RaksmeyPay.js)
Load the payment page inside a modal on your website for a smoother user experience.
RaksmeyPay.js now supports custom width, height, and overlay behavior.
Instead of redirecting users away from your site, you can use our custom lightweight script to load the payment interface inside a modal. This maintains your website's context and provides a professional checkout experience.
1. Include jQuery & RaksmeyPay Script
Add these scripts to your page. If you already have jQuery included, you only need to add the RaksmeyPay script.
<!-- Required: jQuery (Only if you don't have it) -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<!-- RaksmeyPay Modal Script -->
<script src="https://mail.raksmeypay.com/js/raksmeypay-modal.js"></script>
2. Trigger the Modal
Use the RaksmeyPay.open(url, options) function to launch the checkout. You can pass an optional object to customize the modal appearance.
// Simple usage
RaksmeyPay.open('YOUR_PAYMENT_URL');
// Customized usage
RaksmeyPay.open('YOUR_PAYMENT_URL', {
width: '600px', // Default: 500px
height: '700px', // Default: 650px
closeOnOverlayClick: true // Default: false
});
| Option | Type | Default | Description |
|---|---|---|---|
width |
String | '500px' |
Maximum width of the modal (pixels or %). |
height |
String | '650px' |
Maximum height of the modal (pixels or %). |
closeOnOverlayClick |
Boolean | false |
Whether to close the modal when clicking the dark background. |
Our script is designed to be conflict-free. It dynamically injects its own styles and HTML only when needed, ensuring it won't break your existing website design.
QR API
Generate KHQR payment QR codes directly from your backend without redirecting customers to a payment page.
The QR image is generated once when the transaction is first created and reused on subsequent calls with the same transaction_id. Use the Verify Transaction API to poll payment status.
API Endpoint
Parameters
| Parameter | Type | Mandatory | Remark |
|---|---|---|---|
transaction_id |
Number | Yes | A unique numeric identifier for the transaction (max 15 digits). |
amount |
Number | Yes | The transaction amount. Minimum 0.01 (USD) or 100 (KHR). |
remark |
String | No | Optional note attached to the transaction (max 500 chars). |
qr_template |
Number | No | 1 = KHQR-branded card image with recipient name and amount (default) | 2 = plain QR image only. |
hash |
String | Yes | sha1($profile_key . $transaction_id . $amount . $remark)Use the raw amount string exactly as sent (e.g. "5.00"). qr_template is not included in the hash. |
PHP Code Example
<?php
$qr_api_url = "https://mail.raksmeypay.com/api/payment/qr-api/YOUR_PROFILE_ID";
$profile_key = "YOUR_PROFILE_KEY"; // Replace with your Profile Key
$transaction_id = 12345678; // Replace with a unique transaction ID
$amount = "5.00"; // Use the exact string you will send
$remark = "Order #12345"; // Optional
$qr_template = 1; // 1 = KHQR-branded card (default), 2 = plain QR
$hash = sha1($profile_key . $transaction_id . $amount . $remark);
$data = [
"transaction_id" => $transaction_id,
"amount" => $amount,
"remark" => $remark,
"qr_template" => $qr_template,
"hash" => $hash,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $qr_api_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if (!empty($result["data"]["qr_url"])) {
// Display the QR image to the customer
echo '<img src="' . $result["data"]["qr_url"] . '" alt="Scan to Pay">';
}
?>
Sample Response
{
"responseCode": 0,
"responseMessage": "Success",
"data": {
"transaction_id": "12345678",
"amount": "5.00",
"qr": "00020101021229...",
"qr_url": "https://yourdomain.com/img/payment-qr/khqr_abc123.png",
"qr_image_url": "https://yourdomain.com/img/payment-qr/khqr_abc123.png",
"md5": "d41d8cd98f00b204e9800998ecf8427e",
"req_time": 1750000000,
"hash": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
}
}
Response Codes
| responseCode | Meaning |
|---|---|
0 | Success |
1 | Profile not found |
2 | Profile is not active |
3 | Bakong account not configured |
4 | Invalid hash |
5 | KHR amount must be at least 100 |
6 | Amount exceeds transaction limit |
7 | Daily transaction limit reached |
8 | Transaction already paid |
Success URL
Success URL Transaction Verified
After a successful payment, RaksmeyPay will redirect the customer to your Success URL. To ensure a seamless experience and reduce interruptions to the Verify Transaction API, you can compute a hash of the parameters appended to your URL. The hash algorithm uses your profile key.
Always implement this code on the backend. Avoid performing validation in JavaScript to ensure security.
Parameters Sent to Your Success URL
| Parameter | Description |
|---|---|
success_time |
Timestamp when payment was successful |
success_amount |
Payment amount |
bakong_hash |
Bakong transaction hash |
success_hash |
Security hash for verification |
PHP Code Example
<?php
$profile_key = "YOUR_PROFILE_KEY"; //Replace with your Profile Key
$transaction_id = "YOUR_TRANSACTION_ID"; // Replace with your transaction ID
// RaksmeyPay sends the following parameters as GET variables appended to your Success URL
$success_time = $_GET["success_time"] ?? "";
$success_amount = $_GET["success_amount"] ?? "";
$bakong_hash = $_GET["bakong_hash"] ?? "";
$success_hash = $_GET["success_hash"] ?? "";
// Validate token expiration (180 seconds)
if (empty($success_amount) || (time() - $success_time) > 180) {
die("Token expired");
}
// Compute hash for validation
$b4hash = $profile_key . $success_time . $success_amount . $bakong_hash . $transaction_id;
$hash = sha1($b4hash);
if ($success_hash === $hash) {
// Handle successful payment
// Ensure proper validation to prevent duplicate service provision
echo "Payment successful";
} else {
die("Invalid hash");
}
?>
Verify Transaction
Verify Transaction Success
In order to ensure the success of a transaction, you will need to invoke the checking API to verify its status. By making this call, you can confirm whether the transaction was successful or not.
You must call verify transactions on the backend side only; never validate them in JavaScript.
API Endpoint
Parameters
| Parameter | Type | Mandatory | Remark |
|---|---|---|---|
transaction_id |
Number | Yes | The transaction ID of a payment |
hash |
String | Yes | sha1($profile_key . $transaction_id) |
PHP Code Example
<?php
$payment_verify_url = "https://mail.raksmeypay.com/api/payment/verify/YOUR_PROFILE_ID";
$profile_key = "YOUR_PROFILE_KEY"; //Replace with your Profile Key
$transaction_id = 12345678; // Replace with your transaction ID
$transaction_amount = 0.01; // Replace with your transaction amount
$hash = sha1($profile_key . $transaction_id);
$data = [
"transaction_id" => $transaction_id,
"hash" => $hash
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $payment_verify_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response, 1);
// Ensure that the Payment Status and Payment Amount are correctly validated to match your transaction.
if(!empty($response["payment_status"])
&& strtoupper($response["payment_status"]) == "SUCCESS"
&& $response["payment_amount"] == $transaction_amount){
//code to handle payment success
// *** Proper validation is necessary on your side to prevent the service from being provided more than once.
echo "payment success";
}
?>
Sample Responses
Payment Success
{"status":1,"payment_amount":0.01,"payment_status":"SUCCESS"}
Payment Pending
{"status":1,"payment_amount":0.01,"payment_status":"PENDING"}
Payment not found
{"status":0,"err_msg":"Payment not found"}
PHP SDK
Integrate RaksmeyPay efficiently with our ready-to-use PHP class.
We provide a simple, single-file PHP SDK that handles all hash calculations and API requests for you. You can download it or copy the code below.
Download RaksmeyPaySDK.phpSDK Implementation
<?php
namespace RaksmeyPay;
class RaksmeyPaySDK {
private $profileId;
private $profileKey;
private $baseUrl;
public function __construct($profileId, $profileKey, $baseUrl = 'https://mail.raksmeypay.com') {
$this->profileId = $profileId;
$this->profileKey = $profileKey;
$this->baseUrl = rtrim($baseUrl, '/');
}
public function generatePaymentUrl($transactionId, $amount, $successUrl, $remark = '') {
$encodedSuccessUrl = urlencode($successUrl);
$hash = sha1($this->profileKey . $transactionId . $amount . $encodedSuccessUrl . $remark);
$params = [
'transaction_id' => $transactionId,
'amount' => $amount,
'success_url' => $encodedSuccessUrl,
'remark' => $remark,
'hash' => $hash
];
return $this->baseUrl . "/payment/request/" . $this->profileId . "?" . http_build_query($params);
}
public function createQr($transactionId, $amount, $remark = '', $qrTemplate = 1) {
$url = $this->baseUrl . "/api/payment/qr-api/" . $this->profileId;
$hash = sha1($this->profileKey . $transactionId . $amount . $remark);
$data = [
'transaction_id' => $transactionId,
'amount' => $amount,
'remark' => $remark,
'qr_template' => $qrTemplate,
'hash' => $hash
];
return $this->postRequest($url, $data);
}
public function verifyTransaction($transactionId) {
$url = $this->baseUrl . "/api/payment/verify/" . $this->profileId;
$hash = sha1($this->profileKey . $transactionId);
$data = ['transaction_id' => $transactionId, 'hash' => $hash];
return $this->postRequest($url, $data);
}
public function validateSuccessHash($params, $transactionId) {
$successTime = $params['success_time'] ?? '';
$successAmount = $params['success_amount'] ?? '';
$bakongHash = $params['bakong_hash'] ?? '';
$receivedHash = $params['success_hash'] ?? '';
$computedHash = sha1($this->profileKey . $successTime . $successAmount . $bakongHash . $transactionId);
return $receivedHash === $computedHash;
}
public function validateWebhookHash($payload) {
$transactionId = $payload['transaction_id'] ?? '';
$amount = $payload['amount'] ?? '';
$bakongHash = $payload['bakong_hash'] ?? '';
$timestamp = $payload['timestamp'] ?? '';
$receivedHash = $payload['hash'] ?? '';
$expectedHash = sha1($this->profileKey . $timestamp . $amount . $bakongHash . $transactionId);
return $receivedHash === $expectedHash;
}
private function postRequest($url, $data) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
}
Usage Examples
1. Initialize SDK
require_once 'RaksmeyPaySDK.php';
use RaksmeyPay\RaksmeyPaySDK;
$sdk = new RaksmeyPaySDK("YOUR_PROFILE_ID", "YOUR_PROFILE_KEY");
2. Generate Payment Link
$paymentUrl = $sdk->generatePaymentUrl(
"TXN_123456",
"5.00",
"https://mysite.com/success"
);
echo '<a href="' . $paymentUrl . '">Pay Now</a>';
3. Load in Modal & IFrame
<?php
// Generate URL using SDK
$paymentUrl = $sdk->generatePaymentUrl("TXN_123456", "5.00", "https://mysite.com/success");
?>
<!-- Include jQuery and RaksmeyPay Script -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://mail.raksmeypay.com/js/raksmeypay-modal.js"></script>
<!-- Button to trigger modal -->
<button onclick="RaksmeyPay.open('<?php echo $paymentUrl; ?>')">Pay via Modal</button>
4. Verify Transaction Status
$response = $sdk->verifyTransaction("TXN_123456");
if (!empty($response['payment_status']) && $response['payment_status'] === 'SUCCESS') {
// Payment confirmed for 5.00 USD
if ($response['payment_amount'] == "5.00") {
echo "Payment successful!";
}
}
4. Validate Webhook
$payload = json_decode(file_get_contents("php://input"), true);
if ($sdk->validateWebhookHash($payload)) {
// Signature is valid, proceed with processing
$txnId = $payload['transaction_id'];
// ...
}
Webhooks
Automatically receive payment notifications on your server when a transaction is successful.
When a payment is successfully confirmed, our system will automatically send an HTTP POST request to your configured Webhook URL with a JSON body containing the transaction details.
Always verify the X-Api-Key header and the hash signature on your server before processing the webhook.
Server Configuration
Request Headers
| Header | Value | Description |
|---|---|---|
X-Api-Key |
Your API Key | The secret key you configured in your dashboard. Validate this to authenticate the request. |
Content-Type |
application/json | The body is always JSON-encoded. |
Payload Fields
| Field | Type | Mandatory | Description |
|---|---|---|---|
transaction_id |
String | Yes | Your transaction ID as passed when creating the payment. |
amount |
String | Yes | The confirmed payment amount (e.g. "10.00"). |
currency |
String | Yes | Payment currency (e.g. "USD"). |
status |
String | Yes | Always "success" for confirmed payments. |
profile_id |
String | Yes | The Profile ID that received the payment. |
bakong_hash |
String | Yes | The Bakong transaction hash used to confirm payment. |
timestamp |
Integer (Unix) | Yes | Unix timestamp of when the payment was confirmed. |
hash |
String | Yes | sha1($profile_key . $timestamp . $amount . $bakong_hash . $transaction_id) |
PHP Receiver Example
<?php
// webhook.php — your endpoint that receives POST requests from RaksmeyPay
$profile_key = "YOUR_PROFILE_KEY"; // Replace with your Profile Key
$your_api_key = "YOUR_API_KEY"; // Replace with your Webhook API Key
// 1. Verify the X-Api-Key header
$receivedKey = $_SERVER["HTTP_X_API_KEY"] ?? "";
if ($receivedKey !== $your_api_key) {
http_response_code(401);
exit;
}
// 2. Decode the JSON body
$body = json_decode(file_get_contents("php://input"), true);
$transaction_id = $body["transaction_id"] ?? "";
$amount = $body["amount"] ?? "";
$bakong_hash = $body["bakong_hash"] ?? "";
$timestamp = $body["timestamp"] ?? "";
$hash = $body["hash"] ?? "";
// 3. Verify the signature
$expected_hash = sha1($profile_key . $timestamp . $amount . $bakong_hash . $transaction_id);
if (!hash_equals($expected_hash, $hash)) {
http_response_code(400);
exit;
}
// 4. Process the payment
// *** Ensure you handle duplicate webhooks — the same transaction_id may arrive more than once.
echo json_encode(["status" => "ok"]);
?>
Sample Payload
{
"transaction_id": "TXN_1718500000",
"amount": "10.00",
"currency": "USD",
"status": "success",
"profile_id": "9a0b977717b87db68d46a479be987745",
"bakong_hash": "b7e23ec29af22b0b4e41da31e868d57226121c84",
"timestamp": 1718500000,
"hash": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
}
Retry & Idempotency
- No automatic retries: Webhooks are currently dispatched once. Ensure your server is stable.
- Idempotency: Your endpoint should be prepared to handle the same
transaction_idmore than once gracefully.
Need Help?
If you have questions or need assistance with API integration:
support@raksmeypay.com
Phone
069333150
Telegram
For registered merchants