private void DemoNativeFlowWithProduct(BUYProduct product) { if (checkoutCreationTask != null && checkoutCreationTask.State == NSUrlSessionTaskState.Running) { checkoutCreationTask.Cancel(); } var cart = new BUYCart(); cart.AddVariant(product.Variants [0]); var checkout = new BUYCheckout(cart); // Apply billing and shipping address, as well as email to the checkout checkout.ShippingAddress = Address; checkout.BillingAddress = Address; checkout.Email = "*****@*****.**"; client.UrlScheme = "xamarinsample://"; UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; checkoutCreationTask = client.CreateCheckout(checkout, (chkout, error) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; if (error == null && chkout != null) { var shippingController = new ShippingRatesTableViewController(client, chkout); NavigationController.PushViewController(shippingController, true); } else { Console.WriteLine("Error creating checkout: {0}", error); } }); }
private void ApplyGiftCard() { var alertController = UIAlertController.Create("Enter Gift Card Code", null, UIAlertControllerStyle.Alert); alertController.AddTextField(textField => { textField.Placeholder = "Gift Card Code"; }); alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, action => { Console.WriteLine("Cancel action"); })); alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, action => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; client.ApplyGiftCard(alertController.TextFields [0].Text, checkout, (checkout, error) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; if (error == null && checkout != null) { Console.WriteLine("Successfully added gift card"); this.checkout = checkout; TableView.ReloadData(); } else { Console.WriteLine("Error applying gift card: {0}", error); } }); })); PresentViewController(alertController, true, null); }
private void CheckoutWithApplePay(object sender, EventArgs e) { var request = GetPaymentRequest(); applePayHelper = new BUYApplePayHelpers(client, checkout, shop); var paymentController = new PKPaymentAuthorizationViewController(request); // Add additional methods if needed and forward the callback to BUYApplePayHelpers paymentController.DidAuthorizePayment += (_, args) => { applePayHelper.DidAuthorizePayment(paymentController, args.Payment, args.Completion); checkout = applePayHelper.Checkout; GetCompletedCheckout(null); }; paymentController.PaymentAuthorizationViewControllerDidFinish += (_, args) => { applePayHelper.PaymentAuthorizationViewControllerDidFinish(paymentController); }; paymentController.DidSelectShippingAddress += (_, args) => { applePayHelper.DidSelectShippingAddress(paymentController, args.Address, args.Completion); }; paymentController.DidSelectShippingContact += (_, args) => { applePayHelper.DidSelectShippingContact(paymentController, args.Contact, args.Completion); }; paymentController.DidSelectShippingMethod += (_, args) => { applePayHelper.DidSelectShippingMethod(paymentController, args.ShippingMethod, args.Completion); }; /** * * Alternatively we can set the delegate to applePayHelper. * * If you do not care about any IPKPaymentAuthorizationViewControllerDelegate callbacks * uncomment the code below to let BUYApplePayHelpers take care of them automatically. * You can then also safely remove the IPKPaymentAuthorizationViewControllerDelegate * events above. * * // paymentController.Delegate = applePayHelper; * * If you keep the events as the delegate, you have a chance to intercept the * IPKPaymentAuthorizationViewControllerDelegate callbacks and add any additional logging * and method calls as you need. Ensure that you forward them to the BUYApplePayHelpers * class by calling the delegate methods on BUYApplePayHelpers which already implements * the IPKPaymentAuthorizationViewControllerDelegate interface. * */ PresentViewController(paymentController, true, null); }
private void AddCreditCardToCheckout(Action <bool> callback) { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; client.StoreCreditCard(CreditCard, checkout, (checkout, paymentSessionId, error) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; if (error == null && checkout != null) { Console.WriteLine("Successfully added credit card to checkout"); this.checkout = checkout; TableView.ReloadData(); } else { Console.WriteLine("Error applying credit card: {0}", error); } callback(error == null && checkout != null); }); }
private void CheckoutWithCreditCard(object sender, EventArgs e) { // First, the credit card must be stored on the checkout AddCreditCardToCheckout(success => { if (success) { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; // Upon successfully adding the credit card to the checkout, complete checkout must be called immediately client.CompleteCheckout(checkout, (checkout, error) => { if (error == null && checkout != null) { Console.WriteLine("Successfully completed checkout"); this.checkout = checkout; var completionOperation = new GetCompletionStatusOperation(client, checkout); completionOperation.DidReceiveCompletionStatus += (op, status) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; Console.WriteLine("Successfully got completion status: {0}", status); GetCompletedCheckout(null); }; completionOperation.FailedToReceiveCompletionStatus += (op, err) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; Console.WriteLine("Error getting completion status: {0}", err); }; UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; NSOperationQueue.MainQueue.AddOperation(completionOperation); } else { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; Console.WriteLine("Error completing checkout: {0}", error); } }); } }); }
private void GetCompletedCheckout(Action completionBlock) { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; client.GetCheckout(checkout, (checkout, error) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; if (error != null) { Console.WriteLine("Unable to get completed checkout"); Console.WriteLine(error); } if (checkout != null) { this.checkout = checkout; Console.WriteLine(checkout); } if (completionBlock != null) { completionBlock(); } }); }
public GetShippingRatesOperation(BUYClient client, BUYCheckout checkout) { this.client = client; this.Checkout = checkout; }
public CheckoutViewController(BUYClient client, BUYCheckout checkout) : base(UITableViewStyle.Grouped) { this.client = client; this.checkout = checkout; }
private void GetCompletedCheckout(Action completionBlock) { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; client.GetCheckout (checkout, (checkout, error) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; if (error != null) { Console.WriteLine ("Unable to get completed checkout"); Console.WriteLine (error); } if (checkout != null) { this.checkout = checkout; Console.WriteLine (checkout); } if (completionBlock != null) { completionBlock (); } }); }
private void CheckoutWithCreditCard(object sender, EventArgs e) { // First, the credit card must be stored on the checkout AddCreditCardToCheckout (success => { if (success) { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; // Upon successfully adding the credit card to the checkout, complete checkout must be called immediately client.CompleteCheckout (checkout, (checkout, error) => { if (error == null && checkout != null) { Console.WriteLine ("Successfully completed checkout"); this.checkout = checkout; var completionOperation = new GetCompletionStatusOperation (client, checkout); completionOperation.DidReceiveCompletionStatus += (op, status) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; Console.WriteLine ("Successfully got completion status: {0}", status); GetCompletedCheckout (null); }; completionOperation.FailedToReceiveCompletionStatus += (op, err) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; Console.WriteLine ("Error getting completion status: {0}", err); }; UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; NSOperationQueue.MainQueue.AddOperation (completionOperation); } else { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; Console.WriteLine ("Error completing checkout: {0}", error); } }); } }); }
private void CheckoutWithApplePay(object sender, EventArgs e) { var request = GetPaymentRequest (); applePayHelper = new BUYApplePayHelpers (client, checkout, shop); var paymentController = new PKPaymentAuthorizationViewController (request); // Add additional methods if needed and forward the callback to BUYApplePayHelpers paymentController.DidAuthorizePayment += (_, args) => { applePayHelper.DidAuthorizePayment (paymentController, args.Payment, args.Completion); checkout = applePayHelper.Checkout; GetCompletedCheckout (null); }; paymentController.PaymentAuthorizationViewControllerDidFinish += (_, args) => { applePayHelper.PaymentAuthorizationViewControllerDidFinish (paymentController); }; paymentController.DidSelectShippingAddress += (_, args) => { applePayHelper.DidSelectShippingAddress (paymentController, args.Address, args.Completion); }; paymentController.DidSelectShippingContact += (_, args) => { applePayHelper.DidSelectShippingContact (paymentController, args.Contact, args.Completion); }; paymentController.DidSelectShippingMethod += (_, args) => { applePayHelper.DidSelectShippingMethod (paymentController, args.ShippingMethod, args.Completion); }; /** * * Alternatively we can set the delegate to applePayHelper. * * If you do not care about any IPKPaymentAuthorizationViewControllerDelegate callbacks * uncomment the code below to let BUYApplePayHelpers take care of them automatically. * You can then also safely remove the IPKPaymentAuthorizationViewControllerDelegate * events above. * * // paymentController.Delegate = applePayHelper; * * If you keep the events as the delegate, you have a chance to intercept the * IPKPaymentAuthorizationViewControllerDelegate callbacks and add any additional logging * and method calls as you need. Ensure that you forward them to the BUYApplePayHelpers * class by calling the delegate methods on BUYApplePayHelpers which already implements * the IPKPaymentAuthorizationViewControllerDelegate interface. * */ PresentViewController (paymentController, true, null); }
private void DemoNativeFlowWithProduct(BUYProduct product) { if (checkoutCreationTask != null && checkoutCreationTask.State == NSUrlSessionTaskState.Running) { checkoutCreationTask.Cancel (); } var cart = new BUYCart (); cart.AddVariant (product.Variants [0]); var checkout = new BUYCheckout (cart); // Apply billing and shipping address, as well as email to the checkout checkout.ShippingAddress = Address; checkout.BillingAddress = Address; checkout.Email = "*****@*****.**"; client.UrlScheme = "xamarinsample://"; UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; checkoutCreationTask = client.CreateCheckout (checkout, (chkout, error) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; if (error == null && chkout != null) { var shippingController = new ShippingRatesTableViewController (client, chkout); NavigationController.PushViewController (shippingController, true); } else { Console.WriteLine ("Error creating checkout: {0}", error); } }); }
public PreCheckoutViewController(BUYClient client, BUYCheckout checkout) : base(UITableViewStyle.Grouped) { this.client = client; this.checkout = checkout; }
private void ApplyGiftCard() { var alertController = UIAlertController.Create ("Enter Gift Card Code", null, UIAlertControllerStyle.Alert); alertController.AddTextField (textField => { textField.Placeholder = "Gift Card Code"; }); alertController.AddAction (UIAlertAction.Create ("Cancel", UIAlertActionStyle.Cancel, action => { Console.WriteLine ("Cancel action"); })); alertController.AddAction (UIAlertAction.Create ("OK", UIAlertActionStyle.Default, action => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; client.ApplyGiftCard (alertController.TextFields [0].Text, checkout, (checkout, error) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; if (error == null && checkout != null) { Console.WriteLine ("Successfully added gift card"); this.checkout = checkout; TableView.ReloadData (); } else { Console.WriteLine ("Error applying gift card: {0}", error); } }); })); PresentViewController (alertController, true, null); }
public GetShippingRatesOperation(BUYClient client, BUYCheckout checkout) { this.client = client; this.Checkout = checkout; }
public GetCompletionStatusOperation(BUYClient client, BUYCheckout checkout) { this.client = client; this.Checkout = checkout; }
public ShippingRatesTableViewController(BUYClient client, BUYCheckout checkout) { this.client = client; this.checkout = checkout; }
private void AddCreditCardToCheckout(Action<bool> callback) { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; client.StoreCreditCard (CreditCard, checkout, (checkout, paymentSessionId, error) => { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; if (error == null && checkout != null) { Console.WriteLine ("Successfully added credit card to checkout"); this.checkout = checkout; TableView.ReloadData (); } else { Console.WriteLine ("Error applying credit card: {0}", error); } callback (error == null && checkout != null); }); }
public ShippingRatesTableViewController(BUYClient client, BUYCheckout checkout) { this.client = client; this.checkout = checkout; }
public GetCompletionStatusOperation(BUYClient client, BUYCheckout checkout) { this.client = client; this.Checkout = checkout; }