From beb67ed8d2472536e28729eef1690d0b01b1e4f7 Mon Sep 17 00:00:00 2001 From: David Estes Date: Wed, 28 Aug 2019 17:09:05 -0700 Subject: [PATCH 1/3] Add an option to STPPaymentConfiguration to filter the country list --- .../PublicHeaders/STPPaymentConfiguration.h | 9 ++++++ Stripe/STPAddCardViewController.m | 2 +- Stripe/STPAddressFieldTableViewCell.h | 1 + Stripe/STPAddressFieldTableViewCell.m | 18 +++++++++-- Stripe/STPAddressViewModel.h | 3 ++ Stripe/STPAddressViewModel.m | 14 ++++++-- Stripe/STPPaymentConfiguration.m | 2 ++ Stripe/STPShippingAddressViewController.m | 2 +- Tests/Tests/STPPaymentConfigurationTest.m | 3 ++ .../STPShippingAddressViewControllerTest.m | 32 +++++++++++++++++++ 10 files changed, 80 insertions(+), 6 deletions(-) diff --git a/Stripe/PublicHeaders/STPPaymentConfiguration.h b/Stripe/PublicHeaders/STPPaymentConfiguration.h index 23b22b2641a..c44256b7719 100644 --- a/Stripe/PublicHeaders/STPPaymentConfiguration.h +++ b/Stripe/PublicHeaders/STPPaymentConfiguration.h @@ -77,6 +77,15 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, assign, readwrite) STPShippingType shippingType; +/** + The set of countries supported when entering an address. This property accepts + a set of ISO 2-character country codes. + + The default value is nil, which will display all known countries. Setting this + property will limit the available countries to your selected set. + */ +@property (nonatomic, copy, nullable, readwrite) NSSet *availableCountries; + /** The name of your company, for displaying to the user during payment flows. For example, when using Apple Pay, the payment sheet's final line item will read diff --git a/Stripe/STPAddCardViewController.m b/Stripe/STPAddCardViewController.m index 268064f7da4..424867c4950 100644 --- a/Stripe/STPAddCardViewController.m +++ b/Stripe/STPAddCardViewController.m @@ -93,7 +93,7 @@ - (void)commonInitWithConfiguration:(STPPaymentConfiguration *)configuration { _shippingAddress = nil; _hasUsedShippingAddress = NO; _apiClient = [[STPAPIClient alloc] initWithConfiguration:configuration]; - _addressViewModel = [[STPAddressViewModel alloc] initWithRequiredBillingFields:configuration.requiredBillingAddressFields]; + _addressViewModel = [[STPAddressViewModel alloc] initWithRequiredBillingFields:configuration.requiredBillingAddressFields availableCountries:configuration.availableCountries]; _addressViewModel.delegate = self; self.title = STPLocalizedString(@"Add a Card", @"Title for Add a Card view"); diff --git a/Stripe/STPAddressFieldTableViewCell.h b/Stripe/STPAddressFieldTableViewCell.h index 61fd15e69e2..ed632f74abf 100644 --- a/Stripe/STPAddressFieldTableViewCell.h +++ b/Stripe/STPAddressFieldTableViewCell.h @@ -34,6 +34,7 @@ typedef NS_ENUM(NSInteger, STPAddressFieldType) { - (void)addressFieldTableViewCellDidReturn:(STPAddressFieldTableViewCell *)cell; - (void)addressFieldTableViewCellDidEndEditing:(STPAddressFieldTableViewCell *)cell; @property (nonatomic, copy) NSString *addressFieldTableViewCountryCode; +@property (nonatomic, copy) NSSet *availableCountries; @end diff --git a/Stripe/STPAddressFieldTableViewCell.m b/Stripe/STPAddressFieldTableViewCell.m index a8981a96d58..4bf63390332 100644 --- a/Stripe/STPAddressFieldTableViewCell.m +++ b/Stripe/STPAddressFieldTableViewCell.m @@ -69,9 +69,18 @@ - (instancetype)initWithType:(STPAddressFieldType)type _inputAccessoryToolbar = toolbar; NSString *countryCode = [[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleCountryCode]; - NSMutableArray *otherCountryCodes = [[NSLocale ISOCountryCodes] mutableCopy]; + NSMutableArray *otherCountryCodes = [[self.delegate.availableCountries allObjects] mutableCopy]; + if (otherCountryCodes == nil) { + otherCountryCodes = [[NSLocale ISOCountryCodes] mutableCopy]; + } + if ([otherCountryCodes containsObject:countryCode]) { + // Remove the current country code to re-add it once we sort the list. + [otherCountryCodes removeObject:countryCode]; + } else { + // If it isn't in the list (if we've been configured to not show that country), don't re-add it. + countryCode = nil; + } NSLocale *locale = [NSLocale currentLocale]; - [otherCountryCodes removeObject:countryCode]; [otherCountryCodes sortUsingComparator:^NSComparisonResult(NSString *code1, NSString *code2) { NSString *localeID1 = [NSLocale localeIdentifierFromComponents:@{NSLocaleCountryCode: code1}]; NSString *localeID2 = [NSLocale localeIdentifierFromComponents:@{NSLocaleCountryCode: code2}]; @@ -179,6 +188,11 @@ - (void)updateTextFieldsAndCaptions { self.textField.keyboardType = UIKeyboardTypeDefault; // Don't set textContentType for Country, because we don't want iOS to skip the UIPickerView for input self.textField.inputView = self.countryPickerView; + + // If we're being set directly to a country we don't allow, add it to the allowed list + if (![self.countryCodes containsObject:self.contents] && [[NSLocale ISOCountryCodes] containsObject:self.contents]) { + self.countryCodes = [self.countryCodes arrayByAddingObject:self.contents]; + } NSInteger index = [self.countryCodes indexOfObject:self.contents]; if (index == NSNotFound) { self.textField.text = @""; diff --git a/Stripe/STPAddressViewModel.h b/Stripe/STPAddressViewModel.h index f21a7c82d6a..d2e7909818c 100644 --- a/Stripe/STPAddressViewModel.h +++ b/Stripe/STPAddressViewModel.h @@ -25,10 +25,13 @@ @property (nonatomic, readonly) NSArray *addressCells; @property (nonatomic, weak) iddelegate; @property (nonatomic) STPAddress *address; +@property (nonatomic, copy, readwrite) NSSet *availableCountries; @property (nonatomic, readonly) BOOL isValid; - (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredBillingAddressFields; - (instancetype)initWithRequiredShippingFields:(NSSet *)requiredShippingAddressFields; +- (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredBillingAddressFields availableCountries:(NSSet *)availableCountries; +- (instancetype)initWithRequiredShippingFields:(NSSet *)requiredShippingAddressFields availableCountries:(NSSet *)availableCountries; - (STPAddressFieldTableViewCell *)cellAtIndex:(NSInteger)index; @end diff --git a/Stripe/STPAddressViewModel.m b/Stripe/STPAddressViewModel.m index a40d5083ad8..b96f5d24c36 100644 --- a/Stripe/STPAddressViewModel.m +++ b/Stripe/STPAddressViewModel.m @@ -26,11 +26,13 @@ @interface STPAddressViewModel() @implementation STPAddressViewModel @synthesize addressFieldTableViewCountryCode = _addressFieldTableViewCountryCode; +@synthesize availableCountries = _availableCountries; -- (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredBillingAddressFields { +- (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredBillingAddressFields availableCountries:(NSSet *)availableCountries { self = [super init]; if (self) { _isBillingAddress = YES; + _availableCountries = availableCountries; _requiredBillingAddressFields = requiredBillingAddressFields; switch (requiredBillingAddressFields) { case STPBillingAddressFieldsNone: @@ -63,10 +65,11 @@ - (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredB return self; } -- (instancetype)initWithRequiredShippingFields:(NSSet *)requiredShippingAddressFields { +- (instancetype)initWithRequiredShippingFields:(NSSet *)requiredShippingAddressFields availableCountries:(NSSet *)availableCountries { self = [super init]; if (self) { _isBillingAddress = NO; + _availableCountries = availableCountries; _requiredShippingAddressFields = requiredShippingAddressFields; NSMutableArray *cells = [NSMutableArray new]; if ([requiredShippingAddressFields containsObject:STPContactFieldName]) { @@ -103,6 +106,13 @@ - (instancetype)initWithRequiredShippingFields:(NSSet *)require return self; } +- (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredBillingAddressFields { + return [self initWithRequiredBillingFields:requiredBillingAddressFields availableCountries:nil]; +} +- (instancetype)initWithRequiredShippingFields:(NSSet *)requiredShippingAddressFields { + return [self initWithRequiredShippingFields:requiredShippingAddressFields availableCountries:nil]; +} + - (void)commonInit { _addressFieldTableViewCountryCode = [[NSLocale autoupdatingCurrentLocale] objectForKey:NSLocaleCountryCode]; [self updatePostalCodeCellIfNecessary]; diff --git a/Stripe/STPPaymentConfiguration.m b/Stripe/STPPaymentConfiguration.m index c78a1b1d00f..d930afb5287 100644 --- a/Stripe/STPPaymentConfiguration.m +++ b/Stripe/STPPaymentConfiguration.m @@ -120,6 +120,7 @@ - (NSString *)description { [NSString stringWithFormat:@"requiredShippingAddressFields = %@", requiredShippingAddressFieldsDescription], [NSString stringWithFormat:@"verifyPrefilledShippingAddress = %@", (self.verifyPrefilledShippingAddress) ? @"YES" : @"NO"], [NSString stringWithFormat:@"shippingType = %@", shippingTypeDescription], + [NSString stringWithFormat:@"availableCountries = %@", _availableCountries], // Additional configuration [NSString stringWithFormat:@"companyName = %@", self.companyName], @@ -143,6 +144,7 @@ - (id)copyWithZone:(__unused NSZone *)zone { copy.companyName = self.companyName; copy.appleMerchantIdentifier = self.appleMerchantIdentifier; copy.canDeletePaymentOptions = self.canDeletePaymentOptions; + copy.availableCountries = self.availableCountries; return copy; } diff --git a/Stripe/STPShippingAddressViewController.m b/Stripe/STPShippingAddressViewController.m index ff328fe20ff..1e7a9a6cb59 100644 --- a/Stripe/STPShippingAddressViewController.m +++ b/Stripe/STPShippingAddressViewController.m @@ -87,7 +87,7 @@ - (instancetype)initWithConfiguration:(STPPaymentConfiguration *)configuration _selectedShippingMethod = selectedShippingMethod; _billingAddress = prefilledInformation.billingAddress; _hasUsedBillingAddress = NO; - _addressViewModel = [[STPAddressViewModel alloc] initWithRequiredShippingFields:configuration.requiredShippingAddressFields]; + _addressViewModel = [[STPAddressViewModel alloc] initWithRequiredShippingFields:configuration.requiredShippingAddressFields availableCountries:configuration.availableCountries]; _addressViewModel.delegate = self; if (shippingAddress != nil) { _addressViewModel.address = shippingAddress; diff --git a/Tests/Tests/STPPaymentConfigurationTest.m b/Tests/Tests/STPPaymentConfigurationTest.m index d1dddab4e5e..0ffb6e24059 100644 --- a/Tests/Tests/STPPaymentConfigurationTest.m +++ b/Tests/Tests/STPPaymentConfigurationTest.m @@ -107,6 +107,7 @@ - (void)testCopyWithZone { paymentConfigurationA.requiredBillingAddressFields = STPBillingAddressFieldsFull; paymentConfigurationA.requiredShippingAddressFields = allFields; paymentConfigurationA.verifyPrefilledShippingAddress = NO; + paymentConfigurationA.availableCountries = [NSSet setWithArray:@[@"US", @"CA", @"BT"]]; paymentConfigurationA.shippingType = STPShippingTypeDelivery; paymentConfigurationA.companyName = @"companyName"; paymentConfigurationA.appleMerchantIdentifier = @"appleMerchantIdentifier"; @@ -123,6 +124,8 @@ - (void)testCopyWithZone { XCTAssertEqual(paymentConfigurationB.shippingType, STPShippingTypeDelivery); XCTAssertEqualObjects(paymentConfigurationB.companyName, @"companyName"); XCTAssertEqualObjects(paymentConfigurationB.appleMerchantIdentifier, @"appleMerchantIdentifier"); + NSSet *availableCountries = [NSSet setWithArray:@[@"US", @"CA", @"BT"]]; + XCTAssertEqualObjects(paymentConfigurationB.availableCountries, availableCountries); XCTAssertEqual(paymentConfigurationA.canDeletePaymentOptions, paymentConfigurationB.canDeletePaymentOptions); } diff --git a/Tests/Tests/STPShippingAddressViewControllerTest.m b/Tests/Tests/STPShippingAddressViewControllerTest.m index f2fbacb9357..258cbadd87d 100644 --- a/Tests/Tests/STPShippingAddressViewControllerTest.m +++ b/Tests/Tests/STPShippingAddressViewControllerTest.m @@ -46,6 +46,38 @@ - (void)testPrefilledBillingAddress_removeAddress { XCTAssertNoThrow([sut viewDidLoad]); } +- (void)testPrefilledBillingAddress_addAddressWithLimitedCountries { + [NSLocale stp_setCurrentLocale:[NSLocale localeWithLocaleIdentifier:@"en_ZW"]]; + // Zimbabwe does not require zip codes, while the default locale for tests (US) does + // Sanity checks + XCTAssertFalse([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"ZW"]); + XCTAssertTrue([STPPostalCodeValidator postalCodeIsRequiredForCountryCode:@"US"]); + STPPaymentConfiguration *config = [STPFixtures paymentConfiguration]; + config.requiredShippingAddressFields = [NSSet setWithObject:STPContactFieldPostalAddress]; + config.availableCountries = [[NSSet alloc] initWithArray:@[@"CA", @"BT"]]; + + STPAddress *address = [STPAddress new]; + address.name = @"John Smith Doe"; + address.phone = @"8885551212"; + address.email = @"foo@example.com"; + address.line1 = @"55 John St"; + address.city = @"New York"; + address.state = @"NY"; + address.postalCode = @"10002"; + address.country = @"US"; + + STPShippingAddressViewController *sut = [[STPShippingAddressViewController alloc] initWithConfiguration:config + theme:[STPTheme defaultTheme] + currency:nil + shippingAddress:address + selectedShippingMethod:nil + prefilledInformation:nil]; + + XCTAssertNoThrow([sut loadView]); + XCTAssertNoThrow([sut viewDidLoad]); + [NSLocale stp_resetCurrentLocale]; +} + - (void)testPrefilledBillingAddress_addAddress { [NSLocale stp_setCurrentLocale:[NSLocale localeWithLocaleIdentifier:@"en_ZW"]]; // Zimbabwe does not require zip codes, while the default locale for tests (US) does From 6536fbb45b695af569d6708363b2cbfd42a5d1b6 Mon Sep 17 00:00:00 2001 From: davidme-stripe <52758633+davidme-stripe@users.noreply.github.com> Date: Thu, 29 Aug 2019 10:51:56 -0700 Subject: [PATCH 2/3] Apply suggestions from code review Co-Authored-By: Yuki --- Stripe/STPAddressViewModel.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Stripe/STPAddressViewModel.m b/Stripe/STPAddressViewModel.m index b96f5d24c36..ed239ba7a34 100644 --- a/Stripe/STPAddressViewModel.m +++ b/Stripe/STPAddressViewModel.m @@ -32,7 +32,7 @@ - (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredB self = [super init]; if (self) { _isBillingAddress = YES; - _availableCountries = availableCountries; + _availableCountries = [availableCountries copy]; _requiredBillingAddressFields = requiredBillingAddressFields; switch (requiredBillingAddressFields) { case STPBillingAddressFieldsNone: @@ -69,7 +69,7 @@ - (instancetype)initWithRequiredShippingFields:(NSSet *)require self = [super init]; if (self) { _isBillingAddress = NO; - _availableCountries = availableCountries; + _availableCountries = [availableCountries copy]; _requiredShippingAddressFields = requiredShippingAddressFields; NSMutableArray *cells = [NSMutableArray new]; if ([requiredShippingAddressFields containsObject:STPContactFieldName]) { From ec2a5313b2eed65d7e3f1046950a4f081bd937fb Mon Sep 17 00:00:00 2001 From: David Estes Date: Fri, 30 Aug 2019 16:30:09 -0700 Subject: [PATCH 3/3] Updates based on feedback, add UI Test --- LocalizationTester/ViewController.m | 26 +++++++++++++++++++ .../LocalizationTesterUITests.m | 10 +++++++ .../PublicHeaders/STPPaymentConfiguration.h | 6 ++--- Stripe/STPAddCardViewController.m | 2 +- Stripe/STPAddressViewModel.h | 2 ++ Stripe/STPPaymentConfiguration+Private.h | 1 + Stripe/STPPaymentConfiguration.m | 14 +++++++++- Stripe/STPShippingAddressViewController.m | 3 ++- 8 files changed, 58 insertions(+), 6 deletions(-) diff --git a/LocalizationTester/ViewController.m b/LocalizationTester/ViewController.m index b2e21382e6a..dfe18ed411f 100644 --- a/LocalizationTester/ViewController.m +++ b/LocalizationTester/ViewController.m @@ -24,6 +24,7 @@ typedef NS_ENUM(NSInteger, LocalizedScreen) { LocalizedScreenPaymentOptionsVCLoading, LocalizedScreenShippingAddressVC, LocalizedScreenShippingAddressVCBadAddress, + LocalizedScreenShippingAddressVCCountryOutsideAvailable, LocalizedScreenShippingAddressVCDelivery, LocalizedScreenShippingAddressVCContact, }; @@ -46,6 +47,8 @@ typedef NS_ENUM(NSInteger, LocalizedScreen) { return @"Shipping Address VC"; case LocalizedScreenShippingAddressVCBadAddress: return @"Shipping Address VC Bad Address"; + case LocalizedScreenShippingAddressVCCountryOutsideAvailable: + return @"Shipping Address VC Country Outside Available"; case LocalizedScreenShippingAddressVCDelivery: return @"Shipping Address VC for Delivery"; case LocalizedScreenShippingAddressVCContact: @@ -74,6 +77,7 @@ - (void)viewDidLoad { @(LocalizedScreenPaymentOptionsVCLoading), @(LocalizedScreenShippingAddressVC), @(LocalizedScreenShippingAddressVCBadAddress), + @(LocalizedScreenShippingAddressVCCountryOutsideAvailable), @(LocalizedScreenShippingAddressVCDelivery), @(LocalizedScreenShippingAddressVCContact), ]; @@ -269,6 +273,28 @@ - (void)tableView:(__unused UITableView *)tableView didSelectRowAtIndexPath:(__u } break; + case LocalizedScreenShippingAddressVCCountryOutsideAvailable: + { + STPPaymentConfiguration *configuration = [[STPPaymentConfiguration alloc] init]; + configuration.requiredShippingAddressFields = [NSSet setWithObjects:STPContactFieldPostalAddress, STPContactFieldEmailAddress, STPContactFieldPhoneNumber, STPContactFieldName, nil]; + configuration.availableCountries = [NSSet setWithArray:@[@"BT"]]; + STPUserInformation *prefilledInfo = [[STPUserInformation alloc] init]; + STPAddress *billingAddress = [[STPAddress alloc] init]; + billingAddress.name = @"Test"; + billingAddress.country = @"GB"; + prefilledInfo.billingAddress = billingAddress; + + STPShippingAddressViewController *shippingAddressVC = [[STPShippingAddressViewController alloc] initWithConfiguration:configuration + theme:[STPTheme defaultTheme] + currency:@"usd" + shippingAddress:nil + selectedShippingMethod:nil + prefilledInformation:prefilledInfo]; + shippingAddressVC.delegate = self; + vc = shippingAddressVC; + } + break; + case LocalizedScreenShippingAddressVCDelivery: { STPPaymentConfiguration *configuration = [[STPPaymentConfiguration alloc] init]; diff --git a/LocalizationTesterUITests/LocalizationTesterUITests.m b/LocalizationTesterUITests/LocalizationTesterUITests.m index 7bd3440efb7..b76e6a4067d 100644 --- a/LocalizationTesterUITests/LocalizationTesterUITests.m +++ b/LocalizationTesterUITests/LocalizationTesterUITests.m @@ -111,6 +111,16 @@ - (void)testVisitAll { [[errorAlert.buttons elementBoundByIndex:0] tap]; // dismiss alert [app.navigationBars.buttons[@"CoreViewControllerCancelIdentifier"] tap]; +#pragma mark - Visit the Shipping Address VC Country Outside Available Countries + [tablesQuery.staticTexts[@"Shipping Address VC Country Outside Available"] tap]; + [self _waitForElementToAppear:app.navigationBars.buttons[@"ShippingViewControllerNextButtonIdentifier"]]; + + // Fill out the shipping Info + [tablesQuery.buttons[@"ShippingAddressViewControllerUseBillingButton"] tap]; + [self _takeScreenShotNamed:@"Shipping Address VC Country Outside Available"]; + + [app.navigationBars.buttons[@"CoreViewControllerCancelIdentifier"] tap]; + #pragma mark - Visit the Shipping Info VC for Delivery [tablesQuery.staticTexts[@"Shipping Address VC for Delivery"] tap]; [self _waitForElementToAppear:app.navigationBars.buttons[@"ShippingViewControllerNextButtonIdentifier"]]; diff --git a/Stripe/PublicHeaders/STPPaymentConfiguration.h b/Stripe/PublicHeaders/STPPaymentConfiguration.h index c44256b7719..cb4a8498705 100644 --- a/Stripe/PublicHeaders/STPPaymentConfiguration.h +++ b/Stripe/PublicHeaders/STPPaymentConfiguration.h @@ -81,10 +81,10 @@ NS_ASSUME_NONNULL_BEGIN The set of countries supported when entering an address. This property accepts a set of ISO 2-character country codes. - The default value is nil, which will display all known countries. Setting this - property will limit the available countries to your selected set. + The default value is all known countries. Setting this property will limit + the available countries to your selected set. */ -@property (nonatomic, copy, nullable, readwrite) NSSet *availableCountries; +@property (nonatomic, copy, null_resettable, readwrite) NSSet *availableCountries; /** The name of your company, for displaying to the user during payment flows. For diff --git a/Stripe/STPAddCardViewController.m b/Stripe/STPAddCardViewController.m index 424867c4950..a700b862b84 100644 --- a/Stripe/STPAddCardViewController.m +++ b/Stripe/STPAddCardViewController.m @@ -93,7 +93,7 @@ - (void)commonInitWithConfiguration:(STPPaymentConfiguration *)configuration { _shippingAddress = nil; _hasUsedShippingAddress = NO; _apiClient = [[STPAPIClient alloc] initWithConfiguration:configuration]; - _addressViewModel = [[STPAddressViewModel alloc] initWithRequiredBillingFields:configuration.requiredBillingAddressFields availableCountries:configuration.availableCountries]; + _addressViewModel = [[STPAddressViewModel alloc] initWithRequiredBillingFields:configuration.requiredBillingAddressFields availableCountries:configuration._availableCountries]; _addressViewModel.delegate = self; self.title = STPLocalizedString(@"Add a Card", @"Title for Add a Card view"); diff --git a/Stripe/STPAddressViewModel.h b/Stripe/STPAddressViewModel.h index d2e7909818c..7799d8c4eb9 100644 --- a/Stripe/STPAddressViewModel.h +++ b/Stripe/STPAddressViewModel.h @@ -30,6 +30,8 @@ - (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredBillingAddressFields; - (instancetype)initWithRequiredShippingFields:(NSSet *)requiredShippingAddressFields; + +/* The default value of availableCountries is nil, which will allow all known countries. */ - (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredBillingAddressFields availableCountries:(NSSet *)availableCountries; - (instancetype)initWithRequiredShippingFields:(NSSet *)requiredShippingAddressFields availableCountries:(NSSet *)availableCountries; - (STPAddressFieldTableViewCell *)cellAtIndex:(NSInteger)index; diff --git a/Stripe/STPPaymentConfiguration+Private.h b/Stripe/STPPaymentConfiguration+Private.h index ddeb7e1fd1a..d2c50a86bee 100644 --- a/Stripe/STPPaymentConfiguration+Private.h +++ b/Stripe/STPPaymentConfiguration+Private.h @@ -11,6 +11,7 @@ @interface STPPaymentConfiguration () @property (nonatomic, assign, readonly) BOOL applePayEnabled; +@property (nonatomic, assign, readonly) NSSet *_availableCountries; @end diff --git a/Stripe/STPPaymentConfiguration.m b/Stripe/STPPaymentConfiguration.m index d930afb5287..2ea0544e91a 100644 --- a/Stripe/STPPaymentConfiguration.m +++ b/Stripe/STPPaymentConfiguration.m @@ -56,6 +56,18 @@ - (BOOL)applePayEnabled { [Stripe deviceSupportsApplePay]; } +- (NSSet *)availableCountries { + if (_availableCountries == nil) { + return [NSSet setWithArray:[NSLocale ISOCountryCodes]]; + } else { + return _availableCountries; + } +} + +- (NSSet *)_availableCountries { + return _availableCountries; +} + #pragma mark - Description - (NSString *)description { @@ -144,7 +156,7 @@ - (id)copyWithZone:(__unused NSZone *)zone { copy.companyName = self.companyName; copy.appleMerchantIdentifier = self.appleMerchantIdentifier; copy.canDeletePaymentOptions = self.canDeletePaymentOptions; - copy.availableCountries = self.availableCountries; + copy.availableCountries = _availableCountries; return copy; } diff --git a/Stripe/STPShippingAddressViewController.m b/Stripe/STPShippingAddressViewController.m index 1e7a9a6cb59..f3289b28e07 100644 --- a/Stripe/STPShippingAddressViewController.m +++ b/Stripe/STPShippingAddressViewController.m @@ -16,6 +16,7 @@ #import "STPImageLibrary+Private.h" #import "STPLocalizationUtils.h" #import "STPPaymentActivityIndicatorView.h" +#import "STPPaymentConfiguration+Private.h" #import "STPPaymentContext+Private.h" #import "STPSectionHeaderView.h" #import "STPShippingMethodsViewController.h" @@ -87,7 +88,7 @@ - (instancetype)initWithConfiguration:(STPPaymentConfiguration *)configuration _selectedShippingMethod = selectedShippingMethod; _billingAddress = prefilledInformation.billingAddress; _hasUsedBillingAddress = NO; - _addressViewModel = [[STPAddressViewModel alloc] initWithRequiredShippingFields:configuration.requiredShippingAddressFields availableCountries:configuration.availableCountries]; + _addressViewModel = [[STPAddressViewModel alloc] initWithRequiredShippingFields:configuration.requiredShippingAddressFields availableCountries:configuration._availableCountries]; _addressViewModel.delegate = self; if (shippingAddress != nil) { _addressViewModel.address = shippingAddress;