Beejartha

Categories
Oracle APEX

Integrating India’s UPI API with Oracle APEX: A Step-by-Step Guide

Unified Payments Interface (UPI) has revolutionized digital payments in India by offering a seamless and efficient way to conduct transactions. For businesses and developers using Oracle Application Express (APEX), integrating UPI can enhance your application by providing users with a convenient payment method. In this blog post, we’ll explore what UPI is, why it’s beneficial, and walk you through the process of integrating UPI with Oracle APEX.

What is UPI?

UPI is a real-time payment system developed by the National Payments Corporation of India (NPCI). It enables users to link multiple bank accounts to a single mobile application, facilitating quick and secure transactions. With UPI, users can make peer-to-peer payments, pay bills, and complete transactions with just a few clicks.

Benefits of UPI Integration

  1. Instant Transactions: UPI transactions are processed in real-time, making it ideal for quick payments.
  2. User-Friendly: UPI provides a simple and intuitive interface for users.
  3. Cost-Efficient: UPI transactions generally incur lower fees compared to traditional banking methods.
  4. Enhanced Security: UPI employs robust security measures to protect users’ financial information.

Integrating UPI with Oracle APEX

Oracle APEX is a powerful low-code development platform that simplifies the creation of web applications.

Integrating UPI into your Oracle APEX application involves several steps, including setting up a payment gateway, configuring web services, and handling payment responses. Let’s walk through the integration process.

Step 1: Choose a UPI Service Provider

To integrate UPI, you’ll need to use a payment gateway provider that supports UPI transactions. Popular options include Razorpay, Paytm, and PhonePe. For this guide, we’ll use Razorpay. Sign up for an account with Razorpay and obtain your API key and secret.

Step 2: Set Up Web Services in Oracle APEX

  • Login to Oracle APEX: Access your Oracle APEX workspace and navigate to the application where you want to integrate UPI.
  • Create a Web Service:
    • Go to the “SQL Workshop” section.
    • Select “RESTful Web Services” and create a new RESTful Web Service.
  • Define the Web Service:
    • Set the “Base URL” to the endpoint provided by your payment gateway (e.g., Razorpay’s API endpoint).
    • Configure the HTTP methods (GET, POST, etc.) based on the API documentation provided by your payment gateway.
  • Authentication:
    • Implement authentication using the API key and secret provided by your payment gateway.
    • Use the “Web Credentials” feature in APEX to securely store your credentials.

Step 3: Create an API Integration

  1. Create a New PL/SQL Process:
    • Go to “App Builder” and select the page where you want to add UPI payment functionality.
    • Create a new PL/SQL process to handle the payment request.
  2. Set Up the Payment Request:
      • Use the PL/SQL code to call the payment gateway’s API. Here’s an example using Razorpay’s API to create an order:


    DECLARE
    l_order_response clob;
    l_http_request uow_request;
    l_http_response uow_response;
    l_url varchar2(32767);
    BEGIN
    l_url := 'https://api.razorpay.com/v1/orders';
    l_http_request := utl_http.begin_request(l_url, 'POST', 'HTTP/1.1');
    utl_http.set_header(l_http_request, 'Content-Type', 'application/json');
    utl_http.set_authentication(l_http_request, 'YOUR_RAZORPAY_KEY_ID', 'YOUR_RAZORPAY_KEY_SECRET');
    utl_http.write_text(l_http_request, '{"amount":50000,"currency":"INR","payment_capture":1}');
    l_http_response := utl_http.get_response(l_http_request);
    l_order_response := utl_http.get_text(l_http_response);
    dbms_output.put_line(l_order_response);
    utl_http.end_response(l_http_response);
    END;

    • Replace YOUR_RAZORPAY_KEY_ID and YOUR_RAZORPAY_KEY_SECRET with your actual credentials.
    • Handle the Response:
      • Parse the response from the payment gateway to extract necessary details such as order ID and payment link.
      • Display the payment link or redirect users to complete the transaction.

Step 4: Implement Payment Confirmation

  1. Create a Callback Page:
    • Set up a page to handle payment confirmations. This page will receive payment status from the payment gateway.
  2. Handle Payment Status:
    • Implement a process to verify the payment status using the details sent by the payment gateway. For example:


DECLARE
l_payment_id varchar2(255);
l_payment_status varchar2(255);
BEGIN
-- Extract payment ID and status from the request
l_payment_id := :P1_PAYMENT_ID;
l_payment_status := :P1_PAYMENT_STATUS;
-- Verify payment status (implementation depends on gateway API)
IF l_payment_status = 'success' THEN
-- Update order status or perform necessary actions
dbms_output.put_line('Payment successful!');
ELSE
dbms_output.put_line('Payment failed.');
END IF;
END;

  1. Configure Webhooks (Optional):

Some payment gateways offer webhooks to notify your application of payment events. Configure webhooks as per the gateway’s documentation to automatically handle payment updates.

Step 5: Test and Deploy

  1. Testing:
    • Test the integration thoroughly using the payment gateway’s sandbox environment. Ensure that all scenarios (e.g., successful payments, failed payments) are handled correctly.
  2. Deployment:
    • After successful testing, deploy your application to the production environment. Switch to live credentials and monitor transactions to ensure smooth operation.

Conclusion

Integrating UPI with Oracle APEX can significantly enhance your application’s payment capabilities, offering a convenient and secure option for users. By following the steps outlined in this guide, you can successfully integrate UPI into your APEX application, enabling real-time payments and improving user experience.

If you have any questions or need further assistance, feel free to leave a comment below. Happy integrating, and may your UPI implementation be smooth and successful!

Avatar

By Eric K

Experienced Software Developer with a demonstrated history of working in the computer software industry. Skilled in React.js, Vue.js, JavaScript and Node.js.

Any Query?

Ask Beejartha