Card details should never touch your server. The Brick renders the card form in the page and returns a token. Your server only ever sees that token.
1. Render the Brick and get a token
Load Mercado Pago's JavaScript SDK with your public key, mount the Card Payment Brick, and send the token it returns to your own endpoint.
2. Create the payment on the server
Call the Payments API from Laravel with the token, amount and payer details, using your private access token. Send an idempotency key so a double click or retry cannot charge twice.
// Laravel controller, simplified
$response = Http::withToken(config('services.mercadopago.token'))
->withHeaders(['X-Idempotency-Key' => $order->uuid])
->post('https://api.mercadopago.com/v1/payments', [
'transaction_amount' => $order->total,
'token' => $request->token,
'installments' => $request->installments,
'payer' => ['email' => $request->email],
]);3. Confirm with a webhook
A payment can be pending or change state after the browser returns. Treat the webhook, plus a fresh lookup of the payment by ID, as the source of truth. Verify the webhook's signature as described in Mercado Pago's documentation.
Things to test
- Declined and pending payments, not only approved ones.
- The same webhook arriving twice.
- Local currency and installment rules for each country you sell in.
