示例#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);
        }
示例#2
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);
        }