APIスコープ

開発者APIリファレンス

ステーブルコインチェックアウト、注文作成、配達追跡のための生産重視のcURLおよびNodeの例。

このガイドでカバーされている内容

  • ギフトカード
  • モバイルチャージ
  • eSIM購入

ここではカバーされていません

  • フライト
  • 宿泊

エンドポイントに飛び込む前に、より広い統合の文脈が必要ですか?

統合の概要を開く
1

認証

すべてのAPIリクエストにはこれらのヘッダーが必要です。Cryptorefillsアカウントを作成した後、アカウント情報ページでパートナーIDを見つけることができます。
bash
# Required headers for every API request
-H 'X-Cr-Application: YOUR_PARTNER_ID'
-H 'X-Cr-Version: YOUR_APP_VERSION'
-H 'X-Country-ISO-Code: US'
-H 'Content-Type: application/json'
2

支払い方法

GET/v3/payment_vias
すべてのサポートされているコインとブロックチェーンネットワークを取得します。Solana、Ethereum、Base、Arbitrum、PolygonなどでUSDC、USDTを返します。
bash
curl -X GET 'https://api.cryptorefills.com/v3/payment_vias' \
  -H 'Content-Type: application/json' \
  -H 'X-Cr-Application: YOUR_PARTNER_ID' \
  -H 'X-Cr-Version: YOUR_APP_VERSION'

推奨: SolanaのUSDCは、最も低い手数料と最速の決済を提供します。

3

ブランドカタログ

GET/v2/brands?country_code={countryCode}
(オプション) 国のすべての利用可能なブランドをリストします。ブランドディレクトリや検索機能を構築するのに最適です。
bash
curl -X GET 'https://api.cryptorefills.com/v2/brands?country_code=US' \
  -H 'Content-Type: application/json' \
  -H 'X-Cr-Application: YOUR_PARTNER_ID' \
  -H 'X-Cr-Version: YOUR_APP_VERSION'
4

ホームページフィード

GET/v2/homepage?country_code={countryCode}
(オプション) 国のためのキュレーションされたホームページフィードを取得します。トレンドや特集のギフトカードを表示するのに便利です。
bash
curl -X GET 'https://api.cryptorefills.com/v2/homepage?country_code=US' \
  -H 'Content-Type: application/json' \
  -H 'X-Cr-Application: YOUR_PARTNER_ID' \
  -H 'X-Cr-Version: YOUR_APP_VERSION'
5

商品をブラウズ

GET/v5/products/country/{countryCode}
ブランドと国のためのすべての利用可能なギフトカードをリストします。固定額面とカスタム金額(範囲)をサポートします。
bash
curl -X GET 'https://api.cryptorefills.com/v5/products/country/US?family_name=airbnb&coin=USDC&lang=en' \
  -H 'Content-Type: application/json' \
  -H 'X-Cr-Application: YOUR_PARTNER_ID' \
  -H 'X-Cr-Version: YOUR_APP_VERSION'
6

暗号価格を取得

GET/v4/products/price
任意のギフトカードの価値をステーブルコインの金額に変換します。購入を確認する前にユーザーに正確な暗号の金額を示すために使用します。
bash
curl -X GET 'https://api.cryptorefills.com/v4/products/price?brand_name=Airbnb&country_code=US&face_value=100&coin=USDC' \
  -H 'Content-Type: application/json' \
  -H 'X-Cr-Application: YOUR_PARTNER_ID' \
  -H 'X-Cr-Version: YOUR_APP_VERSION'
7

注文を検証

POST/v5/orders/validations
(推奨) 注文を作成する前に問題をチェックします。Cryptorefillsはその受取人に配信するため、email/beneficiary_accountには実際のエンドユーザーのメールを使用してください。
bash
curl -X POST 'https://api.cryptorefills.com/v5/orders/validations' \
  -H 'Content-Type: application/json' \
  -H 'X-Cr-Application: YOUR_PARTNER_ID' \
  -H 'X-Cr-Version: YOUR_APP_VERSION' \
  -d '{
    "email": "END_USER_EMAIL",
    "payment": {
      "type": "via",
      "payment_via": "USER_WALLET",
      "coin": "USDC"
    },
    "deliveries": [
      {
        "beneficiary_account": "END_USER_EMAIL",
        "brand_name": "Airbnb",
        "country_code": "US",
        "denomination": "100 USD",
        "localized_denomination": "$100"
      }
    ],
    "lang": "en"
  }'
8

注文を作成

POST/v5/orders
注文を作成し、支払いのためのウォレットアドレスを受け取ります。Cryptorefillsはその受取人に製品を配信する必要があるため、実際のエンドユーザーのメールを使用してください。支払いウィンドウは30分です。
bash
curl -X POST 'https://api.cryptorefills.com/v5/orders' \
  -H 'Content-Type: application/json' \
  -H 'X-Cr-Application: YOUR_PARTNER_ID' \
  -H 'X-Cr-Version: YOUR_APP_VERSION' \
  -d '{
    "deliveries": [
      {
        "kind": "giftcard",
        "quantity": 1,
        "deliverable": {
          "brand_name": "Airbnb",
          "country_code": "US",
          "denomination": "100"
        }
      }
    ],
    "payment": {
      "type": "via",
      "coin": "USDC",
      "network": "Solana",
      "payment_via": "USER_WALLET"
    },
    "user": {
      "email": "END_USER_EMAIL",
      "has_accepted_newsletter": true
    },
    "lang": "en",
    "acquisition": {
      "utm_source": "your_platform"
    }
  }'

レスポンスには以下が含まれます wallet_address and coin_amount. これをユーザーと共有してください。

9a

注文を追跡 (ストリームAPI)

GET/api/orders/{orderId}/subscribe
これを2つの必須部分で実装します: サーバー側のSSEプロキシルートとクライアント側のストリームフック。
  • APIルートが受信します/api/orders/{orderId}/subscribe そして上流に転送します/v5/orders/{orderId}/subscribe.
  • クライアントフックが開きますEventSource ローカルAPIルートに、ペイロードを検証し、必要に応じてバックオフで再接続します。

サーバーサイドの必須コード

javascript
// app/api/orders/[orderId]/subscribe/route.ts
let upstream: Response;

try {
  upstream = await fetch(
    `https://api.cryptorefills.com/v5/orders/${params?.orderId}/subscribe`,
    {
      method: 'GET',
      headers: {
        ...(await genHeader.server(session)),
        'User-Agent': user_agent,
        Accept: 'text/event-stream',
        Connection: 'keep-alive',
      },
    },
  );
} catch (err) {
  return NextResponse.json(
    { error: 'Failed to connect to upstream stream' },
    { status: 502 },
  );
}

if (!upstream.ok || !upstream.body) {
  return NextResponse.json(
    { error: 'Upstream returned an error' },
    { status: upstream.status || 502 },
  );
}

// stream = ReadableStream that proxies upstream SSE events
return new Response(stream, {
  status: 200,
  headers: {
    'Content-Type': 'text/event-stream',
    'Cache-Control': 'no-cache, no-transform',
    Connection: 'keep-alive',
    'X-Accel-Buffering': 'no',
  },
});

クライアントサイドの必須コード

javascript

const { data: lastEvent, error } = useSWRSubscription<TOrderSchema>(
  referenceOrderId ? `orders-info-stream-${referenceOrderId}` : null,
  ((key, { next }) => {
    let es: EventSource | null = null;
    let stopped = false;
    let shouldReconnect = true;
    let retryTimeout: number | null = null;
    let retryDelay = 1000;

    const cleanup = () => {
      if (es) {
        es.close();
        es = null;
      }
      if (retryTimeout !== null) {
        window.clearTimeout(retryTimeout);
        retryTimeout = null;
      }
    };

    const stopForever = () => {
      shouldReconnect = false;
      stopped = true;
      cleanup();
    };

    const connect = () => {
      if (stopped) return;
      cleanup();
      es = new EventSource(`/api/orders/${referenceOrderId}/subscribe`);

      es.addEventListener('message', (ev) => {
        try {
          const raw = JSON.parse(ev.data);
          const parsed = orderSchema.safeParse(raw);
          if (!parsed.success) return;
          retryDelay = 1000;
          next(null, parsed.data as TOrderSchema);
        } catch (err) {
          next(err as Error);
        }
      });

      es.addEventListener('stop', () => {
        stopForever();
      });

      es.onerror = () => {
        if (stopped || !shouldReconnect) return;
        cleanup();
        retryTimeout = window.setTimeout(() => {
          retryDelay = Math.min(retryDelay * 2, 30000);
          connect();
        }, retryDelay);
      };
    };

    connect();

    return () => {
      stopped = true;
      cleanup();
    };
  }) as SubscriptionCallback<TOrderSchema>,
);

このリポジトリのルート

app/api/orders/[orderId]/subscribe/route.ts

サーバーサイド (APIルート)

セッションベースのサーバーヘッダーを使用しますgenHeader.server(session)、その後上流を呼び出します${process.env.API_URL}/v5/orders/${params?.orderId}/subscribe. 接続失敗時には返します502.

クライアントサイド (フック)

開きますEventSource /api/orders/${referenceOrderId}/subscribe, 各ペイロードを検証しますorderSchema.safeParse, 処理しますstop イベントを、そして指数バックオフで再接続します。

9b

注文を追跡 (ポーリング)

GET/v5/orders/{orderId}
フォールバックアプローチ: 支払いが受信されるまで5-10秒ごとにポーリングします。ステータスが「完了」のときにギフトカードコードが表示されます。
bash
curl -X GET 'https://api.cryptorefills.com/v5/orders/ord_abc123xyz' \
  -H 'Content-Type: application/json' \
  -H 'X-Cr-Application: YOUR_PARTNER_ID' \
  -H 'X-Cr-Version: YOUR_APP_VERSION'

ポーリングを使用するのは

SSE接続を開いたままにできない場合、またはクライアント環境がEventSourceを信頼できるようにサポートしていない場合です。

典型的な注文状態

WaitingForPayment -> WaitingForDelivery -> Done