|
10 | 10 | * - Atomic transaction wrapper (T013) |
11 | 11 | */ |
12 | 12 |
|
13 | | -import { NextRequest, NextResponse } from 'next/server'; |
| 13 | +import { NextRequest } from 'next/server'; |
14 | 14 | import { z } from 'zod'; |
15 | 15 | import { getServerSession } from 'next-auth/next'; |
16 | 16 | import { authOptions } from '@/lib/auth'; |
@@ -54,7 +54,7 @@ const CompleteCheckoutSchema = z.object({ |
54 | 54 | // SECURITY: Removed client-submitted monetary values |
55 | 55 | // Server recalculates: subtotal, taxAmount, shippingCost, discountAmount |
56 | 56 | shippingMethod: z.string().min(1), |
57 | | - paymentMethod: z.enum(['CREDIT_CARD', 'DEBIT_CARD', 'PAYPAL', 'BANK_TRANSFER']), |
| 57 | + paymentMethod: z.enum(['CREDIT_CARD', 'DEBIT_CARD', 'MOBILE_BANKING', 'BANK_TRANSFER', 'CASH_ON_DELIVERY']), |
58 | 58 | discountCode: z.string().optional(), |
59 | 59 | paymentIntentId: z.string().min(1), // Required for pre-validation (T012) |
60 | 60 | notes: z.string().optional(), |
@@ -85,7 +85,7 @@ export async function POST(request: NextRequest) { |
85 | 85 | const pricing = await calculateCheckoutPricing( |
86 | 86 | storeId, |
87 | 87 | input.items, |
88 | | - input.shippingMethod, |
| 88 | + { name: input.shippingMethod, cost: 0 }, // Shipping method details will be resolved server-side |
89 | 89 | input.discountCode |
90 | 90 | ); |
91 | 91 |
|
@@ -119,14 +119,14 @@ export async function POST(request: NextRequest) { |
119 | 119 | shippingAddress: input.shippingAddress, |
120 | 120 | billingAddress: input.billingAddress, |
121 | 121 | shippingMethod: input.shippingMethod, |
122 | | - shippingCost: pricing.shippingCost, |
| 122 | + shippingCost: pricing.shippingTotal, |
123 | 123 | discountCode: input.discountCode, |
124 | 124 | customerNote: input.notes, |
125 | 125 | ipAddress: request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || undefined, |
126 | 126 | // Pass server-calculated totals |
127 | 127 | subtotal: pricing.subtotal, |
128 | | - taxAmount: pricing.taxAmount, |
129 | | - discountAmount: pricing.discountAmount, |
| 128 | + taxAmount: pricing.taxTotal, |
| 129 | + discountAmount: pricing.discountTotal, |
130 | 130 | paymentMethod: input.paymentMethod, |
131 | 131 | }; |
132 | 132 |
|
@@ -159,8 +159,7 @@ export async function POST(request: NextRequest) { |
159 | 159 | // Return standardized success response (FR-008) |
160 | 160 | return successResponse( |
161 | 161 | order, |
162 | | - { message: 'Order created successfully' }, |
163 | | - 201 |
| 162 | + { message: 'Order created successfully', statusCode: 201 } |
164 | 163 | ); |
165 | 164 | } catch (error) { |
166 | 165 | // Standardized error handling (FR-008) |
|
0 commit comments