Skip to main content

List all Razorpay Orders in Oracle APEX

   

Razorpay Integration with Oracle APEX

The objective of this blog post is to show you how to list all Razorpay Orders (Specific to particular account) in Oracle APEX using APEX_WEB_SERVICE API.

Before we get into the topic, let's take a look at the following link, which will help you to understand how Razorpay payment gateway can be done in Oracle APEX.


List all Razorpay Orders

Below are steps involved to get this process done.

1) Get Razorpay API Keys

2) Get Razorpay Fetch Orders API End Point

3) Invoke 
Razorpay Fetch Orders API with Postman

4) Create a Sample Application

5) List all 
Razorpay Orders in the form of Report using APEX_WEB_SERVICE API

I) Get Razorpay API Keys

API key is a combination of the key_id and key_secret and is required to make any API request to Razorpay. You also have to implement the API key in your code as part of your integration process.

Step 1: Log into your Dashboard with appropriate credentials.

Step 2: Select the mode (Test or Live) which you want to generate the API Key.

Step 3: Navigate to Settings --> API Keys --> Generate Key to generate key for the selected mode.

The key_id and key_secret appear on a pop-up page.

II) Get Razorpay Fetch Orders API End Point

Step 1: You can get the end point from this link (Orders API)

Step 2: Search text "Fetch Orders", then you can find the fetch orders end point.

curl -u [YOUR_KEY_ID]:[YOUR_KEY_SECRET]\

-X GET https://api.razorpay.com/v1/orders

III) Invoke Razorpay Fetch Orders API with Postman

Step 1: Setup Authorization (Basic Authentication) and click "Send" button to call the API.

Username: API Key Id 
Password: API Key Secrete



Note: When status code is between 200 and 299, then API is working fine.

IV) Create a Sample Application

V) List all Razorpay Orders in the form of Report using APEX_WEB_SERVICE API

Step 1: Create a new blank page.

Step 2: Create a new region on the page (Position: Content Body). In the Property Editor, apply the following changes:

Under Identification:
     For Title - enter List Razorpay Orders
     For Type- select Classical Report/Interactive Report
Under Source:
     For Location - Local Database
     For Type - select SQL Query
     For SQL Query - Copy and paste below query.

SQL Query:

SELECT
          id,
          entity,
          amount,
          amount_paid,
          amount_due,
          currency,
          receipt,
          offer_id,
          status,
          attempts
        FROM dual, 
             json_table (apex_web_service.make_rest_request(p_url => 'https://api.razorpay.com/v1/orders', 
                                                           p_http_method => 'GET',
                                                           p_username => <<Your Razorpay API Key Id>>,
                                                           p_password => <<Your Razorpay API Key Secret>>),
                        '$.items[*]' COLUMNS(id VARCHAR2(4000) path '$.id',
                                             entity VARCHAR2(4000) path '$.entity',
                                             amount NUMBER path '$.amount',
                                             amount_paid NUMBER path '$.amount_paid',
                                             amount_due NUMBER path '$.amount_due',
                                             currency VARCHAR2(4000) path '$.currency',
                                             receipt VARCHAR2(4000) path '$.receipt',
                                             offer_id VARCHAR2(4000) path '$.offer_id',
                                             status VARCHAR2(4000) path '$.status',
                                             attempts VARCHAR2(4000) path '$.attempts'))
WHERE 1=1
ORDER BY id ASC NULLS LAST;


Step 3: Report created and it will list all Razorpay Orders.

API Success Response:

{ "entity":"collection", "count":2, "items":[ { "id":"order_EKzX2WiEWbMxmx", "entity":"order", "amount":1234, "amount_paid":0, "amount_due":1234, "currency":"INR", "receipt":"Receipt No. 1", "offer_id":null, "status":"created", "attempts":0, "notes":[ ], "created_at":1582637108 }, { "id":"order_EAI5nRfThga2TU", "entity":"order", "amount":100, "amount_paid":0, "amount_due":100, "currency":"INR", "receipt":"Receipt No. 1", "offer_id":null, "status":"created", "attempts":0, "notes":[ ], "created_at":1580300731 } ] }

Output:


The demo is here.

That's it. Happy APEXing!

Related Posts:

References/Credits:

Comments