コード例 #1
0
        public void WeakRequiredBillingContactFields()
        {
            TestRuntime.AssertXcodeVersion(9, 0);

            using (var pr = new PKPaymentRequest()) {
                Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(0), "Count");

                using (var set = new NSMutableSet()) {
                    pr.WeakRequiredBillingContactFields = set;
                    Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(0), "Count-0");
                    set.Add(PKContactFields.PostalAddress.GetConstant());
                    Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(1), "Count-1");
                    set.Add(PKContactFields.EmailAddress.GetConstant());
                    Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(2), "Count-2");
                    set.Add(PKContactFields.PhoneNumber.GetConstant());
                    Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(3), "Count-3");
                    set.Add(PKContactFields.Name.GetConstant());
                    Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(4), "Count-5");
                    set.Add(PKContactFields.PhoneticName.GetConstant());
                    Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(5), "Count-5");
                    set.Add(PKContactFields.PhoneticName.GetConstant());
                    Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(5), "Count-5b");
                    set.Remove(PKContactFields.PhoneticName.GetConstant());
                    Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(4), "Count-4b");
                    set.RemoveAll();
                    Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(0), "Count-0b");
                }
            }
        }
コード例 #2
0
        public bool AuthorizePayment(string Amount)
        {
            if (!PKPaymentAuthorizationViewController.CanMakePayments)
            {
                ShowAuthorizationAlert();
            }

            if (!PKPaymentAuthorizationViewController.CanMakePaymentsUsingNetworks(supportedNetworks))
            {
                ShowAuthorizationAlert();
            }

            NSString[] paymentNetworks = new NSString[] { PKPaymentNetwork.Visa, PKPaymentNetwork.Discover,

                                                          PKPaymentNetwork.MasterCard, PKPaymentNetwork.Amex };
            var merchantID = "merchant.com.orem.grylloo";
            // Enter merchant ID registered in apple.developer.com

            PKPaymentRequest paymentRequest = new PKPaymentRequest();

            paymentRequest.MerchantIdentifier   = merchantID;
            paymentRequest.SupportedNetworks    = paymentNetworks;
            paymentRequest.MerchantCapabilities = PKMerchantCapability.ThreeDS;
            paymentRequest.CountryCode          = "US";
            paymentRequest.CurrencyCode         = "USD";

            paymentRequest.PaymentSummaryItems = new PKPaymentSummaryItem[] {
                new PKPaymentSummaryItem()
                {
                    Label  = "Payable Amount",
                    Amount = new NSDecimalNumber(Amount)
                }
            };
            Task.Delay(10000);
            PKPaymentAuthorizationViewController controller = new
                                                              PKPaymentAuthorizationViewController(paymentRequest);

            controller.Delegate = (PassKit.IPKPaymentAuthorizationViewControllerDelegate)Self;
            var rootController = UIApplication.SharedApplication.
                                 KeyWindow.RootViewController;

            rootController.PresentViewController(controller,
                                                 true, null);


            Task.Delay(50000);

            return(false);
        }
コード例 #3
0
        public static void Init(AppDelegate appDelegate)
        {
            if (isInitialised)
            {
                return;
            }

            OnGetTokenRequestReceived += (tcs, totalToPay, donations, coverStripeFee) =>
            {
                var summaryItems = donations.Select(x => new PKPaymentSummaryItem()
                {
                    Label  = x.ProjectNameEn,
                    Amount = new NSDecimalNumber(x.Amount / 100d)
                }).ToList();
                if (coverStripeFee)
                {
                    summaryItems.Add(new PKPaymentSummaryItem()
                    {
                        Label  = "Stripe Processing Fee",
                        Amount = new NSDecimalNumber(Math.Ceiling((totalToPay * 0.014d) + 20d) / 100d)
                    });
                }
                summaryItems.Add(new PKPaymentSummaryItem()
                {
                    Label  = "Street Kids Direct",
                    Amount = new NSDecimalNumber(totalToPay / 100d)
                });
                var paymentRequest = new PKPaymentRequest
                {
                    MerchantIdentifier   = App.AppleMerchantId,
                    CountryCode          = "GB",
                    CurrencyCode         = "GBP",
                    SupportedNetworks    = supportedNetworks,
                    PaymentSummaryItems  = summaryItems.ToArray(),
                    MerchantCapabilities = PKMerchantCapability.ThreeDS,
                };
                var viewController = new PKPaymentAuthorizationViewController(paymentRequest)
                {
                    Delegate = new PKPaymentDelegateThing(tcs)
                };
                appDelegate.Window.RootViewController.PresentViewController(viewController, true, null);
            };

            isInitialised = true;
        }
コード例 #4
0
        public Task <string> Pay(PaymentOrderInfo info, Action authorizationCallback = null)
        {
            if (info == null)
            {
                return(Task.FromResult(string.Empty));
            }

            _tcs = new TaskCompletionSource <string>();

            var request = new PKPaymentRequest();

            request.MerchantIdentifier   = Config.MerchantId;
            request.SupportedNetworks    = Config.SupportedNetworks.Select(n => new NSString(n)).ToArray();
            request.MerchantCapabilities = PKMerchantCapability.ThreeDS;
            request.CountryCode          = Config.CountryCode;
            request.CurrencyCode         = info.Currency;

            var paymentItems = new List <PKPaymentSummaryItem>();

            if (!info.Items.IsNullOrEmpty())
            {
                paymentItems = info.Items.Select(item => new PKPaymentSummaryItem()
                {
                    Label  = item.Title,
                    Amount = new NSDecimalNumber(item.Amount.ToString())
                }).ToList();
            }

            //добавляем итоговую стоимость
            paymentItems.Add(new PKPaymentSummaryItem()
            {
                Label  = "Итог",
                Amount = new NSDecimalNumber(info.Amount.ToString())
            });

            request.PaymentSummaryItems = paymentItems.ToArray();

            var paymentViewController = new PKPaymentAuthorizationController(request);

            paymentViewController.Delegate = this;
            paymentViewController.Present(null);

            return(_tcs.Task);
        }
コード例 #5
0
        public async Task <bool> Show(XPayRequest request)
        {
            NSString[] paymentNetworks = new NSString[] { PKPaymentNetwork.MasterCard, PKPaymentNetwork.Visa };

            if (!PKPaymentAuthorizationViewController.CanMakePayments || !PKPaymentAuthorizationViewController.CanMakePaymentsUsingNetworks(paymentNetworks))
            {
                throw new NotSupportedException();
            }

            List <PKPaymentSummaryItem> items = new List <PKPaymentSummaryItem>();

            for (int i = 0; i < request.Items.Count; i++)
            {
                XPayRequestItem requestItem = request.Items[i];
                items.Add(PKPaymentSummaryItem.Create(requestItem.Label, new NSDecimalNumber(requestItem.Amount.ToString())));
            }

            // add the total PKPaymentSummaryItem by summing together all the amounts
            items.Add(PKPaymentSummaryItem.Create(request.PayTo ?? "Payee", new NSDecimalNumber(items.Sum(x => x.Amount.FloatValue).ToString())));

            PKPaymentRequest paymentRequest = new PKPaymentRequest();

            paymentRequest.PaymentSummaryItems  = items.ToArray();
            paymentRequest.MerchantIdentifier   = request.MerchantIdentifier;
            paymentRequest.MerchantCapabilities = PKMerchantCapability.ThreeDS;
            paymentRequest.CountryCode          = request.CountryCode;
            paymentRequest.CurrencyCode         = request.CurrencyCode;
            paymentRequest.SupportedNetworks    = paymentNetworks;

            this.paymentController          = new PKPaymentAuthorizationViewController(paymentRequest);
            this.paymentController.Delegate = this;

            UIWindow         window = UIApplication.SharedApplication.KeyWindow;
            UIViewController vc     = window.RootViewController;

            while (vc.PresentedViewController != null)
            {
                vc = vc.PresentedViewController;
            }

            await vc.PresentViewControllerAsync(this.paymentController, true);

            return(true);
        }
コード例 #6
0
        void RequestPaymentAuthorization(PKPaymentRequest paymentRequest, IDictionary <string, double> summaryItems, string merchantId)
        {
            UserDialogs.Instance.ShowLoading("Loading");

            paymentRequest.MerchantIdentifier   = merchantId;
            paymentRequest.MerchantCapabilities = PKMerchantCapability.ThreeDS;
            paymentRequest.CountryCode          = "US";
            paymentRequest.CurrencyCode         = "USD";

            if (summaryItems != null)
            {
                paymentRequest.PaymentSummaryItems = summaryItems.Select(i => new PKPaymentSummaryItem()
                {
                    Label  = i.Key,
                    Amount = new NSDecimalNumber(i.Value)
                }).ToArray();
            }

            var window          = UIApplication.SharedApplication.KeyWindow;
            var _viewController = window.RootViewController;

            while (_viewController.PresentedViewController != null)
            {
                _viewController = _viewController.PresentedViewController;
            }


            pKPaymentAuthorizationViewController = new PKPaymentAuthorizationViewController(paymentRequest);
            UserDialogs.Instance.HideLoading();
            if (pKPaymentAuthorizationViewController != null)
            {
                pKPaymentAuthorizationViewController.Delegate = this;
                _viewController?.PresentViewController(pKPaymentAuthorizationViewController, true, null);
            }
            else
            {
                if (!isDropUI)
                {
                    OnTokenizationError?.Invoke(this, "Error: Payment request is invalid.");
                }

                payTcs?.SetException(new Exception("Error: Payment request is invalid."));
            }
        }
コード例 #7
0
        private PKPaymentRequest GetPaymentRequest()
        {
            var paymentRequest = new PKPaymentRequest();

            paymentRequest.MerchantIdentifier            = AppDelegate.MERCHANT_ID;
            paymentRequest.RequiredBillingAddressFields  = PKAddressField.All;
            paymentRequest.RequiredShippingAddressFields = checkout.RequiresShipping ? PKAddressField.All : PKAddressField.Email | PKAddressField.Phone;
            paymentRequest.SupportedNetworks             = new [] {
                PKPaymentNetwork.Visa,
                PKPaymentNetwork.MasterCard
            };
            paymentRequest.MerchantCapabilities = PKMerchantCapability.ThreeDS;
            paymentRequest.CountryCode          = shop != null ? shop.Country : "US";
            paymentRequest.CurrencyCode         = shop != null ? shop.Currency : "USD";

            paymentRequest.PaymentSummaryItems = checkout.ApplePaySummaryItems(shop.Name);

            return(paymentRequest);
        }
コード例 #8
0
        public void RequiredBillingContactFields()
        {
            TestRuntime.AssertXcodeVersion(9, 0);

            using (var pr = new PKPaymentRequest()) {
                Assert.That(pr.RequiredBillingContactFields, Is.EqualTo(PKContactFields.None), "None");

                pr.RequiredBillingContactFields |= PKContactFields.PostalAddress;
                Assert.That(pr.RequiredBillingContactFields, Is.EqualTo(PKContactFields.PostalAddress), "PostalAddress");

                pr.RequiredBillingContactFields |= PKContactFields.EmailAddress;
                pr.RequiredBillingContactFields |= PKContactFields.PhoneNumber;
                pr.RequiredBillingContactFields |= PKContactFields.Name;
                pr.RequiredBillingContactFields |= PKContactFields.PhoneticName;
                Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(5), "Count-5");

                pr.RequiredBillingContactFields = PKContactFields.PhoneticName;
                Assert.That(pr.RequiredBillingContactFields, Is.EqualTo(PKContactFields.PhoneticName), "PhoneticName");
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        public void MakeApplePayment(ApplePayViewModel payment, JudoSuccessCallback success, JudoFailureCallback failure, UINavigationController controller, ApplePaymentType type)
        {
            try {
                PKPaymentRequest request = new PKPaymentRequest();

                request.CurrencyCode = payment.CurrencyCode;

                request.CountryCode = payment.CountryCode;

                request.MerchantCapabilities = (PKMerchantCapability)payment.MerchantCapabilities;


                request.SupportedNetworks = payment.SupportedNetworks;


                request.PaymentSummaryItems = payment.Basket;

                request.MerchantIdentifier = payment.MerchantIdentifier;// @"merchant.com.judo.Xamarin"; // do it with configuration/overwrite

                var pkDelegate = new JudoPKPaymentAuthorizationViewControllerDelegate(this, request, payment.ConsumerRef.ToString(), type, success, failure);



                PKPaymentAuthorizationViewController pkController = new PKPaymentAuthorizationViewController(request)
                {
                    Delegate = pkDelegate
                };
                controller.PresentViewController(pkController, true, null);
            } catch (Exception e) {
                Console.WriteLine(e.InnerException.ToString());

                var judoError = new JudoError()
                {
                    Exception = e
                };
                failure(judoError);
            }
        }
コード例 #11
0
        partial void applePayPressed(UIButton sender)
        {
            if (!PKPaymentAuthorizationViewController.CanMakePaymentsUsingNetworks(supportedNetworks))
            {
                ShowAuthorizationAlert();
                return;
            }

            var paymentRequest = new PKPaymentRequest();

            paymentRequest.MerchantIdentifier   = "merchant.id.sample";
            paymentRequest.CountryCode          = "US";
            paymentRequest.CurrencyCode         = "USD";
            paymentRequest.MerchantCapabilities = PKMerchantCapability.ThreeDS;

            paymentRequest.PaymentSummaryItems = MakeSummaryItems();
            paymentRequest.SupportedNetworks   = supportedNetworks;

            var viewController = new PKPaymentAuthorizationViewController(paymentRequest);

            viewController.Delegate = this;
            PresentViewController(viewController, true, null);
        }
コード例 #12
0
        private PKPaymentRequest GetPaymentRequest()
        {
            var paymentRequest = new PKPaymentRequest ();

            paymentRequest.MerchantIdentifier = AppDelegate.MERCHANT_ID;
            paymentRequest.RequiredBillingAddressFields = PKAddressField.All;
            paymentRequest.RequiredShippingAddressFields = checkout.RequiresShipping ? PKAddressField.All : PKAddressField.Email | PKAddressField.Phone;
            paymentRequest.SupportedNetworks = new [] {
                PKPaymentNetwork.Visa,
                PKPaymentNetwork.MasterCard
            };
            paymentRequest.MerchantCapabilities = PKMerchantCapability.ThreeDS;
            paymentRequest.CountryCode = shop != null ? shop.Country : "US";
            paymentRequest.CurrencyCode = shop != null ? shop.Currency : "USD";

            paymentRequest.PaymentSummaryItems = checkout.ApplePaySummaryItems (shop.Name);

            return paymentRequest;
        }
コード例 #13
0
		PKPaymentRequest GetPKPaymentRequest(ApplePayModel model)
		{
			var summaryItems = model.Items.Select(x => new PKPaymentSummaryItem
			{
				Amount = new NSDecimalNumber(x.Amount),
				Label = x.Label
			}).ToList();

			var applePayment = new PKPaymentRequest
			{
				CurrencyCode = new NSString(model.CurrencyCode),
				CountryCode = new NSString(model.CountryCode),
				SupportedNetworks = GetSupportedNetworks(model.SupportedCardNetworks).ToArray(),
				MerchantIdentifier = new NSString(model.MerchantIdentifier),
				MerchantCapabilities = PKMerchantCapability.ThreeDS
			};

			if (!string.IsNullOrWhiteSpace(model.ItemsSummaryLabel))
			{
				summaryItems.Add(new PKPaymentSummaryItem
				{
					Amount = new NSDecimalNumber(model.ItemsTotalAmount()),
					Label = model.ItemsSummaryLabel
				});
			}

			applePayment.PaymentSummaryItems = summaryItems.ToArray();

			return applePayment;
		}
コード例 #14
0
		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);

		}
コード例 #15
0
 public JudoPKPaymentAuthorizationViewControllerDelegate(IApplePayService applePayService, PKPaymentRequest request, string customerRef, ApplePaymentType type, JudoSuccessCallback success, JudoFailureCallback failure)
 {
     _applePayService = applePayService;
     _runningTotal    = request.PaymentSummaryItems [request.PaymentSummaryItems.Length - 1].Amount;
     _paymentAction   = type;
     _successCallBack = success;
     _failureCallback = failure;
     _customerRef     = customerRef;
 }