Commit 9e50f380 by Brent Gulanowski

Lift conditional out of method into call sites.

parent fd81b6e6
...@@ -135,13 +135,17 @@ typedef void (^AddressUpdateCompletion)(PKPaymentAuthorizationStatus, NSArray<PK ...@@ -135,13 +135,17 @@ typedef void (^AddressUpdateCompletion)(PKPaymentAuthorizationStatus, NSArray<PK
-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingAddress:(ABRecordRef)address completion:(AddressUpdateCompletion)completion -(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingAddress:(ABRecordRef)address completion:(AddressUpdateCompletion)completion
{ {
self.checkout.shippingAddress = [self buyAddressWithABRecord:address]; self.checkout.shippingAddress = [self buyAddressWithABRecord:address];
[self updateCheckoutWithAddressCompletion:completion]; if ([self.checkout.shippingAddress isValidAddressForShippingRates]) {
[self updateCheckoutWithAddressCompletion:completion];
}
} }
-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(AddressUpdateCompletion)completion -(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(AddressUpdateCompletion)completion
{ {
self.checkout.shippingAddress = [self buyAddressWithContact:contact]; self.checkout.shippingAddress = [self buyAddressWithContact:contact];
[self updateCheckoutWithAddressCompletion:completion]; if ([self.checkout.shippingAddress isValidAddressForShippingRates]) {
[self updateCheckoutWithAddressCompletion:completion];
}
} }
-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingMethod:(PKShippingMethod *)shippingMethod completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion -(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingMethod:(PKShippingMethod *)shippingMethod completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
...@@ -171,26 +175,21 @@ typedef void (^AddressUpdateCompletion)(PKPaymentAuthorizationStatus, NSArray<PK ...@@ -171,26 +175,21 @@ typedef void (^AddressUpdateCompletion)(PKPaymentAuthorizationStatus, NSArray<PK
self.checkout.partialAddresses = @YES; self.checkout.partialAddresses = @YES;
} }
if ([self.checkout.shippingAddress isValidAddressForShippingRates]) { [self.client updateCheckout:self.checkout completion:^(BUYCheckout *checkout, NSError *error) {
[self.client updateCheckout:self.checkout completion:^(BUYCheckout *checkout, NSError *error) { if (checkout && !error) {
if (checkout && !error) { self.checkout = checkout;
self.checkout = checkout; }
} else if (error) {
else if (error) { self.lastError = error;
self.lastError = error; }
} if (checkout.requiresShipping) {
if (checkout.requiresShipping) { self.shippingRates = @[];
self.shippingRates = @[]; [self updateShippingRatesCompletion:completion];
[self updateShippingRatesCompletion:completion]; }
} else {
else { completion(PKPaymentAuthorizationStatusSuccess, @[], [self.checkout buy_summaryItemsWithShopName:self.shopName]);
completion(PKPaymentAuthorizationStatusSuccess, @[], [self.checkout buy_summaryItemsWithShopName:self.shopName]); }
} }];
}];
}
else {
completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress, @[], [self.checkout buy_summaryItemsWithShopName:self.shopName]);
}
} }
- (void)updateShippingRatesCompletion:(AddressUpdateCompletion)completion - (void)updateShippingRatesCompletion:(AddressUpdateCompletion)completion
......
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