Subito-it / braintree-android-drop-in

Braintree Drop-In SDK for Android

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

📣  A new major version of the SDK is now available. See the v6 migration guide for details.

Screenshot of Drop-In

Adding it to your project

Add the dependency in your build.gradle:

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

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'
        }
    }
}

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 Inactive September 2020 November 2022 November 2023
4.x.x Deprecated 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#>", dropInRequest)
dropInClient.launchDropInForResult(this, DROP_IN_REQUEST_CODE)

To handle the result of the Drop-in flow, override onActivityResult:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)

    if (requestCode == DROP_IN_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            val result: DropInResult? = data?.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT)
            val paymentMethodNonce = result?.paymentMethodNonce?.string
            // use the result to update your UI and send the payment method nonce to your server
        } else if (resultCode == RESULT_CANCELED) {
            // the user canceled
        } else {
            // an error occurred, checked the returned exception
            val error: Exception? = data?.getSerializableExtra(DropInResult.EXTRA_ERROR) as? 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 = "test@email.com"
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.

About

Braintree Drop-In SDK for Android

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

License:MIT License


Languages

Language:Java 72.3%Language:Kotlin 26.2%Language:Ruby 1.3%Language:Shell 0.2%