Test etme
test.ping göndermek, yerelde tünel açmak, imza mantığını gerçek istek beklemeden denemek.
1. Panelden test gönderin
Abonelik satırındaki Test gönder düğmesi endpoint'inize bir
test.ping yollar. Gerçek bir sipariş beklemeden tüm
zinciri (adres, sertifika, imza, yanıt) denemenin en hızlı yolu budur.
Sonucu Teslimat geçmişinde görürsünüz: durum kodu, yanıt süresi, hata sınıfı.
test.ping, aboneliğin dinlediği event listesinden bağımsız olarak
gönderilir — listede seçmeniz gerekmez.
2. Yerelde geliştirirken tünel açın
hikie yalnızca herkese açık HTTPS adreslerine istek atar. localhost,
127.0.0.1 ve özel ağ adresleri reddedilir. Geliştirme sırasında bir tünel
kullanın.
npx localtunnel --port 3000Çıktıdaki https://…loca.lt adresini abonelikte kullanın:
https://kirmizi-kedi-42.loca.lt/hikie/webhookTünel adresleri her yeniden başlatmada değişir. Adresi değiştirdiğinizde
abonelikteki URL'yi de güncellemeyi unutmayın, yoksa teslimatlar 404 alır ve
abonelik failing durumuna düşer.
3. Kendi imzalı isteğinizi üretin
Panele hiç gitmeden, imza doğrulama mantığınızı doğrudan test edebilirsiniz.
#!/usr/bin/env bash
set -euo pipefail
URL="${1:-http://localhost:3000/hikie/webhook}"
SECRET="${HIKIE_WEBHOOK_SECRET:?HIKIE_WEBHOOK_SECRET tanımlı değil}"
EVENT="${2:-order.paid}"
TS=$(date +%s)
WEBHOOK_ID="wh_$(openssl rand -hex 16)"
BODY=$(cat <<JSON
{"orderId":"17716204135268844HKS","status":"COMPLETED","currency":"TRY","totals":{"subtotal":"249.90","shipping":"0.00","discount":"0.00","total":"249.90"},"customerInfo":{"firstName":"Ayşe","lastName":"Yılmaz","email":"[email protected]"},"items":[{"itemId":"66b1efd21c9a4e0021f3ab77","title":"VIP Paket","type":"DIGITAL","variant":{"sku":null,"name":"30-gun"},"quantity":1,"unitPrice":"249.90","total":"249.90","isUpsell":false}],"cargo":null}
JSON
)
SIG=$(printf '%s.%s' "$TS" "$BODY" \
| openssl dgst -sha256 -hmac "$SECRET" -hex \
| sed 's/^.* //')
curl -i -X POST "$URL" \
-H "Content-Type: application/json" \
-H "Hikie-Event: $EVENT" \
-H "Hikie-Webhook-Id: $WEBHOOK_ID" \
-H "Hikie-Account-Id: 6512ab3d9f1e4c0012a7bc45" \
-H "Hikie-Timestamp: $TS" \
-H "Hikie-Occurred-At: $(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \
-H "Hikie-Api-Version: 2026-09-04" \
-H "Hikie-Signature: $SIG" \
-H "Hikie-Delivery-Attempt: 1" \
-H "User-Agent: Hikie-Webhooks/2.0" \
--data-raw "$BODY"chmod +x test-webhook.sh
HIKIE_WEBHOOK_SECRET=whsec_test123 ./test-webhook.sh--data-raw kullanın, -d değil. -d bazı durumlarda satır sonlarını
kırpar ve gövde değişince imza tutmaz.
Node.js sürümü
import crypto from 'node:crypto';
const URL_ = process.env.URL ?? 'http://localhost:3000/hikie/webhook';
const SECRET = process.env.HIKIE_WEBHOOK_SECRET;
const webhookId = `wh_${crypto.randomBytes(16).toString('hex')}`;
const timestamp = Math.floor(Date.now() / 1000);
const body = JSON.stringify({
orderId: '17716204135268844HKS',
status: 'COMPLETED',
currency: 'TRY',
totals: { subtotal: '249.90', shipping: '0.00', discount: '0.00', total: '249.90' },
customerInfo: { firstName: 'Ayşe', lastName: 'Yılmaz', email: '[email protected]' },
items: [
{
itemId: '66b1efd21c9a4e0021f3ab77',
title: 'VIP Paket',
type: 'DIGITAL',
variant: { sku: null, name: '30 gün' },
quantity: 1,
unitPrice: '249.90',
total: '249.90',
isUpsell: false,
},
],
cargo: null,
});
const signature = crypto
.createHmac('sha256', SECRET)
.update(`${timestamp}.${body}`, 'utf8')
.digest('hex');
const response = await fetch(URL_, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Hikie-Event': 'order.paid',
'Hikie-Webhook-Id': webhookId,
'Hikie-Account-Id': '6512ab3d9f1e4c0012a7bc45',
'Hikie-Timestamp': String(timestamp),
'Hikie-Occurred-At': new Date().toISOString(),
'Hikie-Api-Version': '2026-09-04',
'Hikie-Signature': signature,
'Hikie-Delivery-Attempt': '1',
},
body, // ← imzaladığımız dizenin AYNISI
});
console.log(response.status, await response.text());4. Otomatik testler
Endpoint'inizi CI'da test edin. Kontrol edilecek dört senaryo:
import crypto from 'node:crypto';
import request from 'supertest';
import { app } from '../server.js';
const SECRET = 'whsec_test123';
function sign(timestamp, body) {
return crypto.createHmac('sha256', SECRET)
.update(`${timestamp}.${body}`, 'utf8')
.digest('hex');
}
function send(overrides = {}) {
const timestamp = overrides.timestamp ?? Math.floor(Date.now() / 1000);
const body = overrides.body ?? JSON.stringify({
subscriptionId: '66b2c1a70f5e8d4319ab72c6',
message: 'Your Hikie webhook connection is working.',
dateSent: new Date().toISOString(),
});
return request(app)
.post('/hikie/webhook')
.set('Content-Type', 'application/json')
.set('Hikie-Event', 'test.ping')
.set('Hikie-Webhook-Id', overrides.webhookId ?? 'wh_test1')
.set('Hikie-Timestamp', String(timestamp))
.set('Hikie-Signature', overrides.signature ?? sign(timestamp, body))
.set('Hikie-Delivery-Attempt', '1')
.send(body);
}
test('geçerli imza kabul edilir', async () => {
const res = await send();
expect(res.status).toBe(200);
});
test('bozuk imza reddedilir', async () => {
const res = await send({ signature: 'f'.repeat(64) });
expect(res.status).toBe(400);
});
test('eski zaman damgası reddedilir', async () => {
const old = Math.floor(Date.now() / 1000) - 3600;
const res = await send({ timestamp: old });
expect(res.status).toBe(400);
});
test('aynı webhookId iki kez işlenmez', async () => {
await send({ webhookId: 'wh_dupe' });
const second = await send({ webhookId: 'wh_dupe' });
expect(second.status).toBe(200);
expect(await countProcessedJobs('wh_dupe')).toBe(1);
});Dördüncü test en önemlisi ve en çok atlanan. Tekrar koruması olmayan bir entegrasyon, ilk zaman aşımında iki kez iş yapar.