Commit 79b3edf4 by Jonathan Baker

Add generics and nullability BUYApplePayAdditions.

parent 0dff9eba
......@@ -37,7 +37,7 @@
* Returns an array of summary items for all Apple Pay requests. Will use 'PAY TOTAL' as the summary label. Apple recommends
* including the business name in the summary label, so it is recommended to use `buy_summaryItemsWithShopName` instead.
*/
- (NSArray *)buy_summaryItems;
- (nonnull NSArray<PKPaymentSummaryItem *> *)buy_summaryItems;
/**
* Returns an array of summary items for all Apple Pay requests using the shop name in the "PAY" section
......@@ -46,7 +46,7 @@
*
* @return An array of PKPaymentSummaryItems
*/
- (NSArray *)buy_summaryItemsWithShopName:(NSString *)shopName;
- (nonnull NSArray<PKPaymentSummaryItem *> *)buy_summaryItemsWithShopName:(nullable NSString *)shopName;
@end
......@@ -59,13 +59,13 @@
*
* @return An array of PKShippingMethods
*/
+ (NSArray *)buy_convertShippingRatesToShippingMethods:(NSArray *)rates;
+ (nonnull NSArray<PKShippingMethod *> *)buy_convertShippingRatesToShippingMethods:(nonnull NSArray<BUYShippingRate *> *)rates;
@end
@interface BUYAddress (ApplePay)
+ (NSString *)buy_emailFromRecord:(ABRecordRef)record;
+ (nullable NSString *)buy_emailFromRecord:(nonnull ABRecordRef)record;
/**
* Creates a BUYAddress from an ABRecordRef
......@@ -74,7 +74,7 @@
*
* @return The BUYAddress created from an ABRecordRef
*/
+ (BUYAddress *)buy_addressFromRecord:(ABRecordRef)record NS_DEPRECATED_IOS(8_0, 9_0, "Use the CNContact backed `buy_addressFromContact:` instead");
+ (nonnull BUYAddress *)buy_addressFromRecord:(nonnull ABRecordRef)record NS_DEPRECATED_IOS(8_0, 9_0, "Use the CNContact backed `buy_addressFromContact:` instead");
/**
* Creates a BUYAddress from a PKContact
......@@ -83,6 +83,6 @@
*
* @return The BUYAddress created from a PKContact
*/
+ (BUYAddress *)buy_addressFromContact:(PKContact*)contact NS_AVAILABLE_IOS(9_0);
+ (nonnull BUYAddress *)buy_addressFromContact:(nonnull PKContact*)contact NS_AVAILABLE_IOS(9_0);
@end
......@@ -38,11 +38,11 @@
@implementation BUYCheckout (ApplePay)
- (NSArray *)buy_summaryItemsWithShopName:(NSString *)shopName {
- (nonnull NSArray<PKPaymentSummaryItem *> *)buy_summaryItemsWithShopName:(nullable NSString *)shopName {
BOOL hasDiscount = [self.discount.amount compare:[NSDecimalNumber zero]] == NSOrderedDescending;
NSMutableArray *summaryItems = [[NSMutableArray alloc] init];
NSMutableArray<PKPaymentSummaryItem *> *summaryItems = [[NSMutableArray alloc] init];
if (hasDiscount || [self.lineItems count] > 1) {
NSDecimalNumber *lineItemSubtotal = [NSDecimalNumber zero];
......@@ -76,10 +76,11 @@
NSString *itemLabel = shopName ?: @"TOTAL";
[summaryItems addObject:[PKPaymentSummaryItem summaryItemWithLabel:itemLabel amount:self.paymentDue ?: [NSDecimalNumber zero]]];
return summaryItems;
}
- (NSArray *)buy_summaryItems
- (nonnull NSArray<PKPaymentSummaryItem *> *)buy_summaryItems
{
return [self buy_summaryItemsWithShopName:nil];
}
......@@ -88,9 +89,9 @@
@implementation BUYShippingRate (ApplePay)
+ (NSArray *)buy_convertShippingRatesToShippingMethods:(NSArray *)rates
+ (nonnull NSArray<PKShippingMethod *> *)buy_convertShippingRatesToShippingMethods:(nonnull NSArray<BUYShippingRate *> *)rates
{
NSMutableArray *shippingMethods = [[NSMutableArray alloc] init];
NSMutableArray<PKShippingMethod *> *shippingMethods = [[NSMutableArray alloc] init];
for (BUYShippingRate *shippingRate in rates) {
PKShippingMethod *shippingMethod = [[PKShippingMethod alloc] init];
shippingMethod.label = shippingRate.title;
......@@ -121,7 +122,7 @@
@implementation BUYAddress (ApplePay)
+ (NSString *)buy_emailFromRecord:(ABRecordRef)record
+ (nullable NSString *)buy_emailFromRecord:(nonnull ABRecordRef)record
{
ABMultiValueRef emailMultiValue = ABRecordCopyValue(record, kABPersonEmailProperty);
CFArrayRef allEmails = ABMultiValueCopyArrayOfAllValues(emailMultiValue);
......@@ -136,7 +137,7 @@
return email;
}
+ (BUYAddress *)buy_addressFromRecord:(ABRecordRef)record
+ (nonnull BUYAddress *)buy_addressFromRecord:(nonnull ABRecordRef)record
{
BUYAddress *address = [[BUYAddress alloc] init];
......@@ -193,7 +194,7 @@
return address;
}
+ (BUYAddress *)buy_addressFromContact:(PKContact*)contact
+ (nonnull BUYAddress *)buy_addressFromContact:(nonnull PKContact*)contact
{
BUYAddress *address = [[BUYAddress alloc] init];
......
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