public string AddDonation(DonationCreatedIntegrationEvent donation)
        {
            var client  = new RestClient(BASEURL);
            var request = new RestRequest($"{_baseId}/Donations", Method.POST);

            request.AddHeader("Authorization", "Bearer " + _apiKey);
            var fields = new Dictionary <string, object>();

            fields.Add("Id", donation.Id);
            fields.Add("Donor Id", donation.UserId);
            fields.Add("Creation Date", donation.CreationDate);
            fields.Add("Donation Amount", donation.DonationAmount);
            fields.Add("Donor Display Name", donation.DonorDisplayName);
            fields.Add("Fundraiser Id", donation.FundraiserId);
            var parameters = new Dictionary <string, Dictionary <string, object> >();

            parameters.Add("fields", fields);

            request.AddParameter("application/json", JsonConvert.SerializeObject(parameters), ParameterType.RequestBody);

            var response = client.Execute(request);

            if (response.ErrorException != null)
            {
                throw new ApplicationException("Error retrieving response.  Check inner details for more info.", response.ErrorException);
            }

            return("ok");
        }
Ejemplo n.º 2
0
        protected override bool HandleCore(Donate request)
        {
            var fundraiser = _fundraiserRepository.FindById(request.FundraiserId);
            var campaign   = _campaignRepository.FindById(fundraiser.CampaignId);

            if (request.DonationAmount > 0)
            {
                try
                {
                    var chargeService = new StripeChargeService();
                    var charge        = chargeService.Create(new StripeChargeCreateOptions()
                    {
                        Amount      = request.DonationAmount * 100,
                        Currency    = "usd",
                        Description = fundraiser.Name,
                        SourceTokenOrExistingSourceId = request.StripeToken
                    });
                    var donation = _donationRepository.Create(campaign, fundraiser, DonationStatus.Completed, request.DonationAmount, "usd", request.DonationAmount, request.UserId, request.DonorDisplayName, charge.Id);

                    var integrationEvent = new DonationCreatedIntegrationEvent(donation.DonorUserId,
                                                                               donation.FundraiserId, donation.Amount, donation.DonorDisplayName);

                    _eventBus.Publish(integrationEvent); // not tested; maybe IEventBus should be named something else since EasyNetQ already has an IEventBus; perhaps Publish(e) should be Publish<T>(e)?
                }
                catch (InvalidOperationException)
                {
                    return(false); // maybe should return json with validation info?
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        static void HandleDonationCreatedMessage(DonationCreatedIntegrationEvent message)
        {
            Console.WriteLine(
                "Message Recieved!\n\n" +
                "Id: " + message.Id + "\n" +
                "UserId: " + message.UserId + "\n" +
                "DonationAmount: " + message.DonationAmount + "\n" +
                "DonorDisplayName: " + message.DonorDisplayName + "\n" +
                "FundraiserId: " + message.FundraiserId + "\n\n"
                );

            var client = new AirtableClient("appJdKhgVuGZUv0va", "keyql7soeJgu7cdsP");

            var x = client.AddDonation(message);
        }