Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jessica-gava-efi committed Aug 7, 2023
1 parent d488bee commit 419f6d5
Show file tree
Hide file tree
Showing 228 changed files with 10,307 additions and 1 deletion.
57 changes: 57 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
.settings
src/main/java/br/com/efi/open_accounts/
34 changes: 34 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sdk-java-examples-apis-efi</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<filteredResources>
<filter>
<id>1665497833948</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
26 changes: 26 additions & 0 deletions README-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h1 align="center">Java SDK for APIs Efí Pay using Examples</h1>

![Banner APIs Efí Pay](https://gnetbr.com/BJgSIUhlYs)

<p align="center">
<a href="https://github.com/efipay/sdk-java-examples-apis-efi">Portuguese</a> |
<span><b>English</b></span>
</p>

This project has some java file examples to test the Java SDK for efi API.

## Requirements
* Java >= 7.0

## Running examples
Update the src/main/resources/credentials.json file with client_id, client_secret and certificate of your application.

You can run using any Java IDE, like Eclipse or Netbeans, with Maven plugin installed, and follow these steps:
1. clone this git repository in a local directory of your choice;
2. on your IDE, open the folder as a Maven project. It'll download sdk-java-apis-efi as a dependencie;
3. choose any project's example and run it as a Java Application. The result will be displayed on the console.

**Warning:** Some examples require you to change some parameters to work, like br.com.efi.charges.carnet.json.DetailCarnet.java where you must change the id parameter.



30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
# sdk-java-examples-apis-efi
<h1 align="center">SDK Java para APIs Efí Pay usando Examplos</h1>

![Banner APIs Efí Pay](https://gnetbr.com/BJgSIUhlYs)

<p align="center">
<span><b>Português</b></span> |
<a href="https://github.com/efipay/sdk-java-examples-apis-efi/blob/master/README-en.md">Inglês</a>
</p>

Este projeto contém alguns exemplos de arquivos java para testar a SDK Java para APIs Efí Pay

## Requisitos
* Java >= 7.0

## Execução de exemplos

Atualize o arquivo src/main/resources/credentials.json com client_id, client_secret e certificate de seu aplicativo.

Você pode rodar usando qualquer IDE Java, como Eclipse ou Netbeans, com o plugin Maven instalado, e seguir os seguintes passos:
1. clone este repositório git em um diretório local de sua escolha;
2. em sua IDE, abra a pasta como um projeto Maven. Ele fará o download do sdk-java-apis-efi como uma dependência;
3. escolha qualquer exemplo de projeto e execute-o como um aplicativo Java. O resultado será exibido no console.

**Aviso:** Alguns exemplos requerem que você altere alguns parâmetros para funcionar, como br.com.efi.charges.carnet.json.DetailCarnet.java onde você deve alterar o parâmetro id.






Empty file.
Empty file added certs/productionCertificate.p12
Empty file.
35 changes: 35 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com.efipay</groupId>
<artifactId>sdk-java-examples-apis-efi</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>br.com.efipay.efisdk</groupId>
<artifactId>sdk-java-apis-efi</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</project>
53 changes: 53 additions & 0 deletions src/main/java/br/com/efi/Credentials.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package br.com.efi;

import java.io.IOException;
import java.io.InputStream;
import org.json.JSONObject;
import org.json.JSONTokener;

public class Credentials {
private String clientId;
private String clientSecret;
private String certificate;
private boolean sandbox;
private boolean debug;

public Credentials() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream credentialsFile = classLoader.getResourceAsStream("credentials.json");
JSONTokener tokener = new JSONTokener(credentialsFile);
JSONObject credentials = new JSONObject(tokener);
try {
credentialsFile.close();
} catch (IOException e) {
System.out.println("Impossible to close file credentials.json");
}

this.clientId = credentials.getString("client_id");
this.clientSecret = credentials.getString("client_secret");
this.certificate = credentials.getString("certificate");
this.sandbox = credentials.getBoolean("sandbox");
this.debug = credentials.getBoolean("debug");
}

public String getClientId() {
return clientId;
}

public String getClientSecret() {
return clientSecret;
}

public String getCertificate() {
return certificate;
}

public boolean isSandbox() {
return sandbox;
}

public boolean isDebug() {
return debug;
}

}
40 changes: 40 additions & 0 deletions src/main/java/br/com/efi/charges/billet/json/CancelBillet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package br.com.efi.charges.billet.json;

import java.util.HashMap;

import org.json.JSONObject;

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

public class CancelBillet {
public static void main(String[] args) {
/* ********* Set credential parameters ******** */

Credentials credentials = new Credentials();

JSONObject options = new JSONObject();
options.put("client_id", credentials.getClientId());
options.put("client_secret", credentials.getClientSecret());
options.put("sandbox", credentials.isSandbox());

/* ************************************************* */

HashMap<String, String> params = new HashMap<String, String>();
params.put("id", "0");

try {
EfiPay efi = new EfiPay(options);
JSONObject response = efi.call("cancelCharge", params, new JSONObject());
System.out.println(response);
}catch (EfiPayException e){
System.out.println(e.getCode());
System.out.println(e.getError());
System.out.println(e.getErrorDescription());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package br.com.efi.charges.billet.json;

import java.util.HashMap;

import org.json.JSONObject;

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

public class CreateBilletHistory {
public static void main(String[] args) {
/* ********* Set credential parameters ******** */

Credentials credentials = new Credentials();

JSONObject options = new JSONObject();
options.put("client_id", credentials.getClientId());
options.put("client_secret", credentials.getClientSecret());
options.put("sandbox", credentials.isSandbox());

/* ************************************************* */

HashMap<String, String> params = new HashMap<String, String>();
params.put("id", "0");

JSONObject body = new JSONObject();
body.put("description", "This charge was not fully paid");

try {
EfiPay efi = new EfiPay(options);
JSONObject response = efi.call("createChargeHistory", params, body);
System.out.println(response);
}catch (EfiPayException e){
System.out.println(e.getCode());
System.out.println(e.getError());
System.out.println(e.getErrorDescription());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
52 changes: 52 additions & 0 deletions src/main/java/br/com/efi/charges/billet/json/CreateCharge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package br.com.efi.charges.billet.json;

import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONObject;

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

public class CreateCharge {
public static void main(String[] args) {
/* ********* Set credentials parameters ******** */

Credentials credentials = new Credentials();

JSONObject options = new JSONObject();
options.put("client_id", credentials.getClientId());
options.put("client_secret", credentials.getClientSecret());
options.put("sandbox", credentials.isSandbox());

/* ************************************************* */

JSONArray items = new JSONArray();

JSONObject item1 = new JSONObject();
item1.put("name", "Item 1");
item1.put("amount", 1);
item1.put("value", 2000);

JSONObject item2 = new JSONObject("{\"name\":\"Item 1\", \"amount\":1, \"value\":1}");

items.put(item1);
items.put(item2);

JSONObject body = new JSONObject();
body.put("items", items);

try {
EfiPay efi = new EfiPay(options);
JSONObject response = efi.call("createCharge", new HashMap<String,String>(), body);
System.out.println(response);
}catch (EfiPayException e){
System.out.println(e.getCode());
System.out.println(e.getError());
System.out.println(e.getErrorDescription());
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Loading

0 comments on commit 419f6d5

Please sign in to comment.