checkout-payments
Checkout and Payments
Quick Start
When working with checkout:
- Validate cart data before creating order
- Validate shipping address
- Create order in database
- Integrate with MercadoPago
- Handle payment webhooks
- Update order status
Key Files
src/app/checkout/- Checkout pagessrc/components/Checkout/- Checkout componentssrc/lib/integrations/mercadopago/- MercadoPago integrationsrc/lib/business/orders/- Order logicsrc/hooks/useCheckout.ts- Checkout hook
Common Patterns
Create Order
import { createOrder } from '@/lib/business/orders/order-service';
import { createPayment } from '@/lib/integrations/mercadopago';
export async function POST(request: NextRequest) {
const { items, shippingAddress, paymentMethod } = await request.json();
const order = await createOrder({
items,
shippingAddress,
status: 'pending_payment',
});
const payment = await createPayment({
transaction_amount: order.total,
description: `Orden #${order.id}`,
payer: {
email: order.customer_email,
},
});
await updateOrder(order.id, {
payment_id: payment.id,
payment_status: 'pending',
});
return NextResponse.json({ order, payment });
}
Validate Address
import { validateAddress } from '@/lib/business/logistics/address-validation';
const validation = await validateAddress({
street: 'Av. Corrientes 1234',
city: 'Buenos Aires',
postalCode: 'C1043AAX',
country: 'AR',
});
if (!validation.isValid) {
return { errors: validation.errors };
}
MercadoPago Wallet
import { initMercadoPago, Wallet } from '@mercadopago/sdk-react';
function CheckoutPayment() {
const [paymentData, setPaymentData] = useState(null);
useEffect(() => {
initMercadoPago('YOUR_PUBLIC_KEY');
}, []);
return (
<Wallet
initialization={{ preferenceId: paymentData?.preference_id }}
onSubmit={onSubmit}
/>
);
}
Order States
pending_payment- Waiting for paymentpaid- Paidprocessing- Processingshipped- Shippeddelivered- Deliveredcancelled- Cancelledrefunded- Refunded
More from santiagoxor/pintureria-digital
authentication
Specialized skill for working with NextAuth.js authentication including session management, JWT tokens, role-based access control, and protected routes. Use when implementing authentication features, securing routes, managing user sessions, or debugging auth issues.
34postgres-best-practices
Postgres performance optimization guidelines from Supabase. Contains rules across 8 categories prioritized by impact. Use when writing SQL queries, designing schemas, implementing indexes, optimizing queries, reviewing database performance, configuring connection pooling, or working with Row-Level Security (RLS).
29testing-qa
Specialized skill for writing and maintaining tests including unit tests, integration tests, E2E tests with Playwright, and accessibility tests. Use when writing tests for new features, debugging failed tests, improving test coverage, or setting up E2E tests.
18error-handling
Specialized skill for implementing proper error handling, logging, user-friendly error messages, and error recovery strategies. Use when implementing error handling in APIs, components, or when debugging error issues.
17lighthouse-audit
Specialized skill for running Lighthouse audits, analyzing Core Web Vitals, identifying performance opportunities, and generating performance reports. Use when auditing performance, analyzing Lighthouse metrics, optimizing Core Web Vitals, or generating performance reports.
17git-commit-push
Automates git commit and push workflow with descriptive commit messages. Analyzes changes, generates conventional commit messages, stages files, commits, and pushes to remote. Use when the user asks to commit changes, push code, or save work to git.
17