This library provides developers with a simple set of bindings to the Mercado Pago API.
- Append MercadoPago dependencies to pom.xml
...
<dependencies>
<dependency>
<groupId> com.mercadopago </groupId>
<artifactId> dx-java </artifactId>
<version> 1.0.36 </version>
</dependency>
</dependencies>
...
- Run
mvn install
and thats all, you have Mercado Pago SDK installed.
- Import Mercado Pago basic clases.
import com.mercadopago.*;
- Setup your credentials.
- For Web-checkout:
MercadoPago.SDK.setClientSecret("CLIENT_SECRET"); MercadoPago.SDK.setClientId("CLIENT_ID");
- For API or Custom-checkout:
MercadoPago.SDK.setAccessToken("ACCESS_TOKEN");
- Using Resource objects.
Sample
import com.mercadopago.*;
import com.mercadopago.exceptions.MPConfException;
import com.mercadopago.exceptions.MPException;
import com.mercadopago.resources.Payment;
import com.mercadopago.resources.datastructures.payment.Payer;
public class Main {
public static void main(String[] args)throws MPException, MPConfException {
MercadoPago.SDK.setClientSecret(System.getenv("CLIENT_SECRET"));
MercadoPago.SDK.setClientId(System.getenv("CLIENT_ID_OK"));
Payment payment = new Payment()
.setTransactionAmount(100f)
.setToken("your_cardtoken")
.setDescription("description")
.setInstallments(1)
.setPaymentMethodId("visa")
.setPayer(new Payer()
.setEmail("dummy_email"));
payment.save();
}
}
- Create an issue https://github.com/mercadopago/dx-java/issues
- Follow your issue status in Issues Support Dashboard https://github.com/mercadopago/dx-java/projects/2