public cnpResponse receiveFromCnp(string batchFileName) { var useEncryption = config.ContainsKey("useEncryption")? config["useEncryption"] : "false"; var pgpPassphrase = config.ContainsKey("pgpPassphrase")? config["pgpPassphrase"] : ""; cnpFile.createDirectory(responseDirectory); var responseFilePath = Path.Combine(responseDirectory, batchFileName); var batchResponseDir = responseDirectory; var finalResponseFilePath = responseFilePath; if ("true".Equals(useEncryption)) { batchResponseDir = Path.Combine(responseDirectory, "encrypted"); finalResponseFilePath = Path.Combine(batchResponseDir, batchFileName); cnpFile.createDirectory(finalResponseFilePath); } communication.FtpPickUp(finalResponseFilePath, config, batchFileName); if ("true".Equals(useEncryption)) { responseFilePath = responseFilePath.Replace(".encrypted", ""); PgpHelper.DecryptFile(finalResponseFilePath, responseFilePath, pgpPassphrase); } var cnpResponse = (cnpResponse)cnpXmlSerializer.DeserializeObjectFromFile(responseFilePath); return(cnpResponse); }
/* * Retrieves a response. */ public cnpResponse ReceiveFromCnp(string batchFileName) { var useEncryption = config.GetValue("useEncryption"); var pgpPassphrase = config.GetValue("pgpPassphrase"); cnpFile.CreateDirectory(this.responseDirectory); var responseFilePath = Path.Combine(this.responseDirectory, batchFileName); var batchResponseDir = this.responseDirectory; var finalResponseFilePath = responseFilePath; // Decrypt the file. if ("true".Equals(useEncryption)) { batchResponseDir = Path.Combine(responseDirectory, "encrypted"); finalResponseFilePath = Path.Combine(batchResponseDir, batchFileName); cnpFile.CreateDirectory(finalResponseFilePath); } communication.FtpPickUp(finalResponseFilePath, config, batchFileName); if ("true".Equals(useEncryption)) { responseFilePath = responseFilePath.Replace(".encrypted", ""); PgpHelper.DecryptFile(finalResponseFilePath, responseFilePath, pgpPassphrase); } // Deserialize and return the response. var cnpResponse = VersionedXMLDeserializer.Deserialize <cnpResponse>(File.ReadAllText(responseFilePath), this.config.GetVersion()); return(cnpResponse); }
/* * Sends the file. */ public string SendToCnp() { var useEncryption = config.GetValue("useEncryption"); var vantivPublicKeyId = config.GetValue("vantivPublicKeyId"); // Serialize the file. var requestFilePath = this.Serialize(); var batchRequestDir = requestDirectory; var finalRequestFilePath = requestFilePath; // Encrypt the file. if ("true".Equals(useEncryption)) { batchRequestDir = Path.Combine(requestDirectory, "encrypted"); Console.WriteLine(batchRequestDir); finalRequestFilePath = Path.Combine(batchRequestDir, Path.GetFileName(requestFilePath) + ".encrypted"); cnpFile.CreateDirectory(finalRequestFilePath); PgpHelper.EncryptFile(requestFilePath, finalRequestFilePath, vantivPublicKeyId); } // Drop off the file. communication.FtpDropOff(batchRequestDir, Path.GetFileName(finalRequestFilePath), config); // Return the file name. return(Path.GetFileName(finalRequestFilePath)); }
//public cnpResponse sendToCnpWithStream() //{ // var requestFilePath = this.Serialize(); // var batchName = Path.GetFileName(requestFilePath); // var responseFilePath = communication.SocketStream(requestFilePath, responseDirectory, config); // var cnpResponse = (cnpResponse)cnpXmlSerializer.DeserializeObjectFromFile(responseFilePath); // return cnpResponse; //} public string sendToCnp() { var useEncryption = config.ContainsKey("useEncryption")? config["useEncryption"] : "false"; var vantivPublicKeyId = config.ContainsKey("vantivPublicKeyId")? config["vantivPublicKeyId"] : ""; var requestFilePath = this.Serialize(); var batchRequestDir = requestDirectory; var finalRequestFilePath = requestFilePath; if ("true".Equals(useEncryption)) { batchRequestDir = Path.Combine(requestDirectory, "encrypted"); Console.WriteLine(batchRequestDir); finalRequestFilePath = Path.Combine(batchRequestDir, Path.GetFileName(requestFilePath) + ".encrypted"); cnpFile.createDirectory(finalRequestFilePath); PgpHelper.EncryptFile(requestFilePath, finalRequestFilePath, vantivPublicKeyId); } communication.FtpDropOff(batchRequestDir, Path.GetFileName(finalRequestFilePath), config); return(Path.GetFileName(finalRequestFilePath)); }