Skip to content

Commit

Permalink
Updates based on feedback, add UI Test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidme-stripe committed Aug 30, 2019
1 parent 6536fbb commit ec2a531
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 6 deletions.
26 changes: 26 additions & 0 deletions LocalizationTester/ViewController.m
Expand Up @@ -24,6 +24,7 @@ typedef NS_ENUM(NSInteger, LocalizedScreen) {
LocalizedScreenPaymentOptionsVCLoading,
LocalizedScreenShippingAddressVC,
LocalizedScreenShippingAddressVCBadAddress,
LocalizedScreenShippingAddressVCCountryOutsideAvailable,
LocalizedScreenShippingAddressVCDelivery,
LocalizedScreenShippingAddressVCContact,
};
Expand All @@ -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:
Expand Down Expand Up @@ -74,6 +77,7 @@ - (void)viewDidLoad {
@(LocalizedScreenPaymentOptionsVCLoading),
@(LocalizedScreenShippingAddressVC),
@(LocalizedScreenShippingAddressVCBadAddress),
@(LocalizedScreenShippingAddressVCCountryOutsideAvailable),
@(LocalizedScreenShippingAddressVCDelivery),
@(LocalizedScreenShippingAddressVCContact),
];
Expand Down Expand Up @@ -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];
Expand Down
10 changes: 10 additions & 0 deletions LocalizationTesterUITests/LocalizationTesterUITests.m
Expand Up @@ -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"]];
Expand Down
6 changes: 3 additions & 3 deletions Stripe/PublicHeaders/STPPaymentConfiguration.h
Expand Up @@ -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<NSString *> *availableCountries;
@property (nonatomic, copy, null_resettable, readwrite) NSSet<NSString *> *availableCountries;

/**
The name of your company, for displaying to the user during payment flows. For
Expand Down
2 changes: 1 addition & 1 deletion Stripe/STPAddCardViewController.m
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions Stripe/STPAddressViewModel.h
Expand Up @@ -30,6 +30,8 @@

- (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredBillingAddressFields;
- (instancetype)initWithRequiredShippingFields:(NSSet<STPContactField> *)requiredShippingAddressFields;

/* The default value of availableCountries is nil, which will allow all known countries. */
- (instancetype)initWithRequiredBillingFields:(STPBillingAddressFields)requiredBillingAddressFields availableCountries:(NSSet<NSString *> *)availableCountries;
- (instancetype)initWithRequiredShippingFields:(NSSet<STPContactField> *)requiredShippingAddressFields availableCountries:(NSSet<NSString *> *)availableCountries;
- (STPAddressFieldTableViewCell *)cellAtIndex:(NSInteger)index;
Expand Down
1 change: 1 addition & 0 deletions Stripe/STPPaymentConfiguration+Private.h
Expand Up @@ -11,6 +11,7 @@
@interface STPPaymentConfiguration ()

@property (nonatomic, assign, readonly) BOOL applePayEnabled;
@property (nonatomic, assign, readonly) NSSet<NSString *> *_availableCountries;

@end

14 changes: 13 additions & 1 deletion Stripe/STPPaymentConfiguration.m
Expand Up @@ -56,6 +56,18 @@ - (BOOL)applePayEnabled {
[Stripe deviceSupportsApplePay];
}

- (NSSet<NSString *> *)availableCountries {
if (_availableCountries == nil) {
return [NSSet setWithArray:[NSLocale ISOCountryCodes]];
} else {
return _availableCountries;
}
}

- (NSSet<NSString *> *)_availableCountries {
return _availableCountries;
}

#pragma mark - Description

- (NSString *)description {
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion Stripe/STPShippingAddressViewController.m
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ec2a531

Please sign in to comment.