Debian Codegraph @

addons/pos_qfpay/static/tests/tours/utils/common.js

raw
1 /* global posmodel */
2
3 const response_from_qfpay_on_pos_payment_webhook = (uuid, sessionID, paymentMethodId, amount) => ({
4 cash_fee_type: "",
5 exchange_rate: "",
6 cancel: "0",
7 pay_type: "802808",
8 txdtm: "2025-08-26 17:50:34",
9 out_trade_no: `${uuid}--${sessionID}--${paymentMethodId}`,
10 syssn: "20250826155400087645770447",
11 status: "1",
12 sysdtm: "2025-08-26 17:50:36",
13 paydtm: "2025-08-26 17:50:37",
14 goods_name: "",
15 txcurrcd: "HKD",
16 mchid: "8Bx9aHgNmaQJ",
17 customer_source: "HK",
18 cash_fee: "0",
19 chnlsn2: "",
20 cardcd: "",
21 txamt: `${amount}`,
22 outcardnm: "",
23 respcd: "0000",
24 goods_info: "",
25 notify_type: "payment",
26 chnlsn: "2025085675626675",
27 });
28
29 const response_from_qfpay_on_pos_refund_webhook = (uuid, sessionID, paymentMethodId, amount) => ({
30 status: "1",
31 sysdtm: "2025-08-26 17:51:34",
32 txcurrcd: "HKD",
33 orig_out_trade_no: `${uuid}--${sessionID}--${paymentMethodId}`,
34 mchid: "8Bx9jdHgmaQJ",
35 txdtm: "2025-08-26 17:51:34",
36 txamt: `${amount}`,
37 orig_syssn: "20250826155400087645770447",
38 out_trade_no: "2cccf6c02d4835bdb79d7c96beb95cbf",
39 syssn: "20250821155400847635342115",
40 respcd: "0000",
41 notify_type: "refund",
42 });
43
44 // Once request for payment/refund has been sent to the qfpay terminal
45 // we wait to receive the notification from qfpay on the webhook
46 // The simplest way to mock this notification is to send it ourselves.
47 export async function mockQFPayWebhook(uuid, paymentMethodId, amount, isRefund = false) {
48 const sessionId = posmodel.config.current_session_id.id;
49 const resp = await fetch("/qfpay/notify", {
50 method: "POST",
51 headers: {
52 "Content-Type": "application/json",
53 },
54 body: JSON.stringify(
55 isRefund
56 ? response_from_qfpay_on_pos_refund_webhook(
57 uuid,
58 sessionId,
59 paymentMethodId,
60 Math.trunc(amount * 100)
61 )
62 : response_from_qfpay_on_pos_payment_webhook(
63 uuid,
64 sessionId,
65 paymentMethodId,
66 Math.trunc(amount * 100)
67 )
68 ),
69 });
70 if (!resp.ok) {
71 throw new Error("Failed to notify Qfpay webhook");
72 }
73 }