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

Support accessibility label #140

Merged
merged 4 commits into from
Mar 25, 2024
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: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build:
runs-on: macos-10.15
runs-on: macos-latest
steps:
- name: Checkout project
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ui-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build:
runs-on: macos-10.15
runs-on: macos-latest
steps:
- name: Checkout project
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Podfile.lock
## Build generated
build/
DerivedData/
/.build

## Various settings
*.pbxuser
Expand Down
50 changes: 45 additions & 5 deletions AffirmSDK/AffirmDataHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

NS_ASSUME_NONNULL_BEGIN

typedef void (^AffirmDataHandlerCompletionHandler)(NSAttributedString * _Nullable attributedString, UIViewController * _Nullable viewController, NSError * _Nullable error);

typedef void (^AffirmDataHandlerCompletionWithHtmlHandler)(NSAttributedString * _Nullable attributedString, NSString * _Nullable html, UIViewController * _Nullable viewController, NSError * _Nullable error);

typedef void (^AffirmDataHandlerCompletionWithAccessibilityHandler)(NSAttributedString * _Nullable attributedString, NSString * _Nullable html, NSString * _Nullable accessibilityLabel, UIViewController * _Nullable viewController, NSError * _Nullable error);

@interface AffirmDataHandler : NSObject

/**
Expand All @@ -38,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
font:(UIFont *)font
textColor:(UIColor *)textColor
delegate:(id<AffirmPrequalDelegate>)delegate
completionHandler:(void (^)(NSAttributedString * _Nullable , UIViewController * _Nullable, NSError * _Nullable))completionHandler
completionHandler:(AffirmDataHandlerCompletionHandler)completionHandler
NS_SWIFT_NAME(getPromoMessage(promoID:amount:showCTA:pageType:logoType:colorType:font:textColor:presentingViewController:completionHandler:));

/**
Expand Down Expand Up @@ -66,7 +72,7 @@ NS_SWIFT_NAME(getPromoMessage(promoID:amount:showCTA:pageType:logoType:colorType
textColor:(UIColor *)textColor
presentingViewController:(id<AffirmPrequalDelegate>)delegate
withNavigation:(BOOL)withNavigation
completionHandler:(void (^)(NSAttributedString * _Nullable , UIViewController * _Nullable, NSError * _Nullable))completionHandler
completionHandler:(AffirmDataHandlerCompletionHandler)completionHandler
NS_SWIFT_NAME(getPromoMessage(promoID:amount:showCTA:pageType:logoType:colorType:font:textColor:presentingViewController:withNavigation:completionHandler:));

/**
Expand Down Expand Up @@ -96,12 +102,12 @@ NS_SWIFT_NAME(getPromoMessage(promoID:amount:showCTA:pageType:logoType:colorType
presentingViewController:(id<AffirmPrequalDelegate>)delegate
withNavigation:(BOOL)withNavigation
withHtmlValue:(BOOL)withHtmlValue
completionHandler:(void (^)(NSAttributedString * _Nullable, NSString * _Nullable, UIViewController * _Nullable, NSError * _Nullable))completionHandler
completionHandler:(AffirmDataHandlerCompletionWithHtmlHandler)completionHandler
NS_SWIFT_NAME(getPromoMessage(promoID:amount:showCTA:pageType:logoType:colorType:font:textColor:presentingViewController:withNavigation:withHtmlValue:completionHandler:));

/**
Get the contents of an Affirm as low as object which describes the merchant and the item.

@param promoID Promo ID to use when getting terms (provided by Affirm)
@param amount Amount of the transaction
@param items Items data
Expand All @@ -128,9 +134,43 @@ NS_SWIFT_NAME(getPromoMessage(promoID:amount:showCTA:pageType:logoType:colorType
presentingViewController:(id<AffirmPrequalDelegate>)delegate
withNavigation:(BOOL)withNavigation
withHtmlValue:(BOOL)withHtmlValue
completionHandler:(void (^)(NSAttributedString * _Nullable, NSString * _Nullable, UIViewController * _Nullable, NSError * _Nullable))completionHandler
completionHandler:(AffirmDataHandlerCompletionWithHtmlHandler)completionHandler
NS_SWIFT_NAME(getPromoMessage(promoID:amount:items:showCTA:pageType:logoType:colorType:font:textColor:presentingViewController:withNavigation:withHtmlValue:completionHandler:));

/**
Get the contents of an Affirm as low as object which describes the merchant and the item.

@param promoID Promo ID to use when getting terms (provided by Affirm)
@param amount Amount of the transaction
@param items Items data
@param showCTA A boolean to use when getting terms
@param pageType type of Affirm page to display
@param logoType type of Affirm logo to display (text, name, symbol)
@param colorType color of Affirm to display (blue, black, white) - only applies to logo and symbol affirmType values
@param font the font of button title, maxFontSize will be set as same value
@param textColor the color of button title
@param delegate custom implementation of AffirmPrequalDelegate
@param withNavigation whether to return UINavigationController including promo modal
@param withHtmlValue whether to return html raw string
@param withAccessibility whether to return accessibility string
@param completionHandler the completion handler
*/
+ (void)getPromoMessageWithPromoID:(nullable NSString *)promoID
amount:(NSDecimalNumber *)amount
items:(nullable NSArray <AffirmItem *>*)items
showCTA:(BOOL)showCTA
pageType:(AffirmPageType)pageType
logoType:(AffirmLogoType)logoType
colorType:(AffirmColorType)colorType
font:(UIFont *)font
textColor:(UIColor *)textColor
presentingViewController:(id<AffirmPrequalDelegate>)delegate
withNavigation:(BOOL)withNavigation
withHtmlValue:(BOOL)withHtmlValue
withAccessibility:(BOOL)withAccessibility
completionHandler:(AffirmDataHandlerCompletionWithAccessibilityHandler)completionHandler
NS_SWIFT_NAME(getPromoMessage(promoID:amount:items:showCTA:pageType:logoType:colorType:font:textColor:presentingViewController:withNavigation:withHtmlValue:withAccessibility:completionHandler:));

@end

NS_ASSUME_NONNULL_END
125 changes: 80 additions & 45 deletions AffirmSDK/AffirmDataHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ + (void)getPromoMessageWithPromoID:(nullable NSString *)promoID
font:(UIFont *)font
textColor:(UIColor *)textColor
delegate:(id<AffirmPrequalDelegate>)delegate
completionHandler:(void (^)(NSAttributedString * _Nullable , UIViewController * _Nullable, NSError * _Nullable))completionHandler
completionHandler:(AffirmDataHandlerCompletionHandler)completionHandler
{
[self getPromoMessageWithPromoID:promoID
amount:amount
Expand All @@ -49,7 +49,7 @@ + (void)getPromoMessageWithPromoID:(nullable NSString *)promoID
textColor:(UIColor *)textColor
presentingViewController:(id<AffirmPrequalDelegate>)delegate
withNavigation:(BOOL)withNavigation
completionHandler:(void (^)(NSAttributedString * _Nullable , UIViewController * _Nullable, NSError * _Nullable))completionHandler
completionHandler:(AffirmDataHandlerCompletionHandler)completionHandler
{
[self getPromoMessageWithPromoID:promoID
amount:amount
Expand Down Expand Up @@ -78,7 +78,7 @@ + (void)getPromoMessageWithPromoID:(nullable NSString *)promoID
presentingViewController:(id<AffirmPrequalDelegate>)delegate
withNavigation:(BOOL)withNavigation
withHtmlValue:(BOOL)withHtmlValue
completionHandler:(void (^)(NSAttributedString * _Nullable, NSString * _Nullable, UIViewController * _Nullable, NSError * _Nullable))completionHandler
completionHandler:(AffirmDataHandlerCompletionWithHtmlHandler)completionHandler
{
[self getPromoMessageWithPromoID:promoID
amount:amount
Expand Down Expand Up @@ -109,21 +109,54 @@ + (void)getPromoMessageWithPromoID:(nullable NSString *)promoID
presentingViewController:(id<AffirmPrequalDelegate>)delegate
withNavigation:(BOOL)withNavigation
withHtmlValue:(BOOL)withHtmlValue
completionHandler:(void (^)(NSAttributedString * _Nullable, NSString * _Nullable, UIViewController * _Nullable, NSError * _Nullable))completionHandler
completionHandler:(AffirmDataHandlerCompletionWithHtmlHandler)completionHandler
{
[self getPromoMessageWithPromoID:promoID
amount:amount
items:items
showCTA:showCTA
pageType:pageType
logoType:logoType
colorType:colorType
font:font
textColor:textColor
presentingViewController:delegate
withNavigation:withNavigation
withHtmlValue:withHtmlValue
withAccessibility:NO
completionHandler:^(NSAttributedString *attributedString, NSString *html, NSString *accessibilityLabel, UIViewController *viewController, NSError *error) {
completionHandler(attributedString, html, viewController, error);
}];
}

+ (void)getPromoMessageWithPromoID:(nullable NSString *)promoID
amount:(NSDecimalNumber *)amount
items:(nullable NSArray <AffirmItem *>*)items
showCTA:(BOOL)showCTA
pageType:(AffirmPageType)pageType
logoType:(AffirmLogoType)logoType
colorType:(AffirmColorType)colorType
font:(UIFont *)font
textColor:(UIColor *)textColor
presentingViewController:(id<AffirmPrequalDelegate>)delegate
withNavigation:(BOOL)withNavigation
withHtmlValue:(BOOL)withHtmlValue
withAccessibility:(BOOL)withAccessibility
completionHandler:(AffirmDataHandlerCompletionWithAccessibilityHandler)completionHandler;
{
[AffirmValidationUtils checkNotNil:amount name:@"amount"];

if (amount.doubleValue > [NSDecimalNumber decimalNumberWithString:AFFIRM_MAX_PROMO_AMOUNT].doubleValue) {
completionHandler(nil, nil, nil, nil);
completionHandler(nil, nil, nil, nil, nil);
return;
}

AffirmColorType logoColor = colorType;
// Using default type when logoColor == AffirmColorTypeBlueBlack
if (logoColor == AffirmColorTypeBlueBlack) {
logoColor = AffirmColorTypeDefault;
}

AffirmPromoRequest *request = [[AffirmPromoRequest alloc] initWithPublicKey:[AffirmConfiguration sharedInstance].publicKey
promoId:promoID
amount:amount
Expand All @@ -135,46 +168,48 @@ + (void)getPromoMessageWithPromoID:(nullable NSString *)promoID
[AffirmPromoClient send:request handler:^(AffirmResponse * _Nullable response, NSError * _Nullable error) {
NSAttributedString *attributedString = nil;
NSString *htmlValue = nil;
NSString *accessibilityLabel = nil;
UIViewController *viewController = nil;
if (response && [response isKindOfClass:[AffirmPromoResponse class]]) {
AffirmPromoResponse *promoResponse = (AffirmPromoResponse *)response;
htmlValue = withHtmlValue ? promoResponse.htmlAla : nil;

NSString *template = nil;
if (promoResponse.ala != nil && promoResponse.ala.length > 0) {
template = promoResponse.ala;
AffirmPromoResponse *promoResponse = (AffirmPromoResponse *)response;
htmlValue = withHtmlValue ? promoResponse.htmlAla : nil;

NSString *template = nil;
if (promoResponse.ala != nil && promoResponse.ala.length > 0) {
template = promoResponse.ala;
accessibilityLabel = withAccessibility ? [promoResponse.ala stringByReplacingOccurrencesOfString:@"{Affirm}" withString:@"Affirm"] : nil;
}
if (template) {
UIImage *logo = nil;
if (logoType != AffirmLogoTypeText) {
logo = [AffirmPromotionalButton getAffirmDisplayForLogoType:logoType colorType:colorType];
}
if (template) {
UIImage *logo = nil;
if (logoType != AffirmLogoTypeText) {
logo = [AffirmPromotionalButton getAffirmDisplayForLogoType:logoType colorType:colorType];
}
attributedString = [AffirmPromotionalButton appendLogo:logo toText:template font:font textColor:textColor logoType:logoType];
attributedString = [AffirmPromotionalButton appendLogo:logo toText:template font:font textColor:textColor logoType:logoType];
}

if (promoResponse.showPrequal) {
NSMutableDictionary *params = [@{
@"public_api_key": [AffirmConfiguration sharedInstance].publicKey,
@"unit_price": [amount toIntegerCents],
@"use_promo": @"true",
@"referring_url": AFFIRM_PREQUAL_REFERRING_URL,
} mutableCopy];
if (promoID) {
params[@"promo_external_id"] = promoID;
}

if (promoResponse.showPrequal) {
NSMutableDictionary *params = [@{
@"public_api_key": [AffirmConfiguration sharedInstance].publicKey,
@"unit_price": [amount toIntegerCents],
@"use_promo": @"true",
@"referring_url": AFFIRM_PREQUAL_REFERRING_URL,
} mutableCopy];
if (promoID) {
params[@"promo_external_id"] = promoID;
}
if (pageType) {
params[@"page_type"] = FormatAffirmPageTypeString(pageType);
}

NSString *url = [NSString stringWithFormat:@"%@/apps/prequal/", [AffirmPromoClient host]];
NSURL *requestURL = [NSURL URLWithString:[NSString stringWithFormat:@"?%@", [params queryURLEncoding]]
relativeToURL:[NSURL URLWithString:url]];
viewController = [[AffirmPrequalModalViewController alloc] initWithURL:requestURL delegate:delegate];
} else {
viewController = [[AffirmPromoModalViewController alloc] initWithPromoId:promoID
amount:amount
pageType:pageType
delegate:delegate];
if (pageType) {
params[@"page_type"] = FormatAffirmPageTypeString(pageType);
}

NSString *url = [NSString stringWithFormat:@"%@/apps/prequal/", [AffirmPromoClient host]];
NSURL *requestURL = [NSURL URLWithString:[NSString stringWithFormat:@"?%@", [params queryURLEncoding]]
relativeToURL:[NSURL URLWithString:url]];
viewController = [[AffirmPrequalModalViewController alloc] initWithURL:requestURL delegate:delegate];
} else {
viewController = [[AffirmPromoModalViewController alloc] initWithPromoId:promoID
amount:amount
pageType:pageType
delegate:delegate];
}
}
NSError *_error;
Expand All @@ -184,9 +219,9 @@ + (void)getPromoMessageWithPromoID:(nullable NSString *)promoID
}
if (viewController && withNavigation) {
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
completionHandler(attributedString, htmlValue, navigationController, error ?: _error);
completionHandler(attributedString, htmlValue, accessibilityLabel, navigationController, error ?: _error);
} else {
completionHandler(attributedString, htmlValue, viewController, error ?: _error);
completionHandler(attributedString, htmlValue, accessibilityLabel, viewController, error ?: _error);
}
}];
}
Expand Down
5 changes: 5 additions & 0 deletions AffirmSDK/AffirmPromotionalButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ - (void)awakeFromNib

- (void)setup
{
self.isAccessibilityElement = YES;
self.showPrequal = YES;
self.clickable = NO;
[self configureWebView];
Expand Down Expand Up @@ -302,6 +303,9 @@ - (void)configureByHtmlStylingWithAmount:(NSDecimalNumber *)amount
if (response && [response isKindOfClass:[AffirmPromoResponse class]]) {
AffirmPromoResponse *promoResponse = (AffirmPromoResponse *)response;
self.showPrequal = promoResponse.showPrequal;
if (promoResponse.ala != nil && promoResponse.ala.length > 0) {
self.accessibilityLabel = [promoResponse.ala stringByReplacingOccurrencesOfString:@"{Affirm}" withString:@"Affirm"];
}
if (promoResponse.htmlAla != nil && promoResponse.htmlAla.length > 0) {
[self configureWithHtmlString:promoResponse.htmlAla amount:amount remoteFontURL:remoteFontURL remoteCssURL:remoteCssURL];
return;
Expand Down Expand Up @@ -373,6 +377,7 @@ - (void)configureWithAmount:(NSDecimalNumber *)amount
AffirmPromoResponse *promoResponse = (AffirmPromoResponse *)response;
if (promoResponse.ala != nil && promoResponse.ala.length > 0) {
template = promoResponse.ala;
self.accessibilityLabel = [promoResponse.ala stringByReplacingOccurrencesOfString:@"{Affirm}" withString:@"Affirm"];
}
self.showPrequal = promoResponse.showPrequal;
UIImage *logo = nil;
Expand Down
Loading
Loading