Commit e64df449 by Gabriel O'Flaherty-Chan

Merge pull request #175 from Shopify/task/154-cleanup-applepay-helpers

Clean up BUYApplePayHelpers
parents be59c98e 20dab27d
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#import "BUYPKContact.h" #import "BUYPKContact.h"
#import "BUYNSPersonNameComponents.h" #import "BUYNSPersonNameComponents.h"
#import "BUYCNPostalAddress.h" #import "BUYCNPostalAddress.h"
#import "BUYModelManager+ApplePay.h"
@interface BUYApplePayAdditionsTest : XCTestCase @interface BUYApplePayAdditionsTest : XCTestCase
@end @end
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
NSURLComponents *components = [NSURLComponents componentsWithURL:request.URL resolvingAgainstBaseURL:NO]; NSURLComponents *components = [NSURLComponents componentsWithURL:request.URL resolvingAgainstBaseURL:NO];
if ([components.path isEqualToString:@"/meta.json"]) { if ([components.path isEqualToString:@"/meta.json"]) {
return [OHHTTPStubsResponse responseWithJSONObject:@{@"id": @"123", @"country": @"US", @"currency": @"USD"} statusCode:200 headers:nil]; return [OHHTTPStubsResponse responseWithJSONObject:@{@"id": @"123", @"name": @"test_shop", @"country": @"US", @"currency": @"USD"} statusCode:200 headers:nil];
} }
else if ([components.path isEqualToString:@"/api/checkouts.json"]) { else if ([components.path isEqualToString:@"/api/checkouts.json"]) {
return [OHHTTPStubsResponse responseWithJSONObject:@{@"checkout":@{@"payment_due": @(99), @"web_checkout_url": @"https://example.com"}} statusCode:200 headers:nil]; return [OHHTTPStubsResponse responseWithJSONObject:@{@"checkout":@{@"payment_due": @(99), @"web_checkout_url": @"https://example.com"}} statusCode:200 headers:nil];
......
...@@ -56,7 +56,7 @@ FOUNDATION_EXPORT const unsigned char BuyVersionString[]; ...@@ -56,7 +56,7 @@ FOUNDATION_EXPORT const unsigned char BuyVersionString[];
#import <Buy/BUYTaxLine.h> #import <Buy/BUYTaxLine.h>
#import <Buy/BUYApplePayAdditions.h> #import <Buy/BUYApplePayAdditions.h>
#import <Buy/BUYApplePayHelpers.h> #import <Buy/BUYApplePayAuthorizationDelegate.h>
#import <Buy/BUYApplePayPaymentProvider.h> #import <Buy/BUYApplePayPaymentProvider.h>
#import <Buy/BUYPaymentController.h> #import <Buy/BUYPaymentController.h>
#import <Buy/BUYPaymentProvider.h> #import <Buy/BUYPaymentProvider.h>
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#import "BUYApplePayPaymentProvider.h" #import "BUYApplePayPaymentProvider.h"
#import "BUYCheckout.h" #import "BUYCheckout.h"
#import "BUYApplePayHelpers.h" #import "BUYApplePayAuthorizationDelegate.h"
#import "BUYApplePayAdditions.h" #import "BUYApplePayAdditions.h"
#import "BUYShop.h" #import "BUYShop.h"
#import "BUYClient+CheckoutHelpers.h" #import "BUYClient+CheckoutHelpers.h"
...@@ -38,7 +38,7 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId"; ...@@ -38,7 +38,7 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
@interface BUYApplePayPaymentProvider () <PKPaymentAuthorizationViewControllerDelegate> @interface BUYApplePayPaymentProvider () <PKPaymentAuthorizationViewControllerDelegate>
@property (nonatomic, strong) BUYShop *shop; @property (nonatomic, strong) BUYShop *shop;
@property (nonatomic, strong) BUYApplePayHelpers *applePayHelper; @property (nonatomic, strong) BUYApplePayAuthorizationDelegate *applePayAuthorizationDelegate;
@property (nonatomic, strong) BUYCheckout *checkout; @property (nonatomic, strong) BUYCheckout *checkout;
@property (nonatomic, assign) PKPaymentAuthorizationStatus paymentAuthorizationStatus; @property (nonatomic, assign) PKPaymentAuthorizationStatus paymentAuthorizationStatus;
@property (nonatomic, strong) BUYClient *client; @property (nonatomic, strong) BUYClient *client;
...@@ -171,7 +171,7 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId"; ...@@ -171,7 +171,7 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
- (void)proceedWithApplePay - (void)proceedWithApplePay
{ {
self.applePayHelper = [[BUYApplePayHelpers alloc] initWithClient:self.client checkout:self.checkout shop:self.shop]; self.applePayAuthorizationDelegate = [[BUYApplePayAuthorizationDelegate alloc] initWithClient:self.client checkout:self.checkout shopName:self.shop.name];
PKPaymentRequest *request = [self paymentRequest]; PKPaymentRequest *request = [self paymentRequest];
request.paymentSummaryItems = [self.checkout buy_summaryItemsWithShopName:self.shop.name]; request.paymentSummaryItems = [self.checkout buy_summaryItemsWithShopName:self.shop.name];
...@@ -221,19 +221,19 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId"; ...@@ -221,19 +221,19 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion
{ {
[self.applePayHelper paymentAuthorizationViewController:controller didAuthorizePayment:payment completion:^(PKPaymentAuthorizationStatus status) { [self.applePayAuthorizationDelegate paymentAuthorizationViewController:controller didAuthorizePayment:payment completion:^(PKPaymentAuthorizationStatus status) {
self.paymentAuthorizationStatus = status; self.paymentAuthorizationStatus = status;
switch (status) { switch (status) {
case PKPaymentAuthorizationStatusFailure: case PKPaymentAuthorizationStatusFailure:
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) { if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) {
[self.delegate paymentProvider:self didFailWithError:self.applePayHelper.lastError]; [self.delegate paymentProvider:self didFailWithError:self.applePayAuthorizationDelegate.lastError];
} }
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailCheckoutNotificationKey object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailCheckoutNotificationKey object:self];
break; break;
case PKPaymentAuthorizationStatusInvalidShippingPostalAddress: case PKPaymentAuthorizationStatusInvalidShippingPostalAddress:
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) { if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) {
[self.delegate paymentProvider:self didFailWithError:self.applePayHelper.lastError]; [self.delegate paymentProvider:self didFailWithError:self.applePayAuthorizationDelegate.lastError];
} }
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self];
break; break;
...@@ -261,10 +261,10 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId"; ...@@ -261,10 +261,10 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingMethod:(nonnull PKShippingMethod *)shippingMethod completion:(nonnull void (^)(PKPaymentAuthorizationStatus, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingMethod:(nonnull PKShippingMethod *)shippingMethod completion:(nonnull void (^)(PKPaymentAuthorizationStatus, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
{ {
[self.applePayHelper paymentAuthorizationViewController:controller didSelectShippingMethod:shippingMethod completion:^(PKPaymentAuthorizationStatus status, NSArray<PKPaymentSummaryItem *> * _Nonnull summaryItems) { [self.applePayAuthorizationDelegate paymentAuthorizationViewController:controller didSelectShippingMethod:shippingMethod completion:^(PKPaymentAuthorizationStatus status, NSArray<PKPaymentSummaryItem *> * _Nonnull summaryItems) {
if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) { if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) { if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) {
[self.delegate paymentProvider:self didFailWithError:self.applePayHelper.lastError]; [self.delegate paymentProvider:self didFailWithError:self.applePayAuthorizationDelegate.lastError];
} }
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self];
} }
...@@ -274,10 +274,10 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId"; ...@@ -274,10 +274,10 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
-(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingAddress:(ABRecordRef)address completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKShippingMethod *> * _Nonnull, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion -(void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingAddress:(ABRecordRef)address completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKShippingMethod *> * _Nonnull, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
{ {
[self.applePayHelper paymentAuthorizationViewController:controller didSelectShippingAddress:address completion:^(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> * _Nonnull shippingMethods, NSArray<PKPaymentSummaryItem *> * _Nonnull summaryItems) { [self.applePayAuthorizationDelegate paymentAuthorizationViewController:controller didSelectShippingAddress:address completion:^(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> * _Nonnull shippingMethods, NSArray<PKPaymentSummaryItem *> * _Nonnull summaryItems) {
if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) { if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) { if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) {
[self.delegate paymentProvider:self didFailWithError:self.applePayHelper.lastError]; [self.delegate paymentProvider:self didFailWithError:self.applePayAuthorizationDelegate.lastError];
} }
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self];
} }
...@@ -287,10 +287,10 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId"; ...@@ -287,10 +287,10 @@ NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKShippingMethod *> * _Nonnull, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(void (^)(PKPaymentAuthorizationStatus, NSArray<PKShippingMethod *> * _Nonnull, NSArray<PKPaymentSummaryItem *> * _Nonnull))completion
{ {
[self.applePayHelper paymentAuthorizationViewController:controller didSelectShippingContact:contact completion:^(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> * _Nonnull shippingMethods, NSArray<PKPaymentSummaryItem *> * _Nonnull summaryItems) { [self.applePayAuthorizationDelegate paymentAuthorizationViewController:controller didSelectShippingContact:contact completion:^(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> * _Nonnull shippingMethods, NSArray<PKPaymentSummaryItem *> * _Nonnull summaryItems) {
if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) { if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) { if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailWithError:)]) {
[self.delegate paymentProvider:self didFailWithError:self.applePayHelper.lastError]; [self.delegate paymentProvider:self didFailWithError:self.applePayAuthorizationDelegate.lastError];
} }
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self]; [[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self];
} }
......
// //
// BUYApplePayHelpers.h // BUYApplePayAuthorizationDelegate.h
// Mobile Buy SDK // Mobile Buy SDK
// //
// Created by Shopify. // Created by Shopify.
...@@ -27,24 +27,13 @@ ...@@ -27,24 +27,13 @@
@import Foundation; @import Foundation;
@import PassKit; @import PassKit;
#import <Buy/BUYModelManager.h>
@class BUYAddress;
@class BUYClient; @class BUYClient;
@class BUYCheckout; @class BUYCheckout;
@class BUYShop; @class BUYShop;
@interface BUYApplePayHelpers : NSObject <PKPaymentAuthorizationViewControllerDelegate> NS_ASSUME_NONNULL_BEGIN
/** @interface BUYApplePayAuthorizationDelegate : NSObject <PKPaymentAuthorizationViewControllerDelegate>
* Initializes a helper to support Apple Pay
*
* @param client A configured client
* @param checkout The checkout which is to be completed using Apple Pay
*
* @return helper object
*/
- (instancetype)initWithClient:(BUYClient *)client checkout:(BUYCheckout *)checkout;
/** /**
* Initializes a helper to support Apple Pay * Initializes a helper to support Apple Pay
...@@ -55,39 +44,8 @@ ...@@ -55,39 +44,8 @@
* *
* @return helper object * @return helper object
*/ */
- (instancetype)initWithClient:(BUYClient *)client checkout:(BUYCheckout *)checkout shop:(BUYShop *)shop; - (instancetype)initWithClient:(BUYClient *)client checkout:(BUYCheckout *)checkout shopName:(NSString *)shopName NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
/**
* Call this method in the PKPaymentAuthorizationViewControllerDelegate `paymentAuthorizationViewController:didAuthorizePayment:completion`
*
* @param payment the authorized payment
* @param completion completion block thats called after Shopify authorizes the payment
*/
- (void)updateAndCompleteCheckoutWithPayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion NS_DEPRECATED_IOS(8_0, 9_0, "Use `PKPaymentAuthorizationViewControllerDelegate` instead");
/**
* Call this method in the PKPaymentAuthorizationViewControllerDelegate `paymentAuthorizationViewController:didSelectShippingMethod:completion`
*
* @param shippingMethod The selected shipping method
* @param completion the completion block called after shipping method is updated on the checkout
*/
- (void)updateCheckoutWithShippingMethod:(PKShippingMethod *)shippingMethod completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray *methods))completion NS_DEPRECATED_IOS(8_0, 9_0, "Use `PKPaymentAuthorizationViewControllerDelegate` instead");
/**
* Call this method in the PKPaymentAuthorizationViewControllerDelegate `paymentAuthorizationViewController:didSelectShippingAddress:completion`
*
* @param address The selected shipping address
* @param completion the completion block called after the shipping address is updated on the checkout
*/
- (void)updateCheckoutWithAddress:(ABRecordRef)address completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray *shippingMethods, NSArray *summaryItems))completion NS_DEPRECATED_IOS(8_0, 9_0, "Use the CNContact backed `updateCheckoutWithContact:completion:` instead");
/**
* Call this method in the PKPaymentAuthorizationViewControllerDelegate `paymentAuthorizationViewController:didSelectShippingAddress:completion`
*
* @param contact The selected contact
* @param completion the completion block called after the shipping address is updated on the checkout
*/
- (void)updateCheckoutWithContact:(PKContact*)contact completion:(void (^)(PKPaymentAuthorizationStatus, NSArray *shippingMethods, NSArray *summaryItems))completion NS_DEPRECATED_IOS(8_0, 9_0, "Use `PKPaymentAuthorizationViewControllerDelegate` instead");
/** /**
* The current checkout * The current checkout
...@@ -105,30 +63,10 @@ ...@@ -105,30 +63,10 @@
@property (nonatomic, strong, readonly) NSError *lastError; @property (nonatomic, strong, readonly) NSError *lastError;
/** /**
* The shop object * The shop name
*/ */
@property (nonatomic, strong, readonly) BUYShop *shop; @property (nonatomic, strong, readonly) NSString *shopName;
@end @end
@interface BUYModelManager (ApplePay) NS_ASSUME_NONNULL_END
/**
* Creates a BUYAddress from an ABRecordRef
*
* @param record ABRecordRef to create a BUYAddress from
*
* @return The BUYAddress created from an ABRecordRef
*/
- (BUYAddress *)buyAddressWithABRecord:(ABRecordRef)addressRecord NS_DEPRECATED_IOS(8_0, 9_0, "Use the CNContact backed `buyAddressWithContact:` instead");
/**
* Creates a BUYAddress from a PKContact
*
* @param contact PKContact to create a BUYAddress from
*
* @return The BUYAddress created from a PKContact
*/
- (BUYAddress *)buyAddressWithContact:(PKContact *)contact NS_AVAILABLE_IOS(9_0);
@end
// //
// BUYApplePayHelpers.m // BUYApplePayAuthorizationDelegate.m
// Mobile Buy SDK // Mobile Buy SDK
// //
// Created by Shopify. // Created by Shopify.
...@@ -24,67 +24,48 @@ ...@@ -24,67 +24,48 @@
// THE SOFTWARE. // THE SOFTWARE.
// //
#import "BUYApplePayHelpers.h" #import "BUYApplePayAuthorizationDelegate.h"
#import "BUYAddress.h"
#import "BUYApplePayAdditions.h" #import "BUYApplePayAdditions.h"
#import "BUYApplePayToken.h"
#import "BUYAssert.h"
#import "BUYClient+Checkout.h" #import "BUYClient+Checkout.h"
#import "BUYClient+Storefront.h" #import "BUYClient+Storefront.h"
#import "BUYCheckout.h" #import "BUYCheckout.h"
#import "BUYError.h" #import "BUYError.h"
#import "BUYModelManager.h" #import "BUYModelManager+ApplePay.h"
#import "BUYShop.h" #import "BUYShop.h"
#import "BUYShopifyErrorCodes.h" #import "BUYShopifyErrorCodes.h"
#import "BUYApplePayToken.h"
const NSTimeInterval PollDelay = 0.5; const NSTimeInterval PollDelay = 0.5;
@interface BUYApplePayHelpers () @interface BUYApplePayAuthorizationDelegate ()
@property (nonatomic, strong) BUYCheckout *checkout; @property (nonatomic, strong) BUYCheckout *checkout;
@property (nonatomic, strong) BUYClient *client;
@property (nonatomic, strong) NSArray *shippingRates; @property (nonatomic, strong) NSArray *shippingRates;
@property (nonatomic, strong) NSError *lastError; @property (nonatomic, strong) NSError *lastError;
@property (nonatomic, strong) BUYShop *shop;
@end @end
@implementation BUYApplePayHelpers @implementation BUYApplePayAuthorizationDelegate
- (instancetype)initWithClient:(BUYClient *)client checkout:(BUYCheckout *)checkout
{
return [self initWithClient:client checkout:checkout shop:nil];
}
- (instancetype)initWithClient:(BUYClient *)client checkout:(BUYCheckout *)checkout shop:(BUYShop *)shop - (instancetype)initWithClient:(BUYClient *)client checkout:(BUYCheckout *)checkout shopName:(NSString *)shopName
{ {
NSParameterAssert(client); BUYAssert(client, @"Failed to initialize BUYApplePayAuthorizationDelegate. Client must not be nil.");
NSParameterAssert(checkout); BUYAssert(checkout, @"Failed to initialize BUYApplePayAuthorizationDelegate. Checkout must not be nil.");
BUYAssert(shopName, @"Failed to initialize BUYApplePayAuthorizationDelegate. Shop name must not be nil.");
self = [super init]; self = [super init];
if (self) { if (self) {
self.client = client; _client = client;
self.checkout = checkout; _checkout = checkout;
_shopName = shopName;
// We need a shop object to display the business name in the pay sheet
if (shop) {
self.shop = shop;
}
else {
[self.client getShop:^(BUYShop *shop, NSError *error) {
if (shop) {
self.shop = shop;
}
}];
}
} }
return self; return self;
} }
#pragma mark - PKPaymentAuthorizationDelegate methods #pragma mark - PKPaymentAuthorizationDelegate methods
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
...@@ -176,7 +157,7 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -176,7 +157,7 @@ const NSTimeInterval PollDelay = 0.5;
else { else {
self.lastError = error; self.lastError = error;
} }
completion(error == nil ? PKPaymentAuthorizationStatusSuccess : PKPaymentAuthorizationStatusFailure, [self.checkout buy_summaryItemsWithShopName:self.shop.name]); completion(error == nil ? PKPaymentAuthorizationStatusSuccess : PKPaymentAuthorizationStatusFailure, [self.checkout buy_summaryItemsWithShopName:self.shopName]);
}]; }];
} }
...@@ -200,40 +181,15 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -200,40 +181,15 @@ const NSTimeInterval PollDelay = 0.5;
} }
else { else {
self.lastError = error; self.lastError = error;
completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress, nil, [self.checkout buy_summaryItemsWithShopName:self.shop.name]); completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress, nil, [self.checkout buy_summaryItemsWithShopName:self.shopName]);
} }
}]; }];
} }
else { else {
completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress, nil, [self.checkout buy_summaryItemsWithShopName:self.shop.name]); completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress, nil, [self.checkout buy_summaryItemsWithShopName:self.shopName]);
} }
} }
- (void)updateAndCompleteCheckoutWithPayment:(PKPayment *)payment
completion:(void (^)(PKPaymentAuthorizationStatus))completion
{
// Since we're deprecating this method and the controller is not used in the delegate method, we can pass in a not-null PKPaymentAuthorizationViewController
[self paymentAuthorizationViewController:[PKPaymentAuthorizationViewController new] didAuthorizePayment:payment completion:completion];
}
- (void)updateCheckoutWithShippingMethod:(PKShippingMethod *)shippingMethod completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray *methods))completion
{
// Since we're deprecating this method and the controller is not used in the delegate method, we can pass in a not-null PKPaymentAuthorizationViewController
[self paymentAuthorizationViewController:[PKPaymentAuthorizationViewController new] didSelectShippingMethod:shippingMethod completion:completion];
}
- (void)updateCheckoutWithAddress:(ABRecordRef)address completion:(void (^)(PKPaymentAuthorizationStatus, NSArray *shippingMethods, NSArray *summaryItems))completion
{
// Since we're deprecating this method and the controller is not used in the delegate method, we can pass in a not-null PKPaymentAuthorizationViewController
[self paymentAuthorizationViewController:[PKPaymentAuthorizationViewController new] didSelectShippingAddress:address completion:completion];
}
- (void)updateCheckoutWithContact:(PKContact*)contact completion:(void (^)(PKPaymentAuthorizationStatus, NSArray *shippingMethods, NSArray *summaryItems))completion
{
// Since we're deprecating this method and the controller is not used in the delegate method, we can pass in a not-null PKPaymentAuthorizationViewController
[self paymentAuthorizationViewController:[PKPaymentAuthorizationViewController new] didSelectShippingContact:contact completion:completion];
}
#pragma mark - internal #pragma mark - internal
- (BUYShippingRate *)rateForShippingMethod:(PKShippingMethod *)method - (BUYShippingRate *)rateForShippingMethod:(PKShippingMethod *)method
...@@ -255,7 +211,7 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -255,7 +211,7 @@ const NSTimeInterval PollDelay = 0.5;
// We then turn our BUYShippingRate objects into PKShippingMethods for Apple to present to the user. // We then turn our BUYShippingRate objects into PKShippingMethods for Apple to present to the user.
if ([self.checkout requiresShipping] == NO) { if ([self.checkout requiresShipping] == NO) {
completion(PKPaymentAuthorizationStatusSuccess, nil, [self.checkout buy_summaryItemsWithShopName:self.shop.name]); completion(PKPaymentAuthorizationStatusSuccess, nil, [self.checkout buy_summaryItemsWithShopName:self.shopName]);
} }
else { else {
[self fetchShippingRates:^(PKPaymentAuthorizationStatus status, NSArray *methods, NSArray *summaryItems) { [self fetchShippingRates:^(PKPaymentAuthorizationStatus status, NSArray *methods, NSArray *summaryItems) {
...@@ -266,12 +222,12 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -266,12 +222,12 @@ const NSTimeInterval PollDelay = 0.5;
if (checkout && error == nil) { if (checkout && error == nil) {
self.checkout = checkout; self.checkout = checkout;
} }
completion(error ? PKPaymentAuthorizationStatusFailure : PKPaymentAuthorizationStatusSuccess, shippingMethods, [self.checkout buy_summaryItemsWithShopName:self.shop.name]); completion(error ? PKPaymentAuthorizationStatusFailure : PKPaymentAuthorizationStatusSuccess, shippingMethods, [self.checkout buy_summaryItemsWithShopName:self.shopName]);
}]; }];
} }
else { else {
self.lastError = [NSError errorWithDomain:BUYShopifyError code:BUYShopifyError_NoShippingMethodsToAddress userInfo:nil]; self.lastError = [NSError errorWithDomain:BUYShopifyError code:BUYShopifyError_NoShippingMethodsToAddress userInfo:nil];
completion(status, nil, [self.checkout buy_summaryItemsWithShopName:self.shop.name]); completion(status, nil, [self.checkout buy_summaryItemsWithShopName:self.shopName]);
} }
}]; }];
} }
...@@ -290,7 +246,7 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -290,7 +246,7 @@ const NSTimeInterval PollDelay = 0.5;
shippingStatus = status; shippingStatus = status;
if (error) { if (error) {
completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress, nil, [self.checkout buy_summaryItemsWithShopName:self.shop.name]); completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress, nil, [self.checkout buy_summaryItemsWithShopName:self.shopName]);
} }
else if (shippingStatus == BUYStatusComplete) { else if (shippingStatus == BUYStatusComplete) {
self.shippingRates = shippingRates; self.shippingRates = shippingRates;
...@@ -298,11 +254,11 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -298,11 +254,11 @@ const NSTimeInterval PollDelay = 0.5;
if ([self.shippingRates count] == 0) { if ([self.shippingRates count] == 0) {
// Shipping address is not supported and no shipping rates were returned // Shipping address is not supported and no shipping rates were returned
if (completion) { if (completion) {
completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress, nil, [self.checkout buy_summaryItemsWithShopName:self.shop.name]); completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress, nil, [self.checkout buy_summaryItemsWithShopName:self.shopName]);
} }
} else { } else {
if (completion) { if (completion) {
completion(PKPaymentAuthorizationStatusSuccess, self.shippingRates, [self.checkout buy_summaryItemsWithShopName:self.shop.name]); completion(PKPaymentAuthorizationStatusSuccess, self.shippingRates, [self.checkout buy_summaryItemsWithShopName:self.shopName]);
} }
} }
...@@ -357,22 +313,3 @@ const NSTimeInterval PollDelay = 0.5; ...@@ -357,22 +313,3 @@ const NSTimeInterval PollDelay = 0.5;
} }
@end @end
@implementation BUYModelManager (ApplePay)
- (BUYAddress *)buyAddressWithABRecord:(ABRecordRef)addressRecord
{
BUYAddress *address = [self insertAddressWithJSONDictionary:nil];
[address updateWithRecord:addressRecord];
return address;
}
- (BUYAddress *)buyAddressWithContact:(PKContact *)contact
{
BUYAddress *address = [self insertAddressWithJSONDictionary:nil];
[address updateWithContact:contact];
return address;
}
@end
\ No newline at end of file
//
// BUYModelManager+ApplePay.h
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import <Buy/BUYModelManager.h>
@import PassKit;
@class BUYAddress;
@interface BUYModelManager (ApplePay)
/**
* Creates a BUYAddress from an ABRecordRef
*
* @param record ABRecordRef to create a BUYAddress from
*
* @return The BUYAddress created from an ABRecordRef
*/
- (BUYAddress *)buyAddressWithABRecord:(ABRecordRef)addressRecord NS_DEPRECATED_IOS(8_0, 9_0, "Use the CNContact backed `buyAddressWithContact:` instead");
/**
* Creates a BUYAddress from a PKContact
*
* @param contact PKContact to create a BUYAddress from
*
* @return The BUYAddress created from a PKContact
*/
- (BUYAddress *)buyAddressWithContact:(PKContact *)contact NS_AVAILABLE_IOS(9_0);
@end
\ No newline at end of file
//
// BUYModelManager+ApplePay.m
// Mobile Buy SDK
//
// Created by Shopify.
// Copyright (c) 2015 Shopify Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BUYAddress.h"
#import "BUYApplePayAdditions.h"
#import "BUYModelManager+ApplePay.h"
@implementation BUYModelManager (ApplePay)
- (BUYAddress *)buyAddressWithABRecord:(ABRecordRef)addressRecord
{
BUYAddress *address = [self insertAddressWithJSONDictionary:nil];
[address updateWithRecord:addressRecord];
return address;
}
- (BUYAddress *)buyAddressWithContact:(PKContact *)contact
{
BUYAddress *address = [self insertAddressWithJSONDictionary:nil];
[address updateWithContact:contact];
return address;
}
@end
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