@aurispec/core-backend 1.0.4 → 1.0.5
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/dist/database/migrations/1772984882048-modified_reviews_table.d.ts +7 -0
- package/dist/database/migrations/1772984882048-modified_reviews_table.d.ts.map +1 -0
- package/dist/database/migrations/1772984882048-modified_reviews_table.js +61 -0
- package/dist/models/BusinessModel.d.ts +2 -0
- package/dist/models/BusinessModel.d.ts.map +1 -1
- package/dist/models/BusinessModel.js +9 -0
- package/dist/models/ReviewModel.d.ts +5 -0
- package/dist/models/ReviewModel.d.ts.map +1 -1
- package/dist/models/ReviewModel.js +19 -0
- package/dist/models/UserModel.d.ts +2 -0
- package/dist/models/UserModel.d.ts.map +1 -1
- package/dist/models/UserModel.js +9 -0
- package/package.json +1 -1
- package/dist/app.js +0 -59
- package/dist/common/configs/express.js +0 -29
- package/dist/common/configs/websocket.js +0 -17
- package/dist/common/constants/chat.d.ts +0 -18
- package/dist/common/constants/chat.d.ts.map +0 -1
- package/dist/common/constants/chat.js +0 -20
- package/dist/common/constants/messages/admin.messages.d.ts +0 -33
- package/dist/common/constants/messages/admin.messages.d.ts.map +0 -1
- package/dist/common/constants/messages/admin.messages.js +0 -35
- package/dist/common/constants/messages/user.messages.d.ts +0 -33
- package/dist/common/constants/messages/user.messages.d.ts.map +0 -1
- package/dist/common/constants/messages/user.messages.js +0 -35
- package/dist/common/dtos/AdminDto.d.ts +0 -5
- package/dist/common/dtos/AdminDto.d.ts.map +0 -1
- package/dist/common/dtos/AdminDto.js +0 -30
- package/dist/common/dtos/ArticleDto.d.ts +0 -11
- package/dist/common/dtos/ArticleDto.d.ts.map +0 -1
- package/dist/common/dtos/ArticleDto.js +0 -61
- package/dist/common/dtos/BusinessDto.d.ts +0 -12
- package/dist/common/dtos/BusinessDto.d.ts.map +0 -1
- package/dist/common/dtos/BusinessDto.js +0 -59
- package/dist/common/dtos/ChatDto.d.ts +0 -17
- package/dist/common/dtos/ChatDto.d.ts.map +0 -1
- package/dist/common/dtos/ChatDto.js +0 -89
- package/dist/common/dtos/CommonDto.d.ts +0 -13
- package/dist/common/dtos/CommonDto.d.ts.map +0 -1
- package/dist/common/dtos/CommonDto.js +0 -59
- package/dist/common/dtos/CommunityDto.d.ts +0 -10
- package/dist/common/dtos/CommunityDto.d.ts.map +0 -1
- package/dist/common/dtos/CommunityDto.js +0 -72
- package/dist/common/dtos/EventDto.d.ts +0 -24
- package/dist/common/dtos/EventDto.d.ts.map +0 -1
- package/dist/common/dtos/EventDto.js +0 -72
- package/dist/common/dtos/IPaginator.d.ts +0 -15
- package/dist/common/dtos/IPaginator.d.ts.map +0 -1
- package/dist/common/dtos/IPaginator.js +0 -40
- package/dist/common/dtos/Plan.dto.d.ts +0 -10
- package/dist/common/dtos/Plan.dto.d.ts.map +0 -1
- package/dist/common/dtos/Plan.dto.js +0 -66
- package/dist/common/dtos/PostDto.d.ts +0 -13
- package/dist/common/dtos/PostDto.d.ts.map +0 -1
- package/dist/common/dtos/PostDto.js +0 -75
- package/dist/common/dtos/ProductDto.d.ts +0 -13
- package/dist/common/dtos/ProductDto.d.ts.map +0 -1
- package/dist/common/dtos/ProductDto.js +0 -66
- package/dist/common/dtos/ServiceDto.d.ts +0 -19
- package/dist/common/dtos/ServiceDto.d.ts.map +0 -1
- package/dist/common/dtos/ServiceDto.js +0 -93
- package/dist/common/dtos/UserDto.d.ts +0 -70
- package/dist/common/dtos/UserDto.d.ts.map +0 -1
- package/dist/common/dtos/UserDto.js +0 -313
- package/dist/common/types/IPagination.d.ts +0 -15
- package/dist/common/types/IPagination.d.ts.map +0 -1
- package/dist/common/types/IPagination.js +0 -2
- package/dist/common/utils/axios.js +0 -26
- package/dist/common/utils/socket.js +0 -16
- package/dist/database/seeds/CommunityDataSeeder.js +0 -48
- package/dist/database/seeds/EventDataSeeder.js +0 -54
- package/dist/database/seeds/FeatureSeeder.js +0 -131
- package/dist/database/seeds/MarketplaceDataSeeder.js +0 -95
- package/dist/database/seeds/PlanSeeder.js +0 -78
- package/dist/database/seeds/UserProfileDataSeeder.js +0 -215
- package/dist/database/seeds/index.js +0 -39
- package/dist/services/StripeService.js +0 -288
- package/dist/services/mobile/ArticleCommentService.js +0 -479
- package/dist/services/mobile/ArticleService.js +0 -507
- package/dist/services/mobile/AuthService.js +0 -362
- package/dist/services/mobile/BusinessService.js +0 -267
- package/dist/services/mobile/BusinessServiceService.js +0 -383
- package/dist/services/mobile/CardService.js +0 -249
- package/dist/services/mobile/ChatService.js +0 -324
- package/dist/services/mobile/CommunityMemberService.js +0 -193
- package/dist/services/mobile/CommunityService.js +0 -561
- package/dist/services/mobile/CompleteProfileService.js +0 -308
- package/dist/services/mobile/ConnectionService.js +0 -338
- package/dist/services/mobile/EventAttendanceService.js +0 -343
- package/dist/services/mobile/EventService.js +0 -540
- package/dist/services/mobile/NotificationService.js +0 -89
- package/dist/services/mobile/PasswordResetService.js +0 -168
- package/dist/services/mobile/PlanService.js +0 -85
- package/dist/services/mobile/PostCommentService.js +0 -611
- package/dist/services/mobile/PostService.js +0 -640
- package/dist/services/mobile/ProductService.js +0 -360
- package/dist/services/mobile/RedisService.js +0 -16
- package/dist/services/mobile/TransactionService.js +0 -51
- package/dist/services/mobile/UploadService.js +0 -110
- package/dist/services/mobile/UserService.js +0 -128
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.stripe = void 0;
|
|
16
|
-
const typedi_1 = require("typedi");
|
|
17
|
-
const logger_1 = require("../common/configs/logger");
|
|
18
|
-
const AppError_1 = require("../common/errors/AppError");
|
|
19
|
-
const configs_1 = require("../common/configs");
|
|
20
|
-
const PlanRepository_1 = require("../repositories/PlanRepository");
|
|
21
|
-
const UserRepository_1 = require("../repositories/UserRepository");
|
|
22
|
-
const IndexEnum_1 = require("../common/enums/IndexEnum");
|
|
23
|
-
const SubscriptionRepository_1 = require("../repositories/SubscriptionRepository");
|
|
24
|
-
const TransactionRepository_1 = require("../repositories/TransactionRepository");
|
|
25
|
-
const TransactionEnum_1 = require("../common/enums/TransactionEnum");
|
|
26
|
-
const moment_1 = __importDefault(require("moment"));
|
|
27
|
-
const SessionRepository_1 = require("../repositories/SessionRepository");
|
|
28
|
-
const stripe_1 = __importDefault(require("stripe"));
|
|
29
|
-
const number_utils_1 = require("../common/utils/number_utils");
|
|
30
|
-
const CardService_1 = __importDefault(require("./mobile/CardService"));
|
|
31
|
-
const PaymentGatewayCustomerRepository_1 = require("@/repositories/PaymentGatewayCustomerRepository");
|
|
32
|
-
const messages_1 = require("@/common/constants/messages");
|
|
33
|
-
exports.stripe = new stripe_1.default(configs_1.CONFIGS.STRIPE.SECRET_KEY, {
|
|
34
|
-
apiVersion: "2025-12-15.clover"
|
|
35
|
-
});
|
|
36
|
-
let StripeService = class StripeService {
|
|
37
|
-
planRepository;
|
|
38
|
-
userRepository;
|
|
39
|
-
subscriptionRepository;
|
|
40
|
-
transactionRepository;
|
|
41
|
-
sessionRepository;
|
|
42
|
-
cardService;
|
|
43
|
-
paymentGatewayCustomerRepository;
|
|
44
|
-
constructor() {
|
|
45
|
-
this.planRepository = new PlanRepository_1.PlanRepository();
|
|
46
|
-
this.userRepository = new UserRepository_1.UserRepository();
|
|
47
|
-
this.subscriptionRepository = new SubscriptionRepository_1.SubscriptionRepository();
|
|
48
|
-
this.transactionRepository = new TransactionRepository_1.TransactionRepository();
|
|
49
|
-
this.sessionRepository = new SessionRepository_1.SessionRepository();
|
|
50
|
-
this.paymentGatewayCustomerRepository = new PaymentGatewayCustomerRepository_1.PaymentGatewayCustomerRepository();
|
|
51
|
-
this.cardService = new CardService_1.default();
|
|
52
|
-
}
|
|
53
|
-
createStripePlan = async (planName, amount, interval) => {
|
|
54
|
-
let message;
|
|
55
|
-
try {
|
|
56
|
-
const product = await exports.stripe.products.create({
|
|
57
|
-
name: planName
|
|
58
|
-
});
|
|
59
|
-
const price = await exports.stripe.prices.create({
|
|
60
|
-
product: product.id,
|
|
61
|
-
unit_amount: (0, number_utils_1.dollar_to_cent)(amount),
|
|
62
|
-
currency: "usd",
|
|
63
|
-
recurring: {
|
|
64
|
-
interval
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
// Check if Stripe returned a price id
|
|
68
|
-
if (!price?.id) {
|
|
69
|
-
message = "Stripe subscription plan creation failed.";
|
|
70
|
-
logger_1.logger.error(message);
|
|
71
|
-
throw new AppError_1.AppError(message, 400);
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
successful: true,
|
|
75
|
-
data: {
|
|
76
|
-
product_id: product.id,
|
|
77
|
-
plan_code: price.id
|
|
78
|
-
},
|
|
79
|
-
message: "Stripe plan created successfully"
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
catch (err) {
|
|
83
|
-
message = err.message || "Stripe subscription plan creation failed.";
|
|
84
|
-
logger_1.logger.error(message);
|
|
85
|
-
throw new AppError_1.AppError(err.message, err.statusCode || 400);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
createStripeSession = async (email, priceId, stripeAmount, billing_cycle, existingPlan, req) => {
|
|
89
|
-
let message;
|
|
90
|
-
try {
|
|
91
|
-
const session = await exports.stripe.checkout.sessions.create({
|
|
92
|
-
mode: "subscription",
|
|
93
|
-
payment_method_types: ["card"],
|
|
94
|
-
customer_email: email,
|
|
95
|
-
line_items: [
|
|
96
|
-
{
|
|
97
|
-
price: priceId,
|
|
98
|
-
quantity: 1
|
|
99
|
-
}
|
|
100
|
-
],
|
|
101
|
-
success_url: `${configs_1.CONFIGS.MAIN_WEBSITE_BASE_URL}/billing/success?session_id={CHECKOUT_SESSION_ID}`,
|
|
102
|
-
cancel_url: `${configs_1.CONFIGS.MAIN_WEBSITE_BASE_URL}/billing/cancel`
|
|
103
|
-
});
|
|
104
|
-
await this.sessionRepository.create({
|
|
105
|
-
user_id: req.user.id,
|
|
106
|
-
session_type: IndexEnum_1.SESSION_TYPE.PLAN_SUSBCRIPTION,
|
|
107
|
-
payload: {
|
|
108
|
-
reference: session.id,
|
|
109
|
-
payer_id: email,
|
|
110
|
-
subscription: true,
|
|
111
|
-
billing_cycle,
|
|
112
|
-
amount: (0, number_utils_1.dollar_to_cent)(stripeAmount),
|
|
113
|
-
payment_engine_plan_id: priceId,
|
|
114
|
-
plan_id: existingPlan.uuid
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
return {
|
|
118
|
-
successful: true,
|
|
119
|
-
data: {
|
|
120
|
-
authorization_url: session.url,
|
|
121
|
-
payment_session: true
|
|
122
|
-
},
|
|
123
|
-
message: "Stripe subscription session created successfully"
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
catch (err) {
|
|
127
|
-
message = err.message || "Stripe subscription session creation failed.";
|
|
128
|
-
logger_1.logger.error(message);
|
|
129
|
-
throw new AppError_1.AppError(message, err.statusCode || 400);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
handleStripeCheckoutCompleted = async (session) => {
|
|
133
|
-
const storedSession = await this.sessionRepository.getRepo()
|
|
134
|
-
.createQueryBuilder("session")
|
|
135
|
-
.where("session.payload->>'reference' = :id", { id: session.id })
|
|
136
|
-
.getOne();
|
|
137
|
-
if (!storedSession)
|
|
138
|
-
return;
|
|
139
|
-
const { plan_id, billing_cycle, payer_id } = storedSession.payload;
|
|
140
|
-
const foundPlan = await this.planRepository.basicFindOneByConditions({
|
|
141
|
-
uuid: plan_id
|
|
142
|
-
});
|
|
143
|
-
if (!foundPlan)
|
|
144
|
-
return;
|
|
145
|
-
const foundUser = await this.userRepository.basicFindOneByConditions({
|
|
146
|
-
email: payer_id
|
|
147
|
-
});
|
|
148
|
-
if (!foundUser)
|
|
149
|
-
return;
|
|
150
|
-
const nextPayment = billing_cycle === "monthly"
|
|
151
|
-
? (0, moment_1.default)().add(1, "month").toDate()
|
|
152
|
-
: (0, moment_1.default)().add(1, "year").toDate();
|
|
153
|
-
await this.userRepository.updateOne({ uuid: foundUser.uuid }, {
|
|
154
|
-
plan_id: foundPlan.id,
|
|
155
|
-
plan_expires_at: nextPayment
|
|
156
|
-
});
|
|
157
|
-
await this.subscriptionRepository.create({
|
|
158
|
-
user_id: foundUser.id,
|
|
159
|
-
payment_ref: session.subscription,
|
|
160
|
-
plan_id: foundPlan.id,
|
|
161
|
-
status: IndexEnum_1.STATUS.ACTIVE
|
|
162
|
-
});
|
|
163
|
-
await this.transactionRepository.create({
|
|
164
|
-
transaction_ref: session.payment_intent,
|
|
165
|
-
user_id: foundUser.id,
|
|
166
|
-
amount: (0, number_utils_1.cent_to_dollar)(session.amount_total).toString(),
|
|
167
|
-
plan_id: foundPlan.id,
|
|
168
|
-
status: TransactionEnum_1.TRANSACTION_STATUS.SUCCESSFUL
|
|
169
|
-
});
|
|
170
|
-
await this.sessionRepository.rawQuery(`DELETE FROM "sessions" WHERE payload->>'reference' = $1`, [session.id]);
|
|
171
|
-
};
|
|
172
|
-
async createCustomer(foundUser) {
|
|
173
|
-
const customer = await exports.stripe.customers.create({
|
|
174
|
-
email: foundUser.email,
|
|
175
|
-
name: `${foundUser.full_name}`,
|
|
176
|
-
metadata: { userId: foundUser.uuid },
|
|
177
|
-
});
|
|
178
|
-
await this.paymentGatewayCustomerRepository.create({
|
|
179
|
-
user_id: foundUser.id,
|
|
180
|
-
customer_id: customer.id
|
|
181
|
-
});
|
|
182
|
-
return {
|
|
183
|
-
successful: true,
|
|
184
|
-
data: customer,
|
|
185
|
-
message: messages_1.dynamic_messages.CREATED_SUCCESSFULLY("Stripe customer"),
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
async attachedCardToCustomer(paymentMethodId, customer_id) {
|
|
189
|
-
// Attach card to customer
|
|
190
|
-
await exports.stripe.paymentMethods.attach(paymentMethodId, { customer: customer_id });
|
|
191
|
-
logger_1.logger.debug("Card Attached to the customer successfully!");
|
|
192
|
-
}
|
|
193
|
-
async handleWebhook(signature, reqBody) {
|
|
194
|
-
try {
|
|
195
|
-
const event = exports.stripe.webhooks.constructEvent(reqBody, signature, configs_1.CONFIGS.STRIPE.WEBHOOK_SECRET);
|
|
196
|
-
const eventData = event.data.object;
|
|
197
|
-
// console.log({eventData})
|
|
198
|
-
switch (event.type) {
|
|
199
|
-
case "payment_method.attached":
|
|
200
|
-
await this.cardService.addCard(eventData);
|
|
201
|
-
break;
|
|
202
|
-
case "setup_intent.succeeded":
|
|
203
|
-
console.log("Card attached:", eventData.card);
|
|
204
|
-
break;
|
|
205
|
-
case "checkout.session.completed":
|
|
206
|
-
await this.handleStripeCheckoutCompleted(event.data.object);
|
|
207
|
-
break;
|
|
208
|
-
case "invoice.payment_succeeded":
|
|
209
|
-
const subscriptionId = eventData.subscription;
|
|
210
|
-
const storedSession = await this.sessionRepository.getRepo()
|
|
211
|
-
.createQueryBuilder("session")
|
|
212
|
-
.where("session.payload->>'reference' = :id", { id: subscriptionId })
|
|
213
|
-
.getOne();
|
|
214
|
-
if (!storedSession)
|
|
215
|
-
return;
|
|
216
|
-
await this.transactionRepository.create({
|
|
217
|
-
transaction_ref: eventData.payment_intent,
|
|
218
|
-
user_id: storedSession.id,
|
|
219
|
-
amount: (0, number_utils_1.cent_to_dollar)(eventData.amount_paid).toString(),
|
|
220
|
-
plan_id: storedSession.payload.plan_id,
|
|
221
|
-
status: TransactionEnum_1.TRANSACTION_STATUS.SUCCESSFUL
|
|
222
|
-
});
|
|
223
|
-
await this.subscriptionRepository.updateOne({ payment_ref: subscriptionId }, { status: IndexEnum_1.STATUS.ACTIVE });
|
|
224
|
-
break;
|
|
225
|
-
case "invoice.payment_failed":
|
|
226
|
-
break;
|
|
227
|
-
default:
|
|
228
|
-
logger_1.logger.debug(`Wrong Stripe Webhook event ${event.type}`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
232
|
-
console.error("Webhook signature verification failed.", err.message);
|
|
233
|
-
// return res.sendStatus(400);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
async chargeCard(amount, customer_id, payment_method_id) {
|
|
237
|
-
const amountInCents = parseFloat(amount) * 100;
|
|
238
|
-
let message;
|
|
239
|
-
const pi = await exports.stripe.paymentIntents.create({
|
|
240
|
-
amount: amountInCents,
|
|
241
|
-
currency: "USD",
|
|
242
|
-
customer: customer_id,
|
|
243
|
-
payment_method: payment_method_id,
|
|
244
|
-
off_session: true,
|
|
245
|
-
confirm: true,
|
|
246
|
-
});
|
|
247
|
-
if (pi.status === "succeeded") {
|
|
248
|
-
message = `${amount} extra bundle purchased successfully`;
|
|
249
|
-
logger_1.logger.debug(message);
|
|
250
|
-
return {
|
|
251
|
-
successful: true,
|
|
252
|
-
data: {
|
|
253
|
-
paymentIntent: pi
|
|
254
|
-
},
|
|
255
|
-
message,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
// If the payment requires additional action (SCA)
|
|
259
|
-
if (pi.status === "requires_action" || pi.next_action) {
|
|
260
|
-
// You need to notify the customer and have them authenticate in the client
|
|
261
|
-
message = `To complete the ${amount} extra bundle purchase, you need to authorise the payment`;
|
|
262
|
-
logger_1.logger.debug(message);
|
|
263
|
-
return {
|
|
264
|
-
successful: false,
|
|
265
|
-
data: {
|
|
266
|
-
requires_action: true,
|
|
267
|
-
paymentIntent: pi
|
|
268
|
-
},
|
|
269
|
-
message
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
message = `${amount} extra bundle purchase failed`;
|
|
273
|
-
logger_1.logger.debug(message);
|
|
274
|
-
return {
|
|
275
|
-
successful: false,
|
|
276
|
-
data: {
|
|
277
|
-
requires_action: true,
|
|
278
|
-
paymentIntent: pi
|
|
279
|
-
},
|
|
280
|
-
message
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
StripeService = __decorate([
|
|
285
|
-
(0, typedi_1.Service)(),
|
|
286
|
-
__metadata("design:paramtypes", [])
|
|
287
|
-
], StripeService);
|
|
288
|
-
exports.default = StripeService;
|