# Node.js Package

#### Supported Mobile Networks

ZenoPay supports the following mobile payment networks:

* **M-PESA**
* **TIGOPESA (MIX BY YAS)**
* **HALOPESA**
* **AIRTEL MONEY**

### Installation

### Install the package using npm or yarn:

```javascript
# Using npm
npm install zenopay

# Using yarn
yarn add zenopay
```

### Usage

#### 1. **Backend Integration**

Here’s how to integrate ZenoPay in a Node.js backend application:

```javascript
import ZenoPay from "zenopay";

const zenoPayOptions = {
    accountID: "your-account-id",
    apiKey: "your-api-key",
    secretKey: "your-secret-key",
};

const zenoPay = new ZenoPay(zenoPayOptions);

// Make a payment
async function makePayment() {
    const paymentOptions = {
        amountToCharge: 1000,
        customerName: "John Doe",
        customerEmail: "johndoe@example.com",
        customerPhoneNumber: "0701234567",
    };

    const result = await zenoPay.Pay(paymentOptions);
    console.log(result);
}

// Check payment status
async function checkPaymentStatus(orderID: string) {
    const result = await zenoPay.CheckPaymentStatus(orderID);
    console.log(result);
}
```

### API Reference

#### 1. **`Pay(paymentOptions: PaymentOptionsType): Promise<RequestResponseType>`**

Initiates a payment request.

**Parameters:**

* `paymentOptions`: An object with the following properties:
  * `amountToCharge` (number): Amount to charge (must be greater than 0).
  * `customerName` (string): Full name of the customer.
  * `customerEmail` (string): Email address of the customer.
  * `customerPhoneNumber` (string): Phone number of the customer (10 or 12 digits).

**Response:**

Returns a promise resolving to:

```javascript
{
    success: boolean,
    message: any // API response or error message
}
```

#### 2. **`CheckPaymentStatus(orderID: string): Promise<RequestResponseType>`**

Checks the status of a payment.

**Parameters:**

* `orderID` (string): Unique identifier of the order to track.

**Response:**

Returns a promise resolving to:

```javascript
{
    success: boolean,
    message: any // API response or error message
}
```

### Example Responses

#### Payment Response:

```javascript
{
{
  "success": true,
  "message": {
    "status": "success",
    "message": "Wallet payment successful",
    "order_id": "674c0d32b09dd"
  }
}
}
```

#### Payment Status Response:

```javascript
{
  "success": true,
  "message": {
    "status": "success",
    "order_id": "674c0d32b09dd",
    "message": "Order status updated",
    "payment_status": "PENDING"
  }
}
```

### Best Practices

* **Keep your keys secure**: Never expose your `apiKey` or `secretKey` in frontend applications. Use environment variables or a secure backend to manage these keys.
* **Validate Inputs**: Ensure all customer details and payment amounts are validated before initiating a payment.
* **Error Handling**: Implement proper error handling to manage failed requests or API errors.

### Support

For questions or support, contact us at <support@zenopay.net>

### License

This project is licensed under the [MIT License](https://github.com/ZenoPay/ZenoPay-Node.js-Package/blob/main/LICENSE).

\---# ZenoPay-Node.js-Package


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zenopay.gitbook.io/zenopay/basics/create-order-check-status-and-webhook/node.js-package.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
