WebUPI Protocol
  • Namaste
    • â„šī¸Welcome to WebUPI!
    • 🏆Benefits of WebUPI
  • How to
    • 👨‍đŸ’ģGetting Started with WebUPI
    • đŸ’ģWebUPI Reference
      • webUPI.enable()
      • webUPI.sendPayment()
      • webUPI.requestPayment()
      • webUPI.getUPIId()
      • webUPI.getPaymentStatus()
      • Error Handling in WebUPI
  • other
    • 📱WebUPI Providers
    • 📓Helpful references
  • WebUPI Providers
    • For Providers
      • Implementing WebUPI as a UPI Provider
  • WebUPI x Web3 Bridge
    • â„šī¸Introduction
    • 👩‍đŸ’ģGet Started
      • webUPI.sendPaymentToLightning()
      • webUPI.requestLightningInvoice()
    • đŸĻ¸Upgrades
  • More Protocols
    • 📓UPI Withdrawal Protocol Specification (UPIW)
    • 📓Commerce Unified Payment Protocol Specifications (CUPP)
    • 📓Real-Time Money Streaming Protocol (RTMS)
Powered by GitBook
On this page
  • Using WebUPI
  • Enabling WebUPI
  • Making a Payment
  • Making a Payment Request
  1. How to

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:


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:


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:


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:


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.

PreviousBenefits of WebUPINextWebUPI Reference

Last updated 2 years ago

👨‍đŸ’ģ