GN API SDK

Android SDK for integrating with Gerencianet API

License

License

Categories

Categories

Net
GroupId

GroupId

br.com.gerencianet.mobile
ArtifactId

ArtifactId

gnapi-sdk
Last Version

Last Version

0.5
Release Date

Release Date

Type

Type

jar
Description

Description

GN API SDK
Android SDK for integrating with Gerencianet API
Project URL

Project URL

https://github.com/franciscotfmc/gn-api-sdk-android
Source Code Management

Source Code Management

https://github.com/franciscotfmc/gn-api-sdk-android

Download gnapi-sdk

How to add to project

<!-- https://jarcasting.com/artifacts/br.com.gerencianet.mobile/gnapi-sdk/ -->
<dependency>
    <groupId>br.com.gerencianet.mobile</groupId>
    <artifactId>gnapi-sdk</artifactId>
    <version>0.5</version>
</dependency>
// https://jarcasting.com/artifacts/br.com.gerencianet.mobile/gnapi-sdk/
implementation 'br.com.gerencianet.mobile:gnapi-sdk:0.5'
// https://jarcasting.com/artifacts/br.com.gerencianet.mobile/gnapi-sdk/
implementation ("br.com.gerencianet.mobile:gnapi-sdk:0.5")
'br.com.gerencianet.mobile:gnapi-sdk:jar:0.5'
<dependency org="br.com.gerencianet.mobile" name="gnapi-sdk" rev="0.5">
  <artifact name="gnapi-sdk" type="jar" />
</dependency>
@Grapes(
@Grab(group='br.com.gerencianet.mobile', module='gnapi-sdk', version='0.5')
)
libraryDependencies += "br.com.gerencianet.mobile" % "gnapi-sdk" % "0.5"
[br.com.gerencianet.mobile/gnapi-sdk "0.5"]

Dependencies

compile (3)

Group / Artifact Type Version
com.google.android : android-test jar 2.2.1
com.google.code.gson : gson jar 2.3.1
com.loopj.android : android-async-http jar 1.4.6

provided (1)

Group / Artifact Type Version
com.google.android : android jar 4.1.1.4

Project Modules

There are no modules declared in this project.

gn-api-sdk-android

An Android SDK for easy integration of your mobile apps with the payment methods provided by Gerencianet.

Build Status Coverage Status [Maven Central](https://search.maven.org/#search|ga|1|g:"br.com.gerencianet.mobile" AND a:"gn-api-sdk-android")

According to Gerencianet API Docs, a payment_token represents a credit card number in their context. With a payment token acquired you can process/confirm payments. The purpose of this SDK is to provide a simple way to get these tokens so that you can send them to your backend from your Android mobile apps.

Requirements

  • Android 2.2+

Installation

Via gradle:

compile 'br.com.gerencianet.mobile:gn-api-sdk-android:0.6'

Via maven:

<dependency>
  <groupId>br.com.gerencianet.mobile</groupId>
  <artifactId>gn-api-sdk-android</artifactId>
  <version>0.6</version>
</dependency>

Usage

Instantiate a Config object, set your account code and whether or not you're using sandbox environment:

Config config = new Config();
config.setAccountCode("yourAccountCode");
config.setSandbox(true);

Create a CreditCard:

CreditCard creditCard = new CreditCard();
creditCard.setBrand("visa");
creditCard.setCvv("123");
creditCard.setNumber("40120010384433");
creditCard.setExpirationMonth("05");
creditCard.setExpirationYear("2018");

Create an Endpoints instance:

Endpoints gnEndpoints = new Endpoints(config, new IGnListener() {
    @Override
    public void onPaymentDataFetched(PaymentData paymentData) {
        Log.d(Constants.TAG, new Gson().toJson(paymentData));
    }

    @Override
    public void onPaymentTokenFetched(PaymentToken paymentToken) {
        Log.d(Constants.TAG, paymentToken.getHash());
    }

    @Override
    public void onError(Error error) {
        Log.d(Constants.TAG, new Gson().toJson(error));
    }
});

Get a PaymentToken:

gnEndpoints.getPaymentToken(creditCard);

Observe that getPaymentToken is an asynchronous call. When the response arrives, onPaymentTokenFetched will be triggered.

Log.d output:

{
  "hash": "5fcf90da4830edcacf96e96814c66f5ec1bf28de"
}

In addition to getting payment tokens, sometimes you'll need to get payment information to display it for the users. For this, first create a PaymentType:

PaymentType paymentType = new PaymentType();
paymentType.setName("visa");
paymentType.setTotal(10000);

gnClient.getPaymentData(paymentType);

This time, onPaymentDataFetched will be triggered if the call succeeds.

Log.d output:

{
  "installments": [{
    "currency": "101,50",
    "hasInterest": false,
    "parcels": 1,
    "value": 10150
  }, {
    "currency": "52,79",
    "hasInterest": true,
    "parcels": 2,
    "value": 5279
  }, {
    "currency": "35,89",
    "hasInterest": true,
    "parcels": 3,
    "value": 3589
  }, {
    "currency": "27,46",
    "hasInterest": true,
    "parcels": 4,
    "value": 2746
  }, {
    "currency": "22,40",
    "hasInterest": true,
    "parcels": 5,
    "value": 2240
  }, {
    "currency": "19,04",
    "hasInterest": true,
    "parcels": 6,
    "value": 1904
  }, {
    "currency": "16,64",
    "hasInterest": true,
    "parcels": 7,
    "value": 1664
  }, {
    "currency": "14,85",
    "hasInterest": true,
    "parcels": 8,
    "value": 1485
  }, {
    "currency": "13,47",
    "hasInterest": true,
    "parcels": 9,
    "value": 1347
  }, {
    "currency": "12,36",
    "hasInterest": true,
    "parcels": 10,
    "value": 1236
  }, {
    "currency": "11,46",
    "hasInterest": true,
    "parcels": 11,
    "value": 1146
  }, {
    "currency": "10,72",
    "hasInterest": true,
    "parcels": 12,
    "value": 1072
  }],
  "interestPercentage": 0,
  "name": "visa",
  "rate": 150
}

As you may have already suspected, onError will be called in case of any error.

Here is a sample app with a checkout page using this SDK.

If you're wondering what to do in your backend code, here are the SDK's that will help:

If you're looking for this same code but for iOS, here it goes:

Tests

To run the test suite with coverage:

./gradlew jacocoTestReport

The output files will be created in app/build/reports.

Changelog

CHANGELOG

License

MIT

Versions

Version
0.5
0.4
0.3
0.2
0.1