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:
- Exclude the
signfield. - Exclude fields with
null,undefined, or empty string values. - 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.
- Sort field names in ascending ASCII order.
- 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. - Append the
SECRETto the end of the Canonical String. - Compute the
SHA-256hash 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);
}
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public final class OnerwaySign {
private static final ObjectMapper JSON = new ObjectMapper();
private static Object normalizeNested(Object value) throws JsonProcessingException {
if (value instanceof List<?> list) {
List<Object> result = new ArrayList<>();
for (Object item : list) {
result.add(normalizeNested(item));
}
return result;
}
if (value instanceof Map<?, ?> map) {
TreeMap<String, Object> result = new TreeMap<>();
for (Map.Entry<?, ?> entry : map.entrySet()) {
Object child = entry.getValue();
result.put(
String.valueOf(entry.getKey()),
child instanceof Map<?, ?> || child instanceof List<?>
? JSON.writeValueAsString(normalizeNested(child))
: child
);
}
return result;
}
return value;
}
private static String normalizeValue(Object value) throws JsonProcessingException {
if (value == null) {
return null;
}
if (value instanceof String text) {
return text.isEmpty() ? null : text;
}
if (value instanceof Map<?, ?> || value instanceof List<?>) {
return JSON.writeValueAsString(normalizeNested(value));
}
return String.valueOf(value);
}
public static String generateSignature(Map<String, Object> payload, String secret) throws Exception {
TreeMap<String, String> normalized = new TreeMap<>();
for (Map.Entry<String, Object> entry : payload.entrySet()) {
if (!"sign".equals(entry.getKey())) {
normalized.put(entry.getKey(), normalizeValue(entry.getValue()));
}
}
StringBuilder canonical = new StringBuilder();
for (String value : normalized.values()) {
if (value != null && !value.isEmpty()) {
canonical.append(value);
}
}
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest((canonical + secret).getBytes(StandardCharsets.UTF_8));
StringBuilder hex = new StringBuilder();
for (byte b : hash) {
hex.append(String.format("%02x", b));
}
return hex.toString();
}
}
package signing
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"sort"
)
func normalizeNested(value any) any {
switch typed := value.(type) {
case []any:
result := make([]any, len(typed))
for i, item := range typed {
result[i] = normalizeNested(item)
}
return result
case map[string]any:
result := map[string]any{}
for key, child := range typed {
switch child.(type) {
case map[string]any, []any:
bytes, _ := json.Marshal(normalizeNested(child))
result[key] = string(bytes)
default:
result[key] = child
}
}
return result
default:
return value
}
}
func normalizeValue(value any) *string {
if value == nil {
return nil
}
switch typed := value.(type) {
case string:
if typed == "" {
return nil
}
return &typed
case map[string]any, []any:
bytes, _ := json.Marshal(normalizeNested(value))
text := string(bytes)
return &text
default:
text := fmt.Sprint(typed)
return &text
}
}
func GenerateSignature(payload map[string]any, secret string) string {
keys := make([]string, 0, len(payload))
normalized := map[string]*string{}
for key, value := range payload {
if key == "sign" {
continue
}
normalized[key] = normalizeValue(value)
keys = append(keys, key)
}
sort.Strings(keys)
canonical := ""
for _, key := range keys {
if value := normalized[key]; value != nil {
canonical += *value
}
}
sum := sha256.Sum256([]byte(canonical + secret))
return hex.EncodeToString(sum[:])
}
import { createHash } from 'node:crypto'
function isPlainObject(value) {
return Object.prototype.toString.call(value) === '[object Object]'
}
function normalizeNested(value) {
if (Array.isArray(value)) {
return value.map((item) => normalizeNested(item))
}
if (isPlainObject(value)) {
const result = {}
Object.keys(value).forEach((key) => {
const child = value[key]
result[key] = child !== null && typeof child === 'object'
? JSON.stringify(normalizeNested(child))
: child
})
return result
}
return value
}
function normalizeValue(value) {
if (value === null || value === undefined || value === '') {
return value
}
if (typeof value === 'object') {
return JSON.stringify(normalizeNested(value))
}
return String(value)
}
export function generateSignature(payload, secret) {
const canonical = Object.keys(payload)
.filter((key) => key !== 'sign')
.sort()
.map((key) => normalizeValue(payload[key]))
.filter((value) => value !== null && value !== undefined && value !== '')
.join('')
return createHash('sha256')
.update(canonical + secret, 'utf8')
.digest('hex')
}
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.