Esempio n. 1
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 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);
            }
        }