Skip to content
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

Merged
merged 5 commits into from
Sep 13, 2017
Merged

Support native redirects #783

merged 5 commits into from
Sep 13, 2017

Conversation

bdorfman-stripe
Copy link
Contributor

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.

Copy link
Contributor

@bg-stripe bg-stripe left a 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

@@ -19,6 +20,8 @@

NS_ASSUME_NONNULL_BEGIN

typedef void (^STPNativeRedirectCompletionBlock)(BOOL success);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

[application openURL:nativeUrl options:@{} completionHandler:^(BOOL success) {
if (!success) {
STRONG(self);
self->_state = STPRedirectContextStateNotStarted;
Copy link
Contributor

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...

Copy link
Contributor Author

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).

Copy link
Contributor

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];
Copy link
Contributor

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?

Copy link
Contributor Author

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.


OCMReject([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]);
OCMReject([sut startSafariAppRedirectFlow]);
OCMVerify([applicationMock openURL:[OCMArg any]
Copy link
Contributor

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:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==

OCMReject([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]);
OCMReject([sut startSafariAppRedirectFlow]);
OCMVerify([applicationMock openURL:[OCMArg any]
options:[OCMArg any]
Copy link
Contributor

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]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==

Copy link
Contributor Author

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?

id mockVC = OCMClassMock([UIViewController class]);
[context startRedirectFlowFromViewController:mockVC];

OCMVerify([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]);
Copy link
Contributor

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

Copy link
Contributor

@joeydong-stripe joeydong-stripe left a 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.

+ (STPSource *)alipaySource;

/**
A Source object with type Alipay
Copy link
Contributor

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"* 😄


OCMReject([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]);
OCMReject([sut startSafariAppRedirectFlow]);
OCMVerify([applicationMock openURL:[OCMArg any]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==

OCMReject([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]);
OCMReject([sut startSafariAppRedirectFlow]);
OCMVerify([applicationMock openURL:[OCMArg any]
options:[OCMArg any]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

==

OCMReject([sut startSafariAppRedirectFlow]);
OCMVerify([applicationMock openURL:[OCMArg any]
options:[OCMArg any]
completionHandler:[OCMArg any]]);
Copy link
Contributor

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();
}]]);

@bdorfman-stripe
Copy link
Contributor Author

Updated if people want to re-review.

Copy link
Contributor

@bg-stripe bg-stripe left a 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])]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 👍

Copy link
Contributor

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])]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet!!

OCMVerify([applicationMock openURL:[OCMArg any]
options:[OCMArg any]
completionHandler:[OCMArg any]]);
OCMVerify([applicationMock openURL:[OCMArg isEqual:sourceURL]
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@bdorfman-stripe bdorfman-stripe force-pushed the bdorfman-native-redirects branch from 7f49eaf to 5de1550 Compare September 12, 2017 23:20
@bdorfman-stripe
Copy link
Contributor Author

Some minor changes if anyone wants to re-review. Otherwise this has been tested with a live charge and is ready to merge.

Copy link
Contributor

@bg-stripe bg-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@bdorfman-stripe bdorfman-stripe merged commit 4163a43 into master Sep 13, 2017
@bdorfman-stripe bdorfman-stripe deleted the bdorfman-native-redirects branch September 13, 2017 19:10
davidme-stripe added a commit that referenced this pull request Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants