Skip to main content

Java

Learn how to install and configure our Java SDK to use Efí APIs

Attention!

Requests made to Efí APIs using the Java SDK require the certificate generated in your Efí account in .p12 format.


Prerequisites

  • Java >=7.0

Tested with

  • Java 7.0, 8.0, 13.0 e 20.0

Installation via gradle

implementation 'br.com.efipay.efisdk:sdk-java-apis-efi:1.0.3'

Installation via maven

<dependency>
<groupId>br.com.efipay.efisdk</groupId>
<artifactId>sdk-java-apis-efi</artifactId>
<version>1.0.3</version>
</dependency>

Installing via Git the Example SDK

Our sample SDK is available in our Efí Github repository.

$ git clone https://github.com/efipay/sdk-java-examples-apis-efi.git

Starting

Requires module and packages:

import br.com.efi.efisdk.EfiPay;
import br.com.efi.efisdk.exceptions.EfiPayException;

Although responses from web services are in json format, the SDK will convert any response from the server to a JSONObject or a Map <String, Object>. The code must be inside a try-catch and exceptions can be handled as follows:

try {
/* code */
} catch(EfiPayException e) {
/* EfiPay's api errors will come here */
} catch(Exception ex) {
/* Other errors will come here */
}

For sandbox environment

Instantiate the module passing its Client_Id, Client_Secret and saging being equal to true:

JSONObject options = new JSONObject();
options.put("client_id", "client_id");
options.put("client_secret", "client_secret");
options.put("certificate", "./certs/developmentCertificate.p12");
options.put("sandbox", true);

EfiPay efi = new EfiPay(options);

For production environment

To change the environment to production, simply set the third sandbox to false, and your production Client_Id and Client_Secret:

JSONObject options = new JSONObject();
options.put("client_id", "client_id");
options.put("client_secret", "client_secret");
options.put("certificate", "./certs/productionCertificate.p12");
options.put("sandbox", false);

EfiPay efi = new EfiPay(options);

Running Tests

To execute the test suite with coverage:

mvn clean test jacoco:report

Running examples

To run some existing examples, follow the steps described in our Efí Github.