Skip to content

Commit

Permalink
Merge branch 'shopper-insights-rp1-feature' into shopper-insights-rp2…
Browse files Browse the repository at this point in the history
…-feature

# Conflicts:
#	CHANGELOG.md
#	PayPal/src/test/java/com/braintreepayments/api/paypal/PayPalClientUnitTest.java
  • Loading branch information
warmkesselj committed Jan 15, 2025
2 parents 9e9a402 + 656f5c7 commit 02b6676
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import androidx.annotation.RestrictTo
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
data class AnalyticsEventParams @JvmOverloads constructor(
var payPalContextId: String? = null,
var linkType: String? = null,
var isVaultRequest: Boolean = false,
var startTime: Long? = null,
var endTime: Long? = null,
var endpoint: String? = null,
val payPalContextId: String? = null,
val linkType: String? = null,
val isVaultRequest: Boolean = false,
val startTime: Long? = null,
val endTime: Long? = null,
val endpoint: String? = null,
val experiment: String? = null,
val appSwitchUrl: String? = null,
val shopperSessionId: String? = null,
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
* Add `shopperSessionId` parameter to `ShopperInsightsClient`
* BraintreePayPal
* Add `shopperSessionId` to `PayPalCheckoutRequest` and `PayPalVaultRequest`
* Fix bug to ensure that `PayPalVaultRequest.userAuthenticationEmail` is not sent as an empty string
* Replace `sendPayPalPresentedEvent()` and `sendVenmoPresentedEvent()` with `sendPresentedEvent()`
* Replace `sendPayPalSelectedEvent()` and `sendVenmoSelectedEvent()` with `sendSelectedEvent()`
* ThreeDSecure
* Return error if no `dfReferenceId` is returned in the 3D Secure flow

## 5.3.0 (2024-12-11)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static PayPalVaultRequest createPayPalVaultRequest(
postalAddress.setStreetAddress("123 Fake Street");
postalAddress.setExtendedAddress("Floor A");
postalAddress.setLocality("San Francisco");
postalAddress.setPostalCode("12345");
postalAddress.setRegion("CA");
postalAddress.setCountryCodeAlpha2("US");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ class ShopperInsightsFragment : BaseFragment() {

venmoClient = VenmoClient(requireContext(), super.getAuthStringArg(), null)
payPalClient = PayPalClient(
requireContext(), super.getAuthStringArg(),
Uri.parse("https://mobile-sdk-demo-site-838cead5d3ab.herokuapp.com/")
requireContext(),
super.getAuthStringArg(),
Uri.parse("https://mobile-sdk-demo-site-838cead5d3ab.herokuapp.com/braintree-payments"),
)

return inflater.inflate(R.layout.fragment_shopping_insights, container, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ class LocalPaymentClient internal constructor(
}

private fun sendAnalyticsEvent(eventName: String) {
val eventParameters = AnalyticsEventParams()
eventParameters.payPalContextId = payPalContextId
val eventParameters = AnalyticsEventParams(
payPalContextId = payPalContextId
)
braintreeClient.sendAnalyticsEvent(eventName, eventParameters)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,9 @@ public void createPaymentAuthRequest_success_withPaymentId_sendsAnalyticsEvents(
sut.createPaymentAuthRequest(getIdealLocalPaymentRequest(), localPaymentAuthCallback);

verify(braintreeClient).sendAnalyticsEvent(LocalPaymentAnalytics.PAYMENT_STARTED, new AnalyticsEventParams());
AnalyticsEventParams params = new AnalyticsEventParams();
params.setPayPalContextId("some-paypal-context-id");
AnalyticsEventParams params = new AnalyticsEventParams(
"some-paypal-context-id"
);
verify(braintreeClient).sendAnalyticsEvent(LocalPaymentAnalytics.BROWSER_SWITCH_SUCCEEDED, params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class PayPalVaultRequest

@OptIn(ExperimentalBetaApi::class)
@Throws(JSONException::class)
@Suppress("LongMethod")
@Suppress("LongMethod", "CyclomaticComplexMethod")
override fun createRequestBody(
configuration: Configuration?,
authorization: Authorization?,
Expand All @@ -92,7 +92,9 @@ class PayPalVaultRequest
parameters.put(DESCRIPTION_KEY, billingAgreementDescription)
}

parameters.putOpt(PAYER_EMAIL_KEY, userAuthenticationEmail)
if (!userAuthenticationEmail.isNullOrEmpty()) {
parameters.put(PAYER_EMAIL_KEY, userAuthenticationEmail)
}

parameters.putOpt(SHOPPER_SESSION_ID, shopperSessionId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,11 @@ public void createPaymentAuthRequest_whenPayPalNotEnabled_returnsError() {
"for more information.",
((PayPalPaymentAuthRequest.Failure) request).getError().getMessage());

AnalyticsEventParams params = new AnalyticsEventParams();
params.setVaultRequest(false);
AnalyticsEventParams params = new AnalyticsEventParams(
null,
null,
false
);
verify(braintreeClient).sendAnalyticsEvent(PayPalAnalytics.TOKENIZATION_FAILED, params);
}

Expand All @@ -311,8 +314,11 @@ public void createPaymentAuthRequest_whenCheckoutRequest_whenConfigError_forward
assertTrue(request instanceof PayPalPaymentAuthRequest.Failure);
assertEquals(authError, ((PayPalPaymentAuthRequest.Failure) request).getError());

AnalyticsEventParams params = new AnalyticsEventParams();
params.setVaultRequest(false);
AnalyticsEventParams params = new AnalyticsEventParams(
null,
null,
false
);
verify(braintreeClient).sendAnalyticsEvent(PayPalAnalytics.TOKENIZATION_FAILED, params);
}

Expand All @@ -336,8 +342,11 @@ public void requestBillingAgreement_whenConfigError_forwardsErrorToListener() {
assertTrue(request instanceof PayPalPaymentAuthRequest.Failure);
assertEquals(authError, ((PayPalPaymentAuthRequest.Failure) request).getError());

AnalyticsEventParams params = new AnalyticsEventParams();
params.setVaultRequest(true);
AnalyticsEventParams params = new AnalyticsEventParams(
null,
null,
true
);
verify(braintreeClient).sendAnalyticsEvent(PayPalAnalytics.TOKENIZATION_FAILED, params);
}

Expand Down Expand Up @@ -416,9 +425,11 @@ public void createPaymentAuthRequest_whenVaultRequest_sendsAppSwitchStartedEvent
assertFalse(browserSwitchOptions.isLaunchAsNewTask());


AnalyticsEventParams params = new AnalyticsEventParams();
params.setVaultRequest(true);
params.setLinkType("universal");
AnalyticsEventParams params = new AnalyticsEventParams(
null,
"universal",
true
);
verify(braintreeClient).sendAnalyticsEvent(PayPalAnalytics.APP_SWITCH_STARTED, params);
}

Expand Down Expand Up @@ -543,8 +554,11 @@ public void tokenize_whenCancelUriReceived_notifiesCancellationAndSendsAnalytics
PayPalResult result = captor.getValue();
assertTrue(result instanceof PayPalResult.Cancel);

AnalyticsEventParams params = new AnalyticsEventParams();
params.setVaultRequest(false);
AnalyticsEventParams params = new AnalyticsEventParams(
null,
null,
false
);
verify(braintreeClient).sendAnalyticsEvent(PayPalAnalytics.BROWSER_LOGIN_CANCELED, params);
}

Expand Down Expand Up @@ -584,9 +598,11 @@ public void tokenize_whenPayPalInternalClientTokenizeResult_callsBackResult()
assertTrue(result instanceof PayPalResult.Success);
assertEquals(payPalAccountNonce, ((PayPalResult.Success) result).getNonce());

AnalyticsEventParams params = new AnalyticsEventParams();
params.setPayPalContextId("EC-HERMES-SANDBOX-EC-TOKEN");
params.setVaultRequest(false);
AnalyticsEventParams params = new AnalyticsEventParams(
"EC-HERMES-SANDBOX-EC-TOKEN",
null,
false
);
verify(braintreeClient).sendAnalyticsEvent(PayPalAnalytics.TOKENIZATION_SUCCEEDED, params);
}

Expand Down Expand Up @@ -626,8 +642,9 @@ public void tokenize_whenPayPalInternalClientTokenizeResult_sendsAppSwitchSuccee
assertTrue(result instanceof PayPalResult.Success);
assertEquals(payPalAccountNonce, ((PayPalResult.Success) result).getNonce());

AnalyticsEventParams params = new AnalyticsEventParams();
params.setPayPalContextId("EC-HERMES-SANDBOX-EC-TOKEN");
AnalyticsEventParams params = new AnalyticsEventParams(
"EC-HERMES-SANDBOX-EC-TOKEN"
);
verify(braintreeClient).sendAnalyticsEvent(PayPalAnalytics.TOKENIZATION_SUCCEEDED, params);
AnalyticsEventParams appSwitchParams = new AnalyticsEventParams(
"EC-HERMES-SANDBOX-EC-TOKEN",
Expand Down Expand Up @@ -667,8 +684,9 @@ public void tokenize_whenPayPalNotEnabled_sendsAppSwitchFailedEvents() throws JS

sut.tokenize(payPalPaymentAuthResult, payPalTokenizeCallback);

AnalyticsEventParams params = new AnalyticsEventParams();
params.setPayPalContextId("SOME-BA");
AnalyticsEventParams params = new AnalyticsEventParams(
"SOME-BA"
);
verify(braintreeClient).sendAnalyticsEvent(PayPalAnalytics.TOKENIZATION_FAILED, params);
AnalyticsEventParams appSwitchParams = new AnalyticsEventParams(
"SOME-BA",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class HttpClient internal constructor(
}

if (url != null) {
val retryCount = getNumRetriesSoFar(url)
val retryCount = getCurrentRetryCount(url)
val shouldRetry = ((retryCount + 1) < MAX_RETRY_ATTEMPTS)
if (shouldRetry) {
scheduleRequest(request, retryStrategy, callback)
Expand All @@ -85,10 +85,7 @@ class HttpClient internal constructor(
}
}

private fun getNumRetriesSoFar(url: URL): Int {
val retryCount = retryCountMap[url] ?: return 0
return retryCount
}
private fun getCurrentRetryCount(url: URL) = retryCountMap[url] ?: 0

private fun resetRetryCount(request: HttpRequest) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ public class TLSSocketFactory extends SSLSocketFactory {

private final SSLSocketFactory internalSSLSocketFactory;

static TLSSocketFactory newInstance() throws SSLException {
return new TLSSocketFactory();
}

TLSSocketFactory() throws SSLException {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null); // use system security providers
internalSSLSocketFactory = sslContext.getSocketFactory();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new SSLException(e.getMessage());
}
}

/**
* @see <a href="http://developer.android.com/training/articles/security-ssl.html#UnknownCa">Android Documentation</a>
*/
Expand Down
Loading

0 comments on commit 02b6676

Please sign in to comment.