Skip to main content

End To End Process Flow

  1. Define Merchant Credentials
  2. First, define your merchant credentials provided by SADAD.

    secretKey="xxxxxxxxx"
    merchantID="1234567"
    ParameterDescription
    merchantIDUnique merchant ID provided by SADAD
    secretKeySecret key used to generate the request signature
  3. Prepare Transaction Parameters
  4. 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

    ParameterDescription
    merchant_idMerchant ID assigned by SADAD
    ORDER_IDUnique order identifier generated by the merchant
    WEBSITEMerchant website domain
    TXN_AMOUNTTransaction amount
    CUST_IDCustomer identifier
    EMAILCustomer email address
    MOBILE_NOCustomer mobile number
    CALLBACK_URLURL where SADAD sends the payment response
    txnDateTransaction date and time
  5. Sort Parameters
  6. 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.

  7. Generate Signature
  8. 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.

  9. Send Payment Request Using cURL
  10. 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.

  11. Add Product Details (Optional)
  12. 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"
    FieldDescription
    order_idProduct order ID
    amountProduct amount
    quantityProduct quantity

    Multiple products can be added using:

    productdetail[1]
    productdetail[2]
  13. Execute the Request
  14. 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"