Skip to content

Commit

Permalink
Merge pull request #1628 from stripe/csabol/redirect_cancel
Browse files Browse the repository at this point in the history
Adds cancellation error in STPRedirectContext completion block
  • Loading branch information
csabol-stripe authored Aug 21, 2020
2 parents ad9aca8 + b804c84 commit 4de42b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion Stripe/STPRedirectContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,20 @@ - (void)cancel {
#pragma mark - SFSafariViewControllerDelegate -

- (void)safariViewControllerDidFinish:(__unused SFSafariViewController *)controller {
NSError *manuallyClosedError = nil;
if (self.returnURL != nil
&& self.state == STPRedirectContextStateInProgress
&& self.completionError == nil
) {
manuallyClosedError = [NSError errorWithDomain:StripeDomain
code:STPCancellationError
userInfo:@{
STPErrorMessageKey: @"User manually closed SFSafariViewController before redirect was completed."
}
];
}
stpDispatchToMainThreadIfNecessary(^{
[self handleRedirectCompletionWithError:nil
[self handleRedirectCompletionWithError:manuallyClosedError
shouldDismissViewController:NO];
});
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/Tests/STPRedirectContextTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ - (void)testSafariViewControllerRedirectFlow_didFinish {
STPRedirectContext *context = [[STPRedirectContext alloc] initWithSource:source completion:^(NSString *sourceID, NSString *clientSecret, NSError *error) {
XCTAssertEqualObjects(sourceID, source.stripeID);
XCTAssertEqualObjects(clientSecret, source.clientSecret);
XCTAssertNil(error);
// because we are manually invoking the dismissal, we report this as a cancelation
XCTAssertEqual(error.domain, StripeDomain);
XCTAssertEqual(error.code, STPCancellationError);
[exp fulfill];
}];
id sut = OCMPartialMock(context);
Expand Down

0 comments on commit 4de42b8

Please sign in to comment.