Example #1
0
        public static TApiClient Create <TApiClient, TResponse>(ClientConfiguration configuration, MockHttpClient <TResponse> httpClient) where TApiClient : ApiClientBase
            where TResponse : class, new()
        {
            var parent = new JustGivingClient(configuration, httpClient);
            var rtn    = Activator.CreateInstance(typeof(TApiClient), parent.HttpChannel) as TApiClient;

            return(rtn);
        }
Example #2
0
        public ActionResult FindCharities(string q)
        {
            var config = new ClientConfiguration(
                "https://api.staging.justgiving.com/",
                ConfigurationManager.AppSettings["JGApiKey"],
                1);
            var client  = new JustGivingClient(config);
            var results = client.Search.CharitySearch(q, 1, 10);

            return(Json(results.Results, JsonRequestBehavior.AllowGet));
        }
        public IEnumerable <BtwCharitySearchResult> FindCharities(string q)
        {
            var config = new ClientConfiguration(
                ConfigurationManager.AppSettings["JgApiBaseUrl"],
                ConfigurationManager.AppSettings["JGApiKey"],
                1);

            var client   = new JustGivingClient(config);
            var response = client.Search.CharitySearch(q);

            return(response.Results
                   .Select(r =>
                           new BtwCharitySearchResult()
            {
                Id = int.Parse(r.CharityId),
                Name = r.Name,
                Logo = r.LogoFileName,
                Description = r.Description
            }));
        }
Example #4
0
        // GET: Sdi
        public async Task <ActionResult> Return(string guid, int?donationId)
        {
            try
            {
                if (!donationId.HasValue)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                var config = new ClientConfiguration(
                    ConfigurationManager.AppSettings["JgApiBaseUrl"],
                    ConfigurationManager.AppSettings["JGApiKey"],
                    1);

                var client = new JustGivingClient(config);

                DonationStatus donationStatus = null;
                try
                {
                    donationStatus = client.Donation.RetrieveStatus(donationId.Value);
                }
                catch
                {
                }

                if ((donationStatus != null && donationStatus.Status == "Accepted") ||
                    ConfigurationManager.AppSettings["SkipDonationReferenceCheck"] == "true")
                {
                    if (donationStatus != null)
                    {
                        _indulgeMeService.Absolve(guid, donationStatus.DonationId, donationStatus.DonationRef,
                                                  donationStatus.Amount,
                                                  donationStatus.Reference);
                    }
                    else if (ConfigurationManager.AppSettings["SkipDonationReferenceCheck"] == "true")
                    {
                        _indulgeMeService.Absolve(guid, 1, "1", 10, "not-a-real-donation");
                    }

                    var indulgence = _indulgeMeService.GetIndulgenceByGuid(guid);
                    _indulgeMeService.GenerateIndulgence(indulgence,
                                                         System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "fonts"),
                                                         System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Content"));

                    await _indulgenceEmailer.Send(indulgence, ConfigurationManager.AppSettings["IndulgencePdfRelativePath"]);

                    _indulgeMeService.Tweet(indulgence);

                    TempData["absolved"] = guid;

                    ControllerContext.RequestContext.HttpContext.Cache.Remove("siteInfo");
                    ControllerContext.RequestContext.HttpContext.Response.RemoveOutputCacheItem(Url.Action("GetLatest",
                                                                                                           "Api"));

                    ViewData["ShowBlessing"] = true;
                    return(RedirectToAction("Index", "Indulgence", new { guid = guid }));
                }

                return(HttpNotFound());
            }
            catch (Exception ex)
            {
                _log.Error("unhandled error returning from SDI", ex);
                return(new ContentResult()
                {
                    Content = ex.Message + "\r\n" + ex.StackTrace,
                    ContentEncoding = Encoding.UTF8,
                    ContentType = "text/plain"
                });
            }
        }
Example #5
0
        public ActionResult Absolve(int id, int?donationId)
        {
            var config = new ClientConfiguration(
                "https://api.staging.justgiving.com/",
                ConfigurationManager.AppSettings["JGApiKey"],
                1);
            var client = new JustGivingClient(config);

            DonationStatus donation = null;

            if (donationId.HasValue)
            {
                donation = client.Donation.RetrieveStatus(donationId.Value);
            }
            else
            {
                donationId = 1;
                donation   = new DonationStatus()
                {
                    Amount = new decimal(r.NextDouble() * 100), DonationId = 1, Reference = "1"
                };
            }

            var indulgence = MvcApplication.CurrentSession.Load <Indulgence>(id.ToRavenDbId("indulgences"));

            if (indulgence == null)
            {
                return(new HttpNotFoundResult());
            }

            indulgence.IsBlessed = true;
            if (donation != null)
            {
                indulgence.AmountDonated        = donation.Amount;
                indulgence.JustGivingDonationId = donationId.Value;
                indulgence.DonationReference    = donation.Reference;
            }

            var sin = MvcApplication.CurrentSession.Load <Sin>(indulgence.SinId);

            sin.TotalDonationCount++;
            if (donation != null)
            {
                sin.TotalDonated += donation.Amount;
            }

            MvcApplication.CurrentSession.SaveChanges();

            MvcApplication.TotalDonated = MvcApplication.CurrentSession
                                          .Query <Indulgence>("BlessedIndulgences").ToList().Sum(a => a.AmountDonated);

            string storagePath   = HostingEnvironment.MapPath("~/content/indulgences");
            string pdfFilename   = string.Format("{0}/indulgence.pdf", indulgence.Id.IdValue());
            string imageFilename = string.Format("{0}/indulgence.png", indulgence.Id.IdValue());

            pdfFilename   = Path.Combine(storagePath, pdfFilename);
            imageFilename = Path.Combine(storagePath, imageFilename);

            _indulgeMeService.GenerateIndulgence(pdfFilename, imageFilename, indulgence,
                                                 HostingEnvironment.MapPath("~/content"), HostingEnvironment.MapPath("~/content"));

            // if the user supplied an email address send the pdf to them
            if (!string.IsNullOrWhiteSpace(indulgence.DonorEmailAddress))
            {
                string donorEmailAddress = indulgence.DonorEmailAddress;
                string donorName         = string.IsNullOrWhiteSpace(indulgence.Name) ? "" : indulgence.Name;
                indulgenceEmailer.Send(indulgence, pdfFilename);
            }

            try
            {
                // add the indulgence to the queue to tweet
                _tweetOutbox.Add(indulgence);
            }
            catch (Exception e)
            {
                log.Error("Could not tweet!", e);
            }

            TempData["absolutionId"] = id;

            // invalidate cache
            ControllerContext.RequestContext.HttpContext.Cache.Remove("siteInfo");
            ControllerContext.RequestContext.HttpContext.Response.RemoveOutputCacheItem(Url.Action("GetLatest", "Api"));

            return(RedirectToAction("Index", "Indulgence", new { id = indulgence.Id.IdValue() }));
        }
 	private void WithAValidClient(WireDataFormat format = WireDataFormat.Xml)
 	{
 		_client = TestContext.CreateClientValidCredentials(format);
 		_api = new TeamApi(_client.HttpChannel);
 	}