Omise Android SDK
Java
Permalink
Failed to load latest commit information.
.idea Built in 3DS verification support (#14) Oct 4, 2016
app
gradle/wrapper
sdk
.gitignore
LICENSE.md
README.md Built in 3DS verification support (#14) Oct 4, 2016
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle Initial commit. May 25, 2016

README.md

Omise Android SDK

Omise is a payment service provider currently operating in Thailand. Omise provides a set of clean APIs that helps merchants of any size accept credit cards online.

Omise Android SDK provides Android bindings for the Omise Tokenization API so you do not need to pass credit card data to your server as well as components for entering credit card information.

Hop into the Gitter chat (click the badge above) or email our support team if you have any question regarding this SDK and the functionality it provides.

Requirements

  • Public key. Register for an Omise account to obtain your API keys.
  • Android 4.0.3+ (API 15) target or higher.
  • Android Studio and Gradle build system.

Merchant Compliance

Card data should never transit through your server. We recommend that you follow our guide on how to safely collect credit information.

To be authorized to create tokens server-side you must have a currently valid PCI-DSS Attestation of Compliance (AoC) delivered by a certified QSA Auditor.

This SDK provides means to tokenize card data on end-user mobile phone without the data having to go through your server.

Installation

Adds the following line to your project's build.gradle file inside the dependencies block:

compile 'co.omise:omise-android:2.0.+'

Usage

Credit Card Activity

The simplest way to use this SDK is to integrate the provided CreditCardActivity directly into your application. This activity contains a pre-made credit form and will automatically tokenize credit card information for you.

To use it, first declare the availability of the activity in your AndroidManifest.xml file as follows:

<activity
  android:name="co.omise.android.ui.CreditCardActivity"
  android:theme="@style/OmiseSDKTheme" />

Then in your activity, declare the method that will start this activity as follows:

private static final String OMISE_PKEY = "pkey_test_123";
private static final int REQUEST_CC = 100;

private void showCreditCardForm() {
  Intent intent = new Intent(this, CreditCardActivity.class);
  intent.putExtra(CreditCardActivity.EXTRA_PKEY, OMISE_PKEY);
  startActivityForResult(intent, REQUEST_CC);
}

Replace the string pkey_test_123 with the public key obtained from your Omise dashboard.

After the end-user completes entering credit card information, the activity result callback will be called, handle it like so:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  switch (requestCode) {
    case REQUEST_CC:
      if (resultCode == CreditCardActivity.RESULT_CANCEL) {
        return;
      }

      Token token = data.getParcelableExtra(CreditCardActivity.EXTRA_TOKEN_OBJECT);
      // process your token here.

    default:
      super.onActivityResult(requestCode, resultCode, data);
  }
}

A number of results are returned as from the activity. You can obtain them from the resulting Intent with the following code:

  • data.getStringExtra(CreditCardActivity.EXTRA_TOKEN) - The string ID of the token. Use this if you only needs the ID and not the card data.
  • data.getParcelableExtra(CreditCardActivity.EXTRA_TOKEN_OBJECT) - The full Token object returned from the Omise API.
  • data.getParcelableExtra(CreditCardActivity.EXTRA_CARD_OBJECT) - The Card object which is part of the Token object returned from the Omise API.

Custom Credit Card Form

If you need to build your own credit card form, components inside CreditCardActivity can be used on its own. For example, the CreditCardEditText can be used in XML like so:

<co.omise.android.ui.CreditCardEditText
  android:layout_width="match_parent"
  android:layout_height="wrap_content" />

This component provides automatic spacing into groups of 4 digits as the user types. Additionally the following utility classes are available from the SDK:

  • co.omise.android.ui.ExpiryMonthSpinnerAdapter - This is a SpinnerAdapter that provide list of months (01-12) for use in a Spinner control for selecting expiry dates.
  • co.omise.android.ui.ExpiryYearSpinnerAdapter - Same as above but lists the current year up to twelve years into the future.
  • co.omise.android.CardNumber - The CardNumber class provides utility methods for validating and formatting credit card numbers.

Manual Tokenization

If you have built your own credit card form you can use the SDK to manually tokenizes the card. First build the Client and supply your public key like so:

Client client = new Client("pkey_test_123");

Then construct the token request with values from your custom form:

TokenRequest request = new TokenRequest();
request.number = "4242424242424242";
request.name = "JOHN SMITH";
request.expirationMonth = 10;
request.expirationYear = 2020;
request.securityCode = "123";

And then send the request using the client we've constructed earlier:

client.send(request, new TokenRequestListener() {
  @Override
  public void onTokenRequestSucceed(TokenRequest request, Token token) {
      // you've got Token!
  }

  @Override
  public void onTokenRequestFailed(TokenRequest request, Throwable throwable) {
      // something bad happened
  }
});

The Client class will automatically dispatch the network call on an internal background thread and will call listener methods on the thread that initially calls the send method.

Card.io support

This library supports integration with Card.IO Android SDK which enables credit card scanning with phone camera. To enable this integration, simply include the library with your project and the SDK will pick it up automatically. A camera button will be added when CreditCardActivity is shown.

Check Card.io SDK setup as the canonical source of information. For convenience, the steps are summarized here:

  1. Adds compile 'io.card:android-sdk:5.4.0' to your build.gradle dependencies list.
  2. Adds the following uses-permission and uses-feature to your AndroidManifest.xml file:

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    
    <uses-feature android:name="android.hardware.camera" android:required="false" />
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
    <uses-feature android:name="android.hardware.camera.flash" android:required="false" />
  3. In the same file, adds Card.io Activity declarations: xml <activity android:name="io.card.payment.CardIOActivity" />

That's it! The SDK should now picks up card.io and shows a camera button automatically.

3DS Verification support

Some merchant require their customers to verify themselves with 3-D Secure verification process. Omise iOS SDK provide a built in class to do the verification.

Verify 3DS Activity

To use it, first declare the availability of the activity in your AndroidManifest.xml file as follows:

<activity
  android:name="co.omise.android.ui.Verify3DSActivity"
  android:theme="@style/OmiseSDKTheme" />

Then in your activity, declare the method that will start this activity as follows:

private void showVerify3DSForm() {
    Intent intent = new Intent(this, Verify3DSActivity.class);
    intent.putExtra(Verify3DSActivity.EXTRA_AUTHORIZED_URL, AUTHORIZED_URL);
    startActivityForResult(intent, REQUEST_CODE);
}

Replace the string AUTHORIZED_URL with the authorized URL that comes with the created charge.

After the end-user completes 3DS verification process, the activity result callback will be called, handle it like so:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 0x3d5 && resultCode == RESULT_OK) {
        String url = data.getStringExtra(Verify3DSActivity.EXTRA_REDIRECTED_URL);
    }
}

Contributing

Pull requests and bugfixes are welcome. For larger scope of work, please pop on to our chatroom to discuss first.

LICENSE

MIT (See the (full license text)[https://github.com/omise/omise-android/blob/master/LICENSE])