void PerformApplePayAction(Judo judo, ApplePayModel model, JudoSuccessCallback success, JudoFailureCallback failure, IApplePayRequest applePayRequest) { try { PKPaymentRequest request = GetPKPaymentRequest(model); var rootView = GetCurrentViewController(); var pkDelegate = new JudoPKPaymentAuthorizationViewControllerDelegate(judo, model, success, failure, applePayRequest); PKPaymentAuthorizationViewController pkController = new PKPaymentAuthorizationViewController(request) { Delegate = pkDelegate }; rootView.PresentViewController(pkController, true, null); } catch (Exception e) { var judoError = new JudoError { Exception = e.InnerException }; failure(judoError); } }
async Task PerformApplePayAction(PKPayment payment, Action<PKPaymentAuthorizationStatus> completion, PKPaymentAuthorizationViewController controller) { var jObject = ConvertToJObject(payment.Token.PaymentData); var paymentServiceModel = new PKPaymentViewModel { Amount = _applePayModel.ItemsTotalAmount(), ConsumerReference = _applePayModel.ConsumerRef, JudoID = _judo.JudoId, PaymentData = jObject, PaymentInstrumentName = payment.Token.PaymentInstrumentName ?? string.Empty, PaymentNetwork = payment.Token.PaymentNetwork ?? string.Empty }; var response = await _applePayRequest.Perform(paymentServiceModel); if (response.ConsideredSuccessful) { if (response.ReceiptModelPresent() && _successCallBack != null) { completion(PKPaymentAuthorizationStatus.Success); controller.DismissViewController(true, null); _successCallBack(response.ReceiptModel); } } else { completion(PKPaymentAuthorizationStatus.Failure); controller.DismissViewController(true, null); if (response.ReceiptModelPresent()) { _failureCallback(response.ErrorModel, response.ReceiptModel); } else { _failureCallback(response.ErrorModel); } } }
public void PaymentAuthorizationViewControllerDidFinish(PKPaymentAuthorizationViewController controller) { controller.DismissViewController(true, null); }
public void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action<PKPaymentAuthorizationStatus> completion) { PerformApplePayAction(payment, completion, controller); }
public override void PaymentAuthorizationViewControllerDidFinish(PKPaymentAuthorizationViewController controller) { this.DidFinish?.Invoke(this, new EventArgs()); }
public override void WillAuthorizePayment(PKPaymentAuthorizationViewController controller) { }
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); }
public async void DidAuthorizePayment (PKPaymentAuthorizationViewController controller, PKPayment payment, Action<PKPaymentAuthorizationStatus> completion) { await HandlePaymentAuthorization (payment, completion); }
/// <summary> /// This is where you would send your payment to be processed - here we will /// simply present a confirmation screen. If your payment processor failed the /// payment you would return `completion(PKPaymentAuthorizationStatus.Failure)` instead. Remember to never /// attempt to decrypt the payment token on device. /// </summary> public void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { paymentToken = payment.Token; completion(PKPaymentAuthorizationStatus.Success); PerformSegue(confirmationSegue, this); }
public override void WillAuthorizePayment(PKPaymentAuthorizationViewController controller) { //throw new NotImplementedException(); }
public override void PaymentAuthorizationViewControllerDidFinish (PKPaymentAuthorizationViewController controller) { controller.DismissViewController(true, null); }
public void ApplyPayButtonClicked () { if (!PKPaymentAuthorizationViewController.CanMakePaymentsUsingNetworks (supportedNetworks)) { ShowAuthorizationAlert (); return; } // Set up our payment request. var paymentRequest = new PKPaymentRequest (); // Our merchant identifier needs to match what we previously set up in // the Capabilities window (or the developer portal). paymentRequest.MerchantIdentifier = AppConfiguration.Merchant.Identififer; // Both country code and currency code are standard ISO formats. Country // should be the region you will process the payment in. Currency should // be the currency you would like to charge in. paymentRequest.CountryCode = "US"; paymentRequest.CurrencyCode = "USD"; // The networks we are able to accept. paymentRequest.SupportedNetworks = supportedNetworks; // Ask your payment processor what settings are right for your app. In // most cases you will want to leave this set to ThreeDS. paymentRequest.MerchantCapabilities = PKMerchantCapability.ThreeDS; // An array of `PKPaymentSummaryItems` that we'd like to display on the // sheet (see the MakeSummaryItems method). paymentRequest.PaymentSummaryItems = MakeSummaryItems (false); // Request shipping information, in this case just postal address. paymentRequest.RequiredShippingAddressFields = PKAddressField.PostalAddress; // Display the view controller. var viewController = new PKPaymentAuthorizationViewController (paymentRequest); viewController.Delegate = this; PresentViewController (viewController, true, null); }
public void PaymentAuthorizationViewControllerDidFinish (PKPaymentAuthorizationViewController controller) { // We always need to dismiss our payment view controller when done. DismissViewController (true, null); }
/// <summary> /// This is where you would send your payment to be processed - here we will /// simply present a confirmation screen. If your payment processor failed the /// payment you would return `completion(PKPaymentAuthorizationStatus.Failure)` instead. Remember to never /// attempt to decrypt the payment token on device. /// </summary> public void DidAuthorizePayment (PKPaymentAuthorizationViewController controller, PKPayment payment, Action<PKPaymentAuthorizationStatus> completion) { paymentToken = payment.Token; completion (PKPaymentAuthorizationStatus.Success); PerformSegue (confirmationSegue, this); }
void DidSelectShippingContact (PKPaymentAuthorizationViewController controller, PKContact contact, PKPaymentShippingAddressSelected completion) { // Create a shipping method. Shipping methods use PKShippingMethod, // which inherits from PKPaymentSummaryItem. It adds a detail property // you can use to specify information like estimated delivery time. var shipping = new PKShippingMethod { Label = "Standard Shipping", Amount = NSDecimalNumber.Zero, Detail = "Delivers within two working days" }; // Note that this is a contrived example. Because addresses can come from // many sources on iOS they may not always have the fields you want. // Your application should be sure to verify the address is correct, // and return the appropriate status. If the address failed to pass validation // you should return `InvalidShippingPostalAddress` instead of `Success`. var address = contact.PostalAddress; var requiresInternationalSurcharge = address.Country != "United States"; PKPaymentSummaryItem[] summaryItems = MakeSummaryItems (requiresInternationalSurcharge); completion (PKPaymentAuthorizationStatus.Success, new [] { shipping }, summaryItems); }
public void WillAuthorizePayment(PKPaymentAuthorizationViewController controller) { }
public void PaymentAuthorizationViewControllerDidFinish(PKPaymentAuthorizationViewController controller) { // We always need to dismiss our payment view controller when done. DismissViewController(true, null); }
public void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action <PKPaymentAuthorizationStatus> completion) { ClearPaymentWithJudo(payment, _customerRef, completion); }