# Print Receipt In-App Integration

## **Processing a Print Receipt Request**

To print a receipt using the **In-App Integration** method, utilize Easypay's internal `PrintImage` handler to send the base64-encoded receipt data directly within the Easypay app environment.

**Example Code:**

```javascript
// Function to print receipt using In-App Integration
async function printReceiptInApp(base64Receipt) {
    // Check if the PrintImage handler is available
    if (window.PrintImage) {
        const printRequest = {
            method: "PrintImage",
            data: base64Receipt, // Base64-encoded receipt image
        };
        
        // Convert the request to JSON
        const message = JSON.stringify(printRequest);

        try {
            // Send the print request to Easypay's PrintImage handler
            await window.PrintImage.postMessage(message);
            console.log("Print request sent (In-App):", printRequest);
        } catch (error) {
            console.error("Failed to send print request (In-App):", error);
            // Optionally, notify the user or implement fallback logic
        }
    } else {
        console.error("PrintImage handler is not available.");
        // Optionally, fallback to WebSocket Integration or notify the user
    }
}

// Example usage:
const base64Receipt = "your_base64_receipt_here"; // Replace with your base64 receipt
printReceiptInApp(base64Receipt);
```

**Explanation:**

* **Method:** `"PrintImage"`
* **Purpose:**\
  Sends the base64-encoded receipt image to Easypay's `PrintImage` handler within the Easypay app 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**

```javascript
// Function to open the cash drawer using In-App Integration
function openCashDrawerInApp() {
    // Check if the OpenDrawer handler is available
    if (window.OpenDrawer) {
        const message = JSON.stringify({ method: "OpenDrawer" });
        try {
            // Send the open drawer request to Easypay
            window.OpenDrawer.postMessage(message);
            console.log("Open drawer request sent to Easypay.");
        } catch (error) {
            console.error("Failed to send open drawer request:", error);
            // Optionally, notify the user about the failure
        }
    } else {
        console.error("OpenDrawer handler is not available.");
        // Optionally, fallback to WebSocket Integration or notify the user
    }
}

// Example usage:
openCashDrawerInApp();
```

**Explanation:**

* **Method:** `"OpenDrawer"`
* **Purpose:**\
  Sends a request within the Easypay app to open the physical cash drawer. This method is suitable for scenarios where user interaction within the app environment initiates the cash drawer opening.
* **Parameters:**
  * `method`: Specifies the action to perform, which is `"OpenDrawer"` in this case.
  * **No additional parameters** are required for this method.
