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

核心概念

  • 支付会话
  • 商户
  • 交易
  • 退款
StablePay 开发者文档
Home
Product
Quick Start
API
SaaS
Login
Register
GitHub
Home
Product
Quick Start
API
SaaS
Login
Register
GitHub
  • 入门指南 / Getting Started

    • 快速开始 / Quick Start
    • 身份认证 / Authentication
  • 核心概念 / Core Concepts

    • 支付会话 / Payment Sessions
    • 商户 / Merchants
    • 交易 / Transactions
    • 退款 / Refunds

快速开始

本指南将帮助您在 10 分钟内完成 StablePay 的集成,开始接受加密货币支付。

前置条件

在开始之前,请确保您已经:

  • 注册了 StablePay 商户账号
  • 获取了 API 密钥
  • 具备基本的 HTTP API 调用知识

Before you begin, make sure you have:

  • Registered a StablePay merchant account
  • Obtained API keys
  • Basic knowledge of HTTP API calls

第一步:获取 API 密钥

  1. 登录 StablePay 商户后台
  2. 进入 开发者设置 页面
  3. 创建新的 API 密钥
  4. 安全保存您的密钥(仅显示一次)

安全提示

请妥善保管您的 API 密钥,不要将其提交到公开代码仓库或泄露给他人。

  1. Log in to StablePay Merchant Dashboard
  2. Go to Developer Settings page
  3. Create new API keys
  4. Securely save your keys (shown only once)

Security Note

Please keep your API keys safe and do not commit them to public code repositories or share them with others.

第二步:配置环境

StablePay 提供两个环境:
环境Base URL用途
测试环境https://api-test.stablepay.co开发和测试
生产环境https://api.stablepay.co正式业务

建议先在测试环境完成集成和测试,再切换到生产环境。

EnvironmentBase URLPurpose
Test Environmenthttps://api-test.stablepay.coDevelopment and testing
Production Environmenthttps://api.stablepay.coLive business

It is recommended to complete integration and testing in the test environment first, then switch to the production environment.

第三步:创建您的第一笔支付

使用 API

curl -X POST https://api-test.stablepay.co/v1/payment/sessions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "merchant_id": "your_merchant_id",
    "order_id": "order_001",
    "amount": {
      "value": "10000",
      "currency": "USDT"
    },
    "description": "Test order",
    "success_url": "https://your-site.com/payment/success",
    "cancel_url": "https://your-site.com/payment/cancel",
    "webhook_url": "https://your-site.com/webhooks/payment"
  }'

响应示例

{
  "base": {
    "code": 0,
    "message": "success"
  },
  "session": {
    "session_id": "sess_1234567890",
    "merchant_id": "your_merchant_id",
    "order_id": "order_001",
    "amount": {
      "value": "10000",
      "currency": "USDT"
    },
    "status": "PENDING",
    "payment_url": "https://checkout.stablepay.co/sess_1234567890",
    "tron_address": "TXxx...xxxx",
    "qr_code_data": "TXxx...xxxx",
    "created_at": 1234567890,
    "expires_at": 1234569690
  }
}

第四步:引导用户支付

获取到支付会话后,有两种方式引导用户完成支付:

After obtaining the payment session, there are two ways to guide users to complete payment:

方式 1:跳转到托管支付页面(推荐)

将用户重定向到返回的 payment_url:

Redirect the user to the returned payment_url:

// Frontend code
window.location.href = response.session.payment_url;

StablePay 会为您展示专业的支付页面,包括:

  • 收款地址和二维码
  • 支付倒计时
  • 支付状态实时更新
  • 多语言支持

StablePay will display a professional payment page for you, including:

  • Payment address and QR code
  • Payment countdown
  • Real-time payment status updates
  • Multi-language support

方式 2:自定义支付页面

使用返回的 tron_address 和 qr_code_data 自己构建支付页面:

Use the returned tron_address and qr_code_data to build your own payment page:

<div class="payment-page">
  <h2>Please scan QR code with wallet to pay</h2>
  <img src="qr-code-url" alt="Payment QR Code">
  <p>Payment address: <code>{{ tron_address }}</code></p>
  <p>Payment amount: {{ amount.value }} {{ amount.currency }}</p>
  <p>Time remaining: <span id="countdown"></span></p>
</div>

<script>
// Poll for payment status
setInterval(async () => {
  const status = await checkPaymentStatus(sessionId);
  if (status === 'COMPLETED') {
    window.location.href = successUrl;
  }
}, 3000);
</script>

第五步:接收支付通知

当支付完成后,StablePay 会向您配置的 webhook_url 发送通知:

When payment is completed, StablePay will send a notification to your configured webhook_url:

{
  "event": "payment.succeeded",
  "data": {
    "session_id": "sess_1234567890",
    "merchant_id": "your_merchant_id",
    "order_id": "order_001",
    "status": "COMPLETED",
    "amount": {
      "value": "10000",
      "currency": "USDT"
    },
    "transaction": {
      "tx_hash": "0xabc...xyz",
      "from_address": "TYxx...xxxx",
      "amount_received": {
        "value": "10000",
        "currency": "USDT"
      },
      "block_number": 12345678,
      "confirmations": 20,
      "confirmed_at": 1234567900
    }
  },
  "signature": "webhook_signature"
}

验证 Webhook 签名

重要

请务必验证 webhook 签名,确保请求来自 StablePay。

Important

Be sure to verify the webhook signature to ensure the request is from StablePay.

const crypto = require('crypto');

function verifyWebhookSignature(payload, signature, secret) {
  const expectedSignature = crypto
    .createHmac('sha256', secret)
    .update(JSON.stringify(payload))
    .digest('hex');

  return signature === expectedSignature;
}

// Express.js example
app.post('/webhooks/payment', (req, res) => {
  const signature = req.headers['x-stablepay-signature'];

  if (!verifyWebhookSignature(req.body, signature, WEBHOOK_SECRET)) {
    return res.status(400).send('Invalid signature');
  }

  const { event, data } = req.body;

  if (event === 'payment.succeeded') {
    // Handle payment success logic
    console.log('Payment succeeded:', data.order_id);
    // Update order status, ship goods, etc.
  }

  res.status(200).send('OK');
});

第六步:查询支付状态

您也可以主动查询支付状态:

You can also proactively query payment status:

curl -X GET https://api-test.stablepay.co/v1/payment/sessions/sess_1234567890 \
  -H "Authorization: Bearer YOUR_API_KEY"

使用 SDK(推荐)

我们提供了多语言 SDK,让集成更加简单:

We provide multi-language SDKs to make integration easier:

Go SDK

package main

import (
    "context"
    "log"
    "code.wenfu.cn/stablepay/stablepay-idl/generated/go/payplatform/payment/paymentservice"
    "code.wenfu.cn/stablepay/stablepay-idl/generated/go/payplatform/common"
)

func main() {
    // Create client
    client, err := paymentservice.NewClient("payment-service")
    if err != nil {
        log.Fatal(err)
    }

    // Create payment session
    req := &payment.CreateSessionRequest{
        MerchantID:  "your_merchant_id",
        OrderID:     "order_001",
        Amount:      &common.Amount{Value: "10000", Currency: "USDT"},
        Description: "Test order",
        SuccessURL:  "https://your-site.com/success",
        CancelURL:   "https://your-site.com/cancel",
        WebhookURL:  "https://your-site.com/webhooks/payment",
    }

    resp, err := client.CreateSession(context.Background(), req)
    if err != nil {
        log.Fatal(err)
    }

    log.Printf("Payment URL: %s", resp.Session.PaymentUrl)
}

Node.js SDK

const StablePay = require('@stablepay/node');

const client = new StablePay({
  apiKey: 'YOUR_API_KEY',
  environment: 'test' // 'test' or 'production'
});

async function createPayment() {
  try {
    const session = await client.payments.createSession({
      merchant_id: 'your_merchant_id',
      order_id: 'order_001',
      amount: {
        value: '10000',
        currency: 'USDT'
      },
      description: 'Test order',
      success_url: 'https://your-site.com/success',
      cancel_url: 'https://your-site.com/cancel',
      webhook_url: 'https://your-site.com/webhooks/payment'
    });

    console.log('Payment URL:', session.payment_url);
  } catch (error) {
    console.error('Failed to create payment:', error);
  }
}

createPayment();

下一步

恭喜!您已经完成了基本集成。接下来可以:

  • 📚 了解核心概念
  • 🔐 配置身份验证
  • 🛠 查看 API 参考文档

Congratulations! You have completed the basic integration. Next you can:

  • 📚 Learn about Core Concepts
  • 🔐 Configure Authentication
  • 🛠 Check API Reference

常见问题

测试环境如何模拟支付?

测试环境提供了模拟支付功能,您可以在商户后台获取测试用的钱包地址和余额,用于完整测试支付流程。

The test environment provides simulated payment functionality. You can obtain test wallet addresses and balances in the merchant dashboard to fully test the payment process.

支付会话的有效期是多久?

默认 30 分钟,您可以通过 expires_in 参数自定义(60 - 3600 秒)。

The default is 30 minutes. You can customize it through the expires_in parameter (60 - 3600 seconds).

如何处理支付超时?

当支付会话过期后,状态会变为 EXPIRED。您可以创建新的支付会话,或者引导用户重新发起支付。

When a payment session expires, the status will change to EXPIRED. You can create a new payment session or guide the user to initiate payment again.

需要多少个区块确认?

TRON 网络默认需要 19 个区块确认,大约需要 1-2 分钟。确认后支付状态会变为 COMPLETED。

The TRON network requires 19 block confirmations by default, which takes approximately 1-2 minutes. After confirmation, the payment status will change to COMPLETED.

最后更新 / Last Updated: 2025/12/16 11:41
Next
身份认证 / Authentication