Mercado Pago Android SDK

This is the latest version: Version

Please, if you have any problems with this version, open an issue in our Github repository


Before starting, take into account that our mobile SDK solution is available in Argentina, Mexico, Brazil, Colombia, Venezuela, Perú and Chile.

*Only card payments in Colombia, Venezuela and Chile with the current SDK version.


Using gradle? Add it in the build.gradle file of the module where you will integrate us.

Otherwise download Mercado Pago SDK

                   dependencies {
                     compile 'com.mercadopago:sdk:'
                   }
                   
                   
                

Possible integrations

Pay a Checkout Preference
  • Create a checkout preference in your server and start our checkout, we handle everything else.
  • Collect data to make a payment.
  • Start our checkout process, we'll return all the information needed to make a payment. It must be made from your server.

  • Pay a Checkout Preference

    After creating a Checkout Preference in Mercado Pago servers, you can use it to start an entire checkout process, getting a Payment as a result.
    Check out our Server side SDK's here.

    Create or get a Checkout Preference

    Get a preference from your server in order to pay it with Our Checkout. You can use the "CustomServer" class in our SDK to retrieve it:

                  
                    Map<String, Object> necessaryInfoMap = new HashMap<>();
                    necessaryInfoMap.put("item_id", "Id1");
                    necessaryInfoMap.put("quantity", 1);
                    necessaryInfoMap.put("site", Sites.ARGENTINA);
                    CustomServer.createCheckoutPreference(this, "https://your-base-URL.com/",
                                    "your_create_preference_URI", necessaryInfoMap, new Callback<CheckoutPreference>() {
                                        @Override
                                        public void success(CheckoutPreference checkoutPreference) {
                                            startMercadoPagoCheckout(checkoutPreference);
                                        }
    
                                        @Override
                                        public void failure(ApiException error) {
                                            //Handle failure
                                        }
                                    });
                     
                     
                  

    Start the Checkout process

    Start Our Checkout with a preference posted to Mercado Pago Servers.

                  
    private void startMercadoPagoCheckout(CheckoutPreference checkoutPreference) {
      new MercadoPagoCheckout.Builder()
              .setActivity(activity)
              .setPublicKey(publicKey)
              .setCheckoutPreference(checkoutPreference)
              .startForPayment();
    }
                     
                     
                  
    Get the response:
                  
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == MercadoPagoCheckout.CHECKOUT_REQUEST_CODE) {
            if (resultCode == MercadoPagoCheckout.PAYMENT_RESULT_CODE) {
                Payment payment = JsonUtil.getInstance().fromJson(data.getStringExtra("payment"), Payment.class);
                //Done!
            } else if (resultCode == RESULT_CANCELED) {
                if (data != null && data.getStringExtra("mercadoPagoError") != null) {
                    //Resolve error in checkout
                } else {
                    //Resolve canceled checkout
                }
            }
        }
    }
    
                     
                     
                  

    Collect data to make a Payment

    An alternative to avoid creating Checkout Preferences in Mercado Pago servers is to collect data to make the payment, and finish it in your servers.

    Create a local instance of a Checkout Preference

    If needed, specify constraints to the Checkout process within this object.

                  
    CheckoutPreference checkoutPreference = new CheckoutPreference.Builder()
                                                  .addItem(new Item("Item", new BigDecimal("1000")))
                                                  .setSite(Sites.ARGENTINA)
                                                  .addExcludedPaymentType(PaymentTypes.TICKET) //Handle exclusions by payment types
                                                  .addExcludedPaymentMethod(PaymentMethods.ARGENTINA.VISA) //Exclude specific payment methods
                                                  .setMaxInstallments(1) //Limit the amount of installments
                                                  .build();
    startMercadoPagoCheckout(checkoutPreference);
                     
                     
                  

    Start the Checkout process

    Start Our Checkout with a local instance of a Checkout Preference.

                  
    private void startMercadoPagoCheckout(CheckoutPreference checkoutPreference) {
      new MercadoPagoCheckout.Builder()
              .setActivity(activity)
              .setPublicKey(publicKey)
              .setCheckoutPreference(checkoutPreference)
              .startForPaymentData();
    }
                     
                     
                  
    Get the response:
                  
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == MercadoPagoCheckout.CHECKOUT_REQUEST_CODE) {
            if (resultCode == MercadoPagoCheckout.PAYMENT_DATA_RESULT_CODE) {
                PaymentData paymentData = JsonUtil.getInstance().fromJson(data.getStringExtra("paymentData"), PaymentData.class);
                //Done!
            } else if (resultCode == RESULT_CANCELED) {
                if (data != null && data.getStringExtra("mercadoPagoError") != null) {
                    //Resolve error in checkout
                } else {
                    //Resolve canceled checkout
                }
            }
        }
    }
                     
                     
                  
    The PaymentData object has all the information needed to make the payment in your server:
                  
    String paymentMethodId = paymentData.getPaymentMethod().getId();
    Long cardIssuerId = paymentData.getIssuer() == null ? null : paymentData.getIssuer().getId();
    Integer installment = paymentData.getPayerCost() == null ? null : paymentData.getPayerCost().getInstallments();
    String cardToken = paymentData.getToken() == null ? null : paymentData.getToken().getId();
    Long campaignId = paymentData.getDiscount() == null ? null : paymentData.getDiscount().getId();
                     
                     
                  
    Check the docs to create a Payment in your server.
    Check out our Server side SDK's here.

    Customize colors

    Create a Decoration Preference and start checkout:

               
    private void startMercadoPagoCheckout(CheckoutPreference checkoutPreference) {
    
    DecorationPreference decorationPreference = new DecorationPreference.Builder()
            .setBaseColor(ContextCompat.getColor(context, R.color.your_color))
            .enableDarkFont() //Optional
            .build();
    
    new MercadoPagoCheckout.Builder()
            .setActivity(activity)
            .setPublicKey(publicKey)
            .setCheckoutPreference(checkoutPreference)
            .setDecorationPreference(decorationPreference)
            .startForPayment();
    }