コード例 #1
0
ファイル: EmailHelper.cs プロジェクト: ratneshchandna/awic
        public static void SendDonationReceivedEmail(Donations donation)
        {
            string Subject = "We've received a donation of $" + donation.AmountInCAD + " CAD from " +
                ( !String.IsNullOrEmpty(donation.Donor) ? donation.Donor :
                    ( !String.IsNullOrEmpty(donation.DonorEmail) ? donation.DonorEmail : "an anonymous donor" )
                ) +
                "!";

            string HTMLBody =
                "<p>A donation of $" + donation.AmountInCAD + " CAD" +
                    ", made on " +
                    donation.DonationDateAndTime.ToLongDateString() + " " + donation.DonationDateAndTime.ToShortTimeString() +
                    ", by " +
                    ( (!String.IsNullOrEmpty(donation.Donor) && !String.IsNullOrEmpty(donation.DonorEmail)) ?
                            donation.Donor + " (" + donation.DonorEmail + ")" :
                            (!String.IsNullOrEmpty(donation.DonorEmail) ?
                                donation.DonorEmail :
                                (!String.IsNullOrEmpty(donation.Donor) ?
                                    donation.Donor :
                                    "an anonymous donor"
                                )
                            )
                    ) +
                    " has been made to us. The donation should be arriving in our bank account in a few days. </p>";

            SendEmail(System.Configuration.ConfigurationManager.AppSettings["OrganisationEmailAddress"], Subject, HTMLBody);
        }
コード例 #2
0
ファイル: EmailHelper.cs プロジェクト: ratneshchandna/awic
        public static void SendDonationReceiptEmail(Donations donation)
        {
            UrlHelper urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);
            string path = urlHelper.Action("Contact", "Home");
            Uri fullURL = new Uri(HttpContext.Current.Request.Url, path);

            string Subject = "Thank you for your donation" +
                ( !String.IsNullOrEmpty(donation.Donor) ? ", " + donation.Donor : "" ) +
                "!";

            string HTMLBody =
                "<p>Hi" + (!String.IsNullOrEmpty(donation.Donor) ? " " + donation.Donor + ", " : ", ") + "</p>" +
                "<p>Thank you for making a donation to AWIC! </p>" +
                "<p>Your donation of $" + donation.AmountInCAD + " CAD, made on " +
                    donation.DonationDateAndTime.ToLongDateString() + " " +
                    donation.DonationDateAndTime.ToShortTimeString() + " has been received by us. </p>" +
                "<p>If you have any questions or concerns about anything (including the details of where your " +
                    "donation money will be used by AWIC), feel free to reply back with your message and we'll be glad " +
                    "to address it. </p>" +
                "<br />" +
                "<p>Sincerely, </p>" +
                "<p>The AWIC Team</p>" +
                "<br />" +
                "<p>PS You can find our general contact information <a href=\"" + fullURL + "\">here</a>. </p>";

            SendEmail(donation.DonorEmail, Subject, HTMLBody);
        }
コード例 #3
0
        public async Task<ActionResult> Payment(Donations donationToProcess, string stripeToken)
        {
            if(ModelState.IsValid)
            {
                string token = stripeToken; //Request.Form.GetValues("stripeToken").GetValue(0);

                var myCharge = new StripeChargeCreateOptions();
                myCharge.Amount = (int)(donationToProcess.AmountInCAD * 100);
                myCharge.Currency = "cad";
                myCharge.Description = "Donation to AWIC";
                myCharge.Source = new StripeSourceOptions()
                {
                    TokenId = token
                };

                var chargeService = new StripeChargeService();
                try
                {
                    StripeCharge stripeCharge = chargeService.Create(myCharge);
                }
                catch(StripeException e)
                {
                    if (e.StripeError.ErrorType == "card_error" || e.StripeError.ErrorType == "invalid_request_error")
                    {
                        ViewBag.Error = e.StripeError.Message;
                    }
                    else
                    {
                        ViewBag.Error = "Something went wrong on our side and we couldn't process your donation. We hope you don't mind trying to submit your donation again!";
                    }
                    
                    return View(donationToProcess);
                }

                try
                {
                    donationToProcess.DonationDateAndTime = DateTime.Now.AddHours(3.0); // since server time zone is PST and we want the default to be EST

                    db.Donations.Add(donationToProcess);

                    await db.SaveChangesAsync();

                    if (db.Donations.Count() > 5)
                    {
                        DateTime earliestDonationDateAndTime = await db.Donations.MinAsync(d => d.DonationDateAndTime);
                        Donations earliestDonation = await db.Donations.FirstOrDefaultAsync(d => d.DonationDateAndTime == earliestDonationDateAndTime);

                        db.Donations.Remove(earliestDonation);

                        await db.SaveChangesAsync();
                    }
                }
                catch(Exception e)
                {
                    // We weren't able to make database changes, which aren't all that crucial, 
                    // as long as the actual donation was successful
                }

                if (SendEmails(donationToProcess))
                {
                    ViewBag.SentEmailToDonor = true;
                }
                else
                {
                    ViewBag.SentEmailToDonor = false;
                }

                return View("DonationReceived", donationToProcess);
            }

            TempData["Error"] = "Something went wrong on our side and we couldn't process your donation. We hope you don't mind trying to submit your donation again!";
            return RedirectToAction("Donate");
        }
コード例 #4
0
        private bool SendEmails(Donations processedDonation)
        {
            bool SentEmailToDonor = false;

            if (!String.IsNullOrEmpty(processedDonation.DonorEmail))
            {
                try
                {
                    AWICEmailHelper.SendDonationReceiptEmail(processedDonation);
                    SentEmailToDonor = true;
                }
                catch (Exception e)
                {
                    // We weren't able to send an email to the donor, which isn't all that crucial
                    // as long as the actual donation was successful (and we return false from this 
                    // method
                }
            }

            try
            {
                AWICEmailHelper.SendDonationReceivedEmail(processedDonation);
            }
            catch(Exception e)
            {
                // We weren't able to send an email to AWIC, which isn't all that crucial
                // as long as the actual donation was successful
            }

            return SentEmailToDonor;
        }