// 문서

개발자 문서

몇 분 만에 NextCryptoPay를 연동하세요. 일반적인 연동의 형태는 다음과 같습니다.

AI 에이전트로 개발 중이신가요?

Claude Code, Codex, Cursor 등 AI 에이전트로 프로젝트를 개발 중이라면 docs-agent.md를 다운로드해 에이전트에게 전달하세요. NextCryptoPay를 자동으로 연동하는 데 필요한 모든 것이 담겨 있습니다.

docs-agent.md 다운로드

1. API 키 생성

대시보드 → API 키에서 키를 생성하세요. 시크릿은 서버에 보관하고, 브라우저에는 절대 두지 마세요.

2. 인보이스 생성

금액, 통화 및 체인을 인보이스 엔드포인트로 POST한 다음, 반환된 체크아웃 URL로 고객을 리디렉션하세요.

3. 웹훅 수신

인보이스가 결제, 확인 중 또는 만료되면 서명된 웹훅을 보냅니다. 웹훅 시크릿으로 서명을 검증하세요.

인증

모든 요청은 Authorization 헤더에 시크릿 키를 넣어 인증하세요. 대시보드 → API 키에서 상점별로 키를 생성하세요(전체 키는 한 번만 표시됩니다).

인보이스 생성

주문 금액, 체인 및 자산을 전송하세요. payAddress와 호스팅 checkoutUrl을 반환받으면 — 고객을 그곳으로 리디렉션하세요.

요청

curl -X POST https://nextcryptopay.com/api/v1/invoices \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "orderId": "ORDER-1001",
    "amount": 99.50,
    "currency": "USD",
    "chain": "tron",
    "asset": "USDT",
    "webhookUrl": "https://yourstore.com/webhooks/cryptopay"
  }'

응답

{
  "id": "inv_abc123",
  "orderId": "ORDER-1001",
  "payAddress": "TJ9xH4n2k8sQw7Lm3vR5pZ1aB6cD8eF2g",
  "cryptoAmount": "99.50",
  "asset": "USDT",
  "chain": "tron",
  "status": "PENDING",
  "expiresAt": "2026-06-17T10:00:00.000Z",
  "checkoutUrl": "https://nextcryptopay.com/pay/inv_abc123"
}

결제 상태 추적

인보이스를 폴링하거나 Server-Sent Events로 실시간 업데이트를 구독하세요. 상태: PENDING → CONFIRMING → PAID (또는 EXPIRED / PARTIALLY_PAID).

# Poll the invoice
curl https://nextcryptopay.com/api/v1/invoices/inv_abc123

# Or subscribe to live updates (Server-Sent Events)
GET https://nextcryptopay.com/api/v1/invoices/inv_abc123/stream

웹훅 검증

상태가 변경될 때마다 서명된 이벤트를 귀하의 웹훅 URL로 POST합니다. 신뢰하기 전에 x-cryptopay-signature 헤더(상점의 웹훅 시크릿을 사용한 원본 본문의 HMAC-SHA256)를 검증하세요. 5초 이내에 2xx를 반환하세요 — 그렇지 않으면 백오프로 재시도합니다.

import crypto from "node:crypto";

app.post("/webhooks/cryptopay", (req, res) => {
  const signature = req.headers["x-cryptopay-signature"];
  const timestamp = req.headers["x-cryptopay-timestamp"];

  // Reject stale deliveries (replay protection): within 5 minutes
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) {
    return res.status(401).end();
  }

  // Signature is HMAC of "timestamp.rawBody"
  const expected = crypto
    .createHmac("sha256", process.env.CRYPTOPAY_WEBHOOK_SECRET)
    .update(timestamp + "." + req.rawBody) // raw JSON body
    .digest("hex");

  if (
    signature.length !== expected.length ||
    !crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))
  ) {
    return res.status(401).end();
  }

  // Dedupe by delivery id (same event may be retried)
  const deliveryId = req.headers["x-cryptopay-delivery"];
  if (alreadyProcessed(deliveryId)) return res.status(200).end();

  const { event, invoice } = req.body;
  if (event === "invoice.paid") fulfillOrder(invoice.orderId);

  res.status(200).end(); // reply 2xx within 15s, else we retry (6 attempts, backoff)
});

지원 체인

Tron(USDT/USDC · TRC20), Ethereum(USDT/USDC · ERC20), BSC(USDT · BEP20), Bitcoin(BTC). 수수료는 성공한 결제당 0.1%이며, 선불 USDT 잔액에서 차감됩니다(또는 플랜 할당량으로 충당).