Skip to content

Commit

Permalink
Updating and adding new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jessica-gavaGN committed Oct 11, 2022
1 parent 1a7bdb8 commit a4547f8
Show file tree
Hide file tree
Showing 105 changed files with 1,937 additions and 74 deletions.
Empty file added .attach_pid44475
Empty file.
18 changes: 18 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@
<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 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"/>
Expand Down
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@
<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>
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

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

In the certs folder, insert your homologation / production certificate

## Requirements
* Java >= 7.0

## Running examples
Update src/main/resources/credentials.json file with client_id and client_secret of your application.
Update 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;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dependency>
<groupId>br.com.gerencianet.gnsdk</groupId>
<artifactId>gn-api-sdk-java</artifactId>
<version>1.0.2</version>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/br/com/gerencianet/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import java.io.IOException;
import java.io.InputStream;

import org.json.JSONObject;
import org.json.JSONTokener;

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

public Credentials() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream credentialsFile = classLoader.getResourceAsStream("credentials.json");
Expand All @@ -24,10 +22,10 @@ public Credentials() {
} 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.certificadoPix = credentials.getString("pix_cert");
this.certificate = credentials.getString("certificate");
this.sandbox = credentials.getBoolean("sandbox");
this.debug = credentials.getBoolean("debug");
}
Expand All @@ -40,8 +38,8 @@ public String getClientSecret() {
return clientSecret;
}

public String getCertificadoPix() {
return certificadoPix;
public String getCertificate() {
return certificate;
}

public boolean isSandbox() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import br.com.gerencianet.gnsdk.Gerencianet;
import br.com.gerencianet.gnsdk.exceptions.GerencianetException;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.gerencianet.defaults.marketplace.json;
package br.com.gerencianet.defaults.charge.json;

import java.util.HashMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.gerencianet.defaults.marketplace.json;
package br.com.gerencianet.defaults.charge.json;

import java.util.HashMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.gerencianet.defaults.marketplace.json;
package br.com.gerencianet.defaults.charge.json;

import java.util.HashMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package br.com.gerencianet.defaults.charge.json;

import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONObject;

import br.com.gerencianet.Credentials;
import br.com.gerencianet.gnsdk.Gerencianet;
import br.com.gerencianet.gnsdk.exceptions.GerencianetException;

public class OneStepLink {
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());

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

// items
JSONArray items = new JSONArray();

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

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

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

JSONObject settings = new JSONObject();
settings.put("payment_method", "all");
settings.put("billet_discount", 10);
settings.put("card_discount", 10);
settings.put("expire_at", "2022-12-12");
settings.put("request_delivery_address", false);

//notification url
JSONObject metadata = new JSONObject();
metadata.put("notification_url", "https://seu.dominio/retorno");

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

try {
Gerencianet gn = new Gerencianet(options);
JSONObject response = gn.call("oneStepLink", new HashMap<String,String>(), body);
System.out.println(response);
}catch (GerencianetException 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.gerencianet.defaults.charge.json;

import java.util.HashMap;

import org.json.JSONObject;

import br.com.gerencianet.Credentials;
import br.com.gerencianet.gnsdk.Gerencianet;
import br.com.gerencianet.gnsdk.exceptions.GerencianetException;

public class ResendChargeLink {
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("email", "oldbuck@gerencianet.com.br");

try {
Gerencianet gn = new Gerencianet(options);
JSONObject response = gn.call("resendChargeLink", params, body);
System.out.println(response);
}catch (GerencianetException 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,48 @@
package br.com.gerencianet.defaults.charge.json;

import java.util.HashMap;

import org.json.JSONObject;

import br.com.gerencianet.Credentials;
import br.com.gerencianet.gnsdk.Gerencianet;
import br.com.gerencianet.gnsdk.exceptions.GerencianetException;

public class UpdateChargeLink {
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("billet_discount", 0);
body.put("card_discount", 0);
body.put("message", "link test");
body.put("expire_at", "2022-12-12");
body.put("request_delivery_address", false);
body.put("payment_method", "all");

try {
Gerencianet gn = new Gerencianet(options);
JSONObject response = gn.call("updateChargeLink", params, body);
System.out.println(response);
}catch (GerencianetException 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
Expand Up @@ -6,7 +6,7 @@
import br.com.gerencianet.gnsdk.Gerencianet;
import br.com.gerencianet.gnsdk.exceptions.GerencianetException;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.gerencianet.defaults.marketplace.map;
package br.com.gerencianet.defaults.charge.map;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.gerencianet.defaults.marketplace.map;
package br.com.gerencianet.defaults.charge.map;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package br.com.gerencianet.defaults.marketplace.map;
package br.com.gerencianet.defaults.charge.map;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package br.com.gerencianet.defaults.charge.map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import br.com.gerencianet.Credentials;
import br.com.gerencianet.gnsdk.Gerencianet;
import br.com.gerencianet.gnsdk.exceptions.GerencianetException;
public class OneStepLink {
public static void main(String[] args) {
/* ********* Set credentials parameters ******** */
Credentials credentials = new Credentials();
HashMap<String, Object> options = new HashMap<String, Object>();
options.put("client_id", credentials.getClientId());
options.put("client_secret", credentials.getClientSecret());
options.put("sandbox", credentials.isSandbox());
/* ************************************************* */

List<Object> items = new ArrayList<Object>();
Map<String, Object> item1 = new HashMap<String, Object>();
item1.put("name", "Item 1");
item1.put("amount", 1);
item1.put("value", 1000);
Map<String, Object> item2 = new HashMap<String, Object>();
item2.put("name", "Item 2");
item2.put("amount", 1);
item2.put("value", 2000);
items.add(item1);
items.add(item2);

Map<String, Object> settings = new HashMap<String, Object>();
settings.put("payment_method", "all");
settings.put("billet_discount", 0);
settings.put("card_discount", 0);
settings.put("expire_at", "2020-12-12");
settings.put("request_delivery_address", false);

Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put("notification_url", "http://domain.com/notification");

Map<String, Object> body = new HashMap<String, Object>();
body.put("items", items);
body.put("settings", settings);
body.put("metadata", metadata);

try {
Gerencianet gn = new Gerencianet(options);
Map<String, Object> response = gn.call("oneStepLink", new HashMap<String,String>(), body);
System.out.println(response);
}catch (GerencianetException 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 a4547f8

Please sign in to comment.