Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages