اللمة
دخول

دليل ربط نظام الكاشير

اللمة هي المحفظة المشتركة المعتمدة الوحيدة. ترسل أنظمة التجار المشتريات وتصرف المكافآت عبر اللمة؛ ولا يحتفظ أي شريك بنسخة مستقلة قابلة للصرف من نفس الرصيد.

  1. أنشئ مفتاح توقيع من بوابة التاجر ← الربط. استخدم عنوان تاجرك الخاص؛ لا يشترط مزود معين.
  2. احفظ LAMMA_SECRET وLAMMA_API_URL وLAMMA_MERCHANT_SLUG في أسرار خادم النظام الخارجي فقط.
  3. اختر حدث كسب واحداً: order.paid أو loyalty.earned. يسجل الآخر للتدقيق فقط. المبالغ قروش صحيحة وليست جنيهات.
  4. كل طلب موقع بوقت لا يتجاوز خمس دقائق. أعد استخدام event_id أو idempotency_key عند إعادة نفس المعاملة.

التوقيع

// Server-side only. LAMMA_SECRET comes from Al Lamma → Merchant portal → Integration.
async function lamma(path, payload) {
  const body = JSON.stringify(payload);
  const ts = Math.floor(Date.now() / 1000).toString();
  const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(process.env["LAMMA_SECRET"]),
    { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
  const mac = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(ts + "." + body));
  const sig = [...new Uint8Array(mac)].map((b) => b.toString(16).padStart(2, "0")).join("");
  const res = await fetch(process.env["LAMMA_API_URL"] + "/" + path, {
    method: "POST",
    headers: { "content-type": "application/json", "x-lamma-merchant": process.env["LAMMA_MERCHANT_SLUG"],
               "x-lamma-timestamp": ts, "x-lamma-signature": sig },
    body,
  });
  return res.json();
}

نقاط الربط (POST)

/api/public/v1/events — order.paid

{ "event_id": "restaurant-a-ord-1042-paid", "event_type": "order.paid",
  "data": { "order_id": "1042", "customer_external_id": "<external customer id>",
            "total_minor": 100000, "currency": "EGP" } }

/api/public/v1/events — order.refunded / order.voided

{ "event_id": "restaurant-a-ord-1042-refund", "event_type": "order.refunded",
  "data": { "order_id": "1042" } }

/api/public/v1/events — menu.item.upserted

{ "event_id": "menu-77-v5", "event_type": "menu.item.upserted",
  "data": { "external_id": "77", "name_en": "Mixed grill", "name_ar": "مشويات مشكلة",
            "price_minor": 32000, "available": true, "category_external_id": "grills",
            "category_name_en": "Grills", "category_name_ar": "مشويات" } }

/api/public/v1/customers/link — link a merchant customer

{ "link_code": "482913", "customer_external_id": "<external customer id>" }

/api/public/v1/wallet/summary — show balance at POS

{ "customer_external_id": "<external customer id>" }

/api/public/v1/redemptions/quote — max usable on a bill

{ "customer_token": "ABCD2345", "bill_minor": 30000 }

/api/public/v1/redemptions/reserve — hold for 5 minutes

{ "customer_token": "ABCD2345", "bill_minor": 30000, "amount_minor": 6000,
  "idempotency_key": "restaurant-a-pos3-ord-1043", "checkout_ref": "1043" }

/api/public/v1/redemptions/commit — after the sale closes

{ "reservation_id": "<from reserve>" }

/api/public/v1/redemptions/cancel — sale abandoned

{ "reservation_id": "<from reserve>" }

/api/public/v1/redemptions/status — after a timeout

{ "idempotency_key": "restaurant-a-pos3-ord-1043" }