braintree / braintree-android-drop-in

Braintree Drop-In SDK for Android
https://developers.braintreepayments.com/guides/drop-in/android/v2
MIT License
124 stars 79 forks source link

How to show 'recent' payment methods in Drop-in UI? #164

Closed volodymyr-mitso closed 4 years ago

volodymyr-mitso commented 4 years ago

I'm currently working on flutter app. One of main requests is PayPal/Braintree payments. I will make android and iOS separately. First I implemented android part.


AndroidManifest.xml

<activity android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="com.xxx.xxx.braintree" />
    </intent-filter>
</activity>

build.gradle

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'com.braintreepayments.api:drop-in:4.4.1'
//    implementation 'com.braintreepayments.api:three-d-secure:3.4.1'

    components.all {
        allVariants {
            withDependencies { deps ->
                deps.each { dep ->
                    if (dep.group == 'net.minidev' && dep.name =='json-smart') {
                        dep.version {
                            prefer "2.3"
                        }
                        dep.because "resolving dependencies issue"
                    }
                }
            }
        }
    }
}

repositories {
    mavenCentral()
    maven {
        url "https://cardinalcommerce.bintray.com/android"
        credentials {
            username 'braintree-team-sdk@cardinalcommerce'
            password '220cc9476025679c4e5c843666c27d97cfb0f951'
        }
    }
}

Activity class

private void showDropInUi(String clientToken) {
        final DropInRequest dropInRequest = new DropInRequest()
                .clientToken(clientToken)
                .vaultManager(true);
        startActivityForResult(dropInRequest.getIntent(this), REQUEST_CODE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        final Map<String, String> map = new LinkedHashMap<>();
        if (requestCode == REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                final DropInResult dropInResult = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
                String paymentNonce = null;
                if (dropInResult != null && dropInResult.getPaymentMethodNonce() != null) {
                    paymentNonce = dropInResult.getPaymentMethodNonce().getNonce();
                }
                if (paymentNonce == null || paymentNonce.isEmpty()) {
                    map.put("status", "failure");
                    map.put("message", "Payment nonce is null or empty.");
                    mResult.success(map);
                } else {
                    map.put("status", "success");
                    map.put("message", "Payment nonce is ready.");
                    map.put("payment_nonce", paymentNonce);
                    mResult.success(map);
                }
            } else if (resultCode == RESULT_CANCELED) {
                map.put("status", "failure");
                map.put("message", "User canceled payment.");
                mResult.success(map);
            } else {
                final Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
                map.put("status", "failure");
                map.put("message", error != null ? error.toString() : "Error is null.");
                mResult.success(map);
            }
        }
    }


I make request to server to get 'client token'. Then I start Drop-in UI. And finally, when I get nonce, I make another request to make transaction. Braintree sdk is working and I already made dozens of payments using test credit cards and test PayPal account.

So, the question is: how to show recent payment methods in Drop-in UI? This must be handled by back end by managing customers and customerId? Or I need some extra java code for this? Because I can't find anything in documentation for this.


I want this: Аннотация 2019-11-12 135943

And only I can get is this: Аннотация 2019-11-12 140057

sestevens commented 4 years ago

Hi @VladimirMitso. You will need to pass a customer ID when creating your client token in order to show vaulted (saved) payment methods in Drop-In. Please take a look at this documentation.