-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathPayment.aspx.cs
167 lines (154 loc) · 6.77 KB
/
Payment.aspx.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using paytm;
public partial class Payment : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERNAME"] != null)
{
if (!IsPostBack)
{
BindPriceData();
}
}
else
{
Response.Redirect("~/SignIn.aspx");
}
}
public void BindPriceData()
{
if (Request.Cookies["CartPID"] != null)
{
string CookieData = Request.Cookies["CartPID"].Value.Split('=')[1];
string[] CookieDataArray = CookieData.Split(',');
if (CookieDataArray.Length > 0)
{
DataTable dtBrands = new DataTable();
Int64 CartTotal = 0;
Int64 Total = 0;
for (int i = 0; i < CookieDataArray.Length; i++)
{
string PID = CookieDataArray[i].ToString().Split('-')[0];
string SizeID = CookieDataArray[i].ToString().Split('-')[1];
if (hdPidSizeID.Value != null && hdPidSizeID.Value != "")
{
hdPidSizeID.Value += "," + PID + "-" + SizeID;
}
else
{
hdPidSizeID.Value = PID + "-" + SizeID;
}
String CS = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
using (SqlCommand cmd = new SqlCommand("select A.*,dbo.getSizeName(" + SizeID + ") as SizeNamee,"
+ SizeID + " as SizeIDD,SizeData.Name,SizeData.Extention from tblProducts A cross apply( select top 1 B.Name,Extention from tblProductImages B where B.PID=A.PID ) SizeData where A.PID="
+ PID + "", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(dtBrands);
}
}
}
CartTotal += Convert.ToInt64(dtBrands.Rows[i]["PPrice"]);
Total += Convert.ToInt64(dtBrands.Rows[i]["PSelPrice"]);
}
divPriceDetails.Visible = true;
spanCartTotal.InnerText = CartTotal.ToString();
spanTotal.InnerText = "Rs. " + Total.ToString();
spanDiscount.InnerText = "- " + (CartTotal - Total).ToString();
hdCartAmount.Value = CartTotal.ToString();
hdCartDiscount.Value = (CartTotal - Total).ToString();
hdTotalPayed.Value = Total.ToString();
}
else
{
//TODO Show Empty Cart
Response.Redirect("~/Products.aspx");
}
}
else
{
//TODO Show Empty Cart
Response.Redirect("~/Products.aspx");
}
}
protected void btnPaytm_Click(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
string USERID = Session["USERID"].ToString();
string PaymentType = "Paytm";
string PaymentStatus = "NotPaid";
string EMAILID = Session["USEREMAIL"].ToString();
//Insert Data to tblPurchase
String CS = ConfigurationManager.ConnectionStrings["MyDatabaseConnectionString1"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("insert into tblPurchase values('" + USERID + "','"
+ hdPidSizeID.Value + "','" + hdCartAmount.Value + "','" + hdCartDiscount.Value + "','"
+ hdTotalPayed.Value + "','" + PaymentType + "','" + PaymentStatus + "',getdate(),'"
+ txtName.Text + "','" + txtAddress.Text + "','" + txtPinCode.Text + "','" + txtMobileNumber.Text + "') select SCOPE_IDENTITY()", con);
con.Open();
Int64 PurchaseID = Convert.ToInt64(cmd.ExecuteScalar());
string CallbackURL = "http://localhost:48599/Callback.aspx";
PaytmPayment(EMAILID, txtMobileNumber.Text, USERID, PurchaseID.ToString(), hdTotalPayed.Value, CallbackURL);
}
}
else
{
Response.Redirect("~/SignIn.aspx");
}
}
public void PaytmPayment(string EMAIL, string MOBILE_NO, string CUST_ID, string ORDER_ID, string TXN_AMOUNT, string CALLBACK_URL)
{
String merchantKey = "MPcGd0ghcT%jAOghhgUD5A";
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("MID", "TechCyghhgfhgfh4079455gb4643273");
parameters.Add("CHANNEL_ID", "WEB");
parameters.Add("INDUSTRY_TYPE_ID", "Retail");
parameters.Add("WEBSITE", "WEBSTAGING");
parameters.Add("EMAIL", EMAIL);
parameters.Add("MOBILE_NO", MOBILE_NO);
parameters.Add("CUST_ID", CUST_ID);
parameters.Add("ORDER_ID", ORDER_ID);
parameters.Add("TXN_AMOUNT", TXN_AMOUNT);
parameters.Add("CALLBACK_URL", CALLBACK_URL); //This parameter is not mandatory. Use this to pass the callback url dynamically.
string checksum = CheckSum.generateCheckSum(merchantKey, parameters);
string paytmURL = "https://pguat.paytm.com/oltp-web/processTransaction?orderid=" + ORDER_ID;
string outputHTML = "<html>";
outputHTML += "<head>";
outputHTML += "<title>Merchant Check Out Page</title>";
outputHTML += "</head>";
outputHTML += "<body>";
outputHTML += "<center><h1>Please do not refresh this page...</h1></center>";
outputHTML += "<form method='post' action='" + paytmURL + "' name='f1'>";
outputHTML += "<table border='1'>";
outputHTML += "<tbody>";
foreach (string key in parameters.Keys)
{
outputHTML += "<input type='hidden' name='" + key + "' value='" + parameters[key] + "'>";
}
outputHTML += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "'>";
outputHTML += "</tbody>";
outputHTML += "</table>";
outputHTML += "<script type='text/javascript'>";
outputHTML += "document.f1.submit();";
outputHTML += "</script>";
outputHTML += "</form>";
outputHTML += "</body>";
outputHTML += "</html>";
Response.Write(outputHTML);
}
}