bitsnap-react 1.3.2 → 1.3.4
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.js +286 -80
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +286 -80
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/errors.d.mts +0 -2
- package/dist/errors.d.ts +0 -2
- package/dist/index.d.mts +0 -308
- package/dist/index.d.ts +0 -308
- package/dist/internal.d.mts +0 -2
- package/dist/internal.d.ts +0 -2
- package/dist/models.d.mts +0 -231
- package/dist/models.d.ts +0 -231
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ var PublicApiClient;
|
|
|
103
103
|
// src/components/checkout/CartProvider.tsx
|
|
104
104
|
var import_protobuf = require("@bufbuild/protobuf");
|
|
105
105
|
var import_react = require("react");
|
|
106
|
-
var
|
|
106
|
+
var import_zod2 = __toESM(require("zod"));
|
|
107
107
|
|
|
108
108
|
// src/components/checkout/constants.ts
|
|
109
109
|
var HOST = "https://bitsnap.pl";
|
|
@@ -362,6 +362,115 @@ function mapGooglePayDisplayItems(items, methods, deliveryMethod, couponCode, co
|
|
|
362
362
|
|
|
363
363
|
// src/components/checkout/CartProvider.tsx
|
|
364
364
|
var import_react_query = require("@tanstack/react-query");
|
|
365
|
+
|
|
366
|
+
// src/components/checkout/frontent.analytics.ts
|
|
367
|
+
var import_zod = __toESM(require("zod"));
|
|
368
|
+
var eventPayload = import_zod.default.object({
|
|
369
|
+
event: import_zod.default.enum([
|
|
370
|
+
"purchase",
|
|
371
|
+
"addToCart",
|
|
372
|
+
"customizeProduct",
|
|
373
|
+
"viewCart",
|
|
374
|
+
"removeFromCart",
|
|
375
|
+
"initiateCheckout"
|
|
376
|
+
]),
|
|
377
|
+
step: import_zod.default.string().optional(),
|
|
378
|
+
value: import_zod.default.number().optional(),
|
|
379
|
+
currency: import_zod.default.string().optional(),
|
|
380
|
+
content_name: import_zod.default.string().optional(),
|
|
381
|
+
items: import_zod.default.array(
|
|
382
|
+
import_zod.default.object({
|
|
383
|
+
id: import_zod.default.string(),
|
|
384
|
+
name: import_zod.default.string(),
|
|
385
|
+
price: import_zod.default.number().default(0),
|
|
386
|
+
currency: import_zod.default.string().default("PLN"),
|
|
387
|
+
quantity: import_zod.default.number().default(1)
|
|
388
|
+
})
|
|
389
|
+
).optional()
|
|
390
|
+
});
|
|
391
|
+
function sendAnalyticEvent(payload) {
|
|
392
|
+
if (typeof window == "undefined") {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
sendGoogleAnalyticsEvent(payload);
|
|
396
|
+
sendPixelAnalyticsEvent(payload);
|
|
397
|
+
}
|
|
398
|
+
function sendGoogleAnalyticsEvent(payload) {
|
|
399
|
+
try {
|
|
400
|
+
if (typeof window.dataLayer == "undefined") {
|
|
401
|
+
window.dataLayer = [];
|
|
402
|
+
}
|
|
403
|
+
window.dataLayer.push(payload);
|
|
404
|
+
} catch (e) {
|
|
405
|
+
console.warn("cannot send google analytics event", e);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function sendPixelAnalyticsEvent(payload) {
|
|
409
|
+
if (typeof window.fbq == "undefined") {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
let eventType = "";
|
|
413
|
+
let eventName = "";
|
|
414
|
+
let eventPayload2 = {};
|
|
415
|
+
switch (payload.event) {
|
|
416
|
+
case "purchase":
|
|
417
|
+
eventType = "track";
|
|
418
|
+
eventName = "Purchase";
|
|
419
|
+
eventPayload2 = {
|
|
420
|
+
category_name: payload.step,
|
|
421
|
+
...payload
|
|
422
|
+
};
|
|
423
|
+
break;
|
|
424
|
+
case "addToCart":
|
|
425
|
+
eventType = "track";
|
|
426
|
+
eventName = "Add to Cart";
|
|
427
|
+
eventPayload2 = {
|
|
428
|
+
category_name: payload.step,
|
|
429
|
+
...payload
|
|
430
|
+
};
|
|
431
|
+
break;
|
|
432
|
+
case "customizeProduct":
|
|
433
|
+
eventType = "track";
|
|
434
|
+
eventName = "Customize Product";
|
|
435
|
+
eventPayload2 = {
|
|
436
|
+
category_name: payload.step,
|
|
437
|
+
...payload
|
|
438
|
+
};
|
|
439
|
+
break;
|
|
440
|
+
case "viewCart":
|
|
441
|
+
eventType = "track";
|
|
442
|
+
eventName = "View Cart";
|
|
443
|
+
eventPayload2 = {
|
|
444
|
+
category_name: payload.step,
|
|
445
|
+
...payload
|
|
446
|
+
};
|
|
447
|
+
break;
|
|
448
|
+
case "removeFromCart":
|
|
449
|
+
eventType = "track";
|
|
450
|
+
eventName = "Remove from Cart";
|
|
451
|
+
eventPayload2 = {
|
|
452
|
+
category_name: payload.step,
|
|
453
|
+
...payload
|
|
454
|
+
};
|
|
455
|
+
break;
|
|
456
|
+
case "initiateCheckout":
|
|
457
|
+
eventType = "track";
|
|
458
|
+
eventName = "Initiate Checkout";
|
|
459
|
+
eventPayload2 = {
|
|
460
|
+
category_name: payload.step,
|
|
461
|
+
...payload
|
|
462
|
+
};
|
|
463
|
+
break;
|
|
464
|
+
default:
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
if (window.location.search.includes("analytics")) {
|
|
468
|
+
console.log("Pushing FB event", eventType, eventName, eventPayload2);
|
|
469
|
+
}
|
|
470
|
+
window.fbq(eventType, eventName, eventPayload2);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// src/components/checkout/CartProvider.tsx
|
|
365
474
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
366
475
|
var MARKETING_AGREEMENT_ID = "__m_a";
|
|
367
476
|
var CartProviderContext = (0, import_react.createContext)(void 0);
|
|
@@ -447,25 +556,25 @@ var useCartProvider = () => {
|
|
|
447
556
|
return context;
|
|
448
557
|
};
|
|
449
558
|
var CartProvider_default = CartProvider;
|
|
450
|
-
var googlePayConfigSchema =
|
|
451
|
-
isAvailable:
|
|
452
|
-
merchantId:
|
|
453
|
-
merchantName:
|
|
454
|
-
gateway:
|
|
455
|
-
gatewayId:
|
|
559
|
+
var googlePayConfigSchema = import_zod2.default.object({
|
|
560
|
+
isAvailable: import_zod2.default.boolean(),
|
|
561
|
+
merchantId: import_zod2.default.string(),
|
|
562
|
+
merchantName: import_zod2.default.string(),
|
|
563
|
+
gateway: import_zod2.default.string(),
|
|
564
|
+
gatewayId: import_zod2.default.string()
|
|
456
565
|
});
|
|
457
|
-
var checkoutSchema =
|
|
458
|
-
country:
|
|
459
|
-
couponCode:
|
|
460
|
-
selectedDeliveryMethod:
|
|
461
|
-
postalCode:
|
|
462
|
-
email:
|
|
463
|
-
products:
|
|
464
|
-
|
|
465
|
-
id:
|
|
466
|
-
productID:
|
|
467
|
-
quantity:
|
|
468
|
-
metadata:
|
|
566
|
+
var checkoutSchema = import_zod2.default.object({
|
|
567
|
+
country: import_zod2.default.string().optional(),
|
|
568
|
+
couponCode: import_zod2.default.string().optional(),
|
|
569
|
+
selectedDeliveryMethod: import_zod2.default.string().optional(),
|
|
570
|
+
postalCode: import_zod2.default.string().optional(),
|
|
571
|
+
email: import_zod2.default.string().optional(),
|
|
572
|
+
products: import_zod2.default.array(
|
|
573
|
+
import_zod2.default.object({
|
|
574
|
+
id: import_zod2.default.string(),
|
|
575
|
+
productID: import_zod2.default.string(),
|
|
576
|
+
quantity: import_zod2.default.number(),
|
|
577
|
+
metadata: import_zod2.default.record(import_zod2.default.string(), import_zod2.default.string().optional()).optional()
|
|
469
578
|
})
|
|
470
579
|
).optional(),
|
|
471
580
|
googlePayConfig: googlePayConfigSchema.optional()
|
|
@@ -496,12 +605,25 @@ function addProducts(products) {
|
|
|
496
605
|
if (checkout.products == null) {
|
|
497
606
|
checkout.products = [];
|
|
498
607
|
}
|
|
499
|
-
checkout.products.push(
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
608
|
+
checkout.products.push(
|
|
609
|
+
...products.map((el) => ({
|
|
610
|
+
id: Math.random().toString(36).substring(7),
|
|
611
|
+
productID: el.productID,
|
|
612
|
+
quantity: el.quantity,
|
|
613
|
+
metadata: el.metadata
|
|
614
|
+
}))
|
|
615
|
+
);
|
|
616
|
+
sendAnalyticEvent({
|
|
617
|
+
event: "addToCart",
|
|
618
|
+
currency: "PLN",
|
|
619
|
+
items: products.map((el) => ({
|
|
620
|
+
id: el.productID,
|
|
621
|
+
name: "",
|
|
622
|
+
price: 0,
|
|
623
|
+
quantity: el.quantity,
|
|
624
|
+
currency: "PLN"
|
|
625
|
+
}))
|
|
626
|
+
});
|
|
505
627
|
saveCheckout(checkout);
|
|
506
628
|
updateNumberOfProductsInCart();
|
|
507
629
|
}
|
|
@@ -514,6 +636,16 @@ function removeProductFromCheckout(ids) {
|
|
|
514
636
|
(product) => !ids.includes(product.productID) && !ids.includes(product.id)
|
|
515
637
|
)
|
|
516
638
|
};
|
|
639
|
+
sendAnalyticEvent({
|
|
640
|
+
event: "removeFromCart",
|
|
641
|
+
items: ids.map((id) => ({
|
|
642
|
+
id,
|
|
643
|
+
name: "",
|
|
644
|
+
price: 0,
|
|
645
|
+
quantity: 1,
|
|
646
|
+
currency: "PLN"
|
|
647
|
+
}))
|
|
648
|
+
});
|
|
517
649
|
saveCheckout(newCheckout);
|
|
518
650
|
updateNumberOfProductsInCart();
|
|
519
651
|
}
|
|
@@ -534,7 +666,9 @@ var getCheckoutMethods = (projectID) => {
|
|
|
534
666
|
return false;
|
|
535
667
|
}
|
|
536
668
|
try {
|
|
537
|
-
const result = await PublicApiClient.get(
|
|
669
|
+
const result = await PublicApiClient.get(
|
|
670
|
+
HOST
|
|
671
|
+
).isOneClickPaymentAvailable({
|
|
538
672
|
projectId: projectID
|
|
539
673
|
});
|
|
540
674
|
return result.applePay;
|
|
@@ -565,7 +699,9 @@ var getCheckoutMethods = (projectID) => {
|
|
|
565
699
|
}
|
|
566
700
|
if (args && args.items != null && args.items.length > 0) {
|
|
567
701
|
if (checkout.products) {
|
|
568
|
-
removeProductFromCheckout(
|
|
702
|
+
removeProductFromCheckout(
|
|
703
|
+
checkout.products.map((el) => el.productID)
|
|
704
|
+
);
|
|
569
705
|
}
|
|
570
706
|
addProducts(args.items);
|
|
571
707
|
}
|
|
@@ -577,7 +713,10 @@ var getCheckoutMethods = (projectID) => {
|
|
|
577
713
|
}
|
|
578
714
|
const result = await PublicApiClient.get(HOST).getPreOrderDetails({
|
|
579
715
|
items: products.map(
|
|
580
|
-
(el) => (0, import_protobuf.create)(PreOrderItemSchema, {
|
|
716
|
+
(el) => (0, import_protobuf.create)(PreOrderItemSchema, {
|
|
717
|
+
id: el.productID,
|
|
718
|
+
quantity: el.quantity
|
|
719
|
+
})
|
|
581
720
|
),
|
|
582
721
|
projectId: projectID,
|
|
583
722
|
// we can detect 5 the closest inpost pickup point based on shipping address.
|
|
@@ -633,10 +772,10 @@ var getCheckoutMethods = (projectID) => {
|
|
|
633
772
|
return [];
|
|
634
773
|
}
|
|
635
774
|
try {
|
|
636
|
-
return
|
|
637
|
-
|
|
638
|
-
name:
|
|
639
|
-
code:
|
|
775
|
+
return import_zod2.default.array(
|
|
776
|
+
import_zod2.default.object({
|
|
777
|
+
name: import_zod2.default.string(),
|
|
778
|
+
code: import_zod2.default.string()
|
|
640
779
|
})
|
|
641
780
|
).parse(await result.json());
|
|
642
781
|
} catch (e) {
|
|
@@ -712,21 +851,18 @@ var getCheckoutMethods = (projectID) => {
|
|
|
712
851
|
if (checkout.products == null || checkout.products.length == 0) {
|
|
713
852
|
return Err("cart-is-empty", "badInput");
|
|
714
853
|
}
|
|
715
|
-
const mergedMetadata = checkout.products.reduce(
|
|
716
|
-
(
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
},
|
|
728
|
-
{}
|
|
729
|
-
);
|
|
854
|
+
const mergedMetadata = checkout.products.reduce((acc, product) => {
|
|
855
|
+
if (product.metadata != null) {
|
|
856
|
+
Object.keys(product.metadata).forEach((key) => {
|
|
857
|
+
var _a;
|
|
858
|
+
const value = (_a = product.metadata) == null ? void 0 : _a[key];
|
|
859
|
+
if (value != null) {
|
|
860
|
+
acc[key] = value;
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
return acc;
|
|
865
|
+
}, {});
|
|
730
866
|
const payload = {
|
|
731
867
|
items: checkout.products.map((el) => {
|
|
732
868
|
return {
|
|
@@ -943,7 +1079,9 @@ var getCheckoutMethods = (projectID) => {
|
|
|
943
1079
|
}
|
|
944
1080
|
if (args && args.expectedItems != null && args.expectedItems.length > 0) {
|
|
945
1081
|
if (checkout.products) {
|
|
946
|
-
removeProductFromCheckout(
|
|
1082
|
+
removeProductFromCheckout(
|
|
1083
|
+
checkout.products.map((el) => el.productID)
|
|
1084
|
+
);
|
|
947
1085
|
}
|
|
948
1086
|
addProducts(args.expectedItems);
|
|
949
1087
|
}
|
|
@@ -953,7 +1091,10 @@ var getCheckoutMethods = (projectID) => {
|
|
|
953
1091
|
}
|
|
954
1092
|
const result = await PublicApiClient.get(HOST).getPreOrderDetails({
|
|
955
1093
|
items: products.map(
|
|
956
|
-
(el) => (0, import_protobuf.create)(PreOrderItemSchema, {
|
|
1094
|
+
(el) => (0, import_protobuf.create)(PreOrderItemSchema, {
|
|
1095
|
+
id: el.productID,
|
|
1096
|
+
quantity: el.quantity
|
|
1097
|
+
})
|
|
957
1098
|
),
|
|
958
1099
|
projectId: projectID,
|
|
959
1100
|
// we can detect 5 the closest inpost pickup point based on shipping address.
|
|
@@ -971,7 +1112,9 @@ var getCheckoutMethods = (projectID) => {
|
|
|
971
1112
|
};
|
|
972
1113
|
});
|
|
973
1114
|
if (result.selectedDeliveryMethod != null) {
|
|
974
|
-
const deliveryMethod = result.methods.find(
|
|
1115
|
+
const deliveryMethod = result.methods.find(
|
|
1116
|
+
(el) => el.id == result.selectedDeliveryMethod
|
|
1117
|
+
);
|
|
975
1118
|
if (deliveryMethod != null) {
|
|
976
1119
|
items.push({
|
|
977
1120
|
amount: `${round(deliveryMethod.amount / 100, 2)}`,
|
|
@@ -1096,7 +1239,10 @@ function updateNumberOfProductsInCart() {
|
|
|
1096
1239
|
const checkout = getCheckout();
|
|
1097
1240
|
let numberOfProductsInCart = 0;
|
|
1098
1241
|
if (checkout == null) {
|
|
1099
|
-
useCheckoutStore.setState((state) => ({
|
|
1242
|
+
useCheckoutStore.setState((state) => ({
|
|
1243
|
+
...state,
|
|
1244
|
+
numberOfProductsInCart
|
|
1245
|
+
}));
|
|
1100
1246
|
return;
|
|
1101
1247
|
}
|
|
1102
1248
|
numberOfProductsInCart = (_b = (_a = checkout.products) == null ? void 0 : _a.reduce((acc, product) => acc + product.quantity, 0)) != null ? _b : 0;
|
|
@@ -1106,7 +1252,13 @@ function updateNumberOfProductsInCart() {
|
|
|
1106
1252
|
// src/components/checkout/ApplePay.tsx
|
|
1107
1253
|
var import_react_query2 = require("@tanstack/react-query");
|
|
1108
1254
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1109
|
-
function ApplePayButtonComponent({
|
|
1255
|
+
function ApplePayButtonComponent({
|
|
1256
|
+
style,
|
|
1257
|
+
buttonType,
|
|
1258
|
+
colorType,
|
|
1259
|
+
items,
|
|
1260
|
+
onClick
|
|
1261
|
+
}) {
|
|
1110
1262
|
const {
|
|
1111
1263
|
checkIfApplePayIsAvailable,
|
|
1112
1264
|
getApplePayPaymentRequest,
|
|
@@ -1131,6 +1283,9 @@ function ApplePayButtonComponent({ style, buttonType, colorType, items, onClick
|
|
|
1131
1283
|
metadata: el.metadata
|
|
1132
1284
|
}));
|
|
1133
1285
|
async function beginSession() {
|
|
1286
|
+
sendAnalyticEvent({
|
|
1287
|
+
event: "initiateCheckout"
|
|
1288
|
+
});
|
|
1134
1289
|
const requiresShipping = items.find((el) => el.isDeliverable === true) != null;
|
|
1135
1290
|
const session = new ApplePaySession(14, {
|
|
1136
1291
|
countryCode: "PL",
|
|
@@ -1138,16 +1293,21 @@ function ApplePayButtonComponent({ style, buttonType, colorType, items, onClick
|
|
|
1138
1293
|
supportedNetworks: ["visa", "masterCard"],
|
|
1139
1294
|
currencyCode: "PLN",
|
|
1140
1295
|
total: {
|
|
1141
|
-
amount: `${round(
|
|
1296
|
+
amount: `${round(
|
|
1297
|
+
items.reduce((acc, item) => acc + item.price * item.quantity, 0) / 100,
|
|
1298
|
+
2
|
|
1299
|
+
)}`,
|
|
1142
1300
|
label: "P\u0142atno\u015B\u0107 za koszyk",
|
|
1143
1301
|
type: "pending"
|
|
1144
1302
|
},
|
|
1145
1303
|
lineItems: [
|
|
1146
|
-
...items.map(
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1304
|
+
...items.map(
|
|
1305
|
+
(item) => ({
|
|
1306
|
+
amount: `${round(item.price * item.quantity / 100, 2)}`,
|
|
1307
|
+
label: item.name,
|
|
1308
|
+
type: "final"
|
|
1309
|
+
})
|
|
1310
|
+
),
|
|
1151
1311
|
requiresShipping ? {
|
|
1152
1312
|
amount: `16.99`,
|
|
1153
1313
|
type: "pending",
|
|
@@ -1157,8 +1317,18 @@ function ApplePayButtonComponent({ style, buttonType, colorType, items, onClick
|
|
|
1157
1317
|
...requiresShipping ? {
|
|
1158
1318
|
shippingMethods: [],
|
|
1159
1319
|
supportsCouponCode: true,
|
|
1160
|
-
requiredBillingContactFields: [
|
|
1161
|
-
|
|
1320
|
+
requiredBillingContactFields: [
|
|
1321
|
+
"name",
|
|
1322
|
+
"email",
|
|
1323
|
+
"postalAddress",
|
|
1324
|
+
"phone"
|
|
1325
|
+
],
|
|
1326
|
+
requiredShippingContactFields: [
|
|
1327
|
+
"name",
|
|
1328
|
+
"email",
|
|
1329
|
+
"postalAddress",
|
|
1330
|
+
"phone"
|
|
1331
|
+
]
|
|
1162
1332
|
} : {}
|
|
1163
1333
|
});
|
|
1164
1334
|
await (onClick == null ? void 0 : onClick());
|
|
@@ -1285,7 +1455,15 @@ function ApplePayButtonComponent({ style, buttonType, colorType, items, onClick
|
|
|
1285
1455
|
};
|
|
1286
1456
|
session.begin();
|
|
1287
1457
|
}
|
|
1288
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1458
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1459
|
+
import_apple_pay_button.default,
|
|
1460
|
+
{
|
|
1461
|
+
style,
|
|
1462
|
+
buttonStyle: colorType,
|
|
1463
|
+
type: buttonType,
|
|
1464
|
+
onClick: beginSession
|
|
1465
|
+
}
|
|
1466
|
+
);
|
|
1289
1467
|
}
|
|
1290
1468
|
function Wrapper(props) {
|
|
1291
1469
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CartProvider_default, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ApplePayButtonComponent, { ...props }) }) });
|
|
@@ -1322,7 +1500,13 @@ function Spinner({ className, ...props }) {
|
|
|
1322
1500
|
// src/components/checkout/GooglePay.tsx
|
|
1323
1501
|
var import_react_query3 = require("@tanstack/react-query");
|
|
1324
1502
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1325
|
-
function GooglePayButtonComponent({
|
|
1503
|
+
function GooglePayButtonComponent({
|
|
1504
|
+
items,
|
|
1505
|
+
style,
|
|
1506
|
+
buttonColor,
|
|
1507
|
+
buttonSizeMode,
|
|
1508
|
+
test
|
|
1509
|
+
}) {
|
|
1326
1510
|
const {
|
|
1327
1511
|
getGooglePayConfiguration,
|
|
1328
1512
|
completeGooglePayPayment,
|
|
@@ -1334,7 +1518,10 @@ function GooglePayButtonComponent({ items, style, buttonColor, buttonSizeMode, t
|
|
|
1334
1518
|
clearCart
|
|
1335
1519
|
} = useCartProvider();
|
|
1336
1520
|
const { data: googlePayConfiguration } = (0, import_react_query3.useQuery)({
|
|
1337
|
-
queryKey: [
|
|
1521
|
+
queryKey: [
|
|
1522
|
+
"get-google-pay-configuration",
|
|
1523
|
+
items.map((el) => el.id).join(",")
|
|
1524
|
+
],
|
|
1338
1525
|
queryFn: () => getGooglePayConfiguration({
|
|
1339
1526
|
items: items.map((el) => ({
|
|
1340
1527
|
...el,
|
|
@@ -1343,11 +1530,16 @@ function GooglePayButtonComponent({ items, style, buttonColor, buttonSizeMode, t
|
|
|
1343
1530
|
}))
|
|
1344
1531
|
})
|
|
1345
1532
|
});
|
|
1346
|
-
const { mutateAsync: completeGooglePayPaymentAsync, isPending } = (0, import_react_query3.useMutation)(
|
|
1347
|
-
|
|
1348
|
-
|
|
1533
|
+
const { mutateAsync: completeGooglePayPaymentAsync, isPending } = (0, import_react_query3.useMutation)(
|
|
1534
|
+
{
|
|
1535
|
+
mutationFn: completeGooglePayPayment
|
|
1536
|
+
}
|
|
1537
|
+
);
|
|
1349
1538
|
if (googlePayConfiguration == null || googlePayConfiguration.isAvailable != true) {
|
|
1350
|
-
console.log(
|
|
1539
|
+
console.log(
|
|
1540
|
+
"google pay configuration is not available",
|
|
1541
|
+
googlePayConfiguration
|
|
1542
|
+
);
|
|
1351
1543
|
return null;
|
|
1352
1544
|
}
|
|
1353
1545
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
@@ -1361,6 +1553,9 @@ function GooglePayButtonComponent({ items, style, buttonColor, buttonSizeMode, t
|
|
|
1361
1553
|
environment: test === true ? "TEST" : "PRODUCTION",
|
|
1362
1554
|
onPaymentDataChanged: async (paymentData) => {
|
|
1363
1555
|
var _a, _b, _c, _d, _e;
|
|
1556
|
+
sendAnalyticEvent({
|
|
1557
|
+
event: "initiateCheckout"
|
|
1558
|
+
});
|
|
1364
1559
|
console.log("payment data changed", paymentData);
|
|
1365
1560
|
if (((_a = paymentData.shippingAddress) == null ? void 0 : _a.postalCode) != null) {
|
|
1366
1561
|
await setPostalCode((_b = paymentData.shippingAddress) == null ? void 0 : _b.postalCode);
|
|
@@ -1414,7 +1609,7 @@ var GooglePay_default = Wrapper2;
|
|
|
1414
1609
|
|
|
1415
1610
|
// src/components/checkout/BitsnapCart.tsx
|
|
1416
1611
|
var import_react8 = require("react");
|
|
1417
|
-
var
|
|
1612
|
+
var import_zod3 = __toESM(require("zod"));
|
|
1418
1613
|
|
|
1419
1614
|
// src/components/checkout/CartComponent.tsx
|
|
1420
1615
|
var import_react7 = require("@formkit/auto-animate/react");
|
|
@@ -1973,11 +2168,11 @@ var CartComponent_default = WrapperCartComponent;
|
|
|
1973
2168
|
|
|
1974
2169
|
// src/components/checkout/BitsnapCart.tsx
|
|
1975
2170
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1976
|
-
var cartAddToCartSchema =
|
|
1977
|
-
id:
|
|
1978
|
-
isSubscription:
|
|
1979
|
-
quantity:
|
|
1980
|
-
metadata:
|
|
2171
|
+
var cartAddToCartSchema = import_zod3.default.object({
|
|
2172
|
+
id: import_zod3.default.string(),
|
|
2173
|
+
isSubscription: import_zod3.default.boolean().default(false),
|
|
2174
|
+
quantity: import_zod3.default.number(),
|
|
2175
|
+
metadata: import_zod3.default.record(import_zod3.default.string(), import_zod3.default.string().optional()).optional()
|
|
1981
2176
|
});
|
|
1982
2177
|
function BitsnapCart({
|
|
1983
2178
|
projectID,
|
|
@@ -1996,6 +2191,11 @@ function BitsnapCart({
|
|
|
1996
2191
|
}
|
|
1997
2192
|
(0, import_react8.useEffect)(() => {
|
|
1998
2193
|
onVisibleChange == null ? void 0 : onVisibleChange(isCartVisible);
|
|
2194
|
+
if (isCartVisible) {
|
|
2195
|
+
sendAnalyticEvent({
|
|
2196
|
+
event: "viewCart"
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
1999
2199
|
}, [isCartVisible]);
|
|
2000
2200
|
(0, import_react8.useEffect)(() => {
|
|
2001
2201
|
setProjectID(projectID);
|
|
@@ -2010,13 +2210,16 @@ function BitsnapCart({
|
|
|
2010
2210
|
window["cart"] = {
|
|
2011
2211
|
buyProduct: async (args) => {
|
|
2012
2212
|
try {
|
|
2013
|
-
const payload =
|
|
2014
|
-
productID:
|
|
2015
|
-
email:
|
|
2016
|
-
name:
|
|
2017
|
-
country:
|
|
2018
|
-
marketingAgreement:
|
|
2213
|
+
const payload = import_zod3.default.object({
|
|
2214
|
+
productID: import_zod3.default.string(),
|
|
2215
|
+
email: import_zod3.default.string().optional(),
|
|
2216
|
+
name: import_zod3.default.string().optional(),
|
|
2217
|
+
country: import_zod3.default.string().optional(),
|
|
2218
|
+
marketingAgreement: import_zod3.default.boolean().optional()
|
|
2019
2219
|
}).parse(args);
|
|
2220
|
+
sendAnalyticEvent({
|
|
2221
|
+
event: "initiateCheckout"
|
|
2222
|
+
});
|
|
2020
2223
|
const methods = getCheckoutMethods(projectID2);
|
|
2021
2224
|
const result = await methods.justRedirectToPayment(payload);
|
|
2022
2225
|
console.log("result", result);
|
|
@@ -2106,7 +2309,10 @@ function BitsnapCart({
|
|
|
2106
2309
|
{
|
|
2107
2310
|
onClick: () => isCartVisible ? hideCart() : showCart(),
|
|
2108
2311
|
style: { position: "relative" },
|
|
2109
|
-
className: [
|
|
2312
|
+
className: [
|
|
2313
|
+
"bitsnap-checkout",
|
|
2314
|
+
className != null ? className : "rounded-full hover:bg-neutral-300 transition p-1"
|
|
2315
|
+
].join(" "),
|
|
2110
2316
|
children: [
|
|
2111
2317
|
children ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
|
|
2112
2318
|
"svg",
|