feat: implement order synchronization with Stripe and enhance order management features
CI/CD / test-and-build (push) Waiting to run
CI/CD / deploy (push) Blocked by required conditions

This commit is contained in:
Najjar\NajjarV02
2026-04-14 10:34:19 +04:00
parent a501d94645
commit 9a1a562fc6
9 changed files with 352 additions and 43 deletions
+7 -1
View File
@@ -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');
};
+36 -1
View File
@@ -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',