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

Pass hasUserLocationConsent to DataCollector #472

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ void collectDeviceData(
boolean hasUserLocationConsent,
DataCollectorCallback callback
) {
// TODO: pass in hasUserLocationConsent
dataCollector.collectDeviceData(activity, callback);
DataCollectorRequest request = new DataCollectorRequest(hasUserLocationConsent);
dataCollector.collectDeviceData(activity, request, callback);
}

void performThreeDSecureVerification(final FragmentActivity activity, PaymentMethodNonce paymentMethodNonce, final DropInResultCallback callback) {
Expand Down Expand Up @@ -148,10 +148,8 @@ void shouldRequestThreeDSecureVerification(PaymentMethodNonce paymentMethodNonce
void tokenizePayPalRequest(FragmentActivity activity, PayPalFlowStartedCallback callback) {
PayPalRequest paypalRequest = dropInRequest.getPayPalRequest();
if (paypalRequest == null) {
paypalRequest = new PayPalVaultRequest();
paypalRequest = new PayPalVaultRequest(dropInRequest.hasUserLocationConsent());
}
// TODO: set hasUserLocationConsent on paypalRequest
dropInRequest.hasUserLocationConsent();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasUserLocationConsent is set on the PayPalRequest directly. No need to set it here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the merchant has set hasUserLocationConsent on their dropInRequest already - can we pass that value in when creating the default PayPalVaultRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, great suggestion! i'll update this.

unrelated question - if this function gets called with a null PayPalRequest and a default one is created, are there scenarios where payPalClient.tokenizePayPalAccount() will ever succeed? are there required fields on the request?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this change, there were no required fields for a PayPalVaultRequest (checkout request requires amount). So if a merchant doesn't pass a custom PayPalRequest to their DropInRequest, drop-ins default behavior is the PayPal billing agreement/vault flow - it should succeed when we create the default vault request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was seeing some errors thrown when returnUrl is not set on the request. I'm not sure if this was just an issue in the PayPal Native module. I'll do some testing outside the scope of this PR/story.

I just pushed the change to pass hasUserLocationConsent from the dropInRequest.

payPalClient.tokenizePayPalAccount(activity, paypalRequest, callback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ public DropInRequest() {
hasUserLocationConsent = false;
}

/**
* @param hasUserLocationConsent informs the SDK if your application has obtained consent from
* the user to collect location data in compliance with
* <a href="https://support.google.com/googleplay/android-developer/answer/10144311#personal-sensitive">Google Play Developer Program policies</a>
* This flag enables PayPal to collect necessary information required for Fraud Detection and Risk Management.
*
* @see <a href="https://support.google.com/googleplay/android-developer/answer/10144311#personal-sensitive">User Data policies for the Google Play Developer Program </a>
* @see <a href="https://support.google.com/googleplay/android-developer/answer/9799150?hl=en#Prominent%20in-app%20disclosure">Examples of prominent in-app disclosures</a>
*/
public DropInRequest(boolean hasUserLocationConsent) {
this.hasUserLocationConsent = hasUserLocationConsent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ public DataCollector build() {
DataCollector dataCollector = mock(DataCollector.class);

doAnswer((Answer<Void>) invocation -> {
DataCollectorCallback callback = (DataCollectorCallback) invocation.getArguments()[1];
DataCollectorCallback callback = (DataCollectorCallback) invocation.getArguments()[2];
if (collectDeviceDataSuccess != null) {
callback.onResult(collectDeviceDataSuccess, null);
} else if (collectDeviceDataError != null) {
callback.onResult(null, collectDeviceDataError);
}
return null;
// TODO: add hasUserLocationConsent argument
}).when(dataCollector).collectDeviceData(any(Context.class), any(DataCollectorCallback.class));
}).when(dataCollector).collectDeviceData(
any(Context.class),
any(DataCollectorRequest.class),
any(DataCollectorCallback.class)
);

return dataCollector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ public void collectDeviceData_forwardsInvocationToDataCollector() {
DropInInternalClient sut = new DropInInternalClient(params);
sut.collectDeviceData(activity, true, callback);

// TODO: add hasUserLocationConsent to verify
verify(dataCollector).collectDeviceData(activity, callback);
DataCollectorRequest request = new DataCollectorRequest(true);
verify(dataCollector).collectDeviceData(activity, request, callback);
}

@Test
Expand Down Expand Up @@ -859,6 +859,26 @@ public void tokenizePayPalAccount_withPayPalVaultRequest_tokenizesPayPalWithVaul
verify(payPalClient).tokenizePayPalAccount(same(activity), same(payPalRequest), same(callback));
}

@Test
public void tokenizePayPalRequest_when_dropInRequest_is_null_hasUserLocationConsent_is_set_from_dropInRequest() {
BraintreeClient braintreeClient = new MockBraintreeClientBuilder().build();
DropInRequest dropInRequest = new DropInRequest(true);
PayPalClient payPalClient = mock(PayPalClient.class);
DropInInternalClientParams params = new DropInInternalClientParams()
.dropInRequest(dropInRequest)
.payPalClient(payPalClient)
.braintreeClient(braintreeClient);

PayPalFlowStartedCallback callback = mock(PayPalFlowStartedCallback.class);
DropInInternalClient sut = new DropInInternalClient(params);

sut.tokenizePayPalRequest(activity, callback);

ArgumentCaptor<PayPalRequest> captor = ArgumentCaptor.forClass(PayPalRequest.class);
verify(payPalClient).tokenizePayPalAccount(same(activity), captor.capture(), same(callback));
assertTrue(captor.getValue().hasUserLocationConsent());
}

@Test
public void tokenizeVenmoAccount_tokenizesVenmo() {
Configuration configuration = mockConfiguration(false, true, false, false, false);
Expand Down
Loading