Exemple #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);
        }
Exemple #2
0
 private static void SendEmailNotification(MarketplaceMember buyer, string productTitle, string ipnHash)
 {
     try
     {
         Mailer.SendNewMarketplaceMessage(buyer.Email, productTitle, ipnHash);
     }
     catch (Exception ex)
     {
         ErrorLogger.Log(ex);
         ErrorLogger.Log(string.Format("Could not send Marketplace email to {0} ({1}). IPN Hash: {2}", buyer.Name, buyer.Email, ipnHash));
     }
 }
Exemple #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();
        }
Exemple #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");
        }