Giter Site home page Giter Site logo

tpaga-android-sdk's Introduction

tpaga-android-sdk

Tpaga SDK allows your application connect with the Tpaga API to create new tokens which represents a credit cards. Have two options to generate credit card tokens. The first include a fragment where you can to write the credit card data or scan it. The other option is to make the request to the Tpaga API. Both return a credit card token. You can show a implementation example here Example Tpaga SDK

Support

Latest release

The most recent release is tpaga-sdk 1.0.0, released December 13, 2016

Get Started

  1. Add depencency:
  • Using Maven add the following
<dependency>
  <groupId>co.tpaga</groupId>
  <artifactId>android</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>
  • Using Gradle
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://raw.github.com/Tpaga/tpaga-android-sdk/releases"
        }
    }
}

dependencies{
  compile 'co.tpaga:android:1.0.0'
}
  • Using Ivy
<dependency org='co.tpaga' name='android' rev='1.0.0'>
  <artifact name='android' ext='pom' />
</dependency>
  1. Other option is download and import the module tpaga-sdk into your project.
  1. Add compile project(":tpaga-sdk") in your app build.gradle
dependencies {
    compile project(":tpaga-sdk")
 }
  1. Add permissions in the manifest
<uses-permission android:name="android.permission.INTERNET" />
  1. Initialize Tpaga SDK

In the Activity or Application file initialize tpagasdk. Set your public key and select environment. Use your public_api_key to initialize. This key is in your dashboard sandbox/production. The enviroment can be TpagaAPI.SANDBOX OR TpagaAPI.PRODUCTION. You must check that the added public_api_key matches the selected environment.

Tpaga.initialize("public_api_key", Tpaga.SANDBOX);

Usage

Add Credit Card (tokenize)

First option is use AddCreditCardFragment to add credit cards

  • Add AddCreditCardFragment fragment in your activity
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
AddCreditCardFragment mAddCreditCardFragment = new AddCreditCardFragment();
ft.add(R.id.content_default, mAddCreditCardFragment, fragmentTag);
ft.commitAllowingStateLoss();
  • Your activity must implement AddCreditCardView.UserActionsListener and override methods.
//This method is execute if fields in fragment are correct and tokenize credit card is successful
@Override
public void onResponseSuccessTokenizeCreditCard(String creditCardToken) {
    /**
     * you must send the creditCardToken to your server to use in payments
     */
}

//This method is called when the request presents a error
@Override
public void showError(Throwable t) {
    if (t instanceof TpagaException) { 
        //.getStatusCode() return the http error
        ((TpagaException) t).getStatusCode();
    }
}

To customize AddCreditCardFragment you can overwrite the next styles

<style name="Base.Button" parent="Theme.AppCompat.Light"></style>
<style name="Base.TextInputLayout" parent="Theme.AppCompat.Light"></style>
<style name="Base.EditText" parent="@style/Base.Widget.AppCompat.EditText"></style>
<style name="Tittle"></style>

Second option without AddCreditCardFragment

  • Implements AddCreditCardView.UserActionsListener and overwrite methods as show above.

  • Call Tpaga.tokenizeCreditCard(this, CreditCard.create("number", "year", "month", "cvv", "name")); to request card token

  • Optionaly you must use Tpaga.startScanCreditCard(this); to start scan credit card intent and in onActivityResult method add the next lines. Where Tpaga.onActivityResultScanCreditCard(data) return a CreditCard object

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case Tpaga.SCAN_CREDIT_CARD:
            if (resultCode == Tpaga.SCAN_CREDIT_CARD_OK)) {
                onResultScanCreditCard(Tpaga.onActivityResultScanCreditCard(data));
            }
            break;
    }
}

Feedback

Github issues - for generally applicable issues Tpaga Support / [email protected] - for personal support at any phase of integration

License

The Tpaga Android SDK is open source and available under the Apache License. See the LICENSE file for more info.

tpaga-android-sdk's People

Contributors

adelatpaga avatar

Stargazers

Sebastian Ortiz avatar

Watchers

 avatar James Cloos avatar Vera avatar Ernesto Nobmann avatar Miguel Angel Rodriguez Bermudez avatar

tpaga-android-sdk's Issues

Specify proguard rules for clients

SDK users must add the following proguard rule in case the code is minified

-keep class co.tpaga.android.Entities.** { *; }

Otherwise, following exception is thrown when attempting to get a credit card token

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.ArrayList.get(int)' on a null object reference at co.tpaga.android.Tools.StatusResponse.create(Unknown Source) at co.tpaga.android.Network.TpagaAPI.getAuthAdapter(Unknown Source) at co.tpaga.android.Tpaga.initialize(Unknown Source) at co.tpaga.android.FragmentCreditCard.AddCreditCardPresenter$1.onResponse(Unknown Source) at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(Unknown Source) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5765) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

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.