Commit 75bf8f17 by Brent Gulanowski

Update to the new convenience checkout completion support.

parent 8bae5f42
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
// THE SOFTWARE. // THE SOFTWARE.
// //
#import <Buy/Buy.h> @import Buy;
#import "CheckoutViewController.h" #import "CheckoutViewController.h"
#import "SummaryItemsTableViewCell.h" #import "SummaryItemsTableViewCell.h"
#import "UIButton+PaymentButton.h" #import "UIButton+PaymentButton.h"
...@@ -138,14 +139,8 @@ NSString * const MerchantId = @""; ...@@ -138,14 +139,8 @@ NSString * const MerchantId = @"";
- (void)addCreditCardToCheckout:(void (^)(BOOL success, id<BUYPaymentToken> token))callback - (void)addCreditCardToCheckout:(void (^)(BOOL success, id<BUYPaymentToken> token))callback
{ {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[self.client storeCreditCard:[self creditCard] checkout:self.checkout completion:^(id<BUYPaymentToken> token, NSError *error) { [self.client storeCreditCard:[self creditCard] checkout:self.checkout completion:^(id<BUYPaymentToken> token, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (error == nil && token) { if (error == nil && token) {
NSLog(@"Successfully added credit card to checkout"); NSLog(@"Successfully added credit card to checkout");
} }
else { else {
...@@ -201,40 +196,23 @@ NSString * const MerchantId = @""; ...@@ -201,40 +196,23 @@ NSString * const MerchantId = @"";
}]; }];
} }
#pragma mark Native Checkout #pragma mark - Native Checkout
- (void)checkoutWithCreditCard - (void)checkoutWithCreditCard
{ {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
__weak CheckoutViewController *welf = self; __weak CheckoutViewController *welf = self;
// First, the credit card must be stored on the checkout // First, the credit card must be stored on the checkout
[self addCreditCardToCheckout:^(BOOL success, id<BUYPaymentToken> token) { [self addCreditCardToCheckout:^(BOOL success, id<BUYPaymentToken> token) {
if (success) { if (success) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
// Upon successfully adding the credit card to the checkout, complete checkout must be called immediately
[welf.client completeCheckout:welf.checkout paymentToken:token completion:^(BUYCheckout *checkout, NSError *error) { [welf.client completeCheckout:welf.checkout paymentToken:token completion:^(BUYCheckout *checkout, NSError *error) {
if (error == nil && checkout) { if (error == nil && checkout) {
NSLog(@"Successfully completed checkout"); NSLog(@"Successfully completed checkout");
welf.checkout = checkout; welf.checkout = checkout;
NSOperation *completionOperation = [welf.client getCompletionStatusOfCheckout:checkout completion:^(BUYStatus status, NSError * _Nullable error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (error) {
NSLog(@"Error getting completion status: %@", error);
}
else {
NSLog(@"Successfully got completion status: %lu", (unsigned long)status);
[welf getCompletedCheckout:NULL];
}
}];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[[NSOperationQueue mainQueue] addOperation:completionOperation];
} }
else { else {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
......
...@@ -43,8 +43,8 @@ ...@@ -43,8 +43,8 @@
@property (nonatomic, strong) BUYClient *client; @property (nonatomic, strong) BUYClient *client;
@property (nonatomic, strong) BUYCollection *collection; @property (nonatomic, strong) BUYCollection *collection;
@property (nonatomic, strong) NSArray *products; @property (nonatomic, strong) NSArray *products;
@property (nonatomic, strong) NSURLSessionDataTask *collectionTask; @property (nonatomic, strong) NSOperation *collectionOperation;
@property (nonatomic, strong) NSURLSessionDataTask *checkoutCreationTask; @property (nonatomic, strong) NSOperation *checkoutCreationOperation;
@property (nonatomic, assign) BOOL demoProductViewController; @property (nonatomic, assign) BOOL demoProductViewController;
@property (nonatomic, assign) ThemeStyle themeStyle; @property (nonatomic, assign) ThemeStyle themeStyle;
...@@ -112,8 +112,8 @@ ...@@ -112,8 +112,8 @@
- (void)dealloc - (void)dealloc
{ {
[self.checkoutCreationTask cancel]; [self.checkoutCreationOperation cancel];
[self.collectionTask cancel]; [self.collectionOperation cancel];
} }
- (void)presentCollectionSortOptions:(id)sender - (void)presentCollectionSortOptions:(id)sender
...@@ -160,9 +160,9 @@ ...@@ -160,9 +160,9 @@
- (void)getCollectionWithSortOrder:(BUYCollectionSort)collectionSort - (void)getCollectionWithSortOrder:(BUYCollectionSort)collectionSort
{ {
[self.collectionTask cancel]; [self.collectionOperation cancel];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
self.collectionTask = [self.client getProductsPage:1 inCollection:self.collection.collectionId sortOrder:collectionSort completion:^(NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error) { self.collectionOperation = [self.client getProductsPage:1 inCollection:self.collection.collectionId sortOrder:collectionSort completion:^(NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (error == nil && products) { if (error == nil && products) {
...@@ -279,8 +279,8 @@ ...@@ -279,8 +279,8 @@
- (void)demoNativeFlowWithProduct:(BUYProduct*)product - (void)demoNativeFlowWithProduct:(BUYProduct*)product
{ {
if (self.checkoutCreationTask.state == NSURLSessionTaskStateRunning) { if (self.checkoutCreationOperation.executing) {
[self.checkoutCreationTask cancel]; [self.checkoutCreationOperation cancel];
} }
BUYCart *cart = [self.client.modelManager insertCartWithJSONDictionary:nil]; BUYCart *cart = [self.client.modelManager insertCartWithJSONDictionary:nil];
...@@ -296,7 +296,7 @@ ...@@ -296,7 +296,7 @@
self.client.urlScheme = @"advancedsample://"; self.client.urlScheme = @"advancedsample://";
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
self.checkoutCreationTask = [self.client createCheckout:checkout completion:^(BUYCheckout *checkout, NSError *error) { self.checkoutCreationOperation = [self.client createCheckout:checkout completion:^(BUYCheckout *checkout, NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (error == nil && checkout) { if (error == nil && checkout) {
......
...@@ -351,8 +351,8 @@ ...@@ -351,8 +351,8 @@
9A0B0C831CEB981C0037D68F /* BUYClient+RoutingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C821CEB981C0037D68F /* BUYClient+RoutingTests.m */; }; 9A0B0C831CEB981C0037D68F /* BUYClient+RoutingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C821CEB981C0037D68F /* BUYClient+RoutingTests.m */; };
9A0B0CA21CECC1BC0037D68F /* BUYClient+Checkout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C711CEB52B90037D68F /* BUYClient+Checkout.m */; }; 9A0B0CA21CECC1BC0037D68F /* BUYClient+Checkout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C711CEB52B90037D68F /* BUYClient+Checkout.m */; };
9A0B0CA31CECC1BD0037D68F /* BUYClient+Checkout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C711CEB52B90037D68F /* BUYClient+Checkout.m */; }; 9A0B0CA31CECC1BD0037D68F /* BUYClient+Checkout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C711CEB52B90037D68F /* BUYClient+Checkout.m */; };
9A0B0CA71CED0A860037D68F /* BUYCheckoutOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0B0CA51CED0A860037D68F /* BUYCheckoutOperation.h */; }; 9A0B0CA71CED0A860037D68F /* BUYCheckoutOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0B0CA51CED0A860037D68F /* BUYCheckoutOperation.h */; settings = {ATTRIBUTES = (Public, ); }; };
9A0B0CA81CED0A860037D68F /* BUYCheckoutOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0B0CA51CED0A860037D68F /* BUYCheckoutOperation.h */; }; 9A0B0CA81CED0A860037D68F /* BUYCheckoutOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0B0CA51CED0A860037D68F /* BUYCheckoutOperation.h */; settings = {ATTRIBUTES = (Public, ); }; };
9A0B0CA91CED0A860037D68F /* BUYCheckoutOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0CA61CED0A860037D68F /* BUYCheckoutOperation.m */; }; 9A0B0CA91CED0A860037D68F /* BUYCheckoutOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0CA61CED0A860037D68F /* BUYCheckoutOperation.m */; };
9A0B0CAA1CED0A860037D68F /* BUYCheckoutOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0CA61CED0A860037D68F /* BUYCheckoutOperation.m */; }; 9A0B0CAA1CED0A860037D68F /* BUYCheckoutOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0CA61CED0A860037D68F /* BUYCheckoutOperation.m */; };
9A102D1B1CDD1F960026CC43 /* BUYErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A102D1A1CDD1F960026CC43 /* BUYErrorTests.m */; }; 9A102D1B1CDD1F960026CC43 /* BUYErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A102D1A1CDD1F960026CC43 /* BUYErrorTests.m */; };
......
...@@ -62,6 +62,7 @@ FOUNDATION_EXPORT const unsigned char BuyVersionString[]; ...@@ -62,6 +62,7 @@ FOUNDATION_EXPORT const unsigned char BuyVersionString[];
#import <Buy/BUYPaymentProvider.h> #import <Buy/BUYPaymentProvider.h>
#import <Buy/BUYWebCheckoutPaymentProvider.h> #import <Buy/BUYWebCheckoutPaymentProvider.h>
#import <Buy/BUYCheckoutOperation.h>
#import <Buy/BUYClient.h> #import <Buy/BUYClient.h>
#import <Buy/BUYClient+Address.h> #import <Buy/BUYClient+Address.h>
#import <Buy/BUYClient+Customers.h> #import <Buy/BUYClient+Customers.h>
......
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