@7365admin1/core 2.23.0 → 2.24.0
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +132 -1
- package/dist/index.js +720 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +723 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -28923,7 +28923,7 @@ function useSiteUnitBillingRepo() {
|
|
|
28923
28923
|
value = MUnitBilling(value);
|
|
28924
28924
|
const res = await collection.insertOne(value, { session });
|
|
28925
28925
|
const acronym = createAcronym(value.billName || "NA");
|
|
28926
|
-
const dateFormatted =
|
|
28926
|
+
const dateFormatted = formatDateString2(/* @__PURE__ */ new Date());
|
|
28927
28927
|
const newId = new ObjectId81(res.insertedId).toString().slice(-6);
|
|
28928
28928
|
const referenceNumber = `${acronym}${newId}${dateFormatted}`;
|
|
28929
28929
|
await collection.updateOne(
|
|
@@ -29262,7 +29262,7 @@ function useSiteUnitBillingRepo() {
|
|
|
29262
29262
|
function createAcronym(billName) {
|
|
29263
29263
|
return billName.split(" ").map((word) => word.charAt(0).toUpperCase()).join("");
|
|
29264
29264
|
}
|
|
29265
|
-
function
|
|
29265
|
+
function formatDateString2(today) {
|
|
29266
29266
|
today = typeof today === "string" ? new Date(today) : today;
|
|
29267
29267
|
let month = today.getMonth() + 1;
|
|
29268
29268
|
let day = today.getDate();
|
|
@@ -44200,6 +44200,724 @@ async function manpowerEvents(io) {
|
|
|
44200
44200
|
});
|
|
44201
44201
|
});
|
|
44202
44202
|
}
|
|
44203
|
+
|
|
44204
|
+
// src/services/reddot-payment.service.ts
|
|
44205
|
+
import axios3 from "axios";
|
|
44206
|
+
|
|
44207
|
+
// src/utils/payment-signature.util.ts
|
|
44208
|
+
import * as crypto3 from "crypto";
|
|
44209
|
+
function paymentSignature(params, secretKey) {
|
|
44210
|
+
const fieldOrder = ["mid", "order_id", "payment_type", "amount", "ccy", "card_no", "exp_date", "cvv2"];
|
|
44211
|
+
let concatenated = "";
|
|
44212
|
+
fieldOrder.forEach((v) => {
|
|
44213
|
+
if (!params.hasOwnProperty(v)) {
|
|
44214
|
+
return;
|
|
44215
|
+
} else if (v === "cvv2") {
|
|
44216
|
+
concatenated += (params[v] ?? "").toString().slice(-1);
|
|
44217
|
+
} else if (v === "card_no") {
|
|
44218
|
+
concatenated += (params[v] ?? "").substring(0, 6) + (params[v] ?? "").slice(-4);
|
|
44219
|
+
} else {
|
|
44220
|
+
concatenated += params[v];
|
|
44221
|
+
}
|
|
44222
|
+
});
|
|
44223
|
+
concatenated += secretKey;
|
|
44224
|
+
const signature = crypto3.createHash("sha512").update(concatenated).digest("hex");
|
|
44225
|
+
return signature;
|
|
44226
|
+
}
|
|
44227
|
+
function genericSignature(params, secretKey) {
|
|
44228
|
+
const paramsCopy = { ...params };
|
|
44229
|
+
delete paramsCopy["signature"];
|
|
44230
|
+
const sortedParams = Object.keys(paramsCopy).sort().reduce((obj, key) => {
|
|
44231
|
+
obj[key] = paramsCopy[key];
|
|
44232
|
+
return obj;
|
|
44233
|
+
}, {});
|
|
44234
|
+
const concatenated = Object.values(sortedParams).join("") + secretKey;
|
|
44235
|
+
const signature = crypto3.createHash("sha512").update(concatenated).digest("hex");
|
|
44236
|
+
return signature;
|
|
44237
|
+
}
|
|
44238
|
+
|
|
44239
|
+
// src/repositories/reddot-payment.repository.ts
|
|
44240
|
+
import { ObjectId as ObjectId120 } from "mongodb";
|
|
44241
|
+
|
|
44242
|
+
// src/utils/date-format.util.ts
|
|
44243
|
+
import moment6 from "moment-timezone";
|
|
44244
|
+
function formatDateString(today, format, dateRange) {
|
|
44245
|
+
today = typeof today === "string" ? new Date(today) : today;
|
|
44246
|
+
let month = today.getMonth() + 1;
|
|
44247
|
+
let day = today.getDate();
|
|
44248
|
+
let year = today.getFullYear();
|
|
44249
|
+
let formattedDate;
|
|
44250
|
+
if (format === "mm-dd-yyyy") {
|
|
44251
|
+
formattedDate = `${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}-${year}`;
|
|
44252
|
+
} else if (format === "dd-mm-yyyy") {
|
|
44253
|
+
formattedDate = `${day.toString().padStart(2, "0")}-${month.toString().padStart(2, "0")}-${year}`;
|
|
44254
|
+
} else if (format === "for-ref") {
|
|
44255
|
+
formattedDate = `${month.toString().padStart(2, "0")}${day.toString().padStart(2, "0")}${year}`;
|
|
44256
|
+
} else if (format === "mm/dd/yyyy") {
|
|
44257
|
+
formattedDate = `${month.toString().padStart(2, "0")}/${day.toString().padStart(2, "0")}/${year}`;
|
|
44258
|
+
} else {
|
|
44259
|
+
formattedDate = `${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}`;
|
|
44260
|
+
}
|
|
44261
|
+
return formattedDate;
|
|
44262
|
+
}
|
|
44263
|
+
|
|
44264
|
+
// src/models/credit-card.model.ts
|
|
44265
|
+
import { ObjectId as ObjectId117 } from "mongodb";
|
|
44266
|
+
var MCardInfo = class {
|
|
44267
|
+
// this is coming from RDP transaction
|
|
44268
|
+
constructor({
|
|
44269
|
+
_id = new ObjectId117(),
|
|
44270
|
+
userId,
|
|
44271
|
+
cardType,
|
|
44272
|
+
cardNumber,
|
|
44273
|
+
cardId,
|
|
44274
|
+
fullName,
|
|
44275
|
+
expiryDate,
|
|
44276
|
+
cvv,
|
|
44277
|
+
site,
|
|
44278
|
+
siteName,
|
|
44279
|
+
organization,
|
|
44280
|
+
createdBy,
|
|
44281
|
+
createdAt,
|
|
44282
|
+
updatedAt,
|
|
44283
|
+
transaction_id
|
|
44284
|
+
} = {}) {
|
|
44285
|
+
this._id = _id;
|
|
44286
|
+
this.userId = userId;
|
|
44287
|
+
this.cardType = cardType;
|
|
44288
|
+
this.cardNumber = cardNumber;
|
|
44289
|
+
this.cardId = cardId;
|
|
44290
|
+
this.fullName = fullName;
|
|
44291
|
+
this.expiryDate = expiryDate;
|
|
44292
|
+
this.cvv = cvv;
|
|
44293
|
+
this.site = site;
|
|
44294
|
+
this.siteName = siteName;
|
|
44295
|
+
this.organization = organization;
|
|
44296
|
+
this.createdBy = createdBy;
|
|
44297
|
+
this.createdAt = createdAt;
|
|
44298
|
+
this.updatedAt = updatedAt;
|
|
44299
|
+
this.transaction_id = transaction_id;
|
|
44300
|
+
}
|
|
44301
|
+
};
|
|
44302
|
+
|
|
44303
|
+
// src/models/cart.model.ts
|
|
44304
|
+
import { ObjectId as ObjectId118 } from "mongodb";
|
|
44305
|
+
var MUnitBillings = class {
|
|
44306
|
+
// transaction response messages
|
|
44307
|
+
constructor({
|
|
44308
|
+
_id = new ObjectId118(),
|
|
44309
|
+
unit,
|
|
44310
|
+
unitId,
|
|
44311
|
+
unitBill,
|
|
44312
|
+
paymentStatus = "Processing" /* processing */,
|
|
44313
|
+
referenceNumber,
|
|
44314
|
+
amountPaid,
|
|
44315
|
+
paidBy,
|
|
44316
|
+
datePaid,
|
|
44317
|
+
billCategory,
|
|
44318
|
+
billFrom,
|
|
44319
|
+
billTo,
|
|
44320
|
+
site,
|
|
44321
|
+
organization,
|
|
44322
|
+
createdBy,
|
|
44323
|
+
createdAt,
|
|
44324
|
+
updatedAt,
|
|
44325
|
+
message
|
|
44326
|
+
} = {}) {
|
|
44327
|
+
this._id = _id;
|
|
44328
|
+
this.unit = unit;
|
|
44329
|
+
this.unitId = unitId;
|
|
44330
|
+
this.referenceNumber = referenceNumber;
|
|
44331
|
+
this.unitBill = unitBill;
|
|
44332
|
+
this.paymentStatus = paymentStatus;
|
|
44333
|
+
this.amountPaid = amountPaid;
|
|
44334
|
+
this.site = site;
|
|
44335
|
+
this.organization = organization;
|
|
44336
|
+
this.paidBy = paidBy;
|
|
44337
|
+
this.datePaid = datePaid;
|
|
44338
|
+
this.billCategory = billCategory;
|
|
44339
|
+
this.billFrom = billFrom;
|
|
44340
|
+
this.billTo = billTo;
|
|
44341
|
+
this.createdBy = createdBy;
|
|
44342
|
+
this.createdAt = createdAt;
|
|
44343
|
+
this.updatedAt = updatedAt;
|
|
44344
|
+
this.message = message;
|
|
44345
|
+
}
|
|
44346
|
+
};
|
|
44347
|
+
|
|
44348
|
+
// src/repositories/payment.repository.ts
|
|
44349
|
+
import { ObjectId as ObjectId119 } from "mongodb";
|
|
44350
|
+
import {
|
|
44351
|
+
InternalServerError as InternalServerError66,
|
|
44352
|
+
useAtlas as useAtlas109
|
|
44353
|
+
} from "@7365admin1/node-server-utils";
|
|
44354
|
+
var PaymentBillRepo = () => {
|
|
44355
|
+
const getDB = () => {
|
|
44356
|
+
const db = useAtlas109.getDb();
|
|
44357
|
+
if (!db) {
|
|
44358
|
+
throw new InternalServerError66("Unable to connect to server.");
|
|
44359
|
+
}
|
|
44360
|
+
return db;
|
|
44361
|
+
};
|
|
44362
|
+
const collection = () => {
|
|
44363
|
+
return getDB().collection("unit-bill");
|
|
44364
|
+
};
|
|
44365
|
+
const billCollection = () => {
|
|
44366
|
+
return getDB().collection("bill-records");
|
|
44367
|
+
};
|
|
44368
|
+
const creditCollection = () => {
|
|
44369
|
+
return getDB().collection("credit-info");
|
|
44370
|
+
};
|
|
44371
|
+
const cartCollection = () => {
|
|
44372
|
+
return getDB().collection("checkout-cart");
|
|
44373
|
+
};
|
|
44374
|
+
const payUnitBill = async (refId, payload) => {
|
|
44375
|
+
try {
|
|
44376
|
+
if (refId)
|
|
44377
|
+
refId = refId.toString();
|
|
44378
|
+
const unitBillInfo = await collection().findOne({ referenceNumber: refId });
|
|
44379
|
+
const unitBillId = unitBillInfo?._id;
|
|
44380
|
+
if (!unitBillInfo) {
|
|
44381
|
+
throw new Error("Unit bill info not found");
|
|
44382
|
+
}
|
|
44383
|
+
if (unitBillInfo?.status === "Inactive" /* inactive */) {
|
|
44384
|
+
throw new Error("This Bill is Inactive!");
|
|
44385
|
+
}
|
|
44386
|
+
const billId = new ObjectId119(unitBillInfo?.billId);
|
|
44387
|
+
const billInfo = await billCollection().findOne({ _id: billId });
|
|
44388
|
+
if (!billInfo) {
|
|
44389
|
+
throw new Error("Bill info not found");
|
|
44390
|
+
}
|
|
44391
|
+
if (payload.paymentStatus === "Partial Payment" /* partial */ && payload.amountPaid) {
|
|
44392
|
+
const price = parseInt(billInfo?.price);
|
|
44393
|
+
const amount = payload.amountPaid;
|
|
44394
|
+
const numericPrice = typeof price === "string" ? parseInt(price) : price;
|
|
44395
|
+
const numericAmount = typeof amount === "string" ? parseInt(amount) : amount;
|
|
44396
|
+
if (typeof amount !== "number") {
|
|
44397
|
+
throw new Error("Amount is not a valid number");
|
|
44398
|
+
} else if (typeof price !== "number") {
|
|
44399
|
+
throw new Error("Price s not a valid number");
|
|
44400
|
+
}
|
|
44401
|
+
payload.balance = numericPrice - numericAmount;
|
|
44402
|
+
} else if (payload.paymentStatus === "Paid" /* paid */ && payload.amountPaid) {
|
|
44403
|
+
payload.datePaid = /* @__PURE__ */ new Date();
|
|
44404
|
+
payload.paymentStatus = "Paid" /* paid */;
|
|
44405
|
+
payload.amountPaid;
|
|
44406
|
+
payload.transaction_id;
|
|
44407
|
+
} else if (payload.paymentStatus === "Failed" /* failed */) {
|
|
44408
|
+
payload.amountPaid = 0;
|
|
44409
|
+
payload.paidBy = "";
|
|
44410
|
+
payload.datePaid = "";
|
|
44411
|
+
payload.paymentStatus = "Failed" /* failed */;
|
|
44412
|
+
payload.transaction_id;
|
|
44413
|
+
}
|
|
44414
|
+
const updatedAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
44415
|
+
payload.updatedAt = updatedAt;
|
|
44416
|
+
const result = await collection().findOneAndUpdate({ _id: unitBillId }, { $set: payload }, { returnDocument: "after" });
|
|
44417
|
+
return result;
|
|
44418
|
+
} catch (error) {
|
|
44419
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44420
|
+
}
|
|
44421
|
+
};
|
|
44422
|
+
const saveCreditCardInfo = async (payload) => {
|
|
44423
|
+
try {
|
|
44424
|
+
if (payload.userId)
|
|
44425
|
+
payload.userId = new ObjectId119(payload.userId);
|
|
44426
|
+
if (payload.site)
|
|
44427
|
+
payload.site = new ObjectId119(payload.site);
|
|
44428
|
+
if (payload.organization)
|
|
44429
|
+
payload.organization = new ObjectId119(payload.organization);
|
|
44430
|
+
if (payload.createdBy)
|
|
44431
|
+
payload.createdBy = new ObjectId119(payload.createdBy);
|
|
44432
|
+
const createdAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
44433
|
+
payload.createdAt = createdAt;
|
|
44434
|
+
const result = await creditCollection().insertOne(new MCardInfo(payload));
|
|
44435
|
+
return result;
|
|
44436
|
+
} catch (error) {
|
|
44437
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44438
|
+
}
|
|
44439
|
+
};
|
|
44440
|
+
const checkOutUnitBills = async (payload) => {
|
|
44441
|
+
try {
|
|
44442
|
+
if (payload.unitId)
|
|
44443
|
+
payload.unitId = new ObjectId119(payload.unitId);
|
|
44444
|
+
if (payload.site)
|
|
44445
|
+
payload.site = new ObjectId119(payload.site);
|
|
44446
|
+
if (payload.organization)
|
|
44447
|
+
payload.organization = new ObjectId119(payload.organization);
|
|
44448
|
+
payload.createdAt = await formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
44449
|
+
const addToCart = await cartCollection().insertOne(new MUnitBillings(payload));
|
|
44450
|
+
const unitId = payload.unitId;
|
|
44451
|
+
const dateFormatted = formatDateString(/* @__PURE__ */ new Date(), "for-ref");
|
|
44452
|
+
const unit = unitId?.toString().slice(-4);
|
|
44453
|
+
const newId = new ObjectId119(addToCart?.insertedId).toString().slice(-4);
|
|
44454
|
+
const referenceNumber = `CRT${unit}${newId}${dateFormatted}`;
|
|
44455
|
+
const result = await cartCollection().findOneAndUpdate({ _id: new ObjectId119(addToCart.insertedId) }, { $set: { referenceNumber } }, { returnDocument: "after" });
|
|
44456
|
+
return result;
|
|
44457
|
+
} catch (error) {
|
|
44458
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44459
|
+
}
|
|
44460
|
+
};
|
|
44461
|
+
const payUnitCart = async (refId, payload) => {
|
|
44462
|
+
try {
|
|
44463
|
+
if (refId)
|
|
44464
|
+
refId = refId.toString();
|
|
44465
|
+
const updatedAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
44466
|
+
const cartInfo = await cartCollection().findOne({ referenceNumber: refId });
|
|
44467
|
+
const refNumber = cartInfo?.unitBill;
|
|
44468
|
+
if (payload.paymentStatus === "Paid" /* paid */ && payload.amountPaid) {
|
|
44469
|
+
payload.datePaid = /* @__PURE__ */ new Date();
|
|
44470
|
+
payload.paymentStatus = "Paid" /* paid */;
|
|
44471
|
+
payload.amountPaid;
|
|
44472
|
+
} else if (payload.paymentStatus === "Failed" /* failed */) {
|
|
44473
|
+
payload.amountPaid = 0;
|
|
44474
|
+
payload.paidBy = "";
|
|
44475
|
+
payload.datePaid = "";
|
|
44476
|
+
payload.paymentStatus = "Failed" /* failed */;
|
|
44477
|
+
}
|
|
44478
|
+
payload.updatedAt = updatedAt;
|
|
44479
|
+
const result = await cartCollection().findOneAndUpdate({ referenceNumber: refId }, { $set: payload }, { returnDocument: "after" });
|
|
44480
|
+
if (!result) {
|
|
44481
|
+
throw new Error("Failed to Process Transaction. Please Try Again Later");
|
|
44482
|
+
} else {
|
|
44483
|
+
for (const ref of refNumber) {
|
|
44484
|
+
const unitBillInfo = await collection().findOne({ referenceNumber: ref });
|
|
44485
|
+
const billId = unitBillInfo?.billId;
|
|
44486
|
+
const billInfo = await billCollection().findOne({ _id: new ObjectId119(billId) });
|
|
44487
|
+
const billAmount = billInfo?.price;
|
|
44488
|
+
payload.updatedAt = updatedAt;
|
|
44489
|
+
payload.amountPaid = billAmount;
|
|
44490
|
+
const eachRef = await payUnitBill(ref, payload);
|
|
44491
|
+
}
|
|
44492
|
+
if (!cartInfo) {
|
|
44493
|
+
throw new Error("Cart info not found");
|
|
44494
|
+
}
|
|
44495
|
+
}
|
|
44496
|
+
return result;
|
|
44497
|
+
} catch (error) {
|
|
44498
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44499
|
+
}
|
|
44500
|
+
};
|
|
44501
|
+
const getCheckedOutBillings = async (refId) => {
|
|
44502
|
+
try {
|
|
44503
|
+
if (refId)
|
|
44504
|
+
refId = refId.toString();
|
|
44505
|
+
const result = await cartCollection().aggregate([
|
|
44506
|
+
{ $match: { referenceNumber: refId } },
|
|
44507
|
+
{
|
|
44508
|
+
$lookup: {
|
|
44509
|
+
from: "unit-bill",
|
|
44510
|
+
localField: "unitBill",
|
|
44511
|
+
foreignField: "referenceNumber",
|
|
44512
|
+
as: "unitBill"
|
|
44513
|
+
}
|
|
44514
|
+
},
|
|
44515
|
+
{
|
|
44516
|
+
$unwind: "$unitBill"
|
|
44517
|
+
},
|
|
44518
|
+
{
|
|
44519
|
+
$lookup: {
|
|
44520
|
+
from: "bill-records",
|
|
44521
|
+
localField: "unitBill.billId",
|
|
44522
|
+
foreignField: "_id",
|
|
44523
|
+
as: "billDetails"
|
|
44524
|
+
}
|
|
44525
|
+
},
|
|
44526
|
+
{
|
|
44527
|
+
$unwind: {
|
|
44528
|
+
path: "$billDetails",
|
|
44529
|
+
preserveNullAndEmptyArrays: true
|
|
44530
|
+
}
|
|
44531
|
+
},
|
|
44532
|
+
{
|
|
44533
|
+
$addFields: {
|
|
44534
|
+
"unitBill.billItemName": "$billDetails.billItem"
|
|
44535
|
+
}
|
|
44536
|
+
},
|
|
44537
|
+
{
|
|
44538
|
+
$project: {
|
|
44539
|
+
"unitBill.paidBy": 0,
|
|
44540
|
+
"unitBill.preDueDateAlert": 0,
|
|
44541
|
+
"unitBill.category": 0,
|
|
44542
|
+
"unitBill.contactNumber": 0,
|
|
44543
|
+
"unitBill.email": 0,
|
|
44544
|
+
"unitBill.site": 0,
|
|
44545
|
+
"unitBill.siteName": 0,
|
|
44546
|
+
"unitBill.organization": 0,
|
|
44547
|
+
"unitBill.billStatus": 0,
|
|
44548
|
+
"unitBill.createdBy": 0,
|
|
44549
|
+
"unitBill.createdAt": 0,
|
|
44550
|
+
"unitBill.updatedAt": 0,
|
|
44551
|
+
"billDetails": 0
|
|
44552
|
+
// Exclude the full billDetails as it's no longer needed
|
|
44553
|
+
}
|
|
44554
|
+
},
|
|
44555
|
+
{
|
|
44556
|
+
$group: {
|
|
44557
|
+
_id: "$_id",
|
|
44558
|
+
unitId: { $first: "$unitId" },
|
|
44559
|
+
referenceNumber: { $first: "$referenceNumber" },
|
|
44560
|
+
unitBill: { $push: "$unitBill" },
|
|
44561
|
+
paymentStatus: { $first: "$paymentStatus" },
|
|
44562
|
+
amountPaid: { $first: "$amountPaid" },
|
|
44563
|
+
site: { $first: "$site" },
|
|
44564
|
+
organization: { $first: "$organization" },
|
|
44565
|
+
paidBy: { $first: "$paidBy" },
|
|
44566
|
+
datePaid: { $first: "$referenceNumber" },
|
|
44567
|
+
billCategory: { $first: "$billCategory" },
|
|
44568
|
+
billFrom: { $first: "$billFrom" },
|
|
44569
|
+
billTo: { $first: "$billTo" },
|
|
44570
|
+
createdBy: { $first: "$createdBy" },
|
|
44571
|
+
createdAt: { $first: "$createdAt" },
|
|
44572
|
+
updatedAt: { $first: "$updatedAt" },
|
|
44573
|
+
transaction_id: { $first: "$transaction_id" }
|
|
44574
|
+
}
|
|
44575
|
+
}
|
|
44576
|
+
]).toArray();
|
|
44577
|
+
if (!result || result.length === 0) {
|
|
44578
|
+
return { success: false, message: "Cart Info Not Found" };
|
|
44579
|
+
}
|
|
44580
|
+
return result[0];
|
|
44581
|
+
} catch (error) {
|
|
44582
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44583
|
+
}
|
|
44584
|
+
};
|
|
44585
|
+
const cancelCheckedOutBillings = async (refId) => {
|
|
44586
|
+
try {
|
|
44587
|
+
if (refId)
|
|
44588
|
+
refId = refId.toString();
|
|
44589
|
+
const result = await cartCollection().findOneAndDelete({ referenceNumber: refId });
|
|
44590
|
+
if (!result) {
|
|
44591
|
+
return { success: false, message: "Cart Info Not Found" };
|
|
44592
|
+
}
|
|
44593
|
+
return { success: true, message: "Cart Deleted Successfully!", referenceNumber: result?.referenceNumber };
|
|
44594
|
+
} catch (error) {
|
|
44595
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44596
|
+
}
|
|
44597
|
+
};
|
|
44598
|
+
return {
|
|
44599
|
+
saveCreditCardInfo,
|
|
44600
|
+
checkOutUnitBills,
|
|
44601
|
+
payUnitBill,
|
|
44602
|
+
payUnitCart,
|
|
44603
|
+
getCheckedOutBillings,
|
|
44604
|
+
cancelCheckedOutBillings
|
|
44605
|
+
};
|
|
44606
|
+
};
|
|
44607
|
+
|
|
44608
|
+
// src/repositories/reddot-payment.repository.ts
|
|
44609
|
+
import {
|
|
44610
|
+
InternalServerError as InternalServerError67,
|
|
44611
|
+
useAtlas as useAtlas110
|
|
44612
|
+
} from "@7365admin1/node-server-utils";
|
|
44613
|
+
var useRedDotPaymentRepo = () => {
|
|
44614
|
+
const getDB = () => {
|
|
44615
|
+
const db = useAtlas110.getDb();
|
|
44616
|
+
if (!db) {
|
|
44617
|
+
throw new InternalServerError67("Unable to connect to server.");
|
|
44618
|
+
}
|
|
44619
|
+
return db;
|
|
44620
|
+
};
|
|
44621
|
+
const collection = () => {
|
|
44622
|
+
return getDB().collection("unit-bill");
|
|
44623
|
+
};
|
|
44624
|
+
const orgCollection = () => {
|
|
44625
|
+
return getDB().collection("organizations");
|
|
44626
|
+
};
|
|
44627
|
+
const cartCollection = () => {
|
|
44628
|
+
return getDB().collection("checkout-cart");
|
|
44629
|
+
};
|
|
44630
|
+
const redDotMerchantCollection = () => {
|
|
44631
|
+
return getDB().collection("reddot-merchant");
|
|
44632
|
+
};
|
|
44633
|
+
const createRedDotAccount = async (_id, payload) => {
|
|
44634
|
+
try {
|
|
44635
|
+
const merchant = await redDotMerchantCollection().insertOne(payload);
|
|
44636
|
+
if (!merchant) {
|
|
44637
|
+
throw new Error("Failed to Add Merchant Details");
|
|
44638
|
+
}
|
|
44639
|
+
const merchantId = merchant?.insertedId;
|
|
44640
|
+
const orgId = new ObjectId120(_id);
|
|
44641
|
+
const result = await orgCollection().findOneAndUpdate({ _id: orgId }, { $push: { merchant: merchantId } }, {
|
|
44642
|
+
returnDocument: "after"
|
|
44643
|
+
});
|
|
44644
|
+
if (!result) {
|
|
44645
|
+
throw new Error("Organization not found");
|
|
44646
|
+
}
|
|
44647
|
+
return {
|
|
44648
|
+
success: true,
|
|
44649
|
+
message: "Merchant Details successfully added."
|
|
44650
|
+
};
|
|
44651
|
+
} catch (error) {
|
|
44652
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44653
|
+
}
|
|
44654
|
+
};
|
|
44655
|
+
const payUnitBillings = async (refId, payload) => {
|
|
44656
|
+
const checkCart = await cartCollection().findOne({ referenceNumber: refId });
|
|
44657
|
+
if (checkCart) {
|
|
44658
|
+
const multiple = await PaymentBillRepo().payUnitCart(refId, payload);
|
|
44659
|
+
if (multiple) {
|
|
44660
|
+
return await PaymentBillRepo().getCheckedOutBillings(refId);
|
|
44661
|
+
}
|
|
44662
|
+
}
|
|
44663
|
+
const single = await PaymentBillRepo().payUnitBill(refId, payload);
|
|
44664
|
+
return single;
|
|
44665
|
+
};
|
|
44666
|
+
const getMerchantDetailsById = async (_id) => {
|
|
44667
|
+
try {
|
|
44668
|
+
if (_id)
|
|
44669
|
+
_id = new ObjectId120(_id);
|
|
44670
|
+
const result = await redDotMerchantCollection().aggregate([
|
|
44671
|
+
{
|
|
44672
|
+
$match: {
|
|
44673
|
+
_id
|
|
44674
|
+
}
|
|
44675
|
+
},
|
|
44676
|
+
{
|
|
44677
|
+
$facet: {
|
|
44678
|
+
totalCount: [{ $count: "count" }],
|
|
44679
|
+
items: [{ $sort: { _id: -1 } }]
|
|
44680
|
+
}
|
|
44681
|
+
}
|
|
44682
|
+
]).toArray();
|
|
44683
|
+
const items = result[0].items;
|
|
44684
|
+
return items;
|
|
44685
|
+
} catch (error) {
|
|
44686
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44687
|
+
}
|
|
44688
|
+
};
|
|
44689
|
+
return {
|
|
44690
|
+
createRedDotAccount,
|
|
44691
|
+
payUnitBillings,
|
|
44692
|
+
getMerchantDetailsById
|
|
44693
|
+
};
|
|
44694
|
+
};
|
|
44695
|
+
|
|
44696
|
+
// src/services/reddot-payment.service.ts
|
|
44697
|
+
var useRedDotPaymentSvc = () => {
|
|
44698
|
+
const createRedDotAccount = async (_id, payload) => {
|
|
44699
|
+
return useRedDotPaymentRepo().createRedDotAccount(_id, payload);
|
|
44700
|
+
};
|
|
44701
|
+
const redirectPaymentTransaction = async (payload) => {
|
|
44702
|
+
try {
|
|
44703
|
+
const SECRET_KEY2 = payload.merchant_key;
|
|
44704
|
+
if (!payload.mid && !payload.merchant_key) {
|
|
44705
|
+
return { success: false, message: "RDP Not Available on this account. Please Contact Management" };
|
|
44706
|
+
}
|
|
44707
|
+
const data = {
|
|
44708
|
+
mid: payload.mid,
|
|
44709
|
+
api_mode: "redirection_hosted",
|
|
44710
|
+
payment_type: "S",
|
|
44711
|
+
order_id: payload.order_id,
|
|
44712
|
+
ccy: "SGD",
|
|
44713
|
+
amount: payload.amount,
|
|
44714
|
+
back_url: payload.back_url,
|
|
44715
|
+
redirect_url: payload.redirect_url,
|
|
44716
|
+
notify_url: payload.notify_url
|
|
44717
|
+
};
|
|
44718
|
+
if (!SECRET_KEY2) {
|
|
44719
|
+
throw new Error("Merchant key is required but was not provided.");
|
|
44720
|
+
}
|
|
44721
|
+
data["signature"] = paymentSignature(data, SECRET_KEY2);
|
|
44722
|
+
const dataString = JSON.stringify(data);
|
|
44723
|
+
const headers = {
|
|
44724
|
+
"Content-Type": "application/json",
|
|
44725
|
+
"Content-Length": String(dataString.length)
|
|
44726
|
+
};
|
|
44727
|
+
if (!process.env.MERCHANT_PAYMENT) {
|
|
44728
|
+
throw new Error("MERCHANT_PAYMENT environment variable is not defined.");
|
|
44729
|
+
}
|
|
44730
|
+
const url = process.env.MERCHANT_PAYMENT;
|
|
44731
|
+
const response = await axios3.post(url, dataString, { headers });
|
|
44732
|
+
const result = response.data;
|
|
44733
|
+
return result;
|
|
44734
|
+
} catch (error) {
|
|
44735
|
+
return Promise.reject(error || error.message || "Server Internal Error!");
|
|
44736
|
+
}
|
|
44737
|
+
};
|
|
44738
|
+
const enquirePaymentTransaction = async (payload) => {
|
|
44739
|
+
try {
|
|
44740
|
+
const SECRET_KEY2 = payload.merchant_key;
|
|
44741
|
+
if (!payload.request_mid && !payload.merchant_key) {
|
|
44742
|
+
return { success: false, message: "RDP Not Available on this account. Please Contact Management" };
|
|
44743
|
+
}
|
|
44744
|
+
const data = {
|
|
44745
|
+
request_mid: payload.request_mid,
|
|
44746
|
+
transaction_id: payload.transaction_id
|
|
44747
|
+
};
|
|
44748
|
+
if (!SECRET_KEY2) {
|
|
44749
|
+
throw new Error("Merchant key is required but was not provided.");
|
|
44750
|
+
}
|
|
44751
|
+
data["signature"] = genericSignature(data, SECRET_KEY2);
|
|
44752
|
+
const dataString = JSON.stringify(data);
|
|
44753
|
+
const headers = {
|
|
44754
|
+
"Content-Type": "application/json"
|
|
44755
|
+
};
|
|
44756
|
+
if (!process.env.MERCHANT_ENQUIRY) {
|
|
44757
|
+
throw new Error("MERCHANT_PAYMENT environment variable is not defined.");
|
|
44758
|
+
}
|
|
44759
|
+
const url = process.env.MERCHANT_ENQUIRY;
|
|
44760
|
+
const response = await axios3.post(url, dataString, { headers });
|
|
44761
|
+
const result = response.data;
|
|
44762
|
+
const transactionId = result.transaction_id;
|
|
44763
|
+
const amount = result.request_amount || 0;
|
|
44764
|
+
const payer = result.payer_name || "";
|
|
44765
|
+
const refId = result.order_id;
|
|
44766
|
+
const message = result.response_msg;
|
|
44767
|
+
const invoiceDate = /* @__PURE__ */ new Date();
|
|
44768
|
+
if (result.response_code === "0") {
|
|
44769
|
+
const success = {
|
|
44770
|
+
method: payload.method,
|
|
44771
|
+
paymentStatus: "Paid" /* paid */,
|
|
44772
|
+
amountPaid: amount,
|
|
44773
|
+
paidBy: payer,
|
|
44774
|
+
updatedAt: invoiceDate,
|
|
44775
|
+
transaction_id: transactionId,
|
|
44776
|
+
message
|
|
44777
|
+
};
|
|
44778
|
+
await useRedDotPaymentRepo().payUnitBillings(refId, success);
|
|
44779
|
+
} else if (result.response_code !== "0") {
|
|
44780
|
+
const fail = {
|
|
44781
|
+
method: payload.method,
|
|
44782
|
+
paymentStatus: "Failed" /* failed */,
|
|
44783
|
+
updatedAt: invoiceDate,
|
|
44784
|
+
paidBy: "",
|
|
44785
|
+
amountPaid: "0",
|
|
44786
|
+
transaction_id: transactionId,
|
|
44787
|
+
message
|
|
44788
|
+
};
|
|
44789
|
+
await useRedDotPaymentRepo().payUnitBillings(refId, fail);
|
|
44790
|
+
}
|
|
44791
|
+
return result;
|
|
44792
|
+
} catch (error) {
|
|
44793
|
+
return Promise.reject(error || error.message || "Server Internal Error!");
|
|
44794
|
+
}
|
|
44795
|
+
};
|
|
44796
|
+
const payInvoice = async (payload) => {
|
|
44797
|
+
try {
|
|
44798
|
+
const data = {
|
|
44799
|
+
cardNumber: payload.cardNumber,
|
|
44800
|
+
rdpMid: payload.rdpMid,
|
|
44801
|
+
orderId: payload.orderId
|
|
44802
|
+
};
|
|
44803
|
+
const dataString = JSON.stringify(data);
|
|
44804
|
+
const headers = {
|
|
44805
|
+
"Content-Type": "application/json",
|
|
44806
|
+
"Content-Length": String(dataString.length)
|
|
44807
|
+
};
|
|
44808
|
+
if (!process.env.MERCHANT_PAYMENT) {
|
|
44809
|
+
throw new Error("MERCHANT_PAYMENT environment variable is not defined.");
|
|
44810
|
+
}
|
|
44811
|
+
const url = process.env.MERCHANT_PAYMENT;
|
|
44812
|
+
const response = await axios3.post(url, dataString, { headers });
|
|
44813
|
+
return response;
|
|
44814
|
+
} catch (error) {
|
|
44815
|
+
return Promise.reject(error || error.message || "Server Internal Error!");
|
|
44816
|
+
}
|
|
44817
|
+
};
|
|
44818
|
+
const getMerchantDetailsById = async (_id) => {
|
|
44819
|
+
return useRedDotPaymentRepo().getMerchantDetailsById(_id);
|
|
44820
|
+
};
|
|
44821
|
+
return {
|
|
44822
|
+
createRedDotAccount,
|
|
44823
|
+
redirectPaymentTransaction,
|
|
44824
|
+
enquirePaymentTransaction,
|
|
44825
|
+
payInvoice,
|
|
44826
|
+
getMerchantDetailsById
|
|
44827
|
+
};
|
|
44828
|
+
};
|
|
44829
|
+
|
|
44830
|
+
// src/controllers/reddot-payment.controller.ts
|
|
44831
|
+
import Joi124 from "joi";
|
|
44832
|
+
function useRedDotPaymentController() {
|
|
44833
|
+
const createRedDotAccount = async (req, res) => {
|
|
44834
|
+
try {
|
|
44835
|
+
const data = req.body;
|
|
44836
|
+
const id = req.params.id;
|
|
44837
|
+
const schema2 = Joi124.object({
|
|
44838
|
+
id: Joi124.string().hex().required(),
|
|
44839
|
+
// organization id
|
|
44840
|
+
paymentMethod: Joi124.string().required(),
|
|
44841
|
+
// payment method (e.g. "Visa / Mastercard / PayNow QR Code")
|
|
44842
|
+
merchant_id: Joi124.string().required(),
|
|
44843
|
+
// merchant id
|
|
44844
|
+
merchant_key: Joi124.string().required()
|
|
44845
|
+
// secret key
|
|
44846
|
+
});
|
|
44847
|
+
const { error } = schema2.validate({ id, ...data });
|
|
44848
|
+
if (error) {
|
|
44849
|
+
return res.status(400).json({ data: null, message: error.message });
|
|
44850
|
+
}
|
|
44851
|
+
const result = await useRedDotPaymentSvc().createRedDotAccount(id, data);
|
|
44852
|
+
return res.json(result);
|
|
44853
|
+
} catch (error) {
|
|
44854
|
+
return res.status(500).json({ message: error.message || error });
|
|
44855
|
+
}
|
|
44856
|
+
};
|
|
44857
|
+
const redirectPaymentTransaction = async (req, res) => {
|
|
44858
|
+
try {
|
|
44859
|
+
const data = req.body;
|
|
44860
|
+
const schema2 = Joi124.object({
|
|
44861
|
+
mid: Joi124.string().optional().allow("", null),
|
|
44862
|
+
order_id: Joi124.string().required(),
|
|
44863
|
+
amount: Joi124.number().required(),
|
|
44864
|
+
merchant_key: Joi124.string().required(),
|
|
44865
|
+
back_url: Joi124.string().required(),
|
|
44866
|
+
redirect_url: Joi124.string().required(),
|
|
44867
|
+
notify_url: Joi124.string().required()
|
|
44868
|
+
});
|
|
44869
|
+
const { error } = schema2.validate({ ...data });
|
|
44870
|
+
if (error) {
|
|
44871
|
+
return res.status(400).json({ data: null, message: error.message });
|
|
44872
|
+
}
|
|
44873
|
+
const result = await useRedDotPaymentSvc().redirectPaymentTransaction(data);
|
|
44874
|
+
return res.json(result);
|
|
44875
|
+
} catch (error) {
|
|
44876
|
+
return res.status(500).json({ message: error.message || error });
|
|
44877
|
+
}
|
|
44878
|
+
};
|
|
44879
|
+
const enquirePaymentTransaction = async (req, res) => {
|
|
44880
|
+
try {
|
|
44881
|
+
const data = req.body;
|
|
44882
|
+
const schema2 = Joi124.object({
|
|
44883
|
+
request_mid: Joi124.string().optional().allow("", null),
|
|
44884
|
+
transaction_id: Joi124.string().required(),
|
|
44885
|
+
merchant_key: Joi124.string().optional().allow("", null),
|
|
44886
|
+
method: Joi124.string().optional().allow("", null)
|
|
44887
|
+
});
|
|
44888
|
+
const { error } = schema2.validate({ ...data });
|
|
44889
|
+
if (error) {
|
|
44890
|
+
return res.status(400).json({ data: null, message: error.message });
|
|
44891
|
+
}
|
|
44892
|
+
const result = await useRedDotPaymentSvc().enquirePaymentTransaction(data);
|
|
44893
|
+
return res.json(result);
|
|
44894
|
+
} catch (error) {
|
|
44895
|
+
return res.status(500).json({ message: error.message || error });
|
|
44896
|
+
}
|
|
44897
|
+
};
|
|
44898
|
+
const getMerchantDetailsById = async (req, res, next) => {
|
|
44899
|
+
try {
|
|
44900
|
+
const _id = req.params.id;
|
|
44901
|
+
const schema2 = Joi124.object({
|
|
44902
|
+
_id: Joi124.string().hex().required()
|
|
44903
|
+
});
|
|
44904
|
+
const { error } = schema2.validate({ _id });
|
|
44905
|
+
if (error) {
|
|
44906
|
+
return res.status(400).json({ data: null, message: error.message });
|
|
44907
|
+
}
|
|
44908
|
+
const result = await useRedDotPaymentSvc().getMerchantDetailsById(_id);
|
|
44909
|
+
return res.json(result);
|
|
44910
|
+
} catch (error) {
|
|
44911
|
+
next(error);
|
|
44912
|
+
}
|
|
44913
|
+
};
|
|
44914
|
+
return {
|
|
44915
|
+
createRedDotAccount,
|
|
44916
|
+
redirectPaymentTransaction,
|
|
44917
|
+
enquirePaymentTransaction,
|
|
44918
|
+
getMerchantDetailsById
|
|
44919
|
+
};
|
|
44920
|
+
}
|
|
44203
44921
|
export {
|
|
44204
44922
|
ANPRMode,
|
|
44205
44923
|
AccessTypeProps,
|
|
@@ -44526,6 +45244,9 @@ export {
|
|
|
44526
45244
|
usePriceRepo,
|
|
44527
45245
|
usePromoCodeController,
|
|
44528
45246
|
usePromoCodeRepo,
|
|
45247
|
+
useRedDotPaymentController,
|
|
45248
|
+
useRedDotPaymentRepo,
|
|
45249
|
+
useRedDotPaymentSvc,
|
|
44529
45250
|
useRobotController,
|
|
44530
45251
|
useRobotRepo,
|
|
44531
45252
|
useRobotService,
|