feat: implement order synchronization with Stripe and enhance order management features
This commit is contained in:
@@ -32,10 +32,16 @@ export function PricingEngine() {
|
||||
|
||||
const handleProceed = () => {
|
||||
const store = orderStore.getState();
|
||||
const lineItems: { label: string; price: number }[] = [
|
||||
{ label: 'G1 Robot Base', price: basePrice },
|
||||
...(personaPrice > 0 ? [{ label: personaLabel, price: personaPrice }] : []),
|
||||
...(colorPrice > 0 ? [{ label: 'Custom Color', price: colorPrice }] : []),
|
||||
];
|
||||
store.setOrderTotal(total);
|
||||
store.setConfigSummary(
|
||||
persona === 'none' ? 'Default' : personaLabel,
|
||||
primaryColor
|
||||
primaryColor,
|
||||
lineItems,
|
||||
);
|
||||
store.setStep('shipping');
|
||||
};
|
||||
|
||||
@@ -46,8 +46,43 @@ export function ReviewStep() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Payment succeeded — upload snapshot
|
||||
// Payment succeeded — save order to DB and upload snapshot
|
||||
const paymentIntentId = orderStore.getState().payment.paymentIntentId;
|
||||
const s = orderStore.getState().shipping;
|
||||
const configSummary = orderStore.getState().personaSummary;
|
||||
const colorVal = orderStore.getState().colorSummary;
|
||||
const priceItems = orderStore.getState().priceItems;
|
||||
const total = orderStore.getState().orderTotal;
|
||||
|
||||
// Retrieve the resolved PaymentIntent to get final status + amount
|
||||
const pi = await stripe.retrievePaymentIntent(clientSecret);
|
||||
const piStatus = pi.paymentIntent?.status ?? 'succeeded';
|
||||
const piAmount = pi.paymentIntent?.amount ?? Math.round(total * 100);
|
||||
|
||||
// Save order to DB directly (covers local dev where webhook can't reach localhost)
|
||||
if (paymentIntentId) {
|
||||
fetch('/api/orders/save/', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
paymentIntentId,
|
||||
amount: piAmount,
|
||||
currency: 'aed',
|
||||
status: piStatus,
|
||||
customerName: s.name,
|
||||
customerEmail: s.email,
|
||||
customerPhone: s.phone,
|
||||
customerAddress: s.address,
|
||||
customerCity: s.city,
|
||||
customerCountry: s.country,
|
||||
customerPostalCode: s.postalCode,
|
||||
persona: configSummary,
|
||||
color: colorVal,
|
||||
priceItems: JSON.stringify(priceItems),
|
||||
}),
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
if (snapshotDataUrl && paymentIntentId) {
|
||||
fetch('/api/snapshots/', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user