YOMEDIA
ADSENSE
Code thanh toán trực tuyến asp.net
661
lượt xem 46
download
lượt xem 46
download
Download
Vui lòng tải xuống để xem tài liệu đầy đủ
Tài liệu tham khảo Code thanh toán trực tuyến asp.net dành cho các bạn kỹ thuật lập trình máy tính
AMBIENT/
Chủ đề:
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Code thanh toán trực tuyến asp.net
- HTML Code: Lựa chọn code | Ẩn/Hiện code Thanh Toan Paypal body{ background:#F5F5F5; text-align:center } Giỏ hàng của bạn đang được chuyển tới dịch vụ thanh toán Paypal Visual C# Code: Lựa chọn code | Ẩn/Hiện 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 = ""; plHej.Controls.Add(new System.Web.UI.LiteralControl(strAdd)); strAdd = "";
- plHej.Controls.Add(new System.Web.UI.LiteralControl(strAdd)); strAdd = ""; plHej.Controls.Add(new System.Web.UI.LiteralControl(strAdd)); strAdd = ""; plHej.Controls.Add(new System.Web.UI.LiteralControl(strAdd)); } } } } Giỏ hàng: Visual C# Code: Lựa chọn code | Ẩn/Hiện 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 ecommerce 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 websiteI decided my self, we can integrate Paypal just like a kids Play. Steps to integrate Paypal API to ASP.NET: Step1) Create Paypal Merchant Account @ www.paypal.com using valid Mail Account Step2) Provide Debit or Credit Card No and Its Type. Step3) Develop ASP.NET Page According To Your Requirement
- Step4) Integrate API by Passing Website Variables as a Input to PayPal Account Using our Mail Account writing customized Business logic Step1) Create Paypal Merchant Account @ www.paypal.com using valid Mail Account : Open www.payapal.com and register with valid Credentials as depicted below, here I used bangarubau.p@gmail.com mail account for receiving amounts, keep remember that this id will use full @ the time of integrating api with Business logic and registered with Business name as BangaruBabu’s Digital Shoppy. When the time I redirected from ASP.NET Page to PayPal Account Business Name will be displayed @ the top of the Paypal web page by using Mail Account I created. After creating Account, the account internals will be created to Individual
- In The above screen @ right hand side in Notifications option, I marked as red circle, in that link provide bank credit and debit card numbers. Left hand side Green Circle indicates money payments and Receivables information was provided. Black Color circle link indicates account status Verification option. Step2) Provide Debit or Credit Card No and Its Type Step3) Develop ASP.NET Page According To Requirement I considered online shopping Scenario by displaying electronic Gadgets on Asp.Net Web Page. In this Step I designed a Page by Using Three Images (Xbox, Bluetooth Headset,) three Labels to display the Currency on Web Page to the respective Electronic Gadgets and three Image Buttons.
- Step4) Integrate API by Passing Website Variables as an Input to PayPal Account using our Mail Account writing customized Business logic. Before going to write Business logic we just discuss Paypal API Link and its Parameters Paypal API https://www.paypal.com/cgibin/webscr?cmd=_cart&business=mailid@server.com&businessname &item_name=Welcome Back&amount=10¤cy=USD&add=5 The above mentioned URL is a Constructive link to get the values from the website to Paypal Gateway. In the URL bold Letters indicates predefined parameters .Following are the some of the Parameter values and their descriptions
- Now add Class [RedirectToPaypal.cs] File in App_Code Folder. Write One Static Method by taking only two [as per as your requirement you can take nno of parameters to the function with predefined variable names mentioned in the above table] dynamic parameters. Here I am using single item Transaction for Shopping Scenario. Write Method as Follows in C# Language to construct a link. public static string getItemNameAndCost(string itemName, string itemCost) { //Converting String Money Value Into Decimal decimal price = Convert.ToDecimal(itemCost); //declaring empty String string returnURL = ""; returnURL +="https://www.paypal.com/xclick/business=bangarubabu.p@gmail.com"; //PassingItem Name as dynamic
- returnURL +="&item_name="+itemName; //AssigningName as Statically to Parameter returnURL += "&first_name"+ "Raghunadh Babu"; //AssigningCity as Statically to Parameter returnURL += "&city"+ "Hyderabad"; //Assigning State as Statically to Parameter returnURL += "&state"+ "Andhra Pradesh"; //Assigning Country as Statically to Parameter returnURL += "&country" + "India"; //Passing Amount as Dynamic returnURL += "&amount=" + price; //Passing Currency as your returnURL += "¤cy=USD"; //retturn Url if Customer wants To return to Previous Page returnURL += "&return=http://bangarubabupureti.spaces.live.com"; //retturn Url if Customer Wants To Cancel the Transaction returnURL += "&cancel_return=http://bangarubabupureti.spaces.live.com"; return returnURL; }
- Write Code Under Image Butons protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { string iName="XBox"; string responseURL = RedirectToPaypal.getItemNameAndCost(iName, lblxbox.Text); Response.Redirect(responseURL); } protected void ImageButton4_Click(object sender, ImageClickEventArgs e) { string iName = "Philips Mobile"; string responseURL = RedirectToPaypal.getItemNameAndCost(iName, lblphone.Text); Response.Redirect(responseURL); } protected void ImageButton5_Click(object sender, ImageClickEventArgs e) { string iName = "BlueTooth HeadSet"; string responseURL = RedirectToPaypal.getItemNameAndCost(iName, lblbluetooth.Text); Response.Redirect(responseURL); }
- Now run and Click On shop Now Paypal Button under Xbox, it will automatically Redirects to Paypal Web Site with your given input, the customer will pay according to your Specifications in the Website Here I used only _xclick command, if you want to add shopping cart or donations or subscriptions, you can customize application according to your requirement. My Reference: http://www.payapal.com Conclusion: In this article I covered all the aspects of the online Payment using PAYPAL gateway except Shopping Cart, even it is very easy. For more information checkhttp://www.payapal.com. I hope this article definitely helps.
ADSENSE
CÓ THỂ BẠN MUỐN DOWNLOAD
Thêm tài liệu vào bộ sưu tập có sẵn:
Báo xấu
LAVA
AANETWORK
TRỢ GIÚP
HỖ TRỢ KHÁCH HÀNG
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn