@feardread/fear 1.1.5 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FEAR.js +76 -63
- package/FEARServer.js +5 -6
- package/controllers/address.js +9 -0
- package/controllers/auth/index.js +499 -92
- package/controllers/order.js +0 -1
- package/controllers/payment.js +5 -185
- package/libs/db/index.js +5 -0
- package/libs/emailer/info.js +22 -34
- package/libs/emailer/smtp.js +511 -65
- package/libs/passport/index.js +137 -0
- package/libs/passport.js +22 -0
- package/libs/paypal/index.js +82 -0
- package/libs/stripe/index.js +306 -0
- package/libs/validator/index.js +2 -2
- package/models/address.js +37 -0
- package/models/order.js +29 -154
- package/models/payment.js +18 -79
- package/models/user.js +116 -51
- package/package.json +1 -1
- package/routes/address.js +16 -0
- package/routes/auth.js +6 -0
- package/routes/mail.js +10 -165
- package/routes/order.js +7 -4
- package/routes/payment.js +4 -8
- package/routes/paypal.js +12 -0
- package/routes/stripe.js +27 -0
- package/libs/passport/passport.js +0 -109
package/controllers/order.js
CHANGED
package/controllers/payment.js
CHANGED
|
@@ -1,191 +1,11 @@
|
|
|
1
|
-
const
|
|
2
|
-
const paypal = require("@paypal/checkout-server-sdk");
|
|
3
|
-
const Payment = require("../models/payment");
|
|
1
|
+
const Payment = require('../models/payment');
|
|
4
2
|
const methods = require("./crud");
|
|
5
3
|
|
|
6
|
-
const instance = new Razorpay({
|
|
7
|
-
key_id: "rzp_test_HSSeDI22muUrLR",
|
|
8
|
-
key_secret: "sRO0YkBxvgMg0PvWHJN16Uf7",
|
|
9
|
-
});
|
|
10
4
|
|
|
11
|
-
//
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// PayPal environment setup
|
|
18
|
-
const paypalEnvironment = () => {
|
|
19
|
-
const clientId = process.env.PAYPAL_CLIENT_ID || "YOUR_PAYPAL_CLIENT_ID";
|
|
20
|
-
const clientSecret = process.env.PAYPAL_CLIENT_SECRET || "YOUR_PAYPAL_CLIENT_SECRET";
|
|
21
|
-
|
|
22
|
-
// Use sandbox for testing, live for production
|
|
23
|
-
return new paypal.core.SandboxEnvironment(clientId, clientSecret);
|
|
24
|
-
// For production: return new paypal.core.LiveEnvironment(clientId, clientSecret);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const paypalClient = () => {
|
|
28
|
-
return new paypal.core.PayPalHttpClient(paypalEnvironment());
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
exports.checkout = async (req, res) => {
|
|
32
|
-
try {
|
|
33
|
-
const { amount } = req.body;
|
|
34
|
-
const option = {
|
|
35
|
-
amount: amount * 100,
|
|
36
|
-
currency: "INR",
|
|
37
|
-
};
|
|
38
|
-
const order = await razorpayInstance.orders.create(option);
|
|
39
|
-
res.json({
|
|
40
|
-
success: true,
|
|
41
|
-
order,
|
|
42
|
-
});
|
|
43
|
-
} catch (error) {
|
|
44
|
-
res.status(500).json({
|
|
45
|
-
success: false,
|
|
46
|
-
message: "Error creating Razorpay order",
|
|
47
|
-
error: error.message,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
exports.paymentVerification = async (req, res) => {
|
|
53
|
-
try {
|
|
54
|
-
const { razorpayOrderId, razorpayPaymentId, razorpaySignature } = req.body;
|
|
55
|
-
|
|
56
|
-
// Verify signature for security
|
|
57
|
-
const crypto = require("crypto");
|
|
58
|
-
const generatedSignature = crypto
|
|
59
|
-
.createHmac("sha256", "sRO0YkBxvgMg0PvWHJN16Uf7")
|
|
60
|
-
.update(`${razorpayOrderId}|${razorpayPaymentId}`)
|
|
61
|
-
.digest("hex");
|
|
62
|
-
|
|
63
|
-
if (generatedSignature === razorpaySignature) {
|
|
64
|
-
res.json({
|
|
65
|
-
success: true,
|
|
66
|
-
razorpayOrderId,
|
|
67
|
-
razorpayPaymentId,
|
|
68
|
-
verified: true,
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
71
|
-
res.status(400).json({
|
|
72
|
-
success: false,
|
|
73
|
-
message: "Payment verification failed",
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
} catch (error) {
|
|
77
|
-
res.status(500).json({
|
|
78
|
-
success: false,
|
|
79
|
-
message: "Error verifying payment",
|
|
80
|
-
error: error.message,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
exports.createStripePayment = async (req, res) => {
|
|
86
|
-
try {
|
|
87
|
-
const { paymentMethodId, amount, currency } = req.body;
|
|
88
|
-
|
|
89
|
-
// Create a PaymentIntent
|
|
90
|
-
const paymentIntent = await stripe.paymentIntents.create({
|
|
91
|
-
amount: amount,
|
|
92
|
-
currency: currency || 'usd',
|
|
93
|
-
payment_method: paymentMethodId,
|
|
94
|
-
confirmation_method: 'manual',
|
|
95
|
-
confirm: true,
|
|
96
|
-
return_url: 'https://your-site.com/payment-success',
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
res.json({
|
|
100
|
-
clientSecret: paymentIntent.client_secret,
|
|
101
|
-
status: paymentIntent.status,
|
|
102
|
-
});
|
|
103
|
-
} catch (error) {
|
|
104
|
-
res.status(400).json({ error: error.message });
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
exports.saveStripePayment = async (req, res) => {
|
|
108
|
-
try {
|
|
109
|
-
const { paymentMethodId, customerId } = req.body;
|
|
110
|
-
|
|
111
|
-
// Attach payment method to customer
|
|
112
|
-
await stripe.paymentMethods.attach(paymentMethodId, {
|
|
113
|
-
customer: customerId,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
// Set as default payment method
|
|
117
|
-
await stripe.customers.update(customerId, {
|
|
118
|
-
invoice_settings: {
|
|
119
|
-
default_payment_method: paymentMethodId,
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
res.json({ success: true });
|
|
124
|
-
} catch (error) {
|
|
125
|
-
res.status(400).json({ error: error.message });
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// ============ PAYPAL METHODS ============
|
|
129
|
-
|
|
130
|
-
exports.createPayPalOrder = async (req, res) => {
|
|
131
|
-
try {
|
|
132
|
-
const { amount, currency = "USD" } = req.body;
|
|
133
|
-
|
|
134
|
-
const request = new paypal.orders.OrdersCreateRequest();
|
|
135
|
-
request.prefer("return=representation");
|
|
136
|
-
request.requestBody({
|
|
137
|
-
intent: "CAPTURE",
|
|
138
|
-
purchase_units: [{
|
|
139
|
-
amount: {
|
|
140
|
-
currency_code: currency,
|
|
141
|
-
value: amount.toString(),
|
|
142
|
-
},
|
|
143
|
-
}],
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const order = await paypalClient().execute(request);
|
|
147
|
-
|
|
148
|
-
res.json({
|
|
149
|
-
success: true,
|
|
150
|
-
orderId: order.result.id,
|
|
151
|
-
order: order.result,
|
|
152
|
-
});
|
|
153
|
-
} catch (error) {
|
|
154
|
-
res.status(500).json({
|
|
155
|
-
success: false,
|
|
156
|
-
message: "Error creating PayPal order",
|
|
157
|
-
error: error.message,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
exports.capturePayPalOrder = async (req, res) => {
|
|
163
|
-
try {
|
|
164
|
-
const { orderId } = req.body;
|
|
165
|
-
|
|
166
|
-
const request = new paypal.orders.OrdersCaptureRequest(orderId);
|
|
167
|
-
request.requestBody({});
|
|
168
|
-
|
|
169
|
-
const capture = await paypalClient().execute(request);
|
|
170
|
-
|
|
171
|
-
res.json({
|
|
172
|
-
success: true,
|
|
173
|
-
captureId: capture.result.id,
|
|
174
|
-
status: capture.result.status,
|
|
175
|
-
capture: capture.result,
|
|
176
|
-
});
|
|
177
|
-
} catch (error) {
|
|
178
|
-
res.status(500).json({
|
|
179
|
-
success: false,
|
|
180
|
-
message: "Error capturing PayPal order",
|
|
181
|
-
error: error.message,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const crud = methods.crudController( Payment );
|
|
187
|
-
for(prop in crud) {
|
|
188
|
-
if(crud.hasOwnProperty(prop)) {
|
|
5
|
+
// Extend with CRUD methods
|
|
6
|
+
const crud = methods.crudController(Payment);
|
|
7
|
+
for (const prop in crud) {
|
|
8
|
+
if (crud.hasOwnProperty(prop)) {
|
|
189
9
|
module.exports[prop] = crud[prop];
|
|
190
10
|
}
|
|
191
11
|
}
|
package/libs/db/index.js
CHANGED
package/libs/emailer/info.js
CHANGED
|
@@ -1,41 +1,29 @@
|
|
|
1
1
|
require("dotenv").config({ path: "backend/.env" });
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"user": process.env.SMTP_MAIL,
|
|
10
|
-
"pass": process.env.SMTP_PASS
|
|
11
|
-
},
|
|
12
|
-
"apps": {
|
|
13
|
-
"gfolio": {
|
|
14
|
-
"auth": {
|
|
15
|
-
"user": process.env.SMTP_MAIL,
|
|
16
|
-
"pass": process.env.SMTP_PASS
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
"gdrea": {
|
|
20
|
-
"auth": {
|
|
21
|
-
"user": process.env.SMTP_MAIL,
|
|
22
|
-
"pass": process.env.SMTP_PASS
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
"jbird": {
|
|
26
|
-
"auth": {
|
|
27
|
-
"user": process.env.SMTP_MAIL,
|
|
28
|
-
"pass": process.env.SMTP_PASS
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
}
|
|
4
|
+
mailgun: {
|
|
5
|
+
domain: "fear.dedyn.io",
|
|
6
|
+
region: 'US',
|
|
7
|
+
apikey: process.env.MG_API_KEY,
|
|
8
|
+
sandbox: "sandbox933b4315c0164f209bbf0bc7fb908598.mailgun.org"
|
|
32
9
|
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
10
|
+
smtp: {
|
|
11
|
+
secure: process.env.SMTP_SECURE === 'true',
|
|
12
|
+
mailgun: {
|
|
13
|
+
host: process.env.MG_SMTP_HOST,
|
|
14
|
+
port: parseInt(process.env.SMTP_PORT),
|
|
15
|
+
auth: {
|
|
16
|
+
user: process.env.MG_SMTP_USER,
|
|
17
|
+
pass: process.env.MG_SMTP_PASS
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
google: {
|
|
21
|
+
host: process.env.GOOGLE_SMTP_HOST,
|
|
22
|
+
port: parseInt(process.env.SMTP_PORT),
|
|
23
|
+
auth: {
|
|
24
|
+
user: process.env.GOOGLE_SMTP_USER,
|
|
25
|
+
pass: process.env.GOOGLE_SMTP_PASS
|
|
26
|
+
}
|
|
39
27
|
}
|
|
40
28
|
}
|
|
41
29
|
}
|