public async Task Index_Process_Verifone_Response_SUCCESS() { //Arrange string transactionGuid = "123456789_3d86fa56-3b9c-4225-98fa-f4926f2683bd"; string result = "SUCCESS"; string tokenId = "10032863201"; string authrorisationCode = "789DE"; //Act var _verifoneTransactionDto = new VerifoneTransactionDto() { TransactionData = "{'LowellReference':'257113803','ClientName':'Lamb','PaymentAmount':501.53,'SourceOfFunds':'Disposable Income','SourceOfFundsOther':null,'UserID':'2e5321ad - af0c - 4a69 - 8036 - 5ecf703017cb','PaidInFull':true,'DiscountAvailable':false,'DiscountSelected':false,'PlanInPlace':false,'InArrears':false}", Status = 0 }; _verifonePaymentProviderService.Setup(x => x.GetVerifoneTransactionAsync(transactionGuid)).Returns(Task.FromResult(_verifoneTransactionDto)); var oneOffPaymentDto = JsonConvert.DeserializeObject <OneOffPaymentDto>(_verifoneTransactionDto.TransactionData); var model = new PaymentResultVm { Reference = transactionGuid, Result = result, TokenId = tokenId, ACode = authrorisationCode, PaymentInfo = oneOffPaymentDto }; var successfulOneOffPaymentVm = new SuccessfulOneOffPaymentVm { ClientName = oneOffPaymentDto.ClientName, PaymentInfo = model.PaymentInfo, UserLoggedIn = !string.IsNullOrEmpty(_caseflowUserId) }; _paymentService.Setup(x => x.MakePayment(model, oneOffPaymentDto)).Verifiable(); _verifonePaymentProviderService.Setup(x => x.UpdateVerifoneTransactionAsync(_verifoneTransactionDto)).Verifiable(); _sessionState.Setup(x => x.LogPaymentResult).Returns(true); _gtmService.Setup(x => x.RaiseOneOffPaymentEvent_PaymentComplete(successfulOneOffPaymentVm, _caseflowUserId, "Regular Account")).Verifiable(); _webActivityService.Setup(x => x.LogOneOffPaymentComplete(model.PaymentInfo.LowellReference, _caseflowUserId, !model.PaymentInfo.PaidInFull, model.PaymentInfo.DiscountSelected)).Returns(Task.CompletedTask); ViewResult response = (ViewResult)await _controller.Index(transactionGuid, result, tokenId, authrorisationCode); SuccessfulOneOffPaymentVm res = (SuccessfulOneOffPaymentVm)response.Model; //Assert Assert.AreEqual(successfulOneOffPaymentVm.ClientName, res.ClientName); Assert.AreEqual(model.PaymentInfo.LowellReference, res.PaymentInfo.LowellReference); VerifyAll(); }
public void RaiseOneOffPaymentEvent_PaymentComplete(SuccessfulOneOffPaymentVm vm, string userId, string planType) { string plan_status = vm.PaymentInfo.PlanInPlace ? "Payment against Plan" : "No Plan in Place"; plan_status = vm.PaymentInfo.InArrears ? "Plan Arrears Payment" : plan_status; vm.GtmEvents.Add(new GtmEvent() { gtm_event = GtmEvents.PaymentEvent, step = PaymentSteps.step4PaymentComplete, payment_type = "One Off Payment", payment_amount = vm.PaymentInfo.PaymentAmount, payment_detail = vm.PaymentInfo.PaidInFull ? "Full Balance" : "Partial Payment", discount_available = vm.PaymentInfo.DiscountAvailable ? "Discount available" : "No discount available", plan_type = planType, balance_selected = vm.PaymentInfo.DiscountSelected ? "Discounted Balance" : "Full Balance", plan_status = plan_status, guid = String.IsNullOrEmpty(userId) ? null : userId, user_status = String.IsNullOrEmpty(userId) ? "Not Logged In" : "Logged In", source_of_funds = vm.PaymentInfo.SourceOfFunds }); }
public async Task <IActionResult> Index( [FromQuery(Name = "ref")] string transactionGuid, [FromQuery] string result, [FromQuery] string tokenId, [FromQuery(Name = "acode")] string authrorisationCode) { try { var verifoneTransactionDto = await _verifonePaymentProviderService.GetVerifoneTransactionAsync(transactionGuid); //Transaction not exists in web or return url tampered if (string.IsNullOrEmpty(verifoneTransactionDto.TransactionData)) { Logger.LogWarning($"Payment transaction { transactionGuid} and this request looks like not exists in webpayment and will be ignored. If this need be actioned for any reason use auth code { authrorisationCode} token { tokenId}"); return(View("Failed", new PaymentResultVm { Reference = transactionGuid, Result = result, TokenId = tokenId, ACode = authrorisationCode })); } var oneOffPaymentDto = JsonConvert.DeserializeObject <OneOffPaymentDto>(verifoneTransactionDto.TransactionData); var model = new PaymentResultVm { Reference = transactionGuid, Result = result, TokenId = tokenId, ACode = authrorisationCode, PaymentInfo = oneOffPaymentDto }; //Transaction already processed or page got refreshed if (verifoneTransactionDto.Status != 0) { if (ApplicationSessionState.LogPaymentResult) { _gtmService.RaiseOneOffPaymentEvent_PaymentFailed(model, LoggedInUserId, "Regular Account"); await _webActivityService.LogOneOffPaymentFailure(model.PaymentInfo.LowellReference, LoggedInUserId, !model.PaymentInfo.PaidInFull, model.PaymentInfo.DiscountSelected); ApplicationSessionState.LogPaymentResult = false; } Logger.LogWarning($"Payment transaction { transactionGuid} is in status { verifoneTransactionDto.Status} and this request looks like a duplicate and will be ignored. If this need be actioned for any reason use auth code { authrorisationCode} token { tokenId}"); return(View("Failed", model)); } //set transaction details verifoneTransactionDto.TransactionGuid = transactionGuid; verifoneTransactionDto.Result = result; verifoneTransactionDto.TokenId = tokenId; verifoneTransactionDto.AuthorisationCode = authrorisationCode; if (model.Result == "CANCELLED") { await _verifonePaymentProviderService.UpdateVerifoneTransactionAsync(verifoneTransactionDto); if (ApplicationSessionState.LogPaymentResult) { _gtmService.RaiseOneOffPaymentEvent_PaymentCancelled(model, LoggedInUserId, "Regular Account"); await _webActivityService.LogOneOffPaymentCancelled(model.PaymentInfo.LowellReference, LoggedInUserId, !model.PaymentInfo.PaidInFull, model.PaymentInfo.DiscountSelected); ApplicationSessionState.LogPaymentResult = false; } return(View("Cancelled", model)); } if (model.Result == "FAILED") { await _verifonePaymentProviderService.UpdateVerifoneTransactionAsync(verifoneTransactionDto); if (ApplicationSessionState.LogPaymentResult) { _gtmService.RaiseOneOffPaymentEvent_PaymentFailed(model, LoggedInUserId, "Regular Account"); await _webActivityService.LogOneOffPaymentFailure(model.PaymentInfo.LowellReference, LoggedInUserId, !model.PaymentInfo.PaidInFull, model.PaymentInfo.DiscountSelected); ApplicationSessionState.LogPaymentResult = false; } return(View("Failed", model)); } if (model.Result == "SUCCESS") { var successfulOneOffPaymentVm = new SuccessfulOneOffPaymentVm { ClientName = oneOffPaymentDto.ClientName, PaymentInfo = model.PaymentInfo, UserLoggedIn = !string.IsNullOrEmpty(LoggedInUserId) }; await _paymentService.MakePayment(model, oneOffPaymentDto); await _verifonePaymentProviderService.UpdateVerifoneTransactionAsync(verifoneTransactionDto); if (ApplicationSessionState.LogPaymentResult) { _gtmService.RaiseOneOffPaymentEvent_PaymentComplete(successfulOneOffPaymentVm, LoggedInUserId, "Regular Account"); await _webActivityService.LogOneOffPaymentComplete(model.PaymentInfo.LowellReference, LoggedInUserId, !model.PaymentInfo.PaidInFull, model.PaymentInfo.DiscountSelected); ApplicationSessionState.LogPaymentResult = false; } return(View("Success", successfulOneOffPaymentVm)); } return(View("Error")); } catch (Exception ex) { Logger.LogError("One off payment error", ex); return(View("Error")); } }