Commit 3e7059b9 by Rune Madsen

Merge pull request #69 from Shopify/hotfix/runmad.68-partial-address-shipping-rates

Fix shipping rate invalidation bug using Apple Pay in 1.2.2
parents f5c7af61 837165d1
...@@ -102,6 +102,8 @@ ...@@ -102,6 +102,8 @@
BUYCart *cart = [[BUYCart alloc] init]; BUYCart *cart = [[BUYCart alloc] init];
BUYCheckout *checkout = [[BUYCheckout alloc] initWithCart:cart]; BUYCheckout *checkout = [[BUYCheckout alloc] initWithCart:cart];
XCTAssertThrows([checkout setPartialAddresses:NO]);
NSURLSessionDataTask *task = [self.client createCheckout:checkout completion:nil]; NSURLSessionDataTask *task = [self.client createCheckout:checkout completion:nil];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:task.originalRequest.HTTPBody options:0 error:nil]; NSDictionary *json = [NSJSONSerialization JSONObjectWithData:task.originalRequest.HTTPBody options:0 error:nil];
XCTAssertFalse([json[@"checkout"][@"partial_addresses"] boolValue]); XCTAssertFalse([json[@"checkout"][@"partial_addresses"] boolValue]);
......
...@@ -250,6 +250,8 @@ ...@@ -250,6 +250,8 @@
/** /**
* Flag used to inform server that the shipping address is partially filled, suitable to retrieve shipping rates * Flag used to inform server that the shipping address is partially filled, suitable to retrieve shipping rates
* with partial shipping addresses provided by PKPaymentAuthorizationViewController.
* Note: This should only ever be set to YES. Setting it to NO throws an exception.
*/ */
@property (nonatomic, assign) BOOL partialAddresses; @property (nonatomic, assign) BOOL partialAddresses;
......
...@@ -202,6 +202,14 @@ ...@@ -202,6 +202,14 @@
return @{ @"checkout" : json }; return @{ @"checkout" : json };
} }
-(void)setPartialAddresses:(BOOL)partialAddresses
{
if (partialAddresses == NO) {
@throw [NSException exceptionWithName:@"partialAddress" reason:@"partialAddresses can only be set to true and should never be set to false on a complete address" userInfo:nil];
}
_partialAddresses = partialAddresses;
}
- (BOOL)hasToken - (BOOL)hasToken
{ {
return (_token && [_token length] > 0); return (_token && [_token length] > 0);
......
...@@ -90,7 +90,6 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -90,7 +90,6 @@ const NSTimeInterval PollDelay = 0.5;
// Update the checkout with the rest of the information. Apple has now provided us with a FULL billing address and a FULL shipping address. // Update the checkout with the rest of the information. Apple has now provided us with a FULL billing address and a FULL shipping address.
// We now update the checkout with our new found data so that you can ship the products to the right address, and we collect whatever else we need. // We now update the checkout with our new found data so that you can ship the products to the right address, and we collect whatever else we need.
self.checkout.partialAddresses = NO;
if ([payment respondsToSelector:@selector(shippingContact)]) { if ([payment respondsToSelector:@selector(shippingContact)]) {
self.checkout.email = payment.shippingContact.emailAddress; self.checkout.email = payment.shippingContact.emailAddress;
self.checkout.shippingAddress = self.checkout.requiresShipping ? [BUYAddress buy_addressFromContact:payment.shippingContact] : nil; self.checkout.shippingAddress = self.checkout.requiresShipping ? [BUYAddress buy_addressFromContact:payment.shippingContact] : nil;
...@@ -166,7 +165,12 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -166,7 +165,12 @@ const NSTimeInterval PollDelay = 0.5;
- (void)updateCheckoutWithAddressCompletion:(void (^)(PKPaymentAuthorizationStatus, NSArray *shippingMethods, NSArray *summaryItems))completion - (void)updateCheckoutWithAddressCompletion:(void (^)(PKPaymentAuthorizationStatus, NSArray *shippingMethods, NSArray *summaryItems))completion
{ {
self.checkout.partialAddresses = [self.checkout.shippingAddress isPartialAddress]; // This method call is internal to selection of shipping address that are returned as partial from PKPaymentAuthorizationViewController
// However, to ensure we never set partialAddresses to NO, we want to guard the setter. Should PKPaymentAuthorizationViewController ever
// return a full address through it's delegate method, this will still function since a complete address can be used to calculate shipping rates
if ([self.checkout.shippingAddress isPartialAddress] == YES) {
self.checkout.partialAddresses = YES;
}
if ([self.checkout.shippingAddress isValidAddressForShippingRates]) { if ([self.checkout.shippingAddress isValidAddressForShippingRates]) {
......
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