Skip to content

Commit 47f128c

Browse files
committed
hi
1 parent 64a7c65 commit 47f128c

3 files changed

Lines changed: 328 additions & 16 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,18 @@ export async function POST(request: NextRequest) {
138138
// Create payment record linked to validated intent
139139
await tx.payment.create({
140140
data: {
141+
storeId,
141142
orderId: createdOrder.id,
142143
amount: pricing.grandTotal,
143144
currency: pricing.currency,
144-
paymentMethod: input.paymentMethod,
145+
method: input.paymentMethod,
146+
gateway: 'STRIPE', // TODO: Make dynamic based on payment method
145147
status: 'PENDING',
146-
paymentIntentId: input.paymentIntentId,
147-
metadata: {
148+
gatewayPaymentId: input.paymentIntentId, // Stripe payment_intent_id
149+
metadata: JSON.stringify({
148150
validatedAt: new Date().toISOString(),
149151
ipAddress: orderInput.ipAddress,
150-
},
152+
}),
151153
},
152154
});
153155

src/services/payments/intent-validator.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function validatePaymentIntent(
5757
// Look up payment intent in database (temporary implementation)
5858
const existingPayment = await db.payment.findFirst({
5959
where: {
60-
paymentIntentId,
60+
gatewayPaymentId: paymentIntentId,
6161
order: {
6262
storeId, // Multi-tenant isolation
6363
},
@@ -73,7 +73,7 @@ export async function validatePaymentIntent(
7373

7474
// If payment already exists and is completed, prevent duplicate order creation
7575
if (existingPayment) {
76-
if (existingPayment.status === 'COMPLETED') {
76+
if (existingPayment.status === 'PAID') {
7777
return {
7878
isValid: false,
7979
reason: 'Payment intent already used for a completed order',
@@ -84,7 +84,7 @@ export async function validatePaymentIntent(
8484
};
8585
}
8686

87-
if (existingPayment.status === 'FAILED' || existingPayment.status === 'CANCELLED') {
87+
if (existingPayment.status === 'REFUNDED' || existingPayment.status === 'DISPUTED') {
8888
return {
8989
isValid: false,
9090
reason: `Payment intent has status: ${existingPayment.status}`,
@@ -144,13 +144,13 @@ export async function validatePaymentIntent(
144144
* Prevents tampering where client submits payment intent with lower amount
145145
* than actual order total.
146146
*
147-
* @param paymentIntentId - Stripe payment intent ID
148-
* @param expectedAmount - Server-calculated order total (in cents)
147+
* @param _paymentIntentId - Stripe payment intent ID (unused in mock)
148+
* @param _expectedAmount - Server-calculated order total in cents (unused in mock)
149149
* @returns True if amounts match within 1 cent tolerance
150150
*/
151151
export async function verifyPaymentIntentAmount(
152-
paymentIntentId: string,
153-
expectedAmount: number
152+
_paymentIntentId: string,
153+
_expectedAmount: number
154154
): Promise<boolean> {
155155
// TODO: Implement Stripe API call to retrieve payment intent amount
156156
// const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
@@ -185,7 +185,7 @@ export async function verifyPaymentIntentStore(
185185
// For now, check database payment records
186186
const payment = await db.payment.findFirst({
187187
where: {
188-
paymentIntentId,
188+
gatewayPaymentId: paymentIntentId,
189189
order: {
190190
storeId,
191191
},
@@ -203,9 +203,8 @@ export async function verifyPaymentIntentStore(
203203
*/
204204
export function getValidCheckoutStatuses(): string[] {
205205
return [
206-
'requires_confirmation',
207-
'requires_action',
208-
'processing',
209-
'succeeded',
206+
'PENDING', // Payment initiated
207+
'AUTHORIZED', // Payment authorized (not captured)
208+
// Note: 'PAID' is excluded - if payment is already PAID, order likely exists
210209
];
211210
}

0 commit comments

Comments
 (0)