Example #1
0
        /*
         * This method shows use of optional payment details and item list.
         */
        private PayPalPayment getStuffToBuy(string paymentIntent)
        {
            //--- include an item list, payment amount details
            PayPalItem[] items =
            {
                new PayPalItem("sample item #1",                    new Java.Lang.Integer(2), new Java.Math.BigDecimal("87.50"), "USD",
                               "sku-12345678"),
                new PayPalItem("free sample item #2",               new Java.Lang.Integer(1), new Java.Math.BigDecimal("0.00"),
                               "USD",                               "sku-zero-price"),
                new PayPalItem("sample item #3 with a longer name", new Java.Lang.Integer(6), new Java.Math.BigDecimal("37.99"),
                               "USD",                               "sku-33333")
            };
            Java.Math.BigDecimal subtotal       = PayPalItem.GetItemTotal(items);
            Java.Math.BigDecimal shipping       = new BigDecimal("7.21");
            BigDecimal           tax            = new BigDecimal("4.67");
            PayPalPaymentDetails paymentDetails = new PayPalPaymentDetails(shipping, subtotal, tax);
            BigDecimal           amount         = subtotal.Add(shipping).Add(tax);
            PayPalPayment        payment        = new PayPalPayment(amount, "USD", "sample item", paymentIntent);

            payment.Items(items).PaymentDetails(paymentDetails);

            //--- set other optional fields like invoice_number, custom field, and soft_descriptor
            payment.Custom("This is text that will be associated with the payment that the app can use.");

            return(payment);
        }
Example #2
0
        public static double SlowAndPainfulRoundDoubleFallback(double value, int decimals, MidpointRounding midpointRounding)
        {
            var roundingMode = Java.Math.RoundingMode.UNNECESSARY;

            switch (midpointRounding)
            {
            case MidpointRounding.AwayFromZero:
                roundingMode = Java.Math.RoundingMode.HALF_UP;
                break;

            case MidpointRounding.ToEven:
                roundingMode = Java.Math.RoundingMode.HALF_EVEN;
                break;
            }

            var bigDecimal = new Java.Math.BigDecimal(value); // <-- this line might be problematic, as rounding errors may occur when not using the string constructor.

            bigDecimal = bigDecimal.SetScale(decimals, roundingMode);

            return(bigDecimal.DoubleValue());
        }
Example #3
0
        public static double SlowAndPainfulRoundDoubleFallback(double value, int decimals, MidpointRounding midpointRounding)
        {
            var roundingMode = Java.Math.RoundingMode.UNNECESSARY;
            switch (midpointRounding)
            {
                case MidpointRounding.AwayFromZero:
                    roundingMode = Java.Math.RoundingMode.HALF_UP;
                    break;

                case MidpointRounding.ToEven:
                    roundingMode = Java.Math.RoundingMode.HALF_EVEN;
                    break;
            }

            var bigDecimal = new Java.Math.BigDecimal(value); // <-- this line might be problematic, as rounding errors may occur when not using the string constructor.
            bigDecimal = bigDecimal.SetScale(decimals, roundingMode);

            return bigDecimal.DoubleValue();
        }