public static readonly string ReturnUnlinked = "ReturnUnlinked"; // Return/Refund without a prior sale (CP) public static string GetTranType(CardTransactionType txnType, string prevTxnReference = "") { string velocityTxnType = ""; switch (txnType) { case CardTransactionType.Sale: velocityTxnType = TerminalTransactionType.CCR1; break; case CardTransactionType.Refund: velocityTxnType = string.IsNullOrEmpty(prevTxnReference) ? TerminalTransactionType.CCR9 : Refund; break; case CardTransactionType.Void: velocityTxnType = Void; break; default: velocityTxnType = ""; break; } return(velocityTxnType); }
public TransactionResponse RunApiTransaction(double amount, CardTransactionType transactionType, string prevTxnId) { TransactionResponse response = new TransactionResponse(); string txnType = VelocityTransactionType.GetTranType(transactionType, prevTxnId); if (!string.IsNullOrEmpty(txnSessionToken)) { if (string.Equals(txnType, VelocityTransactionType.Void)) { UndoTxn undoTran = new UndoTxn(applnProfileId, prevTxnId); string postDataJson = undoTran.toJson(); response = ExecRestTransaction(txnEndPoint, postDataJson, txnSessionToken, "PUT", txnType); } else if (string.Equals(txnType, VelocityTransactionType.Refund)) { ReturnByIdTxn refundTxn = new ReturnByIdTxn(applnProfileId, merchantProfileId, prevTxnId, amount); string postDataJson = refundTxn.toJson(); response = ExecRestTransaction(txnEndPoint, postDataJson, txnSessionToken, "POST", txnType); } } else { response.ErrorMessage = string.Format("Error processing {0} on endPoint {1} : Result: {2}", txnType, txnEndPoint, "Empty or Invalid session token"); response.IsError = true; } return(response); }
public static CardTransaction Create(Transaction transaction, CardTransactionType transactionType) { return(new CardTransaction { Id = Guid.NewGuid(), Transaction = transaction, TransactionType = transactionType }); }
public TransactionResponse ProcessTransaction(double amount, CardTransactionType transactionType = CardTransactionType.Sale, string prevTransactionID = "") { TransactionResponse response = null; TransactionProcessor txnProcessor = new TransactionProcessor(); System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; if (transactionType == CardTransactionType.Sale || (transactionType == CardTransactionType.Refund && string.IsNullOrEmpty(prevTransactionID))) { response = txnProcessor.RunTerminalTransaction(terminalUri, amount, transactionType); } else { string sessionToken = GetSessionToken(); string txnUrl = BuildRestUri(prevTransactionID); txnProcessor.SetTxnApiData(txnUrl, sessionToken, APP_PROFILE_ID, MERCH_PROFILE_ID); response = txnProcessor.RunApiTransaction(amount, transactionType, prevTransactionID); } return(response); }
public TransactionResponse RunTerminalTransaction(string uri, double amount, CardTransactionType transactionType) { TransactionResponse response = new TransactionResponse(); string txnType = VelocityTransactionType.GetTranType(transactionType); string postDataXml = string.Format("<DETAIL><TRAN_TYPE>{0}</TRAN_TYPE><AMOUNT>{1}</AMOUNT></DETAIL>", txnType, amount.ToString()); HttpClientApi httpClientApi = new HttpClientApi(); string responseMessage = httpClientApi.ProcessTransaction(uri, postDataXml); if (httpClientApi.httpStatus == System.Net.HttpStatusCode.OK && httpClientApi.exceptionStatus == "NONE") { response = TerminalTxnResponse.GetTransactionResponseFromXml(responseMessage); } else { response.ErrorMessage = string.Format("Error processing {0} on device {1} : Result: {2} : Detail: {3}", txnType, uri, httpClientApi.statusCode, httpClientApi.exceptionData); response.IsError = true; } return(response); }