@springmicro/cart 0.7.22 → 0.7.24
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 +3654 -3687
- package/dist/index.umd.cjs +54 -54
- package/package.json +3 -3
- package/src/checkout/ReviewCartAndCalculateTaxes.tsx +92 -77
- package/src/checkout/components/AddCard.tsx +66 -43
- package/src/checkout/components/Address.tsx +7 -5
- package/src/checkout/components/CartList.tsx +11 -28
- package/src/checkout/components/CartProductCard.tsx +3 -1
- package/src/checkout/components/StatusBar.tsx +10 -4
- package/src/checkout/index.tsx +15 -26
- package/src/utils/storage.ts +0 -2
package/src/checkout/index.tsx
CHANGED
|
@@ -28,6 +28,7 @@ export default function Checkout({
|
|
|
28
28
|
disableFields = [],
|
|
29
29
|
dev,
|
|
30
30
|
invoiceId,
|
|
31
|
+
affiliateCode,
|
|
31
32
|
order: _order,
|
|
32
33
|
}: {
|
|
33
34
|
apiBaseUrl: string;
|
|
@@ -41,22 +42,22 @@ export default function Checkout({
|
|
|
41
42
|
disableFields?: string[];
|
|
42
43
|
dev?: boolean;
|
|
43
44
|
invoiceId?;
|
|
45
|
+
affiliateCode?;
|
|
44
46
|
order?;
|
|
45
47
|
}) {
|
|
46
48
|
const store = useStore(cartStore);
|
|
47
49
|
const localCart = useMemo(() => JSON.parse(store), [store]);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const [order, setOrder] = useState(_order); // starts undefined on a typical checkout. If an order is provided, it's likely an invoice.
|
|
51
|
+
console.log("CART", invoiceId, order, localCart);
|
|
52
|
+
const cart = invoiceId ? { items: order.basket } : localCart; // todo fix calculation
|
|
50
53
|
|
|
51
54
|
const [products, setProducts] = useState({});
|
|
52
55
|
const [prices, setPrices] = useState({});
|
|
53
56
|
const [subtotal, setSubtotal] = useState("Loading prices...");
|
|
54
|
-
const taxState = useState<any>({ tax_amount: "TBD" });
|
|
55
57
|
const shipping = 0;
|
|
56
58
|
const discount = 0;
|
|
57
59
|
|
|
58
60
|
const [status, setStatus] = useState(0);
|
|
59
|
-
const [order, setOrder] = useState(_order); // starts undefined on a typical checkout. If an order is provided, it's likely an invoice.
|
|
60
61
|
const [successData, setSuccessData] = useState(null);
|
|
61
62
|
|
|
62
63
|
useEffect(() => {
|
|
@@ -76,12 +77,12 @@ export default function Checkout({
|
|
|
76
77
|
order.charge_id ||
|
|
77
78
|
!["pending", "awaiting_payment"].includes(order.status)
|
|
78
79
|
? 2
|
|
79
|
-
: 0 // normally this should be set to 1 but we need to ensure it sends card data to the payment provider and that data is likely lost on refresh.
|
|
80
|
+
: 0, // normally this should be set to 1 but we need to ensure it sends card data to the payment provider and that data is likely lost on refresh.
|
|
80
81
|
);
|
|
81
82
|
})
|
|
82
83
|
.catch(() => {
|
|
83
84
|
console.error("Failed to get order");
|
|
84
|
-
})
|
|
85
|
+
}),
|
|
85
86
|
);
|
|
86
87
|
}
|
|
87
88
|
}, []);
|
|
@@ -92,22 +93,22 @@ export default function Checkout({
|
|
|
92
93
|
const pricesToGet = cart.items
|
|
93
94
|
.map((c) => c.price_id)
|
|
94
95
|
.filter(
|
|
95
|
-
(pId) => Object.keys(products).findIndex((pKey) => pKey == pId) === -1
|
|
96
|
+
(pId) => Object.keys(products).findIndex((pKey) => pKey == pId) === -1,
|
|
96
97
|
);
|
|
97
98
|
|
|
98
99
|
// filter out products that have already been queried
|
|
99
100
|
const productsToGet = cart.items
|
|
100
101
|
.map((c) => c.product_id)
|
|
101
102
|
.filter(
|
|
102
|
-
(pId) => Object.keys(products).findIndex((pKey) => pKey == pId) === -1
|
|
103
|
+
(pId) => Object.keys(products).findIndex((pKey) => pKey == pId) === -1,
|
|
103
104
|
);
|
|
104
105
|
|
|
105
106
|
const priceUrl = `${apiBaseUrl}/api/ecommerce/price?filter={'ids':[${pricesToGet.join(
|
|
106
|
-
","
|
|
107
|
+
",",
|
|
107
108
|
)}]}`;
|
|
108
109
|
|
|
109
110
|
const productUrl = `${apiBaseUrl}/api/ecommerce/products?filter={'ids':[${productsToGet.join(
|
|
110
|
-
","
|
|
111
|
+
",",
|
|
111
112
|
)}]}`;
|
|
112
113
|
|
|
113
114
|
const fetchSettings = {
|
|
@@ -137,7 +138,7 @@ export default function Checkout({
|
|
|
137
138
|
...o,
|
|
138
139
|
[p.id]: p,
|
|
139
140
|
}),
|
|
140
|
-
prices
|
|
141
|
+
prices,
|
|
141
142
|
);
|
|
142
143
|
setPrices(data);
|
|
143
144
|
}
|
|
@@ -148,7 +149,7 @@ export default function Checkout({
|
|
|
148
149
|
...o,
|
|
149
150
|
[p.id]: p,
|
|
150
151
|
}),
|
|
151
|
-
products
|
|
152
|
+
products,
|
|
152
153
|
);
|
|
153
154
|
setProducts(data);
|
|
154
155
|
}
|
|
@@ -160,22 +161,10 @@ export default function Checkout({
|
|
|
160
161
|
setSubtotal(
|
|
161
162
|
cart.items
|
|
162
163
|
.map((product) => prices[product.price_id]?.unit_amount)
|
|
163
|
-
.reduce((p, c) => (c ? p + c : p), 0)
|
|
164
|
+
.reduce((p, c) => (c ? p + c : p), 0),
|
|
164
165
|
);
|
|
165
166
|
}, [cart, prices]);
|
|
166
167
|
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
const taxable_items = cart.items.filter(
|
|
169
|
-
(i) =>
|
|
170
|
-
prices[i.price_id]?.unit_amount > 0 &&
|
|
171
|
-
products[i.product_id]?.type !== "DONATION"
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
if (taxable_items.length === 0) {
|
|
175
|
-
taxState[1]({ tax_amount: 0 });
|
|
176
|
-
}
|
|
177
|
-
}, [cart, prices, products]);
|
|
178
|
-
|
|
179
168
|
if (status === 0 && cart.items.length === 0)
|
|
180
169
|
return (
|
|
181
170
|
<div
|
|
@@ -219,7 +208,6 @@ export default function Checkout({
|
|
|
219
208
|
discount={discount}
|
|
220
209
|
shipping={shipping}
|
|
221
210
|
taxProvider={taxProvider}
|
|
222
|
-
taxState={taxState}
|
|
223
211
|
statusState={[status, setStatus]}
|
|
224
212
|
cart={cart}
|
|
225
213
|
prices={prices}
|
|
@@ -239,6 +227,7 @@ export default function Checkout({
|
|
|
239
227
|
hideFields={hideFields}
|
|
240
228
|
disableFields={disableFields}
|
|
241
229
|
invoiceId={invoiceId}
|
|
230
|
+
affiliateCode={affiliateCode}
|
|
242
231
|
/>
|
|
243
232
|
)}
|
|
244
233
|
{status === 2 && order !== undefined && (
|
package/src/utils/storage.ts
CHANGED
|
@@ -61,7 +61,6 @@ apiPathDetails.listen((pathDetails, oldPathDetails) => {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
cartStore.set(cartStr);
|
|
64
|
-
console.log(cartStr);
|
|
65
64
|
} else if (status === 404 && localCartData.items.length > 0) {
|
|
66
65
|
fetchFromCartApi(
|
|
67
66
|
"PUT",
|
|
@@ -115,7 +114,6 @@ export function logout(apiBaseUrl: string | undefined) {
|
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
export function addToCart(p: CartProduct) {
|
|
118
|
-
console.log("ADD TO CART", p);
|
|
119
117
|
const cart: Cart = JSON.parse(cartStore.get());
|
|
120
118
|
const newCart: Cart = {
|
|
121
119
|
...cart,
|