diff --git a/AffirmSDK.xcodeproj/project.pbxproj b/AffirmSDK.xcodeproj/project.pbxproj index 8186d55..889fb4d 100644 --- a/AffirmSDK.xcodeproj/project.pbxproj +++ b/AffirmSDK.xcodeproj/project.pbxproj @@ -20,7 +20,6 @@ 0841E335223A9948006D8B97 /* AffirmConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 0841E333223A9948006D8B97 /* AffirmConstants.m */; }; 0876CA2B22FA6804006F8062 /* AffirmReasonCode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0876CA2922FA6803006F8062 /* AffirmReasonCode.h */; settings = {ATTRIBUTES = (Public, ); }; }; 0876CA2C22FA6804006F8062 /* AffirmReasonCode.m in Sources */ = {isa = PBXBuildFile; fileRef = 0876CA2A22FA6803006F8062 /* AffirmReasonCode.m */; }; - 0885F17423D8419F00123729 /* AffirmCheckoutMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 0885F17223D8419F00123729 /* AffirmCheckoutMetadata.h */; settings = {ATTRIBUTES = (Public, ); }; }; 08A4D3EB23264FE0003A4BEB /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 08A4D3EA23264FE0003A4BEB /* README.md */; }; 08A81F49223F986D00FAA8D2 /* AffirmClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 08A81F47223F986D00FAA8D2 /* AffirmClient.h */; settings = {ATTRIBUTES = (Private, ); }; }; 08A81F4A223F986D00FAA8D2 /* AffirmClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 08A81F48223F986D00FAA8D2 /* AffirmClient.m */; }; @@ -103,8 +102,6 @@ 0841E333223A9948006D8B97 /* AffirmConstants.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AffirmConstants.m; sourceTree = ""; }; 0876CA2922FA6803006F8062 /* AffirmReasonCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AffirmReasonCode.h; sourceTree = ""; }; 0876CA2A22FA6803006F8062 /* AffirmReasonCode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AffirmReasonCode.m; sourceTree = ""; }; - 0885F17223D8419F00123729 /* AffirmCheckoutMetadata.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AffirmCheckoutMetadata.h; sourceTree = ""; }; - 0885F17323D8419F00123729 /* AffirmCheckoutMetadata.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AffirmCheckoutMetadata.m; sourceTree = ""; }; 08A4D3EA23264FE0003A4BEB /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 08A81F47223F986D00FAA8D2 /* AffirmClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AffirmClient.h; sourceTree = ""; }; 08A81F48223F986D00FAA8D2 /* AffirmClient.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AffirmClient.m; sourceTree = ""; }; @@ -252,8 +249,6 @@ 7965AB35223656680063198F /* AffirmSDK.bundle */, 0827FF892325EB9200AEC14C /* AffirmDataHandler.h */, 0827FF8A2325EB9200AEC14C /* AffirmDataHandler.m */, - 0885F17223D8419F00123729 /* AffirmCheckoutMetadata.h */, - 0885F17323D8419F00123729 /* AffirmCheckoutMetadata.m */, ); path = AffirmSDK; sourceTree = ""; @@ -297,7 +292,6 @@ 0876CA2B22FA6804006F8062 /* AffirmReasonCode.h in Headers */, 0827FF8B2325EB9200AEC14C /* AffirmDataHandler.h in Headers */, 7944D9C12248A84D0040525E /* AffirmUtils.h in Headers */, - 0885F17423D8419F00123729 /* AffirmCheckoutMetadata.h in Headers */, 7944D9B72240E2250040525E /* AffirmLogger.h in Headers */, 7944D9932240BF830040525E /* AffirmActivityIndicatorView.h in Headers */, 79088B512238DB840059D691 /* AffirmPromoModalViewController.h in Headers */, diff --git a/AffirmSDK/AffirmCheckout.h b/AffirmSDK/AffirmCheckout.h index 6e01ede..f002293 100644 --- a/AffirmSDK/AffirmCheckout.h +++ b/AffirmSDK/AffirmCheckout.h @@ -13,7 +13,6 @@ @class AffirmDiscount; @class AffirmShippingDetail; @class AffirmBillingDetail; -@class AffirmCheckoutMetadata; NS_ASSUME_NONNULL_BEGIN @@ -63,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN /** Additional metadata for the checkout. Optional. */ -@property (nonatomic, copy, readonly, nullable) AffirmCheckoutMetadata *metadata; +@property (nonatomic, copy, readonly, nullable) NSDictionary *metadata; /** The total amount. Dynamically computed from the other properties of the checkout if not available @@ -102,7 +101,7 @@ NS_ASSUME_NONNULL_BEGIN taxAmount:(NSDecimalNumber *)taxAmount shippingAmount:(NSDecimalNumber *)shippingAmount discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram NS_SWIFT_NAME(init(items:shipping:taxAmount:shippingAmount:discounts:metadata:financingProgram:)); @@ -124,7 +123,7 @@ NS_SWIFT_NAME(init(items:shipping:taxAmount:shippingAmount:discounts:metadata:fi taxAmount:(NSDecimalNumber *)taxAmount shippingAmount:(NSDecimalNumber *)shippingAmount discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram orderId:(nullable NSString *)orderId NS_SWIFT_NAME(init(items:shipping:taxAmount:shippingAmount:discounts:metadata:financingProgram:orderId:)); @@ -163,7 +162,7 @@ NS_SWIFT_NAME(checkout(items:shipping:taxAmount:shippingAmount:financingProgram: taxAmount:(NSDecimalNumber *)taxAmount shippingAmount:(NSDecimalNumber *)shippingAmount discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram NS_SWIFT_NAME(checkout(items:shipping:taxAmount:shippingAmount:discounts:metadata:financingProgram:)); @@ -198,7 +197,7 @@ NS_SWIFT_NAME(checkout(items:shipping:taxAmount:shippingAmount:)); taxAmount:(NSDecimalNumber *)taxAmount shippingAmount:(NSDecimalNumber *)shippingAmount discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata NS_SWIFT_NAME(checkout(items:shipping:taxAmount:shippingAmount:discounts:metadata:)); /** @@ -215,7 +214,7 @@ NS_SWIFT_NAME(checkout(items:shipping:taxAmount:shippingAmount:discounts:metadat - (instancetype)initWithItems:(NSArray *)items shipping:(nullable AffirmShippingDetail *)shipping discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram payoutAmount:(NSDecimalNumber *)payoutAmount API_DEPRECATED("Use initWithItems:shipping:discounts:metadata:financingProgram:totalAmount: instead.", ios(2.0, 13.0)) NS_SWIFT_NAME(init(items:shipping:discounts:metadata:financingProgram:payoutAmount:)); @@ -234,7 +233,7 @@ NS_SWIFT_NAME(init(items:shipping:discounts:metadata:financingProgram:payoutAmou - (instancetype)initWithItems:(NSArray *)items shipping:(nullable AffirmShippingDetail *)shipping discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram totalAmount:(NSDecimalNumber *)totalAmount NS_SWIFT_NAME(init(items:shipping:discounts:metadata:financingProgram:totalAmount:)); @@ -277,8 +276,9 @@ NS_SWIFT_NAME(checkout(items:shipping:totalAmount:)); + (AffirmCheckout *)checkoutWithItems:(NSArray *)items shipping:(nullable AffirmShippingDetail *)shipping totalAmount:(NSDecimalNumber *)totalAmount - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata NS_SWIFT_NAME(checkout(items:shipping:totalAmount:metadata:)); + @end NS_ASSUME_NONNULL_END diff --git a/AffirmSDK/AffirmCheckout.m b/AffirmSDK/AffirmCheckout.m index ecfa825..74685a5 100644 --- a/AffirmSDK/AffirmCheckout.m +++ b/AffirmSDK/AffirmCheckout.m @@ -14,7 +14,6 @@ #import "AffirmShippingDetail.h" #import "AffirmBillingDetail.h" #import "AffirmLogger.h" -#import "AffirmCheckoutMetadata.h" @implementation AffirmCheckout @@ -23,7 +22,7 @@ - (instancetype)initWithItems:(NSArray *)items taxAmount:(NSDecimalNumber *)taxAmount shippingAmount:(NSDecimalNumber *)shippingAmount discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram { [AffirmValidationUtils checkNotNil:items name:@"items"]; @@ -38,7 +37,7 @@ - (instancetype)initWithItems:(NSArray *)items _taxAmount = [taxAmount copy]; _shippingAmount = [shippingAmount copy]; _discounts = (discounts) ? [[NSArray alloc] initWithArray:discounts copyItems:YES] : nil; - _metadata = (metadata) ? [metadata copy] : nil; + _metadata = (metadata) ? [[NSDictionary alloc] initWithDictionary:metadata copyItems:YES] : nil; _financingProgram = (financingProgram) ? [financingProgram copy] : nil; _orderId = nil; _sendShippingAddress = YES; @@ -51,7 +50,7 @@ - (instancetype)initWithItems:(NSArray *)items taxAmount:(NSDecimalNumber *)taxAmount shippingAmount:(NSDecimalNumber *)shippingAmount discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram orderId:(nullable NSString *)orderId { @@ -67,7 +66,7 @@ - (instancetype)initWithItems:(NSArray *)items _taxAmount = [taxAmount copy]; _shippingAmount = [shippingAmount copy]; _discounts = discounts ? [[NSArray alloc] initWithArray:discounts copyItems:YES] : nil; - _metadata = metadata ? [metadata copy] : nil; + _metadata = metadata ? [[NSDictionary alloc] initWithDictionary:metadata copyItems:YES] : nil; _financingProgram = financingProgram ? [financingProgram copy] : nil; _orderId = orderId ? [orderId copy] : nil; _sendShippingAddress = YES; @@ -109,7 +108,7 @@ + (AffirmCheckout *)checkoutWithItems:(NSArray *)items taxAmount:(NSDecimalNumber *)taxAmount shippingAmount:(NSDecimalNumber *)shippingAmount discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata { return [self checkoutWithItems:items shipping:shipping @@ -125,7 +124,7 @@ + (AffirmCheckout *)checkoutWithItems:(NSArray *)items taxAmount:(NSDecimalNumber *)taxAmount shippingAmount:(NSDecimalNumber *)shippingAmount discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram { return [[self alloc] initWithItems:items @@ -140,7 +139,7 @@ + (AffirmCheckout *)checkoutWithItems:(NSArray *)items - (instancetype)initWithItems:(NSArray *)items shipping:(nullable AffirmShippingDetail *)shipping discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram payoutAmount:(NSDecimalNumber *)payoutAmount { @@ -162,7 +161,7 @@ - (instancetype)initWithItems:(NSArray *)items - (instancetype)initWithItems:(NSArray *)items shipping:(nullable AffirmShippingDetail *)shipping discounts:(nullable NSArray *)discounts - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata financingProgram:(nullable NSString *)financingProgram totalAmount:(NSDecimalNumber *)totalAmount { @@ -208,7 +207,7 @@ + (AffirmCheckout *)checkoutWithItems:(NSArray *)items + (AffirmCheckout *)checkoutWithItems:(NSArray *)items shipping:(nullable AffirmShippingDetail *)shipping totalAmount:(NSDecimalNumber *)totalAmount - metadata:(nullable AffirmCheckoutMetadata *)metadata + metadata:(nullable NSDictionary *)metadata { return [[self alloc] initWithItems:items shipping:shipping @@ -294,7 +293,7 @@ - (NSDictionary *)toJSONDictionary } if (self.metadata != nil) { - [dict setObject:[self.metadata toJSONDictionary] forKey:@"metadata"]; + [dict setObject:self.metadata forKey:@"metadata"]; } if (self.financingProgram != nil) { diff --git a/AffirmSDK/AffirmCheckoutMetadata.h b/AffirmSDK/AffirmCheckoutMetadata.h deleted file mode 100644 index f70891a..0000000 --- a/AffirmSDK/AffirmCheckoutMetadata.h +++ /dev/null @@ -1,59 +0,0 @@ -// -// AffirmCheckoutMetadata.h -// AffirmSDK -// -// Created by Victor Zhu on 2020/1/22. -// Copyright © 2020 Affirm, Inc. All rights reserved. -// - -#import -#import "AffirmJSONifiable.h" - -NS_ASSUME_NONNULL_BEGIN - -@interface AffirmCheckoutMetadata : NSObject - -/** - Shipping type. - */ -@property (nonatomic, copy, nullable) NSString *shippingType; - -/** - Entity name. - */ -@property (nonatomic, copy, nullable) NSString *entityName; - -/** - Webhook session id. - */ -@property (nonatomic, copy, nullable) NSString *webhookSessionId; - -/** -Initializer. See properties for more details. - -@param shippingType Shipping type. -@param entityName Entity name. -@param webhookSessionId Webhook session id. -@return The initialized metadata. -*/ -- (instancetype)initWithShippingType:(nullable NSString *)shippingType - entityName:(nullable NSString *)entityName - webhookSessionId:(nullable NSString *)webhookSessionId -NS_SWIFT_NAME(init(shippingType:entityName:webhookSessionId:)); - -/** -Convenience constructor for metadata - -@param shippingType Shipping type. -@param entityName Entity name. -@param webhookSessionId Webhook session id. -@return The newly created metadata. -*/ -+ (AffirmCheckoutMetadata *)checkoutMetadataWithShippingType:(nullable NSString *)shippingType - entityName:(nullable NSString *)entityName - webhookSessionId:(nullable NSString *)webhookSessionId -NS_SWIFT_NAME(checkoutMetadata(shippingType:entityName:webhookSessionId:)); - -@end - -NS_ASSUME_NONNULL_END diff --git a/AffirmSDK/AffirmCheckoutMetadata.m b/AffirmSDK/AffirmCheckoutMetadata.m deleted file mode 100644 index 0d40bb6..0000000 --- a/AffirmSDK/AffirmCheckoutMetadata.m +++ /dev/null @@ -1,57 +0,0 @@ -// -// AffirmCheckoutMetadata.m -// AffirmSDK -// -// Created by Victor Zhu on 2020/1/22. -// Copyright © 2020 Affirm, Inc. All rights reserved. -// - -#import "AffirmCheckoutMetadata.h" -#import "AffirmUtils.h" - -@implementation AffirmCheckoutMetadata - -- (instancetype)initWithShippingType:(nullable NSString *)shippingType - entityName:(nullable NSString *)entityName - webhookSessionId:(nullable NSString *)webhookSessionId -{ - if (self = [super init]) { - _shippingType = shippingType; - _entityName = entityName; - _webhookSessionId = webhookSessionId; - } - return self; -} - -+ (AffirmCheckoutMetadata *)checkoutMetadataWithShippingType:(nullable NSString *)shippingType - entityName:(nullable NSString *)entityName - webhookSessionId:(nullable NSString *)webhookSessionId -{ - return [[self alloc] initWithShippingType:shippingType - entityName:entityName - webhookSessionId:webhookSessionId]; -} - -- (NSMutableDictionary *)toJSONDictionary -{ - NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (self.shippingType) { - dictionary[@"shipping_type"] = self.shippingType; - } - if (self.entityName) { - dictionary[@"entity_name"] = self.entityName; - } - if (self.webhookSessionId) { - dictionary[@"webhook_session_id"] = self.webhookSessionId; - } - return dictionary; -} - -- (id)copyWithZone:(NSZone *)zone -{ - return [[self class] checkoutMetadataWithShippingType:self.shippingType - entityName:self.entityName - webhookSessionId:self.webhookSessionId]; -} - -@end diff --git a/AffirmSDK/AffirmSDK.h b/AffirmSDK/AffirmSDK.h index 1b1e8a4..3989aff 100644 --- a/AffirmSDK/AffirmSDK.h +++ b/AffirmSDK/AffirmSDK.h @@ -23,7 +23,6 @@ FOUNDATION_EXPORT const unsigned char AffirmSDKVersionString[]; #import #import #import -#import #import #import #import diff --git a/Examples/Examples.xcodeproj/project.pbxproj b/Examples/Examples.xcodeproj/project.pbxproj index f801fce..5ea6b56 100644 --- a/Examples/Examples.xcodeproj/project.pbxproj +++ b/Examples/Examples.xcodeproj/project.pbxproj @@ -354,16 +354,11 @@ files = ( ); inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-ExamplesSwift/Pods-ExamplesSwift-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/AffirmSDK/AffirmSDK.framework", + "${PODS_ROOT}/Target Support Files/Pods-ExamplesSwift/Pods-ExamplesSwift-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( - ); - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AffirmSDK.framework", + "${PODS_ROOT}/Target Support Files/Pods-ExamplesSwift/Pods-ExamplesSwift-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -376,16 +371,11 @@ files = ( ); inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Examples/Pods-Examples-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/AffirmSDK/AffirmSDK.framework", + "${PODS_ROOT}/Target Support Files/Pods-Examples/Pods-Examples-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( - ); - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AffirmSDK.framework", + "${PODS_ROOT}/Target Support Files/Pods-Examples/Pods-Examples-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/Examples/Examples/ViewController.m b/Examples/Examples/ViewController.m index 1acda70..8779d04 100644 --- a/Examples/Examples/ViewController.m +++ b/Examples/Examples/ViewController.m @@ -85,7 +85,7 @@ - (IBAction)checkout:(id)sender NSDecimalNumber *dollarPrice = [NSDecimalNumber decimalNumberWithString:self.amountTextField.text]; AffirmItem *item = [AffirmItem itemWithName:@"Affirm Test Item" SKU:@"test_item" unitPrice:dollarPrice quantity:1 URL:[NSURL URLWithString:@"http://sandbox.affirm.com/item"]]; AffirmShippingDetail *shipping = [AffirmShippingDetail shippingDetailWithName:@"Chester Cheetah" addressWithLine1:@"633 Folsom Street" line2:@"" city:@"San Francisco" state:@"CA" zipCode:@"94107" countryCode:@"USA"]; - AffirmCheckoutMetadata *metadata = [AffirmCheckoutMetadata checkoutMetadataWithShippingType:@"UPS Ground" entityName:@"internal-sub_brand-name" webhookSessionId:@"ABC123"]; + NSDictionary *metadata = @{@"shipping_type": @"UPS Ground", @"entity_name": @"internal-sub_brand-name", @"webhook_session_id": @"ABC123"}; AffirmCheckout *checkout = [AffirmCheckout checkoutWithItems:@[item] shipping:shipping totalAmount:[dollarPrice toIntegerCents] metadata:metadata]; AffirmBillingDetail *billing = [AffirmBillingDetail billingDetailWithName:@"Chester Cheetah" email:@"testtester@test.com" phoneNumber:nil addressWithLine1:@"633 Folsom Street" line2:@"" city:@"San Francisco" state:@"CA" zipCode:@"94107" countryCode:@"USA"]; checkout.billing = billing; diff --git a/Examples/ExamplesSwift/ViewController.swift b/Examples/ExamplesSwift/ViewController.swift index 344f0cf..5b661c5 100644 --- a/Examples/ExamplesSwift/ViewController.swift +++ b/Examples/ExamplesSwift/ViewController.swift @@ -168,7 +168,12 @@ extension ViewController: AffirmCheckoutDelegate { } func vcnCheckout(_ checkoutViewController: AffirmCheckoutViewController, completedWith creditCard: AffirmCreditCard) { - resultLabel.text = "Received credit card:\ncredit card id: \(creditCard.creditCardId)\ncheckout token: \(creditCard.checkoutToken)\ncard holder name: \(creditCard.cardholderName)\nnumber:\(creditCard.number)\ncvv: \(creditCard.cvv)\nexpiration: \(creditCard.expiration)\ncallback id: \(creditCard.callbackId)" + if let cardholderName = creditCard.cardholderName, + let number = creditCard.number, + let cvv = creditCard.cvv, + let expiration = creditCard.expiration { + resultLabel.text = "Received credit card:\ncredit card id: \(creditCard.creditCardId)\ncheckout token: \(creditCard.checkoutToken)\ncard holder name: \(cardholderName)\nnumber:\(number)\ncvv: \(cvv)\nexpiration: \(expiration)\ncallback id: \(creditCard.callbackId)" + } checkoutViewController.dismiss(animated: true, completion: nil) }