Giter Site home page Giter Site logo

webpay-token-android's Introduction

webpay-token-android Build Status

webpay-token-android is an Android library for creating a WebPay token from a credit card.

Requirements

Android 2.2 (API level 8) and above

Installation

Retrieving from mavenCentral() repository.

In your Android project's build.gradle file:

dependencies {
  compile 'jp.webpay.android:webpay-token:1.0.0@aar'
}

Sample application

You can try a sample application downloading from Google Play: https://play.google.com/store/apps/details?id=jp.webpay.android.token.sample

It includes a sample for integration with card.io.

How to use

webpay-token provides:

  • Button whose appearance changes depending on the result of token creation
  • User interface filling in user's credit card details
  • Client for creating token

You can use one from the above that fits your need.

Button and payment form

  1. Implement WebPayTokenCompleteListener in your Activity

    + public class MyFragmentActivity implements WebPayTokenCompleteListener {
    - public class MyFragmentActivity {
    @Override
    public void onTokenCreated(Token token) {
        // called when Token created
    }
    
    @Override
    public void onCancelled(Throwable lastException) {
        // called when error raised
    }
  2. Add FrameLayout to position button that opens dialog

    <FrameLayout
        android:id="@+id/webpay_token_button_fragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
  3. Call replace() to replace id of the FrameLayout in 2. with WebPayTokenFragment

    WebPayTokenFragment tokenFragment = WebPayTokenFragment.newInstance(WEBPAY_PUBLISHABLE_KEY);
    getFragmentManager().beginTransaction()
        .replace(R.id.webpay_token_button_fragment, tokenFragment)
        .commit();

See also: sample/TokenCreateActivity

Payment form

You can call the form creating Token directly.

  1. Implement WebPayTokenCompleteListener in your Activity
    + public class MyFragmentActivity implements WebPayTokenCompleteListener {
    - public class MyFragmentActivity {
    @Override
    public void onTokenCreated(Token token) {
        // called when Token created
    }
    
    @Override
    public void onCancelled(Throwable lastException) {
        // called when error raised
    }
  2. Call CardDialogFragment directly
    // You can specify supporting card types manually
    List<CardType> supportedCardTypes = CardType.VM();
    
    CardDialogFragment fragment = CardDialogFragment.newInstance(WEBPAY_PUBLISHABLE_KEY,     supportedCardTypes);
    fragment.setSendButtonTitle(R.string.your_button_title);
    fragment.show(getFragmentManager(), CARD_DIALOG_FRAGMENT_TAG);

See also: sample/CardDialogActivity

Client library

You can also create Token using WebPay class directly. But you need to implement the user interface by yourself.

RawCard rawCard = new RawCard()
    .number(cardNumber)
    .expMonth(cardExpMonth)
    .expYear(cardExpYear)
    .cvc(cardCvc)
    .name(cardName);


new WebPay(WEBPAY_PUBLISHABLE_KEY).createToken(rawCard, new WebPayListener<Token>() {
    @Override
    public void onCreate(Token result) {
        // called when Token created
    }

    @Override
    public void onException(Throwable cause) {
        // called when error raised
    }
});

See also: sample/HandleWebPayActivity

License

Copyright (c) 2015- WebPay, Inc.

Released under the MIT license.

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.