📄 billing.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Billing : System.Web.UI.Page {
double cartSubTotal = 0;
protected void Page_Load(object sender, EventArgs e) {
//this page MUST be protected by SSL!
pnlBillInfo.Visible = radPayType.SelectedIndex == 0;
trPlaceOrder.Visible = radPayType.SelectedIndex == 0;
if (!Page.IsPostBack) {
//as a convenience
LoadExpirationYear();
LoadProfile();
BindOrder();
}
}
void BindOrder() {
ShoppingCart cart = ShoppingCartManager.GetCart();
cartSubTotal = cart.SubTotal;
dgBasket.DataSource = cart.Items;
dgBasket.DataBind();
}
void LoadExpirationYear() {
for (int i = DateTime.Now.Year; i < DateTime.Now.Year + 6; i++) {
ddlExpYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
}
string GetUserEmail() {
//get the user's data
MembershipUser thisUser = Membership.GetUser(User.Identity.Name);
return thisUser.Email;
}
void LoadProfile() {
//if the profile has been set,
//use that
string sState = "";
string sCountry = "";
if (Profile.First != string.Empty) {
txtBillFirst.Text = Profile.First;
txtBillLast.Text = Profile.Last;
txtBillCity.Text = Profile.City;
txtBillZip.Text = Profile.Zip;
txtBillAddress2.Text = Profile.Address2;
txtBillAddress.Text = Profile.Address1;
sState = Profile.State;
sCountry = Profile.Country;
} else {
//assume it's the same as shipping
txtBillFirst.Text = Profile.Commerce.ShipFirst;
txtBillLast.Text = Profile.Commerce.ShipLast;
txtBillCity.Text = Profile.Commerce.ShipCity;
txtBillZip.Text = Profile.Commerce.ShipZip;
txtBillAddress2.Text = Profile.Commerce.ShipAddress2;
txtBillAddress.Text = Profile.Commerce.ShipAddress1;
sState = Profile.Commerce.ShipState;
sCountry = Profile.Commerce.ShipCountry;
}
LocationSelector1.LoadDrops(sState, sCountry);
}
void SetProfile() {
Profile.First = txtBillFirst.Text;
Profile.Last = txtBillLast.Text;
Profile.City = txtBillCity.Text;
Profile.Zip = txtBillZip.Text;
Profile.Address1 = txtBillAddress.Text;
Profile.Address2 = txtBillAddress2.Text;
Profile.State = LocationSelector1.GetSelectedState();
Profile.Country = LocationSelector1.GetSelectedCountry();
Profile.Save();
}
protected void btnPayPal_Click(object sender, EventArgs e) {
SetExpressOrder();
}
void SetExpressOrder() {
//use the API to get the SetCheckout response.
//Then, redirect to PayPal
Commerce.PayPal.APIWrapper wrapper = new Commerce.PayPal.APIWrapper(
SiteConfiguration.PayPalAPIAccountName, SiteConfiguration.PayPalAPIAccountPassword,
SiteConfiguration.PayPalAPICertificationPath, SiteConfiguration.PayPalAPICertificationPassword);
string sEmail = GetUserEmail();
ShoppingCart cart = ShoppingCartManager.GetCart();
try {
string successURL = Utility.GetSiteRoot() + "/checkoutconfirm.aspx";
string cancelURL = Utility.GetSiteRoot() + "/checkout.aspx";
string ppToken = wrapper.SetExpressCheckout(sEmail, cart.SubTotal,
successURL, cancelURL);
string sUrl = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ppToken;
if (SiteConfiguration.UseSandbox) {
sUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ppToken;
}
Response.Redirect(sUrl);
} catch (Exception x) {
pnlError.Visible = true;
lblError.Text = x.Message;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -