コード例 #1
0
 /// <summary>
 /// Gets the total discounts.
 /// </summary>
 /// <returns>
 /// Returns the total discounts message.
 /// </returns>
 public GetTotalDiscountsResponse GetTotalDiscounts()
 {
     return(new GetTotalDiscountsResponse
     {
         TotalDiscount = TotalDiscount == 0 ? Discounts.NoDiscountsApplied : string.Format(Discounts.DiscountsApplied, TotalDiscount.ToString("#.##"))
     });
 }
コード例 #2
0
ファイル: Order.cs プロジェクト: p8b/OSnack
        internal async Task <PayPalCheckoutSdk.Orders.Order> ConvertToPayPalOrder()
        {
            OrderRequest orderRequest = new OrderRequest();

            orderRequest.CheckoutPaymentIntent = "CAPTURE";
            orderRequest.ApplicationContext    = new ApplicationContext()
            {
                BrandName          = AppConst.Settings.BrandName,
                UserAction         = "CONTINUE",
                ShippingPreference = "SET_PROVIDED_ADDRESS",
            };

            orderRequest.PurchaseUnits = new List <PurchaseUnitRequest>()
            {
                new PurchaseUnitRequest()
                {
                    ReferenceId         = "PUHF",
                    Description         = "Snacks and food products",
                    CustomId            = "CUST-HighFashions",
                    SoftDescriptor      = "Snacks",
                    AmountWithBreakdown = new AmountWithBreakdown()
                    {
                        CurrencyCode    = AppConst.Settings.PayPal.CurrencyCode,
                        Value           = TotalPrice.ToString("0.00"),
                        AmountBreakdown = new AmountBreakdown()
                        {
                            ItemTotal = new Money()
                            {
                                CurrencyCode = AppConst.Settings.PayPal.CurrencyCode,
                                Value        = TotalItemPrice.ToString("0.00")
                            },
                            Shipping = new Money()
                            {
                                CurrencyCode = AppConst.Settings.PayPal.CurrencyCode,
                                Value        = ShippingPrice.ToString("0.00")
                            },
                            Discount = new Money()
                            {
                                CurrencyCode = AppConst.Settings.PayPal.CurrencyCode,
                                Value        = TotalDiscount.ToString("0.00")
                            }
                        }
                    },
                    Items = ConvertItem(),
                }
            };
            if (User != null)
            {
                orderRequest.PurchaseUnits.FirstOrDefault().ShippingDetail = new ShippingDetail()
                {
                    Name = new Name()
                    {
                        FullName = $"{User.FirstName} {User.Surname}"
                    },
                    AddressPortable = new AddressPortable()
                    {
                        AddressLine1 = FirstLine,
                        AddressLine2 = SecondLine,
                        PostalCode   = Postcode,
                        CountryCode  = "GB",
                        AdminArea1   = "UK",
                        AdminArea2   = City
                    },
                };
                orderRequest.Payer = new Payer()
                {
                    Email = User.Email,
                    Name  = new Name()
                    {
                        GivenName = User.FirstName,
                        Surname   = User.Surname
                    },
                    AddressPortable = new AddressPortable()
                    {
                        AddressLine1 = FirstLine,
                        AddressLine2 = SecondLine,
                        PostalCode   = Postcode,
                        CountryCode  = "GB",
                        AdminArea2   = City
                    }
                };
            }
            else
            {
                orderRequest.ApplicationContext.ShippingPreference = "GET_FROM_FILE";
            }
            OrdersCreateRequest request = new OrdersCreateRequest();

            request.Prefer("return=representation");

            request.RequestBody(orderRequest);
            var response = await PayPalClient.client().Execute(request).ConfigureAwait(false);

            PayPalCheckoutSdk.Orders.Order paypalOrder = response.Result <PayPalCheckoutSdk.Orders.Order>();

            return(paypalOrder);
        }