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.
There are two main classes,
Let's construct a
As you can see in the example above, the
Installation
- First download the stripe-android libraries.
- Be sure you've installed the Android SDK with API Level 17 and android-support-v4
- Import the
stripefolder into Eclipse. - In your project settings, add the
stripeproject 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.*;
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();
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
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.