Overview
The PaymentMethodService class retrieves all available payment methods for your MercadoPago account. This includes credit cards, debit cards, and other payment types accepted in your configured countries.
Source : src/Services/PaymentMethodService.php:9
Available payment methods depend on your MercadoPago account configuration, supported countries, and enabled payment types.
Constructor
public function __construct (
private MercadoPagoClientFactory $clientFactory ,
) {}
Dependencies
clientFactory
MercadoPagoClientFactory
required
Factory for creating and configuring MercadoPago SDK clients. Automatically injected by Laravel’s service container.
Methods
all()
Retrieves all available payment methods for the configured account.
public function all () : mixed
Source : src/Services/PaymentMethodService.php:15
Parameters
This method takes no parameters.
Returns
Array of payment method objects. Each payment method contains: Payment method identifier (e.g., “visa”, “master”, “amex”)
Display name (e.g., “Visa”, “Mastercard”)
Payment type: credit_card, debit_card, prepaid_card, ticket, bank_transfer, etc.
Payment method status: active or inactive
URL to payment method logo image
Whether the method supports deferred capture: supported, unsupported, or does_not_apply
Configuration settings:
security_code (object): CVV requirements
card_number (object): Card number validation
bin (object): BIN detection settings
Additional fields required for this payment method
Time in minutes until payment is credited
Available issuing banks/institutions
Usage
Controller injection
Service resolution
Route closure
Filter by type
use Fitodac\LaravelMercadoPago\Services\ PaymentMethodService ;
use Illuminate\Http\ JsonResponse ;
final class PaymentMethodController
{
public function index (
PaymentMethodService $paymentMethodService
) : JsonResponse {
$methods = $paymentMethodService -> all ();
// Format response
$formatted = collect ( $methods ) -> map ( fn ( $method ) => [
'id' => data_get ( $method , 'id' ),
'name' => data_get ( $method , 'name' ),
'type' => data_get ( $method , 'payment_type_id' ),
'thumbnail' => data_get ( $method , 'secure_thumbnail' ),
]);
return response () -> json ( $formatted );
}
}
Common Payment Method IDs
Credit Cards
ID Name visaVisa masterMastercard amexAmerican Express naranjaNaranja cabalCabal cencosudCencosud cordobesaCordobesa
Debit Cards
ID Name debvisaVisa Débito debmasterMastercard Débito (Maestro) debcabalCabal Débito
Available payment methods vary by country and account configuration. Always fetch methods dynamically rather than hardcoding IDs.
Common Patterns
Display payment options to users
Build a payment method selector:
use Fitodac\LaravelMercadoPago\Services\ PaymentMethodService ;
public function getPaymentOptions ()
{
$methods = app ( PaymentMethodService :: class ) -> all ();
$options = collect ( $methods )
-> filter ( fn ( $m ) => data_get ( $m , 'status' ) === 'active' )
-> filter ( fn ( $m ) => data_get ( $m , 'payment_type_id' ) === 'credit_card' )
-> map ( fn ( $method ) => [
'value' => data_get ( $method , 'id' ),
'label' => data_get ( $method , 'name' ),
'icon' => data_get ( $method , 'secure_thumbnail' ),
])
-> values ();
return view ( 'checkout.payment-methods' , [
'paymentMethods' => $options ,
]);
}
Cache payment methods
Reduce API calls by caching results:
use Fitodac\LaravelMercadoPago\Services\ PaymentMethodService ;
use Illuminate\Support\Facades\ Cache ;
public function getCachedPaymentMethods ()
{
return Cache :: remember ( 'mercadopago.payment_methods' , now () -> addHours ( 24 ), function () {
return app ( PaymentMethodService :: class ) -> all ();
});
}
Validate payment method ID
Verify a payment method is available:
use Fitodac\LaravelMercadoPago\Services\ PaymentMethodService ;
public function validatePaymentMethod ( string $methodId ) : bool
{
$methods = app ( PaymentMethodService :: class ) -> all ();
return collect ( $methods ) -> contains ( function ( $method ) use ( $methodId ) {
return data_get ( $method , 'id' ) === $methodId
&& data_get ( $method , 'status' ) === 'active' ;
});
}
Get installment options
Extract installment information:
use Fitodac\LaravelMercadoPago\Services\ PaymentMethodService ;
public function getInstallmentOptions ( string $methodId )
{
$methods = app ( PaymentMethodService :: class ) -> all ();
$method = collect ( $methods )
-> firstWhere ( 'id' , $methodId );
if ( ! $method ) {
return [];
}
$issuers = data_get ( $method , 'financial_institutions' , []);
return collect ( $issuers ) -> map ( fn ( $issuer ) => [
'id' => data_get ( $issuer , 'id' ),
'name' => data_get ( $issuer , 'name' ),
]) -> values ();
}
Build frontend configuration
Generate configuration for MercadoPago.js:
use Fitodac\LaravelMercadoPago\Services\ PaymentMethodService ;
public function getFrontendConfig ()
{
$methods = app ( PaymentMethodService :: class ) -> all ();
return [
'public_key' => config ( 'mercadopago.public_key' ),
'payment_methods' => collect ( $methods )
-> filter ( fn ( $m ) => data_get ( $m , 'status' ) === 'active' )
-> map ( fn ( $m ) => [
'id' => data_get ( $m , 'id' ),
'name' => data_get ( $m , 'name' ),
'type' => data_get ( $m , 'payment_type_id' ),
])
-> values (),
];
}
Response Example
Typical response for a single payment method:
{
"id" : "visa" ,
"name" : "Visa" ,
"payment_type_id" : "credit_card" ,
"status" : "active" ,
"secure_thumbnail" : "https://www.mercadopago.com/org-img/MP3/API/logos/visa.gif" ,
"thumbnail" : "https://www.mercadopago.com/org-img/MP3/API/logos/visa.gif" ,
"deferred_capture" : "supported" ,
"settings" : [
{
"security_code" : {
"length" : 3 ,
"card_location" : "back" ,
"mode" : "mandatory"
},
"card_number" : {
"length" : 16 ,
"validation" : "standard"
},
"bin" : {
"pattern" : "^4" ,
"installments_pattern" : "^4" ,
"exclusion_pattern" : null
}
}
],
"additional_info_needed" : [
"cardholder_name" ,
"cardholder_identification_number"
],
"min_allowed_amount" : 0.5 ,
"max_allowed_amount" : 250000 ,
"accreditation_time" : 0 ,
"financial_institutions" : []
}
Error Handling
MercadoPagoConfigurationException
Thrown when:
MercadoPago SDK is not installed
Required SDK classes are not found
SDK methods are unavailable
Thrown by the MercadoPago SDK for API errors:
Invalid credentials
Network errors
API unavailability
Error handling example
use Fitodac\LaravelMercadoPago\Exceptions\ MercadoPagoConfigurationException ;
try {
$methods = $paymentMethodService -> all ();
return response () -> json ( $methods );
} catch ( MercadoPagoConfigurationException $e ) {
\ Log :: error ( 'MercadoPago configuration error' , [
'message' => $e -> getMessage (),
]);
return response () -> json ([ 'error' => 'Service misconfigured' ], 500 );
} catch ( \ Exception $e ) {
\ Log :: error ( 'Failed to fetch payment methods' , [
'error' => $e -> getMessage (),
]);
return response () -> json ([ 'error' => 'Could not load payment methods' ], 500 );
}
PaymentService Process payments with payment methods
CardService Save customer payment methods
Additional Resources
Processing Payments Guide Learn about payment processing
MercadoPago API Documentation Official payment methods API reference