API Standards and Protocols
Transport and Data Format
Signature and Verification
Response Evaluation
Always evaluate API responses using this process:- Check the HTTP status code first
- Then examine the
status,code,label, anderrorMessagefields in the response body - Extract business data from the
datafield if the request was successful
Unified Response Structure
All GatePay API responses follow this standardized structure:Request Parameter Standards
Merchant Order Number (merchantTradeNo)
The merchant order number is a unique identifier you assign to each transaction:
Transaction Amount
Timestamp Format
Request Headers and Signing
Required Request Headers
Every API request must include these headers:Signature String Format
The signature is computed from a string containing three lines, each ending with a newline character (\n):
<request_timestamp>is the value ofX-GatePay-Timestamp<request_nonce>is the value ofX-GatePay-Nonce<request_body>is the raw JSON body of the request, or an empty string if there is no body
Signature Generation Steps
Follow these steps to compute theX-GatePay-Signature header value:
- Generate a unique
X-GatePay-Timestamp(current UTC time in milliseconds) - Generate a random
X-GatePay-Nonce(32 characters or less, letters and digits only) - Read the raw JSON request body as
request_body; use an empty string if there is no body - Construct the signature string:
timestamp\nnonce\nbody\n - Compute HMAC-SHA512 using your Payment API Secret as the key
- Encode the result as a hexadecimal string
- Place the computed signature into the
X-GatePay-Signatureheader
Example Request Structure
The following example is provided only to explain how the signing string is constructed. It is not a complete business-ready request body for a specific endpoint. For actual required fields, always follow the corresponding API Reference page and OpenAPI definition.Payment Result Callbacks
Callback Overview
GatePay sends asynchronous payment notifications to your configured callback URL via HTTP POST requests. These notifications inform your system of payment status changes. For comprehensive details on callback events and handling, refer to the Notification guide.Callback Payload Structure
The payload below is shown to explain the common callback envelope. The object carried indata varies by product and business type, so it should always be read together with the relevant product guide and callback reference.
GatePay will POST a JSON payload with the following structure:
Expected Callback Response
Your callback endpoint must respond with a JSON object indicating successful processing:
Success Response Example:
Callback Verification Steps
Every callback you receive must be verified to ensure it originated from GatePay and has not been tampered with:- Extract the
X-GatePay-Timestampheader from the incoming callback request - Extract the
X-GatePay-Nonceheader from the incoming callback request - Extract the
X-GatePay-Signatureheader from the incoming callback request - Read the raw JSON callback request body
- Construct the signature string using the format:
timestamp\nnonce\nbody\n - Compute HMAC-SHA512 using your Payment API Secret as the key
- Compare the computed signature with the
X-GatePay-Signatureheader value - Only process the callback if the signatures match exactly
Callback Request Headers
When GatePay sends a callback to your endpoint, it includes these headers:Time Window Clarification
Two different time windows appear in this documentation, and they apply to different scenarios:
Read them as follows:
10 secondsapplies to requests you send to GatePay.5 minutesis a recommended merchant-side validation window when verifying callbacks.- If your security model requires a stricter callback window, you can reduce it as long as normal network delay is still tolerated.
Tools and Resources
Signature Verification Tool
GatePay provides an online tool to help you debug and verify signatures during development: GatePay Signature Verification Tool This tool allows you to:- Test signature generation with sample data
- Verify computed signatures match expected values
- Debug signature-related integration issues
Error Handling
For a comprehensive list of error codes and best practices for handling API errors, see the Error Codes and Best Practices guide.Security Best Practices
- Secure Key Storage: Store your Payment API Secret and Authorization Secret securely on your server. Never expose these secrets in client-side code or version control.
- Nonce Uniqueness: Ensure each request uses a unique nonce to prevent replay attacks.
- Timestamp Validation: Keep merchant-initiated request timestamps within the 10-second acceptance window, and use a local callback-validation window such as 5 minutes for anti-replay checks.
- Signature Verification: Always verify callback signatures before processing any sensitive operations.
- HTTPS Only: All communication with GatePay must use HTTPS with TLS 1.2 or above.
- Callback Idempotency: Design your callback handler to be idempotent, as GatePay may retry callbacks if it does not receive a successful response.
- Error Messages: Do not expose sensitive information (such as keys or internal system details) in error messages returned to the client.
Related Documentation
- Integration Overview - App configuration and credential setup
- Notification - Detailed callback event handling
- Error Codes and Best Practices - Error code reference and troubleshooting

