Commit 5801c8bc by Brent Gulanowski

Add payment providers.

parent f3321e31
......@@ -145,6 +145,24 @@
84B0A71E1CDD253A00253EB0 /* orders.json in Resources */ = {isa = PBXBuildFile; fileRef = 84B0A71D1CDD253A00253EB0 /* orders.json */; };
84B0A7201CDD261100253EB0 /* BUYSerializable.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A71F1CDD261100253EB0 /* BUYSerializable.m */; };
84B0A7211CDD261100253EB0 /* BUYSerializable.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A71F1CDD261100253EB0 /* BUYSerializable.m */; };
84B0A7301CE10ED900253EB0 /* BUYApplePayPaymentProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A7291CE10ED900253EB0 /* BUYApplePayPaymentProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A7311CE10ED900253EB0 /* BUYApplePayPaymentProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A7291CE10ED900253EB0 /* BUYApplePayPaymentProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A7321CE10ED900253EB0 /* BUYApplePayPaymentProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A72A1CE10ED900253EB0 /* BUYApplePayPaymentProvider.m */; };
84B0A7331CE10ED900253EB0 /* BUYApplePayPaymentProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A72A1CE10ED900253EB0 /* BUYApplePayPaymentProvider.m */; };
84B0A7341CE10ED900253EB0 /* BUYPaymentController.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A72B1CE10ED900253EB0 /* BUYPaymentController.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A7351CE10ED900253EB0 /* BUYPaymentController.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A72B1CE10ED900253EB0 /* BUYPaymentController.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A7361CE10ED900253EB0 /* BUYPaymentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A72C1CE10ED900253EB0 /* BUYPaymentController.m */; };
84B0A7371CE10ED900253EB0 /* BUYPaymentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A72C1CE10ED900253EB0 /* BUYPaymentController.m */; };
84B0A7381CE10ED900253EB0 /* BUYPaymentProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A72D1CE10ED900253EB0 /* BUYPaymentProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A7391CE10ED900253EB0 /* BUYPaymentProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A72D1CE10ED900253EB0 /* BUYPaymentProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A73A1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A72E1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A73B1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A72E1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A73C1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A72F1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.m */; };
84B0A73D1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A72F1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.m */; };
84B0A7401CE10F8100253EB0 /* BUYClient+Checkout.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A73E1CE10F8100253EB0 /* BUYClient+Checkout.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A7411CE10F8100253EB0 /* BUYClient+Checkout.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B0A73E1CE10F8100253EB0 /* BUYClient+Checkout.h */; settings = {ATTRIBUTES = (Public, ); }; };
84B0A7421CE10F8100253EB0 /* BUYClient+Checkout.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A73F1CE10F8100253EB0 /* BUYClient+Checkout.m */; };
84B0A7431CE10F8100253EB0 /* BUYClient+Checkout.m in Sources */ = {isa = PBXBuildFile; fileRef = 84B0A73F1CE10F8100253EB0 /* BUYClient+Checkout.m */; };
84CD7C2D1CC65D5A00B6EE61 /* _BUYCheckoutAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 84CD7C2B1CC65D5500B6EE61 /* _BUYCheckoutAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; };
84CD7C2E1CC65D5A00B6EE61 /* _BUYCheckoutAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 84CD7C2B1CC65D5500B6EE61 /* _BUYCheckoutAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; };
84CD7C2F1CC65D7B00B6EE61 /* _BUYCheckoutAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CD7C2C1CC65D5500B6EE61 /* _BUYCheckoutAttribute.m */; };
......@@ -619,6 +637,15 @@
8498DCC81CDD208200BD12A8 /* TestModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestModel.m; sourceTree = "<group>"; };
84B0A71D1CDD253A00253EB0 /* orders.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = orders.json; sourceTree = "<group>"; };
84B0A71F1CDD261100253EB0 /* BUYSerializable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYSerializable.m; sourceTree = "<group>"; };
84B0A7291CE10ED900253EB0 /* BUYApplePayPaymentProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYApplePayPaymentProvider.h; sourceTree = "<group>"; };
84B0A72A1CE10ED900253EB0 /* BUYApplePayPaymentProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYApplePayPaymentProvider.m; sourceTree = "<group>"; };
84B0A72B1CE10ED900253EB0 /* BUYPaymentController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYPaymentController.h; sourceTree = "<group>"; };
84B0A72C1CE10ED900253EB0 /* BUYPaymentController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYPaymentController.m; sourceTree = "<group>"; };
84B0A72D1CE10ED900253EB0 /* BUYPaymentProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYPaymentProvider.h; sourceTree = "<group>"; };
84B0A72E1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BUYWebCheckoutPaymentProvider.h; sourceTree = "<group>"; };
84B0A72F1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BUYWebCheckoutPaymentProvider.m; sourceTree = "<group>"; };
84B0A73E1CE10F8100253EB0 /* BUYClient+Checkout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BUYClient+Checkout.h"; sourceTree = "<group>"; };
84B0A73F1CE10F8100253EB0 /* BUYClient+Checkout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "BUYClient+Checkout.m"; sourceTree = "<group>"; };
84CD7C2B1CC65D5500B6EE61 /* _BUYCheckoutAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _BUYCheckoutAttribute.h; sourceTree = "<group>"; };
84CD7C2C1CC65D5500B6EE61 /* _BUYCheckoutAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _BUYCheckoutAttribute.m; sourceTree = "<group>"; };
84D73BFE1CDD1931000F978A /* _BUYAddress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _BUYAddress.h; sourceTree = "<group>"; };
......@@ -1022,6 +1049,22 @@
path = "Value Transformers";
sourceTree = "<group>";
};
84B0A7281CE10ED900253EB0 /* Payment Providers */ = {
isa = PBXGroup;
children = (
84B0A73E1CE10F8100253EB0 /* BUYClient+Checkout.h */,
84B0A73F1CE10F8100253EB0 /* BUYClient+Checkout.m */,
84B0A7291CE10ED900253EB0 /* BUYApplePayPaymentProvider.h */,
84B0A72A1CE10ED900253EB0 /* BUYApplePayPaymentProvider.m */,
84B0A72B1CE10ED900253EB0 /* BUYPaymentController.h */,
84B0A72C1CE10ED900253EB0 /* BUYPaymentController.m */,
84B0A72D1CE10ED900253EB0 /* BUYPaymentProvider.h */,
84B0A72E1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.h */,
84B0A72F1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.m */,
);
path = "Payment Providers";
sourceTree = "<group>";
};
906CF1AE1B8B660F001F7D5B /* PKContact Test Objects */ = {
isa = PBXGroup;
children = (
......@@ -1297,11 +1340,12 @@
F773749F19C77E4E0039681C /* Classes */ = {
isa = PBXGroup;
children = (
841ADDEA1CB6C942000004B0 /* Additions */,
90DA8DF11BC6A82D0027BCB7 /* Buy.h */,
841ADDEA1CB6C942000004B0 /* Additions */,
F7FDA16F19C93F6100AF4E93 /* Data */,
F773744419C779C20039681C /* Models */,
90FC31AB1B50589800AFAB51 /* Product View */,
84B0A7281CE10ED900253EB0 /* Payment Providers */,
F773744519C779C20039681C /* Utils */,
84980F491CB760FA00CFAB58 /* Value Transformers */,
BE1C4DF21AE98F8E00E21624 /* View Controllers */,
......@@ -1341,6 +1385,7 @@
84DD129D1CC63FE600A2442D /* _BUYCollection.h in Headers */,
84DD12A11CC63FE600A2442D /* _BUYImageLink.h in Headers */,
84DD12A51CC63FE600A2442D /* _BUYOption.h in Headers */,
84B0A7411CE10F8100253EB0 /* BUYClient+Checkout.h in Headers */,
84D73C041CDD1945000F978A /* _BUYAddress.h in Headers */,
84DD12C31CC63FEE00A2442D /* _BUYDiscount.h in Headers */,
84DD12A71CC63FE600A2442D /* _BUYOptionValue.h in Headers */,
......@@ -1369,8 +1414,10 @@
901931371BC5B9BC00D1134E /* BUYTaxLine.h in Headers */,
901931381BC5B9BC00D1134E /* BUYVariantSelectionViewController.h in Headers */,
901931391BC5B9BC00D1134E /* BUYOptionValueCell.h in Headers */,
84B0A7351CE10ED900253EB0 /* BUYPaymentController.h in Headers */,
9019313A1BC5B9BC00D1134E /* BUYImageLink.h in Headers */,
9019313B1BC5B9BC00D1134E /* BUYOptionValue.h in Headers */,
84B0A7311CE10ED900253EB0 /* BUYApplePayPaymentProvider.h in Headers */,
9019313C1BC5B9BC00D1134E /* BUYShop.h in Headers */,
9019313D1BC5B9BC00D1134E /* BUYShippingRate.h in Headers */,
9019313E1BC5B9BC00D1134E /* BUYApplePayAdditions.h in Headers */,
......@@ -1391,6 +1438,7 @@
84980F2D1CB75B5E00CFAB58 /* BUYModelManagerProtocol.h in Headers */,
84D73C051CDD1945000F978A /* BUYAddress.h in Headers */,
901931451BC5B9BC00D1134E /* UIFont+BUYAdditions.h in Headers */,
84B0A73B1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.h in Headers */,
841ADE081CB6C942000004B0 /* NSDateFormatter+BUYAdditions.h in Headers */,
841ADE001CB6C942000004B0 /* NSArray+BUYAdditions.h in Headers */,
841ADE101CB6C942000004B0 /* NSDictionary+BUYAdditions.h in Headers */,
......@@ -1435,6 +1483,7 @@
901931691BC5B9BC00D1134E /* BUYProduct.h in Headers */,
9019316A1BC5B9BC00D1134E /* BUYSerializable.h in Headers */,
9019316B1BC5B9BC00D1134E /* BUYProductVariant.h in Headers */,
84B0A7391CE10ED900253EB0 /* BUYPaymentProvider.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1455,6 +1504,7 @@
84DD12911CC63FE600A2442D /* _BUYOrder.h in Headers */,
84DD12811CC63FE600A2442D /* _BUYCart.h in Headers */,
84DD12851CC63FE600A2442D /* _BUYCollection.h in Headers */,
84B0A7401CE10F8100253EB0 /* BUYClient+Checkout.h in Headers */,
84D73C021CDD1944000F978A /* _BUYAddress.h in Headers */,
84DD12891CC63FE600A2442D /* _BUYImageLink.h in Headers */,
84DD128D1CC63FE600A2442D /* _BUYOption.h in Headers */,
......@@ -1483,8 +1533,10 @@
BEB74A7D1B5564870005A300 /* BUYVariantSelectionViewController.h in Headers */,
BE10079B1B6165EC0031CEE7 /* BUYOptionValueCell.h in Headers */,
BE9A64591B503CD40033E558 /* BUYImageLink.h in Headers */,
84B0A7341CE10ED900253EB0 /* BUYPaymentController.h in Headers */,
BE9A64681B503D080033E558 /* BUYOptionValue.h in Headers */,
BE9A64661B503D010033E558 /* BUYShop.h in Headers */,
84B0A7301CE10ED900253EB0 /* BUYApplePayPaymentProvider.h in Headers */,
BE9A644D1B503CA20033E558 /* BUYShippingRate.h in Headers */,
BE9A646C1B503D180033E558 /* BUYApplePayAdditions.h in Headers */,
906EAE431B836DE000976165 /* BUYTheme+Additions.h in Headers */,
......@@ -1505,6 +1557,7 @@
84980F2C1CB75B5E00CFAB58 /* BUYModelManagerProtocol.h in Headers */,
84D73C031CDD1944000F978A /* BUYAddress.h in Headers */,
841ADE131CB6C942000004B0 /* NSException+BUYAdditions.h in Headers */,
84B0A73A1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.h in Headers */,
841ADE031CB6C942000004B0 /* NSDate+BUYAdditions.h in Headers */,
841ADE071CB6C942000004B0 /* NSDateFormatter+BUYAdditions.h in Headers */,
841ADDFF1CB6C942000004B0 /* NSArray+BUYAdditions.h in Headers */,
......@@ -1549,6 +1602,7 @@
BE9A64611B503CEF0033E558 /* BUYProduct.h in Headers */,
BE9A64651B503CFE0033E558 /* BUYSerializable.h in Headers */,
BE9A64631B503CF70033E558 /* BUYProductVariant.h in Headers */,
84B0A7381CE10ED900253EB0 /* BUYPaymentProvider.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -1760,6 +1814,7 @@
901930E91BC5B9BC00D1134E /* BUYProductVariant.m in Sources */,
84D9154E1CC03F1600D334FB /* BUYManagedObject.m in Sources */,
901930EA1BC5B9BC00D1134E /* BUYProductViewController.m in Sources */,
84B0A7331CE10ED900253EB0 /* BUYApplePayPaymentProvider.m in Sources */,
841ADE021CB6C942000004B0 /* NSArray+BUYAdditions.m in Sources */,
901930EC1BC5B9BC00D1134E /* BUYError.m in Sources */,
841ADE0E1CB6C942000004B0 /* NSDecimalNumber+BUYAdditions.m in Sources */,
......@@ -1800,6 +1855,7 @@
901931081BC5B9BC00D1134E /* BUYRuntime.m in Sources */,
84DD12C21CC63FEE00A2442D /* _BUYCheckout.m in Sources */,
901931091BC5B9BC00D1134E /* BUYCart.m in Sources */,
84B0A73D1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.m in Sources */,
9019310A1BC5B9BC00D1134E /* BUYPaymentButton.m in Sources */,
84D915521CC03F1600D334FB /* BUYModelManager.m in Sources */,
84DD129C1CC63FE600A2442D /* _BUYCartLineItem.m in Sources */,
......@@ -1832,7 +1888,9 @@
841ADE061CB6C942000004B0 /* NSDate+BUYAdditions.m in Sources */,
901931181BC5B9BC00D1134E /* BUYGradientView.m in Sources */,
901931191BC5B9BC00D1134E /* BUYViewController.m in Sources */,
84B0A7431CE10F8100253EB0 /* BUYClient+Checkout.m in Sources */,
9019311A1BC5B9BC00D1134E /* BUYImageKit.m in Sources */,
84B0A7371CE10ED900253EB0 /* BUYPaymentController.m in Sources */,
9019311C1BC5B9BC00D1134E /* BUYOption.m in Sources */,
84D73C081CDD194D000F978A /* _BUYAddress.m in Sources */,
9019311D1BC5B9BC00D1134E /* BUYClient.m in Sources */,
......@@ -1911,6 +1969,7 @@
BE9A64641B503CFB0033E558 /* BUYProductVariant.m in Sources */,
84D9154D1CC03F1600D334FB /* BUYManagedObject.m in Sources */,
BEB74A2E1B554E8B0005A300 /* BUYProductViewController.m in Sources */,
84B0A7321CE10ED900253EB0 /* BUYApplePayPaymentProvider.m in Sources */,
841ADE011CB6C942000004B0 /* NSArray+BUYAdditions.m in Sources */,
BE4734101B66C4EF00AA721A /* BUYError.m in Sources */,
841ADE0D1CB6C942000004B0 /* NSDecimalNumber+BUYAdditions.m in Sources */,
......@@ -1951,6 +2010,7 @@
BE9A646F1B503D210033E558 /* BUYRuntime.m in Sources */,
84DD12B41CC63FEE00A2442D /* _BUYCheckout.m in Sources */,
BE9A644A1B503C980033E558 /* BUYCart.m in Sources */,
84B0A73C1CE10ED900253EB0 /* BUYWebCheckoutPaymentProvider.m in Sources */,
BE9A64831B503DB10033E558 /* BUYPaymentButton.m in Sources */,
84D915511CC03F1600D334FB /* BUYModelManager.m in Sources */,
84DD12841CC63FE600A2442D /* _BUYCartLineItem.m in Sources */,
......@@ -1983,7 +2043,9 @@
841ADE051CB6C942000004B0 /* NSDate+BUYAdditions.m in Sources */,
BEB74A661B5564030005A300 /* BUYGradientView.m in Sources */,
BE9A64811B503D9E0033E558 /* BUYViewController.m in Sources */,
84B0A7421CE10F8100253EB0 /* BUYClient+Checkout.m in Sources */,
900E7C851B5DA559006F3C81 /* BUYImageKit.m in Sources */,
84B0A7361CE10ED900253EB0 /* BUYPaymentController.m in Sources */,
BE9A64601B503CEC0033E558 /* BUYOption.m in Sources */,
84D73C061CDD194D000F978A /* _BUYAddress.m in Sources */,
BE9A64481B503C900033E558 /* BUYClient.m in Sources */,
......
......@@ -57,8 +57,14 @@ FOUNDATION_EXPORT const unsigned char BuyVersionString[];
#import <Buy/BUYApplePayAdditions.h>
#import <Buy/BUYApplePayHelpers.h>
#import <Buy/BUYApplePayPaymentProvider.h>
#import <Buy/BUYPaymentController.h>
#import <Buy/BUYPaymentProvider.h>
#import <Buy/BUYWebCheckoutPaymentProvider.h>
#import <Buy/BUYClient.h>
#import <Buy/BUYClient+Customers.h>
#import <Buy/BUYClient+Checkout.h>
#import <Buy/BUYError.h>
#import <Buy/BUYError+BUYAdditions.h>
#import <Buy/BUYManagedObject.h>
......@@ -75,6 +81,7 @@ FOUNDATION_EXPORT const unsigned char BuyVersionString[];
#import <Buy/BUYViewController.h>
#import <Buy/NSArray+BUYAdditions.h>
#import <Buy/NSDate+BUYAdditions.h>
#import <Buy/NSDateFormatter+BUYAdditions.h>
#import <Buy/NSDecimalNumber+BUYAdditions.h>
#import <Buy/NSDictionary+BUYAdditions.h>
......
//
// BUYApplePayPaymentProvider.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 UIKit;
#import "BUYPaymentProvider.h"
extern NSString *const _Nonnull BUYApplePayPaymentProviderId;
@class BUYClient;
@interface BUYApplePayPaymentProvider : NSObject <BUYPaymentProvider>
/**
* Initializer for Apple Pay payment provider
*
* @param client a `BUYClient`
* @param merchantID the merchant ID for Apple Pay
*
* @return an instance of `BUYApplePayPaymentProvider`
*/
- (instancetype _Nullable)initWithClient:(BUYClient * _Nonnull)client merchantID:(NSString * _Nonnull)merchantID NS_DESIGNATED_INITIALIZER;
- (instancetype _Nullable)init NS_UNAVAILABLE;
/**
* The supported credit card payment networks. Default values:
* iOS 8.3: PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa.
* iOS 9.0: PKPaymentNetworkAmex, PKPaymentNetworkDiscover, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa.
*/
@property (nonatomic, copy) NSArray * _Nonnull supportedNetworks;
/**
* The merchant ID required for Apple Pay
*/
@property (nonatomic, copy, readonly) NSString * _Nonnull merchantID;
/**
* 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;
@end
//
// BUYApplePayPaymentProvider.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 PassKit;
#import "BUYApplePayPaymentProvider.h"
#import "BUYCheckout.h"
#import "BUYApplePayHelpers.h"
#import "BUYApplePayAdditions.h"
#import "BUYShop.h"
#import "BUYClient+Checkout.h"
NSString *const BUYApplePayPaymentProviderId = @"BUYApplePayPaymentProviderId";
@interface BUYApplePayPaymentProvider () <PKPaymentAuthorizationViewControllerDelegate>
@property (nonatomic, strong) BUYShop *shop;
@property (nonatomic, strong) BUYApplePayHelpers *applePayHelper;
@property (nonatomic, strong) BUYCheckout *checkout;
@property (nonatomic, assign) PKPaymentAuthorizationStatus paymentAuthorizationStatus;
@property (nonatomic, strong) BUYClient *client;
@property (nonatomic, assign) BOOL inProgress;
@end
@implementation BUYApplePayPaymentProvider
@synthesize delegate;
- (instancetype)initWithClient:(BUYClient *)client merchantID:(NSString *)merchantID
{
NSParameterAssert(client);
NSParameterAssert(merchantID);
self = [super init];
if (self) {
_client = client;
_merchantID = merchantID;
_allowApplePaySetup = YES;
}
return self;
}
- (NSUInteger)hash
{
return self.identifier.hash;
}
- (BOOL)isEqual:(id)object
{
return ([object isKindOfClass:[self class]] && [self.identifier isEqual:[object identifier]]);
}
- (NSString *)identifier
{
return BUYApplePayPaymentProviderId;
}
- (void)startCheckout:(BUYCheckout *)checkout
{
if (self.isInProgress) {
return;
}
self.inProgress = YES;
self.checkout = checkout;
// Default to the failure state, since cancelling a payment would not update the state and thus appear as a success
self.paymentAuthorizationStatus = PKPaymentAuthorizationStatusFailure;
// download the shop
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
[self.client getShop:^(BUYShop *theShop, NSError *error) {
if (error) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailCheckoutWithError:)]) {
[self.delegate paymentProvider:self didFailCheckoutWithError:error];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailCheckoutNotificationKey object:self];
}
else {
self.shop = theShop;
}
dispatch_group_leave(group);
}];
dispatch_group_enter(group);
[self.client handleCheckout:checkout completion:^(BUYCheckout *checkout, NSError *error) {
if (error) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailCheckoutWithError:)]) {
[self.delegate paymentProvider:self didFailCheckoutWithError:error];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailCheckoutNotificationKey object:self];
}
else {
self.checkout = checkout;
}
dispatch_group_leave(group);
}];
// create the checkout on Shopify
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
if (self.shop && self.checkout) {
[self proceedWithApplePay];
}
else {
[self cancelCheckout];
}
});
}
- (void)cancelCheckout
{
self.inProgress = NO;
self.checkout = nil;
}
- (BOOL)isAvailable
{
// checks if the client is setup to use Apple Pay
// checks if device hardware is capable of using Apple Pay
// checks if the device has a payment card setup
return (self.merchantID.length &&
[PKPaymentAuthorizationViewController canMakePayments] &&
[PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:self.supportedNetworks]);
}
- (BOOL)canShowApplePaySetup
{
PKPassLibrary *passLibrary = [[PKPassLibrary alloc] init];
if ([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;
}
}
- (void)proceedWithApplePay
{
self.applePayHelper = [[BUYApplePayHelpers alloc] initWithClient:self.client checkout:self.checkout shop:self.shop];
PKPaymentRequest *request = [self paymentRequest];
request.paymentSummaryItems = [self.checkout buy_summaryItemsWithShopName:self.shop.name];
PKPaymentAuthorizationViewController *controller = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
if (controller) {
controller.delegate = self;
[self.delegate paymentProvider:self wantsControllerPresented:controller];
}
else {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailCheckoutWithError:)]) {
[self.delegate paymentProvider:self didFailCheckoutWithError:nil];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailCheckoutNotificationKey object:self];
}
}
- (PKPaymentRequest *)paymentRequest
{
PKPaymentRequest *paymentRequest = [[PKPaymentRequest alloc] init];
[paymentRequest setMerchantIdentifier:self.merchantID];
[paymentRequest setRequiredBillingAddressFields:PKAddressFieldAll];
[paymentRequest setRequiredShippingAddressFields:self.checkout.requiresShipping ? PKAddressFieldAll : PKAddressFieldEmail|PKAddressFieldPhone];
[paymentRequest setSupportedNetworks:self.supportedNetworks];
[paymentRequest setMerchantCapabilities:PKMerchantCapability3DS];
[paymentRequest setCountryCode:self.shop.country];
[paymentRequest setCurrencyCode:self.shop.currency];
return paymentRequest;
}
- (NSArray *)supportedNetworks
{
if (_supportedNetworks == nil) {
if (&PKPaymentNetworkDiscover != NULL) {
self.supportedNetworks = @[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa, PKPaymentNetworkDiscover];
} else {
self.supportedNetworks = @[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa];
}
}
return _supportedNetworks;
}
#pragma mark - PKPaymentAuthorizationViewControllerDelegate Methods
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion
{
[self.applePayHelper paymentAuthorizationViewController:controller didAuthorizePayment:payment completion:^(PKPaymentAuthorizationStatus status) {
self.paymentAuthorizationStatus = status;
switch (status) {
case PKPaymentAuthorizationStatusFailure:
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailCheckoutWithError:)]) {
[self.delegate paymentProvider:self didFailCheckoutWithError:self.applePayHelper.lastError];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailCheckoutNotificationKey object:self];
break;
case PKPaymentAuthorizationStatusInvalidShippingPostalAddress:
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailToUpdateCheckoutWithError:)]) {
[self.delegate paymentProvider:self didFailToUpdateCheckoutWithError:self.applePayHelper.lastError];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self];
break;
default:
break;
}
completion(status);
}];
}
- (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller
{
[self.delegate paymentProviderWantsControllerDismissed:self];
BUYStatus status = (self.paymentAuthorizationStatus == PKPaymentAuthorizationStatusSuccess) ? BUYStatusComplete : BUYStatusFailed;
if ([self.delegate respondsToSelector:@selector(paymentProvider:didCompleteCheckout:withStatus:)]) {
[self.delegate paymentProvider:self didCompleteCheckout:self.checkout withStatus:status];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidCompleteCheckoutNotificationKey object:self];
self.inProgress = NO;
}
- (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) {
if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailToUpdateCheckoutWithError:)]) {
[self.delegate paymentProvider:self didFailToUpdateCheckoutWithError:self.applePayHelper.lastError];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self];
}
completion(status, summaryItems);
}];
}
-(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) {
if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailToUpdateCheckoutWithError:)]) {
[self.delegate paymentProvider:self didFailToUpdateCheckoutWithError:self.applePayHelper.lastError];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self];
}
completion(status, shippingMethods, summaryItems);
}];
}
- (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) {
if (status == PKPaymentAuthorizationStatusInvalidShippingPostalAddress) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailToUpdateCheckoutWithError:)]) {
[self.delegate paymentProvider:self didFailToUpdateCheckoutWithError:self.applePayHelper.lastError];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey object:self];
}
completion(status, shippingMethods, summaryItems);
}];
}
@end
//
// BUYClient+Checkout.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/Buy.h>
@interface BUYClient (Checkout)
- (NSURLSessionDataTask *)handleCheckout:(BUYCheckout *)checkout completion:(BUYDataCheckoutBlock)completion;
@end
//
// BUYClient+Checkout.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 "BUYClient+Checkout.h"
@implementation BUYClient (Checkout)
- (NSURLSessionDataTask *)handleCheckout:(BUYCheckout *)checkout completion:(BUYDataCheckoutBlock)completion
{
if ([checkout hasToken]) {
return [self updateCheckout:checkout completion:completion];
} else {
return [self createCheckout:checkout completion:completion];
}
}
@end
//
// BUYPaymentController.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 Foundation;
#import "BUYPaymentProvider.h"
@interface BUYPaymentController : NSObject
/**
* The registered payment providers
*/
@property (nonatomic, strong, readonly) NSOrderedSet <id <BUYPaymentProvider>> *providers;
/**
* Register a payment provider
*
* @param paymentProvider a payment provider
*
* @note can only add 1 provider per type
*/
- (void)addPaymentProvider:(id <BUYPaymentProvider>)paymentProvider;
/**
* Convenience method to retrieve a BUYPaymentProvider by the identifier
*
* @param type The identifier for the payment provider
*
* @return The payment provider matching the given identifier
*/
- (id <BUYPaymentProvider>)providerForType:(NSString *)type;
/**
* Start a checkout
*
* @param checkout the `BUYCheckout` to start
* @param type the type of payment provider to use
*/
- (void)startCheckout:(BUYCheckout *)checkout withProviderType:(NSString *)typeIdentifier;
@end
//
// BUYPaymentController.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 "BUYPaymentController.h"
NSString *const BUYPaymentProviderWillStartCheckoutNotificationKey = @"BUYPaymentProviderWillStartCheckoutNotificationKey";
NSString *const BUYPaymentProviderDidDismissCheckoutNotificationKey = @"BUYPaymentProviderDidDismissCheckoutNotificationKey";
NSString *const BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey = @"BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey";
NSString *const BUYPaymentProviderDidFailCheckoutNotificationKey = @"BUYPaymentProviderDidFailCheckoutNotificationKey";
NSString *const BUYPaymentProviderDidCompleteCheckoutNotificationKey = @"BUYPaymentProviderDidCompleteCheckoutNotificationKey";
@interface BUYPaymentController ()
@property (nonatomic, strong) NSMutableOrderedSet <id <BUYPaymentProvider>> *mutableProviders;
@end
@implementation BUYPaymentController
- (void)startCheckout:(BUYCheckout *)checkout withProviderType:(NSString *)typeIdentifier;
{
id <BUYPaymentProvider> provider = [self providerForType:typeIdentifier];
[provider startCheckout:checkout];
}
- (void)addPaymentProvider:(id <BUYPaymentProvider>)paymentProvider
{
if ([self.mutableProviders containsObject:paymentProvider]) {
NSLog(@"Payment provider %@ has already been added", paymentProvider.identifier);
}
[self.mutableProviders addObject:paymentProvider];
}
- (NSSet <id <BUYPaymentProvider>> *)providers
{
return [self.mutableProviders copy];
}
- (NSMutableOrderedSet *)mutableProviders
{
if (_mutableProviders == nil) {
_mutableProviders = [[NSMutableOrderedSet alloc] init];
}
return _mutableProviders;
}
- (id <BUYPaymentProvider>)providerForType:(NSString *)type
{
for (id <BUYPaymentProvider> provider in self.mutableProviders) {
if ([provider.identifier isEqualToString: type]) {
return provider;
}
}
return nil;
}
@end
//
// BUYPaymentProvider.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 UIKit;
#import "BUYClient.h"
@class BUYCheckout;
@protocol BUYPaymentProvider;
extern NSString *const BUYPaymentProviderWillStartCheckoutNotificationKey;
extern NSString *const BUYPaymentProviderDidDismissCheckoutNotificationKey;
extern NSString *const BUYPaymentProviderDidFailToUpdateCheckoutNotificationKey;
extern NSString *const BUYPaymentProviderDidFailCheckoutNotificationKey;
extern NSString *const BUYPaymentProviderDidCompleteCheckoutNotificationKey;
@protocol BUYPaymentProviderDelegate <NSObject>
@required
/**
* Called when a view controller needs to be presented
*
* @param provider the `BUYPaymentProvider`
* @param controller the `UIViewController` to be presented
*/
- (void)paymentProvider:(id <BUYPaymentProvider>)provider wantsControllerPresented:(UIViewController *)controller;
/**
* Called when the view controller
*
* @param provider the `BUYPaymentProvider`
*/
- (void)paymentProviderWantsControllerDismissed:(id <BUYPaymentProvider>)provider;
@optional
/**
* Called when the checkout process has started
*
* @param provider the `BUYPaymentProvider`
*/
- (void)paymentProviderWillStartCheckout:(id <BUYPaymentProvider>)provider;
/**
* Called when the checkout has been dismissed
*
* @param provider the `BUYPaymentProvider`
*/
- (void)paymentProviderDidDismissCheckout:(id <BUYPaymentProvider>)provider;
/**
* Called when a checkout failed to update
*
* @param provider the `BUYPaymentProvider`
* @param error the optional `NSError`
*/
- (void)paymentProvider:(id <BUYPaymentProvider>)provider didFailToUpdateCheckoutWithError:(NSError *)error;
/**
* Called when the checkout failed
*
* @param provider the `BUYPaymentProvider`
* @param error the optional `NSError`
*/
- (void)paymentProvider:(id <BUYPaymentProvider>)provider didFailCheckoutWithError:(NSError *)error;
/**
* Called when the checkout has completed
*
* @param provider the `BUYPaymentProvider`
* @param checkout the `BUYCheckout`
* @param status the `BUYStatus` of the checkout
*/
- (void)paymentProvider:(id <BUYPaymentProvider>)provider didCompleteCheckout:(BUYCheckout *)checkout withStatus:(BUYStatus)status;
@end
@protocol BUYPaymentProvider <NSObject>
/**
* Starts the checkout process
*
* @param checkout the `BUYCheckout`
*/
- (void)startCheckout:(BUYCheckout *)checkout;
/**
* Clears the current checkout in progress
*/
- (void)cancelCheckout;
/**
* The payment type identifier
*/
@property (nonatomic, readonly) NSString *identifier;
/**
* The checkout object. If checkout has started, the checkout token will be set.
*/
@property (nonatomic, readonly) BUYCheckout *checkout;
/**
* Whether the payment provider is currently available given the current device and configuration of the `BUYPaymentProvider`
*/
@property (nonatomic, readonly, getter=isAvailable) BOOL available;
/**
* Returns YES if the checkout is currently in progress. `startPaymentForCheckout` should not be called when a checkout is already in progress
*/
@property (nonatomic, readonly, getter=isInProgress) BOOL inProgress;
/**
* Delegate to receive callback messages
*/
@property (nonatomic, weak) id <BUYPaymentProviderDelegate> delegate;
@end
//
// BUYWebCheckoutPaymentProvider.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 <Foundation/Foundation.h>
#import "BUYPaymentProvider.h"
extern NSString * _Nonnull BUYSafariCallbackURLNotification;
extern NSString * _Nonnull BUYURLKey;
extern NSString * _Nonnull const BUYWebPaymentProviderId;
@interface BUYWebCheckoutPaymentProvider : NSObject <BUYPaymentProvider>
/**
* Web payment provider
*
* @param client a `BUYClient`
*
* @return an instance of `BUYWebCheckoutPaymentProvider`
*/
- (instancetype _Nullable)initWithClient:(BUYClient * _Nonnull)client NS_DESIGNATED_INITIALIZER;
- (instancetype _Nullable)init NS_UNAVAILABLE;
@end
//
// BUYWebCheckoutPaymentProvider.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 "BUYWebCheckoutPaymentProvider.h"
#import "BUYCheckout.h"
#import "BUYClient+Checkout.h"
@import SafariServices;
NSString * BUYSafariCallbackURLNotification = @"kBUYSafariCallbackURLNotification";
NSString * BUYURLKey = @"url";
NSString * const BUYWebPaymentProviderId = @"BUYWebPaymentProviderId";
static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token";
@interface BUYWebCheckoutPaymentProvider () <SFSafariViewControllerDelegate>
@property (nonatomic, strong) BUYCheckout *checkout;
@property (nonatomic, strong) BUYClient *client;
@end
@implementation BUYWebCheckoutPaymentProvider
@synthesize delegate;
- (instancetype)initWithClient:(BUYClient *)client
{
NSParameterAssert(client);
self = [super init];
if (self) {
_client = client;
}
return self;
}
- (BOOL)isInProgress
{
return (self.checkout != nil);
}
- (NSUInteger)hash
{
return self.identifier.hash;
}
- (BOOL)isEqual:(id)object
{
return ([object isKindOfClass:[self class]] && [self.identifier isEqual:[object identifier]]);
}
- (NSString *)identifier
{
return BUYWebPaymentProviderId;
}
- (void)startCheckout:(BUYCheckout *)checkout
{
if (self.isInProgress) {
return;
}
self.checkout = checkout;
[self.client handleCheckout:checkout completion:^(BUYCheckout *checkout, NSError *error) {
[self postCheckoutCompletion:checkout error:error];
}];
}
- (void)cancelCheckout
{
self.checkout = nil;
}
- (void)cancelCheckoutAndNotify
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:BUYSafariCallbackURLNotification object:nil];
if ([self.delegate respondsToSelector:@selector(paymentProviderDidDismissCheckout:)]) {
[self.delegate paymentProviderDidDismissCheckout:self];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidDismissCheckoutNotificationKey object:self];
self.checkout = nil;
}
- (BOOL)isAvailable
{
return YES;
}
- (void)postCheckoutCompletion:(BUYCheckout *)checkout error:(NSError *)error
{
if (self.checkout && error == nil) {
self.checkout = checkout;
if ([self.delegate respondsToSelector:@selector(paymentProviderWillStartCheckout:)]) {
[self.delegate paymentProviderWillStartCheckout:self];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderWillStartCheckoutNotificationKey object:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveCallbackURLNotification:) name:BUYSafariCallbackURLNotification object:nil];
[self openWebCheckout:checkout];
}
else {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didFailCheckoutWithError:)]) {
[self.delegate paymentProvider:self didFailCheckoutWithError:error];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidFailCheckoutNotificationKey object:self];
self.checkout = nil;
}
}
- (void)openWebCheckout:(BUYCheckout *)checkout
{
NSURL *checkoutURL = [self authenticatedWebCheckoutURL:checkout.webCheckoutURL];
if ([SFSafariViewController class]) {
SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:checkoutURL];
safariViewController.delegate = self;
[self.delegate paymentProvider:self wantsControllerPresented:safariViewController];
}
else {
[[UIApplication sharedApplication] openURL:checkoutURL];
}
}
- (NSURL *)authenticatedWebCheckoutURL:(NSURL *)url
{
NSString *customerToken = self.client.customerToken;
if (!customerToken.length) {
return url;
}
NSURLQueryItem *item = [NSURLQueryItem queryItemWithName:WebCheckoutCustomerAccessToken value:customerToken];
NSURLComponents *authenticatedComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES];
authenticatedComponents.queryItems = authenticatedComponents.queryItems ? [authenticatedComponents.queryItems arrayByAddingObject:item] : @[item];
return authenticatedComponents.URL;
}
#pragma mark - Web Checkout delegate methods
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller;
{
[self cancelCheckoutAndNotify];
}
- (void)didReceiveCallbackURLNotification:(NSNotification *)notification
{
NSURL *url = notification.userInfo[BUYURLKey];
[self.client getCompletionStatusOfCheckoutURL:url completion:^(BUYStatus status, NSError *error) {
if ([self.delegate respondsToSelector:@selector(paymentProvider:didCompleteCheckout:withStatus:)]) {
[self.delegate paymentProvider:self didCompleteCheckout:self.checkout withStatus:status];
}
[[NSNotificationCenter defaultCenter] postNotificationName:BUYPaymentProviderDidCompleteCheckoutNotificationKey object:self];
[[NSNotificationCenter defaultCenter] removeObserver:self name:BUYSafariCallbackURLNotification object:nil];
}];
[self.delegate paymentProviderWantsControllerDismissed:self];
self.checkout = nil;
}
@end
......@@ -36,9 +36,6 @@
#import "BUYCartLineItem.h"
#import "BUYCheckout.h"
#import "BUYCheckoutAttribute.h"
#import "BUYClient+Test.h"
#import "BUYClient.h"
#import "BUYClient+Customers.h"
#import "BUYCollection.h"
#import "BUYCreditCard.h"
#import "BUYCustomer.h"
......@@ -56,7 +53,17 @@
#import "BUYShop.h"
#import "BUYTaxLine.h"
#import "BUYApplePayHelpers.h"
#import "BUYApplePayPaymentProvider.h"
#import "BUYPaymentController.h"
#import "BUYPaymentProvider.h"
#import "BUYWebCheckoutPaymentProvider.h"
#import "BUYClient.h"
#import "BUYClient+Customers.h"
#import "BUYClient+Checkout.h"
#import "BUYError.h"
#import "BUYError+BUYAdditions.h"
#import "BUYManagedObject.h"
#import "BUYModelManager.h"
#import "BUYModelManagerProtocol.h"
......
......@@ -35,10 +35,7 @@
#import "BUYApplePayHelpers.h"
#import "BUYDiscount.h"
#import "BUYShop.h"
NSString * BUYSafariCallbackURLNotification = @"kBUYSafariCallbackURLNotification";
NSString * BUYURLKey = @"url";
#import "BUYWebCheckoutPaymentProvider.h"
@interface BUYViewController () <SFSafariViewControllerDelegate>
......
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