@betterstore/react 0.2.36 → 0.2.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/CHANGELOG.md +12 -0
- package/dist/components/checkout-embed/checkout-form.d.ts +2 -1
- package/dist/components/checkout-embed/checkout-schema.d.ts +36 -16
- package/dist/components/checkout-embed/steps/shipping/form.d.ts +5 -1
- package/dist/components/checkout-embed/steps/shipping/providers/zasilkovna.d.ts +13 -0
- package/dist/components/checkout-embed/steps/shipping/shipping-option-wrapper.d.ts +9 -0
- package/dist/components/payment-element/checkout-form.d.ts +2 -1
- package/dist/components/payment-element/index.d.ts +2 -1
- package/dist/index.cjs.js +147 -74
- package/dist/index.mjs +147 -74
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,7 @@ interface CheckoutFormProps {
|
|
|
15
15
|
fonts?: StripeElementsOptions["fonts"];
|
|
16
16
|
locale?: StripeElementLocale;
|
|
17
17
|
setShippingCost: (cost: number) => void;
|
|
18
|
+
exchangeRate: number;
|
|
18
19
|
}
|
|
19
|
-
export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, }: CheckoutFormProps): React.JSX.Element;
|
|
20
|
+
export default function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, }: CheckoutFormProps): React.JSX.Element;
|
|
20
21
|
export {};
|
|
@@ -10,11 +10,13 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
10
10
|
state: z.ZodOptional<z.ZodString>;
|
|
11
11
|
zipCode: z.ZodString;
|
|
12
12
|
country: z.ZodString;
|
|
13
|
+
countryCode: z.ZodString;
|
|
13
14
|
}, "strip", z.ZodTypeAny, {
|
|
14
15
|
line1: string;
|
|
15
16
|
city: string;
|
|
16
17
|
zipCode: string;
|
|
17
18
|
country: string;
|
|
19
|
+
countryCode: string;
|
|
18
20
|
line2?: string | undefined;
|
|
19
21
|
state?: string | undefined;
|
|
20
22
|
}, {
|
|
@@ -22,6 +24,7 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
22
24
|
city: string;
|
|
23
25
|
zipCode: string;
|
|
24
26
|
country: string;
|
|
27
|
+
countryCode: string;
|
|
25
28
|
line2?: string | undefined;
|
|
26
29
|
state?: string | undefined;
|
|
27
30
|
}>;
|
|
@@ -36,6 +39,7 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
36
39
|
city: string;
|
|
37
40
|
zipCode: string;
|
|
38
41
|
country: string;
|
|
42
|
+
countryCode: string;
|
|
39
43
|
line2?: string | undefined;
|
|
40
44
|
state?: string | undefined;
|
|
41
45
|
};
|
|
@@ -50,6 +54,7 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
50
54
|
city: string;
|
|
51
55
|
zipCode: string;
|
|
52
56
|
country: string;
|
|
57
|
+
countryCode: string;
|
|
53
58
|
line2?: string | undefined;
|
|
54
59
|
state?: string | undefined;
|
|
55
60
|
};
|
|
@@ -58,19 +63,22 @@ export declare const customerSchema: z.ZodObject<{
|
|
|
58
63
|
}>;
|
|
59
64
|
export declare const shippingMethodSchema: z.ZodObject<{
|
|
60
65
|
rateId: z.ZodString;
|
|
61
|
-
name: z.ZodString;
|
|
62
66
|
provider: z.ZodString;
|
|
63
|
-
|
|
67
|
+
price: z.ZodNumber;
|
|
68
|
+
name: z.ZodString;
|
|
69
|
+
pickupPointId: z.ZodOptional<z.ZodString>;
|
|
64
70
|
}, "strip", z.ZodTypeAny, {
|
|
65
71
|
rateId: string;
|
|
66
|
-
name: string;
|
|
67
72
|
provider: string;
|
|
68
|
-
|
|
73
|
+
price: number;
|
|
74
|
+
name: string;
|
|
75
|
+
pickupPointId?: string | undefined;
|
|
69
76
|
}, {
|
|
70
77
|
rateId: string;
|
|
71
|
-
name: string;
|
|
72
78
|
provider: string;
|
|
73
|
-
|
|
79
|
+
price: number;
|
|
80
|
+
name: string;
|
|
81
|
+
pickupPointId?: string | undefined;
|
|
74
82
|
}>;
|
|
75
83
|
export declare const checkoutSchema: z.ZodObject<{
|
|
76
84
|
customer: z.ZodObject<{
|
|
@@ -84,11 +92,13 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
84
92
|
state: z.ZodOptional<z.ZodString>;
|
|
85
93
|
zipCode: z.ZodString;
|
|
86
94
|
country: z.ZodString;
|
|
95
|
+
countryCode: z.ZodString;
|
|
87
96
|
}, "strip", z.ZodTypeAny, {
|
|
88
97
|
line1: string;
|
|
89
98
|
city: string;
|
|
90
99
|
zipCode: string;
|
|
91
100
|
country: string;
|
|
101
|
+
countryCode: string;
|
|
92
102
|
line2?: string | undefined;
|
|
93
103
|
state?: string | undefined;
|
|
94
104
|
}, {
|
|
@@ -96,6 +106,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
96
106
|
city: string;
|
|
97
107
|
zipCode: string;
|
|
98
108
|
country: string;
|
|
109
|
+
countryCode: string;
|
|
99
110
|
line2?: string | undefined;
|
|
100
111
|
state?: string | undefined;
|
|
101
112
|
}>;
|
|
@@ -110,6 +121,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
110
121
|
city: string;
|
|
111
122
|
zipCode: string;
|
|
112
123
|
country: string;
|
|
124
|
+
countryCode: string;
|
|
113
125
|
line2?: string | undefined;
|
|
114
126
|
state?: string | undefined;
|
|
115
127
|
};
|
|
@@ -124,6 +136,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
124
136
|
city: string;
|
|
125
137
|
zipCode: string;
|
|
126
138
|
country: string;
|
|
139
|
+
countryCode: string;
|
|
127
140
|
line2?: string | undefined;
|
|
128
141
|
state?: string | undefined;
|
|
129
142
|
};
|
|
@@ -132,19 +145,22 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
132
145
|
}>;
|
|
133
146
|
shipping: z.ZodObject<{
|
|
134
147
|
rateId: z.ZodString;
|
|
135
|
-
name: z.ZodString;
|
|
136
148
|
provider: z.ZodString;
|
|
137
|
-
|
|
149
|
+
price: z.ZodNumber;
|
|
150
|
+
name: z.ZodString;
|
|
151
|
+
pickupPointId: z.ZodOptional<z.ZodString>;
|
|
138
152
|
}, "strip", z.ZodTypeAny, {
|
|
139
153
|
rateId: string;
|
|
140
|
-
name: string;
|
|
141
154
|
provider: string;
|
|
142
|
-
|
|
155
|
+
price: number;
|
|
156
|
+
name: string;
|
|
157
|
+
pickupPointId?: string | undefined;
|
|
143
158
|
}, {
|
|
144
159
|
rateId: string;
|
|
145
|
-
name: string;
|
|
146
160
|
provider: string;
|
|
147
|
-
|
|
161
|
+
price: number;
|
|
162
|
+
name: string;
|
|
163
|
+
pickupPointId?: string | undefined;
|
|
148
164
|
}>;
|
|
149
165
|
customerId: z.ZodOptional<z.ZodString>;
|
|
150
166
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -157,6 +173,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
157
173
|
city: string;
|
|
158
174
|
zipCode: string;
|
|
159
175
|
country: string;
|
|
176
|
+
countryCode: string;
|
|
160
177
|
line2?: string | undefined;
|
|
161
178
|
state?: string | undefined;
|
|
162
179
|
};
|
|
@@ -165,9 +182,10 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
165
182
|
};
|
|
166
183
|
shipping: {
|
|
167
184
|
rateId: string;
|
|
168
|
-
name: string;
|
|
169
185
|
provider: string;
|
|
170
|
-
|
|
186
|
+
price: number;
|
|
187
|
+
name: string;
|
|
188
|
+
pickupPointId?: string | undefined;
|
|
171
189
|
};
|
|
172
190
|
customerId?: string | undefined;
|
|
173
191
|
}, {
|
|
@@ -180,6 +198,7 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
180
198
|
city: string;
|
|
181
199
|
zipCode: string;
|
|
182
200
|
country: string;
|
|
201
|
+
countryCode: string;
|
|
183
202
|
line2?: string | undefined;
|
|
184
203
|
state?: string | undefined;
|
|
185
204
|
};
|
|
@@ -188,9 +207,10 @@ export declare const checkoutSchema: z.ZodObject<{
|
|
|
188
207
|
};
|
|
189
208
|
shipping: {
|
|
190
209
|
rateId: string;
|
|
191
|
-
name: string;
|
|
192
210
|
provider: string;
|
|
193
|
-
|
|
211
|
+
price: number;
|
|
212
|
+
name: string;
|
|
213
|
+
pickupPointId?: string | undefined;
|
|
194
214
|
};
|
|
195
215
|
customerId?: string | undefined;
|
|
196
216
|
}>;
|
|
@@ -8,6 +8,10 @@ interface ShippingMethodFormProps {
|
|
|
8
8
|
onBack: () => void;
|
|
9
9
|
contactEmail: string;
|
|
10
10
|
shippingAddress: string;
|
|
11
|
+
currency: string;
|
|
12
|
+
exchangeRate: number;
|
|
13
|
+
locale?: string;
|
|
14
|
+
countryCode?: string;
|
|
11
15
|
}
|
|
12
|
-
export default function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, contactEmail, shippingAddress, }: ShippingMethodFormProps): React.JSX.Element;
|
|
16
|
+
export default function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, contactEmail, shippingAddress, currency, exchangeRate, locale, countryCode, }: ShippingMethodFormProps): React.JSX.Element;
|
|
13
17
|
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
Packeta: any;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export default function ZasilkovnaShippingOption({ children, onPickupPointSelected, locale, countryCode, apiKey, }: {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
onPickupPointSelected?: (pickupPointId: string) => void;
|
|
10
|
+
locale?: string;
|
|
11
|
+
countryCode?: string;
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ShippingRate } from "@betterstore/sdk";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export default function ShippingOptionWrapper({ rate, children, onPickupPointSelected, locale, countryCode, }: {
|
|
4
|
+
rate: ShippingRate;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
onPickupPointSelected?: (pickupPointId: string) => void;
|
|
7
|
+
locale?: string;
|
|
8
|
+
countryCode?: string;
|
|
9
|
+
}): React.JSX.Element | undefined;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
declare const _default: React.MemoExoticComponent<({ onSuccess, onError, children, }: {
|
|
2
|
+
declare const _default: React.MemoExoticComponent<({ onSuccess, onError, children, setSubmitting, }: {
|
|
3
3
|
onSuccess?: () => void;
|
|
4
4
|
onError?: () => void;
|
|
5
5
|
children: React.ReactNode;
|
|
6
|
+
setSubmitting?: (isSubmitting: boolean) => void;
|
|
6
7
|
}) => React.JSX.Element>;
|
|
7
8
|
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Appearance, StripeElementLocale, StripeElementsOptions } from "@stripe/stripe-js";
|
|
2
2
|
import React from "react";
|
|
3
|
-
declare function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSuccess, onError, children, }: {
|
|
3
|
+
declare function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSuccess, onError, children, setSubmitting, }: {
|
|
4
4
|
paymentSecret: string;
|
|
5
5
|
checkoutAppearance?: Appearance;
|
|
6
6
|
locale?: StripeElementLocale;
|
|
@@ -8,6 +8,7 @@ declare function PaymentElement({ paymentSecret, checkoutAppearance, locale, fon
|
|
|
8
8
|
onSuccess?: () => void;
|
|
9
9
|
onError?: () => void;
|
|
10
10
|
children: React.ReactNode;
|
|
11
|
+
setSubmitting?: (isSubmitting: boolean) => void;
|
|
11
12
|
}): React.JSX.Element;
|
|
12
13
|
declare const _default: React.MemoExoticComponent<typeof PaymentElement>;
|
|
13
14
|
export default _default;
|
package/dist/index.cjs.js
CHANGED
|
@@ -2593,6 +2593,13 @@ function defaults(obj) {
|
|
|
2593
2593
|
});
|
|
2594
2594
|
return obj;
|
|
2595
2595
|
}
|
|
2596
|
+
function hasXSS(input) {
|
|
2597
|
+
if (typeof input !== 'string') return false;
|
|
2598
|
+
|
|
2599
|
+
// Common XSS attack patterns
|
|
2600
|
+
const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
|
|
2601
|
+
return xssPatterns.some(pattern => pattern.test(input));
|
|
2602
|
+
}
|
|
2596
2603
|
|
|
2597
2604
|
// eslint-disable-next-line no-control-regex
|
|
2598
2605
|
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
@@ -2956,7 +2963,7 @@ class Browser {
|
|
|
2956
2963
|
if (lookup) detected = detected.concat(lookup);
|
|
2957
2964
|
}
|
|
2958
2965
|
});
|
|
2959
|
-
detected = detected.map(d => this.options.convertDetectedLanguage(d));
|
|
2966
|
+
detected = detected.filter(d => d !== undefined && d !== null && !hasXSS(d)).map(d => this.options.convertDetectedLanguage(d));
|
|
2960
2967
|
if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
|
2961
2968
|
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
|
2962
2969
|
}
|
|
@@ -3269,7 +3276,11 @@ const CheckoutEmbed$2 = {
|
|
|
3269
3276
|
estimatedDeliveryDate: "Odhadované datum dodání:",
|
|
3270
3277
|
shipTo: "Ship to:",
|
|
3271
3278
|
shipping: "Doprava:",
|
|
3272
|
-
title: "Přeprava"
|
|
3279
|
+
title: "Přeprava",
|
|
3280
|
+
description: {
|
|
3281
|
+
other: "Váš balíček bude doručen kurýrem.",
|
|
3282
|
+
zasilkovna: "Váš balíček bude doručen do bodu vyzvednutí."
|
|
3283
|
+
}
|
|
3273
3284
|
}
|
|
3274
3285
|
};
|
|
3275
3286
|
const Errors$1 = {
|
|
@@ -3337,7 +3348,11 @@ const CheckoutEmbed$1 = {
|
|
|
3337
3348
|
shipping: "Shipping:",
|
|
3338
3349
|
estimatedDeliveryDate: "Estimated delivery date: ",
|
|
3339
3350
|
day: "day",
|
|
3340
|
-
days: "days"
|
|
3351
|
+
days: "days",
|
|
3352
|
+
description: {
|
|
3353
|
+
other: "Your package will be delivered by a courier.",
|
|
3354
|
+
zasilkovna: "Your package will be delivered to a pickup point."
|
|
3355
|
+
}
|
|
3341
3356
|
},
|
|
3342
3357
|
Payment: {
|
|
3343
3358
|
title: "Payment",
|
|
@@ -3552,6 +3567,8 @@ const convertCheckoutAppearanceToStripeAppearance = (appearance$1, fonts) => {
|
|
|
3552
3567
|
return newAppearance;
|
|
3553
3568
|
};
|
|
3554
3569
|
|
|
3570
|
+
const storeHelpers = sdk.createStoreHelpers();
|
|
3571
|
+
|
|
3555
3572
|
const LayoutGroupContext = React.createContext({});
|
|
3556
3573
|
|
|
3557
3574
|
/**
|
|
@@ -3666,33 +3683,36 @@ function PopChild({ children, isPresent, anchorX }) {
|
|
|
3666
3683
|
const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, presenceAffectsLayout, mode, anchorX, }) => {
|
|
3667
3684
|
const presenceChildren = useConstant(newChildrenMap);
|
|
3668
3685
|
const id = React.useId();
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3686
|
+
let isReusedContext = true;
|
|
3687
|
+
let context = React.useMemo(() => {
|
|
3688
|
+
isReusedContext = false;
|
|
3689
|
+
return {
|
|
3690
|
+
id,
|
|
3691
|
+
initial,
|
|
3692
|
+
isPresent,
|
|
3693
|
+
custom,
|
|
3694
|
+
onExitComplete: (childId) => {
|
|
3695
|
+
presenceChildren.set(childId, true);
|
|
3696
|
+
for (const isComplete of presenceChildren.values()) {
|
|
3697
|
+
if (!isComplete)
|
|
3698
|
+
return; // can stop searching when any is incomplete
|
|
3699
|
+
}
|
|
3700
|
+
onExitComplete && onExitComplete();
|
|
3701
|
+
},
|
|
3702
|
+
register: (childId) => {
|
|
3703
|
+
presenceChildren.set(childId, false);
|
|
3704
|
+
return () => presenceChildren.delete(childId);
|
|
3705
|
+
},
|
|
3706
|
+
};
|
|
3707
|
+
}, [isPresent, presenceChildren, onExitComplete]);
|
|
3688
3708
|
/**
|
|
3689
3709
|
* If the presence of a child affects the layout of the components around it,
|
|
3690
3710
|
* we want to make a new context value to ensure they get re-rendered
|
|
3691
3711
|
* so they can detect that layout change.
|
|
3692
3712
|
*/
|
|
3693
|
-
presenceAffectsLayout
|
|
3694
|
-
|
|
3695
|
-
|
|
3713
|
+
if (presenceAffectsLayout && isReusedContext) {
|
|
3714
|
+
context = { ...context };
|
|
3715
|
+
}
|
|
3696
3716
|
React.useMemo(() => {
|
|
3697
3717
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
3698
3718
|
}, [isPresent]);
|
|
@@ -5599,7 +5619,7 @@ class MotionValue {
|
|
|
5599
5619
|
* This will be replaced by the build step with the latest version number.
|
|
5600
5620
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
5601
5621
|
*/
|
|
5602
|
-
this.version = "12.7.
|
|
5622
|
+
this.version = "12.7.4";
|
|
5603
5623
|
/**
|
|
5604
5624
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
5605
5625
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -13201,7 +13221,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
13201
13221
|
* and warn against mismatches.
|
|
13202
13222
|
*/
|
|
13203
13223
|
if (process.env.NODE_ENV === "development") {
|
|
13204
|
-
warnOnce(nextValue.version === "12.7.
|
|
13224
|
+
warnOnce(nextValue.version === "12.7.4", `Attempting to mix Motion versions ${nextValue.version} with 12.7.4 may not work as expected.`);
|
|
13205
13225
|
}
|
|
13206
13226
|
}
|
|
13207
13227
|
else if (isMotionValue(prevValue)) {
|
|
@@ -18241,6 +18261,7 @@ const customerSchema = z.object({
|
|
|
18241
18261
|
state: z.string().optional(),
|
|
18242
18262
|
zipCode: z.string().min(5, "invalid_zipCode"),
|
|
18243
18263
|
country: z.string().min(1, "required_error"),
|
|
18264
|
+
countryCode: z.string().min(1, "required_error"),
|
|
18244
18265
|
}),
|
|
18245
18266
|
saveInfo: z.boolean().optional(),
|
|
18246
18267
|
phone: z.string().regex(phoneRegex, "invalid_phone"),
|
|
@@ -18248,9 +18269,10 @@ const customerSchema = z.object({
|
|
|
18248
18269
|
// Shipping method schema
|
|
18249
18270
|
const shippingMethodSchema = z.object({
|
|
18250
18271
|
rateId: z.string().min(1, "required_error"),
|
|
18251
|
-
name: z.string().min(1, "required_error"),
|
|
18252
18272
|
provider: z.string().min(1, "required_error"),
|
|
18253
|
-
|
|
18273
|
+
price: z.number().min(1, "required_error"),
|
|
18274
|
+
name: z.string().min(1, "required_error"),
|
|
18275
|
+
pickupPointId: z.string().optional(),
|
|
18254
18276
|
});
|
|
18255
18277
|
// Combined checkout schema
|
|
18256
18278
|
z.object({
|
|
@@ -32622,6 +32644,7 @@ function AddressInput() {
|
|
|
32622
32644
|
React.createElement(FormLabel, null, t("CheckoutEmbed.CustomerForm.address.country")),
|
|
32623
32645
|
React.createElement(CountryDropdown, { placeholder: t("CheckoutEmbed.CustomerForm.address.countryPlaceholder"), defaultValue: field.value, onChange: (country) => {
|
|
32624
32646
|
field.onChange(country.name);
|
|
32647
|
+
form.setValue("address.countryCode", country.alpha2);
|
|
32625
32648
|
} }),
|
|
32626
32649
|
React.createElement(FormMessage, null))) })),
|
|
32627
32650
|
React.createElement(DialogFooter, null,
|
|
@@ -34142,7 +34165,7 @@ const useCheckout = create((set) => ({
|
|
|
34142
34165
|
setIsSubmitting: (isSubmitting) => set({ isSubmitting }),
|
|
34143
34166
|
}));
|
|
34144
34167
|
|
|
34145
|
-
const CheckoutForm$1 = ({ onSuccess, onError, children, }) => {
|
|
34168
|
+
const CheckoutForm$1 = ({ onSuccess, onError, children, setSubmitting, }) => {
|
|
34146
34169
|
const stripe = reactStripe_umdExports.useStripe();
|
|
34147
34170
|
const elements = reactStripe_umdExports.useElements();
|
|
34148
34171
|
const { setIsSubmitting } = useCheckout();
|
|
@@ -34152,6 +34175,7 @@ const CheckoutForm$1 = ({ onSuccess, onError, children, }) => {
|
|
|
34152
34175
|
if (!stripe || !elements) {
|
|
34153
34176
|
return;
|
|
34154
34177
|
}
|
|
34178
|
+
setSubmitting === null || setSubmitting === void 0 ? void 0 : setSubmitting(true);
|
|
34155
34179
|
setIsSubmitting(true);
|
|
34156
34180
|
const response = yield stripe.confirmPayment({
|
|
34157
34181
|
elements,
|
|
@@ -34160,15 +34184,18 @@ const CheckoutForm$1 = ({ onSuccess, onError, children, }) => {
|
|
|
34160
34184
|
if (response.error) {
|
|
34161
34185
|
setErrorMessage(response.error.message || "Something went wrong.");
|
|
34162
34186
|
setIsSubmitting(false);
|
|
34187
|
+
setSubmitting === null || setSubmitting === void 0 ? void 0 : setSubmitting(false);
|
|
34163
34188
|
onError === null || onError === void 0 ? void 0 : onError();
|
|
34164
34189
|
}
|
|
34165
34190
|
else {
|
|
34166
34191
|
setErrorMessage(undefined);
|
|
34167
34192
|
setIsSubmitting(false);
|
|
34193
|
+
setSubmitting === null || setSubmitting === void 0 ? void 0 : setSubmitting(false);
|
|
34168
34194
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
|
|
34169
34195
|
}
|
|
34170
34196
|
setErrorMessage(undefined);
|
|
34171
34197
|
setIsSubmitting(false);
|
|
34198
|
+
setSubmitting === null || setSubmitting === void 0 ? void 0 : setSubmitting(false);
|
|
34172
34199
|
});
|
|
34173
34200
|
return (React.createElement("form", { onSubmit: handleSubmit },
|
|
34174
34201
|
React.createElement("div", null,
|
|
@@ -34180,7 +34207,7 @@ var CheckoutForm$2 = React.memo(CheckoutForm$1);
|
|
|
34180
34207
|
|
|
34181
34208
|
const publicStripeKey = "pk_test_51RCjhw2cgbkVT71muwgBSw1tP06YVR4l4P9zI8wP2ipmze9VnTmTwxESVVePmU6QV8TL6bxG7f10oXQRnKC3F3KT00EsvlPAoS";
|
|
34182
34209
|
const stripePromise = loadStripe(publicStripeKey);
|
|
34183
|
-
function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSuccess, onError, children, }) {
|
|
34210
|
+
function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSuccess, onError, children, setSubmitting, }) {
|
|
34184
34211
|
const options = {
|
|
34185
34212
|
locale: locale !== null && locale !== void 0 ? locale : "en",
|
|
34186
34213
|
appearance: checkoutAppearance,
|
|
@@ -34188,11 +34215,12 @@ function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSu
|
|
|
34188
34215
|
fonts: fonts,
|
|
34189
34216
|
};
|
|
34190
34217
|
return (React.createElement(reactStripe_umdExports.Elements, { stripe: stripePromise, options: options },
|
|
34191
|
-
React.createElement(CheckoutForm$2, { onSuccess: onSuccess, onError: onError, children: children })));
|
|
34218
|
+
React.createElement(CheckoutForm$2, { onSuccess: onSuccess, onError: onError, children: children, setSubmitting: setSubmitting })));
|
|
34192
34219
|
}
|
|
34193
34220
|
var PaymentElement$1 = React.memo(PaymentElement);
|
|
34194
34221
|
|
|
34195
34222
|
function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingProvider, shippingPrice, checkoutAppearance, fonts, locale, }) {
|
|
34223
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
34196
34224
|
const { t } = useTranslation();
|
|
34197
34225
|
return (React.createElement("div", { className: "space-y-6" },
|
|
34198
34226
|
React.createElement("div", null,
|
|
@@ -34220,12 +34248,12 @@ function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack,
|
|
|
34220
34248
|
" \u00B7 ",
|
|
34221
34249
|
shippingPrice)),
|
|
34222
34250
|
React.createElement(Button, { variant: "link", size: "link", onClick: onBack }, t("CheckoutEmbed.Shipping.change")))),
|
|
34223
|
-
React.createElement("div", { className: "mt-8" }, paymentSecret && (React.createElement(PaymentElement$1, { fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), locale: locale, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError },
|
|
34251
|
+
React.createElement("div", { className: "mt-8" }, paymentSecret && (React.createElement(PaymentElement$1, { fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), locale: locale, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, setSubmitting: setIsSubmitting },
|
|
34224
34252
|
React.createElement("div", { className: "flex justify-between items-center pt-8" },
|
|
34225
34253
|
React.createElement(Button, { type: "button", variant: "ghost", onClick: onBack },
|
|
34226
34254
|
React.createElement(ChevronLeft, null),
|
|
34227
34255
|
t("CheckoutEmbed.Payment.back")),
|
|
34228
|
-
React.createElement(SubmitButton, { isValid: true, isSubmitting:
|
|
34256
|
+
React.createElement(SubmitButton, { isValid: true, isSubmitting: isSubmitting }, t("CheckoutEmbed.Payment.button"))))))));
|
|
34229
34257
|
}
|
|
34230
34258
|
|
|
34231
34259
|
function Skeleton(_a) {
|
|
@@ -34233,16 +34261,62 @@ function Skeleton(_a) {
|
|
|
34233
34261
|
return (React__namespace.createElement("div", Object.assign({ "data-slot": "skeleton", className: cn("bg-accent animate-pulse rounded-md", className) }, props)));
|
|
34234
34262
|
}
|
|
34235
34263
|
|
|
34236
|
-
function
|
|
34264
|
+
function ZasilkovnaShippingOption({ children, onPickupPointSelected, locale, countryCode, apiKey, }) {
|
|
34265
|
+
const [widgetLoaded, setWidgetLoaded] = React.useState(false);
|
|
34266
|
+
React.useEffect(() => {
|
|
34267
|
+
// Check if the script is already present
|
|
34268
|
+
if (!document.querySelector('script[src="https://widget.packeta.com/v6/www/js/library.js"]')) {
|
|
34269
|
+
const script = document.createElement("script");
|
|
34270
|
+
script.src = "https://widget.packeta.com/v6/www/js/library.js";
|
|
34271
|
+
script.async = true;
|
|
34272
|
+
script.onload = () => {
|
|
34273
|
+
setWidgetLoaded(true);
|
|
34274
|
+
console.log("loaded");
|
|
34275
|
+
};
|
|
34276
|
+
script.onerror = () => console.error("Failed to load Packeta Widget script.");
|
|
34277
|
+
document.body.appendChild(script);
|
|
34278
|
+
}
|
|
34279
|
+
else {
|
|
34280
|
+
setWidgetLoaded(true);
|
|
34281
|
+
}
|
|
34282
|
+
}, []);
|
|
34283
|
+
const handleClick = () => {
|
|
34284
|
+
if (widgetLoaded && window.Packeta && window.Packeta.Widget) {
|
|
34285
|
+
const options = {
|
|
34286
|
+
language: locale,
|
|
34287
|
+
country: countryCode,
|
|
34288
|
+
view: "modal",
|
|
34289
|
+
valueFormat: "id,name,city,street",
|
|
34290
|
+
};
|
|
34291
|
+
window.Packeta.Widget.pick(apiKey, (point) => {
|
|
34292
|
+
onPickupPointSelected === null || onPickupPointSelected === void 0 ? void 0 : onPickupPointSelected(point.id);
|
|
34293
|
+
}, options);
|
|
34294
|
+
}
|
|
34295
|
+
else {
|
|
34296
|
+
console.error("Packeta widget not found", window);
|
|
34297
|
+
}
|
|
34298
|
+
};
|
|
34299
|
+
return (React.createElement(React.Fragment, null,
|
|
34300
|
+
React.createElement("div", { onClick: () => handleClick() }, children)));
|
|
34301
|
+
}
|
|
34302
|
+
|
|
34303
|
+
function ShippingOptionWrapper({ rate, children, onPickupPointSelected, locale, countryCode, }) {
|
|
34304
|
+
if (rate.provider === "zasilkovna") {
|
|
34305
|
+
return (React.createElement(ZasilkovnaShippingOption, { onPickupPointSelected: onPickupPointSelected, locale: locale, countryCode: countryCode, apiKey: rate.clientSecret }, children));
|
|
34306
|
+
}
|
|
34307
|
+
return;
|
|
34308
|
+
}
|
|
34309
|
+
|
|
34310
|
+
function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, contactEmail, shippingAddress, currency, exchangeRate, locale, countryCode, }) {
|
|
34237
34311
|
var _a;
|
|
34238
34312
|
const { t } = useTranslation();
|
|
34239
34313
|
const form = useForm({
|
|
34240
34314
|
resolver: s$1(shippingMethodSchema),
|
|
34241
34315
|
defaultValues: initialData || {
|
|
34242
34316
|
rateId: "",
|
|
34243
|
-
name: "",
|
|
34244
34317
|
provider: "",
|
|
34245
|
-
|
|
34318
|
+
price: 0,
|
|
34319
|
+
pickupPointId: "",
|
|
34246
34320
|
},
|
|
34247
34321
|
});
|
|
34248
34322
|
const currentRateId = form.watch("rateId");
|
|
@@ -34266,28 +34340,27 @@ function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, cont
|
|
|
34266
34340
|
shippingRates.length === 0 &&
|
|
34267
34341
|
Array.from({ length: 3 }).map((_, index) => (React.createElement(ShippingRateLoading, { key: index }))),
|
|
34268
34342
|
shippingRates.map((rate) => {
|
|
34269
|
-
const rateId = rate.
|
|
34270
|
-
const intPrice = Math.ceil(Number(rate.
|
|
34271
|
-
const
|
|
34272
|
-
|
|
34273
|
-
|
|
34274
|
-
|
|
34275
|
-
|
|
34276
|
-
form.setValue("
|
|
34277
|
-
|
|
34278
|
-
|
|
34279
|
-
|
|
34280
|
-
|
|
34281
|
-
|
|
34282
|
-
|
|
34283
|
-
|
|
34284
|
-
|
|
34285
|
-
|
|
34286
|
-
|
|
34287
|
-
|
|
34288
|
-
|
|
34289
|
-
|
|
34290
|
-
: t("CheckoutEmbed.Shipping.days")))));
|
|
34343
|
+
const rateId = rate.provider + rate.name;
|
|
34344
|
+
const intPrice = Math.ceil(Number(rate.price));
|
|
34345
|
+
const displayPrice = storeHelpers.formatPrice(intPrice, currency, exchangeRate);
|
|
34346
|
+
const description = rate.provider === "zasilkovna"
|
|
34347
|
+
? t("CheckoutEmbed.Shipping.description.zasilkovna")
|
|
34348
|
+
: t("CheckoutEmbed.Shipping.description.other");
|
|
34349
|
+
return (React.createElement(ShippingOptionWrapper, { rate: rate, key: rateId, onPickupPointSelected: (pickupPointId) => {
|
|
34350
|
+
form.setValue("pickupPointId", pickupPointId);
|
|
34351
|
+
}, locale: locale, countryCode: countryCode },
|
|
34352
|
+
React.createElement("div", { className: clsx("p-4 cursor-pointer rounded-md border bg-background", {
|
|
34353
|
+
"bg-muted border-primary": currentRateId === rateId,
|
|
34354
|
+
}), onClick: () => {
|
|
34355
|
+
form.setValue("rateId", rateId);
|
|
34356
|
+
form.setValue("provider", rate.provider);
|
|
34357
|
+
form.setValue("name", rate.name);
|
|
34358
|
+
form.setValue("price", intPrice);
|
|
34359
|
+
} },
|
|
34360
|
+
React.createElement("div", { className: "flex items-center justify-between w-full" },
|
|
34361
|
+
React.createElement("p", null, rate.name),
|
|
34362
|
+
React.createElement("p", null, displayPrice)),
|
|
34363
|
+
React.createElement("p", { className: "text-sm text-muted-foreground" }, description))));
|
|
34291
34364
|
}),
|
|
34292
34365
|
React.createElement(FormMessage, null, (_a = form.formState.errors.rateId) === null || _a === void 0 ? void 0 : _a.message),
|
|
34293
34366
|
React.createElement("div", { className: "flex justify-between items-center pt-4" },
|
|
@@ -34317,7 +34390,7 @@ const motionSettings = {
|
|
|
34317
34390
|
exit: { opacity: 0 },
|
|
34318
34391
|
transition: { duration: 0.2 },
|
|
34319
34392
|
};
|
|
34320
|
-
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, }) {
|
|
34393
|
+
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, }) {
|
|
34321
34394
|
const { formData, setFormData, step, setStep } = useFormStore(checkoutId)();
|
|
34322
34395
|
const [paymentSecret, setPaymentSecret] = React.useState(null);
|
|
34323
34396
|
const [shippingRates, setShippingRates] = React.useState([]);
|
|
@@ -34341,7 +34414,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34341
34414
|
validateStep();
|
|
34342
34415
|
}, [step]);
|
|
34343
34416
|
React.useEffect(() => {
|
|
34344
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
34417
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
34345
34418
|
if (customer && !((_a = formData.customer) === null || _a === void 0 ? void 0 : _a.email)) {
|
|
34346
34419
|
setFormData(Object.assign(Object.assign({}, formData), { customerId: customer.id, customer: {
|
|
34347
34420
|
firstName: (_d = (_c = (_b = customer.address) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.split(" ")[0]) !== null && _d !== void 0 ? _d : "",
|
|
@@ -34354,6 +34427,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34354
34427
|
city: (_r = (_q = customer.address) === null || _q === void 0 ? void 0 : _q.city) !== null && _r !== void 0 ? _r : "",
|
|
34355
34428
|
zipCode: (_t = (_s = customer.address) === null || _s === void 0 ? void 0 : _s.zipCode) !== null && _t !== void 0 ? _t : "",
|
|
34356
34429
|
country: (_v = (_u = customer.address) === null || _u === void 0 ? void 0 : _u.country) !== null && _v !== void 0 ? _v : "",
|
|
34430
|
+
countryCode: (_x = (_w = customer.address) === null || _w === void 0 ? void 0 : _w.countryCode) !== null && _x !== void 0 ? _x : "",
|
|
34357
34431
|
},
|
|
34358
34432
|
} }));
|
|
34359
34433
|
}
|
|
@@ -34365,12 +34439,14 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34365
34439
|
return;
|
|
34366
34440
|
const getShippingRates = () => __awaiter(this, void 0, void 0, function* () {
|
|
34367
34441
|
const shippingRates = yield storeClient.getCheckoutShippingRates(clientSecret, checkoutId);
|
|
34442
|
+
console.log(shippingRates);
|
|
34368
34443
|
setShippingRates(shippingRates);
|
|
34369
34444
|
});
|
|
34370
34445
|
getShippingRates();
|
|
34371
34446
|
}, [step, shippingRates]);
|
|
34372
34447
|
// Handle address form submission
|
|
34373
34448
|
const handleCustomerSubmit = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
34449
|
+
setFormData(Object.assign(Object.assign({}, formData), { customer: data }));
|
|
34374
34450
|
let newCustomerId = formData.customerId;
|
|
34375
34451
|
if (!newCustomerId) {
|
|
34376
34452
|
const newCustomer = yield storeClient.createCustomer(clientSecret, {
|
|
@@ -34404,16 +34480,15 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34404
34480
|
const newFormData = Object.assign(Object.assign({}, formData), { shipping: data });
|
|
34405
34481
|
setFormData(newFormData);
|
|
34406
34482
|
yield storeClient.updateCheckout(clientSecret, checkoutId, {
|
|
34407
|
-
shipping: data.
|
|
34408
|
-
|
|
34409
|
-
rateId: data.rateId,
|
|
34410
|
-
name: data.name,
|
|
34483
|
+
shipping: data.price,
|
|
34484
|
+
shipmentInfo: {
|
|
34411
34485
|
provider: data.provider,
|
|
34486
|
+
pickupPointId: data.pickupPointId,
|
|
34412
34487
|
},
|
|
34413
34488
|
});
|
|
34414
34489
|
const paymentSecret = yield storeClient.generateCheckoutsPaymentSecret(clientSecret, checkoutId);
|
|
34415
34490
|
setPaymentSecret(paymentSecret);
|
|
34416
|
-
setShippingCost(data.
|
|
34491
|
+
setShippingCost(data.price);
|
|
34417
34492
|
setStep("payment");
|
|
34418
34493
|
});
|
|
34419
34494
|
// Navigate back to previous step
|
|
@@ -34443,9 +34518,9 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34443
34518
|
step === "customer" && (React.createElement(motion.div, Object.assign({ key: "customer" }, motionSettings, { className: "absolute w-full" }),
|
|
34444
34519
|
React.createElement(CustomerForm, { initialData: formData.customer, onSubmit: handleCustomerSubmit }))),
|
|
34445
34520
|
step === "shipping" && formData.customer && (React.createElement(motion.div, Object.assign({ key: "shipping" }, motionSettings, { className: "absolute w-full" }),
|
|
34446
|
-
React.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address) }))),
|
|
34521
|
+
React.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), currency: currency, exchangeRate: exchangeRate, locale: locale, countryCode: formData.customer.address.countryCode }))),
|
|
34447
34522
|
step === "payment" && formData.customer && formData.shipping && (React.createElement(motion.div, Object.assign({ key: "payment" }, motionSettings, { className: "absolute w-full" }),
|
|
34448
|
-
React.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: formData.shipping.
|
|
34523
|
+
React.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: storeHelpers.formatPrice(formData.shipping.price, currency, exchangeRate) }))))));
|
|
34449
34524
|
}
|
|
34450
34525
|
|
|
34451
34526
|
function CheckoutFormLoading() {
|
|
@@ -34467,8 +34542,6 @@ function InputGroupLoading({ className }) {
|
|
|
34467
34542
|
React.createElement(Skeleton, { className: "w-full h-9" })));
|
|
34468
34543
|
}
|
|
34469
34544
|
|
|
34470
|
-
const storeHelpers = sdk.createStoreHelpers();
|
|
34471
|
-
|
|
34472
34545
|
function CheckoutSummary({ lineItems, shipping, tax, currency, cancelUrl, exchangeRate, }) {
|
|
34473
34546
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
34474
34547
|
const { t } = useTranslation();
|
|
@@ -34559,7 +34632,7 @@ function CheckoutSummaryLoading() {
|
|
|
34559
34632
|
}
|
|
34560
34633
|
|
|
34561
34634
|
function CheckoutEmbed({ checkoutId, config }) {
|
|
34562
|
-
var _a, _b, _c, _d;
|
|
34635
|
+
var _a, _b, _c, _d, _e;
|
|
34563
34636
|
const { cancelUrl, successUrl, appearance, locale, clientSecret, clientProxy, } = config;
|
|
34564
34637
|
const storeClient = sdk.createStoreClient({ proxy: clientProxy });
|
|
34565
34638
|
React.useMemo(() => createI18nInstance(locale), []);
|
|
@@ -34608,10 +34681,10 @@ function CheckoutEmbed({ checkoutId, config }) {
|
|
|
34608
34681
|
return;
|
|
34609
34682
|
setCheckout(Object.assign(Object.assign({}, checkout), { shipping: cost }));
|
|
34610
34683
|
};
|
|
34611
|
-
return (React.createElement("div", { className: "checkout-embed mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
|
|
34684
|
+
return (React.createElement("div", { className: "checkout-embed scrollbar-hidden mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
|
|
34612
34685
|
React.createElement(Appearance, { appearance: appearance }),
|
|
34613
|
-
React.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React.createElement(CheckoutFormLoading, null)) : (React.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError }))),
|
|
34614
|
-
React.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React.createElement(CheckoutSummaryLoading, null)) : (React.createElement(CheckoutSummary, { currency: (
|
|
34686
|
+
React.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React.createElement(CheckoutFormLoading, null)) : (React.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1 }))),
|
|
34687
|
+
React.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React.createElement(CheckoutSummaryLoading, null)) : (React.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, cancelUrl: cancelUrl, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1 })))));
|
|
34615
34688
|
}
|
|
34616
34689
|
var index = React.memo(CheckoutEmbed);
|
|
34617
34690
|
|
package/dist/index.mjs
CHANGED
|
@@ -2570,6 +2570,13 @@ function defaults(obj) {
|
|
|
2570
2570
|
});
|
|
2571
2571
|
return obj;
|
|
2572
2572
|
}
|
|
2573
|
+
function hasXSS(input) {
|
|
2574
|
+
if (typeof input !== 'string') return false;
|
|
2575
|
+
|
|
2576
|
+
// Common XSS attack patterns
|
|
2577
|
+
const xssPatterns = [/<\s*script.*?>/i, /<\s*\/\s*script\s*>/i, /<\s*img.*?on\w+\s*=/i, /<\s*\w+\s*on\w+\s*=.*?>/i, /javascript\s*:/i, /vbscript\s*:/i, /expression\s*\(/i, /eval\s*\(/i, /alert\s*\(/i, /document\.cookie/i, /document\.write\s*\(/i, /window\.location/i, /innerHTML/i];
|
|
2578
|
+
return xssPatterns.some(pattern => pattern.test(input));
|
|
2579
|
+
}
|
|
2573
2580
|
|
|
2574
2581
|
// eslint-disable-next-line no-control-regex
|
|
2575
2582
|
const fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
|
|
@@ -2933,7 +2940,7 @@ class Browser {
|
|
|
2933
2940
|
if (lookup) detected = detected.concat(lookup);
|
|
2934
2941
|
}
|
|
2935
2942
|
});
|
|
2936
|
-
detected = detected.map(d => this.options.convertDetectedLanguage(d));
|
|
2943
|
+
detected = detected.filter(d => d !== undefined && d !== null && !hasXSS(d)).map(d => this.options.convertDetectedLanguage(d));
|
|
2937
2944
|
if (this.services && this.services.languageUtils && this.services.languageUtils.getBestMatchFromCodes) return detected; // new i18next v19.5.0
|
|
2938
2945
|
return detected.length > 0 ? detected[0] : null; // a little backward compatibility
|
|
2939
2946
|
}
|
|
@@ -3246,7 +3253,11 @@ const CheckoutEmbed$2 = {
|
|
|
3246
3253
|
estimatedDeliveryDate: "Odhadované datum dodání:",
|
|
3247
3254
|
shipTo: "Ship to:",
|
|
3248
3255
|
shipping: "Doprava:",
|
|
3249
|
-
title: "Přeprava"
|
|
3256
|
+
title: "Přeprava",
|
|
3257
|
+
description: {
|
|
3258
|
+
other: "Váš balíček bude doručen kurýrem.",
|
|
3259
|
+
zasilkovna: "Váš balíček bude doručen do bodu vyzvednutí."
|
|
3260
|
+
}
|
|
3250
3261
|
}
|
|
3251
3262
|
};
|
|
3252
3263
|
const Errors$1 = {
|
|
@@ -3314,7 +3325,11 @@ const CheckoutEmbed$1 = {
|
|
|
3314
3325
|
shipping: "Shipping:",
|
|
3315
3326
|
estimatedDeliveryDate: "Estimated delivery date: ",
|
|
3316
3327
|
day: "day",
|
|
3317
|
-
days: "days"
|
|
3328
|
+
days: "days",
|
|
3329
|
+
description: {
|
|
3330
|
+
other: "Your package will be delivered by a courier.",
|
|
3331
|
+
zasilkovna: "Your package will be delivered to a pickup point."
|
|
3332
|
+
}
|
|
3318
3333
|
},
|
|
3319
3334
|
Payment: {
|
|
3320
3335
|
title: "Payment",
|
|
@@ -3529,6 +3544,8 @@ const convertCheckoutAppearanceToStripeAppearance = (appearance$1, fonts) => {
|
|
|
3529
3544
|
return newAppearance;
|
|
3530
3545
|
};
|
|
3531
3546
|
|
|
3547
|
+
const storeHelpers = createStoreHelpers();
|
|
3548
|
+
|
|
3532
3549
|
const LayoutGroupContext = createContext({});
|
|
3533
3550
|
|
|
3534
3551
|
/**
|
|
@@ -3643,33 +3660,36 @@ function PopChild({ children, isPresent, anchorX }) {
|
|
|
3643
3660
|
const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, presenceAffectsLayout, mode, anchorX, }) => {
|
|
3644
3661
|
const presenceChildren = useConstant(newChildrenMap);
|
|
3645
3662
|
const id = useId();
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3663
|
+
let isReusedContext = true;
|
|
3664
|
+
let context = useMemo(() => {
|
|
3665
|
+
isReusedContext = false;
|
|
3666
|
+
return {
|
|
3667
|
+
id,
|
|
3668
|
+
initial,
|
|
3669
|
+
isPresent,
|
|
3670
|
+
custom,
|
|
3671
|
+
onExitComplete: (childId) => {
|
|
3672
|
+
presenceChildren.set(childId, true);
|
|
3673
|
+
for (const isComplete of presenceChildren.values()) {
|
|
3674
|
+
if (!isComplete)
|
|
3675
|
+
return; // can stop searching when any is incomplete
|
|
3676
|
+
}
|
|
3677
|
+
onExitComplete && onExitComplete();
|
|
3678
|
+
},
|
|
3679
|
+
register: (childId) => {
|
|
3680
|
+
presenceChildren.set(childId, false);
|
|
3681
|
+
return () => presenceChildren.delete(childId);
|
|
3682
|
+
},
|
|
3683
|
+
};
|
|
3684
|
+
}, [isPresent, presenceChildren, onExitComplete]);
|
|
3665
3685
|
/**
|
|
3666
3686
|
* If the presence of a child affects the layout of the components around it,
|
|
3667
3687
|
* we want to make a new context value to ensure they get re-rendered
|
|
3668
3688
|
* so they can detect that layout change.
|
|
3669
3689
|
*/
|
|
3670
|
-
presenceAffectsLayout
|
|
3671
|
-
|
|
3672
|
-
|
|
3690
|
+
if (presenceAffectsLayout && isReusedContext) {
|
|
3691
|
+
context = { ...context };
|
|
3692
|
+
}
|
|
3673
3693
|
useMemo(() => {
|
|
3674
3694
|
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
3675
3695
|
}, [isPresent]);
|
|
@@ -5576,7 +5596,7 @@ class MotionValue {
|
|
|
5576
5596
|
* This will be replaced by the build step with the latest version number.
|
|
5577
5597
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
5578
5598
|
*/
|
|
5579
|
-
this.version = "12.7.
|
|
5599
|
+
this.version = "12.7.4";
|
|
5580
5600
|
/**
|
|
5581
5601
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
5582
5602
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -13178,7 +13198,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
13178
13198
|
* and warn against mismatches.
|
|
13179
13199
|
*/
|
|
13180
13200
|
if (process.env.NODE_ENV === "development") {
|
|
13181
|
-
warnOnce(nextValue.version === "12.7.
|
|
13201
|
+
warnOnce(nextValue.version === "12.7.4", `Attempting to mix Motion versions ${nextValue.version} with 12.7.4 may not work as expected.`);
|
|
13182
13202
|
}
|
|
13183
13203
|
}
|
|
13184
13204
|
else if (isMotionValue(prevValue)) {
|
|
@@ -18218,6 +18238,7 @@ const customerSchema = z.object({
|
|
|
18218
18238
|
state: z.string().optional(),
|
|
18219
18239
|
zipCode: z.string().min(5, "invalid_zipCode"),
|
|
18220
18240
|
country: z.string().min(1, "required_error"),
|
|
18241
|
+
countryCode: z.string().min(1, "required_error"),
|
|
18221
18242
|
}),
|
|
18222
18243
|
saveInfo: z.boolean().optional(),
|
|
18223
18244
|
phone: z.string().regex(phoneRegex, "invalid_phone"),
|
|
@@ -18225,9 +18246,10 @@ const customerSchema = z.object({
|
|
|
18225
18246
|
// Shipping method schema
|
|
18226
18247
|
const shippingMethodSchema = z.object({
|
|
18227
18248
|
rateId: z.string().min(1, "required_error"),
|
|
18228
|
-
name: z.string().min(1, "required_error"),
|
|
18229
18249
|
provider: z.string().min(1, "required_error"),
|
|
18230
|
-
|
|
18250
|
+
price: z.number().min(1, "required_error"),
|
|
18251
|
+
name: z.string().min(1, "required_error"),
|
|
18252
|
+
pickupPointId: z.string().optional(),
|
|
18231
18253
|
});
|
|
18232
18254
|
// Combined checkout schema
|
|
18233
18255
|
z.object({
|
|
@@ -32599,6 +32621,7 @@ function AddressInput() {
|
|
|
32599
32621
|
React__default.createElement(FormLabel, null, t("CheckoutEmbed.CustomerForm.address.country")),
|
|
32600
32622
|
React__default.createElement(CountryDropdown, { placeholder: t("CheckoutEmbed.CustomerForm.address.countryPlaceholder"), defaultValue: field.value, onChange: (country) => {
|
|
32601
32623
|
field.onChange(country.name);
|
|
32624
|
+
form.setValue("address.countryCode", country.alpha2);
|
|
32602
32625
|
} }),
|
|
32603
32626
|
React__default.createElement(FormMessage, null))) })),
|
|
32604
32627
|
React__default.createElement(DialogFooter, null,
|
|
@@ -34119,7 +34142,7 @@ const useCheckout = create((set) => ({
|
|
|
34119
34142
|
setIsSubmitting: (isSubmitting) => set({ isSubmitting }),
|
|
34120
34143
|
}));
|
|
34121
34144
|
|
|
34122
|
-
const CheckoutForm$1 = ({ onSuccess, onError, children, }) => {
|
|
34145
|
+
const CheckoutForm$1 = ({ onSuccess, onError, children, setSubmitting, }) => {
|
|
34123
34146
|
const stripe = reactStripe_umdExports.useStripe();
|
|
34124
34147
|
const elements = reactStripe_umdExports.useElements();
|
|
34125
34148
|
const { setIsSubmitting } = useCheckout();
|
|
@@ -34129,6 +34152,7 @@ const CheckoutForm$1 = ({ onSuccess, onError, children, }) => {
|
|
|
34129
34152
|
if (!stripe || !elements) {
|
|
34130
34153
|
return;
|
|
34131
34154
|
}
|
|
34155
|
+
setSubmitting === null || setSubmitting === void 0 ? void 0 : setSubmitting(true);
|
|
34132
34156
|
setIsSubmitting(true);
|
|
34133
34157
|
const response = yield stripe.confirmPayment({
|
|
34134
34158
|
elements,
|
|
@@ -34137,15 +34161,18 @@ const CheckoutForm$1 = ({ onSuccess, onError, children, }) => {
|
|
|
34137
34161
|
if (response.error) {
|
|
34138
34162
|
setErrorMessage(response.error.message || "Something went wrong.");
|
|
34139
34163
|
setIsSubmitting(false);
|
|
34164
|
+
setSubmitting === null || setSubmitting === void 0 ? void 0 : setSubmitting(false);
|
|
34140
34165
|
onError === null || onError === void 0 ? void 0 : onError();
|
|
34141
34166
|
}
|
|
34142
34167
|
else {
|
|
34143
34168
|
setErrorMessage(undefined);
|
|
34144
34169
|
setIsSubmitting(false);
|
|
34170
|
+
setSubmitting === null || setSubmitting === void 0 ? void 0 : setSubmitting(false);
|
|
34145
34171
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess();
|
|
34146
34172
|
}
|
|
34147
34173
|
setErrorMessage(undefined);
|
|
34148
34174
|
setIsSubmitting(false);
|
|
34175
|
+
setSubmitting === null || setSubmitting === void 0 ? void 0 : setSubmitting(false);
|
|
34149
34176
|
});
|
|
34150
34177
|
return (React__default.createElement("form", { onSubmit: handleSubmit },
|
|
34151
34178
|
React__default.createElement("div", null,
|
|
@@ -34157,7 +34184,7 @@ var CheckoutForm$2 = memo$1(CheckoutForm$1);
|
|
|
34157
34184
|
|
|
34158
34185
|
const publicStripeKey = "pk_test_51RCjhw2cgbkVT71muwgBSw1tP06YVR4l4P9zI8wP2ipmze9VnTmTwxESVVePmU6QV8TL6bxG7f10oXQRnKC3F3KT00EsvlPAoS";
|
|
34159
34186
|
const stripePromise = loadStripe(publicStripeKey);
|
|
34160
|
-
function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSuccess, onError, children, }) {
|
|
34187
|
+
function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSuccess, onError, children, setSubmitting, }) {
|
|
34161
34188
|
const options = {
|
|
34162
34189
|
locale: locale !== null && locale !== void 0 ? locale : "en",
|
|
34163
34190
|
appearance: checkoutAppearance,
|
|
@@ -34165,11 +34192,12 @@ function PaymentElement({ paymentSecret, checkoutAppearance, locale, fonts, onSu
|
|
|
34165
34192
|
fonts: fonts,
|
|
34166
34193
|
};
|
|
34167
34194
|
return (React__default.createElement(reactStripe_umdExports.Elements, { stripe: stripePromise, options: options },
|
|
34168
|
-
React__default.createElement(CheckoutForm$2, { onSuccess: onSuccess, onError: onError, children: children })));
|
|
34195
|
+
React__default.createElement(CheckoutForm$2, { onSuccess: onSuccess, onError: onError, children: children, setSubmitting: setSubmitting })));
|
|
34169
34196
|
}
|
|
34170
34197
|
var PaymentElement$1 = memo$1(PaymentElement);
|
|
34171
34198
|
|
|
34172
34199
|
function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack, contactEmail, shippingAddress, shippingProvider, shippingPrice, checkoutAppearance, fonts, locale, }) {
|
|
34200
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
34173
34201
|
const { t } = useTranslation();
|
|
34174
34202
|
return (React__default.createElement("div", { className: "space-y-6" },
|
|
34175
34203
|
React__default.createElement("div", null,
|
|
@@ -34197,12 +34225,12 @@ function PaymentForm({ paymentSecret, onSuccess, onError, onBack, onDoubleBack,
|
|
|
34197
34225
|
" \u00B7 ",
|
|
34198
34226
|
shippingPrice)),
|
|
34199
34227
|
React__default.createElement(Button, { variant: "link", size: "link", onClick: onBack }, t("CheckoutEmbed.Shipping.change")))),
|
|
34200
|
-
React__default.createElement("div", { className: "mt-8" }, paymentSecret && (React__default.createElement(PaymentElement$1, { fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), locale: locale, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError },
|
|
34228
|
+
React__default.createElement("div", { className: "mt-8" }, paymentSecret && (React__default.createElement(PaymentElement$1, { fonts: fonts, checkoutAppearance: convertCheckoutAppearanceToStripeAppearance(checkoutAppearance, fonts), locale: locale, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, setSubmitting: setIsSubmitting },
|
|
34201
34229
|
React__default.createElement("div", { className: "flex justify-between items-center pt-8" },
|
|
34202
34230
|
React__default.createElement(Button, { type: "button", variant: "ghost", onClick: onBack },
|
|
34203
34231
|
React__default.createElement(ChevronLeft, null),
|
|
34204
34232
|
t("CheckoutEmbed.Payment.back")),
|
|
34205
|
-
React__default.createElement(SubmitButton, { isValid: true, isSubmitting:
|
|
34233
|
+
React__default.createElement(SubmitButton, { isValid: true, isSubmitting: isSubmitting }, t("CheckoutEmbed.Payment.button"))))))));
|
|
34206
34234
|
}
|
|
34207
34235
|
|
|
34208
34236
|
function Skeleton(_a) {
|
|
@@ -34210,16 +34238,62 @@ function Skeleton(_a) {
|
|
|
34210
34238
|
return (React.createElement("div", Object.assign({ "data-slot": "skeleton", className: cn("bg-accent animate-pulse rounded-md", className) }, props)));
|
|
34211
34239
|
}
|
|
34212
34240
|
|
|
34213
|
-
function
|
|
34241
|
+
function ZasilkovnaShippingOption({ children, onPickupPointSelected, locale, countryCode, apiKey, }) {
|
|
34242
|
+
const [widgetLoaded, setWidgetLoaded] = useState(false);
|
|
34243
|
+
useEffect(() => {
|
|
34244
|
+
// Check if the script is already present
|
|
34245
|
+
if (!document.querySelector('script[src="https://widget.packeta.com/v6/www/js/library.js"]')) {
|
|
34246
|
+
const script = document.createElement("script");
|
|
34247
|
+
script.src = "https://widget.packeta.com/v6/www/js/library.js";
|
|
34248
|
+
script.async = true;
|
|
34249
|
+
script.onload = () => {
|
|
34250
|
+
setWidgetLoaded(true);
|
|
34251
|
+
console.log("loaded");
|
|
34252
|
+
};
|
|
34253
|
+
script.onerror = () => console.error("Failed to load Packeta Widget script.");
|
|
34254
|
+
document.body.appendChild(script);
|
|
34255
|
+
}
|
|
34256
|
+
else {
|
|
34257
|
+
setWidgetLoaded(true);
|
|
34258
|
+
}
|
|
34259
|
+
}, []);
|
|
34260
|
+
const handleClick = () => {
|
|
34261
|
+
if (widgetLoaded && window.Packeta && window.Packeta.Widget) {
|
|
34262
|
+
const options = {
|
|
34263
|
+
language: locale,
|
|
34264
|
+
country: countryCode,
|
|
34265
|
+
view: "modal",
|
|
34266
|
+
valueFormat: "id,name,city,street",
|
|
34267
|
+
};
|
|
34268
|
+
window.Packeta.Widget.pick(apiKey, (point) => {
|
|
34269
|
+
onPickupPointSelected === null || onPickupPointSelected === void 0 ? void 0 : onPickupPointSelected(point.id);
|
|
34270
|
+
}, options);
|
|
34271
|
+
}
|
|
34272
|
+
else {
|
|
34273
|
+
console.error("Packeta widget not found", window);
|
|
34274
|
+
}
|
|
34275
|
+
};
|
|
34276
|
+
return (React__default.createElement(React__default.Fragment, null,
|
|
34277
|
+
React__default.createElement("div", { onClick: () => handleClick() }, children)));
|
|
34278
|
+
}
|
|
34279
|
+
|
|
34280
|
+
function ShippingOptionWrapper({ rate, children, onPickupPointSelected, locale, countryCode, }) {
|
|
34281
|
+
if (rate.provider === "zasilkovna") {
|
|
34282
|
+
return (React__default.createElement(ZasilkovnaShippingOption, { onPickupPointSelected: onPickupPointSelected, locale: locale, countryCode: countryCode, apiKey: rate.clientSecret }, children));
|
|
34283
|
+
}
|
|
34284
|
+
return;
|
|
34285
|
+
}
|
|
34286
|
+
|
|
34287
|
+
function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, contactEmail, shippingAddress, currency, exchangeRate, locale, countryCode, }) {
|
|
34214
34288
|
var _a;
|
|
34215
34289
|
const { t } = useTranslation();
|
|
34216
34290
|
const form = useForm({
|
|
34217
34291
|
resolver: s$1(shippingMethodSchema),
|
|
34218
34292
|
defaultValues: initialData || {
|
|
34219
34293
|
rateId: "",
|
|
34220
|
-
name: "",
|
|
34221
34294
|
provider: "",
|
|
34222
|
-
|
|
34295
|
+
price: 0,
|
|
34296
|
+
pickupPointId: "",
|
|
34223
34297
|
},
|
|
34224
34298
|
});
|
|
34225
34299
|
const currentRateId = form.watch("rateId");
|
|
@@ -34243,28 +34317,27 @@ function ShippingMethodForm({ shippingRates, initialData, onSubmit, onBack, cont
|
|
|
34243
34317
|
shippingRates.length === 0 &&
|
|
34244
34318
|
Array.from({ length: 3 }).map((_, index) => (React__default.createElement(ShippingRateLoading, { key: index }))),
|
|
34245
34319
|
shippingRates.map((rate) => {
|
|
34246
|
-
const rateId = rate.
|
|
34247
|
-
const intPrice = Math.ceil(Number(rate.
|
|
34248
|
-
const
|
|
34249
|
-
|
|
34250
|
-
|
|
34251
|
-
|
|
34252
|
-
|
|
34253
|
-
form.setValue("
|
|
34254
|
-
|
|
34255
|
-
|
|
34256
|
-
|
|
34257
|
-
|
|
34258
|
-
|
|
34259
|
-
|
|
34260
|
-
|
|
34261
|
-
|
|
34262
|
-
|
|
34263
|
-
|
|
34264
|
-
|
|
34265
|
-
|
|
34266
|
-
|
|
34267
|
-
: t("CheckoutEmbed.Shipping.days")))));
|
|
34320
|
+
const rateId = rate.provider + rate.name;
|
|
34321
|
+
const intPrice = Math.ceil(Number(rate.price));
|
|
34322
|
+
const displayPrice = storeHelpers.formatPrice(intPrice, currency, exchangeRate);
|
|
34323
|
+
const description = rate.provider === "zasilkovna"
|
|
34324
|
+
? t("CheckoutEmbed.Shipping.description.zasilkovna")
|
|
34325
|
+
: t("CheckoutEmbed.Shipping.description.other");
|
|
34326
|
+
return (React__default.createElement(ShippingOptionWrapper, { rate: rate, key: rateId, onPickupPointSelected: (pickupPointId) => {
|
|
34327
|
+
form.setValue("pickupPointId", pickupPointId);
|
|
34328
|
+
}, locale: locale, countryCode: countryCode },
|
|
34329
|
+
React__default.createElement("div", { className: clsx("p-4 cursor-pointer rounded-md border bg-background", {
|
|
34330
|
+
"bg-muted border-primary": currentRateId === rateId,
|
|
34331
|
+
}), onClick: () => {
|
|
34332
|
+
form.setValue("rateId", rateId);
|
|
34333
|
+
form.setValue("provider", rate.provider);
|
|
34334
|
+
form.setValue("name", rate.name);
|
|
34335
|
+
form.setValue("price", intPrice);
|
|
34336
|
+
} },
|
|
34337
|
+
React__default.createElement("div", { className: "flex items-center justify-between w-full" },
|
|
34338
|
+
React__default.createElement("p", null, rate.name),
|
|
34339
|
+
React__default.createElement("p", null, displayPrice)),
|
|
34340
|
+
React__default.createElement("p", { className: "text-sm text-muted-foreground" }, description))));
|
|
34268
34341
|
}),
|
|
34269
34342
|
React__default.createElement(FormMessage, null, (_a = form.formState.errors.rateId) === null || _a === void 0 ? void 0 : _a.message),
|
|
34270
34343
|
React__default.createElement("div", { className: "flex justify-between items-center pt-4" },
|
|
@@ -34294,7 +34367,7 @@ const motionSettings = {
|
|
|
34294
34367
|
exit: { opacity: 0 },
|
|
34295
34368
|
transition: { duration: 0.2 },
|
|
34296
34369
|
};
|
|
34297
|
-
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, }) {
|
|
34370
|
+
function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl, clientSecret, customer, currency, checkoutAppearance, fonts, locale, setShippingCost, exchangeRate, }) {
|
|
34298
34371
|
const { formData, setFormData, step, setStep } = useFormStore(checkoutId)();
|
|
34299
34372
|
const [paymentSecret, setPaymentSecret] = useState(null);
|
|
34300
34373
|
const [shippingRates, setShippingRates] = useState([]);
|
|
@@ -34318,7 +34391,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34318
34391
|
validateStep();
|
|
34319
34392
|
}, [step]);
|
|
34320
34393
|
useEffect(() => {
|
|
34321
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
34394
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
34322
34395
|
if (customer && !((_a = formData.customer) === null || _a === void 0 ? void 0 : _a.email)) {
|
|
34323
34396
|
setFormData(Object.assign(Object.assign({}, formData), { customerId: customer.id, customer: {
|
|
34324
34397
|
firstName: (_d = (_c = (_b = customer.address) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.split(" ")[0]) !== null && _d !== void 0 ? _d : "",
|
|
@@ -34331,6 +34404,7 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34331
34404
|
city: (_r = (_q = customer.address) === null || _q === void 0 ? void 0 : _q.city) !== null && _r !== void 0 ? _r : "",
|
|
34332
34405
|
zipCode: (_t = (_s = customer.address) === null || _s === void 0 ? void 0 : _s.zipCode) !== null && _t !== void 0 ? _t : "",
|
|
34333
34406
|
country: (_v = (_u = customer.address) === null || _u === void 0 ? void 0 : _u.country) !== null && _v !== void 0 ? _v : "",
|
|
34407
|
+
countryCode: (_x = (_w = customer.address) === null || _w === void 0 ? void 0 : _w.countryCode) !== null && _x !== void 0 ? _x : "",
|
|
34334
34408
|
},
|
|
34335
34409
|
} }));
|
|
34336
34410
|
}
|
|
@@ -34342,12 +34416,14 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34342
34416
|
return;
|
|
34343
34417
|
const getShippingRates = () => __awaiter(this, void 0, void 0, function* () {
|
|
34344
34418
|
const shippingRates = yield storeClient.getCheckoutShippingRates(clientSecret, checkoutId);
|
|
34419
|
+
console.log(shippingRates);
|
|
34345
34420
|
setShippingRates(shippingRates);
|
|
34346
34421
|
});
|
|
34347
34422
|
getShippingRates();
|
|
34348
34423
|
}, [step, shippingRates]);
|
|
34349
34424
|
// Handle address form submission
|
|
34350
34425
|
const handleCustomerSubmit = (data) => __awaiter(this, void 0, void 0, function* () {
|
|
34426
|
+
setFormData(Object.assign(Object.assign({}, formData), { customer: data }));
|
|
34351
34427
|
let newCustomerId = formData.customerId;
|
|
34352
34428
|
if (!newCustomerId) {
|
|
34353
34429
|
const newCustomer = yield storeClient.createCustomer(clientSecret, {
|
|
@@ -34381,16 +34457,15 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34381
34457
|
const newFormData = Object.assign(Object.assign({}, formData), { shipping: data });
|
|
34382
34458
|
setFormData(newFormData);
|
|
34383
34459
|
yield storeClient.updateCheckout(clientSecret, checkoutId, {
|
|
34384
|
-
shipping: data.
|
|
34385
|
-
|
|
34386
|
-
rateId: data.rateId,
|
|
34387
|
-
name: data.name,
|
|
34460
|
+
shipping: data.price,
|
|
34461
|
+
shipmentInfo: {
|
|
34388
34462
|
provider: data.provider,
|
|
34463
|
+
pickupPointId: data.pickupPointId,
|
|
34389
34464
|
},
|
|
34390
34465
|
});
|
|
34391
34466
|
const paymentSecret = yield storeClient.generateCheckoutsPaymentSecret(clientSecret, checkoutId);
|
|
34392
34467
|
setPaymentSecret(paymentSecret);
|
|
34393
|
-
setShippingCost(data.
|
|
34468
|
+
setShippingCost(data.price);
|
|
34394
34469
|
setStep("payment");
|
|
34395
34470
|
});
|
|
34396
34471
|
// Navigate back to previous step
|
|
@@ -34420,9 +34495,9 @@ function CheckoutForm({ storeClient, checkoutId, onSuccess, onError, cancelUrl,
|
|
|
34420
34495
|
step === "customer" && (React__default.createElement(motion.div, Object.assign({ key: "customer" }, motionSettings, { className: "absolute w-full" }),
|
|
34421
34496
|
React__default.createElement(CustomerForm, { initialData: formData.customer, onSubmit: handleCustomerSubmit }))),
|
|
34422
34497
|
step === "shipping" && formData.customer && (React__default.createElement(motion.div, Object.assign({ key: "shipping" }, motionSettings, { className: "absolute w-full" }),
|
|
34423
|
-
React__default.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address) }))),
|
|
34498
|
+
React__default.createElement(ShippingMethodForm, { shippingRates: shippingRates, initialData: formData.shipping, onSubmit: handleShippingSubmit, onBack: handleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), currency: currency, exchangeRate: exchangeRate, locale: locale, countryCode: formData.customer.address.countryCode }))),
|
|
34424
34499
|
step === "payment" && formData.customer && formData.shipping && (React__default.createElement(motion.div, Object.assign({ key: "payment" }, motionSettings, { className: "absolute w-full" }),
|
|
34425
|
-
React__default.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: formData.shipping.
|
|
34500
|
+
React__default.createElement(PaymentForm, { locale: locale, fonts: fonts, checkoutAppearance: checkoutAppearance, paymentSecret: paymentSecret, onSuccess: onSuccess, onError: onError, onBack: handleBack, onDoubleBack: handleDoubleBack, contactEmail: formData.customer.email, shippingAddress: formatAddress(formData.customer.address), shippingProvider: formData.shipping.provider, shippingPrice: storeHelpers.formatPrice(formData.shipping.price, currency, exchangeRate) }))))));
|
|
34426
34501
|
}
|
|
34427
34502
|
|
|
34428
34503
|
function CheckoutFormLoading() {
|
|
@@ -34444,8 +34519,6 @@ function InputGroupLoading({ className }) {
|
|
|
34444
34519
|
React__default.createElement(Skeleton, { className: "w-full h-9" })));
|
|
34445
34520
|
}
|
|
34446
34521
|
|
|
34447
|
-
const storeHelpers = createStoreHelpers();
|
|
34448
|
-
|
|
34449
34522
|
function CheckoutSummary({ lineItems, shipping, tax, currency, cancelUrl, exchangeRate, }) {
|
|
34450
34523
|
const [isOpen, setIsOpen] = useState(false);
|
|
34451
34524
|
const { t } = useTranslation();
|
|
@@ -34536,7 +34609,7 @@ function CheckoutSummaryLoading() {
|
|
|
34536
34609
|
}
|
|
34537
34610
|
|
|
34538
34611
|
function CheckoutEmbed({ checkoutId, config }) {
|
|
34539
|
-
var _a, _b, _c, _d;
|
|
34612
|
+
var _a, _b, _c, _d, _e;
|
|
34540
34613
|
const { cancelUrl, successUrl, appearance, locale, clientSecret, clientProxy, } = config;
|
|
34541
34614
|
const storeClient = createStoreClient({ proxy: clientProxy });
|
|
34542
34615
|
React__default.useMemo(() => createI18nInstance(locale), []);
|
|
@@ -34585,10 +34658,10 @@ function CheckoutEmbed({ checkoutId, config }) {
|
|
|
34585
34658
|
return;
|
|
34586
34659
|
setCheckout(Object.assign(Object.assign({}, checkout), { shipping: cost }));
|
|
34587
34660
|
};
|
|
34588
|
-
return (React__default.createElement("div", { className: "checkout-embed mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
|
|
34661
|
+
return (React__default.createElement("div", { className: "checkout-embed scrollbar-hidden mx-auto max-w-[1200px] min-h-screen overflow-x-hidden gap-6 md:gap-0 py-4 md:py-12 flex flex-col md:grid md:grid-cols-7 " },
|
|
34589
34662
|
React__default.createElement(Appearance, { appearance: appearance }),
|
|
34590
|
-
React__default.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React__default.createElement(CheckoutFormLoading, null)) : (React__default.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError }))),
|
|
34591
|
-
React__default.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React__default.createElement(CheckoutSummaryLoading, null)) : (React__default.createElement(CheckoutSummary, { currency: (
|
|
34663
|
+
React__default.createElement("div", { className: "md:col-span-4 px-4 md:px-8" }, loading ? (React__default.createElement(CheckoutFormLoading, null)) : (React__default.createElement(CheckoutForm, { locale: locale, setShippingCost: setShippingCost, storeClient: storeClient, fonts: config.fonts, checkoutAppearance: appearance, currency: (_a = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _a !== void 0 ? _a : "", customer: checkout === null || checkout === void 0 ? void 0 : checkout.customer, cancelUrl: cancelUrl, checkoutId: checkoutId, clientSecret: clientSecret, onSuccess: onSuccess, onError: onError, exchangeRate: (_b = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _b !== void 0 ? _b : 1 }))),
|
|
34664
|
+
React__default.createElement("div", { className: "md:col-span-3 px-4 md:px-8 order-first md:order-last" }, loading ? (React__default.createElement(CheckoutSummaryLoading, null)) : (React__default.createElement(CheckoutSummary, { currency: (_c = checkout === null || checkout === void 0 ? void 0 : checkout.currency) !== null && _c !== void 0 ? _c : "", lineItems: (_d = checkout === null || checkout === void 0 ? void 0 : checkout.lineItems) !== null && _d !== void 0 ? _d : [], shipping: checkout === null || checkout === void 0 ? void 0 : checkout.shipping, tax: checkout === null || checkout === void 0 ? void 0 : checkout.tax, cancelUrl: cancelUrl, exchangeRate: (_e = checkout === null || checkout === void 0 ? void 0 : checkout.exchangeRate) !== null && _e !== void 0 ? _e : 1 })))));
|
|
34592
34665
|
}
|
|
34593
34666
|
var index = memo$1(CheckoutEmbed);
|
|
34594
34667
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterstore/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.38",
|
|
4
4
|
"description": "E-commerce for Developers",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"author": "Better Store",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@betterstore/sdk": "^0.3.
|
|
22
|
+
"@betterstore/sdk": "^0.3.31",
|
|
23
23
|
"@changesets/cli": "^2.28.1",
|
|
24
24
|
"@rollup/plugin-commonjs": "^28.0.3",
|
|
25
25
|
"@rollup/plugin-json": "^6.1.0",
|