Esempio n. 1
0
        public static void Create(MarketplaceMember buyer, int quantity, MarketplaceProduct product)
        {
            MarketplaceIPN IPN = new MarketplaceIPN(buyer.Id, quantity, product.Id, buyer.DeliveryAddress, buyer.Email);

            IPN.Save();

            SendEmailNotification(buyer, product.Title, IPN.Hash);
        }
Esempio n. 2
0
        private static void ConfirmIPN(MarketplaceIPN ipn)
        {
            MarketplaceProduct product = new MarketplaceProduct(ipn.ProductId);
            Member             seller  = new Member(product.SellerId);

            if (ipn.Status == MarketplaceIPNStatus.Pending)
            {
                ipn.Status = MarketplaceIPNStatus.Confirmed;
                ipn.Save();

                seller.AddToPurchaseBalance(ipn.ProductQuantity * product.Price, "Marketplace sale", BalanceLogType.MarketplaceSale);
                seller.SaveBalances();
            }
        }
Esempio n. 3
0
        public void Buy(Member buyer, int quantity, string deliveryAddress, string email, BalanceType targetBalance)
        {
            Money totalAmount = this.Price * quantity;

            if (totalAmount <= Money.Zero)
            {
                throw new MsgException(U5006.AMOUNTEQUALZERO);
            }

            if (targetBalance == BalanceType.PurchaseBalance)
            {
                if (totalAmount > buyer.PurchaseBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                //Take money and save the user
                buyer.SubtractFromPurchaseBalance(totalAmount, "Marketplace purchase", BalanceLogType.MarketplacePurchase);
            }
            else if (targetBalance == BalanceType.MarketplaceBalance)
            {
                if (totalAmount > buyer.MarketplaceBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                //Take money and save the user
                buyer.SubtractFromMarketplaceBalance(totalAmount, "Marketplace purchase", BalanceLogType.MarketplacePurchase);
            }
            else
            {
                throw new ArgumentException("Invalid argument: " + targetBalance.ToString(), "targetBalance");
            }
            buyer.SaveBalances();

            //Add history entry
            History.AddPurchase(buyer.Name, totalAmount, "Marketplace purchase");

            MarketplaceMember mBuyer = new MarketplaceMember(email, deliveryAddress, buyer.Name, buyer.Id);

            MarketplaceIPN.Create(mBuyer, quantity, this);

            this.Quantity -= Quantity;
            this.Sold     += Quantity;
            this.Save();
        }
Esempio n. 4
0
        public void BuyViaProcessor(string username, int quantity, string emailAddress, string deliveryAddress, Money paidAmount, int?promotorId)
        {
            Money totalAmount = this.Price * quantity;

            if (totalAmount <= Money.Zero)
            {
                throw new MsgException(U5006.AMOUNTEQUALZERO);
            }

            if (paidAmount < totalAmount)
            {
                throw new MsgException(L1.NOTENOUGHFUNDS);
            }

            MarketplaceMember mBuyer;

            if (Member.Exists(username))
            {
                Member user = new Member(username);
                mBuyer = new MarketplaceMember(emailAddress, deliveryAddress, user.Name, user.Id);
            }
            else
            {
                mBuyer = new MarketplaceMember(emailAddress, deliveryAddress);
            }

            if (promotorId != null)
            {
                Member promotor = new Member((int)promotorId);
                var    amount   = totalAmount * AppSettings.Marketplace.MarketplacePromoteCommission / 100;
                promotor.AddToMainBalance(amount, "Marketplace commission");
                promotor.SaveBalances();
            }

            MarketplaceIPN.Create(mBuyer, quantity, this);

            this.Quantity -= quantity;
            this.Sold     += quantity;
            this.Save();

            History.AddPurchase(mBuyer.Name, totalAmount, "Marketplace purchase");
        }
Esempio n. 5
0
        public static void TryConfirmIPN(int ipnId)
        {
            MarketplaceIPN ipn = new MarketplaceIPN(ipnId);

            ConfirmIPN(ipn);
        }