To use this plugin, add mercadopago_sdk
as a dependency in your pubspec.yaml file.
- Basic checkout
- Customized checkout
- Generic methods
Configure your credentials
- Get your CLIENT_ID and CLIENT_SECRET in the following address:
- Argentina: https://www.mercadopago.com/mla/herramientas/aplicaciones
- Brazil: https://www.mercadopago.com/mlb/ferramentas/aplicacoes
- México: https://www.mercadopago.com/mlm/herramientas/aplicaciones
- Venezuela: https://www.mercadopago.com/mlv/herramientas/aplicaciones
- Colombia: https://www.mercadopago.com/mco/herramientas/aplicaciones
- Chile: https://www.mercadopago.com/mlc/herramientas/aplicaciones
import 'package:mercadopago_sdk/mercadopago_sdk.dart';
var mp = MP("CLIENT_ID", "CLIENT_SECRET");
Instance with only access token
var mp = MP.fromAccessToken("TOKEN");
Get an existent Checkout preference
Future<Map<String, dynamic>> index() async {
result = await mp.getPreference("PREFERENCE_ID");
return result;
}
Create a Checkout preference
Future<Map<String, dynamic>> index() async {
var preference = {
"items": [
{
"title": "Test",
"quantity": 1,
"currency_id": "USD",
"unit_price": 10.4
}
]
};
var result = await mp.createPreference(preference);
return result;
}
Update an existent Checkout preference
Future<Map<String, dynamic>> index() async {
var preference = {
"items": [
{
"title": "Test Modified",
"quantity": 1,
"currency_id": "USD",
"unit_price": 20.4
}
]
};
var result = await mp.updatePreference(id, preference);
return result;
}
Future<Map<String, dynamic>> index() async {
var filters = {
"id": None,
"external_reference": None
};
var searchResult = await mp.searchPayment(filters)
return searchResult;
}
Future<Map<String, dynamic>> index() async {
paymentInfo = await mp.getPayment("PID");
return paymentInfo;
}
Future<Map<String, dynamic>> index() async {
var result = await mp.cancelPayment("PID");
// Show result
return result;
}
Future<Map<String, dynamic>> index() async {
var result = await mp.refundPayment("PID");
// Show result
return result;
}
- Get your ACCESS_TOKEN in the following address:
- Argentina: https://www.mercadopago.com/mla/account/credentials
- Brazil: https://www.mercadopago.com/mlb/account/credentials
- Mexico: https://www.mercadopago.com/mlm/account/credentials
- Venezuela: https://www.mercadopago.com/mlv/account/credentials
- Colombia: https://www.mercadopago.com/mco/account/credentials
import 'package:mercadopago_sdk/mercadopago_sdk.dart';
var mp = MP("ACCESS_TOKEN");
mp.post("/v1/payments", data);
mp.post("/v1/customers", {"email": "email@test.com"});
mp.get("/v1/customers/CUSTOMER_ID");
- View more Custom checkout related APIs in Developers Site
- Argentina: https://www.mercadopago.com.ar/developers
- Brazil: https://www.mercadopago.com.br/developers
- Mexico: https://www.mercadopago.com.mx/developers
- Venezuela: https://www.mercadopago.com.ve/developers
- Colombia: https://www.mercadopago.com.co/developers
You can access any other resource from the MercadoPago API using the generic methods:
// Get a resource, with optional URL params. Also you can disable authentication for public APIs
mp.get("/resource/uri", { params, authenticate });
// Create a resource with "data" and optional URL params.
mp.post("/resource/uri", { data, params });
// Update a resource with "data" and optional URL params.
mp.put("/resource/uri", { data, params });
// Delete a resource with optional URL params.
mp.delete("/resource/uri", { params });
For example, if you want to get the Sites list (no params and no authentication):
var result = mp.get("/sites");
print(result);