示例#1
0
        private List <SessionLineItemOptions> CreateRecharge(int userId, decimal Amount)
        {
            List <SessionLineItemOptions>              Items       = new List <SessionLineItemOptions>();
            SessionLineItemOptions                     ItemOptions = new SessionLineItemOptions();
            SessionLineItemPriceDataOptions            priceData   = new SessionLineItemPriceDataOptions();
            SessionLineItemPriceDataProductDataOptions prdData     = new SessionLineItemPriceDataProductDataOptions();

            prdData.Name   = "Customer Recharge Wallet | " + userId;
            prdData.Images = new List <string>()
            {
                "https://valhallaplanet.art/img/Logo.png"
            };
            prdData.Description = "Valhallaplanet User Wallet Recharge";

            priceData.ProductData       = prdData;
            priceData.Currency          = "eur";
            priceData.UnitAmountDecimal = Amount * 100;


            ItemOptions.Quantity  = 1;
            ItemOptions.PriceData = priceData;

            Items.Add(ItemOptions);

            return(Items);
        }
示例#2
0
        private Session GetCreateSession(SessionLineItemPriceDataOptions priceData, string user, string successUrl, string cancelUrl)
        {
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card"
                },
                LineItems = new List <SessionLineItemOptions>
                {
                    new SessionLineItemOptions
                    {
                        PriceData = priceData,
                        Quantity  = 1,
                    }
                },
                Metadata = new Dictionary <string, string>
                {
                    { "SessionCreated", DateTime.UtcNow.ToString() },
                    { "Product", priceData?.Product },
                    { "ProductName", priceData?.ProductData?.Name }
                },
                ClientReferenceId = user,
                Mode       = "payment",
                SuccessUrl = successUrl,
                CancelUrl  = cancelUrl,
            };
            var     service = new SessionService();
            Session session = service.Create(options);

            return(session);
        }
示例#3
0
        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);
        }