Commit adbfef17 by Dima Bart

Remove use of deprecated AddressBook API.

parent 78c20740
......@@ -24,7 +24,6 @@
// THE SOFTWARE.
//
@import AddressBook;
@import PassKit;
@import UIKit;
@import XCTest;
......@@ -276,118 +275,6 @@
#pragma mark - BUYAddress Apple Pay additions
- (void)testEmailFromRecord
{
ABRecordRef person = ABPersonCreate();
CFErrorRef error = NULL;
ABRecordSetValue(person, kABPersonFirstNameProperty, CFSTR("Bob"), &error);
ABRecordSetValue(person, kABPersonLastNameProperty, CFSTR("Banana"), &error);
ABMutableMultiValueRef emails = ABMultiValueCreateMutable(kABStringPropertyType);
ABMultiValueAddValueAndLabel(emails, CFSTR("bob@banana.com"), CFSTR("work"), nil);
ABMultiValueAddValueAndLabel(emails, CFSTR("dino@banana.com"), CFSTR("home"), nil);
ABRecordSetValue(person, kABPersonEmailProperty, emails, &error);
CFRelease(emails);
XCTAssertEqualObjects(@"bob@banana.com", [BUYAddress buy_emailFromRecord:person]);
CFRelease(person);
}
- (void)testEmailFromRecordWithoutAnEmail
{
ABRecordRef person = ABPersonCreate();
CFErrorRef error = NULL;
ABRecordSetValue(person, kABPersonFirstNameProperty, CFSTR("Bob"), &error);
ABRecordSetValue(person, kABPersonLastNameProperty, CFSTR("Banana"), &error);
XCTAssertNil([BUYAddress buy_emailFromRecord:person]);
CFRelease(person);
}
- (void)testAddressFromRecord
{
BUYAddress *newAddress = [self buyAddressWithTestRecordFullDetails:YES];
XCTAssertNotNil(newAddress);
XCTAssertEqualObjects(@"Bob", newAddress.firstName);
XCTAssertEqualObjects(@"Banana", newAddress.lastName);
XCTAssertEqualObjects(@"150 Elgin Street", newAddress.address1);
XCTAssertEqualObjects(@"Ottawa", newAddress.city);
XCTAssertEqualObjects(@"Ontario", newAddress.province);
XCTAssertEqualObjects(@"K1N5T5", newAddress.zip);
XCTAssertNil(newAddress.country);
XCTAssertEqualObjects(@"CA", newAddress.countryCode);
XCTAssertEqualObjects(@"1-888-746-7439", newAddress.phone);
}
- (BUYAddress*)buyAddressWithTestRecordFullDetails:(BOOL)fullDetails
{
ABRecordRef person = ABPersonCreate();
CFErrorRef error = NULL;
if (fullDetails) {
ABRecordSetValue(person, kABPersonFirstNameProperty, CFSTR("Bob"), &error);
ABRecordSetValue(person, kABPersonLastNameProperty, CFSTR("Banana"), &error);
}
ABMutableMultiValueRef addresses = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
CFMutableDictionaryRef address = CFDictionaryCreateMutable(kCFAllocatorDefault, 10, nil, nil);
if (fullDetails) {
CFDictionarySetValue(address, kABPersonAddressStreetKey, CFSTR("150 Elgin Street"));
}
CFDictionarySetValue(address, kABPersonAddressCityKey, CFSTR("Ottawa"));
CFDictionarySetValue(address, kABPersonAddressStateKey, CFSTR("Ontario"));
CFDictionarySetValue(address, kABPersonAddressZIPKey, CFSTR("K1N5T5"));
CFDictionarySetValue(address, kABPersonAddressCountryKey, CFSTR("Canada"));
CFDictionarySetValue(address, kABPersonAddressCountryCodeKey, CFSTR("CA"));
if (fullDetails) {
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue, @"1-888-746-7439", kABPersonPhoneMobileLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
}
ABMultiValueAddValueAndLabel(addresses, address, CFSTR("Shipping"), nil);
CFRelease(address);
ABRecordSetValue(person, kABPersonAddressProperty, addresses, &error);
CFRelease(addresses);
BUYAddress *newAddress = [_modelManager buyAddressWithABRecord:person];
CFRelease(person);
return newAddress;
}
- (void)testAddressFromRecordWithoutNameOrStreetOrPhone
{
BUYAddress *newAddress = [self buyAddressWithTestRecordFullDetails:NO];
XCTAssertNotNil(newAddress);
XCTAssertEqualObjects(nil, newAddress.address1);
XCTAssertEqualObjects(@"Ottawa", newAddress.city);
XCTAssertEqualObjects(@"Ontario", newAddress.province);
XCTAssertEqualObjects(@"K1N5T5", newAddress.zip);
XCTAssertNil(newAddress.country);
XCTAssertEqualObjects(@"CA", newAddress.countryCode);
XCTAssertEqualObjects(nil, newAddress.phone);
}
- (void)testAddressFromContact
{
BUYAddress *newAddress = [self buyAddressWithTestContactFullDetails:YES];
XCTAssertNotNil(newAddress);
XCTAssertEqualObjects(@"Bob", newAddress.firstName);
XCTAssertEqualObjects(@"Banana", newAddress.lastName);
XCTAssertEqualObjects(@"150 Elgin Street", newAddress.address1);
XCTAssertEqualObjects(@"Ottawa", newAddress.city);
XCTAssertEqualObjects(@"Ontario", newAddress.province);
XCTAssertEqualObjects(@"K1N5T5", newAddress.zip);
XCTAssertNil(newAddress.country);
XCTAssertEqualObjects(@"CA", newAddress.countryCode);
}
- (BUYAddress*)buyAddressWithTestContactFullDetails:(BOOL)fullDetails
{
BUYPKContact *contact = [[BUYPKContact alloc ] init];
......@@ -413,20 +300,6 @@
return [_modelManager buyAddressWithContact:contact];
}
- (void)testCompareAddressWithContactWithNameOrStreetOrPhone
{
BUYAddress *addressFromRecord = [self buyAddressWithTestRecordFullDetails:YES];
BUYAddress *addressFromContact = [self buyAddressWithTestContactFullDetails:YES];
[self compareAddressFromRecord:addressFromRecord withAddressFromContact:addressFromContact];
}
- (void)testCompareAddressWithContactWithoutNameOrStreetOrPhone
{
BUYAddress *addressFromRecord = [self buyAddressWithTestRecordFullDetails:NO];
BUYAddress *addressFromContact = [self buyAddressWithTestContactFullDetails:NO];
[self compareAddressFromRecord:addressFromRecord withAddressFromContact:addressFromContact];
}
- (void)compareAddressFromRecord:(BUYAddress*)addressFromRecord withAddressFromContact:(BUYAddress*)addressFromContact {
XCTAssertNotNil(addressFromRecord);
XCTAssertNotNil(addressFromContact);
......
......@@ -273,19 +273,6 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
}];
}
-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingAddress:(ABRecordRef)address completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKShippingMethod *> * _Nonnull, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
{
[self.applePayAuthorizationDelegate paymentAuthorizationViewController:controller didSelectShippingAddress:address completion:^(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> * _Nonnull shippingMethods, NSArray<PKPaymentSummaryItem *> * _Nonnull summaryItems) {
if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) {
[self.delegate paymentProvider:self didFailWithError:self.applePayAuthorizationDelegate.lastError];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self];
}
completion(status, shippingMethods, summaryItems);
}];
}
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKShippingMethod *> * _Nonnull, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
{
[self.applePayAuthorizationDelegate paymentAuthorizationViewController:controller didSelectShippingContact:contact completion:^(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> * _Nonnull shippingMethods, NSArray<PKPaymentSummaryItem *> * _Nonnull summaryItems) {
......
......@@ -65,10 +65,6 @@
@interface BUYAddress (ApplePay)
+ (nullable NSString *)buy_emailFromRecord:(nullable ABRecordRef)record;
- (void)updateWithRecord:(nullable ABRecordRef)record NS_DEPRECATED_IOS(8_0, 9_0, "Use the CNContact backed `updateWithContact:` instead");
- (void)updateWithContact:(nullable PKContact*)contact NS_AVAILABLE_IOS(9_0);
@end
......@@ -24,7 +24,6 @@
// THE SOFTWARE.
//
@import AddressBook;
@import PassKit;
#import "BUYLineItem.h"
#import "BUYGiftCard.h"
......@@ -121,61 +120,6 @@
@implementation BUYAddress (ApplePay)
+ (nullable NSString *)buy_emailFromRecord:(nullable ABRecordRef)record
{
ABMultiValueRef emailMultiValue = ABRecordCopyValue(record, kABPersonEmailProperty);
CFArrayRef allEmails = ABMultiValueCopyArrayOfAllValues(emailMultiValue);
NSString *email = nil;
if (allEmails && CFArrayGetCount(allEmails)) {
email = (__bridge NSString *)CFArrayGetValueAtIndex(allEmails, 0);
}
CFSafeRelease(allEmails);
CFSafeRelease(emailMultiValue);
return email;
}
- (void)updateWithRecord:(nullable ABRecordRef)record
{
//Grab the simple information
self.firstName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty);
self.lastName = (__bridge_transfer NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty);
//Grab the address information
ABMultiValueRef addressMultiValue = ABRecordCopyValue(record, kABPersonAddressProperty);
CFArrayRef allAddresses = ABMultiValueCopyArrayOfAllValues(addressMultiValue);
if (allAddresses && CFArrayGetCount(allAddresses) > 0) {
CFDictionaryRef firstAddress = CFArrayGetValueAtIndex(allAddresses, 0);
//NOTE: We do not receive an address1 line right now via this partial address, as Apple deemds it unimportant to calculate the shipping rates. We get the actual address later on in a later step.
self.address1 = (__bridge NSString *)CFDictionaryGetValue(firstAddress, kABPersonAddressStreetKey);
self.city = (__bridge NSString *)CFDictionaryGetValue(firstAddress, kABPersonAddressCityKey);
self.province = (__bridge NSString *)CFDictionaryGetValue(firstAddress, kABPersonAddressStateKey);
self.zip = (__bridge NSString *)CFDictionaryGetValue(firstAddress, kABPersonAddressZIPKey);
// The Checkout API accepts country OR ISO country code.
// We default to the ISO country code because it's more
// reliable regardless of locale. Fallback to country if
// we do not receive it (iOS 8 sometimes)
self.countryCode = (__bridge NSString *)CFDictionaryGetValue(firstAddress, kABPersonAddressCountryCodeKey);
if ([self.countryCode length] == 0) {
self.country = (__bridge NSString *)CFDictionaryGetValue(firstAddress, kABPersonAddressCountryKey);
}
}
CFSafeRelease(allAddresses);
CFSafeRelease(addressMultiValue);
//Grab the phone number information
ABMultiValueRef phoneMultiValue = ABRecordCopyValue(record, kABPersonPhoneProperty);
CFArrayRef allPhoneNumbers = ABMultiValueCopyArrayOfAllValues(phoneMultiValue);
if (allPhoneNumbers && CFArrayGetCount(allPhoneNumbers) > 0) {
self.phone = (__bridge NSString *)CFArrayGetValueAtIndex(allPhoneNumbers, 0);
}
CFSafeRelease(phoneMultiValue);
CFSafeRelease(allPhoneNumbers);
}
- (void)updateWithContact:(nullable PKContact*)contact
{
self.firstName = contact.name.givenName;
......
......@@ -74,23 +74,12 @@ 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.
if ([payment respondsToSelector:@selector(shippingContact)]) {
self.checkout.email = payment.shippingContact.emailAddress;
if (self.checkout.requiresShipping) {
self.checkout.shippingAddress = [self buyAddressWithContact:payment.shippingContact];
}
} else {
self.checkout.email = [BUYAddress buy_emailFromRecord:payment.shippingAddress];
if (self.checkout.requiresShipping) {
self.checkout.shippingAddress = [self buyAddressWithABRecord:payment.shippingAddress];
}
self.checkout.email = payment.shippingContact.emailAddress;
if (self.checkout.requiresShipping) {
self.checkout.shippingAddress = [self buyAddressWithContact:payment.shippingContact];
}
if ([payment respondsToSelector:@selector(billingContact)]) {
self.checkout.billingAddress = [self buyAddressWithContact:payment.billingContact];
} else {
self.checkout.billingAddress = [self buyAddressWithABRecord:payment.billingAddress];
}
self.checkout.billingAddress = [self buyAddressWithContact:payment.billingContact];
[self.client updateCheckout:self.checkout completion:^(BUYCheckout *checkout, NSError *error) {
if (checkout && error == nil) {
......@@ -118,11 +107,6 @@ const NSTimeInterval PollDelay = 0.5;
}];
}
- (BUYAddress *)buyAddressWithABRecord:(ABRecordRef)addressRecord
{
return [self.client.modelManager buyAddressWithABRecord:addressRecord];
}
- (BUYAddress *)buyAddressWithContact:(PKContact *)contact
{
return [self.client.modelManager buyAddressWithContact:contact];
......@@ -133,12 +117,6 @@ const NSTimeInterval PollDelay = 0.5;
[controller dismissViewControllerAnimated:YES completion:nil];
}
-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingAddress:(ABRecordRef)address completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKShippingMethod *> * _Nonnull, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
{
self.checkout.shippingAddress = [self buyAddressWithABRecord:address];
[self updateCheckoutWithAddressCompletion:completion];
}
-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKShippingMethod *> * _Nonnull, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
{
self.checkout.shippingAddress = [self buyAddressWithContact:contact];
......
......@@ -32,15 +32,6 @@
@interface BUYModelManager (ApplePay)
/**
* Creates a BUYAddress from an ABRecordRef
*
* @param record ABRecordRef to create a BUYAddress from
*
* @return The BUYAddress created from an ABRecordRef
*/
- (BUYAddress *)buyAddressWithABRecord:(ABRecordRef)addressRecord NS_DEPRECATED_IOS(8_0, 9_0, "Use the CNContact backed `buyAddressWithContact:` instead");
/**
* Creates a BUYAddress from a PKContact
*
* @param contact PKContact to create a BUYAddress from
......
......@@ -30,13 +30,6 @@
@implementation BUYModelManager (ApplePay)
- (BUYAddress *)buyAddressWithABRecord:(ABRecordRef)addressRecord
{
BUYAddress *address = [self insertAddressWithJSONDictionary:nil];
[address updateWithRecord:addressRecord];
return address;
}
- (BUYAddress *)buyAddressWithContact:(PKContact *)contact
{
BUYAddress *address = [self insertAddressWithJSONDictionary:nil];
......
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