Giter Site home page Giter Site logo

ehtisham-ali-emumba / 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 0.0 0.0 31.51 MB

Braintree Drop-In SDK for Android

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

License: MIT License

Shell 0.04% Ruby 0.15% Java 72.25% Kotlin 27.56%

braintree-android-drop-in's Introduction

Braintree Android Drop-In

Tests

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

📣 Announcements

  • A new major version of the SDK is now available. See the v6 migration guide for details.
  • Upgrade your integration to continue accepting Braintree payments The SSL certificates for the Android SDK are set to expire by June 31, 2025. Upgrade to v6.16.0+ to continue using the Braintree SDK.

Adding it to your project

Add the dependency in your build.gradle:

dependencies {
  implementation 'com.braintreepayments.api:drop-in:6.16.0'
}

Additionally, add the following Maven repository and (non-sensitive) credentials to your app-level gradle:

repositories {
    maven {
        url "https://cardinalcommerceprod.jfrog.io/artifactory/android"
        credentials {
            username 'braintree_team_sdk'
            password 'AKCp8jQcoDy2hxSWhDAUQKXLDPDx6NYRkqrgFLRc3qDrayg6rrCbJpsKKyMwaykVL8FWusJpp'
        }
    }
}

To preview the latest work in progress builds, add the following SNAPSHOT dependency in your build.gradle:

dependencies {
  implementation 'com.braintreepayments.api:drop-in:6.16.1-SNAPSHOT'
}

You will also need to add the Sonatype snapshots repo to your top-level build.gradle to import SNAPSHOT builds:

allprojects {
    repositories {
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }
    }
}

Versions

This SDK abides by our Client SDK Deprecation Policy. For more information on the potential statuses of an SDK, check our developer docs.

Major version number Status Released Deprecated Unsupported
6.x.x Active November 2021 TBA TBA
5.x.x Unsupported September 2020 November 2022 November 2023
4.x.x Unsupported February 2019 September 2021 September 2022

Versions 3 and below are unsupported.

Usage

Create a DropInRequest to start the Drop-in UI with specified options:

val dropInRequest = DropInRequest()

DropInClient is responsible for launching the Drop-in UI. To launch Drop-in, instantiate a DropInClient with client authorization and call DropInClient#launchDropInForResult with the DropInRequest you configured above and a request code that you have defined for Drop-in:

val dropInClient = DropInClient(this, "<#CLIENT_AUTHORIZATION#>")
dropInClient.setListener(this)
dropInClient.launchDropIn(dropInRequest)

To handle the result of the Drop-in flow, implement DropInListener methods onDropInSuccess() and onDropInFailure():

override fun onDropInSuccess(result: DropInResult) {
  // use the result to update your UI and send the payment method nonce to your server
  val paymentMethodNonce = result.paymentMethodNonce?.string
}

override fun onDropInFailure(error: Exception) {
  // an error occurred, checked the returned exception
}

Localization

Drop-In is currently localized for 25 languages. To view localized text for a specific locale, open its corresponding values-<LOCALE_NAME>/strings.xml resource file.

3D Secure + Drop-in

Drop-In supports 3D-Secure verification. Assuming you have 3D-Secure configured for your account, create a ThreeDSecureRequest() object, setting ThreeDSecurePostalAddress and ThreeDSecureAdditionalInformation fields where possible; the more fields that are set, the less likely a user will be presented with a challenge. For more information, check our 3D Secure Migration Guide. Make sure to attach this object to the BTDropInRequest before use.

val address = ThreeDSecurePostalAddress()
address.givenName = "Jill" // ASCII-printable characters required, else will throw a validation error
address.surname = "Doe" // ASCII-printable characters required, else will throw a validation error
address.phoneNumber = "5551234567"
address.streetAddress = "555 Smith St"
address.extendedAddress = "#2"
address.locality = "Chicago"
address.region = "IL"
address.postalCode = "12345"
address.countryCodeAlpha2 = "US"

// Optional additional information.
// For best results, provide as many additional elements as possible.
val additionalInformation = ThreeDSecureAdditionalInformation()
additionalInformation.shippingAddress = address

val threeDSecureRequest = ThreeDSecureRequest()
threeDSecureRequest.amount = "1.00"
threeDSecureRequest.email = "[email protected]"
threeDSecureRequest.billingAddress = address
threeDSecureRequest.versionRequested = VERSION_2
threeDSecureRequest.additionalInformation = additionalInformation

val dropInRequest = DropInRequest()
dropInRequest.threeDSecureRequest = threeDSecureRequest

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 DropInClient#fetchMostRecentPaymentMethod. A payment method will only be returned when using a client token created with a customer_id.

val dropInClient = DropInClient(this, "<#CLIENT_TOKEN_WITH_CUSTOMER_ID>", dropInRequest)
dropInClient.fetchMostRecentPaymentMethod(this) { dropInResult, error ->
    error?.let {
        // an error occurred
    }
    dropInResult?.let { result ->
        result.paymentMethodType?.let { paymentMethodType ->
            // use the icon and name to show in your UI
            val icon = paymentMethodType.drawable
            val name = paymentMethodType.localizedName

            if (paymentMethodType == DropInPaymentMethod.GOOGLE_PAY) {
                // The last payment method the user used was Google Pay.
                // The Google Pay flow will need to be performed by the
                // user again at the time of checkout.
            } else {
                // Show the payment method in your UI and charge the user
                // at the time of checkout.
                val paymentMethod = result.paymentMethodNonce
            }
        }
    } ?: run {
        // there was no existing payment method
    }
}

Help

Feedback

Here are a few ways to get in touch:

License

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

braintree-android-drop-in's People

Contributors

lkorth avatar braintreeps avatar quinnjn avatar sshropshire avatar sarahkoop avatar billwerges avatar scannillo avatar sestevens avatar hollabaq86 avatar epreuve avatar kgangineni avatar jaxdesmarais avatar demerino avatar tdchow avatar bblackbelt avatar cooperbarth avatar mattwylder avatar jackellenberger avatar jplukarski avatar khushboo18 avatar stechiu avatar vigneshravi7117 avatar

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.