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
ed403bd4
Commit
ed403bd4
authored
Jun 01, 2016
by
Dima Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor gift card implementation to remove `updateCheckout` method
parent
a8fd24b9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
20 deletions
+31
-20
BUYClient+Checkout.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Checkout.m
+25
-20
BUYCheckout.h
Mobile Buy SDK/Mobile Buy SDK/Models/Transient/BUYCheckout.h
+1
-0
BUYCheckout.m
Mobile Buy SDK/Mobile Buy SDK/Models/Transient/BUYCheckout.m
+5
-0
No files found.
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Checkout.m
View file @
ed403bd4
...
...
@@ -168,23 +168,6 @@
block
(
checkout
,
error
);
}
-
(
void
)
updateCheckout
:(
BUYCheckout
*
)
checkout
withGiftCardDictionary
:(
NSDictionary
*
)
giftCardDictionary
addingGiftCard
:(
BOOL
)
addingGiftCard
{
if
(
addingGiftCard
)
{
BUYGiftCard
*
giftCard
=
[
self
.
modelManager
insertGiftCardWithJSONDictionary
:
giftCardDictionary
];
[
checkout
.
giftCardsSet
addObject
:
giftCard
];
}
else
{
[
checkout
removeGiftCardWithIdentifier
:
giftCardDictionary
[
@"id"
]];
}
checkout
.
paymentDue
=
[
NSDecimalNumber
buy_decimalNumberFromJSON
:
giftCardDictionary
[
@"checkout"
][
@"payment_due"
]];
// Marking the checkout as clean. The properties we have updated above we don't need to re-sync with Shopify.
// There's also an issue with gift cards where syncing the gift card JSON won't work since the update endpoint
// doesn't accept the gift card without a gift card code (which we do not have).
[
checkout
markAsClean
];
}
#pragma mark - Shipping Rates -
-
(
BUYRequestOperation
*
)
getShippingRatesForCheckoutForToken
:(
NSString
*
)
checkoutToken
completion
:(
BUYDataShippingRatesBlock
)
block
...
...
@@ -245,7 +228,18 @@
return
[
self
postRequestForURL
:
route
object
:
giftCard
completionHandler
:^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
if
(
json
&&
!
error
)
{
[
self
updateCheckout
:
checkout
withGiftCardDictionary
:
json
[
@"gift_card"
]
addingGiftCard
:
YES
];
NSDictionary
*
giftCardJSON
=
json
[
@"gift_card"
];
BUYGiftCard
*
giftCard
=
[
self
.
modelManager
insertGiftCardWithJSONDictionary
:
giftCardJSON
];
/* ---------------------------------
* We have to update a copy of the
* checkout that was passed in with
* a new 'paymentDue' value and the
* gift card.
*/
checkout
.
JSONDictionary
=
giftCardJSON
[
@"checkout"
];
[
checkout
addGiftCard
:
giftCard
];
}
block
(
checkout
,
error
);
}];
...
...
@@ -258,8 +252,19 @@
NSURL
*
route
=
[
self
urlForCheckoutsUsingGiftCard
:
giftCard
.
identifier
token
:
checkout
.
token
];
return
[
self
deleteRequestForURL
:
route
completionHandler
:
^
(
NSDictionary
*
json
,
NSHTTPURLResponse
*
response
,
NSError
*
error
)
{
if
(
!
error
)
{
[
self
updateCheckout
:
checkout
withGiftCardDictionary
:
json
[
@"gift_card"
]
addingGiftCard
:
NO
];
if
(
json
&&
!
error
)
{
NSDictionary
*
giftCardJSON
=
json
[
@"gift_card"
];
NSNumber
*
giftCardID
=
giftCardJSON
[
@"id"
];
/* ---------------------------------
* We have to update a copy of the
* checkout that was passed in with
* a new 'paymentDue' value and the
* gift card.
*/
checkout
.
JSONDictionary
=
giftCardJSON
[
@"checkout"
];
[
checkout
removeGiftCardWithIdentifier
:
giftCardID
];
}
block
(
checkout
,
error
);
}];
...
...
Mobile Buy SDK/Mobile Buy SDK/Models/Transient/BUYCheckout.h
View file @
ed403bd4
...
...
@@ -45,6 +45,7 @@
-
(
void
)
updateWithCart
:(
BUYCart
*
)
cart
;
-
(
BUYGiftCard
*
)
giftCardWithIdentifier
:(
NSNumber
*
)
identifier
;
-
(
void
)
addGiftCard
:(
BUYGiftCard
*
)
giftCard
;
-
(
void
)
removeGiftCardWithIdentifier
:(
NSNumber
*
)
identifier
;
@end
...
...
Mobile Buy SDK/Mobile Buy SDK/Models/Transient/BUYCheckout.m
View file @
ed403bd4
...
...
@@ -145,6 +145,11 @@
return
[[
self
.
giftCards
filteredOrderedSetUsingPredicate
:
predicate
]
firstObject
];
}
-
(
void
)
addGiftCard
:
(
BUYGiftCard
*
)
giftCard
{
[
self
.
giftCardsSet
addObject
:
giftCard
];
}
-
(
void
)
removeGiftCardWithIdentifier
:
(
NSNumber
*
)
identifier
{
BUYGiftCard
*
giftCard
=
[
self
giftCardWithIdentifier
:
identifier
];
...
...
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