Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Sample App: Prefetch BUYShop for Apple Pay #4

Merged
merged 4 commits into from Oct 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -38,6 +38,7 @@ @interface CheckoutViewController () <GetCompletionStatusOperationDelegate, SFSa

@property (nonatomic, strong) BUYCheckout *checkout;
@property (nonatomic, strong) BUYClient *client;
@property (nonatomic, strong) BUYShop *shop;
@property (nonatomic, strong) NSArray *summaryItems;
@property (nonatomic, strong) BUYApplePayHelpers *applePayHelper;

Expand Down Expand Up @@ -100,6 +101,11 @@ - (void)viewDidLoad {
self.tableView.tableFooterView = footerView;

[self.tableView registerClass:[SummaryItemsTableViewCell class] forCellReuseIdentifier:@"SummaryCell"];

// Prefetch the shop object for Apple Pay
[self.client getShop:^(BUYShop *shop, NSError *error) {
_shop = shop;
}];
}

- (void)setCheckout:(BUYCheckout *)checkout
Expand Down Expand Up @@ -239,8 +245,8 @@ - (void)checkoutWithApplePay
PKPaymentRequest *request = [self paymentRequest];

PKPaymentAuthorizationViewController *paymentController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];

self.applePayHelper = [[BUYApplePayHelpers alloc] initWithClient:self.client checkout:self.checkout];
self.applePayHelper = [[BUYApplePayHelpers alloc] initWithClient:self.client checkout:self.checkout shop:self.shop];
paymentController.delegate = self;

/**
Expand Down Expand Up @@ -272,10 +278,10 @@ - (PKPaymentRequest *)paymentRequest
[paymentRequest setRequiredShippingAddressFields:self.checkout.requiresShipping ? PKAddressFieldAll : PKAddressFieldEmail|PKAddressFieldPhone];
[paymentRequest setSupportedNetworks:@[PKPaymentNetworkVisa, PKPaymentNetworkMasterCard]];
[paymentRequest setMerchantCapabilities:PKMerchantCapability3DS];
[paymentRequest setCountryCode:@"US"];
[paymentRequest setCurrencyCode:@"USD"];
[paymentRequest setCountryCode:self.shop.country ?: @"US"];
[paymentRequest setCurrencyCode:self.shop.currency ?: @"USD"];

[paymentRequest setPaymentSummaryItems: [self.checkout buy_summaryItems]];
[paymentRequest setPaymentSummaryItems:[self.checkout buy_summaryItemsWithShopName:self.shop.name]];

return paymentRequest;
}
Expand All @@ -288,6 +294,17 @@ - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController
{
// Add additional methods if needed and forward the callback to BUYApplePayHelpers
[self.applePayHelper paymentAuthorizationViewController:controller didAuthorizePayment:payment completion:completion];

// Get the completed checkout
[self.client getCheckout:self.applePayHelper.checkout completion:^(BUYCheckout *checkout, NSError *error) {
if (error) {
NSLog(@"Unable to get completed checkout");
NSLog(@"%@", error);
}
if (checkout) {
NSLog(@"%@", checkout);
}
}];
}

- (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller
Expand Down