protected string parseRequest(GatewayRequest request) { StringBuilder requestString = new StringBuilder(); requestString.Append("profile_id=").Append(settings.getProfileId()); requestString.Append("&profile_key=").Append(settings.getProfileKey()); string typeCode = null; switch (request.getType()) { case GatewayRequest.TransactionType.SALE: typeCode = "D"; break; case GatewayRequest.TransactionType.PREAUTH: typeCode = "P"; break; case GatewayRequest.TransactionType.REAUTH: typeCode = "J"; break; case GatewayRequest.TransactionType.OFFLINE: typeCode = "O"; break; case GatewayRequest.TransactionType.SETTLE: typeCode = "S"; break; case GatewayRequest.TransactionType.VOID: typeCode = "V"; break; case GatewayRequest.TransactionType.CREDIT: typeCode = "C"; break; case GatewayRequest.TransactionType.REFUND: typeCode = "U"; break; case GatewayRequest.TransactionType.VERIFY: typeCode = "A"; break; case GatewayRequest.TransactionType.TOKENIZE: typeCode = "T"; break; case GatewayRequest.TransactionType.DETOKENIZE: typeCode = "X"; break; case GatewayRequest.TransactionType.BATCHCLOSE: typeCode = "Z"; break; default: throw new MesRuntimeException("Transaction type unsupported: "+typeCode); } requestString.Append("&transaction_type=").Append(typeCode); foreach (DictionaryEntry entry in request.requestTable) requestString.Append("&").Append(entry.Key).Append("=").Append(entry.Value); return requestString.ToString(); }
///<summary> ///Sends the given request to the gateway, and returns a response object. ///</summary> public GatewayResponse run(GatewayRequest request) { http.setRequest(parseRequest(request)); if (settings.isVerbose()) System.Console.WriteLine("Sending request: "+http.getRequest()); http.run(); if (settings.isVerbose()) System.Console.WriteLine("Response: (HTTP "+http.getHttpCode()+" - "+http.getDuration()+"ms) " + http.getResponse()); return parseResponse(); }
public override ProcessPaymentResult ProcessPayment(ProcessPaymentEvaluationContext context) { var retVal = new ProcessPaymentResult(); GatewaySettings settings = new GatewaySettings(); settings.setCredentials(ProfileId, ProfileKey) .setVerbose(true) .setHostUrl(GatewaySettings.URL_CERT); Gateway gateway = new Gateway(settings); GatewayRequest request = new GatewayRequest(GatewayRequest.TransactionType.SALE); if (string.IsNullOrEmpty(context.Payment.OuterId)) { request.setCardData("4012888812348882", "1216"); } else { request.setTokenData(context.Payment.OuterId, string.Empty); } request.setAmount("1.03"); GatewayResponse response = gateway.run(request); var tranId = response.getTransactionId(); var errorCode = response.getErrorCode(); if(errorCode.Equals("000")) { retVal.OuterId = tranId; retVal.IsSuccess = true; retVal.NewPaymentStatus = PaymentStatus.Pending; //maybe } else { retVal.NewPaymentStatus = PaymentStatus.Voided; retVal.Error = string.Format("Mes error {0}", errorCode); } return retVal; }