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
eb7cd466
Commit
eb7cd466
authored
Jun 13, 2016
by
Brent Gulanowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out distinct operation from body of completion block.
parent
7d727d9d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
38 deletions
+37
-38
BUYApplePayAuthorizationDelegate.m
...K/Mobile Buy SDK/Utils/BUYApplePayAuthorizationDelegate.m
+37
-38
No files found.
Mobile Buy SDK/Mobile Buy SDK/Utils/BUYApplePayAuthorizationDelegate.m
View file @
eb7cd466
...
...
@@ -38,6 +38,8 @@
const
NSTimeInterval
PollDelay
=
0
.
5
;
typedef
void
(
^
AddressUpdateCompletion
)(
PKPaymentAuthorizationStatus
,
NSArray
*
shippingMethods
,
NSArray
*
summaryItems
);
@interface
BUYApplePayAuthorizationDelegate
()
@property
(
nonatomic
,
strong
)
BUYCheckout
*
checkout
;
...
...
@@ -160,7 +162,7 @@ const NSTimeInterval PollDelay = 0.5;
#pragma mark -
-
(
void
)
updateCheckoutWithAddressCompletion
:(
void
(
^
)(
PKPaymentAuthorizationStatus
,
NSArray
*
shippingMethods
,
NSArray
*
summaryItems
)
)
completion
-
(
void
)
updateCheckoutWithAddressCompletion
:(
AddressUpdateCompletion
)
completion
{
// This method call is internal to selection of shipping address that are returned as partial from PKPaymentAuthorizationViewController
// However, to ensure we never set partialAddresses to NO, we want to guard the setter. Should PKPaymentAuthorizationViewController ever
...
...
@@ -170,45 +172,19 @@ const NSTimeInterval PollDelay = 0.5;
}
if
([
self
.
checkout
.
shippingAddress
isValidAddressForShippingRates
])
{
[
self
.
client
updateCheckout
:
self
.
checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
checkout
&&
error
==
nil
)
{
[
self
.
client
updateCheckout
:
self
.
checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
checkout
&&
!
error
)
{
self
.
checkout
=
checkout
;
if
([
self
.
checkout
requiresShipping
]
==
NO
)
{
completion
(
PKPaymentAuthorizationStatusSuccess
,
nil
,
[
self
.
checkout
buy_summaryItemsWithShopName
:
self
.
shopName
]);
}
else
{
self
.
shippingRates
=
@[];
[
self
.
client
getShippingRatesForCheckoutWithToken
:
self
.
checkout
.
token
completion
:
^
(
NSArray
*
shippingRates
,
BUYStatus
status
,
NSError
*
error
)
{
self
.
shippingRates
=
shippingRates
;
if
(
shippingRates
)
{
NSArray
*
shippingMethods
=
[
BUYShippingRate
buy_convertShippingRatesToShippingMethods
:
shippingRates
];
if
(
shippingMethods
.
count
>
0
)
{
[
self
selectShippingMethod
:
shippingMethods
[
0
]
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
checkout
&&
error
==
nil
)
{
self
.
checkout
=
checkout
;
}
completion
(
error
?
PKPaymentAuthorizationStatusFailure
:
PKPaymentAuthorizationStatusSuccess
,
shippingMethods
,
[
self
.
checkout
buy_summaryItemsWithShopName
:
self
.
shopName
]);
}];
}
else
{
self
.
lastError
=
[
NSError
errorWithDomain
:
BUYShopifyError
code
:
BUYShopifyError_NoShippingMethodsToAddress
userInfo
:
nil
];
completion
(
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
,
nil
,
[
self
.
checkout
buy_summaryItemsWithShopName
:
self
.
shopName
]);
}
}
else
{
completion
(
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
,
nil
,
[
self
.
checkout
buy_summaryItemsWithShopName
:
self
.
shopName
]);
}
}];
}
}
else
{
}
else
if
(
error
)
{
self
.
lastError
=
error
;
completion
(
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
,
nil
,
[
self
.
checkout
buy_summaryItemsWithShopName
:
self
.
shopName
]);
}
if
(
checkout
.
requiresShipping
)
{
self
.
shippingRates
=
@[];
[
self
updateShippingRatesCompletion
:
completion
];
}
else
{
completion
(
PKPaymentAuthorizationStatusSuccess
,
nil
,
[
self
.
checkout
buy_summaryItemsWithShopName
:
self
.
shopName
]);
}
}];
}
...
...
@@ -217,6 +193,29 @@ const NSTimeInterval PollDelay = 0.5;
}
}
-
(
void
)
updateShippingRatesCompletion
:(
AddressUpdateCompletion
)
completion
{
[
self
.
client
getShippingRatesForCheckoutWithToken
:
self
.
checkout
.
token
completion
:
^
(
NSArray
*
shippingRates
,
BUYStatus
status
,
NSError
*
error
)
{
self
.
shippingRates
=
shippingRates
;
NSArray
*
shippingMethods
=
[
BUYShippingRate
buy_convertShippingRatesToShippingMethods
:
shippingRates
];
if
(
shippingMethods
.
count
>
0
)
{
[
self
selectShippingMethod
:
shippingMethods
[
0
]
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
checkout
&&
!
error
)
{
self
.
checkout
=
checkout
;
}
completion
(
error
?
PKPaymentAuthorizationStatusFailure
:
PKPaymentAuthorizationStatusSuccess
,
shippingMethods
,
[
self
.
checkout
buy_summaryItemsWithShopName
:
self
.
shopName
]);
}];
}
else
{
self
.
lastError
=
[
NSError
errorWithDomain
:
BUYShopifyError
code
:
BUYShopifyError_NoShippingMethodsToAddress
userInfo
:
nil
];
completion
(
PKPaymentAuthorizationStatusInvalidShippingPostalAddress
,
nil
,
[
self
.
checkout
buy_summaryItemsWithShopName
:
self
.
shopName
]);
}
}];
}
#pragma mark - Internal -
-
(
BUYShippingRate
*
)
rateForShippingMethod
:(
PKShippingMethod
*
)
method
...
...
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