# Node.js Express PhonePe Payment Gateway Integration

Welcome to the **Node.js Express PhonePe Payment Gateway Integration Package** 🚀

---

## **PhonePe For Business Registration**

For official business registration, click:  
🔗 [Registration here](https://business.phonepe.com/register?referral-code=RF2502100937302404539487)


## **UAT Testing Credentials**

`MERCHANT_ID` = "PGTESTSBUAT";
`SALT_INDEX` = 1;
`SALT_KEY` = "7ab50f0c-a5d9-4bd1-b757-f7fe2fce8a48";

For testing purposes in the UAT environment, use the following credentials:

- **Card Number:** `4242424242424242`  
- **Expiry Month:** `12`  
- **Expiry Year:** `44`  
- **CVV:** `936`  
- **OTP:** `123456`  

---

## **Demo Project Implement This PhonePe Library**

This repository provides an integration of the PhonePe Payment Gateway with Node.js and Express. It allows you to handle payments, refunds, and transaction status checks using the PhonePe API:

```sh
# Clone the repository
git clone https://github.com/kaviyarasanofficial/Node.js-Express-PhonePe-Payment-Gateway-Integration.git

# Navigate to the project folder
cd Node.js-Express-PhonePe-Payment-Gateway-Integration

# Install dependencies
npm install
```

## **Install Dependencies**

Run the following command to install the required package:

```sh
npm i @codemoon/phonepe-lib
```

---

## **Import the Package**

```javascript
const { phonePe, phonePePayAmount, phonePeCheckMerchantId } = require('@codemoon/phonepe-lib');
```

---

## **Initiate Payment Request**

To generate a payment URL, use the following function:

### **API Testing Mode**
```plaintext
isLive = false
```

### **API Live Mode**
```plaintext
isLive = true
```

```javascript
const result = await phonePePayAmount(
  isLive,
  amount,
  userId,
  APP_BE_URL,
  mobile,
  MERCHANT_ID,
  SALT_INDEX,
  SALT_KEY
);
```

- `APP_BE_URL`: The backend URL where your Node.js server is running. Example:
  ```js
  APP_BE_URL = "http://localhost:3002/";
  ```
- `MERCHANT_ID`, `SALT_INDEX`, `SALT_KEY`: These credentials will be provided by the [**PhonePe business registration then get call from phonepe team**](https://business.phonepe.com/register?referral-code=RF2502100937302404539487) ..

- `userId` : this is getting from payment user id its unique

## **PhonePe For Business Registration**

For official business registration, click:  
🔗 [Registration here](https://business.phonepe.com/register?referral-code=RF2502100937302404539487)


---

## **Check Payment Status**

### **API Testing Mode**
```plaintext
isLive = false
```

### **API Live Mode**
```plaintext
isLive = true
```

To verify whether the payment was **successful or failed**, use the following function:

```javascript
const result = await phonePeCheckMerchantId(
  merchantTransactionId,
  MERCHANT_ID,
  SALT_INDEX,
  SALT_KEY
);
```

- `MERCHANT_ID`, `SALT_INDEX`, `SALT_KEY`: These credentials will be provided by the [**PhonePe business registration then get call from phonepe team**](https://business.phonepe.com/register?referral-code=RF2502100937302404539487) .

---

## **Check Refund Status**

### **API Testing Mode**
```plaintext
isLive = false
```

### **API Live Mode**
```plaintext
isLive = true
```

To verify whether the payment was **successful or failed**, use the following function:

```javascript
const result = await phonePePayRefundCheck(
  isLive,
  amount,
  merchantId,
  merchantUserId,
  merchantTransactionId,
  originalTransactionId,
  callbackUrl,
  saltKey,
  saltIndex
);
```

`merchantUserId` :- User Id passed in the debit request
`merchantTransactionId` :- Unique Refund Transaction ID generated by the merchant.
`originalTransactionId` :- The actual merchantTransactionId used in the Pay API call generated by the merchant for accepting the forward payments.

- `MERCHANT_ID`, `SALT_INDEX`, `SALT_KEY`: These credentials will be provided by the [**PhonePe business registration then get call from phonepe team**](https://business.phonepe.com/register?referral-code=RF2502100937302404539487) .

---

## **PhonePe For Business Registration**

For PhonePe official business registration, click:  
🔗 [Registration Link Click here](https://business.phonepe.com/register?referral-code=RF2502100937302404539487)


## **PhonePe Support**

For official documentation and support, visit:  
🔗 [PhonePe Developer Docs](https://developer.phonepe.com/v1/docs/contact-us/)

---

## **How to Run Demo Project**

Clone the project:
`git clone https://github.com/kaviyarasanofficial/Node.js-Express-PhonePe-Payment-Gateway-Integration.git`

Install dependencies:
`npm install`

Run the app:
`npm run start`

## **Contact Information**

For any inquiries, collaborations, or development work, feel free to reach out:

📧 **Email:** `klscse6@gmail.com`  
🔗 **PhonePe Team:** [Contact PhonePe Support](https://developer.phonepe.com/v1/docs/contact-us/)

Happy coding! 🎉

