Commit 7c29408d by Rune Madsen

Minor improvements to the logic in the sample app for handling a…

Minor improvements to the logic in the sample app for handling a SFSafariViewController checkout and returning from a successful checkout using the urlScheme button
parent 02da0c5e
......@@ -195,7 +195,13 @@ NSString * const MerchantId = @"";
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller
{
[self.navigationController popToRootViewControllerAnimated:YES];
[self getCompletedCheckout:^{
dispatch_async(dispatch_get_main_queue(), ^{
if (self.checkout.order) {
[self showCheckoutConfirmation];
}
});
}];
}
#pragma mark Native Checkout
......@@ -240,7 +246,7 @@ NSString * const MerchantId = @"";
NSLog(@"Successfully got completion status: %lu", (unsigned long)completionStatus);
[self getCompletedCheckout];
[self getCompletedCheckout:NULL];
}
- (void)operation:(GetCompletionStatusOperation *)operation failedToReceiveCompletionStatus:(NSError *)error
......@@ -308,7 +314,9 @@ NSString * const MerchantId = @"";
[self.applePayHelper paymentAuthorizationViewController:controller didAuthorizePayment:payment completion:completion];
self.checkout = self.applePayHelper.checkout;
[self getCompletedCheckout];
[self getCompletedCheckout:^{
}];
}
- (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller
......@@ -360,25 +368,37 @@ NSString * const MerchantId = @"";
__weak CheckoutViewController *welf = self;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
void (^completionBlock)() = ^void() {
[self.client getCompletionStatusOfCheckoutURL:url completion:^(BUYStatus status, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (error == nil && status == BUYStatusComplete) {
NSLog(@"Successfully completed checkout");
[welf getCompletedCheckout];
[welf getCompletedCheckout:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self showCheckoutConfirmation];
});
}];
}
else {
NSLog(@"Error completing checkout: %@", error);
}
}];
};
if ([self.presentedViewController isKindOfClass:[SFSafariViewController class]]) {
[self dismissViewControllerAnimated:self.presentedViewController completion:completionBlock];
} else {
completionBlock();
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[[NSNotificationCenter defaultCenter] removeObserver:self name:CheckoutCallbackNotification object:nil];
}
- (void)getCompletedCheckout
- (void)getCompletedCheckout:(void (^)(void))completionBlock
{
__weak CheckoutViewController *welf = self;
......@@ -394,9 +414,12 @@ NSString * const MerchantId = @"";
}
if (checkout) {
welf.checkout = checkout;
[welf showCheckoutConfirmation];
NSLog(@"%@", checkout);
}
if (completionBlock) {
completionBlock();
}
}];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment