Print Receipt WiFi Integration

Processing a Print Receipt Request

To print a receipt using the WiFi Integration method, establish a WebSocket connection and send a PrintImage method along with the base64-encoded receipt data to Easypay's service in real-time.

Example Code:

// Function to print receipt using WebSocket Integration
function printReceiptWebSocket(socket, base64Receipt) {
    // Prepare the print request
    const printRequest = {
        method: "PrintImage",
        data: base64Receipt, // Base64-encoded receipt image
    };

    // Convert the request to JSON
    const message = JSON.stringify(printRequest);

    // Send the print request through the WebSocket
    try {
        socket.send(message);
        console.log("Print request sent:", printRequest);
    } catch (error) {
        console.error("Failed to send print request:", error);
        // Optionally, implement retry logic or notify the user
    }

}

// Example usage:
const socket = new WebSocket("wss://your-ip-address:9000");

socket.onopen = () => {
    console.log("WebSocket connection established.");
    const base64Receipt = "your_base64_receipt_here"; // Replace with your base64 receipt
    printReceiptWebSocket(socket, base64Receipt);
};

socket.onclose = () => {
    console.log("WebSocket connection closed.");
};

Explanation:

  • Method: "PrintImage"

  • Purpose: Sends the base64-encoded receipt image to Easypay for printing.

  • Parameters:

    • method: Specifies the action to perform, which is "PrintImage" in this case.

    • data: The receipt image encoded in base64 format.

Processing Open Cash Drawer Request

// Function to open the cash drawer using WebSocket Integration
function openCashDrawerWebSocket(socket) {
    // Prepare the open drawer request data
    const openDrawerRequest = {
        method: "OpenDrawer"
    };

    // Send the open drawer request through the WebSocket
    try {
        socket.send(JSON.stringify(openDrawerRequest));
        console.log("Open drawer request sent:", openDrawerRequest);
    } catch (sendError) {
        console.error("Failed to send open drawer request:", sendError);
        // Optionally, implement retry logic or notify the user
        return;
    }
}

// Example usage:
const socket = new WebSocket("wss://your-ip-address:9000");

socket.onopen = () => {
    console.log("WebSocket connection established.");
    openCashDrawerWebSocket(socket);
};

socket.onclose = () => {
    console.log("WebSocket connection closed.");
};

Explanation:

  • Method: "OpenDrawer"

  • Purpose: Sends a request to Easypay to open the physical cash drawer connected to the printer. This allows for automated control of the cash drawer without manual intervention.

  • Parameters:

    • method: Specifies the action to perform, which is "OpenDrawer" in this case.

    • No additional parameters are required for this method.

Last updated