public string SubmitOrder(HomeViewModel model) { //submit the order to processor ChargeCreditCardClient authnetChargeClient = new ChargeCreditCardClient(); creditCardType creditCard = new creditCardType { cardNumber = model.CreditCard.CardNumber, expirationDate = String.Format("{0:00}", model.CreditCard.ExpMonth) + String.Format("{0:00}", model.CreditCard.ExpYear), cardCode = model.CreditCard.CardCode }; customerAddressType billingAddress = new customerAddressType { firstName = model.CreditCard.BillFirstName, lastName = model.CreditCard.BillLastName, address = model.CreditCard.BillStreet, city = model.CreditCard.BillCity, state = model.CreditCard.BillState, zip = model.CreditCard.BillZip }; int linecount = model.Order.Items.Count; lineItemType[] lineItems = new lineItemType[linecount + 3]; for (int i = 0; i < linecount; i++) { lineItems[i] = new lineItemType { itemId = i.ToString(), name = model.Order.Items[i].ProductName + ", " + model.Order.Items[i].ProductShortDescr, quantity = model.Order.Items[i].Quantity, unitPrice = model.Order.Items[i].UnitPrice }; } lineItems[linecount] = new lineItemType { itemId = linecount.ToString(), name = "Tax", quantity = 1m, unitPrice = model.Order.Tax }; lineItems[linecount + 1] = new lineItemType { itemId = (linecount + 1).ToString(), name = "Shipping and Handling", quantity = 1m, unitPrice = model.Order.ShipHand }; lineItems[linecount + 2] = new lineItemType { itemId = (linecount + 2).ToString(), name = "Adjustment", quantity = 1m, unitPrice = model.Order.Adjustment }; string authorizeNetApiLoginID = ConfigurationManager.AppSettings["authorizeNetApiLoginID"]; string authorizeNetApiTransactionKey = ConfigurationManager.AppSettings["authorizeNetApiTransactionKey"]; //Debug.WriteLine("If this were real, your charge would be processed HERE"); //return "HI!"; createTransactionResponse response = authnetChargeClient.RunCharge(authorizeNetApiLoginID, authorizeNetApiTransactionKey, creditCard, billingAddress, lineItems, model.Order.Total); model.ResponseCode = response.transactionResponse.responseCode; model.TransactionId = response.transactionResponse.transId; model.AuthorizationCode = response.transactionResponse.authCode; //save the order in the Db model.Order.CardLastFour = model.CreditCard.CardNumber.Substring(model.CreditCard.CardNumber.Length - 4); model.Order.TransactionId = model.TransactionId; model.Order.ResponseCode = model.ResponseCode; model.Order.AuthorizationCode = model.AuthorizationCode; repository.AddOrderAsync(model.Order, false); string subject = "New MagnoVault order"; string content = "<p>A new order was submitted:</p><p>" + model.Order.ShipFirstName + " " + model.Order.ShipLastName + "</p><p> + " + linecount + " line items totalling $" + model.Order.Total + "</p>"; SendEmail(subject, content); //return the response from the gateway return model.ResponseCode; }
public ActionResult AuthorizeNetSandbox(HomeViewModel model) { ChargeCreditCardClient authnetChargeClient = new ChargeCreditCardClient(); creditCardType creditCard = new creditCardType { cardNumber = "4111111111111111", expirationDate = "0718", cardCode = "123" }; customerAddressType billingAddress = new customerAddressType { firstName = "John", lastName = "Doe", address = "123 My St", city = "OurTown", zip = "98004" }; lineItemType[] lineItems = new lineItemType[2]; lineItems[0] = new lineItemType { itemId = "1", name = "t-shirt", quantity = 2, unitPrice = new Decimal(15.00) }; lineItems[1] = new lineItemType { itemId = "2", name = "snowboard", quantity = 1, unitPrice = new Decimal(450.00) }; createTransactionResponse response = authnetChargeClient.RunCharge(authorizeNetApiLoginID, authorizeNetApiTransactionKey, creditCard, billingAddress, lineItems, 99.75m); model.ResponseCode = response.transactionResponse.responseCode; model.TransactionId = response.transactionResponse.transId; model.AuthorizationCode = response.transactionResponse.authCode; return View(model); //RefundTransactionClient authnetRefundClient = new RefundTransactionClient(); //creditCardType creditCard = new creditCardType //{ // cardNumber = "1111", // expirationDate = "XXXX" //}; //decimal amount = 99.75m; //string transactionId = "12345"; //createTransactionResponse response = authnetRefundClient.RunRefund(authorizeNetApiLoginID, authorizeNetApiTransactionKey, creditCard, amount, transactionId); //model.ResponseCode = Int32.Parse(response.transactionResponse.responseCode); //model.TransactionId = response.transactionResponse.transId; //model.AuthorizationCode = response.transactionResponse.authCode; //return View(model); }
public async Task<ActionResult> AddOrder(HomeViewModel model) { //submit the order to processor ChargeCreditCardClient authnetChargeClient = new ChargeCreditCardClient(); creditCardType creditCard = new creditCardType { cardNumber = model.CreditCard.CardNumber, expirationDate = String.Format("{0:00}", model.CreditCard.ExpMonth) + String.Format("{0:00}", model.CreditCard.ExpYear), cardCode = model.CreditCard.CardCode }; customerAddressType billingAddress = new customerAddressType { firstName = model.CreditCard.BillFirstName, lastName = model.CreditCard.BillLastName, address = model.CreditCard.BillStreet, city = model.CreditCard.BillCity, zip = model.CreditCard.BillZip }; lineItemType[] lineItems = new lineItemType[model.EditOrder.Items.Count + 3]; for (int i = 0; i < model.EditOrder.Items.Count; i++) { lineItems[i] = new lineItemType { itemId = i.ToString(), name = model.EditOrder.Items[i].ProductName + ", " + model.EditOrder.Items[i].ProductShortDescr, quantity = model.EditOrder.Items[i].Quantity, unitPrice = model.EditOrder.Items[i].UnitPrice }; } lineItems[model.EditOrder.Items.Count] = new lineItemType { itemId = model.EditOrder.Items.Count.ToString(), name = "Tax", quantity = 1m, unitPrice = model.EditOrder.Tax }; lineItems[model.EditOrder.Items.Count + 1] = new lineItemType { itemId = (model.EditOrder.Items.Count + 1).ToString(), name = "Shipping and Handling", quantity = 1m, unitPrice = model.EditOrder.ShipHand }; lineItems[model.EditOrder.Items.Count + 2] = new lineItemType { itemId = (model.EditOrder.Items.Count + 2).ToString(), name = "Adjustment", quantity = 1m, unitPrice = model.EditOrder.Adjustment }; createTransactionResponse response = authnetChargeClient.RunCharge(authorizeNetApiLoginID, authorizeNetApiTransactionKey, creditCard, billingAddress, lineItems, model.EditOrder.Total); model.ResponseCode = response.transactionResponse.responseCode; model.TransactionId = response.transactionResponse.transId; model.AuthorizationCode = response.transactionResponse.authCode; //save the order in the Db model.EditOrder.CardLastFour = model.CreditCard.CardNumber.Substring(model.CreditCard.CardNumber.Length - 4); model.EditOrder.TransactionId = model.TransactionId; model.EditOrder.ResponseCode = model.ResponseCode; model.EditOrder.AuthorizationCode = model.AuthorizationCode; model.Orders = await repository.AddOrderAsync(model.EditOrder, true); return View("Orders", model); }