Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Client Metadata Id Accessor to DropInClient #380

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions Drop-In/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.braintreepayments.api;

import androidx.annotation.Nullable;

public interface GetClientMetadataIdCallback {

void onResult(@Nullable String clientMetadataId, @Nullable Exception error);
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down