getPreferenceId function
Future<String?>
getPreferenceId(
- double amount,
- String desc,
- BuildContext context,
- String _accessToken,
Implementation
Future<String?> getPreferenceId(double amount, String desc, BuildContext context, String _accessToken) async {
var code = appSettings.code;
String returnURL = "";
String cancelURL = '';
returnURL = currentBase + "mercadopago_success?booking=$cartLastAddedId";
cancelURL = currentBase + "mercadopago_cancel?booking=$cartLastAddedId";
var response = await http.post(
Uri.parse("https://api.mercadopago.com/checkout/preferences"),
body: convert.jsonEncode({
"items": [
{
"title": desc,
"description": "",
"picture_url": "http://www.myapp.com/myimage.jpg",
"category_id": "cat123",
"quantity": 1,
"currency_id": code, // "BRL",
// "currency_id": "BRL",
"unit_price": amount
}
],
"payer": {
"phone": {},
"identification": {},
"address": {}
},
"payment_methods": {
"excluded_payment_methods": [
{}
],
"excluded_payment_types": [
{}
]
},
"shipments": {
"free_methods": [
{}
],
"receiver_address": {}
},
"back_urls": {
"success": returnURL,
"failure": cancelURL,
"pending": returnURL
},
"differential_pricing": {},
// "tracks": [
// {
// "type": "google_ad"
// }
// ]
}),
headers: {
"content-type": "application/json",
'Authorization': 'Bearer ' + _accessToken // Access Token
});
final body = convert.jsonDecode(response.body);
if (response.statusCode == 201) {
return body["id"];
} else
messageError(context, body["message"]);
return null;
}