Beispiel #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 BigDecimal("87.50"), "USD",
                               "sku-12345678"),
                new PayPalItem("free sample item #2",               new Java.Lang.Integer(1), new BigDecimal("0.00"),
                               "USD",                               "sku-zero-price"),
                new PayPalItem("sample item #3 with a longer name", new Java.Lang.Integer(6), new BigDecimal("37.99"),
                               "USD",                               "sku-33333")
            };
            BigDecimal           subtotal       = PayPalItem.GetItemTotal(items);
            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);
        }
Beispiel #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);
            }
        }
Beispiel #4
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 BigDecimal("87.50"), "USD",
					"sku-12345678"),
				new PayPalItem("free sample item #2", new Java.Lang.Integer(1), new BigDecimal("0.00"),
					"USD", "sku-zero-price"),
				new PayPalItem("sample item #3 with a longer name", new Java.Lang.Integer(6), new BigDecimal("37.99"),
					"USD", "sku-33333") 
			};
			BigDecimal subtotal = PayPalItem.GetItemTotal(items);
			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;
		}
Beispiel #5
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);
            }
        }
Beispiel #6
0
		public void BuyItems(
			PayPal.Forms.Abstractions.PayPalItem[] items,
			Deveel.Math.BigDecimal xfshipping,
			Deveel.Math.BigDecimal xftax,
			Action onCancelled,
			Action<string> onSuccess,
			Action<string> onError
		) {

			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 (product.Price.ToString ()),
					product.Currency,
					product.SKU)
				);
			}

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

			PayPalPayment payment = new PayPalPayment (amount, nativeItems.FirstOrDefault().Currency, "Multiple items", PayPalPayment.PaymentIntentSale);
			payment = payment.Items (nativeItems.ToArray ()).PaymentDetails (paymentDetails);

			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);
		}
Beispiel #7
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);
        }
Beispiel #8
0
        public IHttpActionResult Buy(string karta, PayPalPaymentDetails paymentDetails)
        {
            var             userId = User.Identity.GetUserId();
            ApplicationUser user   = new ApplicationUser();
            UserType        userType;

            if (userId == null)
            {
                user     = this.unitOfWork.User.Get("appu");
                userType = this.unitOfWork.UserType.Get(1);
            }
            else
            {
                user = this.unitOfWork.User.Get(userId);

                userType = this.unitOfWork.UserType.Get((int)user.UserTypeID);
            }



            Pricelist pricelist = unitOfWork.Pricelist.Find(x => x.To == null).FirstOrDefault();

            if (pricelist == null)
            {
                return(BadRequest("trenutno ne postoji cenovnik"));
            }

            PriceFinal priceFinal = unitOfWork.PriceFinal.GetAll().Where(z => z.PricelistID == pricelist.ID).FirstOrDefault();

            if (priceFinal == null)
            {
                return(BadRequest("trenutno ne postoji cena trenutni cenovnik"));
            }

            DateTime dateTimeNow = DateTime.UtcNow;

            var    expires = ExpiresAt(karta);
            Ticket ticket;

            if (userId == null)
            {
                ticket = new Ticket()
                {
                    BoughtAt             = dateTimeNow,
                    PayPalPaymentDetails = paymentDetails,
                    TicketType           = karta,
                    UserID   = "appu",
                    User     = user,
                    PriceRSD = priceFinal.Price * 1,
                    Expires  = expires,
                    //PriceFinal = priceFinal
                };
            }
            else
            {
                ticket = new Ticket()
                {
                    BoughtAt             = dateTimeNow,
                    PayPalPaymentDetails = paymentDetails,
                    PriceRSD             = priceFinal.Price * userType.Coefficient,
                    TicketType           = karta,
                    UserID  = userId,
                    User    = user,
                    Expires = expires,
                    //PriceFinal = priceFinal
                };

                if (user.Status == null)
                {
                    ticket.PriceRSD = priceFinal.Price * 1;
                }
                //var str = $"Bought at:{ticket.BoughtAt}\t Price in RSD:{ticket.PriceRSD}\t Ticket type:{ticket.TicketType}\t UserID:{ticket.UserID}\n\n Thank You for using our service.";
                //SendEMailHelper.Send(user.Email, "Ticket details from transport service",
                //    str);
            }

            unitOfWork.Ticket.Add(ticket);
            //unitOfWork.Ticket.att
            unitOfWork.Complete();

            PriceFinal p = new PriceFinal()
            {
                Price       = userType.Coefficient * priceFinal.Price,
                PricelistID = pricelist.ID,
                Pricelist   = pricelist,
                Ticket      = ticket
            };


            unitOfWork.PriceFinal.Add(p);
            unitOfWork.Complete();

            ticket.PriceFinal = p;

            unitOfWork.Ticket.Update(ticket);
            unitOfWork.Complete();

            return(Ok(ticket));
        }