Coder Social home page Coder Social logo

patneedham / braintree-android-drop-in Goto Github PK

View Code? Open in Web Editor NEW

This project forked from braintree/braintree-android-drop-in

0.0 3.0 0.0 28.69 MB

Braintree Drop-In SDK for Android

Home Page: https://developers.braintreepayments.com/guides/drop-in/android/v2

License: MIT License

Java 97.95% Ruby 1.77% Shell 0.28%

braintree-android-drop-in's Introduction

Braintree Android Drop-In

Build Status

Braintree Android Drop-In is a readymade UI that allows you to accept card and alternative payments in your Android app.

Screenshot of Drop-In

What's new in 3.0

  • All new UI and integration for Drop-In
  • Fetch a customer's saved payment method without showing UI
  • Added UnionPay support to Drop-In

Please create an issue with any comments or concerns.

Adding it to your project

Add the dependency in your build.gradle:

dependencies {
  compile 'com.braintreepayments.api:drop-in:3.1.0'
}

To use the latest build from the master branch use:

dependencies {
  compile 'com.braintreepayments.api:drop-in:3.1.1-SNAPSHOT'
}

Usage

Create a DropInRequest and use the Intent to start Drop-In:

DropInRequest dropInRequest = new DropInRequest()
    .clientToken(mClientToken);
startActivityForResult(dropInRequest.getIntent(context), DROP_IN_REQUEST);

Handle the response:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == DROP_IN_REQUEST) {
        if (resultCode == Activity.RESULT_OK) {
            DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
            String paymentMethodNonce = result.getPaymentMethodNonce().getNonce();
            // send paymentMethodNonce to your server
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // canceled
        } else {
            // an error occurred, checked the returned exception
            Exception exception = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
        }
    }
}

Fetch last used payment method

If your user already has an existing payment method, you may not need to show Drop-In. You can check if they have an existing payment method using DropInResult#fetchDropInResult. Note that a payment method will only be returned when using a client token created with a customer_id.

DropInResult.fetchDropInResult(activity, clientToken, new DropInResult.DropInResultListener() {
    @Override
    public void onError(Exception exception) {
        // an error occurred
    }

    @Override
    public void onResult(DropInResult result) {
        if (result.getPaymentMethodType() != null) {
            // use the icon and name to show in your UI
            int icon = result.getPaymentMethodType().getDrawable();
            int name = result.getPaymentMethodType().getLocalizedName();

            if (result.getPaymentMethodType() == PaymentMethodType.ANDROID_PAY) {
                // The last payment method the user used was Android Pay. The Android Pay
                // flow will need to be performed by the user again at the time of checkout
                // using AndroidPay#requestAndroidPay(...). No PaymentMethodNonce will be
                // present in result.getPaymentMethodNonce(), this is only an indication that
                // the user last used Android Pay. Note: if you have enabled preauthorization
                // and the user checked the "Use selected info for future purchases from this app"
                // last time Android Pay was used you may need to call
                // AndroidPay#requestAndroidPay(...) and then offer the user the option to change
                // the default payment method using AndroidPay#changePaymentMethod(...)
            } else {
                // show the payment method in your UI and charge the user at the
                // time of checkout using the nonce: paymentMethod.getNonce()
                PaymentMethodNonce paymentMethod = result.getPaymentMethodNonce();
            }
        } else {
            // there was no existing payment method
        }
    }
});

card.io

To offer card scanning via card.io, add the dependency in your build.gradle:

dependencies {
    compile 'io.card:android-sdk:5.+'
}

Drop-In will include a menu icon to scan cards when card.io is included.

Help

Feedback

Here are a few ways to get in touch:

Releases

Subscribe to our Google Group to be notified when SDK releases go out.

License

Braintree Android Drop-In is open source and available under the MIT license. See the LICENSE file for more info.

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.