public ActionResult Error() { var code = (string)TempData["code"]; var message = (string)TempData["message"]; if (string.IsNullOrEmpty(code)) { return(RedirectToAction("Index", "Profile", new { Area = "Customer" })); } var statusDescription = PayPointStatusTranslator.TranslateStatusCode(code); var msg = string.Format("Paypoint result code is : {0} ({1}). Message: {2}", code, string.Join(", ", statusDescription.ToArray()), message); log.Say(code == "N" ? Severity.Warn : Severity.Alert, msg); ViewData["Message"] = msg; return(View("Error")); } // Error
public ActionResult Callback( bool valid, string trans_id, string code, string auth_code, decimal?amount, string ip, string test_status, string hash, string message, string type, int loanId, string card_no, string customer, string expiry ) { if (test_status == "true") { // Use last 4 random digits as card number (to enable useful tests) string random4Digits = string.Format("{0}{1}", DateTime.UtcNow.Second, DateTime.UtcNow.Millisecond); if (random4Digits.Length > 4) { random4Digits = random4Digits.Substring(random4Digits.Length - 4); } card_no = random4Digits; expiry = string.Format( "{0}{1}", "01", DateTime.UtcNow.AddYears(2).Year.ToString().Substring(2, 2) ); } // if var customerContext = this.context.Customer; PayPointFacade payPointFacade = new PayPointFacade( customerContext.MinOpenLoanDate(), customerContext.CustomerOrigin.Name ); if (!payPointFacade.CheckHash(hash, Request.Url)) { log.Alert("Paypoint callback is not authenticated for user {0}", customerContext.Id); this.logRepository.Log( this.context.UserId, DateTime.UtcNow, "Paypoint Pay Redirect to ", "Failed", String.Format("Paypoint callback is not authenticated for user {0}", customerContext.Id) ); return(View("Error")); } // if var statusDescription = PayPointStatusTranslator.TranslateStatusCode(code); if (!valid || code != "A") { if (code == "N") { log.Warn( "Paypoint result code is : {0} ({1}). Message: {2}", code, string.Join(", ", statusDescription.ToArray()), message ); } else { log.Alert( "Paypoint result code is : {0} ({1}). Message: {2}", code, string.Join(", ", statusDescription.ToArray()), message ); } // if this.logRepository.Log( this.context.UserId, DateTime.UtcNow, "Paypoint Pay Redirect to ", "Failed", string.Format( "Paypoint result code is : {0} ({1}). Message: {2}", code, string.Join(", ", statusDescription.ToArray()), message ) ); return(View("Error")); } // if if (!amount.HasValue) { log.Alert("Paypoint amount is null. Message: {0}", message); this.logRepository.Log( this.context.UserId, DateTime.UtcNow, "Paypoint Pay Redirect to ", "Failed", String.Format("Paypoint amount is null. Message: {0}", message) ); return(View("Error")); } // if // If there is transaction with such id in database, // it means that customer refreshes page // show in this case cashed result if (this.paypointTransactionRepository.ByGuid(trans_id).Any()) { var data = TempData.Get <PaymentConfirmationModel>(); if (data == null) { return(RedirectToAction("Index", "Profile", new { Area = "Customer" })); } return(View(TempData.Get <PaymentConfirmationModel>())); } // if NL_Payments nlPayment = new NL_Payments() { CreatedByUserID = this.context.UserId, Amount = amount.Value, PaymentMethodID = (int)NLLoanTransactionMethods.CustomerAuto, PaymentSystemType = NLPaymentSystemTypes.Paypoint }; log.Debug("Callback: Sending nlPayment: {0} for customer {1}, oldloanId {2}", nlPayment, this.context.UserId, loanId); LoanPaymentFacade loanRepaymentFacade = new LoanPaymentFacade(); PaymentResult res = loanRepaymentFacade.MakePayment(trans_id, amount.Value, ip, type, loanId, customerContext, null, "payment from customer", null, null, nlPayment); SendEmails(loanId, amount.Value, customerContext); this.logRepository.Log(this.context.UserId, DateTime.UtcNow, "Paypoint Pay Callback", "Successful", ""); var refNumber = ""; bool isEarly = false; if (loanId > 0) { var loan = customerContext.GetLoan(loanId); if (loan != null) { refNumber = loan.RefNumber; if (loan.Schedule != null) { List <LoanScheduleItem> scheduledPayments = loan.Schedule .Where( x => x.Status == LoanScheduleStatus.StillToPay || x.Status == LoanScheduleStatus.Late || x.Status == LoanScheduleStatus.AlmostPaid ).ToList(); if (scheduledPayments.Any()) { DateTime earliestSchedule = scheduledPayments.Min(x => x.Date); bool scheduleIsEarly = earliestSchedule.Date >= DateTime.UtcNow && ( earliestSchedule.Date.Year != DateTime.UtcNow.Year || earliestSchedule.Date.Month != DateTime.UtcNow.Month || earliestSchedule.Date.Day != DateTime.UtcNow.Day ); if (scheduleIsEarly) { isEarly = true; } } // if } // if has schedule } // if loan } // if loan id if (string.IsNullOrEmpty(customer)) { customer = customerContext.PersonalInfo.Fullname; } customerContext.TryAddPayPointCard(trans_id, card_no, expiry, customer, payPointFacade.PayPointAccount); var confirmation = new PaymentConfirmationModel { amount = amount.Value.ToString(CultureInfo.InvariantCulture), saved = res.Saved, savedPounds = res.SavedPounds, card_no = card_no, email = customerContext.Name, surname = customerContext.PersonalInfo.Surname, name = customerContext.PersonalInfo.FirstName, refnum = refNumber, transRefnums = res.TransactionRefNumbersFormatted, hasLateLoans = customerContext.HasLateLoans, isRolloverPaid = res.RolloverWasPaid, IsEarly = isEarly }; TempData.Put(confirmation); return(View(confirmation)); } // Callback