Skip to main content

Integrity

OxPay ensures the integrity with a cryptographically generated signature. Merchants need to sign the payload using the Sign Key and create a signature.

Prepare Signature

Python version : 3.11.7

import json
import hashlib
import hmac

sign_key = '<SIGN_KEY>'.encode()

def reformat_json(json_string: str) -> str:
"""
Remove all line breaks and whitespaces only in the structure (does not apply to data in the payload). Do not change the original order. You can refer following example code
"""
data_json = json.loads(json_string)
return json.dumps(data_json, separators=(",", ":"))

json_string = """{
"field_one": "value one",
"field_three": "value three",
"field_two": "value two"
}"""

reformatted_json_string = reformat_json(json_string)

signature = hmac.new(sign_key, reformatted_json_string, hashlib.sha256).hexdigest()

print(signature)