-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[App Switch] Construct Uri to launch PayPal App (#1092)
* Pass app linkk return uri as paremeter * Update json parameters with uri * Update UTs * Catch Uri null * Address PR comment * Rename parameter * Update validation to append new parameters * Map payPalApprovalURL key from response * Add and fix UTs * Add method to verified if paypal is installed * Check linkType to parse response model * Add UTs and textures * Add method to append query items and create app switch uri * Fix tests and modify baToken validation * Add linkType enum * Update LinkType on venmo client * Update PayPal/src/main/java/com/braintreepayments/api/paypal/PayPalInternalClient.java Change BraintreeException instead of Exception on internal client Co-authored-by: sshropshire <[email protected]> * Add missing import * Change isPayPalInstalled method to property * Linting * Revert changes on isPayPalInstalled * Lint LinkTye * Revert linkTyope validation to instantiate PaymentResource * Use linkType enum instead of String * Fix UTs * Add RestrictTo on LinkType enum --------- Co-authored-by: sshropshire <[email protected]>
- Loading branch information
1 parent
7e31bb2
commit ee52cee
Showing
9 changed files
with
163 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
BraintreeCore/src/main/java/com/braintreepayments/api/core/LinkType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.braintreepayments.api.core | ||
|
||
import androidx.annotation.RestrictTo | ||
|
||
/** | ||
* Used to describe the link type for analytics | ||
* Note: This enum is exposed for internal Braintree use only. Do not use. | ||
* It is not covered by Semantic Versioning and may change or be removed at any time. | ||
*/ | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
public enum class LinkType(val stringValue: String) { | ||
UNIVERSAL("universal"), | ||
DEEPLINK("deeplink") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import static junit.framework.TestCase.assertNull; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
|
@@ -551,6 +552,66 @@ public void sendRequest_withPayPalVaultRequest_callsBackPayPalResponseOnSuccess( | |
assertEquals(expectedUrl, payPalPaymentAuthRequestParams.getApprovalUrl()); | ||
} | ||
|
||
@Test | ||
public void sendRequest_withPayPalVaultRequest_callsBackPayPalResponseOnSuccess_returnsPayPalURL() { | ||
BraintreeClient braintreeClient = new MockBraintreeClientBuilder() | ||
.configuration(configuration) | ||
.authorizationSuccess(clientToken) | ||
.appLinkReturnUri(Uri.parse("https://example.com")) | ||
.sendPOSTSuccessfulResponse(Fixtures.PAYPAL_HERMES_RESPONSE_WITH_PAYPAL_REDIRECT_URL) | ||
.isPayPalInstalled(true) | ||
.build(); | ||
|
||
PayPalInternalClient sut = new PayPalInternalClient(braintreeClient, dataCollector, apiClient); | ||
|
||
PayPalVaultRequest payPalRequest = new PayPalVaultRequest(true); | ||
payPalRequest.setUserAuthenticationEmail("[email protected]"); | ||
payPalRequest.setEnablePayPalAppSwitch(true); | ||
|
||
sut.sendRequest(context, payPalRequest, payPalInternalClientCallback); | ||
|
||
ArgumentCaptor<PayPalPaymentAuthRequestParams> captor = ArgumentCaptor.forClass( | ||
PayPalPaymentAuthRequestParams.class); | ||
verify(payPalInternalClientCallback).onResult(captor.capture(), (Exception) isNull()); | ||
|
||
PayPalPaymentAuthRequestParams payPalPaymentAuthRequestParams = captor.getValue(); | ||
assertTrue(payPalPaymentAuthRequestParams.isBillingAgreement()); | ||
|
||
Uri approvalUri = Uri.parse(payPalPaymentAuthRequestParams.getApprovalUrl()); | ||
String pairingId = approvalUri.getQueryParameter("ba_token"); | ||
assertNotNull(pairingId); | ||
assertEquals(pairingId, payPalPaymentAuthRequestParams.getPairingId()); | ||
assertNotNull(approvalUri.getQueryParameter("source")); | ||
assertNotNull(approvalUri.getQueryParameter("switch_initiated_time")); | ||
assertEquals(approvalUri.getHost(), "paypal.com"); | ||
} | ||
|
||
@Test | ||
public void sendRequest_withPayPalVaultRequest_callsBackPayPalResponseOnSuccess_returnsApprovalURL() { | ||
BraintreeClient braintreeClient = new MockBraintreeClientBuilder() | ||
.configuration(configuration) | ||
.authorizationSuccess(clientToken) | ||
.appLinkReturnUri(Uri.parse("https://example.com")) | ||
.sendPOSTSuccessfulResponse(Fixtures.PAYPAL_HERMES_RESPONSE_WITH_APPROVAL_URL) | ||
.build(); | ||
|
||
PayPalInternalClient sut = new PayPalInternalClient(braintreeClient, dataCollector, apiClient); | ||
|
||
PayPalVaultRequest payPalRequest = new PayPalVaultRequest(true); | ||
|
||
sut.sendRequest(context, payPalRequest, payPalInternalClientCallback); | ||
|
||
ArgumentCaptor<PayPalPaymentAuthRequestParams> captor = ArgumentCaptor.forClass( | ||
PayPalPaymentAuthRequestParams.class); | ||
verify(payPalInternalClientCallback).onResult(captor.capture(), (Exception) isNull()); | ||
|
||
String expectedUrl = "https://www.example.com/some?ba_token=fake-ba-token"; | ||
PayPalPaymentAuthRequestParams payPalPaymentAuthRequestParams = captor.getValue(); | ||
assertTrue(payPalPaymentAuthRequestParams.isBillingAgreement()); | ||
assertEquals("fake-ba-token", payPalPaymentAuthRequestParams.getPairingId()); | ||
assertEquals(expectedUrl, payPalPaymentAuthRequestParams.getApprovalUrl()); | ||
} | ||
|
||
@Test | ||
public void sendRequest_withPayPalCheckoutRequest_callsBackPayPalResponseOnSuccess() { | ||
when(dataCollector.getClientMetadataId(context, configuration, true)).thenReturn("sample-client-metadata-id"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters