Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

C# with SQL Database Data in PayPal Smart Button Order List

I am working on a C# Web Forms project where I have created a Class to handle various functions of a shopping cart that I am integrating with the new PayPal Smart Buttons using the PayPalCheckoutSdk. Inside of my ShoppingCartActions Class I am running a function that displays the total price of an item based on quantity; everything works fine with this code:

public decimal GetTotal()
        {
            ShoppingCartId = GetCartId();
            // Multiply product price by quantity of that product to get        
            // the current price for each of those products in the cart.  
            // Sum all product price totals to get the cart total.   
            decimal? total = decimal.Zero;
            total = (decimal?)(from cartItems in _db.ShoppingCartItems
                               where cartItems.CartId == ShoppingCartId
                               select (int?)cartItems.Quantity *
                               cartItems.Product.UnitPrice).Sum();
            return total ?? decimal.Zero;
        }

I am able to display the value on my Cart Page with the following code:

public static string price;
protected void Page_Load(object sender, EventArgs e)
{
    using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
    {
        cartTotal = usersShoppingCart.GetTotal();
        price = String.Format("{0:c}", cartTotal);
        Lbl01.Text = price;
    }
}

Here is where my issue comes in: I am wanting to use this value in an Order Request for Paypal but when I try it will not display a value! Below is OrderRequest:

public OrderRequest orderRequest = new OrderRequest()
        {
            CheckoutPaymentIntent = "CAPTURE",

            ApplicationContext = new ApplicationContext
            {
                BrandName = "EXAMPLE INC",
                LandingPage = "BILLING",
                CancelUrl = "https://www.example.com",
                ReturnUrl = "https://www.example.com",
                UserAction = "CONTINUE",
                ShippingPreference = "SET_PROVIDED_ADDRESS"
            },
            PurchaseUnits = new List<PurchaseUnitRequest>
                {
                    new PurchaseUnitRequest{
                        ReferenceId =  "ReferenceId1",
                        Description = "Description1",
                        CustomId = "CustomId1",
                        SoftDescriptor = "SoftDescriptor1",
                        AmountWithBreakdown = new AmountWithBreakdown
                        {
                            CurrencyCode = Currency,
                            Value = "110.00",
                            AmountBreakdown = new AmountBreakdown
                            {
                                ItemTotal = new Money
                                {
                                    CurrencyCode = Currency,
                                    Value = price<<<<<<Here is where I try to read the data but no error!
                                },
                                Shipping = new Money
                                {
                                    CurrencyCode = Currency,
                                    Value = "15.00"
                                },
                                Handling = new Money
                                {
                                    CurrencyCode = Currency,
                                    Value = "5.00"
                                },
                                TaxTotal = new Money
                                {
                                    CurrencyCode = Currency,
                                    Value = "10.00"
                                },
                                ShippingDiscount = new Money
                                {
                                    CurrencyCode = Currency,
                                    Value = "10.00"
                                }
                            }
                        },
                        Items = new List<Item>
                        {
                            new Item
                            {
                                Name = "Product 1",
                                Description = "Product 1 Description",
                                Sku = "Sku1",
                                UnitAmount = new Money
                                {
                                    CurrencyCode = Currency,
                                    Value = "100.00"<<<<<<<<< I tried here as well but nothing displays!
                                },
                                Tax = new Money
                                {
                                    CurrencyCode = Currency,
                                    Value = "10.00"
                                },
                                Quantity = "1",
                                Category = "PHYSICAL_GOODS"
                            },
                        },
                        ShippingDetail = new ShippingDetail
                        {
                            Name = new Name
                            {
                                FullName = ""
                            },
                            AddressPortable = new AddressPortable
                            {
                                AddressLine1 = "",
                                AdminArea2 = "",
                                AdminArea1 = "",
                                PostalCode = "",
                                CountryCode = ""
                            }
                        }
                    }
                }
        };

How can I set the string value to be read inside of the Order Request? Any help is GREATLY appreciated!

question from:https://stackoverflow.com/questions/65879779/c-sharp-with-sql-database-data-in-paypal-smart-button-order-list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...