webpay-token-android is an Android library for creating a WebPay token from a credit card.
Android 2.2 (API level 8) and above
Retrieving from mavenCentral()
repository.
In your Android project's build.gradle
file:
dependencies {
compile 'jp.webpay.android:webpay-token:1.0.0@aar'
}
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.
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.
-
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 }
-
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" />
-
Call
replace()
to replace id of the FrameLayout in 2. with WebPayTokenFragmentWebPayTokenFragment tokenFragment = WebPayTokenFragment.newInstance(WEBPAY_PUBLISHABLE_KEY); getFragmentManager().beginTransaction() .replace(R.id.webpay_token_button_fragment, tokenFragment) .commit();
See also: sample/TokenCreateActivity
You can call the form creating Token directly.
- 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 }
- 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
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
Copyright (c) 2015- WebPay, Inc.
Released under the MIT license.