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

Fix createsCardSources <> didCreatePaymentResult , Apple Pay #893

Merged
merged 5 commits into from
Feb 2, 2018

Conversation

bg-stripe
Copy link
Contributor

r? @danj-stripe

This fixes two issues:

  • didCreatePaymentResult wasn't called when createsCardSources = true
  • selecting apple pay created a card token when createsCardSources = true

I tested Apple Pay and didCreatePaymentResult in the example app with sources. I've also updated the example app to always create card sources.

self.onTokenCreation(token, ^(NSError *tokenCreationError){
if (tokenCreationError) {
self.lastError = tokenCreationError;
id<STPSourceProtocol> source;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is source used for? It kind of looks like you meant to pass source to the onSourceCreation() call, but it's getting result right now, so I think this is dead code.

edit: neat, static analyzer agrees with me and failed the build 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm more confident that you meant to pass source instead of result: down in the definition of applePaySourceHandler, the code used to be constructing a STPPaymentResult with token.card, and now it just passes source directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh derp, good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so i think i understand why this worked (returning STPToken instead of the child STPCard for an apple pay source). we don't display apple pay sources in the UI, so it didn't matter that STPToken doesn't conform to <STPPaymentMethod> (the protocol defining how a payment method is displayed). i'll still fix for consistency with how we handle non-apple pay sources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in eb09444, re-r?

@@ -582,9 +582,10 @@ - (void)requestPayment {
else if ([self requestPaymentShouldPresentShippingViewController]) {
[self presentShippingViewControllerWithNewState:STPPaymentContextStateRequestingPayment];
}
else if ([self.selectedPaymentMethod isKindOfClass:[STPCard class]]) {
else if ([self.selectedPaymentMethod isKindOfClass:[STPCard class]] ||
[self.selectedPaymentMethod isKindOfClass:[STPSource class]]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about checking [self.selectedPaymentMethod conformsToProtocol:@protocol(STPSourceProtocol)] instead?

I don't know:

  • whether there are other classes that conform to the protocol at we want excluded from this branch (making the check invalid)
  • how likely it is that we'll add new classes that do conform to the protocol that should take this branch (updated check would future-proof us)
  • how likely that we'll remove conformance to the protocol from these classes (which would break the check)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mm, interesting idea. I think it's unlikely that we'll create other class that conform to this protocol (the protocol is mostly a compatibility shim for card tokens to work with sources). I think we should leave it this way and explicitly reference STPCard, which we should start treating as a legacy class (card tokens will continue to be supported for a long time, but sources are the preferred integration).

@danj-stripe danj-stripe assigned bg-stripe and unassigned danj-stripe Feb 2, 2018
@bg-stripe bg-stripe assigned danj-stripe and unassigned bg-stripe Feb 2, 2018
Copy link
Contributor

@danj-stripe danj-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

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.

3 participants