Commit 837165d1 by Rune Madsen

Fix an issue where partialAddresses flag was set to false, which would invalidat…

Fix an issue where partialAddresses flag was set to false, which would invalidat the already set (through a updateCheckout: call) shippingRate on a checkout during completeCheckout:
parent f5c7af61
......@@ -101,6 +101,8 @@
{
BUYCart *cart = [[BUYCart alloc] init];
BUYCheckout *checkout = [[BUYCheckout alloc] initWithCart:cart];
XCTAssertThrows([checkout setPartialAddresses:NO]);
NSURLSessionDataTask *task = [self.client createCheckout:checkout completion:nil];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:task.originalRequest.HTTPBody options:0 error:nil];
......
......@@ -250,6 +250,8 @@
/**
* 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;
......
......@@ -202,6 +202,14 @@
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
{
return (_token && [_token length] > 0);
......
......@@ -89,8 +89,7 @@ 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.
// 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)]) {
self.checkout.email = payment.shippingContact.emailAddress;
self.checkout.shippingAddress = self.checkout.requiresShipping ? [BUYAddress buy_addressFromContact:payment.shippingContact] : nil;
......@@ -165,8 +164,13 @@ const NSTimeInterval PollDelay = 0.5;
#pragma mark -
- (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]) {
......
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