Onerway

Request signing

Generate SHA256 signatures for Transfer API requests.

Onerway authenticates API requests using the sign field. Generate the sign dynamically on your server using the environment-specific SECRET. Never expose the SECRET in frontend code, mobile applications, or public repositories.

Before sending server-side API requests, you must also configure the IP allowlist for the target environment. Configure sandbox and production allowlists separately.

Signing rules

Generate the sign dynamically using the following rules:

  1. Exclude the sign field.
  2. Exclude fields with null, undefined, or empty string values.
  3. Serialize object (Object) and array (Array) values into compact JSON strings (without extra spaces or line breaks); see Object and array fields for nested structures.
  4. Sort field names in ascending ASCII order.
  5. Concatenate only the sorted field values directly. Do not include field names, equals signs (=), ampersands (&), or any other separators. The resulting string is called the Canonical String.
  6. Append the SECRET to the end of the Canonical String.
  7. Compute the SHA-256 hash of the final string and output the result as a lowercase hexadecimal string.

Non-string scalars are concatenated as strings: booleans become true / false; numbers use their decimal string form without trailing zeros or scientific notation (for example 1.10 is concatenated as 1.1).

Object and array fields

Transfer uses JSON strings for receiverInfo, address, and accountInfomation. The following receiverInfo fragment illustrates conversion; include the other fields required by the endpoint in a complete request.

{
  "receiverInfo": {
    "firstName": "Beta",
    "lastName": "Tester"
  }
}

After conversion, use the same value for signing and sending:

{
  "receiverInfo": "{\"firstName\":\"Beta\",\"lastName\":\"Tester\"}"
}

The payoutIds and requestIds fields in batch transfer queries also use JSON array strings. Follow the endpoint schema. Use an already serialized string directly for signing; do not serialize it again.

Request example

This example uses Initiate a transfer by beneficiary ID. The merchant number 800699 and beneficiary ID are examples. Replace them with values for your environment and use a unique requestId for each payout.

{
  "merchantNo": "800699",
  "beneficiaryId": "1953727182141784064",
  "requestId": "demo_transfer_001",
  "chargeFlag": "Y",
  "sourceCurrency": "USD",
  "targetCurrency": "PKR",
  "targetAmount": 1901,
  "transactionPurpose": "4",
  "sign": null
}

Calculate the signature and include it in the final request:

{
  "beneficiaryId": "1953727182141784064",
  "chargeFlag": "Y",
  "merchantNo": "800699",
  "requestId": "demo_transfer_001",
  "sign": "replace_with_calculated_signature",
  "sourceCurrency": "USD",
  "targetAmount": 1901,
  "targetCurrency": "PKR",
  "transactionPurpose": "4"
}

Worked example

Check your implementation using Query transfer parameters and the demo secret demo_signing_secret:

{
  "merchantNo": "800699",
  "requestId": "demo_transfer_001",
  "sign": null
}
Canonical String: 800699demo_transfer_001
String to hash:   800699demo_transfer_001demo_signing_secret
sign:             25750766247df1f829bd6fa38b879f3c27fd5781e6cd02d806285f1be31b746d

Code examples

The examples below assume the input is a server-side map (Map) or object (Object); if a field is already a JSON string, ensure it has been serialized with the same inside-out rule. Use the normalizeValue result for both signing and the final request body; do not rebuild object or array fields with a different serializer after calculating the signature — this causes verification failures on the gateway.

<?php

function is_assoc_array(array $value): bool {
    if ($value === []) {
        return false;
    }
    return array_keys($value) !== range(0, count($value) - 1);
}

function normalize_nested($value) {
    if (!is_array($value)) {
        return $value;
    }

    if (!is_assoc_array($value)) {
        return array_map('normalize_nested', $value);
    }

    $result = [];
    foreach ($value as $key => $child) {
        $result[$key] = is_array($child)
            ? json_encode(normalize_nested($child), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
            : $child;
    }
    return $result;
}

function normalize_value($value) {
    if ($value === null || $value === '') {
        return $value;
    }
    if (is_bool($value)) {
        return $value ? 'true' : 'false';
    }
    return is_array($value)
        ? json_encode(normalize_nested($value), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
        : (string) $value;
}

function generate_signature(array $payload, string $secret): string {
    $normalized = [];
    foreach ($payload as $key => $value) {
        if ($key !== 'sign') {
            $normalized[$key] = normalize_value($value);
        }
    }

    ksort($normalized, SORT_STRING);

    $canonical = '';
    foreach ($normalized as $value) {
        if ($value !== null && $value !== '') {
            $canonical .= $value;
        }
    }

    return hash('sha256', $canonical . $secret);
}

Payment notification verification

Transfer payment notifications authenticate the sender with Authorization: Credentials <token>. See Transfer result notifications for configuration, verification, and acknowledgement requirements.

Common mistakes

  • Object or array fields are not converted to JSON strings as defined by the endpoint, or are serialized again after signing, so the transmitted values differ from the signed values.
  • Field names, equals signs, or separators are concatenated, or fields are not sorted in ascending ASCII order.
  • Fields not defined by the endpoint are sent, causing the sets of signed fields to differ.
  • Merchant credentials and API URLs belong to different environments.

When you need support

Provide the environment, endpoint path, business request ID, and error response. Compare the Canonical String before appending the secret and the generated sign on your server. If you need to share a request, use a secure channel and protect personal and account information. Never log or send secret or the string to hash after the secret has been appended.