-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support native redirects #783
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work! left a few small comments
Stripe/STPRedirectContext.m
Outdated
@@ -19,6 +20,8 @@ | |||
|
|||
NS_ASSUME_NONNULL_BEGIN | |||
|
|||
typedef void (^STPNativeRedirectCompletionBlock)(BOOL success); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we call this STPBoolCompletionBlock
to match our other block type names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, should i move it to STPBlocks.h ? I wasn't sure about just naming it just BoolBlock because the bool is specifically success or failure and wasn't sure if that was generic across what all bool using blocks would be.
Stripe/STPRedirectContext.m
Outdated
[application openURL:nativeUrl options:@{} completionHandler:^(BOOL success) { | ||
if (!success) { | ||
STRONG(self); | ||
self->_state = STPRedirectContextStateNotStarted; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooc, why self->_state=
instead of just _state=
?
Also, can't we just use the getters/setters in this method instead of ivars? I usually only use ivars in init
, or if the getter/setter has side effects. Maybe we should add something to the style guide...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to do self->state
or you get a compiler warning about implicit retain of self.
Yeah there are some style guide stuff here I guess. I didn't actually make setters for these in the .m file, I generally prefer doing it this way, but we can change (And have a style guide conversation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, forgot about that compiler warning. 👍
} | ||
else { | ||
_state = STPRedirectContextStateInProgress; | ||
BOOL opened = [application openURL:nativeUrl]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOC, do you know if this behaves differently from the new openURL:options:completionHandler:
method? E.g. does the returned success value here always match the success value in the async completion block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know it's always the same, it's described the same in the docs. The main difference in the new API afaict is the options and the asyncronicity.
Tests/Tests/STPRedirectContextTest.m
Outdated
|
||
OCMReject([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]); | ||
OCMReject([sut startSafariAppRedirectFlow]); | ||
OCMVerify([applicationMock openURL:[OCMArg any] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's check the URL argument too with OCMArg isEqual:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==
Tests/Tests/STPRedirectContextTest.m
Outdated
OCMReject([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]); | ||
OCMReject([sut startSafariAppRedirectFlow]); | ||
OCMVerify([applicationMock openURL:[OCMArg any] | ||
options:[OCMArg any] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can use [OCMArg isNil]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think any of these should be nil?
Tests/Tests/STPRedirectContextTest.m
Outdated
id mockVC = OCMClassMock([UIViewController class]); | ||
[context startRedirectFlowFromViewController:mockVC]; | ||
|
||
OCMVerify([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can verify this arg is equal to mockVC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Same reservations about the state
instance variable access.
Tests/Tests/STPFixtures.h
Outdated
+ (STPSource *)alipaySource; | ||
|
||
/** | ||
A Source object with type Alipay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"A Source object with type Alipay and native url"* 😄
Tests/Tests/STPRedirectContextTest.m
Outdated
|
||
OCMReject([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]); | ||
OCMReject([sut startSafariAppRedirectFlow]); | ||
OCMVerify([applicationMock openURL:[OCMArg any] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==
Tests/Tests/STPRedirectContextTest.m
Outdated
OCMReject([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]); | ||
OCMReject([sut startSafariAppRedirectFlow]); | ||
OCMVerify([applicationMock openURL:[OCMArg any] | ||
options:[OCMArg any] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
==
Tests/Tests/STPRedirectContextTest.m
Outdated
OCMReject([sut startSafariAppRedirectFlow]); | ||
OCMVerify([applicationMock openURL:[OCMArg any] | ||
options:[OCMArg any] | ||
completionHandler:[OCMArg any]]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the past, I've been able to use an [OCMArg checkWithBlock:]
to trigger the completion to test the entire flow:
OCMVerify([applicationMock openURL:options:completionHandler:[OCMArg checkWithBlock:^BOOL(void (^)completion) {
completion();
}]]);
Updated if people want to re-review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
OCMStub([applicationMock sharedApplication]).andReturn(applicationMock); | ||
OCMStub([applicationMock openURL:[OCMArg any] | ||
options:[OCMArg any] | ||
completionHandler:([OCMArg invokeBlockWithArgs:@YES, nil])]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet!!
OCMStub([applicationMock sharedApplication]).andReturn(applicationMock); | ||
OCMStub([applicationMock openURL:[OCMArg any] | ||
options:[OCMArg any] | ||
completionHandler:([OCMArg invokeBlockWithArgs:@YES, nil])]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet!!
Tests/Tests/STPRedirectContextTest.m
Outdated
OCMVerify([applicationMock openURL:[OCMArg any] | ||
options:[OCMArg any] | ||
completionHandler:[OCMArg any]]); | ||
OCMVerify([applicationMock openURL:[OCMArg isEqual:sourceURL] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just write sourceURL
instead of [OCMArg isEqual:sourceURL]
in the verify calls? Not completely sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it wasn't clear to me if they were the same. I thought maybe one way did == sourceURL
and one way did isEqual:sourceURL
? But I'm not sure.
7f49eaf
to
5de1550
Compare
Some minor changes if anyone wants to re-review. Otherwise this has been tested with a live charge and is ready to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Not going to merge immediately because I think there's still some question about where in the source return data the native url for Alipay is going to be, but this is a general framework for dealing with sources that support native redirects going forward.