add: gui sep requests
This commit is contained in:
61
index.js
61
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)
|
// all-payments: list of saved SEP pay requests (from MongoDB)
|
||||||
app.get("/all-payments", async (req, res) => {
|
app.get("/all-payments", async (req, res) => {
|
||||||
let list = [];
|
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, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid #eee; }
|
||||||
th { background: #fafafa; font-weight: bold; color: #555; }
|
th { background: #fafafa; font-weight: bold; color: #555; }
|
||||||
tr:hover { background: #f9f9f9; }
|
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; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -1016,9 +1054,28 @@ app.get("/all-payments", async (req, res) => {
|
|||||||
}
|
}
|
||||||
var rows = list.map(function(item) {
|
var rows = list.map(function(item) {
|
||||||
var createdAt = item.createdAt ? new Date(item.createdAt).toLocaleString('fa-IR') : '-';
|
var createdAt = item.createdAt ? new Date(item.createdAt).toLocaleString('fa-IR') : '-';
|
||||||
return '<tr><td>' + (item.amountRaw || item.amount) + '</td><td>' + (item.provincecode || '-') + '</td><td>' + (item.isLink ? 'بله' : 'خیر') + '</td><td>' + (item.phone || '-') + '</td><td>' + createdAt + '</td></tr>';
|
var id = item._id;
|
||||||
|
return '<tr><td>' + (item.amountRaw || item.amount) + '</td><td>' + (item.provincecode || '-') + '</td><td>' + (item.isLink ? 'بله' : 'خیر') + '</td><td>' + (item.phone || '-') + '</td><td>' + createdAt + '</td><td><button type="button" class="btn-send" data-id="' + id + '">ارسال به سرور</button><div class="cell-msg" id="msg-' + id + '"></div></td></tr>';
|
||||||
}).join('');
|
}).join('');
|
||||||
listEl.innerHTML = '<table><thead><tr><th>مبلغ</th><th>استان</th><th>لینک</th><th>موبایل</th><th>تاریخ</th></tr></thead><tbody>' + rows + '</tbody></table>';
|
listEl.innerHTML = '<table><thead><tr><th>مبلغ</th><th>استان</th><th>لینک</th><th>موبایل</th><th>تاریخ</th><th>ارسال به سرور</th></tr></thead><tbody>' + rows + '</tbody></table>';
|
||||||
|
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; });
|
||||||
|
});
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user