# UPIDrop WooCommerce Payment Gateway Plugin

Accept direct, zero-commission UPI payments on your WooCommerce WordPress store. Customers pay via Google Pay, PhonePe, Paytm, BHIM, or any UPI app, with money settling directly into your bank account.

---

## Highlights

- **0% Transaction Fees:** Bypass 2-3% aggregator fees completely.
- **Direct Bank Settlement:** Funds deposit instantly to your bank account via UPI.
- **SmartTrack Auto-Reconciliation:** Automatic confirmation via bank credit notifications and buyer UTR.
- **Stock Depletion Protection:** Inventory is reserved and stock levels are decremented **only after** payment confirmation via webhook (no premature depletion on checkout bounce).
- **Mobile-First UX:** Seamless deep-linking into UPI apps on Android/iOS; crisp dynamic QR code on desktop.

---

## System Requirements

- WordPress 5.8 or higher
- WooCommerce 5.0 or higher
- PHP 7.4, 8.0, 8.1, 8.2, or 8.3
- cURL and OpenSSL PHP extensions enabled
- Active UPIDrop Merchant Account ([https://upidrop.roori.in](https://upidrop.roori.in))

---

## Installation

### Method 1: Direct File Upload (Easiest)

1. Download [`upidrop-gateway.php`](/plugins/woocommerce/upidrop-gateway.php).
2. Connect to your server via FTP or cPanel File Manager.
3. Navigate to `wp-content/plugins/` and create a folder named `upidrop-gateway`.
4. Upload `upidrop-gateway.php` into `wp-content/plugins/upidrop-gateway/`.
5. In your WordPress Admin: Go to **Plugins** → **Installed Plugins**.
6. Find **UPIDrop Gateway for WooCommerce** and click **Activate**.

### Method 2: Upload as ZIP

1. Compress `upidrop-gateway.php` into a ZIP archive named `upidrop-gateway.zip`.
2. In WordPress Admin: Go to **Plugins** → **Add New Plugin** → **Upload Plugin**.
3. Choose `upidrop-gateway.zip` and click **Install Now**.
4. Click **Activate Plugin**.

---

## Configuration

1. In your WordPress Admin, go to **WooCommerce** → **Settings** → **Payments**.
2. Locate **UPIDrop** in the list and click **Manage** (or toggle it **ON**).
3. Fill in the following settings:

| Setting | Recommended Value | Notes |
| :--- | :--- | :--- |
| **Enable/Disable** | Checked (Enable) | Activates the gateway on the checkout page. |
| **Title** | `Pay via UPI (0% Fee - GPay, PhonePe, Paytm)` | Customer-facing payment method title. |
| **Description** | `Scan QR or open Google Pay, PhonePe, Paytm to pay directly.` | Instructions displayed upon selection. |
| **Public Key** | `pk_live_...` | Copied from your UPIDrop Dashboard. |
| **Secret Key** | `sk_live_...` | Used to verify HMAC signatures on incoming webhooks. |
| **API Base URL** | `https://upidrop-pg.upidrop-payment-gateway.workers.dev` | Production Worker API endpoint. |

4. Click **Save changes**.

---

## Webhook Setup (Crucial for Instant Auto-Confirmation)

The plugin automatically registers a webhook listener at:
```text
https://yourstore.com/?wc-api=wc_gateway_upidrop
```

To connect your WooCommerce store to UPIDrop:
1. Log into your [UPIDrop Dashboard](https://upidrop.roori.in).
2. Go to the **Webhooks** tab.
3. In the **Webhook URL** field, enter your store's webhook endpoint:
   ```text
   https://yourstore.com/?wc-api=wc_gateway_upidrop
   ```
4. Click **Save**.

Whenever an order is paid:
1. UPIDrop sends an HMAC-SHA256 signed `order.paid` event.
2. The plugin verifies the signature against your `Secret Key`.
3. The WooCommerce order status updates to **Processing** (or **Completed** for virtual/downloadable products).
4. Stock levels are reduced and order notes record the 12-digit UPI UTR reference.

---

## How the Customer Experience Works

1. **Checkout:** Customer adds items to cart and selects "Pay via UPI".
2. **Redirect to Hosted Checkout:** The customer is redirected to the secure UPIDrop checkout (`pay.html`).
3. **Payment Execution:**
   - On mobile: Customer taps **Google Pay**, **PhonePe**, or **Paytm** to open their bank app with amount pre-filled.
   - On desktop: Customer scans the high-resolution dynamic QR code.
4. **Instant Verification:** SmartTrack detects the credit and automatically confirms the order.
5. **Return to Store:** Customer is automatically redirected back to your WooCommerce **Order Received** (Thank You) page.

---

## Troubleshooting

- **Order remains "Pending Payment":**
  - Verify that your Webhook URL in UPIDrop Dashboard is publicly accessible and using HTTPS.
  - Verify your **Secret Key** matches between WordPress and UPIDrop.
- **"Invalid API Key" error at checkout:**
  - Check that there are no leading or trailing whitespace characters when pasting your `Public Key`.
- **UPI Deep link doesn't open bank app:**
  - The customer must have a UPI-enabled app installed on their phone.
