Tài liệu tích hợp

Shop mới? Bắt đầu tại Hướng dẫn shop — không cần đọc API. Dùng thử · Tham chiếu API.

Gửi một giao dịch

POST /api/v1/events/ingest
POST /api/v1/events/ingest
Authorization: Bearer sp_live_...
Content-Type: application/json

{
  "bank_id": "MB",
  "account_number": "9981468491",
  "external_id": "txn-unique-id",
  "amount_vnd": 50000,
  "transfer_content": "NAP STABCDEF1234"
}

Gửi nhiều giao dịch

POST /api/v1/events/batch
POST /api/v1/events/batch
Authorization: Bearer sp_live_...
Content-Type: application/json

{
  "events": [
    {
      "bank_id": "MB",
      "account_number": "9981468491",
      "external_id": "txn-1",
      "amount_vnd": 50000,
      "transfer_content": "STCODE123"
    }
  ]
}

Tối đa 100 giao dịch / request.

Thông báo thanh toán

POST {url_thong_bao_shop}
X-StaliPay-Event: payment.matched
X-StaliPay-Timestamp: 1710000000
X-StaliPay-Signature: sha256=...
X-StaliPay-Delivery: {uuid}

{
  "event": "payment.matched",
  "id": "...",
  "data": {
    "amount_vnd": 50000,
    "order_code": "STCODE123",
    "transfer_content": "...",
    "bank_id": "MB",
    "bank_account": "9981468491",
    "reference": "txn-1"
  }
}

Chữ ký: HMAC-SHA256(secret, timestamp + "." + rawBody) → header sha256=hex

POST /api/v1/webhooks/sink — endpoint mẫu trên pay.stali.vn để kiểm tra chữ ký.

Kết nối trực tiếp ngân hàng

StaliPay đồng bộ giao dịch trực tiếp từ ngân hàng qua StaliPay Direct. Hạ tầng do StaliPay vận hành — tiền vẫn về tài khoản MB Bank của shop.

GET /api/v1/connector/direct/health

→ {
  "service": "StaliPay Direct",
  "status": "connected",
  "health": { "adapter": "mbbank_unofficial", ... }
}

Health: /api/status · /status

Bắt đầu với StaliPay

StaliPay là cổng thanh toán độc lập — kết nối trực tiếp ngân hàng (MB Bank qua StaliPay Direct), khớp mã đơn và gửi webhook có chữ ký về hệ thống bán hàng của bạn.

  1. Đăng ký shop tại StaliPay và cấu hình URL thông báo trong trang điều khiển.
  2. Thay endpoint ingest/webhook sang pay.stali.vn.
  3. Bật StaliPay Direct — đồng bộ giao dịch thẳng từ MB Bank.
  4. Dùng khóa sp_test_* thử trước khi chạy chính thức.

Chi tiết: Hướng dẫn shop · StaliPay Direct · Tham chiếu API

WooCommerce & website

Shop nhận webhook có chữ ký HMAC khi khách chuyển khoản MB Bank. Luồng khuyến nghị: bật StaliPay Direct trong trang điều khiển, cấu hình URL thông báo trỏ về WordPress.

  1. Trang điều khiển → Cài đặt → URL thông báo: https://shop-cua-ban.vn/wp-json/stalipay/v1/webhook
  2. Lưu webhook_secret từ trang điều khiển vào plugin hoặc functions.php.
  3. Khi nhận payment.matched, cập nhật đơn WooCommerce theo order_code trong payload.
// functions.php — xác minh chữ ký StaliPay
add_action('rest_api_init', function () {
  register_rest_route('stalipay/v1', '/webhook', [
    'methods' => 'POST',
    'callback' => 'stalipay_handle_webhook',
    'permission_callback' => '__return_true',
  ]);
});

function stalipay_handle_webhook(WP_REST_Request $req) {
  $secret = getenv('STALIPAY_WEBHOOK_SECRET');
  $sig = $req->get_header('x-stalipay-signature');
  $ts = $req->get_header('x-stalipay-timestamp');
  $body = $req->get_body();
  $expected = 'sha256=' . hash_hmac('sha256', $ts . '.' . $body, $secret);
  if (!hash_equals($expected, $sig)) {
    return new WP_Error('invalid_signature', 'Bad signature', ['status' => 401]);
  }
  $data = json_decode($body, true);
  if (($data['event'] ?? '') === 'payment.matched') {
    $order_code = $data['data']['order_code'] ?? '';
    // wc_get_orders / update status → processing
  }
  return ['ok' => true];
}

Tải plugin mẫu: stalipay-for-woocommerce.zip · stalipay-for-woocommerce.php · Thử chữ ký: Playground · StaliPay Direct đồng bộ thẳng từ MB Bank.

Đăng plugin lên WordPress.org

Gói stalipay-for-woocommerce.zip đã bao gồm readme.txt và LICENSE-GPL.txt theo chuẩn WordPress.org. Plugin kết nối thẳng StaliPay qua webhook HMAC.

  1. Tạo tài khoản developer tại wordpress.org/plugins/developers.
  2. Submit plugin: tên slug stalipay-for-woocommerce, mô tả nhấn mạnh cổng độc lập + MB Bank Direct.
  3. Trong Trang điều khiển StaliPay: cấu hình URL thông báo và webhook secret cho từng shop.
  4. Sau khi duyệt: shop cài từ kho chính thức, nhập API key từ trang điều khiển.

Tải zip: stalipay-for-woocommerce.zip · Trang tích hợp

Haravan

Shop cấu hình webhook URL trỏ về server tự host (hoặc serverless) để nhận payment.matched và cập nhật đơn qua Haravan API.

  1. Trang điều khiển StaliPay → Cài đặt → URL thông báo trỏ endpoint của bạn.
  2. Xác minh HMAC giống WooCommerce (header x-stalipay-signature).
  3. Gọi Haravan Admin API cập nhật trạng thái đơn theo order_code trong payload.
// Node.js — endpoint webhook Haravan + StaliPay
import crypto from "node:crypto";

export async function POST(req) {
  const secret = process.env.STALIPAY_WEBHOOK_SECRET;
  const body = await req.text();
  const sig = req.headers.get("x-stalipay-signature");
  const ts = req.headers.get("x-stalipay-timestamp");
  const expected = "sha256=" + crypto.createHmac("sha256", secret).update(ts + "." + body).digest("hex");
  if (sig !== expected) return new Response("unauthorized", { status: 401 });

  const event = JSON.parse(body);
  if (event.event !== "payment.matched") return Response.json({ ok: true });

  const orderCode = event.data?.order_code;
  // TODO: Haravan API — tìm đơn theo order_code, mark paid
  return Response.json({ ok: true, order_code: orderCode });
}

Xem thêm trang tích hợp · Tham chiếu API · Tải worker mẫu: stalipay-haravan-worker.js · wrangler-haravan.example.toml

Shopify

Shopify không có app StaliPay trên App Store — shop tích hợp qua webhook URL tùy chỉnh (App Proxy, Cloudflare Worker hoặc server riêng). StaliPay gửi payment.matched có chữ ký HMAC; backend của bạn gọi Shopify Admin API để đánh dấu đơn đã thanh toán.

  1. Trang điều khiển → Cài đặt → URL thông báo: endpoint HTTPS của bạn (ví dụ https://hooks.shop-cua-ban.com/stalipay).
  2. Lưu webhook_secret từ trang điều khiển vào biến môi trường server.
  3. Khi nhận payment.matched, tìm đơn Shopify theo order_code (thường là order name hoặc metafield) và tạo transaction manual / mark as paid.
// Cloudflare Worker — StaliPay → Shopify
export default {
  async fetch(request, env) {
    if (request.method !== "POST") return new Response("method", { status: 405 });
    const body = await request.text();
    const sig = request.headers.get("x-stalipay-signature");
    const ts = request.headers.get("x-stalipay-timestamp");
    const key = await crypto.subtle.importKey(
      "raw",
      new TextEncoder().encode(env.STALIPAY_WEBHOOK_SECRET),
      { name: "HMAC", hash: "SHA-256" },
      false,
      ["sign"],
    );
    const mac = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(ts + "." + body));
    const expected = "sha256=" + [...new Uint8Array(mac)].map(b => b.toString(16).padStart(2, "0")).join("");
    if (sig !== expected) return new Response("unauthorized", { status: 401 });

    const event = JSON.parse(body);
    if (event.event !== "payment.matched") return Response.json({ ok: true });

    const orderCode = event.data?.order_code;
    // Shopify Admin GraphQL: orders search by name/metafield → transactionsCreate
    return Response.json({ ok: true, order_code: orderCode });
  },
};

Khuyến nghị lưu order_code StaliPay vào metafield đơn hàng khi tạo checkout. Luồng: MB Bank → StaliPay Direct → webhook của bạn. · Tải worker mẫu: stalipay-shopify-worker.js · wrangler-shopify.example.toml

Tra cứu thanh toán

GET /api/v1/payments/lookup?order_code=STCODE123
Authorization: Bearer sp_live_...

Header Idempotency-Key trên ingest/batch — cùng key trong 24h trả kết quả đã lưu.

Tham chiếu OpenAPI

Spec machine-readable: stalipay-openapi.json · Xem tài liệu tương tác →

GET /api/metrics — định dạng Prometheus (tỷ lệ khớp, độ trễ Direct, p95 thông báo).