| 1 |
/* global posmodel */ |
| 2 |
import { registry } from "@web/core/registry"; |
| 3 |
import * as Utils from "@pos_self_order/../tests/tours/utils/common"; |
| 4 |
import * as ProductPage from "@pos_self_order/../tests/tours/utils/product_page_util"; |
| 5 |
import { patch } from "@web/core/utils/patch"; |
| 6 |
import { QFPay } from "@pos_qfpay/app/qfpay"; |
| 7 |
import { mockQFPayWebhook } from "@pos_qfpay/../tests/tours/utils/common"; |
| 8 |
|
| 9 |
// Patch QFPay to validate the request that would be sent to the terminal |
| 10 |
patch(QFPay.prototype, { |
| 11 |
makeQFPayRequest: async function (endpoint, payload) { |
| 12 |
if (endpoint !== "trade") { |
| 13 |
throw new Error("Only 'trade' endpoint is supported on self checkout"); |
| 14 |
} |
| 15 |
const paymentMethod = posmodel.models["pos.payment.method"].getAll()[0]; |
| 16 |
const order = posmodel.currentOrder; |
| 17 |
const sessionId = posmodel.config.current_session_id.id; |
| 18 |
const expectedPayload = { |
| 19 |
func_type: 1001, |
| 20 |
amt: order.amount_total, |
| 21 |
channel: paymentMethod.qfpay_payment_type, |
| 22 |
out_trade_no: `${order.uuid}--${sessionId}--${paymentMethod.id}`, |
| 23 |
wait_card_timeout: 30, |
| 24 |
camera_id: 1, |
| 25 |
}; |
| 26 |
if (!payload || JSON.stringify(payload) !== JSON.stringify(expectedPayload)) { |
| 27 |
throw new Error("Payload does not match expected payload"); |
| 28 |
} |
| 29 |
return true; |
| 30 |
}, |
| 31 |
}); |
| 32 |
|
| 33 |
registry.category("web_tour.tours").add("kiosk_qfpay_order", { |
| 34 |
steps: () => [ |
| 35 |
Utils.clickBtn("Order Now"), |
| 36 |
ProductPage.clickProduct("Letter Tray"), |
| 37 |
Utils.clickBtn("Checkout"), |
| 38 |
Utils.clickBtn("Pay"), |
| 39 |
Utils.checkIsNoBtn("Pay"), |
| 40 |
{ |
| 41 |
content: "Waiting for Qfpay payment to be processed", |
| 42 |
trigger: "body:not(:has(.btn:text(Retry)))", |
| 43 |
run: async function () { |
| 44 |
const amount = posmodel.currentOrder.amount_total; |
| 45 |
const paymentMethodId = posmodel.models["pos.payment.method"].getAll()[0].id; |
| 46 |
mockQFPayWebhook(posmodel.currentOrder.uuid, paymentMethodId, amount, false); |
| 47 |
}, |
| 48 |
}, |
| 49 |
Utils.clickBtn("Close"), |
| 50 |
], |
| 51 |
}); |