littleshop/TeleBot/TeleBot/Models/ShoppingCart.cs
SilverLabs DevTeam 73e8773ea3 Configure BTCPay with external nodes via Tor
- Set up Tor container for SOCKS proxy (port 9050)
- Configured Monero wallet with remote onion node
- Bitcoin node continues syncing in background (60% complete)
- Created documentation for wallet configuration steps
- All external connections routed through Tor for privacy

BTCPay requires manual wallet configuration through web interface:
- Bitcoin: Need to add xpub/zpub for watch-only wallet
- Monero: Need to add address and view key

System ready for payment acceptance once wallets configured.
2025-09-19 12:14:39 +01:00

106 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace TeleBot.Models
{
public class ShoppingCart
{
public string Id { get; set; } = Guid.NewGuid().ToString();
public List<CartItem> Items { get; set; } = new();
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
public void AddItem(Guid productId, string productName, decimal price, int quantity = 1, Guid? variationId = null)
{
var existingItem = Items.FirstOrDefault(i =>
i.ProductId == productId && i.VariationId == variationId);
if (existingItem != null)
{
existingItem.Quantity += quantity;
existingItem.UpdateTotalPrice();
}
else
{
var newItem = new CartItem
{
ProductId = productId,
VariationId = variationId,
ProductName = productName,
UnitPrice = price,
Quantity = quantity
};
newItem.UpdateTotalPrice(); // Ensure total is calculated after all properties are set
Items.Add(newItem);
}
UpdatedAt = DateTime.UtcNow;
}
public void RemoveItem(Guid productId)
{
Items.RemoveAll(i => i.ProductId == productId);
UpdatedAt = DateTime.UtcNow;
}
public void UpdateQuantity(Guid productId, int quantity)
{
var item = Items.FirstOrDefault(i => i.ProductId == productId);
if (item != null)
{
if (quantity <= 0)
{
RemoveItem(productId);
}
else
{
item.Quantity = quantity;
item.UpdateTotalPrice();
UpdatedAt = DateTime.UtcNow;
}
}
}
public void Clear()
{
Items.Clear();
UpdatedAt = DateTime.UtcNow;
}
public decimal GetTotalAmount()
{
return Items.Sum(i => i.TotalPrice);
}
public int GetTotalItems()
{
return Items.Sum(i => i.Quantity);
}
public bool IsEmpty()
{
return !Items.Any();
}
}
public class CartItem
{
public Guid ProductId { get; set; }
public Guid? VariationId { get; set; }
public string ProductName { get; set; } = string.Empty;
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
public decimal TotalPrice { get; set; }
public CartItem()
{
// Don't calculate total in constructor - wait for properties to be set
}
public void UpdateTotalPrice()
{
TotalPrice = UnitPrice * Quantity;
}
}
}