Example #1
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 ( PayPalItem.ItemWithName (
					product.Name,
					(nuint)product.Quantity,
					new NSDecimalNumber(DoFormat(product.Price.ToDouble())),
					product.Currency,
					product.SKU)
				);
			}

			var subtotal = PayPalItem.TotalPriceForItems (nativeItems.ToArray ());

			// Optional: include payment details
			var shipping = new NSDecimalNumber(DoFormat(xfshipping.ToDouble()));
			var tax = new NSDecimalNumber (DoFormat (xftax.ToDouble ()));
			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 (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);
			}

		}
Example #2
0
		public void BuyItem(
			PayPal.Forms.Abstractions.PayPalItem item,
			Deveel.Math.BigDecimal xftax,
			Action onCancelled,
			Action<string> onSuccess,
			Action<string> onError
		){

			OnCancelled = onCancelled;
			OnSuccess = onSuccess;
			OnError = onError;

			NSDecimalNumber amount = new NSDecimalNumber (DoFormat (item.Price.ToDouble ())).Add (new NSDecimalNumber (DoFormat (xftax.ToDouble ())));

			var paymentDetails = PayPalPaymentDetails.PaymentDetailsWithSubtotal (amount, new NSDecimalNumber(0), new NSDecimalNumber (xftax.ToString ()));

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