Laravel MercadoPago provides eight dedicated service classes, each handling a specific aspect of the Mercado Pago integration. All services are registered as singletons and can be injected via dependency injection.
Type Safety - Accept and return properly typed data structures
Version Compatibility - Handle SDK version differences transparently
All services are automatically registered in the service container. You can inject them into your controllers, jobs, or other services without manual configuration.
Purpose: Manage saved payment cards for customersLocation: src/Services/CardService.php:9Use Cases:
Saving customer payment cards for future use
Deleting stored cards
Enabling subscription or recurring payments
Methods:
// Save a card to a customerpublic function create(string $customerId, array $payload): mixed// Delete a saved cardpublic function delete(string $customerId, string $cardId): mixed
Example - Save Card:
use Fitodac\LaravelMercadoPago\Services\CardService;class CardController extends Controller{ public function __construct( private CardService $cardService ) {} public function store(Request $request) { $customerId = auth()->user()->mercadopago_customer_id; $card = $this->cardService->create($customerId, [ 'token' => $request->input('token') // From SDK.js ]); // Store card reference auth()->user()->paymentCards()->create([ 'mercadopago_card_id' => $card->id, 'last_four' => $card->last_four_digits, 'brand' => $card->payment_method->name ]); return response()->json(['card_id' => $card->id]); }}
Example - Delete Card:
public function destroy(string $cardId){ $customerId = auth()->user()->mercadopago_customer_id; $this->cardService->delete($customerId, $cardId); auth()->user()->paymentCards() ->where('mercadopago_card_id', $cardId) ->delete(); return response()->json(['message' => 'Card deleted']);}
Purpose: Process full and partial refunds for completed paymentsLocation: src/Services/RefundService.php:9Use Cases:
Issuing full refunds
Processing partial refunds
Handling order cancellations
Methods:
public function create(string $paymentId, array $payload = []): mixed
The service automatically determines whether to issue a full or partial refund based on the presence of an amount key in the payload.Example - Full Refund:
use Fitodac\LaravelMercadoPago\Services\RefundService;class RefundController extends Controller{ public function __construct( private RefundService $refundService ) {} public function refundFull(string $paymentId) { $refund = $this->refundService->create($paymentId); return response()->json([ 'refund_id' => $refund->id, 'status' => $refund->status ]); }}
Purpose: Create test users for development and QA automationLocation: src/Services/TestUserService.php:9Use Cases:
Generating test users for sandbox testing
Automating QA workflows
Creating buyer and seller test accounts
Methods:
public function create(array $payload): mixed
Example:
use Fitodac\LaravelMercadoPago\Services\TestUserService;class TestUserController extends Controller{ public function __construct( private TestUserService $testUserService ) {} public function createTestUser() { $testUser = $this->testUserService->create([ 'site_id' => 'MLA' // Argentina ]); return response()->json([ 'id' => $testUser['id'], 'nickname' => $testUser['nickname'], 'email' => $testUser['email'], 'password' => $testUser['password'] ]); }}
TestUserService uses SdkHttpClient to make direct API calls (src/Services/TestUserService.php:17) since the test user endpoint isn’t wrapped by the standard SDK client classes.