Skip to content

Commit

Permalink
Merge pull request #878 from stripe/bg-redirectcontext-chargeable
Browse files Browse the repository at this point in the history
update RedirectContext to accept pending or chargeable sources
  • Loading branch information
bg-stripe authored Jan 5, 2018
2 parents ce14914 + ebce801 commit 6521f67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Stripe/STPRedirectContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ - (nullable instancetype)initWithSource:(STPSource *)source
completion:(STPRedirectContextCompletionBlock)completion {

if (source.flow != STPSourceFlowRedirect
|| source.status != STPSourceStatusPending
|| !(source.status == STPSourceStatusPending ||
source.status == STPSourceStatusChargeable)
|| source.redirect.returnURL == nil
|| (source.redirect.url == nil
&& [self nativeRedirectURLForSource:source] == nil)) {
Expand Down
11 changes: 11 additions & 0 deletions Tests/Tests/STPRedirectContextTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "NSURLComponents+Stripe.h"
#import "STPFixtures.h"
#import "STPRedirectContext.h"
#import "STPTestUtils.h"
#import "STPURLCallbackHandler.h"
#import "STPWeakStrongMacros.h"

Expand Down Expand Up @@ -66,6 +67,16 @@ - (void)testInitWithNonRedirectSourceReturnsNil {
XCTAssertNil(sut);
}

- (void)testInitWithConsumedSourceReturnsNil {
NSMutableDictionary *json = [[STPTestUtils jsonNamed:STPTestJSONSourceCard] mutableCopy];
json[@"status"] = @"consumed";
STPSource *source = [STPSource decodedObjectFromAPIResponse:json];
STPRedirectContext *sut = [[STPRedirectContext alloc] initWithSource:source completion:^(__unused NSString *sourceID, __unused NSString *clientSecret, __unused NSError *error) {
XCTFail(@"completion was called");
}];
XCTAssertNil(sut);
}

/**
After starting a SafariViewController redirect flow,
when a WillEnterForeground notification is posted, RedirectContext's completion
Expand Down

0 comments on commit 6521f67

Please sign in to comment.