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
86047b7a
Commit
86047b7a
authored
May 19, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update checkout operation to wrap 3 calls, update tests.
parent
b5c0b88a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
91 deletions
+72
-91
BUYClientTest.m
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest.m
+2
-2
BUYIntegrationTest.m
Mobile Buy SDK/Mobile Buy SDK Tests/BUYIntegrationTest.m
+4
-65
BUYClient+Checkout.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Checkout.m
+3
-1
BUYClient+Internal.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Internal.h
+2
-0
BUYClient.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
+3
-3
BUYCheckoutOperation.m
... Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.m
+58
-20
No files found.
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest.m
View file @
86047b7a
...
...
@@ -47,7 +47,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
@implementation
BUYClient_Test
-
(
void
)
start
Task
:(
BUYRequestOperation
*
)
task
-
(
void
)
start
Operation
:(
BUYOperation
*
)
operation
{
// Do nothing
}
...
...
@@ -128,7 +128,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
{
BUYCheckout
*
checkout
=
[[
BUYCheckout
alloc
]
initWithModelManager
:
self
.
client
.
modelManager
JSONDictionary
:@{
@"token"
:
@"abcdef"
,
@"payment_due"
:
@0
}];
BUY
Request
Operation
*
task
=
[
self
.
client
completeCheckout
:
checkout
paymentToken
:
nil
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{}];
BUYOperation
*
task
=
[
self
.
client
completeCheckout
:
checkout
paymentToken
:
nil
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{}];
XCTAssertNotNil
(
task
);
}
...
...
Mobile Buy SDK/Mobile Buy SDK Tests/BUYIntegrationTest.m
View file @
86047b7a
...
...
@@ -272,68 +272,13 @@
[
self
.
client
completeCheckout
:
_checkout
paymentToken
:
paymentToken
completion
:^
(
BUYCheckout
*
returnedCheckout
,
NSError
*
error
)
{
XCTAssertNil
(
error
);
XCTAssertNotNil
(
returnedCheckout
);
XCTAssertNotNil
(
returnedCheckout
.
order
);
XCTAssertNotNil
(
returnedCheckout
.
order
.
identifier
);
XCTAssertNotNil
(
returnedCheckout
.
order
.
statusURL
);
XCTAssertNotNil
(
returnedCheckout
.
order
.
name
);
_checkout
=
returnedCheckout
;
[
expectation
fulfill
];
}];
[
self
waitForExpectationsWithTimeout
:
10
handler
:
^
(
NSError
*
error
)
{
XCTAssertNil
(
error
);
}];
}
-
(
void
)
pollUntilCheckoutIsComplete
{
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCheckoutFlowUsingCreditCard_14"
];
}];
__block
BUYStatus
checkoutStatus
=
BUYStatusUnknown
;
__block
NSError
*
checkoutError
=
nil
;
while
(
_checkout
.
token
&&
checkoutStatus
!=
BUYStatusFailed
&&
checkoutStatus
!=
BUYStatusComplete
)
{
NSLog
(
@"Checking completion status..."
);
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getCompletionStatusOfCheckout
:
_checkout
completion
:
^
(
BUYStatus
status
,
NSError
*
error
)
{
XCTAssertNil
(
error
);
checkoutError
=
error
;
checkoutStatus
=
status
;
[
expectation
fulfill
];
}];
[
self
waitForExpectationsWithTimeout
:
10
handler
:
^
(
NSError
*
error
)
{
XCTAssertNil
(
error
);
}];
if
(
checkoutStatus
!=
BUYStatusComplete
)
{
[
NSThread
sleepForTimeInterval
:
0
.
5
f
];
}
}
XCTAssertNil
(
checkoutError
);
XCTAssertEqual
(
checkoutStatus
,
BUYStatusComplete
);
}
-
(
void
)
verifyCompletedCheckout
{
XCTAssertNil
(
_checkout
.
order
.
identifier
);
[
OHHTTPStubs
stubRequestsPassingTest
:
^
BOOL
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
self
shouldUseMocks
];
}
withStubResponse
:
^
OHHTTPStubsResponse
*
_Nonnull
(
NSURLRequest
*
_Nonnull
request
)
{
return
[
OHHTTPStubsResponse
responseWithKey
:
@"testCheckoutFlowUsingCreditCard_15"
];
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getCheckout
:
_checkout
completion
:
^
(
BUYCheckout
*
returnedCheckout
,
NSError
*
error
)
{
XCTAssertNil
(
error
);
XCTAssertNotNil
(
returnedCheckout
);
_checkout
=
returnedCheckout
;
XCTAssertNotNil
(
_checkout
.
order
.
identifier
);
XCTAssertNotNil
(
_checkout
.
order
.
statusURL
);
XCTAssertNotNil
(
_checkout
.
order
.
name
);
[
expectation
fulfill
];
[
self
confirmCreditCard
];
...
...
@@ -994,9 +939,6 @@
[
self
updateCheckout
];
[
self
completeCheckoutWithToken
:[
self
addCreditCardToCheckout
]];
[
self
pollUntilCheckoutIsComplete
];
[
self
verifyCompletedCheckout
];
}
-
(
void
)
testCheckoutWithAPartialAddress
...
...
@@ -1042,9 +984,6 @@
//We use a credit card here because we're not generating apple pay tokens in the tests
id
<
BUYPaymentToken
>
token
=
[
self
addCreditCardToCheckout
];
[
self
completeCheckoutWithToken
:
token
];
[
self
pollUntilCheckoutIsComplete
];
[
self
verifyCompletedCheckout
];
}
-
(
void
)
testCheckoutCreationWithApplicableDiscount
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Checkout.m
View file @
86047b7a
...
...
@@ -164,7 +164,9 @@
}
-
(
BUYOperation
*
)
completeCheckout
:(
BUYCheckout
*
)
checkout
paymentToken
:(
id
<
BUYPaymentToken
>
)
paymentToken
completion
:(
BUYDataCheckoutBlock
)
block
{
return
[[
BUYCheckoutOperation
alloc
]
initWithClient
:
self
checkout
:
checkout
token
:
paymentToken
completion
:
block
];
BUYCheckoutOperation
*
operation
=
[[
BUYCheckoutOperation
alloc
]
initWithClient
:
self
checkout
:
checkout
token
:
paymentToken
completion
:
block
];
[
self
startOperation
:
operation
];
return
operation
;
}
-
(
BUYRequestOperation
*
)
beginCheckout
:(
BUYCheckout
*
)
checkout
paymentToken
:(
id
<
BUYPaymentToken
>
)
paymentToken
completion
:(
BUYDataCheckoutBlock
)
block
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Internal.h
View file @
86047b7a
...
...
@@ -52,4 +52,6 @@ typedef void (^BUYClientRequestJSONCompletion)(NSDictionary *json, NSURLResponse
-
(
BUYStatus
)
statusForStatusCode
:(
NSUInteger
)
statusCode
error
:(
NSError
*
)
error
;
-
(
NSError
*
)
errorFromJSON
:(
NSDictionary
*
)
json
response
:(
NSURLResponse
*
)
response
;
-
(
void
)
startOperation
:(
BUYOperation
*
)
operation
;
@end
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
86047b7a
...
...
@@ -173,9 +173,9 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
#pragma mark - Generic Requests
-
(
void
)
start
Task
:
(
BUYRequestOperation
*
)
task
-
(
void
)
start
Operation
:
(
BUYOperation
*
)
operation
{
[
self
.
requestQueue
addOperation
:
task
];
[
self
.
requestQueue
addOperation
:
operation
];
}
-
(
NSString
*
)
authorizationHeader
...
...
@@ -213,7 +213,7 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
}];
if
(
start
)
{
[
self
start
Task
:
operation
];
[
self
start
Operation
:
operation
];
}
return
operation
;
}
...
...
Mobile Buy SDK/Mobile Buy SDK/Operations/BUYCheckoutOperation.m
View file @
86047b7a
...
...
@@ -36,6 +36,8 @@
-
(
BUYRequestOperation
*
)
getCompletionStatusOfCheckoutToken
:(
NSString
*
)
token
start
:(
BOOL
)
start
completion
:(
BUYDataStatusBlock
)
block
;
-
(
BUYRequestOperation
*
)
getCheckout
:(
BUYCheckout
*
)
checkout
start
:(
BOOL
)
start
completion
:(
BUYDataCheckoutBlock
)
block
;
-
(
void
)
startOperation
:(
BUYOperation
*
)
operation
;
@end
@interface
BUYCheckoutOperation
()
...
...
@@ -44,7 +46,7 @@
@property
(
strong
,
nonatomic
,
readonly
)
id
<
BUYPaymentToken
>
token
;
@property
(
strong
,
nonatomic
,
readonly
)
BUYCheckoutOperationCompletion
completion
;
@property
(
strong
,
nonatomic
,
readonly
)
NSArray
*
operations
;
@property
(
strong
,
nonatomic
)
BUYRequestOperation
*
currentOperation
;
@end
...
...
@@ -87,48 +89,84 @@
-
(
void
)
startExecution
{
if
(
self
.
isCancelled
)
{
return
;
}
[
super
startExecution
];
__weak
typeof
(
self
)
weakSelf
=
self
;
BUYRequestOperation
*
beginOperation
=
[
self
.
client
beginCheckout
:
self
.
checkout
paymentToken
:
self
.
token
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
weakSelf
.
isCancelled
||
!
checkout
)
{
[
weakSelf
cancel
];
BUYRequestOperation
*
beginOperation
=
[
weakSelf
.
client
beginCheckout
:
weakSelf
.
checkout
paymentToken
:
weakSelf
.
token
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
weakSelf
.
isCancelled
)
{
return
;
}
}];
BUYRequestOperation
*
pollingOperation
=
[
self
.
client
getCompletionStatusOfCheckoutToken
:
self
.
checkout
.
token
start
:
NO
completion
:^
(
BUYStatus
status
,
NSError
*
error
)
{
if
(
weakSelf
.
isCancelled
||
status
!=
BUYStatusComplete
)
{
[
weakSelf
cancel
];
if
(
!
checkout
)
{
[
weakSelf
finishWithError
:
error
];
return
;
}
BUYRequestOperation
*
pollOperation
=
[
weakSelf
.
client
getCompletionStatusOfCheckoutToken
:
weakSelf
.
checkout
.
token
start
:
NO
completion
:^
(
BUYStatus
status
,
NSError
*
error
)
{
if
(
weakSelf
.
isCancelled
)
{
return
;
}
if
(
status
!=
BUYStatusComplete
)
{
[
weakSelf
finishWithError
:
error
];
return
;
}
}];
pollingOperation
.
pollingHandler
=
^
BOOL
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
return
response
.
statusCode
==
BUYStatusProcessing
;
};
BUYRequestOperation
*
getOperation
=
[
self
.
client
getCheckout
:
self
.
checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
weakSelf
.
isCancelled
||
!
checkout
)
{
[
weakSelf
cancel
];
BUYRequestOperation
*
getOperation
=
[
weakSelf
.
client
getCheckout
:
weakSelf
.
checkout
start
:
NO
completion
:^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
weakSelf
.
isCancelled
)
{
return
;
}
if
(
checkout
)
{
[
weakSelf
finishWithCheckout
:
checkout
];
}
else
{
[
weakSelf
finishWithError
:
error
];
}
}];
// Update current operation
[
weakSelf
locked
:
^
{
weakSelf
.
currentOperation
=
getOperation
;
}];
NSLog
(
@"Getting completed checkout."
);
[
weakSelf
.
client
startOperation
:
getOperation
];
}];
pollOperation
.
pollingHandler
=
^
BOOL
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSLog
(
@"Polling checkout..."
);
return
response
.
statusCode
==
BUYStatusProcessing
;
};
// Update current operation
[
weakSelf
locked
:
^
{
weakSelf
.
currentOperation
=
pollOperation
;
}];
NSLog
(
@"Starting checkout status polling."
);
[
weakSelf
.
client
startOperation
:
pollOperation
];
}];
// Update current operation
[
self
locked
:
^
{
_operations
=
@[
beginOperation
,
pollingOperation
,
getOperation
]
;
self
.
currentOperation
=
beginOperation
;
}];
[
self
.
client
.
requestQueue
addOperations
:
self
.
operations
waitUntilFinished
:
NO
];
NSLog
(
@"Starting checkout."
);
[
self
.
client
startOperation
:
beginOperation
];
}
-
(
void
)
cancelExecution
{
[
super
cancelExecution
];
for
(
NSOperation
*
operation
in
self
.
operations
)
{
[
operation
cancel
];
}
__block
BUYRequestOperation
*
currentOperation
=
nil
;
[
self
locked
:
^
{
currentOperation
=
self
.
currentOperation
;
}];
[
currentOperation
cancel
];
}
@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