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
50f26233
Commit
50f26233
authored
May 16, 2016
by
Brent Gulanowski
Committed by
Gabriel O'Flaherty-Chan
May 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make checkout error mapping more robust.
parent
bde22786
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
15 deletions
+38
-15
BUYError+BUYAdditions.m
Mobile Buy SDK/Mobile Buy SDK/Utils/BUYError+BUYAdditions.m
+38
-15
No files found.
Mobile Buy SDK/Mobile Buy SDK/Utils/BUYError+BUYAdditions.m
View file @
50f26233
...
@@ -25,26 +25,49 @@
...
@@ -25,26 +25,49 @@
//
//
#import "BUYError+BUYAdditions.h"
#import "BUYError+BUYAdditions.h"
#import "NSArray+BUYAdditions.h"
@interface
NSDictionary
(
BUYCheckoutErrorParsing
)
-
(
NSDictionary
*
)
buy_errorsDictionary
;
-
(
NSDictionary
*
)
buy_checkoutErrorsDictionary
;
-
(
NSArray
*
)
buy_lineItemErrors
;
@end
@implementation
NSDictionary
(
BUYCheckoutErrorParsing
)
-
(
NSDictionary
*
)
buy_errorsDictionary
{
NSDictionary
*
errorsDictionary
=
self
[
@"errors"
];
return
[
errorsDictionary
isKindOfClass
:[
NSDictionary
class
]]
?
errorsDictionary
:
nil
;
}
-
(
NSDictionary
*
)
buy_checkoutErrorsDictionary
{
NSDictionary
*
checkoutErrorsDictionary
=
[
self
buy_errorsDictionary
][
@"checkout"
];
return
[
checkoutErrorsDictionary
isKindOfClass
:[
NSDictionary
class
]]
?
checkoutErrorsDictionary
:
nil
;
}
-
(
NSArray
*
)
buy_lineItemErrors
{
NSArray
*
lineItemErrors
=
[
self
buy_checkoutErrorsDictionary
][
@"line_items"
];
return
[
lineItemErrors
isKindOfClass
:[
NSArray
class
]]
?
lineItemErrors
:
nil
;
}
@end
@implementation
BUYError
(
Checkout
)
@implementation
BUYError
(
Checkout
)
+
(
NSArray
<
BUYError
*>
*
)
errorsFromCheckoutJSON
:(
NSDictionary
*
)
json
+
(
NSArray
<
BUYError
*>
*
)
errorsFromCheckoutJSON
:(
NSDictionary
*
)
json
{
{
NSArray
*
lineItems
=
json
[
@"errors"
][
@"checkout"
][
@"line_items"
];
return
[[
json
buy_lineItemErrors
]
buy_map
:
^
id
(
NSDictionary
<
NSString
*
,
NSArray
*>
*
lineItemError
)
{
NSMutableArray
*
errors
=
[
NSMutableArray
array
];
return
[
lineItemError
isKindOfClass
:[
NSDictionary
class
]]
?
[
self
errorWithJSONDictionary
:
lineItemError
]
:
[
NSNull
null
];
}];
for
(
NSDictionary
<
NSString
*
,
NSArray
*>
*
lineItem
in
lineItems
)
{
}
if
(
lineItem
==
(
id
)[
NSNull
null
])
{
[
errors
addObject
:
lineItem
];
+
(
BUYError
*
)
errorWithJSONDictionary
:(
NSDictionary
<
NSString
*
,
NSArray
*>
*
)
dictionary
}
{
else
{
NSString
*
key
=
dictionary
.
allKeys
.
firstObject
;
for
(
NSString
*
key
in
lineItem
.
allKeys
)
{
return
[[
self
alloc
]
initWithKey
:
key
json
:
dictionary
[
key
].
firstObject
];
NSDictionary
*
reason
=
[
lineItem
[
key
]
firstObject
];
[
errors
addObject
:[[
BUYError
alloc
]
initWithKey
:
key
json
:
reason
]];
};
}
};
return
errors
;
}
}
-
(
NSString
*
)
quantityRemainingMessage
-
(
NSString
*
)
quantityRemainingMessage
...
...
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