API Kapsamı

Geliştirici API referansı

Stablecoin ödemesi, sipariş oluşturma ve teslimat takibi için üretim odaklı cURL ve Node örnekleri.

Bu kılavuzda kapsananlar

  • Hediye kartları
  • Mobil yüklemeler
  • eSIM satın alımları

Burada kapsanmayanlar

  • Uçuşlar
  • Konaklamalar

Uç noktalarına dalmadan önce daha geniş entegrasyon bağlamına mı ihtiyacınız var?

Entegrasyon genel görünümünü aç
1

Kimlik doğrulama

Her API isteği bu başlıkları gerektirir. Cryptorefills hesabı oluşturduktan sonra, Ortak ID'nizi hesap bilgileri sayfanızda bulabilirsiniz.
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

Ödeme yöntemleri

GET/v3/payment_vias
Tüm desteklenen coinleri ve blockchain ağlarını alın. Solana, Ethereum, Base, Arbitrum, Polygon ve daha fazlasında USDC, USDT döner.
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'

Tavsiye edilen: Solana'daki USDC, en düşük ücretleri ve en hızlı yerleşimi sunar.

3

Marka kataloğu

GET/v2/brands?country_code={countryCode}
(Opsiyonel) Bir ülke için mevcut tüm markaları listeleyin. Marka dizini veya arama özellikleri oluşturmak için harika.
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

Ana sayfa akışı

GET/v2/homepage?country_code={countryCode}
(Opsiyonel) Bir ülke için küratörlü bir ana sayfa akışı alın. Trend olan veya öne çıkan hediye kartlarını görüntülemek için kullanışlı.
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

Ürünleri gözden geçirin

GET/v5/products/country/{countryCode}
Bir marka ve ülke için mevcut tüm hediye kartlarını listeleyin. Sabit tutarları ve özel miktarları (aralıkları) destekler.
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

Kripto fiyatını al

GET/v4/products/price
Herhangi bir hediye kartı değerini stabilcoin miktarına dönüştürün. Kullanıcılara satın alma onaylamadan önce tam kripto miktarını göstermek için bunu kullanın.
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

Siparişi doğrula

POST/v5/orders/validations
(Tavsiye edilir) Siparişi oluşturmadan önce sorunları kontrol edin. Gerçek son kullanıcı e-posta adresini email/beneficiary_account içinde kullanın, çünkü Cryptorefills bu alıcıya teslimat yapar.
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

Sipariş oluştur

POST/v5/orders
Bir sipariş oluşturun ve ödeme için bir cüzdan adresi alın. Gerçek son kullanıcı e-posta adresini kullanın çünkü Cryptorefills ürünü bu alıcıya teslim etmelidir. Ödeme penceresi 30 dakikadır.
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"
    }
  }'

Yanıt içerir wallet_address and coin_amount. Bunları kullanıcılarınızla paylaşın.

9a

Siparişi takip et (stream API)

GET/api/orders/{orderId}/subscribe
Bunu iki gerekli parçaya uygulayın: bir sunucu tarafı SSE proxy rotası ve bir istemci tarafı akış kancası.
  • API rotası alır/api/orders/{orderId}/subscribe ve yukarıya iletir/v5/orders/{orderId}/subscribe.
  • İstemci kancası açarEventSource yerel API rotasına, yükleri doğrular ve gerektiğinde geri bağlantı yapar.

Sunucu Tarafı Temel Kod

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',
  },
});

İstemci Tarafı Temel Kod

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>,
);

Bu repodaki rota

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

Sunucu tarafı (API rotası)

Oturum tabanlı sunucu başlıklarını kullanırgenHeader.server(session), ardından yukarıya çağrılar yapar${process.env.API_URL}/v5/orders/${params?.orderId}/subscribe. Bağlantı hatası durumunda döner502.

İstemci tarafı (kanca)

AçarEventSource şu adrese/api/orders/${referenceOrderId}/subscribe, her yükü doğrularorderSchema.safeParse, işlemleri yönetirstop olayları ve üstel geri bağlantı yapar.

9b

Siparişi takip et (polling)

GET/v5/orders/{orderId}
Yedek yaklaşım: Ödeme alınana kadar her 5-10 saniyede bir sorgulayın. Hediye kartı kodu 'Tamamlandı' durumunda görünür.
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'

Sorgulamayı kullanın

Bir SSE bağlantısını açık tutamıyorsanız veya istemci ortamınız EventSource'u güvenilir bir şekilde desteklemiyorsa.

Tipik sipariş durumları

ÖdemeBekliyor -> TeslimatBekliyor -> Tamamlandı