Skip to main content
This document outlines the preparation required before integrating with the StablePay API, including account and key acquisition, request signature algorithms, Webhook event notification mechanisms, and the request headers required for each endpoint.

Basic Information

Prerequisites

Before beginning integration, please confirm that you have:
  1. Registered a StablePay merchant account and completed the qualification review
  2. Created a store in the merchant dashboard, selected API as the channel type, and awaited review approval
  3. Generated and obtained the following in the store’s Key Management menu:
    • API Key: Used in the Authorization request header to identify the caller
    • Secret Key: Used to generate request signatures, please store it securely and never commit it to public code repositories or share it with others

Creating an API Store

If your team plans to integrate via the StablePay API, please first visit the Stores and Developers page.

Step 1: Create an API Store

  1. Open the Stores and Developers page.
  2. Click Create Store.
  3. Select API as the channel type.
  4. Enter the store name and domain according to your actual business information.
  5. Submit the creation request and await review by the StablePay operations team.
Creating an API store on the Stores and Developers page
API credentials and Webhook settings are created and managed at the store level. Please confirm you have created the correct store and wait for it to be reviewed and activated before proceeding.

Step 2: Wait for Store Activation

Once the review is complete, the store status will display as Activated. Only after the store is activated can you access the Keys and Webhook configuration options in the store’s action menu.

Creating an API Key and Secret Key

Once the store status displays as Activated:
  1. Return to the Stores and Developers page.
  2. Open the action menu for the corresponding store.
  3. Click Keys.
  4. Create the API Key and Secret Key.
  5. If the validity period is set to 0 days, the key will remain valid indefinitely.
Creating API Key and Secret Key in the action menu of an activated store, and accessing Webhook configuration
Please copy and securely store the Secret Key immediately after creation. Do not expose it in frontend code, browser storage, screenshots, public repositories, or chat messages.

Authentication and Signing

Required Request Headers

All API requests must include the following headers:

Signature Payload Construction

  • {requestBody}: For POST/PUT requests, the raw JSON string (do not reserialize or format)
  • For GET/DELETE methods with no request body: {requestBody} is an empty string
  • Signature algorithm: HMAC-SHA256(sign_payload, secret_key) → lowercase hex string

Example Code

The requestBody in the signature payload must be the actual raw bytes sent. Do not format or reorder JSON fields after calculating the signature, otherwise the signature verification will fail.

Required Headers by Endpoint

POST /api/v1/subscriptions/create also requires the Idempotency-Key header. When retrying with the same key, the server returns the initially created subscription object.

Idempotency

The following endpoints support idempotency using merchant-defined IDs as idempotency keys: When submitting with the same idempotency key, the server returns the initially created resource without generating duplicate data.

Webhook Notifications

StablePay asynchronously pushes key events to your configured callback URL via Webhook.
If you need to view event examples, risk control freeze status explanations, and handling suggestions for payment.failed with status = "frozen", please refer to Webhook Notifications.

Event Types

Webhook Request Headers

Signature Verification Steps

  1. Extract X-StablePay-Signature, X-StablePay-Timestamp, and X-StablePay-Nonce from the request headers;
  2. Verify that the timestamp is within 5 minutes of the current time (replay prevention)
  3. Verify that the Nonce length is between 16 and 64 characters
  4. Take the raw request body bytes (do not parse then reserialize), and concatenate as follows:
  5. Calculate HMAC-SHA256 using your Secret Key to obtain a lowercase hex string
  6. Compare with the signature in the request header using constant-time comparison (e.g., hmac.compare_digest)

Response Requirements and Retry Strategy

  • Your service must return HTTP 2xx within 30 seconds
  • Returning 429 or 5xx will enter the retry queue; other 4xx responses will not be retried
  • Maximum of 10 retries, using exponential backoff intervals (minutes): 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024

Idempotent Consumption

Please use X-StablePay-Event-ID (or the id field in the request body) as the idempotency key. Check whether the event has already been processed before handling to avoid side effects from duplicate delivery.

Error Responses

Errors are returned using HTTP status codes with a JSON response body. The error field may be a string or a structured object:
Common error codes:

Security Recommendations

  • The Secret Key must only be used server-side and must not appear in frontend code, APKs, mini-program packages, or logs
  • We recommend injecting the Secret Key via key management services (KMS/Vault/SSM) in your CI/CD pipeline
  • Webhook callback URLs must use HTTPS
  • For each received Webhook, perform signature verification + idempotent deduplication + business status verification (e.g., ensure the order status is “paid” before processing a refund)
  • Regularly rotate your API Key and Secret Key in the merchant backend
Last modified on June 29, 2026