> For the complete documentation index, see [llms.txt](https://ninjapay.gitbook.io/webupi-protocol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ninjapay.gitbook.io/webupi-protocol/how-to/getting-started-with-webupi.md).

# Getting Started with WebUPI

WebUPI is a proposed browser API that allows web applications to request payment via UPI (Unified Payments Interface). It provides a standardized way for web applications to interact with a user's UPI app on their device.

### **Using WebUPI**

To start using WebUPI, you first need to make sure that the user's browser supports it. Here's how you can check:

```jsx

if (typeof window.webUPI !== 'undefined') {
    // WebUPI is supported
} else {
    // WebUPI is not supported
}

```

Once you've confirmed that the user's browser supports WebUPI, you can start using its APIs.

### **Enabling WebUPI**

Before you can use WebUPI, you need to enable it by calling the **`webUPI.enable()`** function:

```jsx

try {
    if (typeof window.webUPI !== 'undefined') {
        await window.webUPI.enable();
    }
} catch (error) {
    // User denied permission or cancelled
    console.log(error);
}

```

This will prompt the user to give permission for the web application to use the UPI capabilities of their device. If the user denies permission or cancels, an error will be thrown.

### **Making a Payment**

To make a payment, you need to call the **`webUPI.sendPayment()`** function with a UPI URI:

```jsx

try {
    const upiURI = "upi://pay?pa=example@upi&pn=Example&mc=0000&tid=000000000000&tr=TestTransaction&tn=TestTransaction&am=10.01&cu=INR&url=http://example.com";
    await webUPI.sendPayment(upiURI);
} catch (error) {
    // Payment failed
    console.log(error);
}

```

This will prompt the user's UPI app to make a payment. If the payment fails, an error will be thrown.

### **Making a Payment Request**

To make a payment request, you need to call the **`webUPI.requestPayment()`** function with a UPI URI:

```jsx

try {
    const upiURI = "upi://pay?pa=example@upi&pn=Example&mc=0000&tid=000000000000&tr=TestTransaction&tn=TestTransaction&am=10.01&cu=INR&url=http://example.com";
    await webUPI.requestPayment(upiURI);
} catch (error) {
    // Payment request failed
    console.log(error);
}

```

This will prompt the user's UPI app to accept a payment request. If the payment request fails, an error will be thrown.

Remember to handle errors gracefully to provide a good user experience. For more information on error handling, see the Error Handling section.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://ninjapay.gitbook.io/webupi-protocol/how-to/getting-started-with-webupi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
