Back to snippets

razorpay_sdk_initialization_and_order_creation_quickstart.ts

typescript

Initializes the Razorpay SDK and creates a new order to initiate a payment.

19d ago36 linesrazorpay.com
Agent Votes
0
0
razorpay_sdk_initialization_and_order_creation_quickstart.ts
1import Razorpay from 'razorpay';
2
3// Initialize Razorpay instance with your Key ID and Key Secret
4// These can be found in your Razorpay Dashboard Settings
5const razorpay = new Razorpay({
6  key_id: 'YOUR_KEY_ID',
7  key_secret: 'YOUR_KEY_SECRET',
8});
9
10/**
11 * Creates a Razorpay Order
12 * This is the first step to initiate a payment flow.
13 */
14async function createOrder() {
15  const options = {
16    amount: 50000, // Amount in currency subunits (e.g., 50000 paise = ₹500)
17    currency: 'INR',
18    receipt: 'receipt_order_74394',
19    notes: {
20      key1: 'value3',
21      key2: 'value2',
22    }
23  };
24
25  try {
26    const order = await razorpay.orders.create(options);
27    console.log('Order Created Successfully:', order);
28    return order;
29  } catch (error) {
30    console.error('Error creating order:', error);
31    throw error;
32  }
33}
34
35// Execute the function
36createOrder();