API Reference

To generate the checksum, kindly utilize your private key.

Below are examples of how to generate the checksum in various programming languages for your convenience.

👍

You can retrieve your Private Key //add link later

public function generateChecksum($data, $pkey)
{
  ksort($data);

  foreach ($data as $key => $value) {
    if (is_array($value)) {
      $data[$key] = json_encode($value);
    }
  }

  $data = implode(',', $data);
  $privatekey = openssl_pkey_get_private($pkey);
  return hash_hmac('sha256', $data, $privatekey);
}
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class ChecksumGenerator {
    public static String generateChecksum(Map<String, Object> data, String privateKey) throws Exception {
        TreeMap<String, Object> sortedData = new TreeMap<>(data);

        ObjectMapper mapper = new ObjectMapper();
        for (Map.Entry<String, Object> entry : sortedData.entrySet()) {
            if (entry.getValue() instanceof Map || entry.getValue() instanceof List) {
                sortedData.put(entry.getKey(), mapper.writeValueAsString(entry.getValue()));
            }
        }

        String concatenatedData = String.join(",", sortedData.values().stream()
                .map(Object::toString)
                .toArray(String[]::new));

        Mac mac = Mac.getInstance("HmacSHA256");
        SecretKeySpec secretKeySpec = new SecretKeySpec(privateKey.getBytes(), "HmacSHA256");
        mac.init(secretKeySpec);

        byte[] hash = mac.doFinal(concatenatedData.getBytes());
        StringBuilder hexString = new StringBuilder();
        for (byte b : hash) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    }
}

import json
import hmac
import hashlib

def generate_checksum(data, private_key):
    sorted_data = {k: data[k] for k in sorted(data)}

    for key, value in sorted_data.items():
        if isinstance(value, (dict, list)):
            sorted_data[key] = json.dumps(value)
    
    concatenated_data = ','.join(str(value) for value in sorted_data.values())
    return hmac.new(private_key.encode(), concatenated_data.encode(), hashlib.sha256).hexdigest()

const crypto = require('crypto');

function generateChecksum(data, privateKey) {
    const sortedKeys = Object.keys(data).sort();
    const sortedData = {};

    sortedKeys.forEach(key => {
        const value = data[key];
        sortedData[key] = Array.isArray(value) || typeof value === 'object'
            ? JSON.stringify(value)
            : value;
    });

    const concatenatedData = Object.values(sortedData).join(',');
    return crypto.createHmac('sha256', privateKey).update(concatenatedData).digest('hex');
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json;

public class ChecksumGenerator
{
    public static string GenerateChecksum(Dictionary<string, object> data, string privateKey)
    {
        // Sort the dictionary by key
        var sortedData = data.OrderBy(kvp => kvp.Key)
                             .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

        // Serialize nested objects or arrays to JSON
        foreach (var key in sortedData.Keys.ToList())
        {
            if (sortedData[key] is Dictionary<string, object> || sortedData[key] is IEnumerable<object>)
            {
                sortedData[key] = JsonConvert.SerializeObject(sortedData[key]);
            }
        }

        // Concatenate values with a comma
        var concatenatedData = string.Join(",", sortedData.Values);

        // Generate HMAC-SHA256 checksum
        using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(privateKey)))
        {
            byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(concatenatedData));
            return BitConverter.ToString(hash).Replace("-", "").ToLower();
        }
    }
}