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
0f998783
Commit
0f998783
authored
Jan 25, 2016
by
David Muzi
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #90 from Shopify/bugfix/applepay-race-condition
Prevent race condition during Apple Pay Checkout
parents
76b37ee0
61d03c98
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
21 deletions
+57
-21
CheckoutViewController.m
...d/Mobile Buy SDK Advanced Sample/CheckoutViewController.m
+3
-2
ProductListViewController.h
...obile Buy SDK Advanced Sample/ProductListViewController.h
+4
-0
ProductListViewController.m
...obile Buy SDK Advanced Sample/ProductListViewController.m
+0
-4
BUYClient.m
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
+0
-2
BUYViewController.m
...y SDK/Mobile Buy SDK/View Controllers/BUYViewController.m
+50
-13
No files found.
Mobile Buy SDK Sample Apps/Sample App Advanced/Mobile Buy SDK Advanced Sample/CheckoutViewController.m
View file @
0f998783
...
@@ -27,12 +27,13 @@
...
@@ -27,12 +27,13 @@
#import "CheckoutViewController.h"
#import "CheckoutViewController.h"
#import "GetCompletionStatusOperation.h"
#import "GetCompletionStatusOperation.h"
#import "SummaryItemsTableViewCell.h"
#import "SummaryItemsTableViewCell.h"
#import "ProductListViewController.h"
@import
Buy
;
@import
Buy
;
@import
PassKit
;
@import
PassKit
;
@import
SafariServices
;
@import
SafariServices
;
NSString
*
const
CheckoutCallbackNotification
=
@"CheckoutCallbackNotification"
;
NSString
*
const
CheckoutCallbackNotification
=
@"CheckoutCallbackNotification"
;
NSString
*
const
MerchantId
=
@""
;
@interface
CheckoutViewController
()
<
GetCompletionStatusOperationDelegate
,
SFSafariViewControllerDelegate
,
PKPaymentAuthorizationViewControllerDelegate
>
@interface
CheckoutViewController
()
<
GetCompletionStatusOperationDelegate
,
SFSafariViewControllerDelegate
,
PKPaymentAuthorizationViewControllerDelegate
>
...
@@ -291,7 +292,7 @@ NSString * const MerchantId = @"";
...
@@ -291,7 +292,7 @@ NSString * const MerchantId = @"";
{
{
PKPaymentRequest
*
paymentRequest
=
[[
PKPaymentRequest
alloc
]
init
];
PKPaymentRequest
*
paymentRequest
=
[[
PKPaymentRequest
alloc
]
init
];
[
paymentRequest
setMerchantIdentifier
:
M
erchantId
];
[
paymentRequest
setMerchantIdentifier
:
M
ERCHANT_ID
];
[
paymentRequest
setRequiredBillingAddressFields
:
PKAddressFieldAll
];
[
paymentRequest
setRequiredBillingAddressFields
:
PKAddressFieldAll
];
[
paymentRequest
setRequiredShippingAddressFields
:
self
.
checkout
.
requiresShipping
?
PKAddressFieldAll
:
PKAddressFieldEmail
|
PKAddressFieldPhone
];
[
paymentRequest
setRequiredShippingAddressFields
:
self
.
checkout
.
requiresShipping
?
PKAddressFieldAll
:
PKAddressFieldEmail
|
PKAddressFieldPhone
];
[
paymentRequest
setSupportedNetworks
:@[
PKPaymentNetworkVisa
,
PKPaymentNetworkMasterCard
]];
[
paymentRequest
setSupportedNetworks
:@[
PKPaymentNetworkVisa
,
PKPaymentNetworkMasterCard
]];
...
...
Mobile Buy SDK Sample Apps/Sample App Advanced/Mobile Buy SDK Advanced Sample/ProductListViewController.h
View file @
0f998783
...
@@ -27,6 +27,10 @@
...
@@ -27,6 +27,10 @@
@import
UIKit
;
@import
UIKit
;
@import
Buy
;
@import
Buy
;
#warning - Enter your merchant ID
// Adding a merchant ID will show Apple Pay in the BUYProductViewController (on supported devices)
#define MERCHANT_ID @""
@interface
ProductListViewController
:
UITableViewController
@interface
ProductListViewController
:
UITableViewController
-
(
instancetype
)
initWithClient
:(
BUYClient
*
)
client
collection
:(
BUYCollection
*
)
collection
;
-
(
instancetype
)
initWithClient
:(
BUYClient
*
)
client
collection
:(
BUYCollection
*
)
collection
;
...
...
Mobile Buy SDK Sample Apps/Sample App Advanced/Mobile Buy SDK Advanced Sample/ProductListViewController.m
View file @
0f998783
...
@@ -30,10 +30,6 @@
...
@@ -30,10 +30,6 @@
#import "ProductViewControllerThemeStyleTableViewCell.h"
#import "ProductViewControllerThemeStyleTableViewCell.h"
#import "ProductViewControllerThemeTintColorTableViewCell.h"
#import "ProductViewControllerThemeTintColorTableViewCell.h"
#warning - Enter your merchant ID
// Adding a merchant ID will show Apple Pay in the BUYProductViewController (on supported devices)
#define MERCHANT_ID @""
@interface
ProductListViewController
()
<
UIViewControllerPreviewingDelegate
>
@interface
ProductListViewController
()
<
UIViewControllerPreviewingDelegate
>
@property
(
nonatomic
,
strong
)
BUYClient
*
client
;
@property
(
nonatomic
,
strong
)
BUYClient
*
client
;
...
...
Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient.m
View file @
0f998783
...
@@ -90,8 +90,6 @@ static NSString *const kBUYClientPathCollectionPublications = @"collection_publi
...
@@ -90,8 +90,6 @@ static NSString *const kBUYClientPathCollectionPublications = @"collection_publi
self
.
queue
=
dispatch_get_main_queue
();
self
.
queue
=
dispatch_get_main_queue
();
NSURLSessionConfiguration
*
config
=
[
NSURLSessionConfiguration
defaultSessionConfiguration
];
NSURLSessionConfiguration
*
config
=
[
NSURLSessionConfiguration
defaultSessionConfiguration
];
// ensure requests are sent serially
config
.
HTTPMaximumConnectionsPerHost
=
1
;
config
.
HTTPAdditionalHeaders
=
@{
@"User-Agent"
:
[
NSString
stringWithFormat
:
@"Mobile Buy SDK iOS/%@"
,
BUYVersionString
]};
config
.
HTTPAdditionalHeaders
=
@{
@"User-Agent"
:
[
NSString
stringWithFormat
:
@"Mobile Buy SDK iOS/%@"
,
BUYVersionString
]};
self
.
session
=
[
NSURLSession
sessionWithConfiguration
:
config
delegate
:
self
delegateQueue
:
nil
];
self
.
session
=
[
NSURLSession
sessionWithConfiguration
:
config
delegate
:
self
delegateQueue
:
nil
];
...
...
Mobile Buy SDK/Mobile Buy SDK/View Controllers/BUYViewController.m
View file @
0f998783
...
@@ -89,12 +89,6 @@ NSString * BUYURLKey = @"url";
...
@@ -89,12 +89,6 @@ NSString * BUYURLKey = @"url";
if
(
error
==
nil
)
{
if
(
error
==
nil
)
{
self
.
shop
=
shop
;
self
.
shop
=
shop
;
}
}
else
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
controllerFailedToStartApplePayProcess
:)])
{
[
self
.
delegate
controllerFailedToStartApplePayProcess
:
self
];
}
}
self
.
isLoadingShop
=
NO
;
self
.
isLoadingShop
=
NO
;
...
@@ -145,22 +139,65 @@ NSString * BUYURLKey = @"url";
...
@@ -145,22 +139,65 @@ NSString * BUYURLKey = @"url";
// Default to the failure state, since cancelling a payment would not update the state and thus appear as a success
// Default to the failure state, since cancelling a payment would not update the state and thus appear as a success
self
.
paymentAuthorizationStatus
=
PKPaymentAuthorizationStatusFailure
;
self
.
paymentAuthorizationStatus
=
PKPaymentAuthorizationStatusFailure
;
if
(
self
.
shop
==
nil
&&
self
.
isLoadingShop
==
NO
)
{
/**
// since requests are sent serially, this will return before the checkout is created
* To perform an Apple Pay checkout, we need both the BUYShop object, and a BUYCheckout
[
self
loadShopWithCallback
:
nil
];
* We will download both in parallel, and continue with the checkout when they both succeed
*/
dispatch_group_t
group
=
dispatch_group_create
();
__block
NSError
*
checkoutError
=
nil
;
// download the shop
if
(
self
.
shop
!=
nil
)
{
dispatch_group_enter
(
group
);
[
self
loadShopWithCallback
:
^
(
BOOL
success
,
NSError
*
error
)
{
if
(
error
)
{
checkoutError
=
error
;
if
([
self
.
delegate
respondsToSelector
:
@selector
(
controllerFailedToStartApplePayProcess
:)])
{
[
self
.
delegate
controllerFailedToStartApplePayProcess
:
self
];
}
}
dispatch_group_leave
(
group
);
}];
}
}
// create the checkout on Shopify
dispatch_group_enter
(
group
);
[
self
handleCheckout
:
checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
[
self
handleCheckout
:
checkout
completion
:
^
(
BUYCheckout
*
checkout
,
NSError
*
error
)
{
if
(
error
)
{
checkoutError
=
error
;
if
([
self
.
delegate
respondsToSelector
:
@selector
(
controller
:
failedToCreateCheckout
:
)])
{
[
self
.
delegate
controller
:
self
failedToCreateCheckout
:
error
];
}
}
else
{
self
.
checkout
=
checkout
;
self
.
checkout
=
checkout
;
}
dispatch_group_leave
(
group
);
}];
// When we have both the shop and checkout, we can request the payment with Apple Pay
dispatch_group_notify
(
group
,
dispatch_get_main_queue
(),
^
{
if
(
self
.
checkout
&&
self
.
shop
)
{
if
(
error
==
nil
)
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
controllerWillCheckoutViaApplePay
:)])
{
if
([
self
.
delegate
respondsToSelector
:
@selector
(
controllerWillCheckoutViaApplePay
:)])
{
[
self
.
delegate
controllerWillCheckoutViaApplePay
:
self
];
[
self
.
delegate
controllerWillCheckoutViaApplePay
:
self
];
}
}
self
.
applePayHelper
=
[[
BUYApplePayHelpers
alloc
]
initWithClient
:
self
.
client
checkout
:
checkout
shop
:
self
.
shop
];
self
.
applePayHelper
=
[[
BUYApplePayHelpers
alloc
]
initWithClient
:
self
.
client
checkout
:
self
.
checkout
shop
:
self
.
shop
];
[
self
requestPayment
];
}
}
[
self
handleCheckoutCompletion
:
checkout
error
:
error
];
else
{
}];
if
([
self
.
delegate
respondsToSelector
:
@selector
(
controller
:
failedToCreateCheckout
:
)])
{
[
self
.
delegate
controller
:
self
failedToCreateCheckout
:
checkoutError
];
}
}
});
}
}
-
(
void
)
startWebCheckout
:
(
BUYCheckout
*
)
checkout
-
(
void
)
startWebCheckout
:
(
BUYCheckout
*
)
checkout
...
...
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