Debian Codegraph @

addons/pos_qfpay/static/tests/tours/qfpay_tour.js

raw
1 /* global posmodel */
2 import * as Chrome from "@point_of_sale/../tests/pos/tours/utils/chrome_util";
3 import * as ReceiptScreen from "@point_of_sale/../tests/pos/tours/utils/receipt_screen_util";
4 import * as PaymentScreen from "@point_of_sale/../tests/pos/tours/utils/payment_screen_util";
5 import * as ProductScreen from "@point_of_sale/../tests/pos/tours/utils/product_screen_util";
6 import * as TicketScreen from "@point_of_sale/../tests/pos/tours/utils/ticket_screen_util";
7 import * as Dialog from "@point_of_sale/../tests/generic_helpers/dialog_util";
8 import { patch } from "@web/core/utils/patch";
9 import { registry } from "@web/core/registry";
10 import { QFPay } from "@pos_qfpay/app/qfpay";
11 import { mockQFPayWebhook } from "@pos_qfpay/../tests/tours/utils/common";
12
13 const { DateTime } = luxon;
14
15 // Patch QFPay to validate the request that would be sent to the terminal
16 patch(QFPay.prototype, {
17 makeQFPayRequest: async function (endpoint, payload) {
18 const paymentLine = posmodel.getPendingPaymentLine("qfpay");
19 const paymentMethod = paymentLine.payment_method_id;
20 let expectedPayload;
21 if (endpoint === "trade") {
22 const uuid = paymentLine.uuid;
23 const sessionId = posmodel.config.current_session_id.id;
24 expectedPayload = {
25 func_type: 1001,
26 amt: paymentLine.amount,
27 channel: paymentMethod.qfpay_payment_type,
28 out_trade_no: `${uuid}--${sessionId}--${paymentMethod.id}`,
29 };
30 } else if (endpoint === "cancel") {
31 const originalPayment = paymentLine.pos_order_id.refunded_order_id.payment_ids.find(
32 (l) => l.payment_method_id.id === paymentMethod.id
33 );
34 expectedPayload = {
35 func_type: 1002,
36 orderId: originalPayment.transaction_id,
37 refund_amount: (-paymentLine.amount).toFixed(2),
38 };
39 }
40 if (!payload || JSON.stringify(payload) !== JSON.stringify(expectedPayload)) {
41 throw new Error("Payload does not match expected payload");
42 }
43 return true;
44 },
45 });
46
47 // Store uuid of payment between order and refund
48 let paymentUuid = "";
49
50 registry.category("web_tour.tours").add("qfpay_order_and_refund", {
51 steps: () =>
52 [
53 // Refund have to be made on the same day before 23:00 HKT.
54 Chrome.freezeDateTime(
55 DateTime.now().setZone("Asia/Hong_Kong").set({ hour: 12 }).toMillis()
56 ),
57 Chrome.startPoS(),
58 Dialog.confirm("Open Register"),
59
60 // ORDER
61 ProductScreen.addOrderline("Desk Pad"),
62 ProductScreen.clickPayButton(),
63 PaymentScreen.clickPaymentMethod("Qfpay"),
64 {
65 content: "Waiting for Qfpay payment to be processed",
66 trigger: ".electronic_status:contains('Waiting for card')",
67 run: async function () {
68 const paymentLine = posmodel.getPendingPaymentLine("qfpay");
69 paymentUuid = paymentLine.uuid;
70 const paymentMethodId = paymentLine.payment_method_id.id;
71 mockQFPayWebhook(paymentUuid, paymentMethodId, paymentLine.amount, false);
72 },
73 },
74 ReceiptScreen.isShown(),
75
76 // REFUND
77 Chrome.clickOrders(),
78 TicketScreen.selectFilter("Active"),
79 TicketScreen.selectFilter("Paid"),
80 TicketScreen.selectOrder("0001"),
81 TicketScreen.confirmRefund(),
82 PaymentScreen.clickPaymentMethod("Qfpay"),
83 PaymentScreen.clickRefundButton(),
84 {
85 content: "Waiting for Qfpay refund to be processed",
86 trigger: ".electronic_status:contains('Refund in process')",
87 run: async function () {
88 const paymentLine = posmodel.getPendingPaymentLine("qfpay");
89 const paymentMethodId = paymentLine.payment_method_id.id;
90 mockQFPayWebhook(paymentUuid, paymentMethodId, paymentLine.amount, true);
91 },
92 },
93 ReceiptScreen.isShown(),
94
95 Chrome.endTour(),
96 ].flat(),
97 });