Skip to content

Commit 2727b17

Browse files
Merge pull request #64 from codegasms/aahnik-razorpay-integration
Create "orders" module to implement generic razorpay integration
2 parents 045e983 + a225868 commit 2727b17

23 files changed

+974
-2264
lines changed

client/docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# flux-client
2+
3+
* The examples folder contains code snippets for certain handy stuff!

client/docs/examples/razorpay.html

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
</head>
9+
<script src="https://cdn.tailwindcss.com"></script>
10+
11+
<body>
12+
13+
<div class="m-12">
14+
<button id="createOrder" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded "> Create Order </button>
15+
<button id="rzp-button1" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded hidden">Pay with Razorpay</button>
16+
17+
</div>
18+
19+
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
20+
<script>
21+
let data = null;
22+
document.getElementById('createOrder').addEventListener('click', async function postData(e) {
23+
const baseUrl = 'http://localhost:3000/orders/create';
24+
25+
try {
26+
const response = await fetch(baseUrl, {
27+
method: 'POST',
28+
headers: {
29+
'accept': 'application/json',
30+
'Content-Type': 'application/json',
31+
},
32+
credentials: "include",
33+
body: JSON.stringify({
34+
amount: 200,
35+
currency: "INR",
36+
receipt: "receipt-hello"
37+
})
38+
39+
});
40+
console.log(response.status);
41+
if (!response.ok) {
42+
console.log(response.status);
43+
console.log(response.statusText);
44+
alert('Could not create order! Make sure setup is correct')
45+
} else {
46+
data = await response.json();
47+
console.log(data);
48+
console.log("end of flow");
49+
}
50+
// console.log(response.body);
51+
52+
} catch (err) {
53+
console.log('error happened')
54+
console.log(err);
55+
if (err?.response) {
56+
console.log(await err.response.json());
57+
}
58+
59+
}
60+
alert(`Order created: id: ${data.order.id}. Click on Pay with Razorpay`);
61+
if (data != null) {
62+
document.getElementById('rzp-button1').classList.remove('hidden');
63+
document.getElementById('createOrder').classList.add('hidden');
64+
65+
}
66+
var options = {
67+
key: data.key,
68+
amount: data.order.amount,
69+
// Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise
70+
currency: data.order.currency,
71+
name: "Flux@Codegasms",
72+
description: "Get your orgasms here!",
73+
image: "https://i.ibb.co/ZJG2pG2/download-7.jpg",
74+
order_id: data.order.id,
75+
callback_url: `http://localhost:3000/${data.verifyUrl}?frontendBase=http://localhost:5501&successRedirect=/success&failureRedirect=/failure`,
76+
77+
"notes": {
78+
"custom-data": "data"
79+
},
80+
"theme": {
81+
"color": "#3399cc"
82+
}
83+
};
84+
if (data.prefill) {
85+
options['prefill'] = data.prefill;
86+
}
87+
88+
var rzp1 = new Razorpay(options);
89+
document.getElementById('rzp-button1').onclick = function(e) {
90+
rzp1.open();
91+
e.preventDefault();
92+
}
93+
94+
95+
96+
});
97+
console.log(data);
98+
</script>
99+
</body>
100+
101+
</html>

server/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
11
# flux-server
22

33
ALl the server side code lives here!
4+
5+
## Running
6+
7+
### Environment Variables
8+
9+
Please set all the environment variables in `.env` as per the requirments outlined here.
10+
11+
_*For quick start, copy the `template.env` file to `.env`. The values given in `template.env` needs to be changed as per deployment parameters_
12+
13+
| Environment variable | Purpose |
14+
| -------------------------- | ---------------------------------------------------------------------------------------------- |
15+
| MONGO_CON_STR | MongoDB Connection String, URI pointing to your database |
16+
| GOOGLE_OAUTH_CLIENT_ID | Obtain From Google Cloud Console >> APIs and Services >> Credentials >> OAuth 2.0 Client IDs |
17+
| GOOGLE_OAUTH_CLIENT_SECRET | ^^ |
18+
| GOOGLE_OAUTH_CALLBACK_URL | http://{yourDomain.com}/oauth/google/callback |
19+
| GITHUB_OAUTH_CLIENT_ID | GitHub Settings >> Developer Settings >> New OAuth App |
20+
| GITHUB_OAUTH_CLIENT_SECRET | ^^ |
21+
| GITHUB_OAUTH_CALLBACK_URL | http://{yourDomain.com}/oauth/google/callback |
22+
| RAZORPAY_KEY_ID | Razorpay Dashboard >> Accounts & Settings >> Website & App Settings >> API Keys |
23+
| RAZORPAY_KEY_SECRET | ^^ |
24+
| CORS_ALLOWED_ORIGINS | Comma seperated list of allowed origins for CORS |
25+
26+
### Cors and Cookies
27+
28+
- For security purposes, cookies are used in "same-site:strict" mode. On successful login/registration the backend sets the cookie `accessToken`.
29+
- Any request to the backend, from [same site](https://portswigger.net/web-security/csrf/bypassing-samesite-restrictions), can send the cookies to backend.
30+
- Make sure that the frontend has the same domain name of the backend. (deploy on a different sub-domain).
31+
- Use [`credentials: "include"`](https://developer.mozilla.org/en-US/docs/Web/API/fetch#credentials), in your `fetch` options, because `fetch` [does not send cookies automatically](https://reqbin.com/code/javascript/lcpj87js/javascript-fetch-with-credentials).
32+
- The `CORS_ALLOWED_ORIGINS` env var must be correctly set, as described above.
33+
34+
> **NOTE**: Doing anything else, would not be permitted by the standard CORS policy implemented by modern browsers.
35+
36+
### Development Mode
37+
38+
To start the backend server with hot-reload:
39+
40+
```shell
41+
npm run dev
42+
```
43+
44+
## Production Deployment
45+
46+
Nginx + PM2 + Certbot

server/docs/References.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1-
## References
1+
# References
2+
3+
## node js
24

3-
- https://dev.to/tugascript/nestjs-authentication-with-oauth20-adding-external-providers-2kj
4-
- https://docs.nestjs.com/recipes/passport
5-
- https://dev.to/chukwutosin_/implement-google-oauth-in-nestjs-using-passport-1j3k
65
- https://stackoverflow.com/questions/43048113/use-fs-in-typescript
76
- https://nodejs.org/api/path.html#pathjoinpaths
87
- https://www.w3schools.com/js/js_loop_forof.asp
98
- https://stackoverflow.com/questions/41553291/can-you-import-nodes-path-module-using-import-path-from-path
10-
- https://medium.com/@flavtech/google-oauth2-authentication-with-nestjs-explained-ab585c53edec
9+
10+
## oauth
11+
12+
- https://dev.to/tugascript/nestjs-authentication-with-oauth20-adding-external-providers-2kj
13+
- https://docs.nestjs.com/recipes/passport
14+
- https://dev.to/chukwutosin_/implement-google-oauth-in-nestjs-using-passport-1j3k
15+
- https://medium.com/@flavtech/google-oauth2-authentication-with-nestjs-explained-ab585c53edec
16+
17+
## razorpay
18+
19+
- https://razorpay.com/docs/payments/payment-gateway/web-integration/standard/integration-steps/
20+
- https://medium.com/@aifuture/razorpay-payment-gateway-integration-in-node-js-react-js-6a560740bba7
21+
22+
## cookies
23+
24+
- https://portswigger.net/web-security/csrf/bypassing-samesite-restrictions
25+
- https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1
26+
27+
## fetch
28+
29+
- https://apidog.com/blog/axios-vs-fetch
30+
- https://reqbin.com/code/javascript/lcpj87js/javascript-fetch-with-credentials
31+
- https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
32+
- https://suhanwijaya.medium.com/missing-cookie-in-http-request-when-using-fetch-api-fc0199c3dc3c
33+
- https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#differences_from_jquery.ajax
34+
35+
## cors
36+
37+
- https://aws.amazon.com/what-is/cross-origin-resource-sharing
38+
- https://www.moesif.com/blog/technical/cors/Authoritative-Guide-to-CORS-Cross-Origin-Resource-Sharing-for-REST-APIs/
39+
- https://medium.com/@cybersphere/fetch-api-the-ultimate-guide-to-cors-and-no-cors-cbcef88d371e
40+
- https://web.dev/articles/cross-origin-resource-sharing

0 commit comments

Comments
 (0)