/// <summary> /// View Ticket Payment Page or warning Payment /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <IActionResult> Pay(string id, bool isWarning = false) { var test = _dataProtector.Unprotect(id); //{accountId}-{violationId} var decryptedString = _dataProtector.Unprotect(id).Split('&'); var accountId = Guid.Parse(decryptedString[0]); var citationId = Guid.Parse(decryptedString[1]); var citation = await GetCitation(accountId, citationId); if (citation != null) { var citationFine = citation.Balance.HasValue? citation.Balance : citation.FineAmount; var amount = (int)((citationFine + AppSettings.ProcessingFee) * 100); var model = new TicketPaymentModel { AccountId = accountId, CitationId = citation.Id, AmountDue = amount }; return(View(model)); } return(RedirectToAction("Find")); }
public async Task <IActionResult> Pay(TicketPaymentModel model) { var account = await CommonContext.CommonAccounts.Include(m => m.Partition).Where(m => m.Id == model.AccountId).SingleAsync(); var citation = await GetCitation(account.Id, model.CitationId); //Create Stripe Charge var stripeCharge = await _stripeSvc.ChargeCardAsync(new CreditCardModel { Amount = model.AmountDue, SourceToken = model.StripeToken }, citation, account, ChargeTypeEnum.PayCitation); //Record charge var payment = new CitationPayment { AccountId = account.Id, CitationId = citation.Id, CreateUserId = citation.CreateUserId, UpdateUserId = citation.CreateUserId, Status = PaymentType.Stripe, ProcessingFee = AppSettings.ProcessingFee, CitationFineAmount = citation.Balance.HasValue ? citation.Balance.Value : 0f, ChargeAmount = model.AmountDue, ChargeId = stripeCharge.Id }; _accountCtx.CitationPayments.Add(payment); citation.Balance = citation.Payments.Sum(m => m.ChargeAmount) + payment.ChargeAmount; await _accountCtx.SaveChangesAsync(); await _citationSvc.CreateAuditEvent(account.Id, payment.CitationId, $"{string.Format("{0:C}", model.AmountDue.PenniesToDollarAmount())} payment charged", payment.CreateUserId, Data.Enums.CitationAuditEvent.CitationSuccessPayment); return(RedirectToAction("PaymentComplete")); }