public TripParticipantPledgeDto GetCampaignPledgeInfo(int contactId, int pledgeCampaignId) { var tripParticipantPledgeInfo = new TripParticipantPledgeDto(); var tripRecord = _campaignService.GetGoTripDetailsByCampaign(pledgeCampaignId).FirstOrDefault(); var tripDonor = _mpDonorService.GetContactDonor(contactId); var campaign = _campaignService.GetPledgeCampaign(pledgeCampaignId); tripParticipantPledgeInfo.PledgeAmount = tripRecord != null ? (int)tripRecord.CampaignFundRaisingGoal : 0; tripParticipantPledgeInfo.CampaignNickname = campaign.Nickname; tripParticipantPledgeInfo.CampaignName = campaign.Name; tripParticipantPledgeInfo.Deposit = tripRecord != null ? (int)tripRecord.RegistrationDeposit : 0; tripParticipantPledgeInfo.DonorId = tripDonor.DonorId; tripParticipantPledgeInfo.ProgramId = campaign.ProgramId; tripParticipantPledgeInfo.ProgramName = _programRepository.GetProgramById(tripParticipantPledgeInfo.ProgramId).Name; return(tripParticipantPledgeInfo); }
private IHttpActionResult CreateDonationAndDistributionAuthenticated(String token, CreateDonationDTO dto) { var isPayment = (dto.TransactionType != null && dto.TransactionType.Equals("PAYMENT")); try { if (isPayment) { //check if invoice exists before create Stripe Charge if (dto.InvoiceId != null && !_invoiceRepository.InvoiceExists(dto.InvoiceId.Value)) { var apiError = new ApiErrorDto("Invoice Not Found", new InvoiceNotFoundException(dto.InvoiceId.Value)); throw new HttpResponseException(apiError.HttpResponseMessage); } } var contactId = _authenticationService.GetContactId(token); var donor = _mpDonorService.GetContactDonor(contactId); var charge = _stripeService.ChargeCustomer(donor.ProcessorId, dto.Amount, donor.DonorId, isPayment); var fee = charge.BalanceTransaction != null ? charge.BalanceTransaction.Fee : null; int?pledgeId = null; if (dto.PledgeCampaignId != null && dto.PledgeDonorId != null) { var pledge = _mpPledgeService.GetPledgeByCampaignAndDonor(dto.PledgeCampaignId.Value, dto.PledgeDonorId.Value); if (pledge != null) { pledgeId = pledge.PledgeId; } } if (!isPayment) { var donationAndDistribution = new MpDonationAndDistributionRecord { DonationAmt = dto.Amount, FeeAmt = fee, DonorId = donor.DonorId, ProgramId = dto.ProgramId, PledgeId = pledgeId, ChargeId = charge.Id, PymtType = dto.PaymentType, ProcessorId = donor.ProcessorId, SetupDate = DateTime.Now, RegisteredDonor = true, Anonymous = dto.Anonymous, SourceUrl = dto.SourceUrl, PredefinedAmount = dto.PredefinedAmount }; var donationId = _mpDonorService.CreateDonationAndDistributionRecord(donationAndDistribution, !dto.TripDeposit); if (!dto.GiftMessage.IsNullOrWhiteSpace() && pledgeId != null) { SendMessageFromDonor(pledgeId.Value, donationId, dto.GiftMessage); } var response = new DonationDTO { ProgramId = dto.ProgramId, Amount = (int)dto.Amount, Id = donationId.ToString(), Email = donor.Email }; return(Ok(response)); } else //Payment flow (non-contribution transaction) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.Exception.Message); var dataError = new ApiErrorDto("Payment data Invalid", new InvalidOperationException("Invalid Payment Data" + errors)); throw new HttpResponseException(dataError.HttpResponseMessage); } try { var invoiceId = dto.InvoiceId != null ? dto.InvoiceId.Value : 0; var payment = new MpDonationAndDistributionRecord { DonationAmt = dto.Amount, PymtType = dto.PaymentType, ProcessorId = charge.Id, ContactId = contactId, InvoiceId = invoiceId, FeeAmt = fee }; var paymentReturn = _paymentService.PostPayment(payment); var response = new DonationDTO { Amount = (int)dto.Amount, Email = donor.Email, PaymentId = paymentReturn.PaymentId }; return(Ok(response)); } catch (InvoiceNotFoundException e) { var apiError = new ApiErrorDto("Invoice Not Found", e); throw new HttpResponseException(apiError.HttpResponseMessage); } catch (ContactNotFoundException e) { var apiError = new ApiErrorDto("Contact Not Found", e); throw new HttpResponseException(apiError.HttpResponseMessage); } catch (PaymentTypeNotFoundException e) { var apiError = new ApiErrorDto("PaymentType Not Found", e); throw new HttpResponseException(apiError.HttpResponseMessage); } catch (Exception e) { var apiError = new ApiErrorDto("SavePayment Failed", e); throw new HttpResponseException(apiError.HttpResponseMessage); } } } catch (PaymentProcessorException stripeException) { return(stripeException.GetStripeResult()); } catch (Exception exception) { var apiError = new ApiErrorDto("Donation/Payment Post Failed", exception); throw new HttpResponseException(apiError.HttpResponseMessage); } }
public MpContactDonor GetContactDonorForAuthenticatedUser(string authToken) { var contactId = _authenticationService.GetContactId(authToken); return(_mpDonorService.GetContactDonor(contactId)); }