認証

すべてのAPIリクエストにはHTTPヘッダーによるHMAC-SHA256認証が必要です。ダッシュボード → ストアで認証情報を取得。

必須ヘッダー

ヘッダー説明
X-Api-KeyストアのAPIキー
X-Timestamp現在のUnixタイムスタンプ(±5分)
X-SignatureAPI Secretで署名されたtimestamp + method + path + bodyのHMAC-SHA256

署名の例

payload = "1700000000" + "POST" + "/api/v1/payment/create" + '{"amount":"100"}'
signature = HMAC-SHA256(payload, api_secret)
各ストアには独自のAPIキーがあります。1アカウントで複数ストアを持てます。

決済の作成

POST/api/v1/payment/createAuth Required

新しい決済を作成。暗号通貨直接指定とフィアット変換に対応。

リクエストボディ (JSON)

パラメータ説明
amount*string暗号通貨金額(例:"100.00" USDTまたは "0.005" BTC)
order_idstring内部注文ID
fiat_amountstringフィアット金額(amountを上書き)
fiat_currencystringフィアット通貨:USD、EUR、RUB、CNY、GBP
metadataobject任意のJSON(webhookで返却)
通貨はダッシュボードでストアごとに設定。複数通貨の場合、APIは選択ページ付きのpayment_urlを返します。1通貨のみの場合は即座に作成。
fiat_amount + fiat_currencyでフィアットから自動変換。

レスポンス — 単一通貨

{
  "success": true,
  "data": {
    "payment_id": "a1b2c3d4-...",
    "amount": "100.14",
    "currency": "USDT_TRC20",
    "pay_address": "TXyz...abc",
    "status": "pending",
    "expires_at": "2025-01-15T12:30:00Z",
    "payment_url": "https://soko.ai/pay/a1b2c3d4-..."
  }
}

レスポンス — 複数通貨(選択が必要)

{
  "success": true,
  "data": {
    "payment_id": null,
    "status": "selecting",
    "amount": 100,
    "currencies": ["USDT_TRC20", "BTC", "ETH"],
    "payment_url": "https://soko.ai/pay/select?token=..."
  }
}
重要:常にpayment_urlにリダイレクト。payment_idnullの場合、ユーザーは通貨を選択後、決済が自動作成されます。

決済ステータス

GET/api/v1/payment/{payment_id}Auth Required

レスポンス

{
  "success": true,
  "data": {
    "payment_id": "a1b2c3d4-...",
    "order_id": "ORDER-123",
    "status": "completed",
    "amount_requested": 100.14,
    "amount_with_cents": 100.14,
    "amount_received": 100.14,
    "currency": "USDT_TRC20",
    "pay_address": "TXyz...abc",
    "tx_hash": "abc123...",
    "confirmations": 21,
    "confirmed_at": "2025-01-15T12:25:00Z",
    "expires_at": "2025-01-15T12:30:00Z",
    "created_at": "2025-01-15T12:00:00Z"
  }
}

ステータス一覧

Status説明
selecting通貨選択中
pending支払い待ち
queuedUSDTスロット使用中
confirmingトランザクション検出、確認待ち
completed決済確認済み
expiredタイムアウト
overpaid予想以上の金額
underpaid予想以下の金額

決済一覧

GET/api/v1/paymentsAuth Required

ページ分割リスト。フィルタ対応。

クエリパラメータ

パラメータ説明
pageoptionalintegerページ番号(デフォルト: 1)
per_pageoptionalinteger1ページあたりの結果数、1-100(デフォルト: 20)
statusoptionalstringステータスでフィルター
currencyoptionalstring通貨でフィルター

マーチャント残高

GET/api/v1/merchant/balanceAuth Required
{
  "success": true,
  "data": {
    "USDT_TRC20": {
      "available": 1250.50,
      "pending": 100.00,
      "total_received": 5000.00,
      "total_withdrawn": 3750.00,
      "total_commission": 75.00
    },
    "BTC": {
      "available": 0.05000000,
      "pending": 0.00100000,
      "total_received": 0.10000000,
      "total_withdrawn": 0.04900000,
      "total_commission": 0.00150000
    },
    "ETH": {
      "available": 1.25000000,
      "pending": 0.10000000,
      "total_received": 2.00000000,
      "total_withdrawn": 0.65000000,
      "total_commission": 0.03000000
    }
  }
}

為替レート Public

GET/api/v1/rates

認証不要。5分キャッシュ。

変換

GET /api/v1/rates?amount=5000&fiat=RUB&crypto=USDT_TRC20

{
  "success": true,
  "data": {
    "rates": {
      "btc": { "usd": 97500, "eur": 91200, "rub": 8775000 },
      "eth": { "usd": 3200, "eur": 2990, "rub": 288000 },
      "usdt": { "usd": 1.0001, "eur": 0.935, "rub": 90.5 }
    },
    "converted": 55.24
  }
}

Webhook

ステータス変更時にPOSTリクエストを送信します。

Webhookヘッダー

ヘッダー説明
X-SignatureWebhook Secretで署名されたtimestamp + bodyのHMAC-SHA256
X-TimestampUnixタイムスタンプ

Webhookボディ

{
  "event": "payment.completed",
  "payment_id": "a1b2c3d4-...",
  "order_id": "ORDER-123",
  "amount": 100.14,
  "amount_received": 100.14,
  "currency": "USDT_TRC20",
  "tx_hash": "abc123...",
  "confirmed_at": "2025-01-15T12:25:00Z",
  "status": "completed",
  "metadata": { "user_id": 42 }
}

イベント

payment.completed決済確認
payment.confirmingトランザクション検出
payment.expired決済期限切れ
payment.underpaid不足金額
必ず署名を検証。HTTP 200を返却。最大5回再試行。

署名検証 (PHP)

$timestamp = $_SERVER['HTTP_X_TIMESTAMP'];
$signature = $_SERVER['HTTP_X_SIGNATURE'];
$body = file_get_contents('php://input');

$expected = hash_hmac('sha256', $timestamp . $body, $webhookSecret);

if (!hash_equals($expected, $signature)) {
    http_response_code(401);
    die('Invalid signature');
}

$payload = json_decode($body, true);
// Process payment...

JavaScriptウィジェット

決済ウィジェットを埋め込み。HTML + JSのみ。

クイックスタート

<script src="https://soko.ai/widget.js"></script>
<script>
CryptoMerchant.init({ apiKey: 'YOUR_STORE_API_KEY' });

document.getElementById('pay-btn').addEventListener('click', function() {
    CryptoMerchant.pay({
        amount: 100.00,
        order_id: 'ORDER-123',

        // Or use fiat conversion:
        // fiat_amount: 5000,
        // fiat_currency: 'RUB',

        onSuccess: function(payment) {
            alert('Payment confirmed! TX: ' + payment.tx_hash);
        },
        onClose: function() {
            console.log('Widget closed');
        },
        onError: function(err) {
            console.error('Payment error:', err);
        }
    });
});
</script>

<button id="pay-btn">Pay with Crypto</button>
iframeオーバーレイで開きます。

あらゆるWebサイトで暗号通貨の寄付を受け付けます。API署名不要 — ストアAPIキーのみ。

仕組み

ストア設定で寄付を有効にし、Webサイトにウィジェットを追加します。訪問者はUSDT、BTC、ETHで寄付できます。各寄付は追跡可能な支払いとして作成され、ダッシュボードの❤️ 寄付で確認できます。

クイックスタート — ボタン

スクリプトの位置に「寄付」ボタンを追加:

<script src="https://soko.ai/donate-widget.js"
        data-store-key="YOUR_STORE_API_KEY"></script>

トップバー

ページ上部に固定の寄付バーを表示:

<script src="https://soko.ai/donate-widget.js"
        data-store-key="YOUR_STORE_API_KEY"
        data-mode="topbar"></script>

インライン

指定した要素内にボタンをレンダリング:

<div id="crypto-donate"></div>
<script src="https://soko.ai/donate-widget.js"
        data-store-key="YOUR_STORE_API_KEY"
        data-mode="inline"
        data-target="crypto-donate"></script>

カスタマイズ属性

パラメータ説明
data-store-keyストアAPIキー required
data-modebutton(デフォルト)、topbarinline
data-targetインラインモード用の要素ID optional
data-textカスタムテキスト(ストア設定を上書き) optional
data-amountsプリセット金額、カンマ区切り: "5,10,25" optional
data-colorアクセントカラー、例: "#e11d48" optional

直接寄付ページ

ウィジェットなしで寄付ページに直接リンクすることもできます:

https://soko.ai/donate/YOUR_STORE_API_KEY

API: 寄付作成

POST/donate/create Public

プログラムで寄付を作成。署名不要。

パラメータ説明
api_keyストアAPIキー required
fiat_amount法定通貨の金額(例: 10required*
fiat_currency法定通貨コード(例: USDoptional, default: USD
amount暗号通貨の直接金額(法定通貨の代替) optional
currencyUSDT_TRC20BTCETH required
donor_name寄付者の名前 optional
donor_message寄付者のメッセージ(最大500文字) optional
寄付はWebhookをトリガーしません。ダッシュボード → ❤️ 寄付で監視してください。

エラー処理

{
  "success": false,
  "error": "Description of what went wrong"
}
HTTPコード意味
200成功
400不正なリクエスト
401認証ヘッダー不足
403無効な署名
404見つかりません
500サーバーエラー

コード例

PHP
Python
Node.js
cURL
<?php
$apiKey = 'your_api_key';
$apiSecret = 'your_api_secret';

$body = json_encode([
    'amount' => '100.00',
    'order_id' => 'ORDER-' . time(),
]);

$timestamp = (string) time();
$method = 'POST';
$path = '/api/v1/payment/create';

$signature = hash_hmac('sha256', $timestamp . $method . $path . $body, $apiSecret);

$ch = curl_init('https://soko.ai' . $path);
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'X-Api-Key: ' . $apiKey,
        'X-Timestamp: ' . $timestamp,
        'X-Signature: ' . $signature,
    ],
]);

$response = json_decode(curl_exec($ch), true);
echo $response['data']['payment_url'];
import hmac, hashlib, time, json, requests

API_KEY = 'your_api_key'
API_SECRET = 'your_api_secret'
BASE_URL = 'https://soko.ai'

body = json.dumps({
    'amount': '100.00',
    'order_id': f'ORDER-{int(time.time())}'
})

timestamp = str(int(time.time()))
method = 'POST'
path = '/api/v1/payment/create'

payload = f'{timestamp}{method}{path}{body}'
signature = hmac.new(API_SECRET.encode(), payload.encode(), hashlib.sha256).hexdigest()

r = requests.post(f'{BASE_URL}{path}', data=body, headers={
    'Content-Type': 'application/json',
    'X-Api-Key': API_KEY,
    'X-Timestamp': timestamp,
    'X-Signature': signature,
})

print(r.json()['data']['payment_url'])
const crypto = require('crypto');
const https = require('https');

const API_KEY = 'your_api_key';
const API_SECRET = 'your_api_secret';

const body = JSON.stringify({
    amount: '100.00',
    order_id: `ORDER-${Date.now()}`
});

const timestamp = Math.floor(Date.now() / 1000).toString();
const method = 'POST';
const path = '/api/v1/payment/create';

const signature = crypto
    .createHmac('sha256', API_SECRET)
    .update(timestamp + method + path + body)
    .digest('hex');

fetch('https://soko.ai' + path, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'X-Api-Key': API_KEY,
        'X-Timestamp': timestamp,
        'X-Signature': signature,
    },
    body
})
.then(r => r.json())
.then(data => console.log(data.data.payment_url));
# Generate signature first (bash):
TIMESTAMP=$(date +%s)
BODY='{"amount":"100.00","order_id":"ORDER-1"}'
PAYLOAD="${TIMESTAMP}POST/api/v1/payment/create${BODY}"
SIGNATURE=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "your_api_secret" | cut -d' ' -f2)

curl -X POST https://soko.ai/api/v1/payment/create \
  -H "Content-Type: application/json" \
  -H "X-Api-Key: your_api_key" \
  -H "X-Timestamp: $TIMESTAMP" \
  -H "X-Signature: $SIGNATURE" \
  -d "$BODY"
English Русский 中文 Español Deutsch Français Português 日本語