HTML Code:
La chn code | n/Hin code
<%@
Page Language="C#" AutoEventWireup="true" CodeFile="TTPaypal.aspx.cs" Inher
its="NguoiDung_TTPaypal" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Thanh Toan Paypal</title>
<style type="text/css">
body{
background:#F5F5F5;
text-align:center
}
</style>
</head>
<body onload="document.paypal.submit()">
<form name="paypal" action="https://www.sandbox.paypal.com/cgi-
bin/webscr" method="post" title="Nguyen Van ABC">
<h1>Gi hàng c a b n đang đ c chuy n t i d ch v thanh toán ượ
Paypal</h1>
<input type="image" src="../Images/Design/installation_progress.gif" name=
"submit" alt="Please wait..!" />
<input name="business" type="hidden" value="Email-nguoi-
ban@gmail.com" />
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="Shipping" value= "USD"/>
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="rm" value="2" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="cs" value="0" />
<asp:PlaceHolder ID="plHej" runat="server"></asp:PlaceHolder>
</form>
</body>
</html>
Visual C# Code:
La chn code | n/Hin code
public partial class NguoiDung_TTPaypal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GioHang _cart = (GioHang)Session["GioHang"];
string strAdd = "";
if(_cart.Rows.Count > 0) {
for(int i = 0; i < _cart.Rows.Count; i++)
{
strAdd = "<input type=\"hidden\" value=\"" + _cart.Rows[i]
["TENSP"].ToString() + "\" name=\"item_name_" + (i + 1) + "\">";
plHej.Controls.Add(new System.Web.UI.LiteralControl(strAdd));
strAdd = "<input type=\"hidden\" value=\"" + _cart.Rows[i]
["GIAUSD"].ToString() + "\" name=\"amount_" + (i + 1) + "\">";
plHej.Controls.Add(new System.Web.UI.LiteralControl(strAdd));
strAdd = "<input type=\"hidden\" value=\"" + _cart.Rows[i]
["SOLUONG"].ToString() + "\" name=\"quantity_" + (i + 1) + "\">";
plHej.Controls.Add(new System.Web.UI.LiteralControl(strAdd));
strAdd = "<input type=\"hidden\" value=\"" + _cart.Rows[0]
["_shipping"].ToString() + "\" name=\"shipping_" + 1 + "\">";
plHej.Controls.Add(new System.Web.UI.LiteralControl(strAdd));
}
}
}
}
Gi hàng:
Visual C# Code:
La chn code | n/Hin code
public class GioHang:DataTable
{
private int MASP;
private string TENSP;
private int SOLUONG;
private double GIABAN;
private double GIAUSD;
private string HINHANH;
private double TONGGIA;
private double TONGGIAUSD;
private double _shipping;
public int Ma
{
set { MASP = value; }
get { return MASP; }
}
public string Ten
{
set { TENSP = value; }
get { return TENSP; }
}
public int soluong
{
set
{
if(SOLUONG >0)
{
SOLUONG = value;
}
}
get { return SOLUONG; }
}
public string anh
{
set { HINHANH = value; }
get { return HINHANH; }
}
public double Gia
{
set { GIABAN = value; }
get { return GIABAN; }
}
public double GiaUSD
{
set { GIAUSD = value; }
get { return GIAUSD; }
}
public double Tong
{
set { TONGGIA = value; }
get { return (GIABAN * SOLUONG); }
}
public double TongUSD
{
set { TONGGIAUSD = value; }
get { return (GiaUSD * SOLUONG); }
}
public double Shipping
{
get
{
return _shipping;
}
set
{
_shipping = value;
}
}
public GioHang()
{
this.Columns.Add("masp", typeof(int));
this.Columns.Add("tensp", typeof(string));
this.Columns.Add("soluong", typeof(int));
this.Columns.Add("gia", typeof(int));
this.Columns.Add("giaUSD", typeof(int));
this.Columns.Add("hinhanh",typeof(string));
this.Columns.Add("tonggia", typeof(double), "soluong*gia");
this.Columns.Add("tonggiaUSD", typeof(double), "soluong*giaUSD");
this.Columns.Add("_shipping", typeof(double), "2");
this.PrimaryKey = new DataColumn[] { this.Columns["masp"] };
}
public GioHang(int _ma, string _ten, string _anh, int _soluong, double _g
ia,double _giaUSD)
{
this.MASP = _ma;
this.TENSP = _ten;
this.HINHANH = _anh;
this.SOLUONG = _soluong;
this.GIABAN = _gia;
this.GIAUSD = _giaUSD;
this.TONGGIA = _gia * _soluong;
this.TONGGIAUSD = _giaUSD * _soluong;
}
public void themvaogiohang(int masp, string hinhanh, string tensp, int sl
, int gia, int giaUSD)
{
DataRow tmp = this.NewRow();
//neu san pham nay da co trong gio hang
if (kt(masp))
{
for (int i = 0; i < this.Rows.Count; i++)
{
if (masp == int.Parse(this.Rows[i]["masp"].ToString()))
{
this.Rows[i]["soluong"] = int.Parse(this.Rows[i]
["soluong"].ToString()) + 1;
}
}
}
//nguoc lai add them 1 dong moi
else
{
tmp["masp"] = masp;
tmp["hinhanh"] = hinhanh;
tmp["tensp"] = tensp;
tmp["soluong"] = sl;
tmp["gia"] = gia;
tmp["giaUSD"] = giaUSD;
this.Rows.Add(tmp);
}
}
//kien tra san pham nay da co trong gio hang chua
public bool kt(int masp) {
bool ok = false;
if (this.Rows.Count > 0) {
for (int i = 0; i < this.Rows.Count;i++ ) {
if (masp == Convert.ToInt16(this.Rows[i]
["masp"].ToString()))
ok = true;
}
} return ok;
}
public double tongtien() {
double g = 0;
for (int i = 0; i < this.Rows.Count; i++)
{
g = g + Convert.ToInt64(this.Rows[i]["tonggia"]);
} return g;
}
public double tongtienUSD()
{
double g = 0;
for (int i = 0; i < this.Rows.Count; i++)
{
g = g + Convert.ToInt64(this.Rows[i]["tonggiaUSD"]);
} return g;
}
public int tongsoluong() {
int s = 0;
for (int i = 0; i < this.Rows.Count; i++)
{
s = s + Convert.ToInt32(this.Rows[i]["soluong"]);
} return s;
}
public void updatesoluong(int sl, int masp)
{
try
{
for (int i = 0; i < this.Rows.Count; i++)
{
if (masp == Convert.ToInt64(this.Rows[i]
["masp"].ToString()))
{
this.Rows[i]["soluong"] = sl;
}
}
}
catch (Exception ex) { }
}
public void xoagiohang(int masp ) {
try {
DataRow dr = this.Rows.Find(masp);
this.Rows.Remove(dr);
}catch(Exception ex){}
}
}
Abstarct: In this article I am going to explain Step by Step Procedure, about integrating PayPal
account with asp.net.
Case Study: If any of the web application need to collect money from their customers, the best and
ideal solution is to open a Paypal Merchant account by using valid email id and respective Credit card
which belongs to their individual accounts.
PayPal is an e-commerce business which allows payments and money transfers via Internet.
It is an alternative to traditional paper methods such as checks and money orders.
Here I don’t want to give more explanation on Paypal accounting standards and money
transfers, why because it is a self explanatory resource which is available @ www.paypal.com for
more information.
Even we can integrate any web application not only PayPal, we had also third party vendors
like CCAvenue (http://www.ccavenue.com/), PayByWeb (http://www.paybyweb.com/), ABC Payments
(http://www.abcpayments.com/),EBS(www.ebs.in),Web link India (www.weblinkindia.net),Times Of
Money(http://www.timesofmoney.com/direcpay/jsp/home.jsp) ,Pro Pay(www.propay.com) ,World Pay
(www.worldpay.com) ,Data Cash(www.datcash.com).e.t.c. But in my real application I used PayPal
API for receiving Money from Customers.
Hands on Experiment :
In this experiment I will give total explanation and step by step procedure about integrating Paypal to
asp.net website –which I did in my initial stages of development career. At that time the word online
payments hampers my Head Like anything, after a long research on Google and Paypal website-I
decided my self, we can integrate Paypal just like a kids Play.
Steps to integrate Paypal API to ASP.NET:
Step-1) Create Paypal Merchant Account @ www.paypal.com using valid Mail Account
Step-2) Provide Debit or Credit Card No and Its Type.
Step-3) Develop ASP.NET Page According To Your Requirement