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
3a2e7135
Commit
3a2e7135
authored
8 years ago
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inline post request for store credit card. Reorganize methods.
parent
d8fb9503
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
27 deletions
+22
-27
BUYClient.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
+22
-27
No files found.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
3a2e7135
...
@@ -523,11 +523,13 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
...
@@ -523,11 +523,13 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
json
[
@"billing_address"
]
=
[
checkout
.
billingAddress
jsonDictionaryForCheckout
];
json
[
@"billing_address"
]
=
[
checkout
.
billingAddress
jsonDictionaryForCheckout
];
}
}
NSData
*
data
=
[
NSJSONSerialization
dataWithJSONObject
:@{
@"checkout"
:
json
}
options
:
0
error
:
nil
];
return
[
self
postRequestForURL
:
checkout
.
paymentURL
object
:@{
@"checkout"
:
json
}
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
id
<
BUYPaymentToken
>
token
=
nil
;
BUYAssert
(
data
,
@"Failed to store credit card. Unable to serialize JSON payload. Possibly invalid credit card object."
);
if
(
!
error
)
{
token
=
[[
BUYCreditCardToken
alloc
]
initWithPaymentSessionID
:
json
[
@"id"
]];
return
[
self
postPaymentRequestWithCheckout
:
checkout
body
:
data
completion
:
completion
];
}
completion
(
checkout
,
token
,
error
);
}];
}
}
-
(
NSURLSessionDataTask
*
)
removeProductReservationsFromCheckout
:
(
BUYCheckout
*
)
checkout
completion
:
(
BUYDataCheckoutBlock
)
block
-
(
NSURLSessionDataTask
*
)
removeProductReservationsFromCheckout
:
(
BUYCheckout
*
)
checkout
completion
:
(
BUYDataCheckoutBlock
)
block
...
@@ -538,7 +540,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
...
@@ -538,7 +540,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
return
[
self
updateCheckout
:
checkout
completion
:
block
];
return
[
self
updateCheckout
:
checkout
completion
:
block
];
}
}
#pragma mark -
Helpers
#pragma mark -
Error
+
(
BUYStatus
)
statusForStatusCode
:
(
NSUInteger
)
statusCode
error
:
(
NSError
*
)
error
+
(
BUYStatus
)
statusForStatusCode
:
(
NSUInteger
)
statusCode
error
:
(
NSError
*
)
error
{
{
...
@@ -566,6 +568,19 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
...
@@ -566,6 +568,19 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
return
[[
NSError
alloc
]
initWithDomain
:
kShopifyError
code
:
statusCode
userInfo
:
errorDictionary
];
return
[[
NSError
alloc
]
initWithDomain
:
kShopifyError
code
:
statusCode
userInfo
:
errorDictionary
];
}
}
#pragma mark - Generic Requests
-
(
void
)
startTask
:
(
NSURLSessionDataTask
*
)
task
{
[
task
resume
];
}
-
(
NSString
*
)
authorizationHeader
{
NSData
*
data
=
[
_apiKey
dataUsingEncoding
:
NSUTF8StringEncoding
];
return
[
NSString
stringWithFormat
:
@"%@ %@"
,
@"Basic"
,
[
data
base64EncodedStringWithOptions
:
0
]];
}
-
(
NSURLSessionDataTask
*
)
requestForURL
:
(
NSURL
*
)
url
method
:
(
NSString
*
)
method
object
:
(
id
<
BUYSerializable
>
)
object
completionHandler
:
(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
-
(
NSURLSessionDataTask
*
)
requestForURL
:
(
NSURL
*
)
url
method
:
(
NSString
*
)
method
object
:
(
id
<
BUYSerializable
>
)
object
completionHandler
:
(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
{
{
BUYAssert
(
object
,
@"Failed to perform request. id<BUYSerializable> must not be nil."
);
BUYAssert
(
object
,
@"Failed to perform request. id<BUYSerializable> must not be nil."
);
...
@@ -576,11 +591,6 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
...
@@ -576,11 +591,6 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
return
[
self
requestForURL
:
url
method
:
method
body
:
data
completionHandler
:
completionHandler
];
return
[
self
requestForURL
:
url
method
:
method
body
:
data
completionHandler
:
completionHandler
];
}
}
-
(
void
)
startTask
:
(
NSURLSessionDataTask
*
)
task
{
[
task
resume
];
}
-
(
NSURLSessionDataTask
*
)
requestForURL
:
(
NSURL
*
)
url
method
:
(
NSString
*
)
method
body
:
(
NSData
*
)
body
completionHandler
:
(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
-
(
NSURLSessionDataTask
*
)
requestForURL
:
(
NSURL
*
)
url
method
:
(
NSString
*
)
method
body
:
(
NSData
*
)
body
completionHandler
:
(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
{
{
NSMutableURLRequest
*
request
=
[[
NSMutableURLRequest
alloc
]
initWithURL
:
url
];
NSMutableURLRequest
*
request
=
[[
NSMutableURLRequest
alloc
]
initWithURL
:
url
];
...
@@ -623,16 +633,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
...
@@ -623,16 +633,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
return
task
;
return
task
;
}
}
-
(
NSURLSessionDataTask
*
)
postPaymentRequestWithCheckout
:
(
BUYCheckout
*
)
checkout
body
:
(
NSData
*
)
body
completion
:
(
BUYDataCreditCardBlock
)
block
#pragma mark - Convenience Requests
{
return
[
self
requestForURL
:
checkout
.
paymentURL
method
:
kPOST
body
:
body
completionHandler
:^
(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
)
{
id
<
BUYPaymentToken
>
token
=
nil
;
if
(
!
error
)
{
token
=
[[
BUYCreditCardToken
alloc
]
initWithPaymentSessionID
:
json
[
@"id"
]];
}
block
(
checkout
,
token
,
error
);
}];
}
-
(
NSURLSessionDataTask
*
)
getRequestForURL
:
(
NSURL
*
)
url
completionHandler
:
(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
-
(
NSURLSessionDataTask
*
)
getRequestForURL
:
(
NSURL
*
)
url
completionHandler
:
(
void
(
^
)(
NSDictionary
*
json
,
NSURLResponse
*
response
,
NSError
*
error
))
completionHandler
{
{
...
@@ -669,12 +670,6 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
...
@@ -669,12 +670,6 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
return
[
self
requestForURL
:
url
method
:
kDELETE
body
:
nil
completionHandler
:
completionHandler
];
return
[
self
requestForURL
:
url
method
:
kDELETE
body
:
nil
completionHandler
:
completionHandler
];
}
}
-
(
NSString
*
)
authorizationHeader
{
NSData
*
data
=
[
_apiKey
dataUsingEncoding
:
NSUTF8StringEncoding
];
return
[
NSString
stringWithFormat
:
@"%@ %@"
,
@"Basic"
,
[
data
base64EncodedStringWithOptions
:
0
]];
}
#pragma mark - NSURLSessionTaskDelegate
#pragma mark - NSURLSessionTaskDelegate
-
(
void
)
URLSession
:
(
NSURLSession
*
)
session
task
:
(
NSURLSessionTask
*
)
task
didReceiveChallenge
:
(
NSURLAuthenticationChallenge
*
)
challenge
completionHandler
:
(
void
(
^
)(
NSURLSessionAuthChallengeDisposition
disposition
,
NSURLCredential
*
credential
))
completionHandler
-
(
void
)
URLSession
:
(
NSURLSession
*
)
session
task
:
(
NSURLSessionTask
*
)
task
didReceiveChallenge
:
(
NSURLAuthenticationChallenge
*
)
challenge
completionHandler
:
(
void
(
^
)(
NSURLSessionAuthChallengeDisposition
disposition
,
NSURLCredential
*
credential
))
completionHandler
...
...
This diff is collapsed.
Click to expand it.
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