Esempio n. 1
0
		public static NSDecimal FromString (NSString value)
		{
			NSDecimalNumber number = new NSDecimalNumber (value);
			NSDecimal @decimal = number.DecimalValue;
			number.Release ();
			return @decimal;
		}
Esempio n. 2
0
		public void BuySomething()
		{
			// Remove our last completed payment, just for demo purposes.
			ResultText = "";

				// Note: For purposes of illustration, this example shows a payment that includes
				//       both payment details (subtotal, shipping, tax) and multiple items.
				//       You would only specify these if appropriate to your situation.
				//       Otherwise, you can leave payment.items and/or payment.paymentDetails nil,
				//       and simply set payment.amount to your total charge.

				// Optional: include multiple items
			var item1 = PayPalItem.ItemWithName("Old jeans with holes", 2, new  NSDecimalNumber("84.99"), "USD", "Hip-0037");
			var item2 = PayPalItem.ItemWithName ("Free rainbow patch", 1, new NSDecimalNumber ("0.00"), "USD", "Hip-00066");
			var item3 = PayPalItem.ItemWithName ("Long-sleeve plaid shirt (mustache not included)", 1, new NSDecimalNumber ("37.99"), "USD", "Hip-00291");

			var items = new PayPalItem[] {
				item1, item2, item3
			};
			var subtotal = PayPalItem.TotalPriceForItems (items);

				// Optional: include payment details
			var shipping = new NSDecimalNumber("5.99");
			var tax = new NSDecimalNumber ("2.50");
			var paymentDetails = PayPalPaymentDetails.PaymentDetailsWithSubtotal (subtotal, shipping, tax);

			var total = subtotal.Add (shipping).Add (tax);

			var payment = PayPalPayment.PaymentWithAmount (total, "USD", "Hipster Clothing", PayPalPaymentIntent.Sale);

			payment.Items = items;
			payment.PaymentDetails = paymentDetails;
			if (payment.Processable) {
				var paymentViewController = new PayPalPaymentViewController(payment, _payPalConfig, this);
				var top = GetTopViewController (UIApplication.SharedApplication.KeyWindow);
				top.PresentViewController (paymentViewController, true, null);
			}else {
					// This particular payment will always be processable. If, for
					// example, the amount was negative or the shortDescription was
					// empty, this payment wouldn't be processable, and you'd want
					// to handle that here.
				Debug.WriteLine("Payment not processalbe:"+payment.Items);
			}
		}
        public void BuyItem(
            PayPal.Forms.Abstractions.PayPalItem item,
            Decimal xftax,
            Action onCancelled,
            Action<string> onSuccess,
            Action<string> onError,
            PayPal.Forms.Abstractions.ShippingAddress address
        )
        {

            OnCancelled = onCancelled;
            OnSuccess = onSuccess;
            OnError = onError;


            var subTotal = new NSDecimalNumber(RoundNumber((double)item.Price));
            NSDecimalNumber amount = subTotal.Add(new NSDecimalNumber(RoundNumber((double)xftax)));

            var paymentDetails = PayPalPaymentDetails.PaymentDetailsWithSubtotal(subTotal, new NSDecimalNumber(0), new NSDecimalNumber(RoundNumber((double)xftax)));

            var payment = PayPalPayment.PaymentWithAmount(amount, item.Currency, item.Name, PayPalPaymentIntent.Sale);
            payment.PaymentDetails = paymentDetails;
            payment.Items = new NSObject[]{
                PayPalItem.ItemWithName (
                    item.Name,
                    1,
                    new  NSDecimalNumber (RoundNumber((double)item.Price)),
                    item.Currency,
                    item.SKU
                )
            };

            if (address != null)
            {
                payment.ShippingAddress = PayPalShippingAddress.ShippingAddressWithRecipientName(
                    address.RecipientName,
                    address.Line1,
                    address.Line2,
                    address.City,
                    address.State,
                    address.PostalCode,
                    address.CountryCode
                );
            }


            if (payment.Processable)
            {
                var paymentViewController = new PayPalPaymentViewController(payment, _payPalConfig, this);
                var top = GetTopViewController(UIApplication.SharedApplication.KeyWindow);
                top.PresentViewController(paymentViewController, true, null);
            }
            else {
                OnError?.Invoke("This particular payment will always be processable. If, for example, the amount was negative or the shortDescription was empty, this payment wouldn't be processable, and you'd want to handle that here.");
                OnError = null;
                Debug.WriteLine("Payment not processalbe:" + payment.Items);
            }
        }
Esempio n. 4
0
        #pragma warning restore 219

        private static void Check(NSDecimalNumber number)
        {
            Assert.IsNotNull(number, "Number cannot be null");
            Assert.AreNotEqual(IntPtr.Zero, number.NativePointer, "Native pointer cannot be null");
        }
        public void BuyItems(
            PayPal.Forms.Abstractions.PayPalItem[] items,
            Decimal xfshipping,
            Decimal xftax,
            Action onCancelled,
            Action<string> onSuccess,
            Action<string> onError,
            PayPal.Forms.Abstractions.ShippingAddress address
        )
        {

            OnCancelled = onCancelled;
            OnSuccess = onSuccess;
            OnError = onError;

            List<PayPalItem> nativeItems = new List<PayPalItem>();
            foreach (var product in items)
            {
                nativeItems.Add(PayPalItem.ItemWithName(
                    product.Name,
                    (nuint)product.Quantity,
                    new NSDecimalNumber(RoundNumber((double)product.Price)),
                    product.Currency,
                    product.SKU)
                );
            }

            var subtotal = PayPalItem.TotalPriceForItems(nativeItems.ToArray());

            var shipping = new NSDecimalNumber(RoundNumber((double)xfshipping));
            var tax = new NSDecimalNumber(RoundNumber((double)xftax));
            var paymentDetails = PayPalPaymentDetails.PaymentDetailsWithSubtotal(subtotal, shipping, tax);

            var total = subtotal.Add(shipping).Add(tax);

            var payment = PayPalPayment.PaymentWithAmount(total, nativeItems.FirstOrDefault().Currency, "Multiple items", PayPalPaymentIntent.Sale);
            payment.Items = nativeItems.ToArray();
            payment.PaymentDetails = paymentDetails;

            if (address != null)
            {
                payment.ShippingAddress = PayPalShippingAddress.ShippingAddressWithRecipientName(
                    address.RecipientName,
                    address.Line1,
                    address.Line2,
                    address.City,
                    address.State,
                    address.PostalCode,
                    address.CountryCode
                );
            }

            if (payment.Processable)
            {
                var paymentViewController = new PayPalPaymentViewController(payment, _payPalConfig, this);
                var top = GetTopViewController(UIApplication.SharedApplication.KeyWindow);
                top.PresentViewController(paymentViewController, true, null);
            }
            else {
                OnError?.Invoke("This particular payment will always be processable. If, for example, the amount was negative or the shortDescription was empty, this payment wouldn't be processable, and you'd want to handle that here.");
                Debug.WriteLine("Payment not processalbe:" + payment.Items);
            }

        }
Esempio n. 6
0
		public void BuyItem(
			PayPal.Forms.Abstractions.PayPalItem item,
			Deveel.Math.BigDecimal xftax,
			Action onCancelled,
			Action<string> onSuccess,
			Action<string> onError
		){

			OnCancelled = onCancelled;
			OnSuccess = onSuccess;
			OnError = onError;

			NSDecimalNumber amount = new NSDecimalNumber (DoFormat (item.Price.ToDouble ())).Add (new NSDecimalNumber (DoFormat (xftax.ToDouble ())));

			var paymentDetails = PayPalPaymentDetails.PaymentDetailsWithSubtotal (amount, new NSDecimalNumber(0), new NSDecimalNumber (xftax.ToString ()));

			var payment = PayPalPayment.PaymentWithAmount (amount, item.Currency, item.Name, PayPalPaymentIntent.Sale);
			payment.PaymentDetails = paymentDetails;
			payment.Items = new NSObject[]{
				PayPalItem.ItemWithName (
					item.Name,
					1,
					new  NSDecimalNumber (item.Price.ToString ()),
					item.Currency,
					item.SKU
				)
			};
			if (payment.Processable) {
				var paymentViewController = new PayPalPaymentViewController(payment, _payPalConfig, this);
				var top = GetTopViewController (UIApplication.SharedApplication.KeyWindow);
				top.PresentViewController (paymentViewController, true, null);
			}else {
				OnError?.Invoke ("This particular payment will always be processable. If, for example, the amount was negative or the shortDescription was empty, this payment wouldn't be processable, and you'd want to handle that here.");
				OnError = null;
				Debug.WriteLine("Payment not processalbe:"+payment.Items);
			}
		}
Esempio n. 7
0
        public void BuyItem(
            PayPal.Forms.Abstractions.PayPalItem item,
            Decimal xftax,
            PaymentIntent xfintent,
            Action onCancelled,
            Action <string> onSuccess,
            Action <string> onError,
            PayPal.Forms.Abstractions.ShippingAddress address
            )
        {
            OnCancelled = onCancelled;
            OnSuccess   = onSuccess;
            OnError     = onError;


            var             subTotal = new NSDecimalNumber(RoundNumber((double)item.Price));
            NSDecimalNumber amount   = subTotal.Add(new NSDecimalNumber(RoundNumber((double)xftax)));

            var paymentDetails = PayPalPaymentDetails.PaymentDetailsWithSubtotal(subTotal, new NSDecimalNumber(0), new NSDecimalNumber(RoundNumber((double)xftax)));

            PayPalPaymentIntent paymentIntent;

            switch (xfintent)
            {
            case PaymentIntent.Authorize:
                paymentIntent = PayPalPaymentIntent.Authorize;
                break;

            case PaymentIntent.Order:
                paymentIntent = PayPalPaymentIntent.Order;
                break;

            default:
            case PaymentIntent.Sale:
                paymentIntent = PayPalPaymentIntent.Sale;
                break;
            }

            var payment = PayPalPayment.PaymentWithAmount(amount, item.Currency, item.Name, paymentIntent);

            payment.PaymentDetails = paymentDetails;
            payment.Items          = new NSObject[] {
                PayPalItem.ItemWithName(
                    item.Name,
                    1,
                    new  NSDecimalNumber(RoundNumber((double)item.Price)),
                    item.Currency,
                    item.SKU
                    )
            };

            if (address != null)
            {
                payment.ShippingAddress = PayPalShippingAddress.ShippingAddressWithRecipientName(
                    address.RecipientName,
                    address.Line1,
                    address.Line2,
                    address.City,
                    address.State,
                    address.PostalCode,
                    address.CountryCode
                    );
            }


            if (payment.Processable)
            {
                var paymentViewController = new PayPalPaymentViewController(payment, _payPalConfig, this);
                var top = GetTopViewController(UIApplication.SharedApplication.KeyWindow);
                top.PresentViewController(paymentViewController, true, null);
            }
            else
            {
                OnError?.Invoke("This particular payment will always be processable. If, for example, the amount was negative or the shortDescription was empty, this payment wouldn't be processable, and you'd want to handle that here.");
                OnError = null;
                Debug.WriteLine("Payment not processalbe:" + payment.Items);
            }
        }
Esempio n. 8
0
        public void BuyItems(
            PayPal.Forms.Abstractions.PayPalItem[] items,
            Decimal xfshipping,
            Decimal xftax,
            PaymentIntent xfintent,
            Action onCancelled,
            Action <string> onSuccess,
            Action <string> onError,
            PayPal.Forms.Abstractions.ShippingAddress address
            )
        {
            OnCancelled = onCancelled;
            OnSuccess   = onSuccess;
            OnError     = onError;

            List <PayPalItem> nativeItems = new List <PayPalItem>();

            foreach (var product in items)
            {
                nativeItems.Add(PayPalItem.ItemWithName(
                                    product.Name,
                                    (nuint)product.Quantity,
                                    new NSDecimalNumber(RoundNumber((double)product.Price)),
                                    product.Currency,
                                    product.SKU)
                                );
            }

            var subtotal = PayPalItem.TotalPriceForItems(nativeItems.ToArray());

            var shipping       = new NSDecimalNumber(RoundNumber((double)xfshipping));
            var tax            = new NSDecimalNumber(RoundNumber((double)xftax));
            var paymentDetails = PayPalPaymentDetails.PaymentDetailsWithSubtotal(subtotal, shipping, tax);

            var total = subtotal.Add(shipping).Add(tax);

            PayPalPaymentIntent paymentIntent;

            switch (xfintent)
            {
            case PaymentIntent.Authorize:
                paymentIntent = PayPalPaymentIntent.Authorize;
                break;

            case PaymentIntent.Order:
                paymentIntent = PayPalPaymentIntent.Order;
                break;

            default:
            case PaymentIntent.Sale:
                paymentIntent = PayPalPaymentIntent.Sale;
                break;
            }

            var payment = PayPalPayment.PaymentWithAmount(total, nativeItems.FirstOrDefault().Currency, "Multiple items", paymentIntent);

            payment.Items          = nativeItems.ToArray();
            payment.PaymentDetails = paymentDetails;

            if (address != null)
            {
                payment.ShippingAddress = PayPalShippingAddress.ShippingAddressWithRecipientName(
                    address.RecipientName,
                    address.Line1,
                    address.Line2,
                    address.City,
                    address.State,
                    address.PostalCode,
                    address.CountryCode
                    );
            }

            if (payment.Processable)
            {
                var paymentViewController = new PayPalPaymentViewController(payment, _payPalConfig, this);
                var top = GetTopViewController(UIApplication.SharedApplication.KeyWindow);
                top.PresentViewController(paymentViewController, true, null);
            }
            else
            {
                OnError?.Invoke("This particular payment will always be processable. If, for example, the amount was negative or the shortDescription was empty, this payment wouldn't be processable, and you'd want to handle that here.");
                Debug.WriteLine("Payment not processalbe:" + payment.Items);
            }
        }
Esempio n. 9
0
    public static decimal ToDecimal(this NSDecimal number)
    {
        var stringRepresentation = new NSDecimalNumber(number).ToString();

        return(decimal.Parse(stringRepresentation, CultureInfo.InvariantCulture));
    }