TESTNET ONLY · No real funds are used. Do not send mainnet BTC.

Merchant API

All API calls use Authorization: Bearer YOUR_MERCHANT_API_KEY. Amounts are never trusted from a browser; create invoices from your server.

POST /api/v1/invoices

curl -X POST https://btcmerchant.duckdns.org/api/v1/invoices \
 -H "Authorization: Bearer $GATEWAY_KEY" \
 -H "Content-Type: application/json" \
 -H "Idempotency-Key: order-1001" \
 -d '{"amount":"0.0005","currency":"BTC","orderId":"1001","buyerEmail":"buyer@example.com","redirectUrl":"https://example.com/thanks","metadata":{"item":"eBook"}}'

GET /api/v1/invoices/{id}

curl -H "Authorization: Bearer $GATEWAY_KEY" https://btcmerchant.duckdns.org/api/v1/invoices/INVOICE_ID

POST cancel

curl -X POST -H "Authorization: Bearer $GATEWAY_KEY" https://btcmerchant.duckdns.org/api/v1/invoices/INVOICE_ID/cancel

Node

const r = await fetch('https://btcmerchant.duckdns.org/api/v1/invoices', {method:'POST',headers:{'Authorization':'Bearer '+process.env.GATEWAY_KEY,'Content-Type':'application/json','Idempotency-Key':'1001'},body:JSON.stringify({amount:'0.0005',currency:'BTC',orderId:'1001'})});
const inv = await r.json(); console.log(inv.checkoutUrl);

PHP

$ch=curl_init('https://btcmerchant.duckdns.org/api/v1/invoices');
curl_setopt_array($ch,[CURLOPT_POST=>true,CURLOPT_HTTPHEADER=>['Authorization: Bearer '.getenv('GATEWAY_KEY'),'Content-Type: application/json'],CURLOPT_POSTFIELDS=>json_encode(['amount'=>'0.0005','currency'=>'BTC','orderId'=>'1001']),CURLOPT_RETURNTRANSFER=>true]);
$inv=json_decode(curl_exec($ch),true); header('Location: '.$inv['checkoutUrl']);

Python

import requests, os
r=requests.post('https://btcmerchant.duckdns.org/api/v1/invoices',headers={'Authorization':'Bearer '+os.environ['GATEWAY_KEY']},json={'amount':'0.0005','currency':'BTC','orderId':'1001'})
print(r.json()['checkoutUrl'])

Webhook verification

const sig=req.headers['x-gateway-signature'];
const ts=req.headers['x-gateway-timestamp'];
const expected='sha256='+crypto.createHmac('sha256',process.env.WEBHOOK_SECRET).update(ts+'.'+raw).digest('hex');
if(!crypto.timingSafeEqual(Buffer.from(sig),Buffer.from(expected))) return res.status(401).send('bad signature');

HMAC-SHA256 is computed over timestamp + "." + rawBody. Events: invoice.processing, invoice.settled, invoice.expired, invoice.invalid.