Пример #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);
            }
        }
Пример #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;
            BigDecimal amount = new BigDecimal(RoundNumber((double)item.Price)).Add(new BigDecimal(RoundNumber((double)xftax)));

            PayPalPayment payment = new PayPalPayment(amount, item.Currency, item.Name, PayPalPayment.PaymentIntentSale);

            if (address != null)
            {
                ShippingAddress shippingAddress = new ShippingAddress()
                                                  .RecipientName(address.RecipientName)
                                                  .Line1(address.Line1)
                                                  .Line2(address.Line2)
                                                  .City(address.City)
                                                  .State(address.State)
                                                  .PostalCode(address.PostalCode)
                                                  .CountryCode(address.CountryCode);
                payment = payment.InvokeProvidedShippingAddress(shippingAddress);
            }

            switch (_xfconfig.ShippingAddressOption)
            {
            case Abstractions.Enum.ShippingAddressOption.Both:
            case Abstractions.Enum.ShippingAddressOption.PayPal:
                payment = payment.EnablePayPalShippingAddressesRetrieval(true);
                break;

            default:
                payment = payment.EnablePayPalShippingAddressesRetrieval(false);
                break;
            }

            Intent intent = new Intent(Context, typeof(PaymentActivity));

            intent.PutExtra(PayPalService.ExtraPaypalConfiguration, config);

            intent.PutExtra(PaymentActivity.ExtraPayment, payment);

            (Context as Activity).StartActivityForResult(intent, REQUEST_CODE_PAYMENT);
        }
Пример #3
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);
            }
        }
Пример #4
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(new PayPalItem(
                                    product.Name,
                                    new Java.Lang.Integer((int)product.Quantity),
                                    new BigDecimal(RoundNumber((double)product.Price)),
                                    product.Currency,
                                    product.SKU)
                                );
            }

            BigDecimal           subtotal       = PayPalItem.GetItemTotal(nativeItems.ToArray());
            BigDecimal           shipping       = new BigDecimal(RoundNumber((double)xfshipping));
            BigDecimal           tax            = new BigDecimal(RoundNumber((double)xftax));
            PayPalPaymentDetails paymentDetails = new PayPalPaymentDetails(shipping, subtotal, tax);
            BigDecimal           amount         = subtotal.Add(shipping).Add(tax);

            string paymentIntent;

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

            case PaymentIntent.Order:
                paymentIntent = PayPalPayment.PaymentIntentOrder;
                break;

            default:
            case PaymentIntent.Sale:
                paymentIntent = PayPalPayment.PaymentIntentSale;
                break;
            }

            PayPalPayment payment = new PayPalPayment(amount, nativeItems.FirstOrDefault().Currency, "Multiple items", paymentIntent);

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

            if (address != null)
            {
                ShippingAddress shippingAddress = new ShippingAddress()
                                                  .RecipientName(address.RecipientName)
                                                  .Line1(address.Line1)
                                                  .Line2(address.Line2)
                                                  .City(address.City)
                                                  .State(address.State)
                                                  .PostalCode(address.PostalCode)
                                                  .CountryCode(address.CountryCode);
                payment = payment.InvokeProvidedShippingAddress(shippingAddress);
            }

            switch (_xfconfig.ShippingAddressOption)
            {
            case Abstractions.Enum.ShippingAddressOption.Both:
            case Abstractions.Enum.ShippingAddressOption.PayPal:
                payment = payment.EnablePayPalShippingAddressesRetrieval(true);
                break;

            default:
                payment = payment.EnablePayPalShippingAddressesRetrieval(false);
                break;
            }

            Intent intent = new Intent(Context, typeof(PaymentActivity));

            intent.PutExtra(PayPalService.ExtraPaypalConfiguration, config);

            intent.PutExtra(PaymentActivity.ExtraPayment, payment);

            (Context as Activity).StartActivityForResult(intent, REQUEST_CODE_PAYMENT);
        }