Skip to content

Make userAuthenticationEmail optional for app-switch related flows #1279

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Braintree Android SDK Release Notes

## unreleased

* PayPal
* Make `PayPalCheckoutRequest.userAuthenticationEmail` optional for App Switch flows

## 5.8.0 (2025-03-06)

* All Modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class PayPalCheckoutRequest @JvmOverloads constructor(
}
}

if (enablePayPalAppSwitch && !appLink.isNullOrEmpty() && !userAuthenticationEmail.isNullOrEmpty()) {
if (enablePayPalAppSwitch && !appLink.isNullOrEmpty()) {
parameters.put(ENABLE_APP_SWITCH_KEY, enablePayPalAppSwitch)
parameters.put(OS_VERSION_KEY, Build.VERSION.SDK_INT.toString())
parameters.put(OS_TYPE_KEY, "Android")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class PayPalVaultRequest

userPhoneNumber?.let { parameters.put(PHONE_NUMBER_KEY, it.toJson()) }

if (enablePayPalAppSwitch && !appLink.isNullOrEmpty() && !userAuthenticationEmail.isNullOrEmpty()) {
if (enablePayPalAppSwitch && !appLink.isNullOrEmpty()) {
parameters.put(ENABLE_APP_SWITCH_KEY, enablePayPalAppSwitch)
parameters.put(OS_VERSION_KEY, Build.VERSION.SDK_INT.toString())
parameters.put(OS_TYPE_KEY, "Android")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,30 @@ public void createRequestBody_sets_shippingCallbackUri_when_not_null() throws JS
assertEquals(urlString, jsonObject.getString("shipping_callback_url"));
}

@Test
public void createRequestBody_sets_appSwitchParameters_irrespectiveOf_userAuthenticationEmail_emptyOrNot(
@TestParameter({"", "[email protected]"}) String payerEmail
) throws JSONException {
PayPalCheckoutRequest request = new PayPalCheckoutRequest("1.00", true);
request.setEnablePayPalAppSwitch(true);
request.setUserAuthenticationEmail(payerEmail);
String appLink = "universal_url";

String requestBody = request.createRequestBody(
mock(Configuration.class),
mock(Authorization.class),
"success_url",
"cancel_url",
appLink
);

JSONObject jsonObject = new JSONObject(requestBody);
assertTrue(jsonObject.getBoolean("launch_paypal_app"));
assertEquals("Android", jsonObject.getString("os_type"));
assertEquals(appLink, jsonObject.getString("merchant_app_return_url"));
assertNotNull(jsonObject.getString("os_version"));
}

@Test
public void createRequestBody_sets_shopper_insights_session_id() throws JSONException {
PayPalCheckoutRequest request = new PayPalCheckoutRequest("1.00", true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
package com.braintreepayments.api.paypal;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;

import android.os.Build;
import android.os.Parcel;

import com.braintreepayments.api.core.Authorization;
import com.braintreepayments.api.core.Configuration;
import com.braintreepayments.api.core.PostalAddress;
import com.braintreepayments.api.testutils.Fixtures;
import com.google.testing.junit.testparameterinjector.TestParameter;

import org.json.JSONException;
import org.junit.Assert;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RobolectricTestParameterInjector;
import org.skyscreamer.jsonassert.JSONAssert;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@RunWith(RobolectricTestRunner.class)
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;

@RunWith(RobolectricTestParameterInjector.class)
public class PayPalVaultRequestUnitTest {

@Test
Expand Down Expand Up @@ -303,6 +305,30 @@ public void createRequestBody_correctlyFormatsJSON() throws JSONException {
JSONAssert.assertEquals(Fixtures.PAYPAL_REQUEST_JSON, requestBody, false);
}

@Test
public void createRequestBody_sets_appSwitchParameters_irrespectiveOf_userAuthenticationEmail_emptyOrNot(
@TestParameter({"", "[email protected]"}) String payerEmail
) throws JSONException {
PayPalVaultRequest request = new PayPalVaultRequest( true);
request.setEnablePayPalAppSwitch(true);
request.setUserAuthenticationEmail(payerEmail);
String appLink = "universal_url";

String requestBody = request.createRequestBody(
mock(Configuration.class),
mock(Authorization.class),
"success_url",
"cancel_url",
appLink
);

JSONObject jsonObject = new JSONObject(requestBody);
assertTrue(jsonObject.getBoolean("launch_paypal_app"));
assertEquals("Android", jsonObject.getString("os_type"));
assertEquals(appLink, jsonObject.getString("merchant_app_return_url"));
assertNotNull(jsonObject.getString("os_version"));
}

@Test
public void createRequestBody_sets_userPhoneNumber_when_not_null() throws JSONException {
PayPalVaultRequest request = new PayPalVaultRequest(true);
Expand Down