I am trying to implement for the first time the Mercado Pago's transparent checkout in Android.
I've already downloaded the newest version of the SDK provided in https://github.com/mercadopago/px-android and executed it normally in the Emulator.
In the GitHub page mentioned above, we have an explanation of how to implement Mercado Pago's checkout with just one line of code:
new MercadoPagoCheckout.Builder("public_key", "checkout_preference_id")
.build()
.startPayment(activityOrContext, requestCode);
Where public_key
we can get in the credentials webpage. But the String checkout_preference_id
I have no idea of how to create it, even though they showed how to create it at the end of the GitHub webpage.
Create your preference id
curl -X POST \
'https://api.mercadopago.com/checkout/preferences?access_token=ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"items": [
{
"title": "Dummy Item",
"description": "Multicolor Item",
"quantity": 1,
"currency_id": "ARS",
"unit_price": 10.0
}
],
"payer": {
"email": "payer@email.com"
}
}'
I tried to put a random String in checkout_preference_id
, but it did not work. Only the String in the example app of Mercado Pago worked.
private static final String DUMMY_PREFERENCE_ID = "243962506-0bb62e22-5c7b-425e-a0a6-c22d0f4758a9";
All the other ways of implementing it presented in the example app of Mercado Pago require a fake confirmation of payment.
I appreciate if anyone could show some code of how to create and pass the variable checkout_preference_id
into the main command of Mercado Pago payment.
EDIT
I also appreciate if anyone could give us an example of a Not fake confirmation of payment with some code.
I guess checkout_preference_id
can be accessed via a Marketplace website or maybe creating a curl
using Android's webservice. Then, it is still a mystery to me.
Concerning to the alternitive way of paying with MercadoPago, we have this other arguments to pass:
new MercadoPagoCheckout.Builder("public_key", checkoutPreference, paymentConfiguration)
.build()
.startPayment(activityOrContext, requestCode);
Where checkoutPreference
allows you to create a custom item to sell.
final Item item = new Item.Builder("Product Title", 1, new BigDecimal(12.3)).setDescription("Product Description").build();
CheckoutPreference checkoutPreference = new CheckoutPreference.Builder(Sites.BRASIL, "a@a.a", Collections.singletonList(item)).setDefaultInstallments(1).build();
paymentConfiguration
is implemented the fake confirmation of payment.
PaymentConfiguration paymentConfiguration = new PaymentConfiguration.Builder(new MyPaymentProcessor()).build();
Where the class MyPaymentProcessor()
and the other classes in which it depends on can be found in the GitHub example.