private List <SessionLineItemOptions> AddProducts(BasketModel basket, decimal wallet, Barayand.DAL.Interfaces.IWalletHistoryRepository _walletrepository, int user) { List <SessionLineItemOptions> Items = new List <SessionLineItemOptions>(); var shippingCost = (basket.CartItems.Count > 0) ? basket.ShippingCost / basket.TotalQuantity() : basket.ShippingCost; decimal WALLET = wallet; decimal USEDWALLET = 0; foreach (var item in basket.CartItems) { SessionLineItemOptions ItemOptions = new SessionLineItemOptions(); SessionLineItemPriceDataOptions priceData = new SessionLineItemPriceDataOptions(); SessionLineItemPriceDataProductDataOptions prdData = new SessionLineItemPriceDataProductDataOptions(); prdData.Name = item.Product.P_Code + "|" + item.Product.P_Title; prdData.Images = new List <string>() { Barayand.Common.Services.UtilesService.MediaUrls("ProductMainImage") + item.Product.P_Image }; //prdData.Description = (!string.IsNullOrEmpty(item.Product.P_Description)) ? Regex.Replace(item.Product.P_Description, "<.*?>", String.Empty) : "Valhallaplanet Product"; //priceData.ProductData = prdData; //priceData.Currency = "eur"; //priceData.UnitAmountDecimal = item.Product.FinalPrice(basket.SumDiscount(), shippingCost) * 100; //decimal TotalUnit = item.Product.FinalPrice(basket.SumDiscount(), shippingCost); if (WALLET > 0) { //if (TotalUnit <= WALLET) //{ // priceData.UnitAmountDecimal = 0; // USEDWALLET += TotalUnit; // WALLET = WALLET - TotalUnit; //} //else //{ // USEDWALLET += WALLET; // priceData.UnitAmountDecimal = ((priceData.UnitAmountDecimal / 100) - WALLET) * 100; //} } ItemOptions.Quantity = item.Quantity; ItemOptions.PriceData = priceData; Items.Add(ItemOptions); } if (USEDWALLET > 0) { _walletrepository.DecreaseWallet(user, USEDWALLET); } return(Items); }
public SessionCreateOptions PrepareSession(BasketModel basket, decimal wallet, Barayand.DAL.Interfaces.IWalletHistoryRepository _walletrepository, int user) { try { var options = new SessionCreateOptions { PaymentMethodTypes = new List <string> { "card", }, LineItems = AddProducts(basket, wallet, _walletrepository, user), Mode = "payment", SuccessUrl = "https://localhost:44320/cart/payment/success?session_id={CHECKOUT_SESSION_ID}", //SuccessUrl = "https://valhallaplanet.art/cart/payment/success?session_id={CHECKOUT_SESSION_ID}", //CancelUrl = "https://valhallaplanet.art/cart/payment/cancel?session_id={CHECKOUT_SESSION_ID}", CancelUrl = "https://localhost:44320/cart/payment/cancel?session_id={CHECKOUT_SESSION_ID}", }; return(options); } catch (Exception ex) { return(null); } }