Java
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
e20.0
Installation via gradle
- Efí Pay
implementation 'br.com.efipay.efisdk:sdk-java-apis-efi:1.0.3'
Installation via maven
- Efí Pay
<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.
- Efí Pay
$ git clone https://github.com/efipay/sdk-java-examples-apis-efi.git
Starting
Requires module and packages:
- Efí Pay
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:
- Efí Pay
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
- Map
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);
Map<String, Object> options = new HashMap<String, Object>();
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
- Map
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);
Map<String, Object> options = new HashMap<String, Object>();
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.