@springmicro/cart 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +9891 -9813
- package/dist/index.umd.cjs +66 -92
- package/package.json +3 -3
- package/src/checkout/{CheckoutList.css → ReviewCartAndCalculateTaxes.css} +1 -1
- package/src/checkout/ReviewCartAndCalculateTaxes.tsx +366 -0
- package/src/checkout/components/AddCard.tsx +267 -0
- package/src/checkout/components/Address.tsx +7 -11
- package/src/checkout/components/CartList.tsx +151 -0
- package/src/checkout/components/CartProductCard.css +1 -1
- package/src/checkout/components/CartProductCard.tsx +28 -18
- package/src/checkout/components/Invoice.tsx +145 -0
- package/src/checkout/components/StatusBar.tsx +32 -0
- package/src/checkout/index.tsx +161 -0
- package/src/index.ts +7 -6
- package/src/checkout/CheckoutList.tsx +0 -272
- package/src/checkout/components/Billing.tsx +0 -353
- package/src/checkout/components/Order.tsx +0 -95
- package/src/checkout/components/index.tsx +0 -104
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
Container,
|
|
4
|
-
Typography,
|
|
5
|
-
Table,
|
|
6
|
-
TableBody,
|
|
7
|
-
TableCell,
|
|
8
|
-
TableContainer,
|
|
9
|
-
TableHead,
|
|
10
|
-
TableRow,
|
|
11
|
-
Paper,
|
|
12
|
-
} from "@mui/material";
|
|
13
|
-
|
|
14
|
-
const Order = ({ order, invoiceId }) => {
|
|
15
|
-
// Formatter for currency in USD
|
|
16
|
-
const formatter = new Intl.NumberFormat("en-US", {
|
|
17
|
-
style: "currency",
|
|
18
|
-
currency: "USD",
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
console.log("ORDER", order);
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<Container>
|
|
25
|
-
<Typography variant="h4" gutterBottom>
|
|
26
|
-
{invoiceId ? `Invoice #${invoiceId}` : "Order"}
|
|
27
|
-
</Typography>
|
|
28
|
-
<Typography variant="subtitle1">Reference: {order.reference}</Typography>
|
|
29
|
-
<Typography variant="subtitle1">
|
|
30
|
-
Date: {new Date(order.date).toLocaleDateString()}
|
|
31
|
-
</Typography>
|
|
32
|
-
<Typography variant="subtitle1">Status: {order.status}</Typography>
|
|
33
|
-
{order.customer ? (
|
|
34
|
-
<Typography variant="subtitle1">
|
|
35
|
-
{order.customer.first_name} {order.customer.last_name}
|
|
36
|
-
</Typography>
|
|
37
|
-
) : (
|
|
38
|
-
<Typography variant="subtitle1">
|
|
39
|
-
Customer ID: {order.customer_id}
|
|
40
|
-
</Typography>
|
|
41
|
-
)}
|
|
42
|
-
|
|
43
|
-
<TableContainer component={Paper} sx={{ my: 2 }}>
|
|
44
|
-
<Table>
|
|
45
|
-
<TableHead>
|
|
46
|
-
<TableRow>
|
|
47
|
-
<TableCell>Item ID</TableCell>
|
|
48
|
-
<TableCell>Name</TableCell>
|
|
49
|
-
<TableCell>Description</TableCell>
|
|
50
|
-
<TableCell>Quantity</TableCell>
|
|
51
|
-
<TableCell>Unit Price</TableCell>
|
|
52
|
-
<TableCell>Total Price</TableCell>
|
|
53
|
-
</TableRow>
|
|
54
|
-
</TableHead>
|
|
55
|
-
<TableBody>
|
|
56
|
-
{order.basket.map((item) => (
|
|
57
|
-
<TableRow key={item.item_id}>
|
|
58
|
-
<TableCell>{item.item_id}</TableCell>
|
|
59
|
-
<TableCell>{item.name}</TableCell>
|
|
60
|
-
<TableCell>{item.description || "-"}</TableCell>
|
|
61
|
-
<TableCell>{item.quantity}</TableCell>
|
|
62
|
-
<TableCell>
|
|
63
|
-
{formatter.format(item.unit_price_cents / 100)}
|
|
64
|
-
</TableCell>
|
|
65
|
-
<TableCell>
|
|
66
|
-
{formatter.format(
|
|
67
|
-
(item.quantity * item.unit_price_cents) / 100
|
|
68
|
-
)}
|
|
69
|
-
</TableCell>
|
|
70
|
-
</TableRow>
|
|
71
|
-
))}
|
|
72
|
-
</TableBody>
|
|
73
|
-
</Table>
|
|
74
|
-
</TableContainer>
|
|
75
|
-
|
|
76
|
-
<Typography variant="h6" gutterBottom>
|
|
77
|
-
Subtotal (excl. taxes): {formatter.format(order.subtotal / 100)}
|
|
78
|
-
</Typography>
|
|
79
|
-
<Typography variant="h6" gutterBottom>
|
|
80
|
-
Taxes: {formatter.format(order.taxes / 100)}
|
|
81
|
-
</Typography>
|
|
82
|
-
<Typography variant="h6" gutterBottom>
|
|
83
|
-
Delivery Fees:{" "}
|
|
84
|
-
{formatter.format(
|
|
85
|
-
order.delivery_fees ? order.delivery_fees / 100 : 0.0
|
|
86
|
-
)}
|
|
87
|
-
</Typography>
|
|
88
|
-
<Typography variant="h5" gutterBottom sx={{ mb: 4 }}>
|
|
89
|
-
Total: {formatter.format(order.total / 100)}
|
|
90
|
-
</Typography>
|
|
91
|
-
</Container>
|
|
92
|
-
);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export default Order;
|
|
@@ -1,104 +0,0 @@
|
|
|
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
|
-
}
|