Skip to content
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 shipping rate invalidation bug using Apple Pay in 1.2.2 #69

Merged
merged 1 commit into from
Dec 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ - (void)testPartialAddressesFlag
{
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];
Expand Down
2 changes: 2 additions & 0 deletions Mobile Buy SDK/Mobile Buy SDK/Models/BUYCheckout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions Mobile Buy SDK/Mobile Buy SDK/Models/BUYCheckout.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ - (NSDictionary *)jsonDictionaryForCheckout
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);
Expand Down
12 changes: 8 additions & 4 deletions Mobile Buy SDK/Mobile Buy SDK/Utils/BUYApplePayHelpers.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController
{
// 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;
Expand Down Expand Up @@ -165,8 +164,13 @@ -(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController
#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]) {

Expand Down