Subversion Repository Public Repository

ChrisCompleteCodeTrunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Net;
using System.ComponentModel;
using System.Reflection;
using System.Web;
using System.Security.Cryptography.X509Certificates;

namespace Action_Tire_Payment_Processor
{
    public class EVO_Process
    {

        //EVO Info to be hard-coded here in the executable:
        // Url: https://secure.evogateway.com/api/transact.php
        // User: actiontireco
        // Pwd: 26BBDSsolutions!

        public static int ProcessSalePayment(CardInfoForm cif, ref string resp, ref string authCode, ref string responseText, ref string transID)
        {
            bool fakeEVOPost = false;
            int recID = EVODbLog(cif);
            
            string evoUrl = "https://secure.evogateway.com/api/transact.php";
            //setup some variables
            String username = "actiontireco";
            String password = "26BBDSsolutions!";
            String firstname = cif.tbFirstName.Text.Trim();
            String lastname = cif.tbLastName.Text.Trim();
            String address1 = cif.tbAddress.Text.Trim();
            String city = cif.tbCity.Text.Trim();
            String state = cif.cmbStates.SelectedItem.ToString();
            String zip = cif.tbZip.Text.Trim();
            String amt = cif.tbAmount.Text.Trim();
            String cardNum = cif.tbCardNumber.Text.Trim();
            String cardExp = cif.tbExpirationDate.Text.Trim();
            String cardCVV = cif.tbCVV.Text.Trim();

            if (cif.TransactionType.Equals("refund"))
            {
                if(fakeEVOPost)
                {
                    resp = EVODbLogPost(recID, "", ref authCode, ref responseText, ref transID, fakeEVOPost);
                }
                else
                {
                    String result = "";
                    String strPost = "username=" + username + "&password=" + password + "&transactionid=" + cif.tbTransactionID.Text
                       + "&type=refund" + "&amount=" + amt;
                    StreamWriter myWriter = null;

                    HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(evoUrl);
                    objRequest.Method = "POST";
                    objRequest.ContentLength = strPost.Length;
                    objRequest.ContentType = "application/x-www-form-urlencoded";

                    try
                    {
                        myWriter = new StreamWriter(objRequest.GetRequestStream());
                        myWriter.Write(strPost);
                    }
                    catch (Exception e)
                    {
                    }
                    finally
                    {
                        myWriter.Close();
                    }

                    HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
                    using (StreamReader sr =
                       new StreamReader(objResponse.GetResponseStream()))
                    {
                        result = sr.ReadToEnd();
                        sr.Close();

                        resp = EVODbLogPost(recID, result, ref authCode, ref responseText, ref transID, fakeEVOPost);
                    }
                }
            }
            else if (cif.TransactionType.Equals("sale") || cif.TransactionType.Equals("roa"))
            {
                if(fakeEVOPost)
                {
                    resp = EVODbLogPost(recID, "", ref authCode, ref responseText, ref transID, fakeEVOPost);
                }
                else
                {
                    String result = "";
                    String strPost = "username=" + username + "&password=" + password
                       + "&firstname=" + firstname + "&lastname=" + lastname
                       + "&address1=" + address1 + "&city=" + city + "&state=" + state
                       + "&zip=" + zip + "&payment=creditcard&type=sale"
                       + "&amount=" + amt + "&ccnumber=" + cardNum + "&ccexp=" + cardExp + "&cvv=" + cardCVV;
                    StreamWriter myWriter = null;

                    HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(evoUrl);
                    objRequest.Method = "POST";
                    objRequest.ContentLength = strPost.Length;
                    objRequest.ContentType = "application/x-www-form-urlencoded";

                    try
                    {
                        myWriter = new StreamWriter(objRequest.GetRequestStream());
                        myWriter.Write(strPost);
                    }
                    catch (Exception e)
                    {
                    }
                    finally
                    {
                        myWriter.Close();
                    }

                    HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
                    using (StreamReader sr =
                       new StreamReader(objResponse.GetResponseStream()))
                    {
                        result = sr.ReadToEnd();
                        sr.Close();

                        resp = EVODbLogPost(recID, result, ref authCode, ref responseText, ref transID, fakeEVOPost);
                    }
                }
            }

            return recID;
        }

        public static int EVODbLog(CardInfoForm cif)
        {
            string query = "INSERT INTO Transactions (StoreID, PrinterIP, OrderID, TransType, Amount, CardNbr, CardType, " +
            "CardTypeGroup, CardHolder, FirstName, LastName, ExpDate, Address, City, State, Zip, Phone, Fax, Email, DateCreated) VALUES (" +
            "@StoreID, @PrinterIP, @OrderID, @TransType, @Amount, @CardNbr, @CardType, " +
            "@CardTypeGroup, @CardHolder, @FirstName, @LastName, @ExpDate, @Address, @City, @State, @Zip, @Phone, @Fax, @Email, GETDATE()) " +
            "SELECT IDENT_CURRENT('Transactions') AS RecID";

            SqlCommand cmd = new SqlCommand(query, Database.sql);
            cmd.Parameters.AddWithValue("@StoreID", Settings.GetOption("STORE"));
            cmd.Parameters.AddWithValue("@PrinterIP", Settings.GetOption("PRINTERIP"));
            cmd.Parameters.AddWithValue("@OrderID", cif.tbOrderNumber.Text.Equals("") ? DBNull.Value : (object)cif.tbOrderNumber.Text);
            cmd.Parameters.AddWithValue("@TransType", cif.TransactionType);
            cmd.Parameters.AddWithValue("@Amount", cif.tbAmount.Text);
            cmd.Parameters.AddWithValue("@CardNbr", cif.tbCardNumber.Text.Equals("") || cif.tbCardNumber.Text.Length <= 4 ? "" : cif.tbCardNumber.Text.Substring(cif.tbCardNumber.Text.Length - 4, 4));
            cmd.Parameters.AddWithValue("@CardType", cif.CardType == null ? DBNull.Value : (object)cif.CardType);
            cmd.Parameters.AddWithValue("@CardTypeGroup", cif.CardTypeGroup == null ? DBNull.Value : (object)cif.CardTypeGroup);
            cmd.Parameters.AddWithValue("@CardHolder", cif.CardHolder == null ? DBNull.Value : (object)cif.CardHolder);
            cmd.Parameters.AddWithValue("@FirstName", cif.tbFirstName.Text.Equals("") ? DBNull.Value : (object)cif.tbFirstName.Text);
            cmd.Parameters.AddWithValue("@LastName", cif.tbLastName.Text.Equals("") ? DBNull.Value : (object)cif.tbLastName.Text);
            cmd.Parameters.AddWithValue("@ExpDate", cif.tbExpirationDate.Text);
            cmd.Parameters.AddWithValue("@Address", cif.tbAddress.Text.Equals("") ? (DBNull.Value) : (object)cif.tbAddress.Text);
            cmd.Parameters.AddWithValue("@City", cif.tbCity.Text.Equals("") ? (DBNull.Value) : (object)cif.tbCity.Text);
            cmd.Parameters.AddWithValue("@State", cif.cmbStates.Text.Equals("") ? (DBNull.Value) : (object)cif.cmbStates.Text);
            cmd.Parameters.AddWithValue("@Zip", cif.tbZip.Text.Equals("") ? (DBNull.Value) : (object)cif.tbZip.Text);
            cmd.Parameters.AddWithValue("@Phone", cif.tbPhone.Text.Equals("") ? (DBNull.Value) : (object)cif.tbPhone.Text);
            cmd.Parameters.AddWithValue("@Fax", cif.tbFax.Text.Equals("") ? (DBNull.Value) : (object)cif.tbFax.Text);
            cmd.Parameters.AddWithValue("@Email", cif.tbEmail.Text.Equals("") ? (DBNull.Value) : (object)cif.tbEmail.Text);

            DataTable result = Database.Query(cmd);

            int RecID = -1;

            if (result.Rows.Count > 0)
            {
                RecID = int.Parse(result.Rows[0]["RecID"].ToString());
            }

            result.Dispose();

            return RecID;
        }

        public static string EVODbLogPost(int RecID, string results, ref string authCode, ref string responseText, ref string transID, bool isFake)
        {
            if(isFake)
            {
                string query = "UPDATE Transactions SET Response = @Response, Response_Code = @ResponseCode, " +
                    "Response_Text = @ResponseText, AuthCode = @AuthCode, TransID = @TransID, AVS_Response = @AVSResponse, CVV_Response = @CVVResponse " +
                    "WHERE ID = @RecID";

                string transId = Environment.TickCount.ToString();
                SqlCommand cmd = new SqlCommand(query, Database.sql);
                cmd.Parameters.AddWithValue("@Response", "1");
                cmd.Parameters.AddWithValue("@ResponseCode", "100");
                cmd.Parameters.AddWithValue("@ResponseText", "SUCCESS");
                cmd.Parameters.AddWithValue("@AuthCode", "987654");
                cmd.Parameters.AddWithValue("@TransID", transId);
                cmd.Parameters.AddWithValue("@AVSResponse", "N");
                cmd.Parameters.AddWithValue("@CVVResponse", "M");
                cmd.Parameters.AddWithValue("@RecID", RecID);

                Database.NonQuery(cmd);

                authCode = "987654";
                responseText = "SUCCESS";
                transID = transId;
                return "1";
            }
            else
            {
                NameValueCollection whats = HttpUtility.ParseQueryString(results);

                string query = "UPDATE Transactions SET Response = @Response, Response_Code = @ResponseCode, " +
                    "Response_Text = @ResponseText, AuthCode = @AuthCode, TransID = @TransID, AVS_Response = @AVSResponse, CVV_Response = @CVVResponse " +
                    "WHERE ID = @RecID";

                SqlCommand cmd = new SqlCommand(query, Database.sql);
                cmd.Parameters.AddWithValue("@Response", whats["response"].ToString().Equals("") ? DBNull.Value : (object)whats["response"].ToString());
                cmd.Parameters.AddWithValue("@ResponseCode", whats["response_code"].ToString().Equals("") ? DBNull.Value : (object)whats["response_code"].ToString());
                cmd.Parameters.AddWithValue("@ResponseText", whats["responsetext"].ToString().Equals("") ? DBNull.Value : (object)whats["responsetext"].ToString());
                cmd.Parameters.AddWithValue("@AuthCode", whats["authcode"].ToString().Equals("") ? DBNull.Value : (object)whats["authcode"].ToString());
                cmd.Parameters.AddWithValue("@TransID", whats["transactionid"].ToString().Equals("") ? DBNull.Value : (object)whats["transactionid"].ToString());
                cmd.Parameters.AddWithValue("@AVSResponse", whats["avsresponse"].ToString().Equals("") ? DBNull.Value : (object)whats["avsresponse"].ToString());
                cmd.Parameters.AddWithValue("@CVVResponse", whats["cvvresponse"].ToString().Equals("") ? DBNull.Value : (object)whats["cvvresponse"].ToString());
                cmd.Parameters.AddWithValue("@RecID", RecID);

                Database.NonQuery(cmd);

                authCode = whats["authcode"].ToString().Trim();
                responseText = whats["responsetext"].ToString().Trim();
                transID = whats["transactionid"].ToString().Trim();
                return whats["response"].ToString().Trim();
            }
        }
    }
}

Commits for ChrisCompleteCodeTrunk/ATTP/ATPP_New/EVO_Process.cs

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000