-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7ad68c3
Showing
10 changed files
with
1,700 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
RAZORPAY_KEY_ID=your_key_id | ||
RAZORPAY_KEY_SECRET=your_key_secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Build and Release Folders | ||
bin-debug/ | ||
bin-release/ | ||
[Oo]bj/ | ||
[Bb]in/ | ||
|
||
# Other files and folders | ||
.settings/ | ||
node_modules/ | ||
|
||
|
||
# Executables | ||
*.swf | ||
*.air | ||
*.ipa | ||
*.apk | ||
*.env | ||
|
||
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` | ||
# should NOT be excluded as they contain compiler settings and other important | ||
# information for Eclipse / Flash Builder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Salman Dabbakuti | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require('dotenv').config(); | ||
|
||
const RAZORPAY_KEY_ID = process.env.RAZORPAY_KEY_ID; | ||
const RAZORPAY_KEY_SECRET = process.env.RAZORPAY_KEY_SECRET; | ||
|
||
module.exports = { | ||
RAZORPAY_KEY_ID, | ||
RAZORPAY_KEY_SECRET, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const express = require('express'); | ||
const Razorpay = require('razorpay'); | ||
const { validateWebhookSignature } = require('razorpay/dist/utils/razorpay-utils'); | ||
const app = express(); | ||
const { RAZORPAY_KEY_ID, RAZORPAY_KEY_SECRET } = require('./config'); | ||
|
||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
|
||
// serve static files | ||
app.use(express.static(__dirname + '/public')); | ||
|
||
const razorpay = new Razorpay({ | ||
key_id: RAZORPAY_KEY_ID, | ||
key_secret: RAZORPAY_KEY_SECRET, | ||
}); | ||
|
||
app.post("/create-order", async (req, res) => { | ||
console.log("creating order", req.body); | ||
const { amount, currency } = req.body; | ||
const options = { | ||
amount: amount * 100, // amount in the smallest currency unit | ||
currency, | ||
receipt: "order_rcptid_11", | ||
// custom metadata object from request auth token or database | ||
notes: { | ||
userId: "123", | ||
plan: "basic", | ||
email: "[email protected]" | ||
} | ||
}; | ||
try { | ||
const response = await razorpay.orders.create(options); | ||
res.status(200).send(response); | ||
} catch (error) { | ||
console.log(error); | ||
res.status(500).send(error); | ||
} | ||
}); | ||
|
||
app.post("/verify-payment", async (req, res) => { | ||
console.log("verifying payment webhook", req.body); | ||
const { razorpay_order_id, razorpay_payment_id, razorpay_signature } = req.body; | ||
const body = razorpay_order_id + '|' + razorpay_payment_id; | ||
try { | ||
const isValidSignature = validateWebhookSignature(body, razorpay_signature, RAZORPAY_KEY_SECRET); | ||
if (isValidSignature) { | ||
// Update the order with payment details in your database | ||
console.log("Payment verification successful"); | ||
res.status(200).json({ status: 'ok' }); | ||
} else { | ||
console.log("Payment verification failed"); | ||
res.status(400).json({ status: 'verification_failed' }); | ||
} | ||
} catch (error) { | ||
console.error("Error verifying payment", error); | ||
res.status(500).json({ status: 'error', message: "Failed to verify payment." }); | ||
} | ||
}); | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Hello World'); | ||
}); | ||
|
||
app.get("/purchase", (req, res) => { | ||
res.sendFile(__dirname + "/public/purchase.html"); | ||
}); | ||
|
||
app.get('/payment-cancel', (req, res) => { | ||
res.sendFile(__dirname + '/public/payment-cancel.html'); | ||
}); | ||
|
||
app.get('/payment-success', (req, res) => { | ||
res.sendFile(__dirname + '/public/payment-success.html'); | ||
}); | ||
|
||
app.listen(3000, () => { | ||
console.log('Server is running on http://localhost:3000'); | ||
}); |
Oops, something went wrong.