All Projects → mercadopago → sdk-java

mercadopago / sdk-java

Licence: MIT License
Mercado Pago's Official Java SDK

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to sdk-java

sdk-ruby
Mercado Pago's Official Ruby SDK
Stars: ✭ 48 (+37.14%)
Mutual labels:  mercadopago, backend-sdk
sdk-dotnet
Mercado Pago's Official .Net SDK
Stars: ✭ 50 (+42.86%)
Mutual labels:  mercadopago, backend-sdk
SAPIDK-MercadoPago-PHP
SDK Alternativo de Mercado Pago en PHP
Stars: ✭ 14 (-60%)
Mutual labels:  mercadopago
cart-woocommerce
Mercado Pago's Official WooCommerce Plugin
Stars: ✭ 82 (+134.29%)
Mutual labels:  mercadopago
mercadoabierto
The Mercadolibre clone
Stars: ✭ 24 (-31.43%)
Mutual labels:  mercadopago
react-native-mercadopago-px
🚀 MercadoPago PX bridge for react-native
Stars: ✭ 87 (+148.57%)
Mutual labels:  mercadopago
cart-magento2
Mercado Pago's Official Magento 2 Plugin
Stars: ✭ 50 (+42.86%)
Mutual labels:  mercadopago
django-mercadopago
⚠️ Deprecated. Use https://github.com/jazzband/django-payments/ instead.
Stars: ✭ 32 (-8.57%)
Mutual labels:  mercadopago
mercadopago
Gem to communicate with the MercadoPago API
Stars: ✭ 31 (-11.43%)
Mutual labels:  mercadopago
cart-opencart
Mercado Pago's Official OpenCart 1 Plugin
Stars: ✭ 49 (+40%)
Mutual labels:  mercadopago
mercadopago
A Ruby Object-oriented gem that facilitates the usage of Mercadopago's API.
Stars: ✭ 16 (-54.29%)
Mutual labels:  mercadopago
react-native-mercadopago-checkout
github.com/blackboxvision/react-native-mercadopago-px
Stars: ✭ 15 (-57.14%)
Mutual labels:  mercadopago

Mercado Pago SDK for Java

Maven Central APM

The official Mercado Pago Java client library.

💡 Requirements

Java 1.8 or later

📲 Installation

First time using Mercado Pago? Create your Mercado Pago account, if you don’t have one already.

  1. Append MercadoPago dependencies to pom.xml
<dependency>
  <groupId>com.mercadopago</groupId>
  <artifactId>sdk-java</artifactId>
  <version>2.0.0</version>
</dependency>
  1. Run mvn install and that's all, you have Mercado Pago SDK installed.

  2. Copy the access_token in the credentials section of the page and replace YOUR_ACCESS_TOKEN with it.

That's it! Mercado Pago SDK has been successfully installed.

🌟 Getting Started

Simple usage looks like:

import com.mercadopago.*;

import com.mercadopago.client.payment.PaymentClient;
import com.mercadopago.client.payment.PaymentCreateRequest;
import com.mercadopago.client.payment.PaymentPayerRequest;
import com.mercadopago.exceptions.MPApiException;
import com.mercadopago.exceptions.MPException;
import com.mercadopago.resources.payment.Payment;
import java.math.BigDecimal;

public class Example {

  public static void main(String[] args) {
    MercadoPagoConfig.setAccessToken("YOUR_ACCESS_TOKEN");

    PaymentClient client = new PaymentClient();

    PaymentCreateRequest createRequest =
        PaymentCreateRequest.builder()
            .transactionAmount(new BigDecimal(1000))
            .token("your_cardtoken")
            .description("description")
            .installments(1)
            .paymentMethodId("visa")
            .payer(PaymentPayerRequest.builder().email("dummy_email").build())
            .build();

    try {
      Payment payment = client.create(createRequest);
      System.out.println(payment);
    } catch (MPApiException ex) {
      System.out.printf(
          "MercadoPago Error. Status: %s, Content: %s%n",
          ex.getApiResponse().getStatusCode(), ex.getApiResponse().getContent());
    } catch (MPException ex) {
      ex.printStackTrace();
    }
  }
}

Per-request Configuration

All the request methods accept an optional MPRequestOptions object. With this you can set a custom access token, custom timeouts or even any custom headers you want, like an idempotency key for example.

public class Example {

  public static void main(String[] args) {
    PaymentClient client = new PaymentClient();

    Map<String, String> customHeaders = new HashMap<>();
    customHeaders.put("x-idempotency-key", "...");

    MPRequestOptions requestOptions =
        MPRequestOptions.builder()
            .accessToken("custom_access_token")
            .connectionRequestTimeout(2000)
            .connectionTimeout(2000)
            .socketTimeout(2000)
            .customHeaders(customHeaders)
            .build();

    try {
      Payment payment = client.create(createRequest, requestOptions);
      System.out.println(payment);
    } catch (MPException | MPApiException ex) {
      ex.printStackTrace();
    }
  }
}

SDK configurations

You can also set some customizations directly at MercadoPagoConfig class, for example set custom timeouts, a custom http client, log configurations, etc...

public class Example {

  public static void main(String[] args) {

    MercadoPagoConfig.setConnectionRequestTimeout(2000);
    MercadoPagoConfig.setSocketTimeout(2000);
    MercadoPagoConfig.setLoggingLevel(Level.FINEST);
  }
}

Custom Http Client

You can use a custom http client instead of using the default MPDefaultHttpClient by implementing the MPHttpClient interface.

public class CustomHttpClient implements MPHttpClient {
  //...
}

📚 Documentation

See our documentation for more details.

🤝 Contributing

All contributions are welcome, ranging from people wanting to triage issues, others wanting to write documentation, to people wanting to contribute code.

Please read and follow our contribution guidelines. Contributions not following these guidelines will be disregarded. The guidelines are in place to make all of our lives easier and make contribution a consistent process for everyone.

Patches to version 1.x.x

Since the release of version 2.0.0, version 1 is deprecated and will not be receiving new features, only bug fixes. If you need to submit PRs for that version, please do so by using develop-v1 as your base branch.

❤️ Support

If you require technical support, please contact our support team at our developers site: English / Portuguese / Spanish

🏻 License

MIT license. Copyright (c) 2022 - Mercado Pago / Mercado Libre 
For more information, see the LICENSE file.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].