Exemplo n.º 1
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();
        }
Exemplo n.º 2
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");
        }