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