StablePay Docs
产品开发者联系我们
首页产品文档快速开始APISaaS平台
首页
产品文档
支付产品能力自动货币转换
快速开始
快速开始身份认证支付会话商户交易退款
API
API 参考版本控制身份认证请求与响应分页频率限制错误处理支付服务退款服务Webhook 通知
SaaS平台
ShopifyWooCommerceShoplazza 店匠
  • API 参考
  • 版本控制
  • 身份认证
  • 请求与响应
  • 分页
  • 频率限制
  • 错误处理

支付平台 API

  • 支付服务
  • 退款服务
  • Webhook 通知
StablePay 开发者文档
Home
Product
Quick Start
API
SaaS
Login
Register
GitHub
Home
Product
Quick Start
API
SaaS
Login
Register
GitHub
  • API 概览 / Overview

    • API 参考 / Reference
    • 版本控制 / Versioning
    • 身份认证 / Authentication
    • 请求与响应 / Requests & Responses
    • 分页 / Pagination
    • 频率限制 / Rate Limits
    • 错误处理 / Errors
  • 支付平台 API / Payment API

    • 支付服务 / Payment Service
    • 退款服务 / Refund Service
    • Webhook 通知 / Webhook

身份认证

StablePay API 使用 API Key 进行身份验证。所有 API 请求都必须在 HTTP Header 中包含有效的 API Key。

The StablePay API uses API Keys for authentication. All API requests must include a valid API Key in the HTTP Header.

API Key 类型

StablePay 提供两种类型的 API 密钥:

类型前缀用途环境
测试密钥sk_test_用于开发和测试环境测试环境(Sandbox)
生产密钥sk_live_用于生产环境的真实交易生产环境

重要说明:

  • 测试密钥和生产密钥使用不同的 API 端点
  • 测试密钥产生的交易不会在区块链上真实执行
  • 生产密钥产生的交易会产生真实的资金转移

StablePay provides two types of API keys:

TypePrefixPurposeEnvironment
Test Keysk_test_For development and testingTest Environment (Sandbox)
Live Keysk_live_For real transactionsProduction Environment

Important Notes:

  • Test keys and live keys use different API endpoints
  • Transactions with test keys are not actually executed on the blockchain
  • Transactions with live keys result in real fund transfers

获取 API Key

步骤

  1. 登录 StablePay 商户后台
  2. 进入 开发者设置 > API 密钥
  3. 点击 创建新密钥
  4. 为密钥设置以下信息:
    • 名称:便于识别的密钥名称
    • 类型:测试密钥或生产密钥
    • 权限范围:选择适当的权限级别
    • IP 白名单(可选):限制只能从特定 IP 访问
  5. 点击 创建 并保存密钥

安全警告

API 密钥仅在创建时显示一次! 请立即保存到安全的地方。如果丢失,需要重新生成新密钥。

Steps

  1. Log in to StablePay Merchant Dashboard
  2. Navigate to Developer Settings > API Keys
  3. Click Create New Key
  4. Configure the following:
    • Name: A descriptive name for easy identification
    • Type: Test key or live key
    • Permissions: Select appropriate permission levels
    • IP Whitelist (optional): Restrict access to specific IPs
  5. Click Create and save the key

Security Warning

API keys are only displayed once upon creation! Please save them immediately to a secure location. If lost, you'll need to generate a new key.

认证方式

HTTP Header 认证(推荐)

在每个 API 请求的 HTTP Header 中包含 API Key:
Authorization: Bearer YOUR_API_KEY
**完整请求示例:**
curl -X GET https://api.stablepay.co/v1/payment/sessions/sess_123 \
  -H "Authorization: Bearer sk_live_abc123..." \
  -H "Content-Type: application/json"

权限范围

权限说明可执行操作
read只读权限查询支付会话、交易记录、账户信息等
write写入权限创建支付会话、发起退款、更新商户信息
admin管理权限删除资源、配置 Webhook、管理 API 密钥
PermissionDescriptionAvailable Operations
readRead-onlyQuery payment sessions, transactions, account info
writeWriteCreate payment sessions, initiate refunds, update merchant info
adminAdministrativeDelete resources, configure webhooks, manage API keys

认证错误

401 Unauthorized

原因:

  • API Key 无效或格式错误
  • API Key 已过期
  • API Key 已被删除或撤销
  • 未提供 API Key

Reasons:

  • Invalid or malformed API Key
  • API Key has expired
  • API Key has been deleted or revoked
  • No API Key provided
{
  "error": {
    "type": "authentication_error",
    "code": "invalid_api_key",
    "message": "Invalid API key"
  }
}

403 Forbidden

原因:

  • API Key 缺少执行该操作所需的权限
  • API Key 受 IP 白名单限制
  • 账户被暂停或受限

Reasons:

  • API Key lacks required permissions
  • API Key is restricted by IP whitelist
  • Account is suspended or restricted

最佳实践

  1. 使用环境变量 - 不要将 API Key 硬编码在代码中
  2. 分离测试和生产环境 - 为不同环境使用不同的密钥
  3. 定期轮换密钥 - 建议每 3-6 个月更换一次
  4. 使用密钥管理服务 - 推荐 AWS Secrets Manager 或 HashiCorp Vault
  5. 服务器端认证 - 永远不要在客户端暴露 API Key
  1. Use Environment Variables - Don't hardcode API Keys in your code
  2. Separate Test and Production - Use different keys for different environments
  3. Rotate Keys Regularly - Recommended every 3-6 months
  4. Use Key Management Services - AWS Secrets Manager or HashiCorp Vault recommended
  5. Server-Side Authentication - Never expose API Keys on the client side
// ✅ Correct: Use environment variables
const client = new StablePay({
  apiKey: process.env.STABLEPAY_API_KEY
});
最后更新 / Last Updated: 2025/12/16 11:41
Prev
版本控制 / Versioning
Next
请求与响应 / Requests & Responses