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
91e65606
Commit
91e65606
authored
May 27, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor BUYCheckoutOperation.
parent
e1811bb7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
41 deletions
+65
-41
BUYCheckoutOperation.m
... Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.m
+65
-41
No files found.
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.m
View file @
91e65606
...
...
@@ -37,7 +37,7 @@
@property
(
strong
,
nonatomic
,
readonly
)
id
<
BUYPaymentToken
>
token
;
@property
(
strong
,
nonatomic
,
readonly
)
BUYCheckoutOperationCompletion
completion
;
@property
(
strong
,
atomic
)
BUYRequestOperation
*
currentOperation
;
@property
(
strong
,
atomic
)
NSArray
*
operations
;
@end
...
...
@@ -66,12 +66,22 @@
-
(
void
)
finishWithCheckout
:(
BUYCheckout
*
)
checkout
{
if
(
self
.
isCancelled
)
{
return
;
}
[
self
finishExecution
];
self
.
completion
(
checkout
,
nil
);
}
-
(
void
)
finishWithError
:(
NSError
*
)
error
{
if
(
self
.
isCancelled
)
{
return
;
}
[
self
cancelAllOperations
];
[
self
finishExecution
];
self
.
completion
(
nil
,
error
);
}
...
...
@@ -86,64 +96,78 @@
[
super
startExecution
];
__weak
typeof
(
self
)
weakSelf
=
self
;
BUYRequestOperation
*
beginOperation
=
[
self
createBeginOperation
];
BUYRequestOperation
*
pollOperation
=
[
self
createPollOperation
];
BUYRequestOperation
*
getOperation
=
[
self
createGetOperation
];
BUYRequestOperation
*
beginOperation
=
[
weakSelf
.
client
beginCheckout
:
weakSelf
.
checkout
paymentToken
:
weakSelf
.
token
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
weakSelf
.
isCancelled
)
{
return
;
}
[
pollOperation
addDependency
:
beginOperation
];
[
getOperation
addDependency
:
pollOperation
];
if
(
!
checkout
)
{
[
weakSelf
finishWithError
:
error
];
return
;
}
self
.
operations
=
@[
beginOperation
,
pollOperation
,
getOperation
,
];
BUYRequestOperation
*
pollOperation
=
[
weakSelf
.
client
getCompletionStatusOfCheckoutToken
:
weakSelf
.
checkout
.
token
start
:
NO
completion
:^
(
BUYStatus
status
,
NSError
*
error
)
{
if
(
weakSelf
.
isCancelled
)
{
return
;
}
[
self
startAllOperations
];
}
if
(
status
!=
BUYStatusComplete
)
{
[
weakSelf
finishWithError
:
error
];
return
;
}
-
(
void
)
cancelExecution
{
[
super
cancelExecution
];
[
self
cancelAllOperations
];
}
BUYRequestOperation
*
getOperation
=
[
weakSelf
.
client
getCheckout
:
weakSelf
.
checkout
start
:
NO
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
weakSelf
.
isCancelled
)
{
return
;
#pragma mark - Start / Stop -
-
(
void
)
startAllOperations
{
for
(
BUYRequestOperation
*
operation
in
self
.
operations
)
{
[
self
.
client
startOperation
:
operation
];
}
}
if
(
checkout
)
{
[
weakSelf
finishWithCheckout
:
checkout
];
}
else
{
[
weakSelf
finishWithError
:
error
];
-
(
void
)
cancelAllOperations
{
for
(
BUYRequestOperation
*
operation
in
self
.
operations
)
{
[
operation
cancel
];
}
}];
}
weakSelf
.
currentOperation
=
getOperation
;
#pragma mark - Operations -
[
weakSelf
.
client
startOperation
:
getOperation
];
-
(
BUYRequestOperation
*
)
createBeginOperation
{
return
[
self
.
client
beginCheckout
:
self
.
checkout
paymentToken
:
self
.
token
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
!
checkout
)
{
[
self
finishWithError
:
error
];
}
}];
}
-
(
BUYRequestOperation
*
)
createPollOperation
{
BUYRequestOperation
*
operation
=
[
self
.
client
getCompletionStatusOfCheckoutToken
:
self
.
checkout
.
token
start
:
NO
completion
:^
(
BUYStatus
status
,
NSError
*
error
)
{
if
(
status
!=
BUYStatusComplete
)
{
[
self
finishWithError
:
error
];
}
}];
pollO
peration
.
pollingHandler
=
^
BOOL
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
o
peration
.
pollingHandler
=
^
BOOL
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
return
response
.
statusCode
==
BUYStatusProcessing
;
};
weakSelf
.
currentOperation
=
pollOperation
;
[
weakSelf
.
client
startOperation
:
pollOperation
];
}];
// Update current operation
self
.
currentOperation
=
beginOperation
;
[
self
.
client
startOperation
:
beginOperation
];
return
operation
;
}
-
(
void
)
cancelExecu
tion
-
(
BUYRequestOperation
*
)
createGetOpera
tion
{
[
super
cancelExecution
];
[
self
.
currentOperation
cancel
];
return
[
self
.
client
getCheckout
:
self
.
checkout
start
:
NO
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
checkout
)
{
[
self
finishWithCheckout
:
checkout
];
}
else
{
[
self
finishWithError
:
error
];
}
}];
}
@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