本文整理汇总了C#中Cart.UpdateCart方法的典型用法代码示例。如果您正苦于以下问题:C# Cart.UpdateCart方法的具体用法?C# Cart.UpdateCart怎么用?C# Cart.UpdateCart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cart
的用法示例。
在下文中一共展示了Cart.UpdateCart方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authorize
public ActionResult Authorize() {
HttpContext ctx = System.Web.HttpContext.Current;
Customer customer = new Customer();
Settings settings = ViewBag.settings;
// Retrieve Customer from Sessions/Cookie
customer.GetFromStorage(ctx);
if (!customer.Cart.Validate()) {
return RedirectToAction("Index", "Cart");
}
if (customer.Cart.GetPaymentID() > 0) {
UDF.ExpireCart(ctx, customer.ID);
return RedirectToAction("Index", "Cart");
}
customer.BindAddresses();
decimal amount = customer.Cart.getTotal();
string cardnum = Request.Form["cardnumber"];
string month = Request.Form["expiremonth"];
string year = Request.Form["expireyear"];
string cvv = Request.Form["cvv"];
string first = Request.Form["first"];
string last = Request.Form["last"];
//step 1 - create the request
IGatewayRequest request = new AuthorizationRequest(cardnum, month + year, amount, "Transaction");
//These are optional calls to the API
request.AddCardCode(cvv);
//Customer info - this is used for Fraud Detection
request.AddCustomer(customer.ID.ToString(), first, last, customer.Cart.Billing.street1 + ((customer.Cart.Billing.street2 != "") ? " " + customer.Cart.Billing.street2 : ""), customer.Cart.Billing.State1.abbr, customer.Cart.Billing.postal_code);
//order number
//request.AddInvoice("invoiceNumber");
//Custom values that will be returned with the response
//request.AddMerchantValue("merchantValue", "value");
//Shipping Address
request.AddShipping(customer.ID.ToString(), customer.Cart.Shipping.first, customer.Cart.Shipping.last, customer.Cart.Shipping.street1 + ((customer.Cart.Shipping.street2 != "") ? " " + customer.Cart.Shipping.street2 : ""), customer.Cart.Shipping.State1.abbr, customer.Cart.Shipping.postal_code);
//step 2 - create the gateway, sending in your credentials and setting the Mode to Test (boolean flag)
//which is true by default
//this login and key are the shared dev account - you should get your own if you
//want to do more testing
bool testmode = false;
if (settings.Get("AuthorizeNetTestMode").Trim() == "true") {
testmode = true;
}
Gateway gate = new Gateway(settings.Get("AuthorizeNetLoginKey"), settings.Get("AuthorizeNetTransactionKey"), testmode);
customer.Cart.SetStatus((int)OrderStatuses.PaymentPending);
//step 3 - make some money
IGatewayResponse response = gate.Send(request);
if (response.Approved) {
customer.Cart.AddPayment("credit card", response.AuthorizationCode, "Complete");
customer.Cart.SetStatus((int)OrderStatuses.PaymentComplete);
customer.Cart.SendConfirmation(ctx);
customer.Cart.SendInternalOrderEmail(ctx);
int cartid = customer.Cart.ID;
Cart new_cart = new Cart().Save();
new_cart.UpdateCart(ctx, customer.ID);
DateTime cookexp = Request.Cookies["hdcart"].Expires;
HttpCookie cook = new HttpCookie("hdcart", new_cart.ID.ToString());
cook.Expires = cookexp;
Response.Cookies.Add(cook);
customer.Cart = new_cart;
customer.Cart.BindAddresses();
return RedirectToAction("Complete", new { id = cartid });
} else {
customer.Cart.SetStatus((int)OrderStatuses.PaymentDeclined);
return RedirectToAction("Index", new { message = response.Message });
}
}
示例2: Google
public ActionResult Google()
{
Customer customer = ViewBag.customer;
customer.GetFromStorage();
if (!customer.LoggedIn()) {
return RedirectToAction("Index", "Authenticate", new { referrer = "https://" + Request.Url.Host + "/Cart/Checkout" });
}
if (customer.Cart.payment_id > 0) {
UDF.ExpireCart(customer.ID);
return RedirectToAction("Index", "Cart");
}
EcommercePlatformDataContext db = new EcommercePlatformDataContext();
Settings settings = ViewBag.settings;
CheckoutShoppingCartRequest req = gButton.CreateRequest();
if (Request.Url.Host.Contains("127.0.0") || Request.Url.Host.Contains("localhost") || settings.Get("GoogleCheckoutEnv") == "override") {
req.MerchantID = settings.Get("GoogleDevMerchantId");
req.MerchantKey = settings.Get("GoogleDevMerchantKey");
req.Environment = GCheckout.EnvironmentType.Sandbox;
} else {
req.MerchantID = settings.Get("GoogleMerchantId");
req.MerchantKey = settings.Get("GoogleMerchantKey");
req.Environment = GCheckout.EnvironmentType.Production;
}
if (settings.Get("GoogleAnalyticsCode") != "") {
req.AnalyticsData = Request.Form["analyticsdata"];
}
req.ContinueShoppingUrl = Request.Url.Scheme + "://" + Request.Url.Host;
//req.EditCartUrl = Request.Url.Host + "/Cart";
foreach (CartItem item in customer.Cart.CartItems) {
ShoppingCartItem sitem = new ShoppingCartItem {
Name = "CURT Part #" + item.partID,
Description = item.shortDesc,
Price = item.price,
Quantity = item.quantity,
Weight = Convert.ToDouble(item.weight)
};
req.AddItem(sitem);
}
System.Xml.XmlDocument tempDoc = new System.Xml.XmlDocument();
System.Xml.XmlNode tempNode = tempDoc.CreateElement("OrderNumber");
tempNode.InnerText = customer.Cart.ID.ToString();
req.AddMerchantPrivateDataNode(tempNode);
req.AddShippingPackage("0", customer.Cart.Shipping.city, customer.Cart.Shipping.State1.state1, customer.Cart.Shipping.postal_code);
req.AddFlatRateShippingMethod(customer.Cart.shipping_type, customer.Cart.shipping_price);
Country country = db.Countries.Where(x => x.abbr.Equals("US")).FirstOrDefault();
if(country != null) {
foreach(State state in country.States) {
req.AddStateTaxRule(state.abbr, Convert.ToDouble(state.taxRate / 100), true);
}
}
GCheckoutResponse resp = req.Send();
if (resp.IsGood) {
customer.Cart.AddPayment("Google Checkout", "", "Pending");
Cart new_cart = new Cart().Save();
new_cart.UpdateCart(customer.ID);
DateTime cookexp = Request.Cookies["hdcart"].Expires;
HttpCookie cook = new HttpCookie("hdcart", new_cart.ID.ToString());
cook.Expires = cookexp;
Response.Cookies.Add(cook);
customer.Cart = new_cart;
customer.Cart.BindAddresses();
return Redirect(resp.RedirectUrl);
} else {
return RedirectToAction("Index", new { message = resp.ErrorMessage });
}
}
示例3: CompletePayPalCheckout
public ActionResult CompletePayPalCheckout(string token = "", string payerID = "") {
HttpContext ctx = System.Web.HttpContext.Current;
Customer customer = ViewBag.customer;
customer.GetFromStorage(ctx);
if (!customer.Cart.Validate()) {
return RedirectToAction("Index", "Cart");
}
if (customer.Cart.GetPaymentID() > 0) {
UDF.ExpireCart(ctx, customer.ID);
return RedirectToAction("Index", "Cart");
}
if (customer.Cart.GetStatus().statusID != (int)OrderStatuses.PaymentPending) {
UDF.ExpireCart(ctx, customer.ID);
return RedirectToAction("Index", "Cart");
};
decimal total = customer.Cart.getTotal();
Paypal p = new Paypal();
string confirmationKey = p.ECDoExpressCheckout(token, payerID, total.ToString(), customer.Cart);
if (confirmationKey == "Success") {
customer.Cart.AddPayment("PayPal", token, "Complete");
customer.Cart.SetStatus((int)OrderStatuses.PaymentComplete);
customer.Cart.SendConfirmation(ctx);
customer.Cart.SendInternalOrderEmail(ctx);
int cartid = customer.Cart.ID;
Cart new_cart = new Cart().Save();
new_cart.UpdateCart(ctx, customer.ID);
DateTime cookexp = Request.Cookies["hdcart"].Expires;
HttpCookie cook = new HttpCookie("hdcart", new_cart.ID.ToString());
cook.Expires = cookexp;
Response.Cookies.Add(cook);
customer.Cart = new_cart;
customer.Cart.BindAddresses();
return RedirectToAction("Complete", new { id = cartid });
} else {
return RedirectToAction("Index", new { message = "Your PayPal Transaction Could not be processed. Try Again." });
}
}
示例4: CompletePayPalCheckout
public ActionResult CompletePayPalCheckout(string token = "", string payerID = "")
{
Customer customer = ViewBag.customer;
customer.GetFromStorage();
if (!customer.LoggedIn()) {
return RedirectToAction("Index", "Authenticate", new { referrer = "https://" + Request.Url.Host + "/Cart/Checkout" });
}
decimal total = customer.Cart.getTotal();
Paypal p = new Paypal();
string confirmationKey = p.ECDoExpressCheckout(token, payerID, total.ToString(), customer.Cart);
if (confirmationKey == "Success") {
customer.Cart.AddPayment("PayPal", token, "Complete");
customer.Cart.SendConfirmation();
int cartid = customer.Cart.ID;
Cart new_cart = new Cart().Save();
new_cart.UpdateCart(customer.ID);
DateTime cookexp = Request.Cookies["hdcart"].Expires;
HttpCookie cook = new HttpCookie("hdcart", new_cart.ID.ToString());
cook.Expires = cookexp;
Response.Cookies.Add(cook);
customer.Cart = new_cart;
customer.Cart.BindAddresses();
EDI edi = new EDI();
edi.CreatePurchaseOrder(cartid);
return RedirectToAction("Complete", new { id = cartid });
} else {
return RedirectToAction("Index", new { message = "Your PayPal Transaction Could not be processed. Try Again." });
}
}