@7365admin1/core 3.32.2-staging.37 → 3.32.2-staging.38

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/index.d.ts CHANGED
@@ -6874,6 +6874,7 @@ declare function useRedDotPaymentController(): {
6874
6874
  redirectPaymentTransaction: (req: Request, res: Response) => Promise<Response<any, Record<string, any>>>;
6875
6875
  enquirePaymentTransaction: (req: Request, res: Response) => Promise<Response<any, Record<string, any>>>;
6876
6876
  createPayment: (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
6877
+ getPaymentByReference: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6877
6878
  updateStatus: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6878
6879
  };
6879
6880
 
@@ -6934,6 +6935,8 @@ type TBillingPayments = {
6934
6935
  };
6935
6936
 
6936
6937
  declare const useRedDotPaymentRepo: () => {
6938
+ createIndexes: () => Promise<void>;
6939
+ getPaymentByReference: (referenceNumber: string, session?: ClientSession) => Promise<TBillingPayments>;
6937
6940
  paySingleUnitBill: (refId: string, payload: Partial<TUnitBilling>) => Promise<mongodb.WithId<bson.Document> | null>;
6938
6941
  createPayment: (type: string, payload: Partial<TBillingPayments>, session?: ClientSession) => Promise<string | undefined>;
6939
6942
  payMultipleUnitBill: (refId: string[], payload: Partial<TUnitBilling>) => Promise<{
package/dist/index.js CHANGED
@@ -64766,6 +64766,54 @@ var useRedDotPaymentRepo = () => {
64766
64766
  const redDotMerchantCollection = () => {
64767
64767
  return getDB2().collection("payment-gateways");
64768
64768
  };
64769
+ async function createIndexes() {
64770
+ try {
64771
+ await paymentCollection().createIndexes([
64772
+ // A referenceNumber-prefixed compound index serves both the lookup by
64773
+ // reference alone and the { referenceNumber, status } lookups used by
64774
+ // the pay single / pay multiple flows.
64775
+ {
64776
+ key: { referenceNumber: 1, status: 1 },
64777
+ name: "referenceNumber_1_status_1"
64778
+ }
64779
+ ]);
64780
+ } catch (error) {
64781
+ import_node_server_utils224.logger.log({
64782
+ level: "error",
64783
+ message: error.message
64784
+ });
64785
+ throw new import_node_server_utils224.InternalServerError(
64786
+ "Failed to create index on billing payments."
64787
+ );
64788
+ }
64789
+ }
64790
+ async function getPaymentByReference(referenceNumber, session) {
64791
+ const reference = typeof referenceNumber === "string" ? referenceNumber.trim() : "";
64792
+ if (!reference) {
64793
+ throw new import_node_server_utils224.BadRequestError("Reference number is required.");
64794
+ }
64795
+ try {
64796
+ const payment = await paymentCollection().findOne(
64797
+ {
64798
+ referenceNumber: reference
64799
+ },
64800
+ { session }
64801
+ );
64802
+ if (!payment) {
64803
+ throw new import_node_server_utils224.NotFoundError("Payment not found.");
64804
+ }
64805
+ return payment;
64806
+ } catch (error) {
64807
+ if (error instanceof import_node_server_utils224.AppError) {
64808
+ throw error;
64809
+ }
64810
+ import_node_server_utils224.logger.log({
64811
+ level: "error",
64812
+ message: error.message
64813
+ });
64814
+ throw new import_node_server_utils224.InternalServerError("Failed to get payment.");
64815
+ }
64816
+ }
64769
64817
  async function createPayment(type, payload, session) {
64770
64818
  if (type == "single") {
64771
64819
  try {
@@ -65011,7 +65059,14 @@ var useRedDotPaymentRepo = () => {
65011
65059
  const formattedDate = `${month.toString().padStart(2, "0")}${day.toString().padStart(2, "0")}${year}`;
65012
65060
  return formattedDate;
65013
65061
  }
65014
- return { paySingleUnitBill, createPayment, payMultipleUnitBill, updateStatus };
65062
+ return {
65063
+ createIndexes,
65064
+ getPaymentByReference,
65065
+ paySingleUnitBill,
65066
+ createPayment,
65067
+ payMultipleUnitBill,
65068
+ updateStatus
65069
+ };
65015
65070
  };
65016
65071
 
65017
65072
  // src/services/reddot-payment.service.ts
@@ -65155,7 +65210,7 @@ var useRedDotPaymentSvc = () => {
65155
65210
  var import_joi127 = __toESM(require("joi"));
65156
65211
  var import_node_server_utils226 = require("@7365admin1/node-server-utils");
65157
65212
  function useRedDotPaymentController() {
65158
- const { createPayment: _createPayment, updateStatus: _updateStatus } = useRedDotPaymentRepo();
65213
+ const { createPayment: _createPayment, updateStatus: _updateStatus, getPaymentByReference: _getPaymentByReference } = useRedDotPaymentRepo();
65159
65214
  const redirectPaymentTransaction = async (req, res) => {
65160
65215
  try {
65161
65216
  const data = req.body;
@@ -65251,10 +65306,28 @@ function useRedDotPaymentController() {
65251
65306
  return;
65252
65307
  }
65253
65308
  }
65309
+ async function getPaymentByReference(req, res, next) {
65310
+ const schema2 = import_joi127.default.object({
65311
+ referenceNumber: import_joi127.default.string().required()
65312
+ });
65313
+ const { error, value } = schema2.validate(req.params);
65314
+ if (error) {
65315
+ next(new import_node_server_utils226.BadRequestError(error.message));
65316
+ return;
65317
+ }
65318
+ try {
65319
+ const payment = await _getPaymentByReference(value.referenceNumber);
65320
+ res.json({ data: payment });
65321
+ return;
65322
+ } catch (error2) {
65323
+ next(error2);
65324
+ }
65325
+ }
65254
65326
  return {
65255
65327
  redirectPaymentTransaction,
65256
65328
  enquirePaymentTransaction,
65257
65329
  createPayment,
65330
+ getPaymentByReference,
65258
65331
  updateStatus
65259
65332
  };
65260
65333
  }