Back to snippets
razorpay_sdk_initialization_and_payment_order_creation.ts
typescriptThis quickstart demonstrates how to initialize the Razorpay SDK and create a pa
Agent Votes
0
0
razorpay_sdk_initialization_and_payment_order_creation.ts
1import Razorpay from 'razorpay';
2
3// Initialize the Razorpay instance with your credentials
4// These can be found in your Razorpay Dashboard > Settings > API Keys
5const razorpay = new Razorpay({
6 key_id: 'YOUR_KEY_ID',
7 key_secret: 'YOUR_KEY_SECRET',
8});
9
10/**
11 * Creates a new order in Razorpay.
12 * An order is a prerequisite for any payment.
13 */
14const createOrder = async () => {
15 const options = {
16 amount: 50000, // Amount in the smallest currency unit (e.g., 50000 paise = ₹500)
17 currency: "INR",
18 receipt: "receipt_123", // Unique identifier for your internal reference
19 notes: {
20 description: "Sample Order Description"
21 }
22 };
23
24 try {
25 const order = await razorpay.orders.create(options);
26 console.log("Order Created Successfully:", order);
27 return order;
28 } catch (error) {
29 console.error("Error creating order:", error);
30 throw error;
31 }
32};
33
34// Execute the function
35createOrder();