@springmicro/cart 0.3.0 → 0.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/.eslintrc.cjs +21 -21
- package/README.md +64 -64
- package/dist/index.js +2327 -2322
- package/dist/index.umd.cjs +61 -61
- package/package.json +5 -3
- package/src/AddToCartForm.tsx +16 -16
- package/src/CartButton.tsx +249 -249
- package/src/ProductCard.css +106 -106
- package/src/ProductCard.tsx +165 -165
- package/src/checkout/CheckoutList.css +93 -93
- package/src/checkout/CheckoutList.tsx +272 -264
- package/src/checkout/components/Address.tsx +265 -265
- package/src/checkout/components/Billing.tsx +353 -353
- package/src/checkout/components/CartProductCard.css +67 -67
- package/src/checkout/components/CartProductCard.tsx +80 -80
- package/src/checkout/components/Order.tsx +95 -93
- package/src/checkout/components/ProviderLogos.tsx +93 -93
- package/src/checkout/components/index.tsx +104 -104
- package/src/index.css +5 -5
- package/src/index.ts +35 -35
- package/src/types.d.ts +56 -56
- package/src/utils/api.ts +67 -67
- package/src/utils/cartAuthHandler.ts +50 -50
- package/src/utils/index.ts +28 -28
- package/src/utils/storage.ts +133 -133
- package/tsconfig.json +24 -24
- package/tsconfig.node.json +11 -11
- package/vite.config.ts +25 -25
- package/springmicro-cart-0.2.3.tgz +0 -0
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import { createSvgIcon } from "@mui/material";
|
|
2
|
-
// Source: https://brandfolder.com/s/99gctvbpwgvzbc7mz3j9g4x
|
|
3
|
-
|
|
4
|
-
export const PoweredByStripe = createSvgIcon(
|
|
5
|
-
<svg
|
|
6
|
-
id="Layer_1"
|
|
7
|
-
data-name="Layer 1"
|
|
8
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
9
|
-
viewBox="0 0 150 34"
|
|
10
|
-
>
|
|
11
|
-
<defs>
|
|
12
|
-
<style>{`.cls-1{fill: #635bff}`}</style>
|
|
13
|
-
</defs>
|
|
14
|
-
<title>Powered by Stripe - blurple</title>
|
|
15
|
-
<path
|
|
16
|
-
className="cls-1"
|
|
17
|
-
d="M146,0H3.73A3.73,3.73,0,0,0,0,3.73V30.27A3.73,3.73,0,0,0,3.73,34H146a4,4,0,0,0,4-4V4A4,4,0,0,0,146,0Zm3,30a3,3,0,0,1-3,3H3.73A2.74,2.74,0,0,1,1,30.27V3.73A2.74,2.74,0,0,1,3.73,1H146a3,3,0,0,1,3,3Z"
|
|
18
|
-
/>
|
|
19
|
-
<path
|
|
20
|
-
className="cls-1"
|
|
21
|
-
d="M17.07,11.24h-4.3V22h1.92V17.84h2.38c2.4,0,3.9-1.16,3.9-3.3S19.47,11.24,17.07,11.24Zm-.1,5H14.69v-3.3H17c1.38,0,2.11.59,2.11,1.65S18.35,16.19,17,16.19Z"
|
|
22
|
-
/>
|
|
23
|
-
<path
|
|
24
|
-
className="cls-1"
|
|
25
|
-
d="M25.1,14a3.77,3.77,0,0,0-3.8,4.09,3.81,3.81,0,1,0,7.59,0A3.76,3.76,0,0,0,25.1,14Zm0,6.67c-1.22,0-2-1-2-2.58s.76-2.58,2-2.58,2,1,2,2.58S26.31,20.66,25.1,20.66Z"
|
|
26
|
-
/>
|
|
27
|
-
<polygon
|
|
28
|
-
className="cls-1"
|
|
29
|
-
points="36.78 19.35 35.37 14.13 33.89 14.13 32.49 19.35 31.07 14.13 29.22 14.13 31.59 22.01 33.15 22.01 34.59 16.85 36.03 22.01 37.59 22.01 39.96 14.13 38.18 14.13 36.78 19.35"
|
|
30
|
-
/>
|
|
31
|
-
<path
|
|
32
|
-
className="cls-1"
|
|
33
|
-
d="M44,14a3.83,3.83,0,0,0-3.75,4.09,3.79,3.79,0,0,0,3.83,4.09A3.47,3.47,0,0,0,47.49,20L46,19.38a1.78,1.78,0,0,1-1.83,1.26A2.12,2.12,0,0,1,42,18.47h5.52v-.6C47.54,15.71,46.32,14,44,14Zm-1.93,3.13A1.92,1.92,0,0,1,44,15.5a1.56,1.56,0,0,1,1.69,1.62Z"
|
|
34
|
-
/>
|
|
35
|
-
<path
|
|
36
|
-
className="cls-1"
|
|
37
|
-
d="M50.69,15.3V14.13h-1.8V22h1.8V17.87a1.89,1.89,0,0,1,2-2,4.68,4.68,0,0,1,.66,0v-1.8c-.14,0-.3,0-.51,0A2.29,2.29,0,0,0,50.69,15.3Z"
|
|
38
|
-
/>
|
|
39
|
-
<path
|
|
40
|
-
className="cls-1"
|
|
41
|
-
d="M57.48,14a3.83,3.83,0,0,0-3.75,4.09,3.79,3.79,0,0,0,3.83,4.09A3.47,3.47,0,0,0,60.93,20l-1.54-.59a1.78,1.78,0,0,1-1.83,1.26,2.12,2.12,0,0,1-2.1-2.17H61v-.6C61,15.71,59.76,14,57.48,14Zm-1.93,3.13a1.92,1.92,0,0,1,1.92-1.62,1.56,1.56,0,0,1,1.69,1.62Z"
|
|
42
|
-
/>
|
|
43
|
-
<path
|
|
44
|
-
className="cls-1"
|
|
45
|
-
d="M67.56,15a2.85,2.85,0,0,0-2.26-1c-2.21,0-3.47,1.85-3.47,4.09s1.26,4.09,3.47,4.09a2.82,2.82,0,0,0,2.26-1V22h1.8V11.24h-1.8Zm0,3.35a2,2,0,0,1-2,2.28c-1.31,0-2-1-2-2.52s.7-2.52,2-2.52c1.11,0,2,.81,2,2.29Z"
|
|
46
|
-
/>
|
|
47
|
-
<path
|
|
48
|
-
className="cls-1"
|
|
49
|
-
d="M79.31,14A2.88,2.88,0,0,0,77,15V11.24h-1.8V22H77v-.83a2.86,2.86,0,0,0,2.27,1c2.2,0,3.46-1.86,3.46-4.09S81.51,14,79.31,14ZM79,20.6a2,2,0,0,1-2-2.28v-.47c0-1.48.84-2.29,2-2.29,1.3,0,2,1,2,2.52S80.25,20.6,79,20.6Z"
|
|
50
|
-
/>
|
|
51
|
-
<path
|
|
52
|
-
className="cls-1"
|
|
53
|
-
d="M86.93,19.66,85,14.13H83.1L86,21.72l-.3.74a1,1,0,0,1-1.14.79,4.12,4.12,0,0,1-.6,0v1.51a4.62,4.62,0,0,0,.73.05,2.67,2.67,0,0,0,2.78-2l3.24-8.62H88.82Z"
|
|
54
|
-
/>
|
|
55
|
-
<path
|
|
56
|
-
className="cls-1"
|
|
57
|
-
d="M125,12.43a3,3,0,0,0-2.13.87l-.14-.69h-2.39V25.53l2.72-.59V21.81a3,3,0,0,0,1.93.7c1.94,0,3.72-1.59,3.72-5.11C128.71,14.18,126.91,12.43,125,12.43Zm-.65,7.63a1.61,1.61,0,0,1-1.28-.52l0-4.11a1.64,1.64,0,0,1,1.3-.55c1,0,1.68,1.13,1.68,2.58S125.36,20.06,124.35,20.06Z"
|
|
58
|
-
/>
|
|
59
|
-
<path
|
|
60
|
-
className="cls-1"
|
|
61
|
-
d="M133.73,12.43c-2.62,0-4.21,2.26-4.21,5.11,0,3.37,1.88,5.08,4.56,5.08a6.12,6.12,0,0,0,3-.73V19.64a5.79,5.79,0,0,1-2.7.62c-1.08,0-2-.39-2.14-1.7h5.38c0-.15,0-.74,0-1C137.71,14.69,136.35,12.43,133.73,12.43Zm-1.47,4.07c0-1.26.77-1.79,1.45-1.79s1.4.53,1.4,1.79Z"
|
|
62
|
-
/>
|
|
63
|
-
<path
|
|
64
|
-
className="cls-1"
|
|
65
|
-
d="M113,13.36l-.17-.82h-2.32v9.71h2.68V15.67a1.87,1.87,0,0,1,2.05-.58V12.54A1.8,1.8,0,0,0,113,13.36Z"
|
|
66
|
-
/>
|
|
67
|
-
<path
|
|
68
|
-
className="cls-1"
|
|
69
|
-
d="M99.46,15.46c0-.44.36-.61.93-.61a5.9,5.9,0,0,1,2.7.72V12.94a7,7,0,0,0-2.7-.51c-2.21,0-3.68,1.18-3.68,3.16,0,3.1,4.14,2.6,4.14,3.93,0,.52-.44.69-1,.69a6.78,6.78,0,0,1-3-.9V22a7.38,7.38,0,0,0,3,.64c2.26,0,3.82-1.15,3.82-3.16C103.62,16.12,99.46,16.72,99.46,15.46Z"
|
|
70
|
-
/>
|
|
71
|
-
<path
|
|
72
|
-
className="cls-1"
|
|
73
|
-
d="M107.28,10.24l-2.65.58v8.93a2.77,2.77,0,0,0,2.82,2.87,4.16,4.16,0,0,0,1.91-.37V20c-.35.15-2.06.66-2.06-1V15h2.06V12.66h-2.06Z"
|
|
74
|
-
/>
|
|
75
|
-
<polygon
|
|
76
|
-
className="cls-1"
|
|
77
|
-
points="116.25 11.7 118.98 11.13 118.98 8.97 116.25 9.54 116.25 11.7"
|
|
78
|
-
/>
|
|
79
|
-
<rect className="cls-1" x="116.25" y="12.61" width="2.73" height="9.64" />
|
|
80
|
-
</svg>,
|
|
81
|
-
"PoweredByStripe"
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
export const StripeLogoLink = ({ height }: { height?: string }) => {
|
|
85
|
-
return (
|
|
86
|
-
<a href="https://stripe.com" target="_blank">
|
|
87
|
-
<PoweredByStripe
|
|
88
|
-
sx={{ width: "unset", height: height || "1em" }}
|
|
89
|
-
viewBox="0 0 150 34"
|
|
90
|
-
/>
|
|
91
|
-
</a>
|
|
92
|
-
);
|
|
93
|
-
};
|
|
1
|
+
import { createSvgIcon } from "@mui/material";
|
|
2
|
+
// Source: https://brandfolder.com/s/99gctvbpwgvzbc7mz3j9g4x
|
|
3
|
+
|
|
4
|
+
export const PoweredByStripe = createSvgIcon(
|
|
5
|
+
<svg
|
|
6
|
+
id="Layer_1"
|
|
7
|
+
data-name="Layer 1"
|
|
8
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
9
|
+
viewBox="0 0 150 34"
|
|
10
|
+
>
|
|
11
|
+
<defs>
|
|
12
|
+
<style>{`.cls-1{fill: #635bff}`}</style>
|
|
13
|
+
</defs>
|
|
14
|
+
<title>Powered by Stripe - blurple</title>
|
|
15
|
+
<path
|
|
16
|
+
className="cls-1"
|
|
17
|
+
d="M146,0H3.73A3.73,3.73,0,0,0,0,3.73V30.27A3.73,3.73,0,0,0,3.73,34H146a4,4,0,0,0,4-4V4A4,4,0,0,0,146,0Zm3,30a3,3,0,0,1-3,3H3.73A2.74,2.74,0,0,1,1,30.27V3.73A2.74,2.74,0,0,1,3.73,1H146a3,3,0,0,1,3,3Z"
|
|
18
|
+
/>
|
|
19
|
+
<path
|
|
20
|
+
className="cls-1"
|
|
21
|
+
d="M17.07,11.24h-4.3V22h1.92V17.84h2.38c2.4,0,3.9-1.16,3.9-3.3S19.47,11.24,17.07,11.24Zm-.1,5H14.69v-3.3H17c1.38,0,2.11.59,2.11,1.65S18.35,16.19,17,16.19Z"
|
|
22
|
+
/>
|
|
23
|
+
<path
|
|
24
|
+
className="cls-1"
|
|
25
|
+
d="M25.1,14a3.77,3.77,0,0,0-3.8,4.09,3.81,3.81,0,1,0,7.59,0A3.76,3.76,0,0,0,25.1,14Zm0,6.67c-1.22,0-2-1-2-2.58s.76-2.58,2-2.58,2,1,2,2.58S26.31,20.66,25.1,20.66Z"
|
|
26
|
+
/>
|
|
27
|
+
<polygon
|
|
28
|
+
className="cls-1"
|
|
29
|
+
points="36.78 19.35 35.37 14.13 33.89 14.13 32.49 19.35 31.07 14.13 29.22 14.13 31.59 22.01 33.15 22.01 34.59 16.85 36.03 22.01 37.59 22.01 39.96 14.13 38.18 14.13 36.78 19.35"
|
|
30
|
+
/>
|
|
31
|
+
<path
|
|
32
|
+
className="cls-1"
|
|
33
|
+
d="M44,14a3.83,3.83,0,0,0-3.75,4.09,3.79,3.79,0,0,0,3.83,4.09A3.47,3.47,0,0,0,47.49,20L46,19.38a1.78,1.78,0,0,1-1.83,1.26A2.12,2.12,0,0,1,42,18.47h5.52v-.6C47.54,15.71,46.32,14,44,14Zm-1.93,3.13A1.92,1.92,0,0,1,44,15.5a1.56,1.56,0,0,1,1.69,1.62Z"
|
|
34
|
+
/>
|
|
35
|
+
<path
|
|
36
|
+
className="cls-1"
|
|
37
|
+
d="M50.69,15.3V14.13h-1.8V22h1.8V17.87a1.89,1.89,0,0,1,2-2,4.68,4.68,0,0,1,.66,0v-1.8c-.14,0-.3,0-.51,0A2.29,2.29,0,0,0,50.69,15.3Z"
|
|
38
|
+
/>
|
|
39
|
+
<path
|
|
40
|
+
className="cls-1"
|
|
41
|
+
d="M57.48,14a3.83,3.83,0,0,0-3.75,4.09,3.79,3.79,0,0,0,3.83,4.09A3.47,3.47,0,0,0,60.93,20l-1.54-.59a1.78,1.78,0,0,1-1.83,1.26,2.12,2.12,0,0,1-2.1-2.17H61v-.6C61,15.71,59.76,14,57.48,14Zm-1.93,3.13a1.92,1.92,0,0,1,1.92-1.62,1.56,1.56,0,0,1,1.69,1.62Z"
|
|
42
|
+
/>
|
|
43
|
+
<path
|
|
44
|
+
className="cls-1"
|
|
45
|
+
d="M67.56,15a2.85,2.85,0,0,0-2.26-1c-2.21,0-3.47,1.85-3.47,4.09s1.26,4.09,3.47,4.09a2.82,2.82,0,0,0,2.26-1V22h1.8V11.24h-1.8Zm0,3.35a2,2,0,0,1-2,2.28c-1.31,0-2-1-2-2.52s.7-2.52,2-2.52c1.11,0,2,.81,2,2.29Z"
|
|
46
|
+
/>
|
|
47
|
+
<path
|
|
48
|
+
className="cls-1"
|
|
49
|
+
d="M79.31,14A2.88,2.88,0,0,0,77,15V11.24h-1.8V22H77v-.83a2.86,2.86,0,0,0,2.27,1c2.2,0,3.46-1.86,3.46-4.09S81.51,14,79.31,14ZM79,20.6a2,2,0,0,1-2-2.28v-.47c0-1.48.84-2.29,2-2.29,1.3,0,2,1,2,2.52S80.25,20.6,79,20.6Z"
|
|
50
|
+
/>
|
|
51
|
+
<path
|
|
52
|
+
className="cls-1"
|
|
53
|
+
d="M86.93,19.66,85,14.13H83.1L86,21.72l-.3.74a1,1,0,0,1-1.14.79,4.12,4.12,0,0,1-.6,0v1.51a4.62,4.62,0,0,0,.73.05,2.67,2.67,0,0,0,2.78-2l3.24-8.62H88.82Z"
|
|
54
|
+
/>
|
|
55
|
+
<path
|
|
56
|
+
className="cls-1"
|
|
57
|
+
d="M125,12.43a3,3,0,0,0-2.13.87l-.14-.69h-2.39V25.53l2.72-.59V21.81a3,3,0,0,0,1.93.7c1.94,0,3.72-1.59,3.72-5.11C128.71,14.18,126.91,12.43,125,12.43Zm-.65,7.63a1.61,1.61,0,0,1-1.28-.52l0-4.11a1.64,1.64,0,0,1,1.3-.55c1,0,1.68,1.13,1.68,2.58S125.36,20.06,124.35,20.06Z"
|
|
58
|
+
/>
|
|
59
|
+
<path
|
|
60
|
+
className="cls-1"
|
|
61
|
+
d="M133.73,12.43c-2.62,0-4.21,2.26-4.21,5.11,0,3.37,1.88,5.08,4.56,5.08a6.12,6.12,0,0,0,3-.73V19.64a5.79,5.79,0,0,1-2.7.62c-1.08,0-2-.39-2.14-1.7h5.38c0-.15,0-.74,0-1C137.71,14.69,136.35,12.43,133.73,12.43Zm-1.47,4.07c0-1.26.77-1.79,1.45-1.79s1.4.53,1.4,1.79Z"
|
|
62
|
+
/>
|
|
63
|
+
<path
|
|
64
|
+
className="cls-1"
|
|
65
|
+
d="M113,13.36l-.17-.82h-2.32v9.71h2.68V15.67a1.87,1.87,0,0,1,2.05-.58V12.54A1.8,1.8,0,0,0,113,13.36Z"
|
|
66
|
+
/>
|
|
67
|
+
<path
|
|
68
|
+
className="cls-1"
|
|
69
|
+
d="M99.46,15.46c0-.44.36-.61.93-.61a5.9,5.9,0,0,1,2.7.72V12.94a7,7,0,0,0-2.7-.51c-2.21,0-3.68,1.18-3.68,3.16,0,3.1,4.14,2.6,4.14,3.93,0,.52-.44.69-1,.69a6.78,6.78,0,0,1-3-.9V22a7.38,7.38,0,0,0,3,.64c2.26,0,3.82-1.15,3.82-3.16C103.62,16.12,99.46,16.72,99.46,15.46Z"
|
|
70
|
+
/>
|
|
71
|
+
<path
|
|
72
|
+
className="cls-1"
|
|
73
|
+
d="M107.28,10.24l-2.65.58v8.93a2.77,2.77,0,0,0,2.82,2.87,4.16,4.16,0,0,0,1.91-.37V20c-.35.15-2.06.66-2.06-1V15h2.06V12.66h-2.06Z"
|
|
74
|
+
/>
|
|
75
|
+
<polygon
|
|
76
|
+
className="cls-1"
|
|
77
|
+
points="116.25 11.7 118.98 11.13 118.98 8.97 116.25 9.54 116.25 11.7"
|
|
78
|
+
/>
|
|
79
|
+
<rect className="cls-1" x="116.25" y="12.61" width="2.73" height="9.64" />
|
|
80
|
+
</svg>,
|
|
81
|
+
"PoweredByStripe"
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
export const StripeLogoLink = ({ height }: { height?: string }) => {
|
|
85
|
+
return (
|
|
86
|
+
<a href="https://stripe.com" target="_blank">
|
|
87
|
+
<PoweredByStripe
|
|
88
|
+
sx={{ width: "unset", height: height || "1em" }}
|
|
89
|
+
viewBox="0 0 150 34"
|
|
90
|
+
/>
|
|
91
|
+
</a>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import { AddCard, type AddCardProps } from "./Billing";
|
|
2
|
-
import Order from "./Order";
|
|
3
|
-
import { postCheckout } from "../../utils/api";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import { Alert, Container, Typography, CircularProgress } from "@mui/material";
|
|
6
|
-
|
|
7
|
-
type CheckoutProps = AddCardProps & {
|
|
8
|
-
order: any;
|
|
9
|
-
apiBaseUrl: string;
|
|
10
|
-
invoiceId?: string;
|
|
11
|
-
onPlacement?: () => void;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default function Checkout({
|
|
15
|
-
order,
|
|
16
|
-
apiBaseUrl,
|
|
17
|
-
invoiceId,
|
|
18
|
-
onPlacement,
|
|
19
|
-
}: CheckoutProps) {
|
|
20
|
-
const currentUrl = new URL(window.location.href);
|
|
21
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
22
|
-
const [successData, setSuccessData] = React.useState<any | null>(null);
|
|
23
|
-
const onSubmit = async (values: any) => {
|
|
24
|
-
setIsSubmitting(true);
|
|
25
|
-
const data = await postCheckout(
|
|
26
|
-
apiBaseUrl,
|
|
27
|
-
order.id,
|
|
28
|
-
order.reference,
|
|
29
|
-
values,
|
|
30
|
-
"stripe",
|
|
31
|
-
invoiceId
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
if (data instanceof Response) {
|
|
35
|
-
alert(JSON.stringify(data));
|
|
36
|
-
} else {
|
|
37
|
-
// success
|
|
38
|
-
setSuccessData(data);
|
|
39
|
-
onPlacement && onPlacement();
|
|
40
|
-
// Get the current URL
|
|
41
|
-
const currentUrl = new URL(window.location.href);
|
|
42
|
-
// Set the query parameter 'showReceipt' to '1'
|
|
43
|
-
currentUrl.searchParams.set("showReceipt", "1");
|
|
44
|
-
currentUrl.searchParams.set("orderId", order.id);
|
|
45
|
-
currentUrl.searchParams.set("orderRef", order.reference);
|
|
46
|
-
|
|
47
|
-
// Update the browser's URL and history without refreshing the page
|
|
48
|
-
window.history.pushState({}, "", currentUrl);
|
|
49
|
-
}
|
|
50
|
-
setIsSubmitting(false);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
successData !== null ||
|
|
55
|
-
// currentUrl.searchParams.get("showReceipt")
|
|
56
|
-
order.charge_id ||
|
|
57
|
-
!["pending", "awaiting_payment"].includes(order.status)
|
|
58
|
-
) {
|
|
59
|
-
const print = (
|
|
60
|
-
<a
|
|
61
|
-
href="#"
|
|
62
|
-
onClick={() => {
|
|
63
|
-
window.print();
|
|
64
|
-
return false;
|
|
65
|
-
}}
|
|
66
|
-
style={{ textDecoration: "underline" }}
|
|
67
|
-
>
|
|
68
|
-
print
|
|
69
|
-
</a>
|
|
70
|
-
);
|
|
71
|
-
const text =
|
|
72
|
-
successData !== null ? (
|
|
73
|
-
<>
|
|
74
|
-
Payment received! An email was sent to{" "}
|
|
75
|
-
<strong>{successData.billing_information.email}</strong>. You can also{" "}
|
|
76
|
-
{print} this page for your records.
|
|
77
|
-
</>
|
|
78
|
-
) : (
|
|
79
|
-
<>Payment received! You can {print} this page for your records.</>
|
|
80
|
-
);
|
|
81
|
-
return (
|
|
82
|
-
<>
|
|
83
|
-
<Container>
|
|
84
|
-
<Alert severity="success">{text}</Alert>
|
|
85
|
-
</Container>
|
|
86
|
-
<Order order={order} invoiceId={invoiceId} />
|
|
87
|
-
</>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
return (
|
|
91
|
-
<>
|
|
92
|
-
<Order order={order} invoiceId={invoiceId} />
|
|
93
|
-
{isSubmitting ? (
|
|
94
|
-
<Container>
|
|
95
|
-
<Typography>
|
|
96
|
-
<CircularProgress color="primary" /> Submitting...
|
|
97
|
-
</Typography>
|
|
98
|
-
</Container>
|
|
99
|
-
) : (
|
|
100
|
-
<AddCard contact={order.customer} onSubmit={onSubmit} />
|
|
101
|
-
)}
|
|
102
|
-
</>
|
|
103
|
-
);
|
|
104
|
-
}
|
|
1
|
+
import { AddCard, type AddCardProps } from "./Billing";
|
|
2
|
+
import Order from "./Order";
|
|
3
|
+
import { postCheckout } from "../../utils/api";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { Alert, Container, Typography, CircularProgress } from "@mui/material";
|
|
6
|
+
|
|
7
|
+
type CheckoutProps = AddCardProps & {
|
|
8
|
+
order: any;
|
|
9
|
+
apiBaseUrl: string;
|
|
10
|
+
invoiceId?: string;
|
|
11
|
+
onPlacement?: () => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default function Checkout({
|
|
15
|
+
order,
|
|
16
|
+
apiBaseUrl,
|
|
17
|
+
invoiceId,
|
|
18
|
+
onPlacement,
|
|
19
|
+
}: CheckoutProps) {
|
|
20
|
+
const currentUrl = new URL(window.location.href);
|
|
21
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
22
|
+
const [successData, setSuccessData] = React.useState<any | null>(null);
|
|
23
|
+
const onSubmit = async (values: any) => {
|
|
24
|
+
setIsSubmitting(true);
|
|
25
|
+
const data = await postCheckout(
|
|
26
|
+
apiBaseUrl,
|
|
27
|
+
order.id,
|
|
28
|
+
order.reference,
|
|
29
|
+
values,
|
|
30
|
+
"stripe",
|
|
31
|
+
invoiceId
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (data instanceof Response) {
|
|
35
|
+
alert(JSON.stringify(data));
|
|
36
|
+
} else {
|
|
37
|
+
// success
|
|
38
|
+
setSuccessData(data);
|
|
39
|
+
onPlacement && onPlacement();
|
|
40
|
+
// Get the current URL
|
|
41
|
+
const currentUrl = new URL(window.location.href);
|
|
42
|
+
// Set the query parameter 'showReceipt' to '1'
|
|
43
|
+
currentUrl.searchParams.set("showReceipt", "1");
|
|
44
|
+
currentUrl.searchParams.set("orderId", order.id);
|
|
45
|
+
currentUrl.searchParams.set("orderRef", order.reference);
|
|
46
|
+
|
|
47
|
+
// Update the browser's URL and history without refreshing the page
|
|
48
|
+
window.history.pushState({}, "", currentUrl);
|
|
49
|
+
}
|
|
50
|
+
setIsSubmitting(false);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
successData !== null ||
|
|
55
|
+
// currentUrl.searchParams.get("showReceipt")
|
|
56
|
+
order.charge_id ||
|
|
57
|
+
!["pending", "awaiting_payment"].includes(order.status)
|
|
58
|
+
) {
|
|
59
|
+
const print = (
|
|
60
|
+
<a
|
|
61
|
+
href="#"
|
|
62
|
+
onClick={() => {
|
|
63
|
+
window.print();
|
|
64
|
+
return false;
|
|
65
|
+
}}
|
|
66
|
+
style={{ textDecoration: "underline" }}
|
|
67
|
+
>
|
|
68
|
+
print
|
|
69
|
+
</a>
|
|
70
|
+
);
|
|
71
|
+
const text =
|
|
72
|
+
successData !== null ? (
|
|
73
|
+
<>
|
|
74
|
+
Payment received! An email was sent to{" "}
|
|
75
|
+
<strong>{successData.billing_information.email}</strong>. You can also{" "}
|
|
76
|
+
{print} this page for your records.
|
|
77
|
+
</>
|
|
78
|
+
) : (
|
|
79
|
+
<>Payment received! You can {print} this page for your records.</>
|
|
80
|
+
);
|
|
81
|
+
return (
|
|
82
|
+
<>
|
|
83
|
+
<Container>
|
|
84
|
+
<Alert severity="success">{text}</Alert>
|
|
85
|
+
</Container>
|
|
86
|
+
<Order order={order} invoiceId={invoiceId} />
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<Order order={order} invoiceId={invoiceId} />
|
|
93
|
+
{isSubmitting ? (
|
|
94
|
+
<Container>
|
|
95
|
+
<Typography>
|
|
96
|
+
<CircularProgress color="primary" /> Submitting...
|
|
97
|
+
</Typography>
|
|
98
|
+
</Container>
|
|
99
|
+
) : (
|
|
100
|
+
<AddCard contact={order.customer} onSubmit={onSubmit} />
|
|
101
|
+
)}
|
|
102
|
+
</>
|
|
103
|
+
);
|
|
104
|
+
}
|
package/src/index.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
@media print {
|
|
2
|
-
#paymentMethodForm {
|
|
3
|
-
display: none !important;
|
|
4
|
-
}
|
|
5
|
-
}
|
|
1
|
+
@media print {
|
|
2
|
+
#paymentMethodForm {
|
|
3
|
+
display: none !important;
|
|
4
|
+
}
|
|
5
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import CartButton from "./CartButton";
|
|
2
|
-
import {
|
|
3
|
-
cartStore,
|
|
4
|
-
addToCart,
|
|
5
|
-
removeFromCart,
|
|
6
|
-
clearCart,
|
|
7
|
-
setOrder,
|
|
8
|
-
} from "./utils/storage";
|
|
9
|
-
import type { Cart, CartProduct } from "./types";
|
|
10
|
-
import AddToCartForm from "./AddToCartForm";
|
|
11
|
-
import { AddCard, AddCardProps } from "./checkout/components/Billing";
|
|
12
|
-
import Order from "./checkout/components/Order";
|
|
13
|
-
import Checkout from "./checkout/components";
|
|
14
|
-
import "react-credit-cards-2/dist/es/styles-compiled.css";
|
|
15
|
-
import "./index.css";
|
|
16
|
-
import ProductCard from "./ProductCard";
|
|
17
|
-
import CheckoutList from "./checkout/CheckoutList";
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
Checkout,
|
|
21
|
-
Order,
|
|
22
|
-
AddCard,
|
|
23
|
-
type AddCardProps,
|
|
24
|
-
cartStore,
|
|
25
|
-
CartButton,
|
|
26
|
-
type Cart,
|
|
27
|
-
type CartProduct,
|
|
28
|
-
addToCart,
|
|
29
|
-
removeFromCart,
|
|
30
|
-
clearCart,
|
|
31
|
-
AddToCartForm,
|
|
32
|
-
setOrder,
|
|
33
|
-
ProductCard,
|
|
34
|
-
CheckoutList,
|
|
35
|
-
};
|
|
1
|
+
import CartButton from "./CartButton";
|
|
2
|
+
import {
|
|
3
|
+
cartStore,
|
|
4
|
+
addToCart,
|
|
5
|
+
removeFromCart,
|
|
6
|
+
clearCart,
|
|
7
|
+
setOrder,
|
|
8
|
+
} from "./utils/storage";
|
|
9
|
+
import type { Cart, CartProduct } from "./types";
|
|
10
|
+
import AddToCartForm from "./AddToCartForm";
|
|
11
|
+
import { AddCard, AddCardProps } from "./checkout/components/Billing";
|
|
12
|
+
import Order from "./checkout/components/Order";
|
|
13
|
+
import Checkout from "./checkout/components";
|
|
14
|
+
import "react-credit-cards-2/dist/es/styles-compiled.css";
|
|
15
|
+
import "./index.css";
|
|
16
|
+
import ProductCard from "./ProductCard";
|
|
17
|
+
import CheckoutList from "./checkout/CheckoutList";
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
Checkout,
|
|
21
|
+
Order,
|
|
22
|
+
AddCard,
|
|
23
|
+
type AddCardProps,
|
|
24
|
+
cartStore,
|
|
25
|
+
CartButton,
|
|
26
|
+
type Cart,
|
|
27
|
+
type CartProduct,
|
|
28
|
+
addToCart,
|
|
29
|
+
removeFromCart,
|
|
30
|
+
clearCart,
|
|
31
|
+
AddToCartForm,
|
|
32
|
+
setOrder,
|
|
33
|
+
ProductCard,
|
|
34
|
+
CheckoutList,
|
|
35
|
+
};
|
package/src/types.d.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
export interface Cart {
|
|
2
|
-
authentication: {
|
|
3
|
-
loggedIn: boolean;
|
|
4
|
-
user_id?: number | string;
|
|
5
|
-
};
|
|
6
|
-
items: CartProduct[];
|
|
7
|
-
order?: {
|
|
8
|
-
id: number;
|
|
9
|
-
reference: string;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export type CartProduct = {
|
|
13
|
-
product_id: number | string;
|
|
14
|
-
price_id: number | string;
|
|
15
|
-
quantity?: number;
|
|
16
|
-
// Used in local cart, delete when sent to api
|
|
17
|
-
name: string;
|
|
18
|
-
image?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type CartContextType = {
|
|
22
|
-
cart: Cart;
|
|
23
|
-
addToCart: (p: CartProduct) => void;
|
|
24
|
-
removeFromCart: (i: number) => void;
|
|
25
|
-
clearCart: () => void;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type ApiCartResponse = {
|
|
29
|
-
cart: string;
|
|
30
|
-
id: any;
|
|
31
|
-
user_id: number | string;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type PathDetailsType = {
|
|
35
|
-
baseUrl?: string;
|
|
36
|
-
userId?: string | number;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export type Product = {
|
|
40
|
-
id: string | number;
|
|
41
|
-
name: string;
|
|
42
|
-
/** v Parses to @type {ProductPricing} v */
|
|
43
|
-
pricing: string;
|
|
44
|
-
description?: string;
|
|
45
|
-
} & unknown;
|
|
46
|
-
|
|
47
|
-
export type ProductPricing = {
|
|
48
|
-
id: number | string;
|
|
49
|
-
unit_amount: number; // in cents
|
|
50
|
-
recurring?: {
|
|
51
|
-
interval: "month" | "week" | "day";
|
|
52
|
-
interval_count: number;
|
|
53
|
-
};
|
|
54
|
-
tier_label?: string;
|
|
55
|
-
tier_description?: string;
|
|
56
|
-
};
|
|
1
|
+
export interface Cart {
|
|
2
|
+
authentication: {
|
|
3
|
+
loggedIn: boolean;
|
|
4
|
+
user_id?: number | string;
|
|
5
|
+
};
|
|
6
|
+
items: CartProduct[];
|
|
7
|
+
order?: {
|
|
8
|
+
id: number;
|
|
9
|
+
reference: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export type CartProduct = {
|
|
13
|
+
product_id: number | string;
|
|
14
|
+
price_id: number | string;
|
|
15
|
+
quantity?: number;
|
|
16
|
+
// Used in local cart, delete when sent to api
|
|
17
|
+
name: string;
|
|
18
|
+
image?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type CartContextType = {
|
|
22
|
+
cart: Cart;
|
|
23
|
+
addToCart: (p: CartProduct) => void;
|
|
24
|
+
removeFromCart: (i: number) => void;
|
|
25
|
+
clearCart: () => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type ApiCartResponse = {
|
|
29
|
+
cart: string;
|
|
30
|
+
id: any;
|
|
31
|
+
user_id: number | string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type PathDetailsType = {
|
|
35
|
+
baseUrl?: string;
|
|
36
|
+
userId?: string | number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type Product = {
|
|
40
|
+
id: string | number;
|
|
41
|
+
name: string;
|
|
42
|
+
/** v Parses to @type {ProductPricing} v */
|
|
43
|
+
pricing: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
} & unknown;
|
|
46
|
+
|
|
47
|
+
export type ProductPricing = {
|
|
48
|
+
id: number | string;
|
|
49
|
+
unit_amount: number; // in cents
|
|
50
|
+
recurring?: {
|
|
51
|
+
interval: "month" | "week" | "day";
|
|
52
|
+
interval_count: number;
|
|
53
|
+
};
|
|
54
|
+
tier_label?: string;
|
|
55
|
+
tier_description?: string;
|
|
56
|
+
};
|