public Transaction CreateTransaction(CheckPaymentVM checkPaymentVM) { Transaction transaction = new Transaction(); billing_address billing_address = new billing_address(); tele_check tele_check = new tele_check(); transaction.method = "tele_check"; transaction.transaction_type = "purchase"; //REMEMBER CANNOT HAVE PERIODS OR SPACES transaction.amount = Convert.ToInt32(checkPaymentVM.PrePaymentVM.Total.Replace(".", "").Trim()); transaction.currency_code = "USD"; billing_address.city = checkPaymentVM.PrePaymentVM.CustomerCity; billing_address.country = "US"; billing_address.state_province = checkPaymentVM.PrePaymentVM.CustomerState; billing_address.street = checkPaymentVM.PrePaymentVM.CustomerAddress; billing_address.zip_postal_code = checkPaymentVM.PrePaymentVM.CustomerZip; transaction.billing_address = billing_address; tele_check.account_number = Convert.ToInt32(checkPaymentVM.AccountNumber); tele_check.routing_number = checkPaymentVM.RoutingNumber; tele_check.check_number = checkPaymentVM.CheckNumber; tele_check.check_type = checkPaymentVM.CheckType; tele_check.accountholder_name = checkPaymentVM.AccountHolderName; tele_check.customer_id_type = checkPaymentVM.CustomerIdType; tele_check.customer_id_number = checkPaymentVM.CustomerIdNumber; tele_check.client_email = checkPaymentVM.PrePaymentVM.CustomerEmail; transaction.tele_check = tele_check; return(transaction); }
public CheckResponse Send(CheckPaymentVM checkPaymentVM) { CheckResponse checkResponse = new CheckResponse(); Transaction transaction = new Transaction(); Token token = new Token(); transaction = CreateTransaction(checkPaymentVM); token = GetToken(); var payload = JsonConvert.SerializeObject(transaction); byte[] byteArray = Encoding.UTF8.GetBytes(payload); var apiKey = token.api_key; var timeStamp = ((long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds).ToString(CultureInfo.InvariantCulture); var nonce = (10000000000000000000 * new Random(DateTime.Now.Millisecond).NextDouble()).ToString("0000000000000000000"); var merchantToken = token.merchant_token; var secretKey = token.api_secret; var post = (HttpWebRequest)HttpWebRequest.Create("https://api-cert.payeezy.com/v1/transactions"); post.Method = "POST"; post.KeepAlive = true; post.Accept = "*/*"; post.Headers.Add("Accept-Encoding", "gzip"); post.Headers.Add("Accept-Language", "en-US"); post.Headers.Add("apikey", apiKey); post.Headers.Add("nonce", nonce); post.Headers.Add("timestamp", timeStamp); var authorize = CreateHMAC(apiKey, secretKey, merchantToken, payload, nonce, timeStamp); post.Headers.Add("Authorization", authorize); post.ContentType = "application/json"; post.Headers.Add("token", merchantToken); post.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7"; post.GetRequestStream().Write(byteArray, 0, byteArray.Length); var response = post.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); var responseFromServer = reader.ReadToEnd(); checkResponse = JsonConvert.DeserializeObject <CheckResponse>(responseFromServer); return(checkResponse); }