Friday, May 22, 2015

Stripe Payment Gateway

Stripe has created a Java library for Android allowing you to easily submit payments from the platform. We support Android back to version 4, and the library has no external dependencies.

Installation

  1. First download the stripe-android libraries.
  2. Be sure you've installed the Android SDK with API Level 17 and android-support-v4
  3. Import the stripe folder into Eclipse.
  4. In your project settings, add the stripe project under the "Libraries" section of the "Android" category.

Creating & Validating Cards

You'll need to import the Stripe classes before you can use them.



import com.stripe.android.*;
There are two main classes, Card and Stripe. The Card class contains a bunch of useful helpers for validating card input on the client-side, before we even try to create a charge.
Let's construct a Card instance with your customers's payment information, perhaps retrived from a form.



Card card = new Card(
    cardNumber,
    cardExpMonth,
    cardExpYear,
    cardCVC
);

card.validateNumber();
card.validateCVC();
As you can see in the example above, the Card instance contains some helpers to validate that the card number passes the Luhn check, that the expiry is the future, and that the CVC looks valid. You'll probably want to validate these three things at once, so we've included a validateCard function to help out:



Card card = new Card("4242-4242-4242-4242", 12, 2016, "123");

if ( !card.validateCard() ) {
    // Show errors
}

Creating tokens

With our mobile library, we shoulder the burden of PCI compliance by helping you avoid the need to send card data directly to your server. Instead, our libraries send the card data directly to our servers, where we can convert them to tokens.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.