-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix out-of-band web payment authentication (#1537)
When a user enters the in-app web payment authentication flow, is taken to another app to complete payment authentication out-of-band (i.e. a bank app), then returns to the WebView, make a request to the completion URL. This resolves the issue where the bank page loaded in the WebView doesn't detect that the user returned from the bank app.
- Loading branch information
1 parent
309c4aa
commit e58c470
Showing
3 changed files
with
82 additions
and
25 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
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import org.robolectric.RobolectricTestRunner; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
|
@@ -40,45 +41,44 @@ public void setup() { | |
|
||
@Test | ||
public void shouldOverrideUrlLoading_withPaymentIntent_shouldSetResult() { | ||
final String deepLink = "stripe://payment_intent_return?payment_intent=pi_123&" + | ||
final String url = "stripe://payment_intent_return?payment_intent=pi_123&" + | ||
"payment_intent_client_secret=pi_123_secret_456&source_type=card"; | ||
final PaymentAuthWebView.PaymentAuthWebViewClient paymentAuthWebViewClient = | ||
createWebViewClient( | ||
"pi_123_secret_456", | ||
"stripe://payment_intent_return" | ||
); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, deepLink); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, url); | ||
verify(mActivity).finish(); | ||
} | ||
|
||
@Test | ||
public void shouldOverrideUrlLoading_withSetupIntent_shouldSetResult() { | ||
final String deepLink = "stripe://payment_auth?setup_intent=seti_1234" + | ||
final String url = "stripe://payment_auth?setup_intent=seti_1234" + | ||
"&setup_intent_client_secret=seti_1234_secret_5678&source_type=card"; | ||
|
||
final PaymentAuthWebView.PaymentAuthWebViewClient paymentAuthWebViewClient = | ||
createWebViewClient("seti_1234_secret_5678", "stripe://payment_auth"); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, deepLink); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, url); | ||
verify(mActivity).finish(); | ||
} | ||
|
||
@Test | ||
public void shouldOverrideUrlLoading_withoutReturnUrl_onPaymentIntentImplicitReturnUrl_shouldSetResult() { | ||
final String deepLink = "stripe://payment_intent_return?payment_intent=pi_123&" + | ||
final String url = "stripe://payment_intent_return?payment_intent=pi_123&" + | ||
"payment_intent_client_secret=pi_123_secret_456&source_type=card"; | ||
final PaymentAuthWebView.PaymentAuthWebViewClient paymentAuthWebViewClient = | ||
createWebViewClient("pi_123_secret_456"); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, deepLink); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, url); | ||
verify(mActivity).finish(); | ||
} | ||
|
||
@Test | ||
public void shouldOverrideUrlLoading_withoutReturnUrl_onSetupIntentImplicitReturnUrl_shouldSetResult() { | ||
final String deepLink = "stripe://payment_auth?setup_intent=seti_1234" + | ||
final String url = "stripe://payment_auth?setup_intent=seti_1234" + | ||
"&setup_intent_client_secret=seti_1234_secret_5678&source_type=card"; | ||
final PaymentAuthWebView.PaymentAuthWebViewClient paymentAuthWebViewClient = | ||
createWebViewClient("seti_1234_secret_5678"); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, deepLink); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, url); | ||
verify(mActivity).finish(); | ||
} | ||
|
||
|
@@ -120,19 +120,19 @@ public void onPageFinished_witRedirectCompleteUrl_shouldFinish() { | |
|
||
@Test | ||
public void shouldOverrideUrlLoading_withOpaqueUri_shouldNotCrash() { | ||
final String deepLink = "mailto:[email protected]?payment_intent=pi_123&" + | ||
final String url = "mailto:[email protected]?payment_intent=pi_123&" + | ||
"payment_intent_client_secret=pi_123_secret_456&source_type=card"; | ||
final PaymentAuthWebView.PaymentAuthWebViewClient paymentAuthWebViewClient = | ||
createWebViewClient("pi_123_secret_456"); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, deepLink); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, url); | ||
} | ||
|
||
@Test | ||
public void shouldOverrideUrlLoading_withUnsupportedDeeplink_shouldFinish() { | ||
final String deepLink = "deep://link"; | ||
final String url = "deep://link"; | ||
final PaymentAuthWebView.PaymentAuthWebViewClient paymentAuthWebViewClient = | ||
createWebViewClient("pi_123_secret_456"); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, deepLink); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, url); | ||
verify(mActivity).finish(); | ||
} | ||
|
||
|
@@ -152,6 +152,29 @@ public void shouldOverrideUrlLoading_withIntentUri_shouldParseUri() { | |
verify(mActivity).finish(); | ||
} | ||
|
||
@Test | ||
public void shouldOverrideUrlLoading_withAuthenticationUrlWithReturnUrlParam_shouldPopulateCompletionUrl() { | ||
final String url = | ||
"https://hooks.stripe.com/three_d_secure/authenticate?amount=1250&client_secret=src_client_secret_abc123&return_url=https%3A%2F%2Fhooks.stripe.com%2Fredirect%2Fcomplete%2Fsrc_X9Y8Z7%3Fclient_secret%3Dsrc_client_secret_abc123&source=src_X9Y8Z7&usage=single_use"; | ||
final PaymentAuthWebView.PaymentAuthWebViewClient paymentAuthWebViewClient = | ||
createWebViewClient("pi_123_secret_456"); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, url); | ||
assertEquals( | ||
"https://hooks.stripe.com/redirect/complete/src_X9Y8Z7?client_secret=src_client_secret_abc123", | ||
paymentAuthWebViewClient.getCompletionUrlParam() | ||
); | ||
} | ||
|
||
@Test | ||
public void shouldOverrideUrlLoading_withAuthenticationUrlWithoutReturnUrlParam_shouldNotPopulateCompletionUrl() { | ||
final String url = | ||
"https://hooks.stripe.com/three_d_secure/authenticate?amount=1250&client_secret=src_client_secret_abc123&return_url=&source=src_X9Y8Z7&usage=single_use"; | ||
final PaymentAuthWebView.PaymentAuthWebViewClient paymentAuthWebViewClient = | ||
createWebViewClient("pi_123_secret_456"); | ||
paymentAuthWebViewClient.shouldOverrideUrlLoading(mWebView, url); | ||
assertNull(paymentAuthWebViewClient.getCompletionUrlParam()); | ||
} | ||
|
||
@NonNull | ||
private PaymentAuthWebView.PaymentAuthWebViewClient createWebViewClient( | ||
@NonNull String clientSecret | ||
|