Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shopify_iossdk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cemarose
shopify_iossdk
Commits
2e1154ad
Commit
2e1154ad
authored
May 13, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add NSOperation subclasses for completing checkout.
parent
432ddba2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
297 additions
and
0 deletions
+297
-0
project.pbxproj
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
+68
-0
BUYCheckoutOperation.h
... Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.h
+23
-0
BUYCheckoutOperation.m
... Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.m
+146
-0
BUYOperation.h
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYOperation.h
+13
-0
BUYOperation.m
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYOperation.m
+47
-0
No files found.
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
View file @
2e1154ad
This diff is collapsed.
Click to expand it.
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.h
0 → 100644
View file @
2e1154ad
//
// BUYCheckoutOperation.h
// Mobile Buy SDK
//
// Created by Dima Bart on 2016-05-12.
// Copyright © 2016 Shopify Inc. All rights reserved.
//
#import "BUYOperation.h"
@class
BUYClient
;
@class
BUYCheckout
;
@protocol
BUYPaymentToken
;
typedef
void
(
^
BUYOperationCheckoutCompletion
)(
BUYCheckout
*
checkout
,
NSError
*
error
);
@interface
BUYCheckoutOperation
:
BUYOperation
@property
(
strong
,
nonatomic
,
readonly
)
BUYOperationCheckoutCompletion
completion
;
-
(
instancetype
)
initWithCheckout
:(
BUYCheckout
*
)
checkout
token
:(
id
<
BUYPaymentToken
>
)
token
client
:(
BUYClient
*
)
client
completion
:(
BUYOperationCheckoutCompletion
)
completion
;
@end
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.m
0 → 100644
View file @
2e1154ad
//
// BUYCheckoutOperation.m
// Mobile Buy SDK
//
// Created by Dima Bart on 2016-05-12.
// Copyright © 2016 Shopify Inc. All rights reserved.
//
#import "BUYCheckoutOperation.h"
#import "BUYCheckout.h"
#import "BUYClient.h"
@interface
BUYOperation
(
Private
)
-
(
void
)
setExecuting
:(
BOOL
)
executing
;
-
(
void
)
setFinished
:(
BOOL
)
finished
;
@end
@interface
BUYCheckoutOperation
()
@property
(
strong
,
nonatomic
)
BUYCheckout
*
checkout
;
@property
(
strong
,
nonatomic
)
id
<
BUYPaymentToken
>
token
;
@property
(
strong
,
nonatomic
)
BUYClient
*
client
;
@end
@implementation
BUYCheckoutOperation
#pragma mark - Init -
-
(
instancetype
)
initWithCheckout
:(
BUYCheckout
*
)
checkout
token
:(
id
<
BUYPaymentToken
>
)
token
client
:(
BUYClient
*
)
client
completion
:(
BUYOperationCheckoutCompletion
)
completion
{
self
=
[
super
init
];
if
(
self
)
{
_checkout
=
checkout
;
_token
=
token
;
_client
=
client
;
_completion
=
completion
;
}
return
self
;
}
#pragma mark - Actions -
-
(
void
)
finishWithCheckout
:(
BUYCheckout
*
)
checkout
{
[
self
setExecuting
:
NO
];
self
.
completion
(
checkout
,
nil
);
}
-
(
void
)
finishWithError
:(
NSError
*
)
error
{
[
self
setExecuting
:
NO
];
self
.
completion
(
nil
,
error
);
}
-
(
void
)
finishByCancellation
{
[
self
setFinished
:
YES
];
[
self
setExecuting
:
NO
];
}
#pragma mark - Start -
-
(
void
)
start
{
[
super
start
];
[
self
setExecuting
:
YES
];
if
(
self
.
isCancelled
)
{
[
self
finishByCancellation
];
return
;
}
/* ---------------------------------
* Initiate the checkout process by
* sending the checkout object to the
* backend for processing.
*/
[
self
.
client
completeCheckout
:
self
.
checkout
paymentToken
:
self
.
token
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
self
.
isCancelled
)
{
[
self
finishByCancellation
];
return
;
}
else
if
(
checkout
)
{
/* ----------------------------------------
* Recursively poll for checkout completion
* status until we encounter an error or
* get a successful completion status.
*/
[
self
pollUntilCheckoutCompletion
:
^
(
BOOL
success
,
NSError
*
error
)
{
if
(
self
.
isCancelled
)
{
[
self
finishByCancellation
];
return
;
}
else
if
(
success
)
{
/* ---------------------------------
* Finally, after the checkout is
* complete, we'll need to fetch the
* completed checkout object.
*/
[
self
.
client
getCheckout
:
self
.
checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
self
.
isCancelled
)
{
[
self
finishByCancellation
];
return
;
}
else
if
(
checkout
)
{
[
self
finishWithCheckout
:
checkout
];
}
else
{
[
self
finishWithError
:
error
];
}
}];
}
else
{
[
self
finishWithError
:
error
];
}
}];
}
else
{
[
self
finishWithError
:
error
];
}
}];
}
#pragma mark - Requests -
-
(
void
)
pollUntilCheckoutCompletion
:
(
void
(
^
)(
BOOL
success
,
NSError
*
error
))
completion
{
[
self
.
client
getCompletionStatusOfCheckout
:
self
.
checkout
completion
:
^
(
BUYStatus
status
,
NSError
*
error
)
{
if
(
self
.
isCancelled
)
{
[
self
finishByCancellation
];
return
;
}
else
if
(
status
==
BUYStatusComplete
)
{
completion
(
YES
,
nil
);
}
else
if
(
error
)
{
completion
(
NO
,
error
);
}
else
{
dispatch_after
(
dispatch_time
(
DISPATCH_TIME_NOW
,
(
int64_t
)(
0
.
5
*
NSEC_PER_SEC
)),
dispatch_get_main_queue
(),
^
{
[
self
pollUntilCheckoutCompletion
:
completion
];
});
}
}];
}
@end
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYOperation.h
0 → 100644
View file @
2e1154ad
//
// BUYOperation.h
// Mobile Buy SDK
//
// Created by Dima Bart on 2016-05-12.
// Copyright © 2016 Shopify Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface
BUYOperation
:
NSOperation
@end
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYOperation.m
0 → 100644
View file @
2e1154ad
//
// BUYOperation.m
// Mobile Buy SDK
//
// Created by Dima Bart on 2016-05-12.
// Copyright © 2016 Shopify Inc. All rights reserved.
//
#import "BUYOperation.h"
@interface
BUYOperation
()
@property
(
atomic
,
assign
)
BOOL
isExecuting
;
@property
(
atomic
,
assign
)
BOOL
isFinished
;
@end
@implementation
BUYOperation
#pragma mark - Init -
-
(
instancetype
)
init
{
self
=
[
super
init
];
if
(
self
)
{
}
return
self
;
}
#pragma mark - Setters -
-
(
void
)
setExecuting
:
(
BOOL
)
executing
{
[
self
willChangeValueForKey
:
@"isExecuting"
];
self
.
isExecuting
=
executing
;
[
self
didChangeValueForKey
:
@"isExecuting"
];
}
-
(
void
)
setFinished
:
(
BOOL
)
finished
{
[
self
willChangeValueForKey
:
@"isFinished"
];
self
.
isFinished
=
finished
;
[
self
didChangeValueForKey
:
@"isFinished"
];
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment