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
edcaa8e9
Commit
edcaa8e9
authored
Jul 22, 2016
by
Brent Gulanowski
Committed by
GitHub
Jul 22, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #267 from Shopify/task/customer-id
Introduce BUYCustomerToken and update APIs
parents
55aad718
ce40c35a
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
239 additions
and
188 deletions
+239
-188
LoginViewController.swift
...pp - Swift/Sample App Customers/LoginViewController.swift
+1
-1
OrdersViewController.swift
...p - Swift/Sample App Customers/OrdersViewController.swift
+1
-1
SignupViewController.swift
...p - Swift/Sample App Customers/SignupViewController.swift
+1
-1
BUYClient+CustomerTests.m
...le Buy SDK/Mobile Buy SDK Tests/BUYClient+CustomerTests.m
+12
-12
BUYClient+RoutingTests.m
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClient+RoutingTests.m
+16
-18
BUYClientTest.m
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest.m
+33
-17
project.pbxproj
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
+8
-8
Buy.h
Mobile Buy SDK/Mobile Buy SDK/Buy.h
+1
-0
BUYClient+Address.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Address.h
+5
-10
BUYClient+Address.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Address.m
+10
-10
BUYClient+Customers.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.h
+12
-18
BUYClient+Customers.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
+25
-27
BUYClient+Routing.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.h
+8
-6
BUYClient+Routing.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.m
+21
-15
BUYClient.h
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.h
+3
-2
BUYClient.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
+2
-1
BUYAccountCredentials.h
Mobile Buy SDK/Mobile Buy SDK/Models/BUYAccountCredentials.h
+1
-0
BUYAccountCredentials.m
Mobile Buy SDK/Mobile Buy SDK/Models/BUYAccountCredentials.m
+5
-0
BUYCustomerToken.h
Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.h
+7
-4
BUYCustomerToken.m
Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.m
+42
-14
contents
... Buy SDK.xcdatamodeld/Mobile Buy SDK.xcdatamodel/contents
+21
-20
BUYWebCheckoutPaymentProvider.m
...Buy SDK/Payment Providers/BUYWebCheckoutPaymentProvider.m
+4
-3
No files found.
Mobile Buy SDK Sample Apps/Customers App - Swift/Sample App Customers/LoginViewController.swift
View file @
edcaa8e9
...
...
@@ -65,7 +65,7 @@ class LoginViewController: UITableViewController {
if
let
customer
=
customer
,
let
token
=
token
{
self
.
clear
()
self
.
delegate
?
.
authenticationDidSucceedForCustomer
(
customer
,
withToken
:
token
)
self
.
delegate
?
.
authenticationDidSucceedForCustomer
(
customer
,
withToken
:
token
.
accessToken
)
}
else
{
self
.
delegate
?
.
authenticationDidFailWithError
(
error
)
}
...
...
Mobile Buy SDK Sample Apps/Customers App - Swift/Sample App Customers/OrdersViewController.swift
View file @
edcaa8e9
...
...
@@ -52,7 +52,7 @@ class OrdersViewController: UIViewController {
}
private
func
loadOrders
()
{
BUYClient
.
sharedClient
.
getOrdersForCustomer
WithID
(
String
(
self
.
customer
.
identifier
))
{
(
orders
,
error
)
in
BUYClient
.
sharedClient
.
getOrdersForCustomer
Callback
{
(
orders
,
error
)
in
if
let
orders
=
orders
{
self
.
orders
=
orders
self
.
tableView
.
reloadData
()
...
...
Mobile Buy SDK Sample Apps/Customers App - Swift/Sample App Customers/SignupViewController.swift
View file @
edcaa8e9
...
...
@@ -73,7 +73,7 @@ class SignupViewController: UITableViewController {
if
let
customer
=
customer
,
let
token
=
token
{
self
.
clear
()
self
.
delegate
?
.
authenticationDidSucceedForCustomer
(
customer
,
withToken
:
token
)
self
.
delegate
?
.
authenticationDidSucceedForCustomer
(
customer
,
withToken
:
token
.
accessToken
)
}
else
{
self
.
delegate
?
.
authenticationDidFailWithError
(
error
)
}
...
...
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClient+CustomerTests.m
View file @
edcaa8e9
...
...
@@ -64,7 +64,7 @@
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
self
.
client
loginCustomerWithCredentials
:[
self
credentialsForLogin
]
callback
:
^
(
BUYCustomer
*
customer
,
BUYCustomerToken
*
token
,
NSError
*
error
)
{
XCTAssertNil
(
error
);
XCTAssertNotNil
(
customer
);
...
...
@@ -87,7 +87,7 @@
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerDuplicateEmail"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForCreation
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForCreation
]
callback
:
^
(
BUYCustomer
*
customer
,
BUYCustomerToken
*
token
,
NSError
*
error
)
{
XCTAssertNil
(
customer
);
XCTAssertNotNil
(
error
);
...
...
@@ -114,7 +114,7 @@
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerInvalidEmailPassword"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForFailure
]
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
[
self
.
client
createCustomerWithCredentials
:[
self
credentialsForFailure
]
callback
:
^
(
BUYCustomer
*
customer
,
BUYCustomerToken
*
token
,
NSError
*
error
)
{
XCTAssertNil
(
customer
);
XCTAssertNotNil
(
error
);
...
...
@@ -149,7 +149,7 @@
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogout"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
logoutCustomer
ID
:
self
.
customer
.
identifier
.
stringValue
c
allback
:
^
(
BUYStatus
status
,
NSError
*
_Nullable
error
)
{
[
self
.
client
logoutCustomer
C
allback
:
^
(
BUYStatus
status
,
NSError
*
_Nullable
error
)
{
XCTAssertNil
(
error
);
XCTAssertEqual
(
status
,
204
);
...
...
@@ -167,7 +167,7 @@
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerGetOrders"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getOrdersForCustomer
WithID
:
self
.
customer
.
identifier
.
stringValue
c
allback
:
^
(
NSArray
<
BUYOrder
*>
*
_Nullable
orders
,
NSError
*
_Nullable
error
)
{
[
self
.
client
getOrdersForCustomer
C
allback
:
^
(
NSArray
<
BUYOrder
*>
*
_Nullable
orders
,
NSError
*
_Nullable
error
)
{
XCTAssertNotNil
(
orders
);
XCTAssertNil
(
error
);
...
...
@@ -186,7 +186,7 @@
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerGetOrder"
useMocks
:[
self
shouldUseMocks
]];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getOrderWithID
:
self
.
customerOrderIDs
.
firstObject
c
ustomerID
:
self
.
customer
.
identifier
.
stringValue
c
allback
:^
(
BUYOrder
*
_Nullable
order
,
NSError
*
_Nullable
error
)
{
[
self
.
client
getOrderWithID
:
self
.
customerOrderIDs
.
firstObject
callback
:
^
(
BUYOrder
*
_Nullable
order
,
NSError
*
_Nullable
error
)
{
XCTAssertNil
(
error
);
XCTAssertTrue
([
order
isKindOfClass
:[
BUYOrder
class
]]);
...
...
@@ -208,7 +208,7 @@
BUYAccountCredentialItem
*
email
=
[
BUYAccountCredentialItem
itemWithEmail
:
self
.
customerEmail
];
BUYAccountCredentials
*
credentials
=
[
BUYAccountCredentials
credentialsWithItems
:@[
email
]];
[
self
.
client
updateCustomerWithCredentials
:
credentials
c
ustomerID
:
self
.
customer
.
identifier
.
stringValue
c
allback
:^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
[
self
.
client
updateCustomerWithCredentials
:
credentials
callback
:
^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
XCTAssertNil
(
error
);
XCTAssertNotNil
(
customer
);
...
...
@@ -231,7 +231,7 @@
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getAddresses
ForCustomerID
:
self
.
customer
.
identifier
.
stringValue
c
allback
:
^
(
NSArray
<
BUYAddress
*>
*
_Nullable
addresses
,
NSError
*
_Nullable
error
)
{
[
self
.
client
getAddresses
C
allback
:
^
(
NSArray
<
BUYAddress
*>
*
_Nullable
addresses
,
NSError
*
_Nullable
error
)
{
XCTAssertNotNil
(
addresses
);
XCTAssertTrue
(
addresses
.
count
>
0
);
...
...
@@ -264,7 +264,7 @@
BUYAddress
*
address
=
[
self
address
];
[
self
.
client
createAddress
:
address
c
ustomerID
:
self
.
customer
.
identifier
.
stringValue
c
allback
:^
(
BUYAddress
*
_Nullable
returnedAddress
,
NSError
*
_Nullable
error
)
{
[
self
.
client
createAddress
:
address
callback
:
^
(
BUYAddress
*
_Nullable
returnedAddress
,
NSError
*
_Nullable
error
)
{
[
OHHTTPStubs
stubUsingResponseWithKey
:
@"testCustomerLogin"
useMocks
:[
self
shouldUseMocks
]];
...
...
@@ -299,7 +299,7 @@
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
getAddressWithID
:
self
.
createdAddress
.
identifier
c
ustomerID
:
self
.
customer
.
identifier
.
stringValue
c
allback
:^
(
BUYAddress
*
_Nullable
address
,
NSError
*
_Nullable
error
)
{
[
self
.
client
getAddressWithID
:
self
.
createdAddress
.
identifier
callback
:
^
(
BUYAddress
*
_Nullable
address
,
NSError
*
_Nullable
error
)
{
XCTAssertNotNil
(
address
);
XCTAssertNil
(
error
);
...
...
@@ -323,7 +323,7 @@
BUYAddress
*
modifiedAddress
=
[
self
addressByModyfyingAddress
:
self
.
createdAddress
];
[
self
.
client
updateAddress
:
modifiedAddress
c
ustomerID
:
self
.
customer
.
identifier
.
stringValue
c
allback
:^
(
BUYAddress
*
_Nullable
returnedAddress
,
NSError
*
_Nullable
error
)
{
[
self
.
client
updateAddress
:
modifiedAddress
callback
:
^
(
BUYAddress
*
_Nullable
returnedAddress
,
NSError
*
_Nullable
error
)
{
XCTAssertNotNil
(
returnedAddress
);
XCTAssertNil
(
error
);
...
...
@@ -353,7 +353,7 @@
}];
XCTestExpectation
*
expectation
=
[
self
expectationWithDescription
:
NSStringFromSelector
(
_cmd
)];
[
self
.
client
deleteAddressWithID
:
self
.
createdAddress
.
identifier
c
ustomerID
:
self
.
customer
.
identifier
.
stringValue
c
allback
:^
(
BUYStatus
status
,
NSError
*
_Nullable
error
)
{
[
self
.
client
deleteAddressWithID
:
self
.
createdAddress
.
identifier
callback
:
^
(
BUYStatus
status
,
NSError
*
_Nullable
error
)
{
XCTAssertEqual
(
status
,
204
);
XCTAssertNil
(
error
);
...
...
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClient+RoutingTests.m
View file @
edcaa8e9
...
...
@@ -26,6 +26,7 @@
#import <XCTest/XCTest.h>
#import "BUYClient+Routing.h"
#import "BUYCustomerToken.h"
@interface
BUYClient_RoutingTests
:
XCTestCase
...
...
@@ -42,13 +43,14 @@
[
super
setUp
];
self
.
client
=
[[
BUYClient
alloc
]
initWithShopDomain
:
@"_DOMAIN_"
apiKey
:
@"_API_KEY_"
appId
:
@"_APP_ID_"
];
self
.
client
.
customerToken
=
[[
BUYCustomerToken
alloc
]
initWithCustomerID
:
@1
accessToken
:
@"token"
expiry
:
[
NSDate
date
]];
}
#pragma mark - Test Routes -
-
(
void
)
testRoutes
{
NSString
*
identifier
=
@"
_ID_
"
;
NSString
*
identifier
=
@"
1
"
;
NSString
*
token
=
@"_TOKEN_"
;
NSDictionary
*
parameters
=
@{
@"param"
:
@"value"
};
...
...
@@ -122,41 +124,37 @@
@"https://_DOMAIN_/api/customers/recover.json"
);
XCTAssertEqualObjects
(
[
self
.
client
urlForCustomersOrders
WithID
:
identifier
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
_ID_
/orders.json"
[
self
.
client
urlForCustomersOrders
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
1
/orders.json"
);
XCTAssertEqualObjects
(
[
self
.
client
urlForCustomersOrdersWith
ID
:
identifier
o
rderID
:
@99
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
_ID_
/orders/99.json"
[
self
.
client
urlForCustomersOrdersWith
O
rderID
:
@99
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
1
/orders/99.json"
);
XCTAssertEqualObjects
(
[
self
.
client
urlForCustomersWithID
:
identifier
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
_ID_
.json"
@"https://_DOMAIN_/api/customers/
1
.json"
);
XCTAssertEqualObjects
(
[
self
.
client
urlForCustomersActivationWithID
:
identifier
parameters
:
parameters
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
_ID_
/activate.json?param=value"
@"https://_DOMAIN_/api/customers/
1
/activate.json?param=value"
);
XCTAssertEqualObjects
(
[
self
.
client
urlForCustomersTokenWithID
:
identifier
].
absoluteString
,
@"https://_DOMAIN_/api/customers/_ID_/customer_token.json"
);
XCTAssertEqualObjects
(
[
self
.
client
urlForCustomersTokenRenewalWithID
:
identifier
].
absoluteString
,
@"https://_DOMAIN_/api/customers/_ID_/customer_token/renew.json"
[
self
.
client
urlForCustomersTokenRenewal
].
absoluteString
,
@"https://_DOMAIN_/api/customers/1/customer_token/renew.json"
);
XCTAssertEqualObjects
(
[
self
.
client
urlForCustomersPasswordResetWithID
:
identifier
parameters
:
parameters
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
_ID_
/reset.json?param=value"
@"https://_DOMAIN_/api/customers/
1
/reset.json?param=value"
);
XCTAssertEqualObjects
(
[
self
.
client
urlForCustomersAddresses
WithID
:
identifier
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
_ID_
/addresses.json"
[
self
.
client
urlForCustomersAddresses
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
1
/addresses.json"
);
XCTAssertEqualObjects
(
[
self
.
client
urlForCustomersAddressWith
ID
:
identifier
a
ddressID
:
@999
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
_ID_
/addresses/999.json"
[
self
.
client
urlForCustomersAddressWith
A
ddressID
:
@999
].
absoluteString
,
@"https://_DOMAIN_/api/customers/
1
/addresses/999.json"
);
}
...
...
Mobile Buy SDK/Mobile Buy SDK Tests/BUYClientTest.m
View file @
edcaa8e9
...
...
@@ -38,8 +38,6 @@
#import "BUYApplePayTestToken.h"
#import "BUYRequestOperation.h"
NSString
*
const
BUYFakeCustomerToken
=
@"dsfasdgafdg"
;
@interface
BUYClient_Test
:
BUYClient
@end
...
...
@@ -58,6 +56,23 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
@implementation
BUYClientTest
-
(
void
)
setUp
{
[
super
setUp
];
self
.
client
.
customerToken
=
[
self
customerTokenForTesting
];
}
-
(
void
)
tearDown
{
self
.
client
.
customerToken
=
nil
;
[
super
tearDown
];
}
-
(
BUYCustomerToken
*
)
customerTokenForTesting
{
return
[[
BUYCustomerToken
alloc
]
initWithCustomerID
:
@1
accessToken
:
@""
expiry
:
[
NSDate
dateWithTimeIntervalSinceNow
:
3600
]];
}
-
(
void
)
setupClient
{
self
.
shopDomain
=
BUYShopDomain_Placeholder
;
...
...
@@ -211,7 +226,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
];
BUYAccountCredentials
*
credentials
=
[
BUYAccountCredentials
credentialsWithItems
:
items
];
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
createCustomerWithCredentials
:
credentials
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
createCustomerWithCredentials
:
credentials
callback
:
^
(
BUYCustomer
*
customer
,
BUYCustomerToken
*
token
,
NSError
*
error
)
{
}];
...
...
@@ -239,7 +254,7 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
[
BUYAccountCredentialItem
itemWithPassword
:
@"password"
],
];
BUYAccountCredentials
*
credentials
=
[
BUYAccountCredentials
credentialsWithItems
:
items
];
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
loginCustomerWithCredentials
:
credentials
callback
:
^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
loginCustomerWithCredentials
:
credentials
callback
:
^
(
BUYCustomer
*
customer
,
BUYCustomerToken
*
token
,
NSError
*
error
)
{
}];
...
...
@@ -260,28 +275,28 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
-
(
void
)
testGetCustomerURL
{
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
getCustomer
WithID
:
@""
c
allback
:
^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
getCustomer
C
allback
:
^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
}];
XCTAssertEqualObjects
(
task
.
originalRequest
.
URL
.
scheme
,
@"https"
);
XCTAssertEqualObjects
(
task
.
originalRequest
.
URL
.
path
,
@"/api/customers.json"
);
XCTAssertEqualObjects
(
task
.
originalRequest
.
URL
.
path
,
@"/api/customers
/1
.json"
);
XCTAssertEqualObjects
(
task
.
originalRequest
.
HTTPMethod
,
@"GET"
);
XCTAssertEqualObjects
(
self
.
client
.
customerToken
,
task
.
originalRequest
.
allHTTPHeaderFields
[
BUYClientCustomerAccessToken
]);
XCTAssertEqualObjects
(
self
.
client
.
customerToken
.
accessToken
,
task
.
originalRequest
.
allHTTPHeaderFields
[
BUYClientCustomerAccessToken
]);
}
-
(
void
)
testGetOrdersForCustomerURL
{
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
getOrdersForCustomer
WithID
:
@"99"
c
allback
:
^
(
NSArray
<
BUYOrder
*>
*
orders
,
NSError
*
error
)
{
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
getOrdersForCustomer
C
allback
:
^
(
NSArray
<
BUYOrder
*>
*
orders
,
NSError
*
error
)
{
}];
XCTAssertEqualObjects
(
task
.
originalRequest
.
URL
.
scheme
,
@"https"
);
XCTAssertEqualObjects
(
task
.
originalRequest
.
URL
.
path
,
@"/api/customers/
99
/orders.json"
);
XCTAssertEqualObjects
(
task
.
originalRequest
.
URL
.
path
,
@"/api/customers/
1
/orders.json"
);
XCTAssertEqualObjects
(
task
.
originalRequest
.
HTTPMethod
,
@"GET"
);
XCTAssertEqualObjects
(
self
.
client
.
customerToken
,
task
.
originalRequest
.
allHTTPHeaderFields
[
BUYClientCustomerAccessToken
]);
XCTAssertEqualObjects
(
self
.
client
.
customerToken
.
accessToken
,
task
.
originalRequest
.
allHTTPHeaderFields
[
BUYClientCustomerAccessToken
]);
}
-
(
void
)
testCustomerRecovery
...
...
@@ -307,11 +322,12 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
{
self
.
client
.
customerToken
=
nil
;
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
renewCustomerToken
WithID
:
@""
callback
:
^
(
NSString
*
token
,
NSError
*
error
)
{}];
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
renewCustomerToken
Callback
:
^
(
BUYCustomerToken
*
token
,
NSError
*
error
)
{}];
XCTAssertNil
(
task
);
// task should be nil if no customer token was set on the client
self
.
client
.
customerToken
=
BUYFakeCustomerToken
;
task
=
(
BUYRequestOperation
*
)[
self
.
client
renewCustomerTokenWithID
:
@"1"
callback
:
^
(
NSString
*
token
,
NSError
*
error
)
{
self
.
client
.
customerToken
=
[[
BUYCustomerToken
alloc
]
initWithCustomerID
:
@1
accessToken
:
@"fake_token"
expiry
:
[
NSDate
dateWithTimeIntervalSinceNow
:
3600
]];
task
=
(
BUYRequestOperation
*
)[
self
.
client
renewCustomerTokenCallback
:
^
(
BUYCustomerToken
*
token
,
NSError
*
error
)
{
}];
...
...
@@ -326,9 +342,9 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
[
BUYAccountCredentialItem
itemWithPassword
:
@"12345"
]
];
BUYAccountCredentials
*
credentials
=
[
BUYAccountCredentials
credentialsWithItems
:
items
];
NS
String
*
customerID
=
@"12345"
;
NS
Number
*
customerID
=
@12345
;
NSString
*
token
=
@"12345"
;
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
activateCustomerWithCredentials
:
credentials
customerID
:
customerID
token
:
token
callback
:^
(
BUYCustomer
*
customer
,
NSString
*
token
,
NSError
*
error
)
{
BUYRequestOperation
*
task
=
(
BUYRequestOperation
*
)[
self
.
client
activateCustomerWithCredentials
:
credentials
customerID
:
customerID
token
:
token
callback
:^
(
BUYCustomer
*
customer
,
BUYCustomerToken
*
token
,
NSError
*
error
)
{
}];
...
...
Mobile Buy SDK/Mobile Buy SDK.xcodeproj/project.pbxproj
View file @
edcaa8e9
...
...
@@ -226,8 +226,8 @@
9A0B0C6D1CEB4D300037D68F
/* BUYClient+Storefront.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C6A1CEB4D300037D68F
/* BUYClient+Storefront.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9A0B0C6F1CEB4D300037D68F
/* BUYClient+Storefront.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C6B1CEB4D300037D68F
/* BUYClient+Storefront.m */
;
};
9A0B0C731CEB52B90037D68F
/* BUYClient+Checkout.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C701CEB52B90037D68F
/* BUYClient+Checkout.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
};
};
9A0B0C791CEB5BBD0037D68F
/* BUY
AuthenticatedResponse.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C761CEB5BBD0037D68F
/* BUYAuthenticatedResponse.h */
;
};
9A0B0C7B1CEB5BBD0037D68F
/* BUY
AuthenticatedResponse.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C771CEB5BBD0037D68F
/* BUYAuthenticatedResponse
.m */
;
};
9A0B0C791CEB5BBD0037D68F
/* BUY
CustomerToken.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C761CEB5BBD0037D68F
/* BUYCustomerToken.h */
;
settings
=
{
ATTRIBUTES
=
(
Public
,
);
}
;
};
9A0B0C7B1CEB5BBD0037D68F
/* BUY
CustomerToken.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0C771CEB5BBD0037D68F
/* BUYCustomerToken
.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 */
;
};
9A0B0CA81CED0A860037D68F
/* BUYCheckoutOperation.h in Headers */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9A0B0CA51CED0A860037D68F
/* BUYCheckoutOperation.h */
;
};
...
...
@@ -470,8 +470,8 @@
9A0B0C6B1CEB4D300037D68F
/* BUYClient+Storefront.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"BUYClient+Storefront.m"
;
sourceTree
=
"<group>"
;
};
9A0B0C701CEB52B90037D68F
/* BUYClient+Checkout.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
"BUYClient+Checkout.h"
;
sourceTree
=
"<group>"
;
};
9A0B0C711CEB52B90037D68F
/* BUYClient+Checkout.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"BUYClient+Checkout.m"
;
sourceTree
=
"<group>"
;
};
9A0B0C761CEB5BBD0037D68F
/* BUY
AuthenticatedResponse.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYAuthenticatedResponse
.h
;
sourceTree
=
"<group>"
;
};
9A0B0C771CEB5BBD0037D68F
/* BUY
AuthenticatedResponse.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYAuthenticatedResponse
.m
;
sourceTree
=
"<group>"
;
};
9A0B0C761CEB5BBD0037D68F
/* BUY
CustomerToken.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYCustomerToken
.h
;
sourceTree
=
"<group>"
;
};
9A0B0C771CEB5BBD0037D68F
/* BUY
CustomerToken.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYCustomerToken
.m
;
sourceTree
=
"<group>"
;
};
9A0B0C821CEB981C0037D68F
/* BUYClient+RoutingTests.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
"BUYClient+RoutingTests.m"
;
sourceTree
=
"<group>"
;
};
9A0B0CA51CED0A860037D68F
/* BUYCheckoutOperation.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
BUYCheckoutOperation.h
;
sourceTree
=
"<group>"
;
};
9A0B0CA61CED0A860037D68F
/* BUYCheckoutOperation.m */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
BUYCheckoutOperation.m
;
sourceTree
=
"<group>"
;
};
...
...
@@ -960,8 +960,8 @@
F773744419C779C20039681C
/* Models */
=
{
isa
=
PBXGroup
;
children
=
(
9A0B0C761CEB5BBD0037D68F
/* BUY
AuthenticatedResponse
.h */
,
9A0B0C771CEB5BBD0037D68F
/* BUY
AuthenticatedResponse
.m */
,
9A0B0C761CEB5BBD0037D68F
/* BUY
CustomerToken
.h */
,
9A0B0C771CEB5BBD0037D68F
/* BUY
CustomerToken
.m */
,
8498DCB91CDD1FA400BD12A8
/* BUYAccountCredentials.h */
,
8498DCBA1CDD1FA400BD12A8
/* BUYAccountCredentials.m */
,
F77374AA19C796BD0039681C
/* BUYCreditCard.h */
,
...
...
@@ -1146,7 +1146,7 @@
9A0B0CA81CED0A860037D68F
/* BUYCheckoutOperation.h in Headers */
,
901931611BC5B9BC00D1134E
/* BUYClient.h in Headers */
,
9A585C0B1CE6440B001F20F0
/* BUYOperation.h in Headers */
,
9A0B0C791CEB5BBD0037D68F
/* BUY
AuthenticatedResponse
.h in Headers */
,
9A0B0C791CEB5BBD0037D68F
/* BUY
CustomerToken
.h in Headers */
,
849810971CB7E07900CFAB58
/* BUYFlatCollectionTransformer.h in Headers */
,
9A6C1DC41D089E4700BFF4F9
/* BUYClientTypes.h in Headers */
,
901931641BC5B9BC00D1134E
/* BUYCartLineItem.h in Headers */
,
...
...
@@ -1332,7 +1332,7 @@
9A0B0CAA1CED0A860037D68F
/* BUYCheckoutOperation.m in Sources */
,
84B0A7211CDD261100253EB0
/* BUYSerializable.m in Sources */
,
9A47CEFE1CE39F6100A6D5BA
/* BUYCreditCardToken.m in Sources */
,
9A0B0C7B1CEB5BBD0037D68F
/* BUY
AuthenticatedResponse
.m in Sources */
,
9A0B0C7B1CEB5BBD0037D68F
/* BUY
CustomerToken
.m in Sources */
,
901930F21BC5B9BC00D1134E
/* BUYOrder.m in Sources */
,
849810991CB7E07900CFAB58
/* BUYFlatCollectionTransformer.m in Sources */
,
84DD12A41CC63FE600A2442D
/* _BUYLineItem.m in Sources */
,
...
...
Mobile Buy SDK/Mobile Buy SDK/Buy.h
View file @
edcaa8e9
...
...
@@ -36,6 +36,7 @@
#import <Buy/BUYCollection.h>
#import <Buy/BUYCreditCard.h>
#import <Buy/BUYCustomer.h>
#import <Buy/BUYCustomerToken.h>
#import <Buy/BUYDiscount.h>
#import <Buy/BUYGiftCard.h>
#import <Buy/BUYImageLink.h>
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Address.h
View file @
edcaa8e9
...
...
@@ -51,60 +51,55 @@ typedef void (^BUYDataAddressBlock)(BUYAddress * _Nullable address, NSError * _N
* GET /api/customers/:customer_id/addresses
* Fetch all customer addresses
*
* @param customerID Customer ID for which to fetch all address
* @param block (NSArray<BUYAddress *> *addresses, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
getAddresses
ForCustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataAddressesBlock
)
block
;
-
(
NSOperation
*
)
getAddresses
C
allback
:(
BUYDataAddressesBlock
)
block
;
/**
* GET /api/customers/:customer_id/addresses/:id
* Fetch a customer address by ID
*
* @param addressID Identifier of the address to fetch
* @param customerID Customer ID for which to fetch the address
* @param block (BUYAddress *address, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
getAddressWithID
:(
NSNumber
*
)
addressID
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataAddressBlock
)
block
;
-
(
NSOperation
*
)
getAddressWithID
:(
NSNumber
*
)
addressID
callback
:(
BUYDataAddressBlock
)
block
;
/**
* POST /api/customers/:customer_id/addresses
* Creates a new customer address
*
* @param address Address to create
* @param customer Customer ID for which to create the address
* @param block (BUYAddress *address, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
createAddress
:(
BUYAddress
*
)
address
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataAddressBlock
)
block
;
-
(
NSOperation
*
)
createAddress
:(
BUYAddress
*
)
address
callback
:(
BUYDataAddressBlock
)
block
;
/**
* PUT /api/customers/:customer_id/addresses/:id
* Updates the customer address
*
* @param address Address to update, containing updated values
* @param customerID Customer ID for which to update the address
* @param block (BUYAddress *address, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
updateAddress
:(
BUYAddress
*
)
address
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataAddressBlock
)
block
;
-
(
NSOperation
*
)
updateAddress
:(
BUYAddress
*
)
address
callback
:(
BUYDataAddressBlock
)
block
;
/**
* DELETE /api/customers/:customer_id/addresses/:id
* Delete the customer address
*
* @param addressID Address ID to delete
* @param customerID Customer ID for which to delete the address
* @param block (BUYStatus status, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
deleteAddressWithID
:(
NSNumber
*
)
addressID
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataStatusBlock
)
block
;
-
(
NSOperation
*
)
deleteAddressWithID
:(
NSNumber
*
)
addressID
callback
:(
BUYDataStatusBlock
)
block
;
@end
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Address.m
View file @
edcaa8e9
...
...
@@ -33,9 +33,9 @@
@implementation
BUYClient
(
Address
)
-
(
NSOperation
*
)
getAddresses
ForCustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataAddressesBlock
)
block
-
(
NSOperation
*
)
getAddresses
C
allback
:(
BUYDataAddressesBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersAddresses
WithID
:
customerID
];
NSURL
*
route
=
[
self
urlForCustomersAddresses
];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSArray
<
BUYAddress
*>
*
addresses
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -45,9 +45,9 @@
}];
}
-
(
NSOperation
*
)
getAddressWithID
:(
NSNumber
*
)
addressID
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataAddressBlock
)
block
-
(
NSOperation
*
)
getAddressWithID
:(
NSNumber
*
)
addressID
callback
:(
BUYDataAddressBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersAddressWith
ID
:
customerID
a
ddressID
:
addressID
];
NSURL
*
route
=
[
self
urlForCustomersAddressWith
A
ddressID
:
addressID
];
return
[
self
getRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
BUYAddress
*
address
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -57,9 +57,9 @@
}];
}
-
(
NSOperation
*
)
createAddress
:(
BUYAddress
*
)
address
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataAddressBlock
)
block
-
(
NSOperation
*
)
createAddress
:(
BUYAddress
*
)
address
callback
:(
BUYDataAddressBlock
)
block
{
NSURL
*
route
=
[
self
urlForCustomersAddresses
WithID
:
customerID
];
NSURL
*
route
=
[
self
urlForCustomersAddresses
];
return
[
self
postRequestForURL
:
route
object
:@{
@"address"
:
address
.
JSONDictionary
}
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
BUYAddress
*
address
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -69,11 +69,11 @@
}];
}
-
(
NSOperation
*
)
updateAddress
:(
BUYAddress
*
)
address
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataAddressBlock
)
block
-
(
NSOperation
*
)
updateAddress
:(
BUYAddress
*
)
address
callback
:(
BUYDataAddressBlock
)
block
{
BUYAssert
(
address
.
identifier
,
@"Failed to update address. Address must have a valid identifier."
);
NSURL
*
route
=
[
self
urlForCustomersAddressWith
ID
:
customerID
a
ddressID
:
address
.
identifier
];
NSURL
*
route
=
[
self
urlForCustomersAddressWith
A
ddressID
:
address
.
identifier
];
return
[
self
putRequestForURL
:
route
object
:@{
@"address"
:
address
.
JSONDictionary
}
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
BUYAddress
*
address
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -83,11 +83,11 @@
}];
}
-
(
NSOperation
*
)
deleteAddressWithID
:(
NSNumber
*
)
addressID
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataStatusBlock
)
block
-
(
NSOperation
*
)
deleteAddressWithID
:(
NSNumber
*
)
addressID
callback
:(
BUYDataStatusBlock
)
block
{
BUYAssert
(
addressID
,
@"Failed to update address. Address must have a valid identifier."
);
NSURL
*
route
=
[
self
urlForCustomersAddressWith
ID
:
customerID
a
ddressID
:
addressID
];
NSURL
*
route
=
[
self
urlForCustomersAddressWith
A
ddressID
:
addressID
];
return
[
self
deleteRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
block
(
response
.
statusCode
,
error
);
}];
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.h
View file @
edcaa8e9
...
...
@@ -27,9 +27,10 @@
#import <Buy/BUYClient.h>
NS_ASSUME_NONNULL_BEGIN
@class
BUYAccountCredentials
;
@class
BUYCustomer
;
@class
BUYCustomerToken
;
@class
BUYOrder
;
@class
BUYAccountCredentials
;
/**
* Return block containing a BUYCustomer object for an existing customer of the shop
...
...
@@ -46,7 +47,7 @@ typedef void (^BUYDataCustomerBlock)(BUYCustomer * _Nullable customer, NSError *
* @param token An authentication token to retrieve the customer later. Store this token securely on the device.
* @param error An optional NSError
*/
typedef
void
(
^
BUYDataCustomerTokenBlock
)(
BUYCustomer
*
_Nullable
customer
,
NSString
*
_Nullable
token
,
NSError
*
_Nullable
error
);
typedef
void
(
^
BUYDataCustomerTokenBlock
)(
BUYCustomer
*
_Nullable
customer
,
BUYCustomerToken
*
_Nullable
token
,
NSError
*
_Nullable
error
);
/**
* Return block containing a customer auth token
...
...
@@ -54,7 +55,7 @@ typedef void (^BUYDataCustomerTokenBlock)(BUYCustomer * _Nullable customer, NSSt
* @param token An authentication token to retrieve the customer later. Store this token securely on the device.
* @param error An optional NSError
*/
typedef
void
(
^
BUYDataTokenBlock
)(
NSString
*
_Nullable
token
,
NSError
*
_Nullable
error
);
typedef
void
(
^
BUYDataTokenBlock
)(
BUYCustomerToken
*
_Nullable
token
,
NSError
*
_Nullable
error
);
/**
* Return block containing an array of BUYOrders
...
...
@@ -81,12 +82,11 @@ typedef void (^BUYDataOrderBlock)(BUYOrder * _Nullable order, NSError * _Nullabl
* GET /api/customers/:customer_id
* Gets an existing customer
*
* @param customerID A customer ID retrieved from either customer creation or login
* @param block (BUYCustomer *customer, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
getCustomer
WithID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataCustomerBlock
)
block
;
-
(
NSOperation
*
)
getCustomer
C
allback
:(
BUYDataCustomerBlock
)
block
;
#pragma mark - Customer -
...
...
@@ -115,19 +115,18 @@ typedef void (^BUYDataOrderBlock)(BUYOrder * _Nullable order, NSError * _Nullabl
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NS
String
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
-
(
NSOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NS
Number
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
/**
* PUT /api/customers/:customer_id
* Update customer credentials represented by BUYAccountCredentials object
*
* @param credentials Credentials containing a password
* @param customerID ID of customer being activated
* @param block (BUYCustomer *customer, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataCustomerBlock
)
block
;
-
(
NSOperation
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerBlock
)
block
;
/**
* PUT /api/customers/:customer_id/reset
...
...
@@ -140,7 +139,7 @@ typedef void (^BUYDataOrderBlock)(BUYOrder * _Nullable order, NSError * _Nullabl
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NS
String
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
-
(
NSOperation
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NS
Number
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
;
#pragma mark - Token -
...
...
@@ -148,12 +147,11 @@ typedef void (^BUYDataOrderBlock)(BUYOrder * _Nullable order, NSError * _Nullabl
* PUT /api/customers/:customer_id/customer_token/renew
* Renews an existing customer's token
*
* @param customerID ID of customer renewing token
* @param block (NSString *token, NSError *error)
*
* @return the associated BUYRequestOperation
*/
-
(
NSOperation
*
)
renewCustomerToken
WithID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataTokenBlock
)
block
;
-
(
NSOperation
*
)
renewCustomerToken
C
allback
:(
BUYDataTokenBlock
)
block
;
#pragma mark - Login -
...
...
@@ -172,14 +170,12 @@ typedef void (^BUYDataOrderBlock)(BUYOrder * _Nullable order, NSError * _Nullabl
/**
* DELETE /api/customers/:customer_id/customer_token
* Logs out an existing customer
* Expects a customerID string
*
* @param customer A customerID represented by a string
* @param block (BUYStatus status, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
logoutCustomer
ID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataStatusBlock
)
block
;
-
(
NSOperation
*
)
logoutCustomer
C
allback
:(
BUYDataStatusBlock
)
block
;
/**
* POST /api/customers/recover
...
...
@@ -198,24 +194,22 @@ typedef void (^BUYDataOrderBlock)(BUYOrder * _Nullable order, NSError * _Nullabl
* GET /api/customers/:customer_id/orders
* Gets orders for a given customer
*
* @param customerID A customer ID for which to retrieve the order
* @param block (NSArray <BUYOrder*> *orders, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
getOrdersForCustomer
WithID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataOrdersBlock
)
block
;
-
(
NSOperation
*
)
getOrdersForCustomer
C
allback
:(
BUYDataOrdersBlock
)
block
;
/**
* GET /api/customers/:customer_id/orders/:id
* Gets order with a given identifier
*
* @param customerID A customer ID for which to retrieve the order
* @param orderID An order ID to retrieve
* @param block (NSArray <BUYOrder*> *orders, NSError *error)
*
* @return The associated BUYRequestOperation
*/
-
(
NSOperation
*
)
getOrderWithID
:(
NSNumber
*
)
orderID
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataOrderBlock
)
block
;
-
(
NSOperation
*
)
getOrderWithID
:(
NSNumber
*
)
orderID
callback
:(
BUYDataOrderBlock
)
block
;
@end
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m
View file @
edcaa8e9
...
...
@@ -27,20 +27,21 @@
#import "BUYClient+Customers.h"
#import "BUYClient+Internal.h"
#import "BUYClient+Routing.h"
#import "NSDateFormatter+BUYAdditions.h"
#import "BUYCustomer.h"
#import "BUYAccountCredentials.h"
#import "BUYAuthenticatedResponse.h"
#import "BUYCustomer.h"
#import "BUYCustomerToken.h"
#import "BUYOrder.h"
#import "BUYShopifyErrorCodes.h"
#import "NSDateFormatter+BUYAdditions.h"
@implementation
BUYClient
(
Customers
)
#pragma mark - Getting -
-
(
NSOperation
*
)
getCustomer
WithID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataCustomerBlock
)
block
-
(
NSOperation
*
)
getCustomer
C
allback
:(
BUYDataCustomerBlock
)
block
{
NSURL
*
url
=
[
self
urlFor
CustomersWithID
:
customerID
];
NSURL
*
url
=
[
self
urlFor
LoggedInCustomer
];
return
[
self
getRequestForURL
:
url
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
BUYCustomer
*
customer
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -65,9 +66,9 @@
}];
}
-
(
NSOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NS
String
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
-
(
NSOperation
*
)
activateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NS
Number
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURL
*
url
=
[
self
urlForCustomersActivationWithID
:
customerID
parameters
:@{
@"token"
:
token
}];
NSURL
*
url
=
[
self
urlForCustomersActivationWithID
:
customerID
.
stringValue
parameters
:@{
@"token"
:
token
}];
return
[
self
putRequestForURL
:
url
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
...
...
@@ -81,9 +82,9 @@
}];
}
-
(
NSOperation
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataCustomerBlock
)
block
-
(
NSOperation
*
)
updateCustomerWithCredentials
:(
BUYAccountCredentials
*
)
credentials
callback
:(
BUYDataCustomerBlock
)
block
{
NSURL
*
url
=
[
self
urlFor
CustomersWithID
:
customerID
];
NSURL
*
url
=
[
self
urlFor
LoggedInCustomer
];
return
[
self
putRequestForURL
:
url
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
BUYCustomer
*
customer
=
nil
;
if
(
json
&&
!
error
)
{
...
...
@@ -93,9 +94,9 @@
}];
}
-
(
NSOperation
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NS
String
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
-
(
NSOperation
*
)
resetPasswordWithCredentials
:(
BUYAccountCredentials
*
)
credentials
customerID
:(
NS
Number
*
)
customerID
token
:(
NSString
*
)
token
callback
:(
BUYDataCustomerTokenBlock
)
block
{
NSURL
*
url
=
[
self
urlForCustomersPasswordResetWithID
:
customerID
parameters
:@{
@"token"
:
token
}];
NSURL
*
url
=
[
self
urlForCustomersPasswordResetWithID
:
customerID
.
stringValue
parameters
:@{
@"token"
:
token
}];
return
[
self
putRequestForURL
:
url
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
email
=
json
[
@"customer"
][
@"email"
];
...
...
@@ -111,19 +112,18 @@
#pragma mark - Token -
-
(
NSOperation
*
)
renewCustomerToken
WithID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataTokenBlock
)
block
-
(
NSOperation
*
)
renewCustomerToken
C
allback
:(
BUYDataTokenBlock
)
block
{
if
(
self
.
customerToken
)
{
NSURL
*
url
=
[
self
urlForCustomersTokenRenewal
WithID
:
customerID
];
NSURL
*
url
=
[
self
urlForCustomersTokenRenewal
];
return
[
self
putRequestForURL
:
url
object
:
nil
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
NSString
*
access
Token
=
nil
;
BUYCustomerToken
*
customer
Token
=
nil
;
if
(
json
&&
!
error
)
{
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseWithJSON
:
json
];
accessToken
=
authenticatedResponse
.
accessToken
;
customerToken
=
[
BUYCustomerToken
customerTokenWithJSONDictionary
:
json
];
}
block
(
access
Token
,
error
);
block
(
customer
Token
,
error
);
}];
}
else
{
...
...
@@ -134,9 +134,9 @@
#pragma mark - Login -
-
(
NSOperation
*
)
logoutCustomer
ID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataStatusBlock
)
block
-
(
NSOperation
*
)
logoutCustomer
C
allback
:(
BUYDataStatusBlock
)
block
{
NSURL
*
url
=
[
self
urlFor
CustomersTokenWithID
:
customerID
];
NSURL
*
url
=
[
self
urlFor
LoggedInCustomerToken
];
return
[
self
deleteRequestForURL
:
url
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
block
(
response
.
statusCode
,
error
);
}];
...
...
@@ -157,9 +157,9 @@
#pragma mark - Orders -
-
(
NSOperation
*
)
getOrdersForCustomer
WithID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataOrdersBlock
)
block
-
(
NSOperation
*
)
getOrdersForCustomer
C
allback
:(
BUYDataOrdersBlock
)
block
{
NSURL
*
url
=
[
self
urlForCustomersOrders
WithID
:
customerID
];
NSURL
*
url
=
[
self
urlForCustomersOrders
];
return
[
self
getRequestForURL
:
url
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
NSArray
*
orders
=
[
self
.
modelManager
ordersWithJSONDictionary
:
json
];
...
...
@@ -170,9 +170,9 @@
}];
}
-
(
NSOperation
*
)
getOrderWithID
:(
NSNumber
*
)
orderID
c
ustomerID
:(
NSString
*
)
customerID
c
allback
:(
BUYDataOrderBlock
)
block
-
(
NSOperation
*
)
getOrderWithID
:(
NSNumber
*
)
orderID
callback
:(
BUYDataOrderBlock
)
block
{
NSURL
*
url
=
[
self
urlForCustomersOrdersWith
ID
:
customerID
o
rderID
:
orderID
];
NSURL
*
url
=
[
self
urlForCustomersOrdersWith
O
rderID
:
orderID
];
return
[
self
getRequestForURL
:
url
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
BUYOrder
*
order
=
[
self
.
modelManager
orderWithJSONDictionary
:
json
];
...
...
@@ -190,11 +190,9 @@
NSURL
*
url
=
[
self
urlForCustomersToken
];
return
[
self
postRequestForURL
:
url
object
:
credentials
.
JSONRepresentation
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
BUYAuthenticatedResponse
*
authenticatedResponse
=
[
BUYAuthenticatedResponse
responseWithJSON
:
json
];
self
.
customerToken
=
authenticatedResponse
.
accessToken
;
self
.
customerToken
=
[
BUYCustomerToken
customerTokenWithJSONDictionary
:
json
];
if
(
!
customerJSON
)
{
[
self
getCustomer
WithID
:
authenticatedResponse
.
customerID
c
allback
:
^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
[
self
getCustomer
C
allback
:
^
(
BUYCustomer
*
customer
,
NSError
*
error
)
{
block
(
customer
,
self
.
customerToken
,
error
);
}];
}
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.h
View file @
edcaa8e9
...
...
@@ -49,16 +49,18 @@
-
(
NSURL
*
)
urlForCustomers
;
-
(
NSURL
*
)
urlForCustomersToken
;
-
(
NSURL
*
)
urlForCustomersPasswordRecovery
;
-
(
NSURL
*
)
urlForLoggedInCustomer
;
-
(
NSURL
*
)
urlForLoggedInCustomerToken
;
-
(
NSURL
*
)
urlForCustomersTokenRenewal
;
-
(
NSURL
*
)
urlForCustomersOrders
;
-
(
NSURL
*
)
urlForCustomersOrdersWithOrderID
:(
NSNumber
*
)
orderID
;
-
(
NSURL
*
)
urlForCustomersOrdersWithID
:(
NSString
*
)
identifier
;
-
(
NSURL
*
)
urlForCustomersOrdersWithID
:(
NSString
*
)
identifier
orderID
:(
NSNumber
*
)
orderID
;
-
(
NSURL
*
)
urlForCustomersWithID
:(
NSString
*
)
identifier
;
-
(
NSURL
*
)
urlForCustomersActivationWithID
:(
NSString
*
)
identifier
parameters
:(
NSDictionary
*
)
parameters
;
-
(
NSURL
*
)
urlForCustomersTokenWithID
:(
NSString
*
)
customerID
;
-
(
NSURL
*
)
urlForCustomersTokenRenewalWithID
:(
NSString
*
)
customerID
;
-
(
NSURL
*
)
urlForCustomersPasswordResetWithID
:(
NSString
*
)
identifier
parameters
:(
NSDictionary
*
)
parameters
;
-
(
NSURL
*
)
urlForCustomersAddresses
WithID
:(
NSString
*
)
customerID
;
-
(
NSURL
*
)
urlForCustomersAddressWith
ID
:(
NSString
*
)
customerID
a
ddressID
:(
NSNumber
*
)
addressID
;
-
(
NSURL
*
)
urlForCustomersAddresses
;
-
(
NSURL
*
)
urlForCustomersAddressWith
A
ddressID
:(
NSNumber
*
)
addressID
;
@end
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Routing.m
View file @
edcaa8e9
...
...
@@ -25,6 +25,7 @@
//
#import "BUYClient+Routing.h"
#import "BUYCustomerToken.h"
#pragma mark - NSURL (Private Routing) -
...
...
@@ -188,6 +189,16 @@
return
[[[
self
urlForCustomers
]
appendPath
:
@"/recover"
]
appendExtension
];
}
-
(
NSURL
*
)
urlForLoggedInCustomer
{
return
[
self
urlForCustomersWithID
:[
self
.
customerToken
.
customerID
stringValue
]];
}
-
(
NSURL
*
)
urlForLoggedInCustomerToken
{
return
[[[
self
urlForLoggedInCustomer
]
appendPath
:
@"/customer_token"
]
appendExtension
];
}
#pragma mark - Customer With ID -
-
(
NSURL
*
)
urlForCustomersWithID
:
(
NSString
*
)
identifier
...
...
@@ -195,14 +206,14 @@
return
[[[
self
urlForCustomers
]
appendPath
:
identifier
]
appendExtension
];
}
-
(
NSURL
*
)
urlForCustomersOrders
WithID
:
(
NSString
*
)
identifier
-
(
NSURL
*
)
urlForCustomersOrders
{
return
[[[
self
urlFor
CustomersWithID
:
identifi
er
]
appendPath
:
@"/orders"
]
appendExtension
];
return
[[[
self
urlFor
LoggedInCustom
er
]
appendPath
:
@"/orders"
]
appendExtension
];
}
-
(
NSURL
*
)
urlForCustomersOrdersWith
ID
:
(
NSString
*
)
identifier
o
rderID
:
(
NSNumber
*
)
orderID
-
(
NSURL
*
)
urlForCustomersOrdersWith
O
rderID
:
(
NSNumber
*
)
orderID
{
return
[[[
self
urlForCustomersOrders
WithID
:
identifier
]
appendIdentifier
:
orderID
]
appendExtension
];
return
[[[
self
urlForCustomersOrders
]
appendIdentifier
:
orderID
]
appendExtension
];
}
-
(
NSURL
*
)
urlForCustomersActivationWithID
:
(
NSString
*
)
identifier
parameters
:
(
NSDictionary
*
)
parameters
...
...
@@ -210,14 +221,9 @@
return
[[[[
self
urlForCustomersWithID
:
identifier
]
appendPath
:
@"/activate"
]
appendParameters
:
parameters
]
appendExtension
];
}
-
(
NSURL
*
)
urlForCustomersTokenWithID
:
(
NSString
*
)
customerID
{
return
[[[
self
urlForCustomersWithID
:
customerID
]
appendPath
:
@"/customer_token"
]
appendExtension
];
}
-
(
NSURL
*
)
urlForCustomersTokenRenewalWithID
:
(
NSString
*
)
customerID
-
(
NSURL
*
)
urlForCustomersTokenRenewal
{
return
[[[
self
urlFor
CustomersWithID
:
customerID
]
appendPath
:
@"/customer_token/renew"
]
appendExtension
];
return
[[[
self
urlFor
LoggedInCustomer
]
appendPath
:
@"/customer_token/renew"
]
appendExtension
];
}
-
(
NSURL
*
)
urlForCustomersPasswordResetWithID
:
(
NSString
*
)
identifier
parameters
:
(
NSDictionary
*
)
parameters
...
...
@@ -227,14 +233,14 @@
#pragma mark - Customer Addresses -
-
(
NSURL
*
)
urlForCustomersAddresses
WithID
:
(
NSString
*
)
customerID
-
(
NSURL
*
)
urlForCustomersAddresses
{
return
[[[
self
urlFor
CustomersWithID
:
customerID
]
appendPath
:
@"/addresses"
]
appendExtension
];
return
[[[
self
urlFor
LoggedInCustomer
]
appendPath
:
@"/addresses"
]
appendExtension
];
}
-
(
NSURL
*
)
urlForCustomersAddressWith
ID
:
(
NSString
*
)
customerID
a
ddressID
:
(
NSNumber
*
)
addressID
-
(
NSURL
*
)
urlForCustomersAddressWith
A
ddressID
:
(
NSNumber
*
)
addressID
{
return
[[[[
self
urlFor
CustomersWithID
:
customerID
]
appendPath
:
@"/addresses"
]
appendIdentifier
:
addressID
]
appendExtension
];
return
[[[[
self
urlFor
LoggedInCustomer
]
appendPath
:
@"/addresses"
]
appendIdentifier
:
addressID
]
appendExtension
];
}
#pragma mark - Utilities -
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.h
View file @
edcaa8e9
...
...
@@ -25,8 +25,9 @@
//
@import
Foundation
;
#import
"BUYClientTypes.h"
#import
<Buy/BUYClientTypes.h>
@class
BUYCustomerToken
;
@class
BUYModelManager
;
@class
BUYOperation
;
@class
BUYRequestOperation
;
...
...
@@ -97,7 +98,7 @@ NS_ASSUME_NONNULL_BEGIN
*
* @param token The token received from the create and login callbacks
*/
@property
(
strong
,
nonatomic
,
nullable
)
NSString
*
customerToken
;
@property
(
strong
,
nonatomic
,
nullable
)
BUYCustomerToken
*
customerToken
;
@end
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
edcaa8e9
...
...
@@ -26,6 +26,7 @@
#import "BUYClient+Internal.h"
#import "BUYAssert.h"
#import "BUYCustomerToken.h"
#import "BUYModelManager.h"
#import "BUYRequestOperation.h"
...
...
@@ -222,7 +223,7 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
[
request
addValue
:
BUYClientJSONMimeType
forHTTPHeaderField
:
@"Accept"
];
if
(
self
.
customerToken
)
{
[
request
addValue
:
self
.
customerToken
forHTTPHeaderField
:
BUYClientCustomerAccessToken
];
[
request
addValue
:
self
.
customerToken
.
accessToken
forHTTPHeaderField
:
BUYClientCustomerAccessToken
];
}
request
.
HTTPMethod
=
method
;
...
...
Mobile Buy SDK/Mobile Buy SDK/Models/BUYAccountCredentials.h
View file @
edcaa8e9
...
...
@@ -48,6 +48,7 @@ OBJC_EXTERN NSString * const BUYAccountPasswordKey;
+
(
BUYAccountCredentials
*
)
credentialsWithItems
:(
NSArray
<
BUYAccountCredentialItem
*>
*
)
items
;
-
(
instancetype
)
initWithItems
:(
NSArray
<
BUYAccountCredentialItem
*>
*
)
items
;
-
(
BUYAccountCredentialItem
*
)
credentialItemForKey
:(
NSString
*
)
key
;
-
(
BUYAccountCredentials
*
)
credentialsByAddingItems
:(
NSArray
<
BUYAccountCredentialItem
*>
*
)
items
;
...
...
Mobile Buy SDK/Mobile Buy SDK/Models/BUYAccountCredentials.m
View file @
edcaa8e9
...
...
@@ -75,6 +75,11 @@ NSString * const BUYAccountPasswordKey = @"password";
return
self
.
credentialItems
.
allValues
;
}
-
(
BUYAccountCredentialItem
*
)
credentialItemForKey
:
(
NSString
*
)
key
{
return
_credentialItems
[
key
];
}
-
(
NSUInteger
)
count
{
return
self
.
credentialItems
.
count
;
...
...
Mobile Buy SDK/Mobile Buy SDK/Models/BUY
AuthenticatedResponse
.h
→
Mobile Buy SDK/Mobile Buy SDK/Models/BUY
CustomerToken
.h
View file @
edcaa8e9
//
// BUY
AuthenticatedResponse
.h
// BUY
CustomerToken
.h
// Mobile Buy SDK
//
// Created by Shopify.
...
...
@@ -26,12 +26,15 @@
#import <Foundation/Foundation.h>
@interface
BUY
AuthenticatedResponse
:
NSObject
@interface
BUY
CustomerToken
:
NSObject
@property
(
nonatomic
,
copy
,
readonly
)
NSString
*
accessToken
;
@property
(
nonatomic
,
copy
,
readonly
)
NSDate
*
expiry
;
@property
(
nonatomic
,
copy
,
readonly
)
NSString
*
customerID
;
@property
(
nonatomic
,
copy
,
readonly
)
NSNumber
*
customerID
;
@property
(
nonatomic
,
copy
,
readonly
)
NSDictionary
*
JSONDictionary
;
+
(
BUYAuthenticatedResponse
*
)
responseWithJSON
:(
NSDictionary
*
)
json
;
-
(
instancetype
)
init
NS_UNAVAILABLE
;
-
(
instancetype
)
initWithCustomerID
:(
NSNumber
*
)
customerID
accessToken
:(
NSString
*
)
accessToken
expiry
:(
NSDate
*
)
expiry
;
+
(
BUYCustomerToken
*
)
customerTokenWithJSONDictionary
:(
NSDictionary
*
)
json
;
@end
Mobile Buy SDK/Mobile Buy SDK/Models/BUY
AuthenticatedResponse
.m
→
Mobile Buy SDK/Mobile Buy SDK/Models/BUY
CustomerToken
.m
View file @
edcaa8e9
//
// BUY
AuthenticatedResponse
.m
// BUY
CustomerToken
.m
// Mobile Buy SDK
//
// Created by Shopify.
...
...
@@ -24,28 +24,56 @@
// THE SOFTWARE.
//
#import "BUY
AuthenticatedResponse
.h"
#import "BUY
CustomerToken
.h"
#import "NSDateFormatter+BUYAdditions.h"
#import "NSDictionary+BUYAdditions.h"
@implementation
BUYAuthenticatedResponse
static
NSString
*
const
customerAccessTokenKey
=
@"customer_access_token"
;
static
NSString
*
const
accessTokenKey
=
@"access_token"
;
static
NSString
*
const
expiresAtKey
=
@"expires_at"
;
static
NSString
*
const
customerIDKey
=
@"customer_id"
;
+
(
BUYAuthenticatedResponse
*
)
responseWithJSON
:(
NSDictionary
*
)
json
{
return
[[[
self
class
]
alloc
]
initWithJSON
:
json
];
}
@implementation
BUYCustomerToken
-
(
instancetype
)
initWith
JSON
:(
NSDictionary
*
)
json
-
(
instancetype
)
initWith
CustomerID
:(
NSNumber
*
)
customerID
accessToken
:(
NSString
*
)
accessToken
expiry
:(
NSDate
*
)
expiry
{
NSParameterAssert
(
customerID
);
NSParameterAssert
(
accessToken
);
NSParameterAssert
(
expiry
);
self
=
[
super
init
];
if
(
self
)
{
NSDateFormatter
*
formatter
=
[
NSDateFormatter
dateFormatterForPublications
];
NSDictionary
*
access
=
json
[
@"customer_access_token"
];
_accessToken
=
access
[
@"access_token"
];
_expiry
=
[
formatter
dateFromString
:
access
[
@"expires_at"
]];
_customerID
=
[
NSString
stringWithFormat
:
@"%@"
,
access
[
@"customer_id"
]];
_customerID
=
customerID
;
_accessToken
=
accessToken
;
_expiry
=
expiry
;
}
return
self
;
}
+
(
BUYCustomerToken
*
)
customerTokenWithJSONDictionary
:(
NSDictionary
*
)
json
{
return
[[
self
alloc
]
initWithJSON
:
json
];
}
-
(
instancetype
)
initWithJSON
:(
NSDictionary
*
)
json
{
NSDateFormatter
*
formatter
=
[
NSDateFormatter
dateFormatterForPublications
];
NSDictionary
*
access
=
json
[
customerAccessTokenKey
]
?:
json
;
NSNumber
*
customerID
=
access
[
customerIDKey
];
NSString
*
accessToken
=
access
[
accessTokenKey
];
NSDate
*
expiry
=
[
formatter
dateFromString
:
access
[
expiresAtKey
]];
return
[
self
initWithCustomerID
:
customerID
accessToken
:
accessToken
expiry
:
expiry
];
}
-
(
NSDictionary
*
)
JSONDictionary
{
NSDateFormatter
*
formatter
=
[
NSDateFormatter
dateFormatterForPublications
];
return
@{
accessTokenKey
:
_accessToken
,
expiresAtKey
:
[
formatter
stringFromDate
:
_expiry
],
customerIDKey
:
_customerID
};
}
@end
Mobile Buy SDK/Mobile Buy SDK/Models/Mobile Buy SDK.xcdatamodeld/Mobile Buy SDK.xcdatamodel/contents
View file @
edcaa8e9
...
...
@@ -983,25 +983,25 @@
<memberEntity
name=
"CheckoutAttribute"
/>
</configuration>
<elements>
<element
name=
"Address"
positionX=
"
126"
positionY=
"521
"
width=
"128"
height=
"255"
/>
<element
name=
"Cart"
positionX=
"-
576"
positionY=
"55
8"
width=
"128"
height=
"60"
/>
<element
name=
"CartLineItem"
positionX=
"-
380"
positionY=
"558
"
width=
"128"
height=
"90"
/>
<element
name=
"Checkout"
positionX=
"
333"
positionY=
"44
2"
width=
"128"
height=
"630"
/>
<element
name=
"CheckoutAttribute"
positionX=
"-9
54"
positionY=
"594
"
width=
"128"
height=
"90"
/>
<element
name=
"Collection"
positionX=
"-
963"
positionY=
"772
"
width=
"128"
height=
"195"
/>
<element
name=
"Customer"
positionX=
"
106"
positionY=
"1263
"
width=
"128"
height=
"330"
/>
<element
name=
"Discount"
positionX=
"
126"
positionY=
"8
77"
width=
"128"
height=
"105"
/>
<element
name=
"GiftCard"
positionX=
"
531"
positionY=
"86
2"
width=
"128"
height=
"135"
/>
<element
name=
"ImageLink"
positionX=
"-1
161"
positionY=
"832
"
width=
"128"
height=
"165"
/>
<element
name=
"LineItem"
positionX=
"-
18"
positionY=
"727
"
width=
"128"
height=
"315"
/>
<element
name=
"MaskedCreditCard"
positionX=
"
531"
positionY=
"693
"
width=
"128"
height=
"150"
/>
<element
name=
"Option"
positionX=
"-
576"
positionY=
"90
7"
width=
"128"
height=
"105"
/>
<element
name=
"OptionValue"
positionX=
"-
387"
positionY=
"907
"
width=
"128"
height=
"105"
/>
<element
name=
"Order"
positionX=
"
682"
positionY=
"922
"
width=
"128"
height=
"180"
/>
<element
name=
"Product"
positionX=
"-
765"
positionY=
"712"
width=
"128"
height=
"285
"
/>
<element
name=
"ProductVariant"
positionX=
"-1
82"
positionY=
"787
"
width=
"128"
height=
"240"
/>
<element
name=
"ShippingRate"
positionX=
"
531"
positionY=
"1035
"
width=
"128"
height=
"135"
/>
<element
name=
"Shop"
positionX=
"-
279"
positionY=
"450
"
width=
"128"
height=
"255"
/>
<element
name=
"TaxLine"
positionX=
"
126"
positionY=
"1026
"
width=
"128"
height=
"133"
/>
<element
name=
"Address"
positionX=
"
-990"
positionY=
"1444
"
width=
"128"
height=
"255"
/>
<element
name=
"Cart"
positionX=
"-
1192"
positionY=
"97
8"
width=
"128"
height=
"60"
/>
<element
name=
"CartLineItem"
positionX=
"-
987"
positionY=
"1183
"
width=
"128"
height=
"90"
/>
<element
name=
"Checkout"
positionX=
"
-765"
positionY=
"107
2"
width=
"128"
height=
"630"
/>
<element
name=
"CheckoutAttribute"
positionX=
"-9
90"
positionY=
"1332
"
width=
"128"
height=
"90"
/>
<element
name=
"Collection"
positionX=
"-
1588"
positionY=
"1063
"
width=
"128"
height=
"195"
/>
<element
name=
"Customer"
positionX=
"
-1190"
positionY=
"1359
"
width=
"128"
height=
"330"
/>
<element
name=
"Discount"
positionX=
"
-551"
positionY=
"13
77"
width=
"128"
height=
"105"
/>
<element
name=
"GiftCard"
positionX=
"
-540"
positionY=
"149
2"
width=
"128"
height=
"135"
/>
<element
name=
"ImageLink"
positionX=
"-1
786"
positionY=
"1108
"
width=
"128"
height=
"165"
/>
<element
name=
"LineItem"
positionX=
"-
353"
positionY=
"1342
"
width=
"128"
height=
"315"
/>
<element
name=
"MaskedCreditCard"
positionX=
"
-567"
positionY=
"1218
"
width=
"128"
height=
"150"
/>
<element
name=
"Option"
positionX=
"-
1588"
positionY=
"128
7"
width=
"128"
height=
"105"
/>
<element
name=
"OptionValue"
positionX=
"-
1390"
positionY=
"894
"
width=
"128"
height=
"105"
/>
<element
name=
"Order"
positionX=
"
-549"
positionY=
"1647
"
width=
"128"
height=
"180"
/>
<element
name=
"Product"
positionX=
"-
1390"
positionY=
"1018"
width=
"128"
height=
"300
"
/>
<element
name=
"ProductVariant"
positionX=
"-1
192"
positionY=
"1063
"
width=
"128"
height=
"240"
/>
<element
name=
"ShippingRate"
positionX=
"
-569"
positionY=
"1836
"
width=
"128"
height=
"135"
/>
<element
name=
"Shop"
positionX=
"-
1786"
positionY=
"843
"
width=
"128"
height=
"255"
/>
<element
name=
"TaxLine"
positionX=
"
-990"
positionY=
"1737
"
width=
"128"
height=
"133"
/>
</elements>
</model>
\ No newline at end of file
Mobile Buy SDK/Mobile Buy SDK/Payment Providers/BUYWebCheckoutPaymentProvider.m
View file @
edcaa8e9
...
...
@@ -27,6 +27,7 @@
#import "BUYWebCheckoutPaymentProvider.h"
#import "BUYCheckout.h"
#import "BUYClient+Checkout.h"
#import "BUYCustomerToken.h"
#import "BUYAssert.h"
@import
SafariServices
;
...
...
@@ -176,11 +177,11 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token"
-
(
NSURL
*
)
authenticatedWebCheckoutURL
:
(
NSURL
*
)
url
{
NSString
*
customerToken
=
self
.
client
.
customer
Token
;
if
(
!
customer
Token
.
length
)
{
NSString
*
accessToken
=
self
.
client
.
customerToken
.
access
Token
;
if
(
!
access
Token
.
length
)
{
return
url
;
}
NSURLQueryItem
*
item
=
[
NSURLQueryItem
queryItemWithName
:
WebCheckoutCustomerAccessToken
value
:
customer
Token
];
NSURLQueryItem
*
item
=
[
NSURLQueryItem
queryItemWithName
:
WebCheckoutCustomerAccessToken
value
:
access
Token
];
NSURLComponents
*
authenticatedComponents
=
[
NSURLComponents
componentsWithURL
:
url
resolvingAgainstBaseURL
:
YES
];
authenticatedComponents
.
queryItems
=
authenticatedComponents
.
queryItems
?
[
authenticatedComponents
.
queryItems
arrayByAddingObject
:
item
]
:
@[
item
];
return
authenticatedComponents
.
URL
;
...
...
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