diff --git a/index.js b/index.js index 809a09d..9733591 100644 --- a/index.js +++ b/index.js @@ -961,6 +961,38 @@ app.post("/sepverify", async (req, res) => { } }); +// all-payments/send: send one payment to Taavon (like sepverify) +app.post("/all-payments/send", async (req, res) => { + const { id } = req.body; + if (!id) { + return res.status(400).json({ error: "id is required" }); + } + try { + const coll = await getSepPayCollection(); + const doc = await coll.findOne({ _id: new ObjectId(id) }); + if (!doc) { + return res.status(404).json({ error: "Record not found" }); + } + const province = (doc.provincecode || "").toString().substring(0, 2); + const isLink = + doc.isLink === true || doc.isLink === "true" || doc.isLink === "1"; + const data = { + authority: doc.token, + refId: doc.traceNo, + cardHolderPan: doc.securePan, + }; + if (isLink) { + await taavonSendDataZarinPalLink(province, data); + } else { + await taavonSendDataZarinPal(province, data); + } + return res.json({ ok: true, message: "ارسال شد" }); + } catch (err) { + console.error("all-payments send error", err); + return res.status(500).json({ error: err.message }); + } +}); + // all-payments: list of saved SEP pay requests (from MongoDB) app.get("/all-payments", async (req, res) => { let list = []; @@ -1001,6 +1033,12 @@ app.get("/all-payments", async (req, res) => { th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid #eee; } th { background: #fafafa; font-weight: bold; color: #555; } tr:hover { background: #f9f9f9; } + .btn-send { background: #1976d2; color: #fff; border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; } + .btn-send:hover { background: #1565c0; } + .btn-send:disabled { background: #9e9e9e; cursor: not-allowed; } + .cell-msg { font-size: 12px; padding: 4px 0; } + .cell-msg.ok { color: #2e7d32; } + .cell-msg.err { color: #c62828; } @@ -1016,9 +1054,28 @@ app.get("/all-payments", async (req, res) => { } var rows = list.map(function(item) { var createdAt = item.createdAt ? new Date(item.createdAt).toLocaleString('fa-IR') : '-'; - return '' + (item.amountRaw || item.amount) + '' + (item.provincecode || '-') + '' + (item.isLink ? 'بله' : 'خیر') + '' + (item.phone || '-') + '' + createdAt + ''; + var id = item._id; + return '' + (item.amountRaw || item.amount) + '' + (item.provincecode || '-') + '' + (item.isLink ? 'بله' : 'خیر') + '' + (item.phone || '-') + '' + createdAt + '
'; }).join(''); - listEl.innerHTML = '' + rows + '
مبلغاستانلینکموبایلتاریخ
'; + listEl.innerHTML = '' + rows + '
مبلغاستانلینکموبایلتاریخارسال به سرور
'; + listEl.querySelectorAll('.btn-send').forEach(function(btn) { + btn.addEventListener('click', function() { + if (!confirm('آیا مطمئن هستید؟')) return; + var id = btn.getAttribute('data-id'); + var msgEl = document.getElementById('msg-' + id); + if (msgEl) { msgEl.textContent = ''; msgEl.className = 'cell-msg'; } + btn.disabled = true; + fetch('/all-payments/send', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: id }) }) + .then(function(r) { return r.json(); }) + .then(function(j) { + if (msgEl) { msgEl.textContent = j.error || j.message || 'ارسال شد'; msgEl.className = 'cell-msg ' + (j.error ? 'err' : 'ok'); } + }) + .catch(function(e) { + if (msgEl) { msgEl.textContent = e.message; msgEl.className = 'cell-msg err'; } + }) + .finally(function() { btn.disabled = false; }); + }); + }); })();