-
Notifications
You must be signed in to change notification settings - Fork 976
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
Changes from all commits
09d1d31
06b63f0
c724928
c8ed039
eb09444
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about checking I don't know:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
self.state = STPPaymentContextStateRequestingPayment; | ||
STPPaymentResult *result = [[STPPaymentResult alloc] initWithSource:(STPCard *)self.selectedPaymentMethod]; | ||
STPPaymentResult *result = [[STPPaymentResult alloc] initWithSource:(id<STPSourceProtocol>)self.selectedPaymentMethod]; | ||
[self.delegate paymentContext:self didCreatePaymentResult:result completion:^(NSError * _Nullable error) { | ||
stpDispatchToMainThreadIfNecessary(^{ | ||
if (error) { | ||
|
@@ -625,19 +626,19 @@ - (void)requestPayment { | |
[customerContext updateCustomerWithShippingAddress:self.shippingAddress completion:nil]; | ||
} | ||
}; | ||
STPApplePayTokenHandlerBlock applePayTokenHandler = ^(STPToken *token, STPErrorBlock tokenCompletion) { | ||
[self.apiAdapter attachSourceToCustomer:token completion:^(NSError *tokenError) { | ||
STPApplePaySourceHandlerBlock applePaySourceHandler = ^(id<STPSourceProtocol> source, STPErrorBlock completion) { | ||
[self.apiAdapter attachSourceToCustomer:source completion:^(NSError *attachSourceError) { | ||
stpDispatchToMainThreadIfNecessary(^{ | ||
if (tokenError) { | ||
tokenCompletion(tokenError); | ||
if (attachSourceError) { | ||
completion(attachSourceError); | ||
} else { | ||
STPPaymentResult *result = [[STPPaymentResult alloc] initWithSource:token.card]; | ||
STPPaymentResult *result = [[STPPaymentResult alloc] initWithSource:source]; | ||
[self.delegate paymentContext:self didCreatePaymentResult:result completion:^(NSError * error) { | ||
// for Apple Pay, the didFinishWithStatus callback is fired later when Apple Pay VC finishes | ||
if (error) { | ||
tokenCompletion(error); | ||
completion(error); | ||
} else { | ||
tokenCompletion(nil); | ||
completion(nil); | ||
} | ||
}]; | ||
} | ||
|
@@ -648,10 +649,11 @@ - (void)requestPayment { | |
paymentAuthVC = [PKPaymentAuthorizationViewController | ||
stp_controllerWithPaymentRequest:paymentRequest | ||
apiClient:self.apiClient | ||
createSource:self.configuration.createCardSources | ||
onShippingAddressSelection:shippingAddressHandler | ||
onShippingMethodSelection:shippingMethodHandler | ||
onPaymentAuthorization:paymentHandler | ||
onTokenCreation:applePayTokenHandler | ||
onTokenCreation:applePaySourceHandler | ||
onFinish:^(STPPaymentStatus status, NSError * _Nullable error) { | ||
[self.hostViewController dismissViewControllerAnimated:[self transitionAnimationsEnabled] | ||
completion:^{ | ||
|
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.
What is
source
used for? It kind of looks like you meant to passsource
to theonSourceCreation()
call, but it's gettingresult
right now, so I think this is dead code.edit: neat, static analyzer agrees with me and failed the build 😄
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'm more confident that you meant to pass
source
instead ofresult
: down in the definition ofapplePaySourceHandler
, the code used to be constructing aSTPPaymentResult
withtoken.card
, and now it just passessource
directly.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 derp, good catch!
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.
so i think i understand why this worked (returning
STPToken
instead of the childSTPCard
for an apple pay source). we don't display apple pay sources in the UI, so it didn't matter thatSTPToken
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.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.
fixed in eb09444, re-r?