diff --git a/Mobile Buy SDK/Mobile Buy SDK/Product View/BUYProductViewController.h b/Mobile Buy SDK/Mobile Buy SDK/Product View/BUYProductViewController.h index c49df6d..23522b6 100644 --- a/Mobile Buy SDK/Mobile Buy SDK/Product View/BUYProductViewController.h +++ b/Mobile Buy SDK/Mobile Buy SDK/Product View/BUYProductViewController.h @@ -76,13 +76,6 @@ @property (nonatomic, assign, readonly) BOOL isLoading; /** - * If the merchantId is set and the device support Apple Pay but no credit card is present this allows the user to add a payment pass to the Wallet. - * The user is given the option to add a payment pass or continue with web checkout. Default is set to true. The Set Up Apple Pay button will, however - * still only show if [PKAddPaymentPassViewController canAddPaymentPass] returns true, merchantId is set and the app is running iOS 9.0 and above. - */ -@property (nonatomic, assign) BOOL allowApplePaySetup; - -/** * This is a convenience method as an alternative to presentViewController: which will force portrait orientation. This method is only * required when presenting from a landscape view controller. * diff --git a/Mobile Buy SDK/Mobile Buy SDK/Product View/BUYProductViewController.m b/Mobile Buy SDK/Mobile Buy SDK/Product View/BUYProductViewController.m index 0772666..b7ba8a5 100644 --- a/Mobile Buy SDK/Mobile Buy SDK/Product View/BUYProductViewController.m +++ b/Mobile Buy SDK/Mobile Buy SDK/Product View/BUYProductViewController.m @@ -128,7 +128,7 @@ CGFloat const BUYMaxProductViewHeight = 640.0; - (BUYProductView *)productView { if (_productView == nil && self.product != nil && self.shop != nil) { - _productView = [[BUYProductView alloc] initWithFrame:CGRectMake(0, 0, self.preferredContentSize.width, self.preferredContentSize.height) product:self.product theme:self.theme shouldShowApplePaySetup:self.allowApplePaySetup]; + _productView = [[BUYProductView alloc] initWithFrame:CGRectMake(0, 0, self.preferredContentSize.width, self.preferredContentSize.height) product:self.product theme:self.theme shouldShowApplePaySetup:self.shouldShowApplePaySetup]; _productView.translatesAutoresizingMaskIntoConstraints = NO; _productView.hidden = YES; [self.view addSubview:_productView]; @@ -149,26 +149,6 @@ CGFloat const BUYMaxProductViewHeight = 640.0; return _productView; } -- (BOOL)canShowApplePaySetup -{ - PKPassLibrary *passLibrary = [[PKPassLibrary alloc] init]; - if (self.allowApplePaySetup == YES && - // Check that it's running iOS 9.0 or above - [passLibrary respondsToSelector:@selector(canAddPaymentPassWithPrimaryAccountIdentifier:)] && - // Check if the device can add a payment pass - [PKPaymentAuthorizationViewController canMakePayments] && - // Check that Apple Pay is enabled for the merchant - [self.merchantId length]) { - return YES; - } else { - return NO; - } -} - -- (BOOL)shouldShowApplePayButton { - return self.isApplePayAvailable ? self.isApplePayAvailable : [self canShowApplePaySetup]; -} - - (CGSize)preferredContentSize { return CGSizeMake(MIN(BUYMaxProductViewWidth, self.view.bounds.size.width), diff --git a/Mobile Buy SDK/Mobile Buy SDK/View Controllers/BUYViewController.h b/Mobile Buy SDK/Mobile Buy SDK/View Controllers/BUYViewController.h index 44017ab..2c78128 100644 --- a/Mobile Buy SDK/Mobile Buy SDK/View Controllers/BUYViewController.h +++ b/Mobile Buy SDK/Mobile Buy SDK/View Controllers/BUYViewController.h @@ -171,6 +171,36 @@ @property (nonatomic, assign, readonly) BOOL isApplePayAvailable; /** + * If the merchantId is set and the device support Apple Pay but no credit card is present this allows the user to add a payment pass to the Wallet. + * The user is given the option to add a payment pass or continue with web checkout. Default is set to true. The Set Up Apple Pay button will, however + * still only show if [PKAddPaymentPassViewController canAddPaymentPass] returns true, merchantId is set and the app is running iOS 9.0 and above. + */ +@property (nonatomic, assign) BOOL allowApplePaySetup; + +/** + * Whether the device is setup to show the Apple Pay setup sheet. + * `allowApplePaySetup` must be set to YES, and the `merchantId` must also be set in addition to the + * device settings for this method to return YES. + * + * @return YES if the Setup Apple Pay button should be shown + */ +- (BOOL)canShowApplePaySetup; + +/** + * Returns whether the Apple Pay button should be shown + * + * @return YES if `isApplePayAvailable` or `canShowApplePaySetup` returns YES + */ +- (BOOL)shouldShowApplePayButton; + +/** + * Returns whether to show the Apple Pay setup button in place of the Apple Pay buy button + * + * @return YES if `isApplePayAvailable` returns NO and `canShowApplePaySetup` returns YES + */ +- (BOOL)shouldShowApplePaySetup; + +/** * The current checkout object */ @property (nonatomic, strong, readonly) BUYCheckout *checkout; diff --git a/Mobile Buy SDK/Mobile Buy SDK/View Controllers/BUYViewController.m b/Mobile Buy SDK/Mobile Buy SDK/View Controllers/BUYViewController.m index ffc9e26..6b3febf 100644 --- a/Mobile Buy SDK/Mobile Buy SDK/View Controllers/BUYViewController.m +++ b/Mobile Buy SDK/Mobile Buy SDK/View Controllers/BUYViewController.m @@ -102,6 +102,22 @@ NSString * BUYURLKey = @"url"; }]; } +- (BOOL)canShowApplePaySetup +{ + PKPassLibrary *passLibrary = [[PKPassLibrary alloc] init]; + if (self.allowApplePaySetup == YES && + // Check that it's running iOS 9.0 or above + [passLibrary respondsToSelector:@selector(canAddPaymentPassWithPrimaryAccountIdentifier:)] && + // Check if the device can add a payment pass + [PKPaymentAuthorizationViewController canMakePayments] && + // Check that Apple Pay is enabled for the merchant + [self.merchantId length]) { + return YES; + } else { + return NO; + } +} + - (BOOL)isApplePayAvailable { // checks if the client is setup to use Apple Pay @@ -112,6 +128,15 @@ NSString * BUYURLKey = @"url"; [PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:self.supportedNetworks]); } +- (BOOL)shouldShowApplePayButton { + return self.isApplePayAvailable || [self canShowApplePaySetup]; +} + +- (BOOL)shouldShowApplePaySetup +{ + return self.isApplePayAvailable == NO && [self canShowApplePaySetup]; +} + #pragma mark - Checkout Flow Methods #pragma mark - Step 1 - Creating or updating a Checkout