GithubHelp home page GithubHelp logo

gerencianet / gn-api-sdk-java Goto Github PK

View Code? Open in Web Editor NEW
20.0 9.0 8.0 74 KB

SDK em Java integrada a API Gerencianet. Esta SDK está preparada para integração à API Pix e API Boletos da Gerencianet, que lhe permite realizar o gerenciamento de cobranças Pix com QR Code e Pix Copia e Cola, boleto/Bolix, carnê, cartão de crédito e muito mais.

Home Page: https://dev.gerencianet.com.br/docs/instalacao-sdk-java

License: MIT License

Java 100.00%
java sdk sdk-java marketplace split subscription assinatura qrcode pix pix-copia-e-cola

gn-api-sdk-java's Introduction

SDK GERENCIANET FOR JAVA

Sdk for Gerencianet Pagamentos' API. For more informations about parameters and values, please refer to Gerencianet documentation.

Em caso de dúvidas, você pode verificar a Documentação da API na Gerencianet e, necessitando de mais detalhes ou informações, entre em contato com nossa consultoria técnica, via nossos Canais de Comunicação.

Build Status Coverage Status Maven Central

Requirements

  • Java >= 7.0

Tested with

java  7.0 and 8.0

Installation

Via gradle:

compile 'br.com.gerencianet.gnsdk:gn-api-sdk-java:2.0.0'

Via maven:

<dependency>
    <groupId>br.com.gerencianet.gnsdk</groupId>
    <artifactId>gn-api-sdk-java</artifactId>
    <version>2.0.0</version>
</dependency>

Getting started

Require the module and packages:

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

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

```java
try {
  /* code */
} catch(GerencianetException e) {
  /* Gerencianet's api errors will come here */
} catch(Exception ex) {
  /* Other errors will come here */
}

For development environment

Instantiate the module passing using your client_id, client_secret and sandbox equals 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);

Gerencianet gn = new Gerencianet($options);

Or

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);

Gerencianet gn = new Gerencianet($options);

For production environment

To change the environment to production, just set the third sandbox to false:

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);

Gerencianet gn = new Gerencianet($options);

Or

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);

Gerencianet gn = new Gerencianet($options);

Running tests

To run the test suite with coverage:

mvn clean test jacoco:report

Running examples

To run some existing examples follow the steps described at gn-api-sdk-java-examples.

Additional Documentation

The full documentation with all available endpoints is in https://dev.gerencianet.com.br/.

Changelog

CHANGELOG

License

MIT

gn-api-sdk-java's People

Contributors

filipemata avatar guilhermecotagn avatar jessica-gavagn avatar thiagogresende avatar whintergoncalves avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gn-api-sdk-java's Issues

SDK should not assume response will be application/json when it does not require it in the Accept header

When I send a request that results in a response with status other than HTTP_OK (200), the API server is currently replying in a format that is not JSON (probably HTML, due to some application firewall at Gerencianet's cloud).

When the response arrives, an exception is being thrown at line 59 of at br/com/gerencianet/gnsdk/Request.java with the following stacktrace:

org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] at org.json.JSONTokener.syntaxError(JSONTokener.java:451) at org.json.JSONObject.<init>(JSONObject.java:195) **at br.com.gerencianet.gnsdk.Request.send(Request.java:59)** at br.com.gerencianet.gnsdk.APIRequest.send(APIRequest.java:59) at br.com.gerencianet.gnsdk.Endpoints.kernelCall(Endpoints.java:80) at br.com.gerencianet.gnsdk.Endpoints.call(Endpoints.java:61)

The code is assuming the response will always be in JSON format, but it does not specify that requirement in the Accept header of the request.

To fix the issue, this class must include a header "Accept: application/json" (provided that the server honors it).

Falha ao chamar api via SDK

Ao realizar a chamada abaixo:

gn.call("createCharge", hashMapOf(), body)

Estou recebendo o erro abaixo:

org.json.JSONException: JSONObject["APIs"] not found.
	at org.json.JSONObject.get(JSONObject.java:471) ~[json-20160810.jar:na]
	at br.com.gerencianet.gnsdk.Config.getEndpoints(Config.java:26) ~[gn-api-sdk-java-2.0.0.jar:na]
	at br.com.gerencianet.gnsdk.Endpoints.kernelCall(Endpoints.java:112) ~[gn-api-sdk-java-2.0.0.jar:na]
	at br.com.gerencianet.gnsdk.Endpoints.call(Endpoints.java:84) ~[gn-api-sdk-java-2.0.0.jar:na]

Analisando o código do SDK, e no construtor da classe Endpoints apresentado abaixo:

public Endpoints(JSONObject options) throws Exception {
        JSONObject config = this.readJSONFile();
        this.config = new Config(options, config);
    }

Ele recebe as configurações passadas na entrada através do atributo options, como credenciais e outras informações adicionais, porém esse outro objeto config é feito a leitura de arquivo config.json que no repositório de exemplo não explica se devemos criar esse arquivo ou como devemos preenche-lo, mas nesse arquivo deveria ter um campo achamado APIs que dispara o erro.

 public JSONObject getEndpoints() {
        return (JSONObject)this.endpoints.get("APIs");
    }

Isso é um bug, ou deveriamos criar esse arquivo config.json?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.