Exemplo n.º 1
0
 private static PayPalPayment GetPayment()
 {
     return(PayPalPayment.PaymentWithAmount(new NSDecimalNumber(OrderManager.Instance.GetPrice),
                                            App.CurrencyPaypal,
                                            App.PaypalName,
                                            PayPalPaymentIntent.Sale));
 }
Exemplo n.º 2
0
        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);
            }
        }
        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);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }