End To End Process Flow
- Curl
- Ruby
- Python
- PHP
- Java
- Node.js
- Go
- .NET
- Define Merchant Credentials First, define your merchant credentials provided by SADAD.
- Prepare Transaction Parameters
- Sort Parameters
- Generate Signature
- Send Payment Request Using cURL
- Add Product Details (Optional)
- Execute the Request
secretKey="xxxxxxxxx"
merchantID="1234567"
| Parameter | Description |
|---|---|
merchantID | Unique merchant ID provided by SADAD |
secretKey | Secret key used to generate the request signature |
Create an associative array containing all the required payment parameters.
declare -A data
data[merchant_id]=$merchantID
data[ORDER_ID]="4641"
data[WEBSITE]="www.example.com"
data[TXN_AMOUNT]="50.00"
data[CUST_ID]="example@example.com"
data[EMAIL]="example@example.com"
data[MOBILE_NO]="999999999"
data[CALLBACK_URL]="https://example.com/callback"
data[txnDate]="$(date '+%Y-%m-%d %H:%M:%S')"
Parameter Description
| Parameter | Description |
|---|---|
merchant_id | Merchant ID assigned by SADAD |
ORDER_ID | Unique order identifier generated by the merchant |
WEBSITE | Merchant website domain |
TXN_AMOUNT | Transaction amount |
CUST_ID | Customer identifier |
EMAIL | Customer email address |
MOBILE_NO | Customer mobile number |
CALLBACK_URL | URL where SADAD sends the payment response |
txnDate | Transaction date and time |
Before generating the signature, parameters must be sorted alphabetically by key.
sorted_keys=$(printf "%s\n" "${!data[@]}" | sort)
Sorting ensures the signature is generated consistently.
The signature is generated by concatenating the secret key with all parameter values and hashing the result using SHA256.
signatureStr=$secretKey
for key in $sorted_keys
do
signatureStr+="${data[$key]}"
done
Generate the SHA256 hash.
signature=$(echo -n "$signatureStr" | sha256sum | awk '{print $1}')
The signature helps SADAD verify that the request originated from a valid merchant.
Send the payment request to the SADAD payment endpoint using a POST request.
curl -X POST https://sadadqa.com/webpurchase \
-d "merchant_id=${data[merchant_id]}" \
-d "ORDER_ID=${data[ORDER_ID]}" \
-d "WEBSITE=${data[WEBSITE]}" \
-d "TXN_AMOUNT=${data[TXN_AMOUNT]}" \
-d "CUST_ID=${data[CUST_ID]}" \
-d "EMAIL=${data[EMAIL]}" \
-d "MOBILE_NO=${data[MOBILE_NO]}" \
-d "CALLBACK_URL=${data[CALLBACK_URL]}" \
-d "txnDate=${data[txnDate]}" \
-d "signature=$signature"
This request sends all required parameters to the SADAD payment gateway.
If product information is required, include product details in the request.
-d "productdetail[0][order_id]=12345" \
-d "productdetail[0][amount]=200.00" \
-d "productdetail[0][quantity]=1"
| Field | Description |
|---|---|
order_id | Product order ID |
amount | Product amount |
quantity | Product quantity |
Multiple products can be added using:
productdetail[1]
productdetail[2]
Run the script to send the request to the SADAD payment gateway. The response from the server will indicate whether the request was successfully received and processed.
Curl
#!/bin/bash
secretKey="xxxxxxxxx"
merchantID="1234567"
declare -A data
data[merchant_id]=$merchantID
data[ORDER_ID]="4641"
data[WEBSITE]="www.example.com"
data[TXN_AMOUNT]="50.00"
data[CUST_ID]="example@example.com"
data[EMAIL]="example@example.com"
data[MOBILE_NO]="999999999"
data[CALLBACK_URL]="https://example.com/callback"
data[txnDate]="$(date '+%Y-%m-%d %H:%M:%S')"
# Sort keys like ksort
sorted_keys=$(printf "%s\n" "${!data[@]}" | sort)
signatureStr=$secretKey
for key in $sorted_keys
do
signatureStr+="${data[$key]}"
done
signature=$(echo -n "$signatureStr" | sha256sum | awk '{print $1}')
curl -X POST https://sadadqa.com/webpurchase \
-d "merchant_id=${data[merchant_id]}" \
-d "ORDER_ID=${data[ORDER_ID]}" \
-d "WEBSITE=${data[WEBSITE]}" \
-d "TXN_AMOUNT=${data[TXN_AMOUNT]}" \
-d "CUST_ID=${data[CUST_ID]}" \
-d "EMAIL=${data[EMAIL]}" \
-d "MOBILE_NO=${data[MOBILE_NO]}" \
-d "CALLBACK_URL=${data[CALLBACK_URL]}" \
-d "txnDate=${data[txnDate]}" \
-d "signature=$signature"
- Define Merchant Credentials First, define your merchant credentials provided by SADAD.
- Prepare Transaction Parameters
- Sort Parameters
- Generate Signature
- Create Payment Form
- Add Product Details
- Auto Submit the Form
secretKey = "xxxxxxxxx"
merchantID = "1234567"
| Parameter | Description |
|---|---|
merchantID | Unique merchant ID provided by SADAD |
secretKey | Secret key used to generate the request signature |
Create a hash containing all the required payment parameters.
data = {
"merchant_id" => merchantID,
"ORDER_ID" => "4641",
"WEBSITE" => "www.example.com",
"TXN_AMOUNT" => "50.00",
"CUST_ID" => "example@example.com",
"EMAIL" => "example@example.com",
"MOBILE_NO" => "999999999",
"CALLBACK_URL" => "https://example.com/callback",
"txnDate" => Time.now.strftime("%Y-%m-%d %H:%M:%S")
}
Parameter Description
| Parameter | Description |
|---|---|
merchant_id | Merchant ID assigned by SADAD |
ORDER_ID | Unique order identifier generated by the merchant |
WEBSITE | Merchant website domain |
TXN_AMOUNT | Transaction amount |
CUST_ID | Customer identifier |
EMAIL | Customer email address |
MOBILE_NO | Customer mobile number |
CALLBACK_URL | URL where SADAD sends the payment response |
txnDate | Transaction date and time |
Before generating the signature, parameters must be sorted alphabetically by key.
sorted = data.sort.to_h
Sorting ensures the signature is generated consistently.
The signature is generated by concatenating the secret key with all parameter values and hashing the result using SHA256.
signatureStr = secretKey + sorted.values.join
Generate the SHA256 hash.
signature = Digest::SHA256.hexdigest(signatureStr)
Add the generated signature to the request parameters.
sorted["signature"] = signature
The signature helps SADAD verify that the request originated from a valid merchant.
Generate an HTML form that submits all parameters to the SADAD payment page.
puts '<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">'
Add all parameters as hidden fields.
sorted.each do |k,v|
puts "<input type='hidden' name='#{k}' value='#{v}' />"
end
The product information is sent as an array.
puts '<input type="hidden" name="productdetail[0][order_id]" value="12345" />'
puts '<input type="hidden" name="productdetail[0][amount]" value="200.00" />'
puts '<input type="hidden" name="productdetail[0][quantity]" value="1" />'
| Field | Description |
|---|---|
order_id | Product order ID |
amount | Product amount |
quantity | Product quantity |
Multiple products can be added using:
productdetail[1]
productdetail[2]
The form is automatically submitted using JavaScript to redirect the user to the SADAD payment page.
<script type="text/javascript">
document.gosadad.submit();
</script>
Once submitted, the customer will be redirected to the SADAD hosted payment page to complete the transaction.
Ruby
require 'digest'
secretKey = "xxxxxxxxx"
merchantID = "1234567"
data = {
"merchant_id"=>merchantID,
"ORDER_ID"=>"4641",
"WEBSITE"=>"www.example.com",
"TXN_AMOUNT"=>"50.00",
"CUST_ID"=>"example@example.com",
"EMAIL"=>"example@example.com",
"MOBILE_NO"=>"999999999",
"CALLBACK_URL"=>"https://example.com/callback",
"txnDate"=>Time.now.strftime("%Y-%m-%d %H:%M:%S")
}
sorted = data.sort.to_h
signatureStr = secretKey + sorted.values.join
signature = Digest::SHA256.hexdigest(signatureStr)
sorted["signature"] = signature
puts '<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">'
sorted.each do |k,v|
puts "<input type='hidden' name='#{k}' value='#{v}' />"
end
puts '<input type="hidden" name="productdetail[0][order_id]" value="12345" />'
puts '<input type="hidden" name="productdetail[0][amount]" value="200.00" />'
puts '<input type="hidden" name="productdetail[0][quantity]" value="1" />'
puts '</form>'
puts '<script type="text/javascript">document.gosadad.submit();</script>'
- Define Merchant Credentials
- Prepare Transaction Parameters
- Sort Parameters
- Generate Signature
- Create Payment Form
- Add Product Details
- Auto Submit the Form
First, define your merchant credentials provided by SADAD.
secretKey = "xxxxxxxxx"
merchantID = "1234567"
| Parameter | Description |
|---|---|
merchantID | Unique merchant ID provided by SADAD |
secretKey | Secret key used to generate the request signature |
Create a dictionary containing all the required payment parameters.
data = {
"merchant_id": merchantID,
"ORDER_ID": "4641",
"WEBSITE": "www.example.com",
"TXN_AMOUNT": "50.00",
"CUST_ID": "example@example.com",
"EMAIL": "example@example.com",
"MOBILE_NO": "999999999",
"CALLBACK_URL": "https://example.com/callback",
"txnDate": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
Parameter Description
| Parameter | Description |
|---|---|
merchant_id | Merchant ID assigned by SADAD |
ORDER_ID | Unique order identifier generated by the merchant |
WEBSITE | Merchant website domain |
TXN_AMOUNT | Transaction amount |
CUST_ID | Customer identifier |
EMAIL | Customer email address |
MOBILE_NO | Customer mobile number |
CALLBACK_URL | URL where SADAD sends the payment response |
txnDate | Transaction date and time |
Before generating the signature, parameters must be sorted alphabetically by key.
sorted_data = dict(sorted(data.items()))
Sorting ensures the signature is generated consistently.
The signature is generated by concatenating the secret key with all parameter values and hashing the result using SHA256.
signatureStr = secretKey + "".join(sorted_data.values())
Generate the SHA256 hash.
signature = hashlib.sha256(signatureStr.encode()).hexdigest()
Add the generated signature to the request parameters.
sorted_data["signature"] = signature
The signature helps SADAD verify that the request originated from a valid merchant.
Generate an HTML form that submits all parameters to the SADAD payment page.
print('<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">')
Add all parameters as hidden fields.
for k, v in sorted_data.items():
print(f'<input type="hidden" name="{k}" value="{v}" />')
The product information is sent as an array.
print('<input type="hidden" name="productdetail[0][order_id]" value="12345" />')
print('<input type="hidden" name="productdetail[0][amount]" value="200.00" />')
print('<input type="hidden" name="productdetail[0][quantity]" value="1" />')
| Field | Description |
|---|---|
order_id | Product order ID |
amount | Product amount |
quantity | Product quantity |
Multiple products can be added using:
productdetail[1]
productdetail[2]
The form is automatically submitted using JavaScript to redirect the user to the SADAD payment page.
<script type="text/javascript">
document.gosadad.submit();
</script>
Once submitted, the customer will be redirected to the SADAD hosted payment page to complete the transaction.
Python
import hashlib
from datetime import datetime
secretKey = "xxxxxxxxx"
merchantID = "1234567"
data = {
"merchant_id": merchantID,
"ORDER_ID": "4641",
"WEBSITE": "www.example.com",
"TXN_AMOUNT": "50.00",
"CUST_ID": "example@example.com",
"EMAIL": "example@example.com",
"MOBILE_NO": "999999999",
"CALLBACK_URL": "https://example.com/callback",
"txnDate": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
sorted_data = dict(sorted(data.items()))
signatureStr = secretKey + "".join(sorted_data.values())
signature = hashlib.sha256(signatureStr.encode()).hexdigest()
sorted_data["signature"] = signature
print('<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">')
for k,v in sorted_data.items():
print(f'<input type="hidden" name="{k}" value="{v}" />')
print('<input type="hidden" name="productdetail[0][order_id]" value="12345" />')
print('<input type="hidden" name="productdetail[0][amount]" value="200.00" />')
print('<input type="hidden" name="productdetail[0][quantity]" value="1" />')
print('</form>')
print('<script type="text/javascript">document.gosadad.submit();</script>')
- Define Merchant Credentials First, define your merchant credentials provided by SADAD.
- Prepare Transaction Parameters Create an array containing all the required payment parameters.
- Sort Parameters Before generating the signature, parameters must be sorted alphabetically by key.
- Generate Signature The signature is generated by concatenating the secret key with all parameter values and hashing the result using SHA256.
- Create Payment Form Generate an HTML form that submits all parameters to the SADAD payment page.
- Add Product Details The product information is sent as an array.
- Auto Submit the Form The form is automatically submitted using JavaScript to redirect the user to the SADAD payment page.
$secretKey = 'xxxxxxxxx';
$merchantID = '1234567';
| Parameter | Description |
|---|---|
merchantID | Unique merchant ID provided by SADAD |
secretKey | Secret key used to generate the request signature |
$sAry['merchant_id'] = $merchantID;
$sAry['ORDER_ID'] = '4641';
$sAry['WEBSITE'] = 'www.example.com';
$sAry['TXN_AMOUNT'] = '50.00';
$sAry['CUST_ID'] = $email;
$sAry['EMAIL'] = $email;
$sAry['MOBILE_NO'] = '999999999';
$sAry['CALLBACK_URL'] = 'https://example.com/callback';
$sAry['txnDate'] = date('Y-m-d H:i:s');
Parameter Description
| Parameter | Description |
|---|---|
merchant_id | Merchant ID assigned by SADAD |
ORDER_ID | Unique order identifier generated by the merchant |
WEBSITE | Merchant website domain |
TXN_AMOUNT | Transaction amount |
CUST_ID | Customer identifier |
EMAIL | Customer email address |
MOBILE_NO | Customer mobile number |
CALLBACK_URL | URL where SADAD sends the payment response |
txnDate | Transaction date and time |
ksort($sAry);
Sorting ensures the signature is generated consistently.
$signatureStr = $secretKey;
foreach ($sAry as $k => $v) {
$signatureStr .= $v;
}
$signature = hash('sha256', $signatureStr, false);
Add the generated signature to the request parameters.
$sAry['signature'] = $signature;
The signature helps SADAD verify that the request originated from a valid merchant.
echo '<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">';
Add all parameters as hidden fields.
foreach ($sAry as $k => $v) {
echo '<input type="hidden" name="' . $k . '" value ="' . $v . '" />';
}
<input type="hidden" name="productdetail[0][order_id]" value="12345" />
<input type="hidden" name="productdetail[0][amount]" value="200.00" />
<input type="hidden" name="productdetail[0][quantity]" value="1" />
| Field | Description |
|---|---|
order_id | Product order ID |
amount | Product amount |
quantity | Product quantity |
Multiple products can be added using:
productdetail[1]
productdetail[2]
<script type="text/javascript">
document.gosadad.submit();
</script>
Once submitted, the customer will be redirected to the SADAD hosted payment page to complete the transaction.
PHP
<?php
$secretKey = 'xxxxxxxxx';
$merchantID = '1234567';
$sAry['merchant_id'] = $merchantID;
$sAry['ORDER_ID'] = '4641';
$sAry['WEBSITE'] = 'www.example.com';
$sAry['TXN_AMOUNT'] = '50.00';
$sAry['CUST_ID'] = $email;
$sAry['EMAIL'] = $email;
$sAry['MOBILE_NO'] = '999999999';
$sAry['CALLBACK_URL'] = 'https://example.com/callback';
$sAry['txnDate'] = date('Y-m-d H:i:s');
ksort($sAry);
$signatureStr = $secretKey;
foreach ($sAry as $k => $v) {
$signatureStr .= $v;
}
$signature = hash('sha256', $signatureStr, false);
$sAry['signature'] = $signature;
echo '<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">';
foreach ($sAry as $k => $v) {
echo '<input type="hidden" name="' . $k . '" value ="' . $v . '" />';
}
echo '<input type="hidden" name="productdetail[0][order_id]" value="12345" />
<input type="hidden" name="productdetail[0][amount]" value="200.00" />
<input type="hidden" name="productdetail[0][quantity]" value="1" />';
echo '</form>
<script type="text/javascript">
document.gosadad.submit();
</script>';
exit;
- Define Merchant Credentials First, define your merchant credentials provided by SADAD.
- Prepare Transaction Parameters
- Sort Parameters Before generating the signature, parameters must be sorted alphabetically by key.
- Generate Signature The signature is generated by concatenating the secret key with all parameter values and hashing the result using SHA-256.
- Create Payment Form Generate an HTML form that submits all parameters to the SADAD payment page
- Add Product Details
- Auto Submit the Form The form is automatically submitted using JavaScript to redirect the user to the SADAD payment page.
String secretKey="xxxxxxxxx";
String merchantID="1234567";
| Parameter | Description |
|---|---|
merchantID | Unique merchant ID provided by SADAD |
secretKey | Secret key used to generate the request signature |
Create a map containing all the required payment parameters.
Map<String,String> data=new HashMap<>();
data.put("merchant_id",merchantID);
data.put("ORDER_ID","4641");
data.put("WEBSITE","www.example.com");
data.put("TXN_AMOUNT","50.00");
data.put("CUST_ID","example@example.com");
data.put("EMAIL","example@example.com");
data.put("MOBILE_NO","999999999");
data.put("CALLBACK_URL","https://example.com/callback");
data.put("txnDate",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
Parameter Description
| Parameter | Description |
|---|---|
merchant_id | Merchant ID assigned by SADAD |
ORDER_ID | Unique order identifier generated by the merchant |
WEBSITE | Merchant website domain |
TXN_AMOUNT | Transaction amount |
CUST_ID | Customer identifier |
EMAIL | Customer email address |
MOBILE_NO | Customer mobile number |
CALLBACK_URL | URL where SADAD sends the payment response |
txnDate | Transaction date and time |
TreeMap<String,String> sorted=new TreeMap<>(data);
Sorting ensures the signature is generated consistently.
String signatureStr=secretKey;
for(String v:sorted.values()){
signatureStr+=v;
}
Generate the SHA-256 hash.
MessageDigest md=MessageDigest.getInstance("SHA-256");
byte[] hash=md.digest(signatureStr.getBytes());
Convert the hash to a hexadecimal string.
StringBuilder hex=new StringBuilder();
for(byte b:hash){
hex.append(String.format("%02x",b));
}
Add the generated signature to the request parameters.
sorted.put("signature",hex.toString());
The signature helps SADAD verify that the request originated from a valid merchant.
System.out.println("<form action=\"https://sadadqa.com/webpurchase\" method=\"post\" name=\"gosadad\">");
Add all parameters as hidden fields.
for(Map.Entry<String,String> e:sorted.entrySet()){
System.out.println("<input type='hidden' name='"+e.getKey()+"' value='"+e.getValue()+"' />");
}
The product information is sent as an array.
<input type="hidden" name="productdetail[0][order_id]" value="12345" />
<input type="hidden" name="productdetail[0][amount]" value="200.00" />
<input type="hidden" name="productdetail[0][quantity]" value="1" />
| Field | Description |
|---|---|
order_id | Product order ID |
amount | Product amount |
quantity | Product quantity |
Multiple products can be added using:
productdetail[1]
productdetail[2]
<script type="text/javascript">
document.gosadad.submit();
</script>
Once submitted, the customer will be redirected to the SADAD hosted payment page to complete the transaction.
Java
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.*;
public class SadadForm {
public static void main(String[] args) throws Exception {
String secretKey="xxxxxxxxx";
String merchantID="1234567";
Map<String,String> data=new HashMap<>();
data.put("merchant_id",merchantID);
data.put("ORDER_ID","4641");
data.put("WEBSITE","www.example.com");
data.put("TXN_AMOUNT","50.00");
data.put("CUST_ID","example@example.com");
data.put("EMAIL","example@example.com");
data.put("MOBILE_NO","999999999");
data.put("CALLBACK_URL","https://example.com/callback");
data.put("txnDate",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
TreeMap<String,String> sorted=new TreeMap<>(data);
String signatureStr=secretKey;
for(String v:sorted.values()){
signatureStr+=v;
}
MessageDigest md=MessageDigest.getInstance("SHA-256");
byte[] hash=md.digest(signatureStr.getBytes());
StringBuilder hex=new StringBuilder();
for(byte b:hash){
hex.append(String.format("%02x",b));
}
sorted.put("signature",hex.toString());
System.out.println("<form action=\"https://sadadqa.com/webpurchase\" method=\"post\" name=\"gosadad\">");
for(Map.Entry<String,String> e:sorted.entrySet()){
System.out.println("<input type='hidden' name='"+e.getKey()+"' value='"+e.getValue()+"' />");
}
System.out.println("<input type='hidden' name='productdetail[0][order_id]' value='12345' />");
System.out.println("<input type='hidden' name='productdetail[0][amount]' value='200.00' />");
System.out.println("<input type='hidden' name='productdetail[0][quantity]' value='1' />");
System.out.println("</form>");
System.out.println("<script type=\"text/javascript\">document.gosadad.submit();</script>");
}
}
- Define Merchant Credentials
- Prepare Transaction Parameters
- Sort Parameters
- Generate Signature
- Create Payment Form
- Add Product Details
- Auto Submit the Form
First, define your merchant credentials provided by SADAD.
const secretKey = "xxxxxxxxx";
const merchantID = "1234567";
| Parameter | Description |
|---|---|
merchantID | Unique merchant ID provided by SADAD |
secretKey | Secret key used to generate the request signature |
Create an object containing all the required payment parameters.
let data = {
merchant_id: merchantID,
ORDER_ID: "4641",
WEBSITE: "www.example.com",
TXN_AMOUNT: "50.00",
CUST_ID: "example@example.com",
EMAIL: "example@example.com",
MOBILE_NO: "999999999",
CALLBACK_URL: "https://example.com/callback",
txnDate: new Date().toISOString().slice(0,19).replace("T"," ")
};
Parameter Description
| Parameter | Description |
|---|---|
merchant_id | Merchant ID assigned by SADAD |
ORDER_ID | Unique order identifier generated by the merchant |
WEBSITE | Merchant website domain |
TXN_AMOUNT | Transaction amount |
CUST_ID | Customer identifier |
EMAIL | Customer email address |
MOBILE_NO | Customer mobile number |
CALLBACK_URL | URL where SADAD sends the payment response |
txnDate | Transaction date and time |
Before generating the signature, parameters must be sorted alphabetically by key.
const sortedKeys = Object.keys(data).sort();
Sorting ensures the signature is generated consistently.
The signature is generated by concatenating the secret key with all parameter values and hashing the result using SHA256.
let signatureStr = secretKey;
sortedKeys.forEach(k => {
signatureStr += data[k];
});
Generate the SHA256 hash.
const signature = crypto.createHash("sha256")
.update(signatureStr)
.digest("hex");
Add the generated signature to the request parameters.
data.signature = signature;
The signature helps SADAD verify that the request originated from a valid merchant.
Generate an HTML form that submits all parameters to the SADAD payment page
console.log('<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">');
Add all parameters as hidden fields.
for (let k in data){
console.log(`<input type="hidden" name="${k}" value="${data[k]}" />`);
}
The product information is sent as an array.
console.log('<input type="hidden" name="productdetail[0][order_id]" value="12345" />');
console.log('<input type="hidden" name="productdetail[0][amount]" value="200.00" />');
console.log('<input type="hidden" name="productdetail[0][quantity]" value="1" />');
| Field | Description |
|---|---|
order_id | Product order ID |
amount | Product amount |
quantity | Product quantity |
Multiple products can be added using:
productdetail[1]
productdetail[2]
The form is automatically submitted using JavaScript to redirect the user to the SADAD payment page.
<script type="text/javascript">
document.gosadad.submit();
</script>
Once submitted, the customer will be redirected to the SADAD hosted payment page to complete the transaction.
Node js
const crypto = require("crypto");
const secretKey = "xxxxxxxxx";
const merchantID = "1234567";
let data = {
merchant_id: merchantID,
ORDER_ID: "4641",
WEBSITE: "www.example.com",
TXN_AMOUNT: "50.00",
CUST_ID: "example@example.com",
EMAIL: "example@example.com",
MOBILE_NO: "999999999",
CALLBACK_URL: "https://example.com/callback",
txnDate: new Date().toISOString().slice(0,19).replace("T"," ")
};
const sortedKeys = Object.keys(data).sort();
let signatureStr = secretKey;
sortedKeys.forEach(k=>{
signatureStr += data[k];
});
const signature = crypto.createHash("sha256").update(signatureStr).digest("hex");
data.signature = signature;
console.log('<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">');
for (let k in data){
console.log(`<input type="hidden" name="${k}" value="${data[k]}" />`);
}
console.log('<input type="hidden" name="productdetail[0][order_id]" value="12345" />');
console.log('<input type="hidden" name="productdetail[0][amount]" value="200.00" />');
console.log('<input type="hidden" name="productdetail[0][quantity]" value="1" />');
console.log('</form>');
console.log('<script type="text/javascript">document.gosadad.submit();</script>');
- Define Merchant Credentials
- Prepare Transaction Parameters
- Sort Parameters
- Generate Signature
- Create Payment Form
- Add Product Details
- Auto Submit the Form
First, define your merchant credentials provided by SADAD.
secretKey := "xxxxxxxxx"
merchantID := "1234567"
| Parameter | Description |
|---|---|
merchantID | Unique merchant ID provided by SADAD |
secretKey | Secret key used to generate the request signature |
Create a map containing all the required payment parameters.
data := map[string]string{
"merchant_id": merchantID,
"ORDER_ID": "4641",
"WEBSITE": "www.example.com",
"TXN_AMOUNT": "50.00",
"CUST_ID": "example@example.com",
"EMAIL": "example@example.com",
"MOBILE_NO": "999999999",
"CALLBACK_URL": "https://example.com/callback",
"txnDate": time.Now().Format("2006-01-02 15:04:05"),
}
Parameter Description
| Parameter | Description |
|---|---|
merchant_id | Merchant ID assigned by SADAD |
ORDER_ID | Unique order identifier generated by the merchant |
WEBSITE | Merchant website domain |
TXN_AMOUNT | Transaction amount |
CUST_ID | Customer identifier |
EMAIL | Customer email address |
MOBILE_NO | Customer mobile number |
CALLBACK_URL | URL where SADAD sends the payment response |
txnDate | Transaction date and time |
Before generating the signature, parameters must be sorted alphabetically by key.
keys := make([]string, 0, len(data))
for k := range data {
keys = append(keys, k)
}
sort.Strings(keys)
Sorting ensures the signature is generated consistently.
The signature is generated by concatenating the secret key with all parameter values and hashing the result using SHA256.
signatureStr := secretKey
for _, k := range keys {
signatureStr += data[k]
}
Generate the SHA256 hash.
hash := sha256.Sum256([]byte(signatureStr))
signature := fmt.Sprintf("%x", hash)
Add the generated signature to the request parameters.
data["signature"] = signature
The signature helps SADAD verify that the request originated from a valid merchant.
Generate an HTML form that submits all parameters to the SADAD payment page.
fmt.Println(`<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">`)
Add all parameters as hidden fields.
for k, v := range data {
fmt.Printf(`<input type="hidden" name="%s" value="%s" />`, k, v)
}
The product information is sent as an array.
fmt.Println(`<input type="hidden" name="productdetail[0][order_id]" value="12345" />`)
fmt.Println(`<input type="hidden" name="productdetail[0][amount]" value="200.00" />`)
fmt.Println(`<input type="hidden" name="productdetail[0][quantity]" value="1" />`)
| Field | Description |
|---|---|
order_id | Product order ID |
amount | Product amount |
quantity | Product quantity |
Multiple products can be added using:
productdetail[1]
productdetail[2]
The form is automatically submitted using JavaScript to redirect the user to the SADAD payment page.
<script type="text/javascript">
document.gosadad.submit();
</script>
Once submitted, the customer will be redirected to the SADAD hosted payment page to complete the transaction.
GO
package main
import (
"crypto/sha256"
"fmt"
"sort"
"time"
)
func main(){
secretKey := "xxxxxxxxx"
merchantID := "1234567"
data := map[string]string{
"merchant_id":merchantID,
"ORDER_ID":"4641",
"WEBSITE":"www.example.com",
"TXN_AMOUNT":"50.00",
"CUST_ID":"example@example.com",
"EMAIL":"example@example.com",
"MOBILE_NO":"999999999",
"CALLBACK_URL":"https://example.com/callback",
"txnDate":time.Now().Format("2006-01-02 15:04:05"),
}
keys := make([]string,0,len(data))
for k := range data{
keys=append(keys,k)
}
sort.Strings(keys)
signatureStr := secretKey
for _,k := range keys{
signatureStr += data[k]
}
hash := sha256.Sum256([]byte(signatureStr))
signature := fmt.Sprintf("%x",hash)
data["signature"]=signature
fmt.Println(`<form action="https://sadadqa.com/webpurchase" method="post" name="gosadad">`)
for k,v := range data{
fmt.Printf(`<input type="hidden" name="%s" value="%s" />`,k,v)
}
fmt.Println(`<input type="hidden" name="productdetail[0][order_id]" value="12345" />`)
fmt.Println(`<input type="hidden" name="productdetail[0][amount]" value="200.00" />`)
fmt.Println(`<input type="hidden" name="productdetail[0][quantity]" value="1" />`)
fmt.Println(`</form>`)
fmt.Println(`<script type="text/javascript">document.gosadad.submit();</script>`)
}
- Define Merchant Credentials
- Prepare Transaction Parameters
- Sort Parameters
- Generate Signature
- Create Payment Form
- Add Product Details
- Auto Submit the Form
First, define your merchant credentials provided by SADAD.
string secretKey="xxxxxxxxx";
string merchantID="1234567";
| Parameter | Description |
|---|---|
merchantID | Unique merchant ID provided by SADAD |
secretKey | Secret key used to generate the request signature |
Create a dictionary containing all the required payment parameters.
Dictionary<string,string> data=new Dictionary<string,string>();
data.Add("merchant_id",merchantID);
data.Add("ORDER_ID","4641");
data.Add("WEBSITE","www.example.com");
data.Add("TXN_AMOUNT","50.00");
data.Add("CUST_ID","example@example.com");
data.Add("EMAIL","example@example.com");
data.Add("MOBILE_NO","999999999");
data.Add("CALLBACK_URL","https://example.com/callback");
data.Add("txnDate",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
Parameter Description
| Parameter | Description |
|---|---|
merchant_id | Merchant ID assigned by SADAD |
ORDER_ID | Unique order identifier generated by the merchant |
WEBSITE | Merchant website domain |
TXN_AMOUNT | Transaction amount |
CUST_ID | Customer identifier |
EMAIL | Customer email address |
MOBILE_NO | Customer mobile number |
CALLBACK_URL | URL where SADAD sends the payment response |
txnDate | Transaction date and time |
Before generating the signature, parameters must be sorted alphabetically by key.
var sorted=data.OrderBy(x=>x.Key);
Sorting ensures the signature is generated consistently.
The signature is generated by concatenating the secret key with all parameter values and hashing the result using SHA256.
string signatureStr=secretKey;
foreach(var v in sorted){
signatureStr+=v.Value;
}
Generate the SHA256 hash.
SHA256 sha=SHA256.Create();
byte[] hash=sha.ComputeHash(Encoding.UTF8.GetBytes(signatureStr));
string signature=BitConverter.ToString(hash).Replace("-","").ToLower();
Add the generated signature to the request parameters.
data.Add("signature",signature);
The signature helps SADAD verify that the request originated from a valid merchant.
Generate an HTML form that submits all parameters to the SADAD payment page.
Console.WriteLine("<form action='https://sadadqa.com/webpurchase' method='post' name='gosadad'>");
Add all parameters as hidden fields.
foreach(var item in data){
Console.WriteLine("<input type='hidden' name='"+item.Key+"' value='"+item.Value+"' />");
}
The product information is sent as an array.
Console.WriteLine("<input type='hidden' name='productdetail[0][order_id]' value='12345' />");
Console.WriteLine("<input type='hidden' name='productdetail[0][amount]' value='200.00' />");
Console.WriteLine("<input type='hidden' name='productdetail[0][quantity]' value='1' />");
| Field | Description |
|---|---|
order_id | Product order ID |
amount | Product amount |
quantity | Product quantity |
Multiple products can be added using:
productdetail[1]
productdetail[2]
The form is automatically submitted using JavaScript to redirect the user to the SADAD payment page.
<script type="text/javascript">
document.gosadad.submit();
</script>
Once submitted, the customer will be redirected to the SADAD hosted payment page to complete the transaction.
.NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
class Program
{
static void Main(){
string secretKey="xxxxxxxxx";
string merchantID="1234567";
Dictionary<string,string> data=new Dictionary<string,string>();
data.Add("merchant_id",merchantID);
data.Add("ORDER_ID","4641");
data.Add("WEBSITE","www.example.com");
data.Add("TXN_AMOUNT","50.00");
data.Add("CUST_ID","example@example.com");
data.Add("EMAIL","example@example.com");
data.Add("MOBILE_NO","999999999");
data.Add("CALLBACK_URL","https://example.com/callback");
data.Add("txnDate",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var sorted=data.OrderBy(x=>x.Key);
string signatureStr=secretKey;
foreach(var v in sorted){
signatureStr+=v.Value;
}
SHA256 sha=SHA256.Create();
byte[] hash=sha.ComputeHash(Encoding.UTF8.GetBytes(signatureStr));
string signature=BitConverter.ToString(hash).Replace("-","").ToLower();
data.Add("signature",signature);
Console.WriteLine("<form action='https://sadadqa.com/webpurchase' method='post' name='gosadad'>");
foreach(var item in data){
Console.WriteLine("<input type='hidden' name='"+item.Key+"' value='"+item.Value+"' />");
}
Console.WriteLine("<input type='hidden' name='productdetail[0][order_id]' value='12345' />");
Console.WriteLine("<input type='hidden' name='productdetail[0][amount]' value='200.00' />");
Console.WriteLine("<input type='hidden' name='productdetail[0][quantity]' value='1' />");
Console.WriteLine("</form>");
Console.WriteLine("<script type='text/javascript'>document.gosadad.submit();</script>");
}
}