diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dd5eb63d..4d3f0e863 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Braintree Android Drop-In Release Notes +## unreleased + +* Add `DropInClient#getClientMetadataId()` method + ## 6.5.1 * Fix issue that caused Add Card button to attempt tokenization multiple times when double tapped. diff --git a/Drop-In/build.gradle b/Drop-In/build.gradle index 7490b957a..9e5ef87c6 100644 --- a/Drop-In/build.gradle +++ b/Drop-In/build.gradle @@ -84,6 +84,8 @@ dependencies { api 'com.braintreepayments:card-form:5.4.0' + implementation deps.payPalDataCollector + implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.google.android.gms:play-services-wallet:16.0.0' implementation 'androidx.recyclerview:recyclerview:1.2.1' diff --git a/Drop-In/src/main/java/com/braintreepayments/api/DropInClient.java b/Drop-In/src/main/java/com/braintreepayments/api/DropInClient.java index 7a0a4c1d2..cbe735297 100644 --- a/Drop-In/src/main/java/com/braintreepayments/api/DropInClient.java +++ b/Drop-In/src/main/java/com/braintreepayments/api/DropInClient.java @@ -29,9 +29,10 @@ public class DropInClient { private final GooglePayClient googlePayClient; private final DropInRequest dropInRequest; - private final DropInSharedPreferences dropInSharedPreferences; + private final PayPalDataCollector payPalDataCollector; + private DropInListener listener; @VisibleForTesting @@ -51,6 +52,7 @@ private static DropInClientParams createDefaultParams(Context context, String au .lifecycle(lifecycle) .dropInRequest(dropInRequest) .braintreeClient(braintreeClient) + .payPalDataCollector(new PayPalDataCollector(braintreeClient)) .paymentMethodClient(new PaymentMethodClient(braintreeClient)) .googlePayClient(new GooglePayClient(braintreeClient)) .dropInSharedPreferences(DropInSharedPreferences.getInstance(context.getApplicationContext())); @@ -172,6 +174,7 @@ public DropInClient(Fragment fragment, ClientTokenProvider clientTokenProvider) this.googlePayClient = params.getGooglePayClient(); this.paymentMethodClient = params.getPaymentMethodClient(); this.dropInSharedPreferences = params.getDropInSharedPreferences(); + this.payPalDataCollector = params.getPayPalDataCollector(); FragmentActivity activity = params.getActivity(); Lifecycle lifecycle = params.getLifecycle(); @@ -369,4 +372,27 @@ void onDropInResult(DropInResult dropInResult) { public void invalidateClientToken() { braintreeClient.invalidateClientToken(); } + + /** + * Gets a Client Metadata ID at the time of payment activity. Once a user initiates a PayPal payment + * from their device, PayPal uses the Client Metadata ID to verify that the payment is + * originating from a valid, user-consented device and application. This helps reduce fraud and + * decrease declines. This method MUST be called prior to initiating a pre-consented payment (a + * "future payment") from a mobile device. Pass the result to your server, to include in the + * payment request sent to PayPal. Do not otherwise cache or store this value. + * + * @param callback + */ + public void getClientMetadataId(GetClientMetadataIdCallback callback) { + braintreeClient.getConfiguration((configuration, error) -> { + if (configuration != null) { + Context appContext = braintreeClient.getApplicationContext(); + String clientMetadataId = + payPalDataCollector.getClientMetadataId(appContext, configuration); + callback.onResult(clientMetadataId, null); + } else { + callback.onResult(null, error); + } + }); + } } diff --git a/Drop-In/src/main/java/com/braintreepayments/api/DropInClientParams.java b/Drop-In/src/main/java/com/braintreepayments/api/DropInClientParams.java index d76cd0ae7..0f1778356 100644 --- a/Drop-In/src/main/java/com/braintreepayments/api/DropInClientParams.java +++ b/Drop-In/src/main/java/com/braintreepayments/api/DropInClientParams.java @@ -10,6 +10,7 @@ class DropInClientParams { private BraintreeClient braintreeClient; private GooglePayClient googlePayClient; private PaymentMethodClient paymentMethodClient; + private PayPalDataCollector payPalDataCollector; private DropInSharedPreferences dropInSharedPreferences; private FragmentActivity activity; private Lifecycle lifecycle; @@ -32,6 +33,15 @@ DropInClientParams braintreeClient(BraintreeClient braintreeClient) { return this; } + PayPalDataCollector getPayPalDataCollector() { + return payPalDataCollector; + } + + DropInClientParams payPalDataCollector(PayPalDataCollector payPalDataCollector) { + this.payPalDataCollector = payPalDataCollector; + return this; + } + GooglePayClient getGooglePayClient() { return googlePayClient; } diff --git a/Drop-In/src/main/java/com/braintreepayments/api/GetClientMetadataIdCallback.java b/Drop-In/src/main/java/com/braintreepayments/api/GetClientMetadataIdCallback.java new file mode 100644 index 000000000..5016803ee --- /dev/null +++ b/Drop-In/src/main/java/com/braintreepayments/api/GetClientMetadataIdCallback.java @@ -0,0 +1,8 @@ +package com.braintreepayments.api; + +import androidx.annotation.Nullable; + +public interface GetClientMetadataIdCallback { + + void onResult(@Nullable String clientMetadataId, @Nullable Exception error); +} diff --git a/build.gradle b/build.gradle index aeeef9a4b..0fd4e34f4 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ buildscript { "googlePay" : "com.braintreepayments.api:google-pay:$brainTreeVersion", "card" : "com.braintreepayments.api:card:$brainTreeVersion", "dataCollector" : "com.braintreepayments.api:data-collector:$brainTreeVersion", + "payPalDataCollector" : "com.braintreepayments.api:paypal-data-collector:$brainTreeVersion", "unionPay" : "com.braintreepayments.api:union-pay:$brainTreeVersion", "cardForm" : "com.braintreepayments:card-form:$brainTreeVersion" ]