addio-admin-sdk 1.7.116 → 1.7.118
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/Interfaces/Cart/index.d.ts +6 -0
- package/dist/Interfaces/Cart/index.js.map +1 -1
- package/dist/lib/Cart/index.d.ts +17 -1
- package/dist/lib/Cart/index.js +302 -50
- package/dist/lib/Cart/index.js.map +1 -1
- package/dist/lib/Category/index.d.ts +1 -0
- package/dist/lib/Category/index.js +25 -0
- package/dist/lib/Category/index.js.map +1 -1
- package/dist/lib/Space/index.d.ts +6 -2
- package/dist/lib/Space/index.js +9 -0
- package/dist/lib/Space/index.js.map +1 -1
- package/dist/utils/cart.d.ts +9 -0
- package/dist/utils/cart.js +20 -1
- package/dist/utils/cart.js.map +1 -1
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ import { IBank } from '../PromiseToPurchase';
|
|
|
19
19
|
import { IG2OrderExternalValues, IG2ProductExternalValues } from '../G2';
|
|
20
20
|
import { ExternalServiceSlugEnum } from '../Space/IExternalService';
|
|
21
21
|
import { IElavonPayload } from './IElavonPayload';
|
|
22
|
+
import ILang from '../../utils/string';
|
|
22
23
|
export declare enum PaymentTypeEnum {
|
|
23
24
|
CREDIT = "credit",
|
|
24
25
|
DEBIT = "debit",
|
|
@@ -39,6 +40,11 @@ export declare enum CustomPaymentTypeEnum {
|
|
|
39
40
|
DEPOT = "depot",
|
|
40
41
|
INCENTIVE = "payment_incentive"
|
|
41
42
|
}
|
|
43
|
+
export interface IPaymentServicePayload {
|
|
44
|
+
type?: ExternalServiceSlugEnum;
|
|
45
|
+
payload?: IStripePayload | IElavonPayload | IPandaPayload | IPaysafePayload;
|
|
46
|
+
error?: ILang;
|
|
47
|
+
}
|
|
42
48
|
export declare enum CartPromoAppliesToEnum {
|
|
43
49
|
ITEMS = "items",
|
|
44
50
|
SHIPPING = "shipping",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Interfaces/Cart/index.ts"],"names":[],"mappings":";;;AAGA,gDAA+G;AAe/G,+CAAmD;AACnD,+CAAkD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Interfaces/Cart/index.ts"],"names":[],"mappings":";;;AAGA,gDAA+G;AAe/G,+CAAmD;AACnD,+CAAkD;AAOlD,IAAY,eAeX;AAfD,WAAY,eAAe;IAC1B,oCAAiB,CAAA;IACjB,kCAAe,CAAA;IACf,gCAAa,CAAA;IACb,kCAAe,CAAA;IACf,kDAA+B,CAAA;IAC/B,oCAAiB,CAAA;IACjB,6CAA0B,CAAA;IAC1B,wCAAqB,CAAA;IACrB,mDAAgC,CAAA;IAChC,uDAAoC,CAAA;IACpC,kCAAe,CAAA;IACf,iDAA8B,CAAA;IAC9B,uDAAoC,CAAA;IACpC,kDAA+B,CAAA;AAChC,CAAC,EAfW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAe1B;AAED,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAChC,wCAAe,CAAA;IACf,wDAA+B,CAAA,CAAC,8NAA8N;AAC/P,CAAC,EAHW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAGhC;AAQD,IAAY,sBAMX;AAND,WAAY,sBAAsB;IACjC,yCAAe,CAAA;IACf,+CAAqB,CAAA;IACrB,6CAAmB,CAAA;IACnB,iEAAuC,CAAA;IACvC,+CAAqB,CAAA;AACtB,CAAC,EANW,sBAAsB,GAAtB,8BAAsB,KAAtB,8BAAsB,QAMjC;AAsJD,IAAY,aAaX;AAbD,WAAY,aAAa;IACxB,sDAAqC,CAAA;IACrC,qFAAoE,CAAA;IACpE,0EAAyD,CAAA;IACzD,oDAAmC,CAAA;IACnC,6CAA4B,CAAA;IAC5B,yDAAwC,CAAA;IACxC,sEAAqD,CAAA;IACrD,sDAAqC,CAAA;IACrC,kEAAiD,CAAA;IACjD,sDAAqC,CAAA;IACrC,6CAA4B,CAAA;IAC5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QAAQ,EAAE,KAAK;YACf,MAAM,EAAE,CAAC;SACT;QACD,aAAa,EAAE,EAAE;QACjB,iBAAiB,EAAE,EAAE;QACrB,aAAa,EAAE,IAAA,oCAAsB,GAAE;QACvC,aAAa,EAAE;YACd,eAAe,EAAE,EAAE;YACnB,gBAAgB,EAAE,EAAE;SACpB;QACD,iBAAiB,EAAE;YAClB,eAAe,EAAE,EAAE;YACnB,gBAAgB,EAAE,EAAE;SACpB;QACD,0BAA0B,EAAE,KAAK;QACjC,iBAAiB;QACjB,qCAAqC;QACrC,wBAAwB;QACxB,IAAI;KACJ,CAAA;AACF,CAAC,CAAA;AA/BY,QAAA,kBAAkB,sBA+B9B"}
|
package/dist/lib/Cart/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ICart, { ICartItem, IShippingQuote, IBoxItem, CartStatusEnum, CartErrorEnum, IActionDoneOnCart, ICartAssignedUser, IBankUsed, PaymentTypeEnum, IIndexedDeclination, ICartPaymentPayloadOptions, ICartPromoApplied, IApplicablePromiseBank, ICartPromiseToPurchase, UpdateTypeEnum } from '../../Interfaces/Cart';
|
|
1
|
+
import ICart, { ICartItem, IShippingQuote, IBoxItem, CartStatusEnum, CartErrorEnum, IActionDoneOnCart, ICartAssignedUser, IBankUsed, PaymentTypeEnum, IIndexedDeclination, ICartPaymentPayloadOptions, ICartPromoApplied, IApplicablePromiseBank, ICartPromiseToPurchase, UpdateTypeEnum, IPaymentServicePayload } from '../../Interfaces/Cart';
|
|
2
2
|
import ISpace from '../../Interfaces/Space';
|
|
3
3
|
import IStore from '../../Interfaces/Store';
|
|
4
4
|
import ITax from '../../Interfaces/Tax';
|
|
@@ -22,6 +22,7 @@ import { TransferRequest } from '../TransferRequest';
|
|
|
22
22
|
import ITransferRequest from '../../Interfaces/TransferRequest';
|
|
23
23
|
import { IExternalServices } from '../../Interfaces/Space/IExternalService';
|
|
24
24
|
import CartReservedQuantities from '../CartReservedQuantities';
|
|
25
|
+
import IPaypalPayload from '../../Interfaces/Cart/IPaypalPayload';
|
|
25
26
|
export default class Cart extends BaseServiceClass<ICart> {
|
|
26
27
|
private _allTaxes;
|
|
27
28
|
constructor(data: any, collection: {
|
|
@@ -118,11 +119,26 @@ export default class Cart extends BaseServiceClass<ICart> {
|
|
|
118
119
|
};
|
|
119
120
|
accessToken?: string;
|
|
120
121
|
}>;
|
|
122
|
+
processPOSPaymentV2: (newCartPayments: IPayment[], cart: Cart, space: Space, isDev?: boolean, saveToDatabase?: boolean, indexCart?: boolean) => Promise<{
|
|
123
|
+
error?: {
|
|
124
|
+
fr: string;
|
|
125
|
+
en: string;
|
|
126
|
+
};
|
|
127
|
+
accessToken?: string;
|
|
128
|
+
}>;
|
|
121
129
|
getPaymentMethod: (options: ICartPaymentPayloadOptions) => PaymentTypeEnum;
|
|
122
130
|
createOrderWithSuccessfulPaymentPayload: ({ paypal_payload, stripe_payload, pandapay_payload, elavon_payload, paysafe_payload, charge_credit, other_payment_method, multi_payment_methods, isDev, saveToDatabase }: {
|
|
123
131
|
isDev: boolean;
|
|
124
132
|
saveToDatabase: boolean;
|
|
125
133
|
} & ICartPaymentPayloadOptions) => Promise<this>;
|
|
134
|
+
createOrderWithSuccessfulPaymentPayloadV2: ({ newPaymentsToSave, creditCardServicePayload, paypalServicePayload, customPaymentMethod, isDev, saveToDatabase }: {
|
|
135
|
+
newPaymentsToSave: IPayment[];
|
|
136
|
+
creditCardServicePayload: IPaymentServicePayload | undefined;
|
|
137
|
+
paypalServicePayload: IPaypalPayload | undefined;
|
|
138
|
+
customPaymentMethod?: IPayment | undefined;
|
|
139
|
+
isDev: boolean;
|
|
140
|
+
saveToDatabase: boolean;
|
|
141
|
+
}) => Promise<this>;
|
|
126
142
|
/**
|
|
127
143
|
* Sets a cart to status completed, and generates invoice_ref if necessary.
|
|
128
144
|
* @param saveToDatabase - Optional, defaults to true.
|
package/dist/lib/Cart/index.js
CHANGED
|
@@ -70,7 +70,9 @@ const cart_3 = require("../../rules/GR/interfaces/cart");
|
|
|
70
70
|
const TransferRequest_1 = require("../TransferRequest");
|
|
71
71
|
const TransferRequest_2 = require("../../Interfaces/TransferRequest");
|
|
72
72
|
const inventories_1 = require("../../utils/inventories");
|
|
73
|
+
const IExternalService_1 = require("../../Interfaces/Space/IExternalService");
|
|
73
74
|
const CartReservedQuantities_1 = __importDefault(require("../CartReservedQuantities"));
|
|
75
|
+
const searchIndexes_1 = require("../../utils/searchIndexes");
|
|
74
76
|
//#endregion
|
|
75
77
|
class Cart extends baseService_1.BaseServiceClass {
|
|
76
78
|
//#endregion
|
|
@@ -1187,31 +1189,6 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
1187
1189
|
let paysafe_payload = undefined;
|
|
1188
1190
|
console.log('====================');
|
|
1189
1191
|
console.log('in processPOSPayment');
|
|
1190
|
-
// TODO - Uncomment when ready to use store credits!
|
|
1191
|
-
// // Valider les store credits si utilisés comme mode de paiement
|
|
1192
|
-
// let usedCredit = 0
|
|
1193
|
-
// type IPaymentWithRef = IPayment & { ref: string }
|
|
1194
|
-
// const foundStoreCreditPayment = !!payment_request_payload.multi_payment_methods
|
|
1195
|
-
// ? (payment_request_payload.multi_payment_methods.find(
|
|
1196
|
-
// (p) => p.method == PaymentTypeEnum.STORE_CREDITS && !!p.ref
|
|
1197
|
-
// ) as IPaymentWithRef | undefined)
|
|
1198
|
-
// : undefined
|
|
1199
|
-
// if (foundStoreCreditPayment) {
|
|
1200
|
-
// const creditCheck = await validateStoreCreditUsage(
|
|
1201
|
-
// foundStoreCreditPayment.amount,
|
|
1202
|
-
// cart.data().customer_id,
|
|
1203
|
-
// space,
|
|
1204
|
-
// foundStoreCreditPayment.ref!
|
|
1205
|
-
// )
|
|
1206
|
-
// if (!creditCheck.valid)
|
|
1207
|
-
// return {
|
|
1208
|
-
// error: creditCheck.error || {
|
|
1209
|
-
// fr: 'Impossible de vérifier le crédit magasin pour la commande',
|
|
1210
|
-
// en: 'Could not check store credit for order'
|
|
1211
|
-
// }
|
|
1212
|
-
// }
|
|
1213
|
-
// usedCredit = foundStoreCreditPayment.amount
|
|
1214
|
-
// }
|
|
1215
1192
|
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
1216
1193
|
// Apply payments to cart and create ref
|
|
1217
1194
|
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
@@ -1241,30 +1218,6 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
1241
1218
|
}
|
|
1242
1219
|
console.log('createOrderWithSuccessfulPaymentPayload delay: ', (0, moment_1.default)().diff(delay1, 'seconds'));
|
|
1243
1220
|
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
1244
|
-
// Check for store credits to update in customer data
|
|
1245
|
-
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
1246
|
-
// TODO - Uncomment when ready to use store credits!
|
|
1247
|
-
// const cartData = cart.data()
|
|
1248
|
-
// if (usedCredit > 0 && !!cartData.customer_id && foundStoreCreditPayment) {
|
|
1249
|
-
// try {
|
|
1250
|
-
// const lastUserToTakePayment = getLastUserWhoTookPayment(cartData)
|
|
1251
|
-
// await space.customers.credits.modify(
|
|
1252
|
-
// cartData.customer_id,
|
|
1253
|
-
// foundStoreCreditPayment.ref,
|
|
1254
|
-
// -usedCredit,
|
|
1255
|
-
// `Commande #${cart.getCartRef(space).order}`,
|
|
1256
|
-
// `POS ${lastUserToTakePayment ? lastUserToTakePayment.user_id || lastUserToTakePayment.user_name : 'Unknown'}`
|
|
1257
|
-
// )
|
|
1258
|
-
// } catch (err) {
|
|
1259
|
-
// return {
|
|
1260
|
-
// error: {
|
|
1261
|
-
// fr: "Impossible d'ajuster les crédits magasin.",
|
|
1262
|
-
// en: 'Could not store credits.'
|
|
1263
|
-
// }
|
|
1264
|
-
// }
|
|
1265
|
-
// }
|
|
1266
|
-
// }
|
|
1267
|
-
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
1268
1221
|
// Check if Algolia is on -- save cart in algo
|
|
1269
1222
|
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
1270
1223
|
if (!!indexCart) {
|
|
@@ -1349,6 +1302,116 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
1349
1302
|
};
|
|
1350
1303
|
}
|
|
1351
1304
|
};
|
|
1305
|
+
this.processPOSPaymentV2 = async (newCartPayments, cart, space, isDev = false, saveToDatabase = true, indexCart = true) => {
|
|
1306
|
+
console.log('====================');
|
|
1307
|
+
console.log('in processPOSPayment');
|
|
1308
|
+
// Valider les store credits si utilisés comme mode de paiement
|
|
1309
|
+
let usedCredit = 0;
|
|
1310
|
+
const foundStoreCreditPayment = !!newCartPayments
|
|
1311
|
+
? newCartPayments.find((p) => p.method == Cart_1.PaymentTypeEnum.STORE_CREDITS && !!p.ref)
|
|
1312
|
+
: undefined;
|
|
1313
|
+
if (foundStoreCreditPayment) {
|
|
1314
|
+
const creditCheck = await (0, cart_1.validateStoreCreditUsage)(foundStoreCreditPayment.amount, cart.data().customer_id, space, foundStoreCreditPayment.ref // Where ref in payment corresponds to store credit slug
|
|
1315
|
+
);
|
|
1316
|
+
if (!creditCheck.valid)
|
|
1317
|
+
return {
|
|
1318
|
+
error: creditCheck.error || {
|
|
1319
|
+
fr: 'Impossible de vérifier le crédit magasin pour la commande',
|
|
1320
|
+
en: 'Could not check store credit for order'
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
usedCredit = foundStoreCreditPayment.amount;
|
|
1324
|
+
}
|
|
1325
|
+
// -------------------------------------------
|
|
1326
|
+
// Apply payments to cart and create ref
|
|
1327
|
+
try {
|
|
1328
|
+
console.log('---------------');
|
|
1329
|
+
let delay1 = (0, moment_1.default)();
|
|
1330
|
+
try {
|
|
1331
|
+
await cart.createOrderWithSuccessfulPaymentPayloadV2({
|
|
1332
|
+
newPaymentsToSave: newCartPayments,
|
|
1333
|
+
creditCardServicePayload: undefined,
|
|
1334
|
+
paypalServicePayload: undefined,
|
|
1335
|
+
isDev,
|
|
1336
|
+
saveToDatabase
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1339
|
+
catch (err) {
|
|
1340
|
+
return {
|
|
1341
|
+
error: {
|
|
1342
|
+
fr: "Impossible de créer la commande avec une charge de paiement réussie. Aucune charge n'a été reçue.",
|
|
1343
|
+
en: 'Could not create order with successful payment payload. No payload was sent.'
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
console.log('createOrderWithSuccessfulPaymentPayload delay: ', (0, moment_1.default)().diff(delay1, 'seconds'));
|
|
1348
|
+
// -------------------------------------------------------
|
|
1349
|
+
// Check for store credits to update in customer data
|
|
1350
|
+
const cartData = cart.data();
|
|
1351
|
+
if (usedCredit > 0 && !!cartData.customer_id && foundStoreCreditPayment && foundStoreCreditPayment.ref) {
|
|
1352
|
+
try {
|
|
1353
|
+
const lastUserToTakePayment = (0, cart_1.getLastUserWhoTookPayment)(cartData);
|
|
1354
|
+
await space.customers.credits.modify(cartData.customer_id, foundStoreCreditPayment.ref, -usedCredit, `Commande #${cart.getCartRef(space).order}`, `POS ${lastUserToTakePayment ? lastUserToTakePayment.user_id || lastUserToTakePayment.user_name : 'Unknown'}`);
|
|
1355
|
+
}
|
|
1356
|
+
catch (err) {
|
|
1357
|
+
return {
|
|
1358
|
+
error: {
|
|
1359
|
+
fr: "Impossible d'ajuster les crédits magasin.",
|
|
1360
|
+
en: 'Could not store credits.'
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
// --------------------------------------------------
|
|
1366
|
+
// Check if Algolia is on -- save cart in algo
|
|
1367
|
+
if (!!indexCart) {
|
|
1368
|
+
console.log('---------------');
|
|
1369
|
+
let delay2 = (0, moment_1.default)();
|
|
1370
|
+
const searchIndexServices = (0, searchIndexes_1.getIndexServices)(space, 'orders');
|
|
1371
|
+
let customer;
|
|
1372
|
+
if (!!cart.data().customer_id) {
|
|
1373
|
+
try {
|
|
1374
|
+
const customerQuery = await space.customers.get({
|
|
1375
|
+
query: [{ field: 'id', operator: '==', value: cart.data().customer_id }]
|
|
1376
|
+
});
|
|
1377
|
+
if (!!customerQuery && !!customerQuery.length) {
|
|
1378
|
+
customer = customerQuery[0];
|
|
1379
|
+
}
|
|
1380
|
+
}
|
|
1381
|
+
catch (e) {
|
|
1382
|
+
console.log('error while fetching customer: ', e.toString());
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
// NEW FUNCTION - returns indexedCartData
|
|
1386
|
+
const indexedCartData = (0, cart_1.getIndexedCartData)(cart.data(), space, {
|
|
1387
|
+
setPaidAtIfUndefined: true,
|
|
1388
|
+
customer: !!customer ? customer.data() : undefined,
|
|
1389
|
+
createdAt: (0, moment_1.default)().toDate()
|
|
1390
|
+
});
|
|
1391
|
+
try {
|
|
1392
|
+
await (0, searchIndexes_1.partialSaveNewEntryToIndex)(searchIndexServices, indexedCartData, `updating cart data on POS payment for cart #${cartData.ref || cartData.id || 'unknown'}`);
|
|
1393
|
+
}
|
|
1394
|
+
catch (e) {
|
|
1395
|
+
console.log('error on indexing cart: ', e.toString());
|
|
1396
|
+
}
|
|
1397
|
+
console.log('indexing cart delay: ', (0, moment_1.default)().diff(delay2, 'seconds'));
|
|
1398
|
+
}
|
|
1399
|
+
console.log('=================');
|
|
1400
|
+
return {
|
|
1401
|
+
accessToken: cart.data().id
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
catch (err) {
|
|
1405
|
+
console.log(err);
|
|
1406
|
+
console.log('=================');
|
|
1407
|
+
return {
|
|
1408
|
+
error: {
|
|
1409
|
+
fr: 'Nous avons rencontré une erreur...',
|
|
1410
|
+
en: 'We encountered an error'
|
|
1411
|
+
}
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
};
|
|
1352
1415
|
this.getPaymentMethod = (options) => {
|
|
1353
1416
|
if (!!options.multi_payment_methods && !!options.multi_payment_methods.length)
|
|
1354
1417
|
return Cart_1.PaymentTypeEnum.MULTIPLE;
|
|
@@ -1526,7 +1589,196 @@ class Cart extends baseService_1.BaseServiceClass {
|
|
|
1526
1589
|
// Check for space reserved quantities option
|
|
1527
1590
|
// If defined for space, or if all items are already reserved, skip all inventory ajustments here - was already ajusted on items added to card!
|
|
1528
1591
|
const spaceHasReservedQuantities = space.options.checkIfOptionIsSet('inventory.reserve_on_add_to_cart');
|
|
1529
|
-
const allItemsHaveReservedQuantities = this.data().items.every((i) => typeof i.qte_reserved == 'number' && i.qte_reserved == i.qte);
|
|
1592
|
+
const allItemsHaveReservedQuantities = this.data().items.every((i) => (0, cart_1.shouldIgnoreInventoryForItem)(i) || (typeof i.qte_reserved == 'number' && i.qte_reserved == i.qte));
|
|
1593
|
+
if (spaceHasReservedQuantities || allItemsHaveReservedQuantities) {
|
|
1594
|
+
console.log(`skipping inventory update in createOrderWithSuccessfulPaymentPayload for space ${space.getName()}. Inventory ajusted on items added to cart!`);
|
|
1595
|
+
}
|
|
1596
|
+
else {
|
|
1597
|
+
try {
|
|
1598
|
+
// Adjust cart items inventory
|
|
1599
|
+
await space.inventory.ajust(this.data().items, 'paid', this.data().cart_type, {
|
|
1600
|
+
currentStoreId: this.data().current_store_id || '',
|
|
1601
|
+
shouldCheckReservedQte: this.data().items.some((i) => typeof i.qte_reserved == 'number')
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
catch (error) {
|
|
1605
|
+
console.log('error while updating inventory', error);
|
|
1606
|
+
await (0, console_1.alertAdminV2)(`Error while updating inventory`, `We are here: /src/lib/Cart/index.ts#2100. We are in space ${space.data().id}. JSON error: ${JSON.stringify(error)}`, error.toString(), space.getRef());
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
console.log('adjusting inventory delay: ', (0, moment_1.default)().diff(delay5, 'seconds'));
|
|
1610
|
+
// -----------------------------------
|
|
1611
|
+
// If cart has promises to purchase, check if banks used are now empty
|
|
1612
|
+
if (!!this._data.promise_to_purchase) {
|
|
1613
|
+
console.log('---------------');
|
|
1614
|
+
let delay6 = (0, moment_1.default)();
|
|
1615
|
+
try {
|
|
1616
|
+
await this.checkForEmptyBanksAfterPayment(space);
|
|
1617
|
+
}
|
|
1618
|
+
catch (e) {
|
|
1619
|
+
console.log('error on checking for empty banks after payment: ', e.toString());
|
|
1620
|
+
}
|
|
1621
|
+
console.log('checkForEmptyBanks delay: ', (0, moment_1.default)().diff(delay6, 'seconds'));
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
catch (error) {
|
|
1625
|
+
await (0, console_1.alertAdminV2)(`Error while saving new cart`, `We are here: /src/lib/Cart/index.ts#2125. We are in space ${space.data().id}. JSON error: ${JSON.stringify(error)}`, error.toString(), space.getRef());
|
|
1626
|
+
throw error;
|
|
1627
|
+
}
|
|
1628
|
+
console.log('====================');
|
|
1629
|
+
return this;
|
|
1630
|
+
};
|
|
1631
|
+
this.createOrderWithSuccessfulPaymentPayloadV2 = async ({ newPaymentsToSave, creditCardServicePayload, paypalServicePayload, customPaymentMethod, isDev, saveToDatabase = true }) => {
|
|
1632
|
+
var _b, _c;
|
|
1633
|
+
console.log('====================');
|
|
1634
|
+
console.log('in V2 createOrderWithSuccessfulPaymentPayload');
|
|
1635
|
+
const cartType = this.data().cart_type;
|
|
1636
|
+
// If web cart with card payement and no payload provided, throw an error
|
|
1637
|
+
if (cartType === Cart_1.CartTypeEnum.WEB &&
|
|
1638
|
+
newPaymentsToSave.some((p) => [Cart_1.PaymentTypeEnum.CREDIT, Cart_1.PaymentTypeEnum.DEBIT].includes(p.method)) &&
|
|
1639
|
+
!!!creditCardServicePayload)
|
|
1640
|
+
throw new Error(`Payment intent payload must be set for a card payment!`);
|
|
1641
|
+
const space = await Space_2.default.getCurrentSpaceWithRef(this._collection.path, this._user);
|
|
1642
|
+
const getPaymentRef = () => {
|
|
1643
|
+
// use default props in cart as default value
|
|
1644
|
+
let refToUse = this.data().payment_reference || '';
|
|
1645
|
+
// check for card ref
|
|
1646
|
+
if (!!creditCardServicePayload && !!creditCardServicePayload.payload) {
|
|
1647
|
+
refToUse = creditCardServicePayload.payload.unique_ref
|
|
1648
|
+
? creditCardServicePayload.payload.unique_ref
|
|
1649
|
+
: creditCardServicePayload.payload.id
|
|
1650
|
+
? creditCardServicePayload.payload.id
|
|
1651
|
+
: '';
|
|
1652
|
+
}
|
|
1653
|
+
return refToUse;
|
|
1654
|
+
};
|
|
1655
|
+
// Fetch space invoice next ref
|
|
1656
|
+
let newRef = !!isDev ? 123456789 : undefined;
|
|
1657
|
+
// -----------------------------------------------------------------------------------------
|
|
1658
|
+
// We will fetch the next avaible ref number from the api
|
|
1659
|
+
// in case of issue up to 3 attemps will be done
|
|
1660
|
+
// if none of these worked we raise an exception
|
|
1661
|
+
// -----------------------------------------------------------------------------------------
|
|
1662
|
+
if (!!this._data.ref) {
|
|
1663
|
+
console.log('Cart already has ref #', this._data.ref, ', skipping ref increment');
|
|
1664
|
+
// if ref already in cart, set newRef with ref value so empty string is not saved in cart afterwards
|
|
1665
|
+
newRef = (0, toNumber_1.default)(this._data.ref);
|
|
1666
|
+
await (0, logs_1.SystemLog)({
|
|
1667
|
+
clientName: `sdk-admin | Cart | ...SuccPayPayload, space: ${(0, services_1.getSpaceInitialsByID)(space.data().id)}`,
|
|
1668
|
+
clientToken: (_b = process.env.NEXT_PUBLIC_LOG_SYSTEM_KEY) !== null && _b !== void 0 ? _b : ''
|
|
1669
|
+
}, logs_1.LogType.WARNING, `Cart already has ref #${this._data.ref}, skipping ref increment`);
|
|
1670
|
+
}
|
|
1671
|
+
else {
|
|
1672
|
+
console.log('---------------');
|
|
1673
|
+
let delay1 = (0, moment_1.default)();
|
|
1674
|
+
if (!isDev) {
|
|
1675
|
+
const token = (0, context_1.getSpaceTokenFromSpaceOnly)(space);
|
|
1676
|
+
const api = __1.API_URL;
|
|
1677
|
+
let triesLeft = 3;
|
|
1678
|
+
while (triesLeft > 0) {
|
|
1679
|
+
try {
|
|
1680
|
+
const resp = await fetch(`${api}/carts/refnumber`, {
|
|
1681
|
+
method: 'GET',
|
|
1682
|
+
headers: {
|
|
1683
|
+
'Content-Type': 'application/json',
|
|
1684
|
+
Authorization: `Bearer ${token}`
|
|
1685
|
+
}
|
|
1686
|
+
});
|
|
1687
|
+
if (resp.status >= 200 && resp.status < 300) {
|
|
1688
|
+
const data = await resp.json();
|
|
1689
|
+
if (data.status == 'success') {
|
|
1690
|
+
newRef = (0, toNumber_1.default)(data.result);
|
|
1691
|
+
break;
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
else
|
|
1695
|
+
console.log('response error ' + (await resp.text()));
|
|
1696
|
+
}
|
|
1697
|
+
catch (e) {
|
|
1698
|
+
console.log('Error fetching invoice number', e);
|
|
1699
|
+
}
|
|
1700
|
+
await (0, tools_1.waitFor)(1000); // whait a second before trying again, server need to recover
|
|
1701
|
+
triesLeft--;
|
|
1702
|
+
}
|
|
1703
|
+
if (triesLeft == 0)
|
|
1704
|
+
throw new Error('could not get a Ref number');
|
|
1705
|
+
}
|
|
1706
|
+
console.log('increment space ref delay: ', (0, moment_1.default)().diff(delay1, 'seconds'));
|
|
1707
|
+
}
|
|
1708
|
+
// Update customer last_activity prop.
|
|
1709
|
+
const customerId = this.data().customer_id;
|
|
1710
|
+
if (!!customerId) {
|
|
1711
|
+
try {
|
|
1712
|
+
await space.customers.updateCustomerLastActivity(customerId, this._user);
|
|
1713
|
+
}
|
|
1714
|
+
catch (e) {
|
|
1715
|
+
console.log(`Could not update last_activity prop for customer: ${customerId}, ${e}`);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
const getCreditCardPayloadToSaveForType = (type) => {
|
|
1719
|
+
return creditCardServicePayload && creditCardServicePayload.type == type
|
|
1720
|
+
? creditCardServicePayload.payload
|
|
1721
|
+
: undefined;
|
|
1722
|
+
};
|
|
1723
|
+
// -----------------------------------------------------------------------------------------
|
|
1724
|
+
// Create new partial cart data with info
|
|
1725
|
+
// -----------------------------------------------------------------------------------------
|
|
1726
|
+
const isPOSTransactionnal = this.data().cart_type === Cart_1.CartTypeEnum.POS_TRANSACTIONNAL;
|
|
1727
|
+
const currentPaymentDetails = this.data().payment_details || [];
|
|
1728
|
+
const partialCartPaidData = Object.assign(Object.assign(Object.assign(Object.assign({}, (this._data.cart_type === Cart_1.CartTypeEnum.WEB && !!customPaymentMethod && !!customPaymentMethod.method
|
|
1729
|
+
? {
|
|
1730
|
+
custom_payment_type: Object.assign({ method: customPaymentMethod.method }, (!!customPaymentMethod.amount ? { amount: customPaymentMethod.amount } : {}))
|
|
1731
|
+
}
|
|
1732
|
+
: {})), (!!currentPaymentDetails.length || newPaymentsToSave.length > 1
|
|
1733
|
+
? { paid_by: Cart_1.PaymentTypeEnum.MULTIPLE, payment_details: [...currentPaymentDetails, newPaymentsToSave] }
|
|
1734
|
+
: { paid_by: newPaymentsToSave[0].method })), { paypal_payload: paypalServicePayload, stripe_payload: getCreditCardPayloadToSaveForType(IExternalService_1.ExternalServiceSlugEnum.STRIPE), pandapay_payload: getCreditCardPayloadToSaveForType(IExternalService_1.ExternalServiceSlugEnum.PANDAPAY), elavon_payload: getCreditCardPayloadToSaveForType(IExternalService_1.ExternalServiceSlugEnum.ELAVON), paysafe_payload: getCreditCardPayloadToSaveForType(IExternalService_1.ExternalServiceSlugEnum.PAYSAFE), paid_at: (0, moment_1.default)().toDate(), status: !!isPOSTransactionnal ? Cart_1.CartStatusEnum.COMPLETED : Cart_1.CartStatusEnum.CHECKOUT_PAYMENT_SUCCESS, payment_reference: getPaymentRef(), ref: isDev ? `${(0, toString_1.default)(newRef)}-test` : (0, toString_1.default)(newRef), is_test: isDev, is: this.defineWhatICanBe() }), (this._data.id ? { id: this._data.id } : {}));
|
|
1735
|
+
try {
|
|
1736
|
+
console.log('---------------');
|
|
1737
|
+
if (!!this._data.ref && !!!this._data.id) {
|
|
1738
|
+
console.log('cart has ref but no id?!?');
|
|
1739
|
+
await (0, logs_1.SystemLog)({
|
|
1740
|
+
clientName: `sdk-admin | Cart | ...SuccPayPayload, space: ${(0, services_1.getSpaceInitialsByID)(space.data().id)}`,
|
|
1741
|
+
clientToken: (_c = process.env.NEXT_PUBLIC_LOG_SYSTEM_KEY) !== null && _c !== void 0 ? _c : ''
|
|
1742
|
+
}, logs_1.LogType.WARNING, `Cart already has ref #${this._data.ref}, but doesn't have an id??, ${this._data.id}`);
|
|
1743
|
+
}
|
|
1744
|
+
let delay2 = (0, moment_1.default)();
|
|
1745
|
+
// -----------------------------------
|
|
1746
|
+
// Save the cart and set it as "PAID"
|
|
1747
|
+
const newCartId = await this.save(partialCartPaidData, undefined, saveToDatabase);
|
|
1748
|
+
console.log('saving to DB delay: ', (0, moment_1.default)().diff(delay2, 'seconds'));
|
|
1749
|
+
// -----------------------------------------------------------------------------------------
|
|
1750
|
+
// If cart is of type POS_TRANSACTIONNAL, check if should create invoice_ref & add order to G2
|
|
1751
|
+
// If so, save partial data to cart
|
|
1752
|
+
if (!!isPOSTransactionnal) {
|
|
1753
|
+
console.log('---------------');
|
|
1754
|
+
let delay3 = (0, moment_1.default)();
|
|
1755
|
+
// a. Create invoice_ref
|
|
1756
|
+
const invoiceRef = await this.setCartWithInvoiceRef(space, false, partialCartPaidData.ref);
|
|
1757
|
+
console.log('setting invoice ref delay: ', (0, moment_1.default)().diff(delay3, 'seconds'));
|
|
1758
|
+
console.log('---------------');
|
|
1759
|
+
let delay4 = (0, moment_1.default)();
|
|
1760
|
+
// b. Add order to G2
|
|
1761
|
+
const skipRef = !!this.data().is_booking || !!this.data().is_booking_beton;
|
|
1762
|
+
let g2OrderRef;
|
|
1763
|
+
if (!skipRef && !(0, cart_2.checkIfCartContainsType)(cart_3.CartGeneralTypeEnum.SAMPLE, this.data())) {
|
|
1764
|
+
g2OrderRef = await this.setG2ExternalOrderRef(space, false, {
|
|
1765
|
+
ref: this.data().ref || partialCartPaidData.ref,
|
|
1766
|
+
id: (this.data().id || newCartId)
|
|
1767
|
+
});
|
|
1768
|
+
}
|
|
1769
|
+
console.log('saving g2 order & setting external_value delay: ', (0, moment_1.default)().diff(delay4, 'seconds'));
|
|
1770
|
+
console.log(`saving POS transactionnal cart to database: ${!!saveToDatabase}, with ref: ${partialCartPaidData.ref}, status: ${partialCartPaidData.status} and invoice ref: ${invoiceRef}${!!g2OrderRef ? ' and external_value.noCommande: ' + g2OrderRef : ''}`);
|
|
1771
|
+
// c. save to database
|
|
1772
|
+
await this.save(Object.assign({ id: this.data().id || newCartId, invoice_ref: invoiceRef }, (!!g2OrderRef ? { external_values: { noCommande: g2OrderRef } } : {})), undefined, saveToDatabase, true);
|
|
1773
|
+
}
|
|
1774
|
+
// -----------------------------------
|
|
1775
|
+
// Save inventory for cart items
|
|
1776
|
+
console.log('---------------');
|
|
1777
|
+
let delay5 = (0, moment_1.default)();
|
|
1778
|
+
// Check for space reserved quantities option
|
|
1779
|
+
// If defined for space, or if all items are already reserved, skip all inventory ajustments here - was already ajusted on items added to card!
|
|
1780
|
+
const spaceHasReservedQuantities = space.options.checkIfOptionIsSet('inventory.reserve_on_add_to_cart');
|
|
1781
|
+
const allItemsHaveReservedQuantities = this.data().items.every((i) => (0, cart_1.shouldIgnoreInventoryForItem)(i) || (typeof i.qte_reserved == 'number' && i.qte_reserved == i.qte));
|
|
1530
1782
|
if (spaceHasReservedQuantities || allItemsHaveReservedQuantities) {
|
|
1531
1783
|
console.log(`skipping inventory update in createOrderWithSuccessfulPaymentPayload for space ${space.getName()}. Inventory ajusted on items added to cart!`);
|
|
1532
1784
|
}
|