public void TestCardValid() { Guid merchantId = Guid.NewGuid(); string payerCardNum = "6031645798969426"; PaymentTransactionDetails paymentTransactionDetails = new PaymentTransactionDetails { Amount = 121.0, CCV = "231", ExpiryDate = "12/12/2021", MerchantId = merchantId, PayerCardNum = payerCardNum }; Mock <IPaymentService> mock = new Mock <IPaymentService>(); Card outputCard = new Card { CardNum = payerCardNum, CCV = "231", ExpiryDate = "12/12/2021" }; mock.Setup(i => i.CheckCard(paymentTransactionDetails)).Returns(outputCard); mock.Object.CheckCard(paymentTransactionDetails); mock.Verify(i => i.CheckCard(paymentTransactionDetails)); Assert.AreEqual(false, mock.Object.CheckCard(paymentTransactionDetails).IsValid); }
public ResponseBase Post([FromBody] PaymentTransactionDetails paymentTransactionDetails) { ResponseBase response = new ResponseBase(); Serilog.Log.Information("Method Process Payment Started"); //logger.InsertLog("Testing", Log.Constants.ErrorSet.Errors.Info); var msg = string.Empty; if (merchantsList != null && merchantsList.MerchantsInfoList != null && merchantsList.MerchantsInfoList.Any()) { var card = paymentService.CheckCard(paymentTransactionDetails); if (card.IsValid) { if (paymentTransactionDetails.MerchantId != Guid.Empty) { var currentMerchant = merchantsList.MerchantsInfoList.FirstOrDefault(i => i.Uid.Equals(paymentTransactionDetails.MerchantId)); if (currentMerchant != null) { var merchantCard = currentMerchant.CardNumber; if (!string.IsNullOrEmpty(merchantCard)) { //calling the bank API here var transactionResponse = paymentService.ProcessTransaction(paymentTransactionDetails, merchantCard); if (transactionResponse != null && transactionResponse.Identifier != Guid.Empty) { var updateHistoryResponse = paymentService.UpdatePaymentHistory(transactionResponse); if (transactionResponse.Status) { response.Success = true; return(response); } response.Error = $"An error occured while processing the transaction. Please try again later"; } else { response.Error = $"An error occured while processing the transaction. Please try again later"; } } } else { response.Error = $"Merchant with ID {paymentTransactionDetails.MerchantId.ToString()} cannot be found"; } } } else { response.Error = "Card is not valid"; } } else { msg = "Merchants list not available"; } return(response); }
public Card CheckCard(PaymentTransactionDetails paymentTransactionDetails) { var card = new Card { CardNum = paymentTransactionDetails.PayerCardNum, CCV = paymentTransactionDetails.CCV, ExpiryDate = paymentTransactionDetails.ExpiryDate }; return(card.ValidateCard(card)); }
public void PostTransactionData(PaymentTransactionDetails transactionDetails) { using (new LogScope(_logger)) { _logger.Debug("Posting Payflow transaction data to formsbuilder. Transaction Id = {0}, LastName={1}", transactionDetails.TransactionResponse.TransactionCode, transactionDetails.TransactionResponse.Lastname); string localRedirectUrl = null; if (transactionDetails.Operation == "cancel") { localRedirectUrl = transactionDetails.TransactionResponse.UserDefinedField1; } else if (transactionDetails.Operation == "error") { localRedirectUrl = transactionDetails.TransactionResponse.UserDefinedField1; } else if (transactionDetails.Operation == "return") { string paymentException = transactionDetails.TransactionResponse.PaymentException == null ? "" : transactionDetails.TransactionResponse.PaymentException.ExceptionMessage; long exceptionCode = 0; if (paymentException != "") { if (transactionDetails.TransactionResponse.PaymentException != null) { exceptionCode = transactionDetails.TransactionResponse.PaymentException.ExceptionCode; } } localRedirectUrl = string.Format("~/PaymentReceipt?firstname={0}&lastname={1}&pnref={2}&exp={3}&lastfour={4}&paymentExceptionCode={5}&paymentException={6}&authcode={7}&pageTitle=Hosted Page Response", transactionDetails.TransactionResponse.Firstname, transactionDetails.TransactionResponse.Lastname, transactionDetails.TransactionResponse.TransactionCode, transactionDetails.TransactionResponse.ExpiryMonthYear, transactionDetails.TransactionResponse.LastFour, exceptionCode, paymentException, transactionDetails.TransactionResponse.Authcode ); } else { _logger.Error("Could not process payment for: " + transactionDetails.TransactionResponse.Firstname + " " + transactionDetails.TransactionResponse.Lastname); } _logger.Debug("Redirecting to {0}", localRedirectUrl); HttpContext.Current.Response.Redirect(localRedirectUrl); } }
public void TestProcessTransactionPass() { Mock <IPaymentService> mock = new Mock <IPaymentService>(); Guid merchantId = Guid.NewGuid(); string payerCardNum = "456712341234"; string merchantCard = "41231425679"; PaymentTransactionDetails ptd = new PaymentTransactionDetails { Amount = 121.0, CCV = "231", ExpiryDate = "12/12/2020", MerchantId = merchantId, PayerCardNum = payerCardNum }; PaymentResponse pr = new PaymentResponse { Amount = 121.0, Identifier = Guid.NewGuid(), MerchantId = merchantId, PayerCardNum = "", Status = false }; mock.Setup(i => i.ProcessTransaction(ptd, merchantCard)).Returns(pr); MerchantsList ml = new MerchantsList { MerchantsInfoList = new System.Collections.Generic.List <MerchantInfo> { new MerchantInfo { Uid = pr.MerchantId, CardNumber = merchantCard } } }; // PaymentGatewayController paymentGatewayController = new PaymentGatewayController(mock.Object, ml); //paymentGatewayController.MakePayment(ptd); mock.Verify(f => f.ProcessTransaction(ptd, merchantCard)); Assert.AreEqual(pr, mock.Object.ProcessTransaction(ptd, merchantCard)); }
public PaymentResponse ProcessTransaction(PaymentTransactionDetails paymentTransactionDetails, string merchantCardNum) { if (!string.IsNullOrEmpty(merchantCardNum)) { try { //RestClient restClient = new RestClient(""); //RestRequest request = new RestRequest("/bank/transaction", Method.POST); //request.AddHeader("Content-Type", "application/json"); //request.AddParameter("merchantcard", merchantCardNum); //request.AddParameter("payeecard", paymentTransactionDetails.PayerCardNum); //request.AddParameter("ccv", paymentTransactionDetails.CCV); //request.AddParameter("amount", paymentTransactionDetails.Amount); //request.AddParameter("expiry", paymentTransactionDetails.ExpiryDate); //var test = restClient.Execute<PaymentResponse>(request); var paymentResponse = new PaymentResponse { Amount = paymentTransactionDetails.Amount, Identifier = Guid.NewGuid(), MerchantId = paymentTransactionDetails.MerchantId, PayerCardNum = paymentTransactionDetails.PayerCardNum, Status = false }; //fail or pass transaction randomly Random random = new Random(); int chosenNum = random.Next(0, 10); if (chosenNum % 2 == 0) { paymentResponse.Status = true; } return(paymentResponse); } catch (Exception e) { Serilog.Log.Error($"Error {e.Message} at {e.StackTrace} "); } } return(new PaymentResponse()); }
public void PostTransactionData(PaymentTransactionDetails transactionDetails) { using (new LogScope(_logger)) { _logger.Debug("Posting Payflow transaction data to formsbuilder. Transaction Id = {0}, LastName={1}", transactionDetails.TransactionResponse.TransactionCode, transactionDetails.TransactionResponse.Lastname); string localRedirectUrl = null; if (transactionDetails.Operation == "cancel") { localRedirectUrl = transactionDetails.TransactionResponse.UserDefinedField1; } else if (transactionDetails.Operation == "error") { localRedirectUrl = transactionDetails.TransactionResponse.UserDefinedField1; } else if (transactionDetails.Operation == "return") { string paymentException = transactionDetails.TransactionResponse.PaymentException == null ? "" : transactionDetails.TransactionResponse.PaymentException.ExceptionMessage; long exceptionCode = 0; if (paymentException != "") { if (transactionDetails.TransactionResponse.PaymentException != null) { exceptionCode = transactionDetails.TransactionResponse.PaymentException.ExceptionCode; } } var paymentServices = ServiceLocator.Default.GetAllInstances <IPaymentAdaptor>(); var paymentAdaptor = paymentServices.FirstOrDefault(svc => svc.GetType().Name.IndexOf("Touchnet", StringComparison.OrdinalIgnoreCase) >= 0); var paymentResponse = paymentAdaptor?.VerifyPayment(new VerifyPaymentRequest() { CorrelationId = transactionDetails.TransactionResponse.TransactionCode, TransactionId = transactionDetails.TransactionResponse.SecureToken, PaymentProviderInfo = new PaymentProviderInfo() { MerchantCode = "191", Partner = "Touchnet", UserName = "******", Password = "******", PaymentGatewayUrl = "https://test.secure.touchnet.net:8703/C30002test_tlink/services/TPGSecureLink", HostedPageUrl = "https://test.secure.touchnet.net:8443/C30002test_upay/web/index.jsp", } }); if (paymentResponse?.PaymentException != null) { //var configuration = InvokePluginUsingFetchExpression(model, new PluginInputData { PaymentProvider = model.PaymentProvider }, "PaymentGatewayConfigurationService").FirstOrDefault(); } localRedirectUrl = string.Format("~/PaymentReceipt?firstname={0}&lastname={1}&pnref={2}&exp={3}&lastfour={4}&paymentExceptionCode={5}&paymentException={6}&authcode={7}&pageTitle=Hosted Page Response", transactionDetails.TransactionResponse.Firstname, transactionDetails.TransactionResponse.Lastname, transactionDetails.TransactionResponse.TransactionCode, transactionDetails.TransactionResponse.ExpiryMonthYear, transactionDetails.TransactionResponse.LastFour, exceptionCode, paymentException, transactionDetails.TransactionResponse.Authcode ); } else { _logger.Error("Could not process payment for: " + transactionDetails.TransactionResponse.Firstname + " " + transactionDetails.TransactionResponse.Lastname); } _logger.Debug("Redirecting to {0}", localRedirectUrl); HttpContext.Current.Response.Redirect(localRedirectUrl); } }