Skip to content

Commit a52d245

Browse files
committed
upp
1 parent d692b0e commit a52d245

4 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/app/api/checkout/complete/route.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* - Atomic transaction wrapper (T013)
1111
*/
1212

13-
import { NextRequest, NextResponse } from 'next/server';
13+
import { NextRequest } from 'next/server';
1414
import { z } from 'zod';
1515
import { getServerSession } from 'next-auth/next';
1616
import { authOptions } from '@/lib/auth';
@@ -54,7 +54,7 @@ const CompleteCheckoutSchema = z.object({
5454
// SECURITY: Removed client-submitted monetary values
5555
// Server recalculates: subtotal, taxAmount, shippingCost, discountAmount
5656
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']),
5858
discountCode: z.string().optional(),
5959
paymentIntentId: z.string().min(1), // Required for pre-validation (T012)
6060
notes: z.string().optional(),
@@ -85,7 +85,7 @@ export async function POST(request: NextRequest) {
8585
const pricing = await calculateCheckoutPricing(
8686
storeId,
8787
input.items,
88-
input.shippingMethod,
88+
{ name: input.shippingMethod, cost: 0 }, // Shipping method details will be resolved server-side
8989
input.discountCode
9090
);
9191

@@ -119,14 +119,14 @@ export async function POST(request: NextRequest) {
119119
shippingAddress: input.shippingAddress,
120120
billingAddress: input.billingAddress,
121121
shippingMethod: input.shippingMethod,
122-
shippingCost: pricing.shippingCost,
122+
shippingCost: pricing.shippingTotal,
123123
discountCode: input.discountCode,
124124
customerNote: input.notes,
125125
ipAddress: request.headers.get('x-forwarded-for') || request.headers.get('x-real-ip') || undefined,
126126
// Pass server-calculated totals
127127
subtotal: pricing.subtotal,
128-
taxAmount: pricing.taxAmount,
129-
discountAmount: pricing.discountAmount,
128+
taxAmount: pricing.taxTotal,
129+
discountAmount: pricing.discountTotal,
130130
paymentMethod: input.paymentMethod,
131131
};
132132

@@ -159,8 +159,7 @@ export async function POST(request: NextRequest) {
159159
// Return standardized success response (FR-008)
160160
return successResponse(
161161
order,
162-
{ message: 'Order created successfully' },
163-
201
162+
{ message: 'Order created successfully', statusCode: 201 }
164163
);
165164
} catch (error) {
166165
// Standardized error handling (FR-008)

src/lib/api-response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export function errorResponse(
302302
error: {
303303
code: normalizedError.code,
304304
message: normalizedError.message,
305-
...(normalizedError.details && { details: normalizedError.details }),
305+
...(normalizedError.details ? { details: normalizedError.details } : {}),
306306
},
307307
};
308308

tests/integration/tenancy/store-resolution.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,22 @@ describe('Store Resolution Integration Tests', () => {
184184
describe('buildCanonicalUrl()', () => {
185185
it('should build canonical URL in production', () => {
186186
const originalEnv = process.env.NODE_ENV;
187-
process.env.NODE_ENV = 'production';
187+
Object.defineProperty(process.env, 'NODE_ENV', { value: 'production', writable: true });
188188

189189
const url = buildCanonicalUrl('custom.example.com', '/products/123');
190190
expect(url).toBe('https://custom.example.com/products/123');
191191

192-
process.env.NODE_ENV = originalEnv;
192+
Object.defineProperty(process.env, 'NODE_ENV', { value: originalEnv, writable: true });
193193
});
194194

195195
it('should build canonical URL in development', () => {
196196
const originalEnv = process.env.NODE_ENV;
197-
process.env.NODE_ENV = 'development';
197+
Object.defineProperty(process.env, 'NODE_ENV', { value: 'development', writable: true });
198198

199199
const url = buildCanonicalUrl('custom.example.com', '/products/123');
200200
expect(url).toBe('http://custom.example.com/products/123');
201201

202-
process.env.NODE_ENV = originalEnv;
202+
Object.defineProperty(process.env, 'NODE_ENV', { value: originalEnv, writable: true });
203203
});
204204

205205
it('should handle root path', () => {

tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)