@shushed/helpers 0.0.291 → 0.0.292

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.
@@ -938,60 +938,48 @@ function transformMasterOrder(payload) {
938
938
  const flat = [...cardPays, ...normalPays];
939
939
  const groupsMap = new Map();
940
940
  flat.forEach((p) => {
941
- try {
942
- const isRefund = String(p.type || '').toLowerCase() === 'refund';
943
- const logicalType = isRefund ? 'REFUND' : 'CHARGE';
944
- let keyBase;
945
- const unifiedId = p.transaction_id || p.payment_gateway_token;
946
- if (unifiedId) {
947
- keyBase = unifiedId;
941
+ const isRefund = String(p.type || '').toLowerCase() === 'refund';
942
+ const logicalType = isRefund ? 'REFUND' : 'CHARGE';
943
+ let keyBase;
944
+ const unifiedId = p.transaction_id || p.payment_gateway_token;
945
+ if (unifiedId) {
946
+ keyBase = unifiedId;
947
+ }
948
+ else if (p.payment_number) {
949
+ keyBase = `PN:${p.payment_number}`;
950
+ }
951
+ else if (!isRefund) {
952
+ const paymentType = String(p.type || '').toUpperCase();
953
+ const amount = Number(p.amount || 0);
954
+ const paymentMethod = String(p.payment_method_code || '').toUpperCase().trim();
955
+ const orderNo = p.order_no || erp_order_id;
956
+ if (paymentType === 'CAPTURE' || paymentType === 'AUTHORISATION') {
957
+ keyBase = `CHARGE-${orderNo}-${amount}-${paymentMethod}`;
948
958
  }
949
- else if (p.payment_number) {
950
- keyBase = `PN:${p.payment_number}`;
959
+ else if (p.gift_certificate_id) {
960
+ keyBase = `GIFT:${p.gift_certificate_id}`;
951
961
  }
952
- else if (!isRefund) {
953
- const paymentType = String(p.type || '').toUpperCase();
954
- const amount = Number(p.amount || 0);
955
- const paymentMethod = String(p.payment_method_code || '').toUpperCase().trim();
962
+ else {
956
963
  const orderNo = p.order_no || erp_order_id;
957
- if (paymentType === 'CAPTURE' || paymentType === 'AUTHORISATION') {
958
- keyBase = `CHARGE-${orderNo}-${amount}-${paymentMethod}`;
959
- }
960
- else if (p.gift_certificate_id) {
961
- keyBase = `GIFT:${p.gift_certificate_id}`;
962
- }
963
- else {
964
- const orderNo = p.order_no || erp_order_id;
965
- const paymentMethod = String(p.payment_method_code || '').toUpperCase().trim();
966
- keyBase = `${orderNo}-${amount}-${paymentMethod}`;
967
- }
964
+ const paymentMethod = String(p.payment_method_code || '').toUpperCase().trim();
965
+ keyBase = `${orderNo}-${amount}-${paymentMethod}`;
966
+ }
967
+ }
968
+ else {
969
+ if (p.payment_refund_number) {
970
+ keyBase = `PRN:${p.payment_refund_number}`;
968
971
  }
969
972
  else {
970
- if (p.payment_refund_number) {
971
- keyBase = `PRN:${p.payment_refund_number}`;
972
- }
973
- else {
974
- const orderNo = p.order_no || erp_order_id;
975
- const amount = Number(p.amount || 0);
976
- const paymentMethod = String(p.payment_method_code || '').toUpperCase().trim();
977
- keyBase = `${orderNo}-${amount}-${paymentMethod}`;
978
- }
973
+ const orderNo = p.order_no || erp_order_id;
974
+ const amount = Number(p.amount || 0);
975
+ const paymentMethod = String(p.payment_method_code || '').toUpperCase().trim();
976
+ keyBase = `${orderNo}-${amount}-${paymentMethod}`;
979
977
  }
980
- const key = `${logicalType}:${keyBase}`;
981
- const g = groupsMap.get(key) || { entries: [], type: logicalType, key };
982
- g.entries.push(p);
983
- groupsMap.set(key, g);
984
- }
985
- catch (error) {
986
- console.error(`Error processing payment entry:`, {
987
- error: error instanceof Error ? error.message : String(error),
988
- payment_type: p?.type,
989
- amount: p?.amount,
990
- order_no: p?.order_no || erp_order_id,
991
- transaction_id: p?.transaction_id,
992
- payment_gateway_token: p?.payment_gateway_token,
993
- });
994
978
  }
979
+ const key = `${logicalType}:${keyBase}`;
980
+ const g = groupsMap.get(key) || { entries: [], type: logicalType, key };
981
+ g.entries.push(p);
982
+ groupsMap.set(key, g);
995
983
  });
996
984
  const allPaymentEntriesByOrder = new Map();
997
985
  flat.forEach(p => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.291",
3
+ "version": "0.0.292",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",