Ejemplo n.º 1
0
        public static void SendEmail(Contribution contrib)
        {
            var smtp = new SmtpClient("localhost");

            var subject = string.Format("Thank you for donating to {0}, redeem your Kudos now! :-)", contrib.IsSpringContribution  ? "Spring/Zero-K" : "Zero-K");

            var body =
                string.Format(
                    "Hi {0}, \nThank you for donating to {1}\nYou can now redeem Kudos - special reward for Zero-K by clicking here: {2} \n (Please be patient Kudos features for the game will be added in the short future)\n\nWe wish you lots of fun playing the game and we are looking forward to meet you in game!\nThe Zero-K team",
                    contrib.Name.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(),
                    contrib.IsSpringContribution ? "the Spring project and Zero-K" : "Zero-K and Spring project",
                    GetCodeLink(contrib.RedeemCode));

            smtp.Send(new MailMessage(GlobalConst.TeamEmail, contrib.Email, subject, body));
        }
Ejemplo n.º 2
0
        public void VerifyAndAddDlc(List <ulong> dlcs)
        {
            if (dlcs == null || dlcs.Count == 0)
            {
                return;
            }
            List <ulong> dlcList = new List <ulong>();

            if (!string.IsNullOrEmpty(PurchasedDlc))
            {
                dlcList = PurchasedDlc.Split(',').Select(ulong.Parse).ToList();
            }

            foreach (var newdlc in dlcs.Where(x => !dlcList.Contains(x)))
            {
                int kudos;
                if (SteamID.HasValue && GlobalConst.DlcToKudos.TryGetValue(newdlc, out kudos))
                {
                    if (new SteamWebApi().CheckAppOwnership((ulong)SteamID.Value, newdlc))
                    {
                        var contrib = new Contribution()
                        {
                            AccountID            = AccountID,
                            KudosValue           = kudos,
                            ItemName             = "Zero-K",
                            IsSpringContribution = false,
                            Comment           = "Steam DLC",
                            OriginalCurrency  = "USD",
                            OriginalAmount    = kudos / 10,
                            Euros             = 0.8 * (kudos / 10), // USD to EUR
                            EurosNet          = 0.5 * (kudos / 10), // USD to EUR, VAT, steam share
                            Time              = DateTime.Now,
                            Name              = Name,
                            ContributionJarID = GlobalConst.SteamContributionJarID
                        };
                        ContributionsByAccountID.Add(contrib);
                        HasKudos = true;
                        dlcList.Add(newdlc);
                    }
                }
            }

            PurchasedDlc = string.Join(",", dlcList);
        }
Ejemplo n.º 3
0
        Contribution AddPayPalContribution(ParsedData parsed)
        {
            try {
                if ((parsed.Status != "Completed" && parsed.Status != "Cleared") || parsed.Gross <= 0)
                {
                    return(null);                                                                                   // not a contribution!
                }
                double netEur;
                double grossEur;
                if (parsed.Currency == "EUR")
                {
                    netEur   = parsed.Net;
                    grossEur = parsed.Gross;
                }
                else
                {
                    netEur   = ConvertToEuros(parsed.Currency, parsed.Net);
                    grossEur = ConvertToEuros(parsed.Currency, parsed.Gross);
                }

                int?accountID, jarID;
                TryParseItemCode(parsed.ItemCode, out accountID, out jarID);

                Contribution contrib;
                using (var db = new ZkDataContext()) {
                    Account         acc = null;
                    ContributionJar jar;
                    if (jarID == null)
                    {
                        jar = db.ContributionJars.FirstOrDefault(x => x.IsDefault);
                    }
                    else
                    {
                        jar = db.ContributionJars.FirstOrDefault(x => x.ContributionJarID == jarID);
                    }

                    if (accountID != null)
                    {
                        acc = db.Accounts.Find(accountID.Value);
                    }

                    if (!string.IsNullOrEmpty(parsed.TransactionID) && db.Contributions.Any(x => x.PayPalTransactionID == parsed.TransactionID))
                    {
                        return(null);                                                                                                                         // contribution already exists
                    }
                    var isSpring = !parsed.ItemCode.StartsWith("ZK") || jar.IsDefault;


                    contrib = new Contribution()
                    {
                        AccountByAccountID = acc,
                        Name                 = parsed.Name,
                        Euros                = grossEur,
                        KudosValue           = (int)Math.Round(grossEur * GlobalConst.EurosToKudos),
                        OriginalAmount       = parsed.Gross,
                        OriginalCurrency     = parsed.Currency,
                        PayPalTransactionID  = parsed.TransactionID,
                        ItemCode             = parsed.ItemCode,
                        Time                 = parsed.Time,
                        EurosNet             = netEur,
                        ItemName             = parsed.ItemName,
                        Email                = parsed.Email,
                        RedeemCode           = Guid.NewGuid().ToString(),
                        IsSpringContribution = isSpring,
                        ContributionJar      = jar
                    };
                    db.Contributions.Add(contrib);

                    db.SaveChanges();

                    if (acc != null)
                    {
                        acc.Kudos = acc.KudosGained - acc.KudosSpent;
                    }
                    db.SaveChanges();


                    // technically not needed to sent when account is known, but perhaps its nice to get a confirmation like that

                    SendEmail(contrib);

                    NewContribution(contrib);
                }

                return(contrib);
            } catch (Exception ex) {
                Trace.TraceError("Error processing payment: {0}", ex);
                Error(ex.ToString());
                return(null);
            }
        }