public override void ApplyCouponToOrder(Commerce.Common.Order order) { //Validate the order to make sure it's good. CouponValidationResponse validationResponse = ValidateCouponForOrder(order); if (!validationResponse.IsValid) { throw new ArgumentException("Coupon is not valid for order: " + validationResponse, "order"); } //updated by Spook, 11-5-2006 //The logic for this coupon is to apply a Percent off to the order items //this does not include shipping/tax since those items are not //first, make sure this coupon hasn't been used if (!order.CouponCodes.Contains(CouponCode)) { //calculate the discount order.DiscountAmount = CalculateDiscountAmount(order.CalculateSubTotal()); //add a comment to the order order.CouponCodes += CouponCode; //save the order order.Save("Coupon System"); } }
public override string Refund(Commerce.Common.Order order) { APIWrapper wrapper = new APIWrapper(_apiUserName, _apiPassword, _signature, _defaultCurrencyCode, _isLive); //the PayPal transactionID is stored in the auth code string transactionID = order.Transactions[0].AuthorizationCode; string sResponse = wrapper.RefundTransaction(transactionID, true); if (sResponse != "Success") { string sMessage = "PayPal has returned an error message for this refund: " + sResponse; string encResponse = System.Web.HttpContext.Current.Server.UrlEncode(sResponse); if (sMessage.ToLower(System.Globalization.CultureInfo.InvariantCulture).IndexOf("you can not refund this type of transaction (10009)") >= 0) { sMessage = "PayPal has rejected the refund of this order for one or more reasons (they don't give exact " + "reasons). If this is a DirectPay (Credit Card) transaction, PayPal will not refund an order if the card for that order is expired. If this is not a DirectPay order, " + "the order is likely too old (greater than 30 days) to be refunded.<br><br>" + "<a href='http://paypal.forums.liveworld.com/search!execute.jspa?q=" + encResponse + "' target=_blank>Find out more</a>"; } throw new Exception(sMessage); } else { //PayPal, for some reason, will not return the transactionID //this is sort of ridiculous //so return a value that means something sResponse = order.OrderNumber + "PayPal_REFUND"; } return(sResponse); }
/************************************************************ * CallCenterGetTotalBottlesOrdered() * determine total quantity ordered * get nFullMaleQty * get nDiscountMaleQty * get nFullFemaleQty * get nDiscountFemaleQty * get nFreeBottle *******************/ public void CallCenterGetTotalBottlesOrdered(Commerce.Common.Order order, out int nTotalQty, out int nFullMaleQty, out int nDiscountMaleQty, out int nFullFemaleQty, out int nDiscountFemaleQty, out bool bFreeBottle) { int nIndex = 0; bFreeBottle = false; nTotalQty = 0; nFullMaleQty = 0; nDiscountMaleQty = 0; nFullFemaleQty = 0; nDiscountFemaleQty = 0; int nItems = order.Items.Count; for (nIndex = 0; nIndex < nItems; nIndex++) { if ("LRM1" == order.Items[nIndex].Sku) { //order.Items[nIndex]; nFullMaleQty = (int)order.Items[nIndex].Quantity; dMaleUnitPrice = order.Items[nIndex].PricePaid; nTotalQty++; } if ("LRW1" == order.Items[nIndex].Sku) { nFullFemaleQty = order.Items[nIndex].Quantity; dFemaleUnitPrice = order.Items[nIndex].PricePaid; nTotalQty++; } if ("LRMCC1" == order.Items[nIndex].Sku) { nDiscountMaleQty = order.Items[nIndex].Quantity; dMaleDiscountPrice = order.Items[nIndex].PricePaid; nTotalQty++; } if ("LRWCC1" == order.Items[nIndex].Sku) { nDiscountFemaleQty = order.Items[nIndex].Quantity; dFemaleDiscountPrice = order.Items[nIndex].PricePaid; nTotalQty++; } if ("DFDF" == order.Items[nIndex].Sku) { bFreeBottle = true; nTotalQty++; } } }
protected void Page_Load(object sender, EventArgs e) { string orderGuid = Utility.GetParameter("t"); if (orderGuid != string.Empty) { order = OrderController.GetOrder(orderGuid); lblReceipt.Text = order.ToHtml(); } else { lblReceipt.Text = "<h4>Invalid Order</h4>"; } }
/// <summary> /// Runs a refund for the passed in order, and returns a verification /// string. An exception will be thrown if there is an error. /// </summary> /// <param name="order"></param> /// <returns></returns> public static string Refund(Commerce.Common.Order order) { //validations //there has to be an initial payment if (order.Transactions.Count == 0) { throw new Exception("This order has no existing transactions; please be sure the transactions are loaded for this order. Cannot refund"); } string sOut = Instance.Refund(order); return(sOut); }
void LoadOrder() { int orderID = Utility.GetIntParameter("id"); if (orderID != 0) { order = OrderController.GetOrder(orderID); gTransactions.DataSource = order.Transactions; gTransactions.DataBind(); LoadNotes(); LoadDropDowns(); lblOrderID.Text = order.OrderID.ToString(); lblOrderNumber.Text = order.OrderNumber; } }
public void GetKeyCode(Commerce.Common.Order order, out String sKey) { sKey = ""; // get OrderMotion keycode OrderNoteCollection noteCollection = order.Notes; int nCount = noteCollection.Count; if (nCount > 0) { OrderNote note = noteCollection[0]; sKey = note.Note; } else { throw new Exception("No OM Keycode provided"); } }
//************************************************************ // //GetTotalBottlesOrdered() // //************************************************************ public void GetTotalBottlesOrdered(Commerce.Common.Order order, out int nTotalQty, out int nMaleQty, out int nFemaleQty, out int nRLQty) { int nIndex = 0; nTotalQty = 0; nMaleQty = 0; nFemaleQty = 0; nRLQty = 0; // determine total qty ordered int nItems = order.Items.Count; for (nIndex = 0; nIndex < nItems; nIndex++) { if (("LRFreeMale" != order.Items[nIndex].Sku) && ("LRFreeFemale" != order.Items[nIndex].Sku)) { nTotalQty += order.Items[nIndex].Quantity; } } // determine how many male // determine how many female for (nIndex = 0; nIndex < nItems; nIndex++) { if (strMaleItemCode == order.Items[nIndex].Sku) { nMaleQty += order.Items[nIndex].Quantity; dMaleUnitPrice = order.Items[nIndex].PricePaid; } if (strFemaleItemCode == order.Items[nIndex].Sku) { nFemaleQty += order.Items[nIndex].Quantity; dFemaleUnitPrice = order.Items[nIndex].PricePaid; } if (sRLG6ItemCode == order.Items[nIndex].Sku) { nRLQty += order.Items[nIndex].Quantity; dRLG6UnitPrice = order.Items[nIndex].PricePaid; } } }
public override Commerce.Common.Transaction Charge(Commerce.Common.Order order) { //open a call to the API wrapper service APIWrapper wrapper = new APIWrapper(_apiUserName, _apiPassword, _signature, _defaultCurrencyCode, _isLive); Transaction trans = null; try { trans = wrapper.DoDirectCheckout(order, authOnly); } catch (Exception x) { //Have to catch the PayPal errors; they tend to be nonsense :). //if the URL says "localhost" in it, it's a local dev box. Don't show links to PayPal for live sites string sUrl = System.Web.HttpContext.Current.Request.UserHostAddress; bool isDev = sUrl == "127.0.0.1"; string sMessage = x.Message; if (isDev) { sMessage = "This order has been rejected; dashCommerce has detected this site running on localhost and will try to help you solve the problem"; string encResponse = System.Web.HttpContext.Current.Server.UrlEncode(x.Message.Replace("ERROR: ", "")); sMessage += "<br><b>PayPal Message: <i>" + x.Message + "</i></b><Br><Br>"; //I am sure this list will grow :). These are a catch for the lame PayPal error messages... if (x.Message.IndexOf("country and billing address associated with this credit card do not match") > 0) { sMessage += "This message usually occurs because the card you're testing with has been used too many time. Try another card (<a href='http://wiki.commercestarterkit.org/index.php?title=Test_CreditCards' target=_blank>you can use our Wiki</a>)."; } if (x.Message.ToLower().Contains("internal error")) { sMessage += "PayPal throws this nice error when it can't process a generated credit card number, or when it can't figure out what currency you're using. You can usually retry the order and it will go through; either that or try another card (<a href='http://wiki.commercestarterkit.org/index.php?title=Test_CreditCards' target=_blank>you can use our Wiki</a>)."; } sMessage += "<br><Br><b>More Info</b>: <a href='http://paypal.forums.liveworld.com/search!execute.jspa?q=" + encResponse + "' target=_blank>PayPal Forums</a><br><Br>"; } else { sMessage = "PayPal has rejected this transaction: " + x.Message + sUrl; } throw new Exception(sMessage, x); } return(trans); }
/// <summary> /// Performs basic validation based on common coupon properties /// </summary> /// <param name="order">Order to validate</param> /// <returns></returns> public virtual CouponValidationResponse ValidateCouponForOrder(Commerce.Common.Order order) { if (IsSingleUse && NumberOfUses > 0) { return(new CouponValidationResponse(false, "This coupon has already been used")); } if (ExpirationDate.HasValue) { if (ExpirationDate < DateTime.UtcNow) { return(new CouponValidationResponse(false, "This coupon has expired")); } } //TODO: how to check the current user id? return(new CouponValidationResponse(true, "")); }
public static Commerce.Common.Transaction RunCharge(Commerce.Common.Order order) { //validations //CCNumber TestCondition.IsTrue(IsValidCardType(order.CreditCardNumber, order.CreditCardType), "Invalid Credit Card Number"); //current expiration DateTime expDate = new DateTime(order.CreditCardExpireYear, order.CreditCardExpireMonth, 28); TestCondition.IsTrue(expDate >= DateTime.Today, "This credit card appears to be expired"); //amount>0 TestCondition.IsGreaterThanZero(order.OrderTotal, "Charge amount cannot be 0 or less"); Commerce.Common.Transaction result = Instance.Charge(order); result.TransactionDate = DateTime.UtcNow; result.Amount = order.OrderTotal; return(result); }
public Transaction TransactCreditCartOrder(Commerce.Common.Order order) { return(OrderController.TransactOrder(order, TransactionType.CreditCardPayment)); }
public Commerce.Common.Transaction DoExpressCheckout(Commerce.Common.Order order, bool AuthOnly) { //validate that the token is applied to the BillingAddress //same with PayerID if (String.IsNullOrEmpty(order.BillingAddress.PayPalPayerID)) { throw new Exception("No payer ID set for the BillingAddress of the order"); } if (String.IsNullOrEmpty(order.BillingAddress.PayPalToken)) { throw new Exception("No Token set for the BillingAddress of the order"); } PayPalSvc.DoExpressCheckoutPaymentReq checkoutRequest = new DoExpressCheckoutPaymentReq(); DoExpressCheckoutPaymentRequestType checkoutReqType = new DoExpressCheckoutPaymentRequestType(); DoExpressCheckoutPaymentRequestDetailsType checkoutDetails = new DoExpressCheckoutPaymentRequestDetailsType(); PaymentDetailsType paymentDetails = new PaymentDetailsType(); if (!AuthOnly) { checkoutDetails.PaymentAction = PaymentActionCodeType.Sale; } else { checkoutDetails.PaymentAction = PaymentActionCodeType.Authorization; } int roundTo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits; checkoutDetails.Token = order.BillingAddress.PayPalToken; checkoutDetails.PayerID = order.BillingAddress.PayPalPayerID; checkoutReqType.Version = PayPalServiceUtility.PayPalAPIVersionNumber; decimal dTotal = order.OrderTotal; paymentDetails.OrderTotal = GetBasicAmount(RoundIt(dTotal, roundTo)); paymentDetails.ShippingTotal = this.GetBasicAmount(RoundIt(order.ShippingAmount, roundTo)); paymentDetails.TaxTotal = this.GetBasicAmount(RoundIt(order.TaxAmount, roundTo)); paymentDetails.Custom = order.OrderNumber; paymentDetails.ItemTotal = GetBasicAmount(RoundIt(order.CalculateSubTotal(), roundTo)); //paymentDetails.OrderDescription = orderDescription; //This tells PayPal that the dashCommerce is making the call. Please leave this //as it helps us keep going :):) (not monetarily, just with some love from PayPal). paymentDetails.ButtonSource = EC_BN_ID; //load up the payment items PaymentDetailsItemType item; int itemCount = order.Items.Count; PaymentDetailsItemType[] items = new PaymentDetailsItemType[itemCount]; for (int i = 0; i < itemCount; i++) { item = new PaymentDetailsItemType(); item.Name = order.Items[i].ProductName; item.Number = order.Items[i].Sku; item.Quantity = order.Items[i].Quantity.ToString(); item.Amount = GetBasicAmount(RoundIt(order.Items[i].PricePaid, roundTo)); items[i] = item; } paymentDetails.PaymentDetailsItem = items; checkoutRequest.DoExpressCheckoutPaymentRequest = checkoutReqType; checkoutRequest.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails = checkoutDetails; checkoutRequest.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails = paymentDetails; PayPalSvc.DoExpressCheckoutPaymentResponseType response = service2.DoExpressCheckoutPayment(checkoutRequest); string errors = this.CheckErrors(response); string sOut = ""; Commerce.Common.Transaction trans = new Commerce.Common.Transaction(); if (errors == string.Empty) { trans.GatewayResponse = response.Ack.ToString(); trans.AuthorizationCode = response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.TransactionID; } else { trans.GatewayResponse = errors; } //return out the transactionID return(trans); }
//************************************************************ // // OrderMotion // //************************************************************ public void OrderMotion(Commerce.Common.Order order, String strAuthCode, int nTransID) { int nTotalQty = 0, nIndex = 0, nFreeBottles = 0, nFreeMale = 0, nFreeFemale = 0; int nMaleQty = 0, nFemaleQty = 0; String strKeycode = ""; // get OrderMotion keycode GetKeyCode(order, out strKeycode); /******************************************** * determine total quantity ordered. dont count the free bottles, if this is CCtr order. * determine how many male * determine how many female * GetTotalBottlesOrdered( out nTotalQty, out nMaleQty, out nFemaleQty ) * * determine how many free bottles to send * determine how many male or female bottles to send * (if CCtr order, the free bottles are already in 'order' object. so set variables accordingly) * * GetFreeBottleQty( int nTotalQty, out int nFreeBottles, out int nFreeMale, out int nFreeFemale ) ********************************************/ GetTotalBottlesOrdered(order, out nTotalQty, out nMaleQty, out nFemaleQty); GetFreeBottleQty(order, nTotalQty, nMaleQty, nFemaleQty, out nFreeBottles, out nFreeMale, out nFreeFemale); //********************************* // generate OrderDetails line items //********************************* // determine total # of line items int nLineItems = 0; if (nMaleQty > 0) { nLineItems++; } if (nFemaleQty > 0) { nLineItems++; } if (nFreeFemale > 0) { nLineItems++; } if (nFreeMale > 0) { nLineItems++; } // END determine total # of line items // Populate XML file String strPost = ""; strPost = "<?xml version=\"1.0\"?>" + "<UDOARequest version=\"2.00\">" + "<UDIParameter>" + "<Parameter key=\"HTTPBizID\">" + "jRfJIJtOgVGWQpJNyPVJhqvwNndjkjkTNuVXUhlScTEueBSeLvaFgjVVgSjQuuBQuPHhgKBYcQTnmEMhfFhwkaJAmExnCdhrvrVolebsqlQqtxmMhPfiDXMFieRpojHVYOgjNHUwgPUpeltQwAUdGQZwdgwLqNkFbxuhneNuiVuhIggLFpEybMjqfLRfoKQQiiAyENJDdbXiaKeOHPJXFNADyQnBVcfOYgMOjvAfXYNKYqjhKrDhRVIrmQnCLil" + "</Parameter>" + "<Parameter key=\"Keycode\">" + strKeycode + "</Parameter>" + "<Parameter key=\"VerifyFlag\">False</Parameter>" + "<Parameter key=\"QueueFlag\">True</Parameter>" + "</UDIParameter>" + "<Header>" + // OrderDate should be in form "CCYY-MM-DD hh:mm" // It isn't necessary so to start I'll leave it out. //"<OrderDate>2003-04-01 22:15:10</OrderDate>" + "<OriginType>3</OriginType>" + "<OrderID>" + order.OrderNumber + "</OrderID>" + "<StoreCode/>" + "</Header>" + "<Customer>" + "<Address type=\"BillTo\">" + "<TitleCode>0</TitleCode>" + "<Company/>" + "<Firstname>" + order.BillingAddress.FirstName + "</Firstname>" + "<Lastname>" + order.BillingAddress.LastName + "</Lastname>" + "<Address1>" + order.BillingAddress.Address1 + "</Address1>" + "<Address2>" + order.BillingAddress.Address2 + "</Address2>" + "<City>" + order.BillingAddress.City + "</City>" + "<State>" + order.BillingAddress.StateOrRegion + "</State>" + "<ZIP>" + order.BillingAddress.Zip + "</ZIP>" + "<TLD>" + order.BillingAddress.Country + "</TLD>" + "<PhoneNumber/>" + "<Email>" + order.BillingAddress.Email + "</Email>" + "</Address>" + "<FlagData>" + "<Flag name=\"DoNotMail\">True</Flag>" + "<Flag name=\"DoNotCall\">True</Flag>" + "<Flag name=\"DoNotEmail\">True</Flag>" + "</FlagData>" + "</Customer>" + "<ShippingInformation>" + "<Address type=\"ShipTo\">" + "<TitleCode>0</TitleCode>" + "<Firstname>" + order.ShippingAddress.FirstName + "</Firstname>" + "<Lastname>" + order.ShippingAddress.LastName + "</Lastname>" + "<Address1>" + order.ShippingAddress.Address1 + "</Address1>" + "<Address2>" + order.ShippingAddress.Address2 + "</Address2>" + "<City>" + order.ShippingAddress.City + "</City>" + "<State>" + order.ShippingAddress.StateOrRegion + "</State>" + "<ZIP>" + order.ShippingAddress.Zip + "</ZIP>" + "<TLD>" + order.ShippingAddress.Country + "</TLD>" + "</Address>" + //"<MethodName> + "1st Class US Mail" + "</MethodName>" + "<MethodCode>2</MethodCode>" + "<ShippingAmount>" + order.ShippingAmount + "</ShippingAmount>" + "<HandlingAmount>0.0</HandlingAmount>" + "<SpecialInstructions>" + order.SpecialInstructions + "</SpecialInstructions>" + "</ShippingInformation>" + "<Payment type=\"1\">" + "<CardNumber>" + order.CreditCardNumber + "</CardNumber>" + "<CardVerification>" + order.CreditCardSecurityNumber + "</CardVerification>" + "<CardExpDateMonth>" + order.CreditCardExpireMonth + "</CardExpDateMonth>" + "<CardExpDateYear>" + order.CreditCardExpireYear + "</CardExpDateYear>" + // CardStatus 11 means 'already authorized'. "<CardStatus>11</CardStatus>" + "<CardAuthCode>" + strAuthCode + "</CardAuthCode>" + //"<CardTransactionID>" + strTransID + "</CardTransactionID>" + "</Payment>"; //********************** // Orderdetail goes here //********************** String strOrderDetail = "<OrderDetail>"; nIndex = 1; if (nMaleQty > 0) { strOrderDetail += "<LineItem lineNumber=\"" + nIndex + "\">" + "<ItemCode>" + strMaleItemCode + "</ItemCode>" + "<Quantity>" + nMaleQty + "</Quantity>" + "<UnitPrice>" + dMaleUnitPrice + "</UnitPrice>" + "</LineItem>"; nIndex++; } // Generate free Male line items if (nFreeMale > 0) { strOrderDetail += "<LineItem lineNumber=\"" + nIndex + "\">" + "<ItemCode>" + strMaleItemCode + "</ItemCode>" + "<Quantity>" + nFreeMale + "</Quantity>" + "<UnitPrice>0.0</UnitPrice>" + "</LineItem>"; nIndex++; } // generate Female line items if (nFemaleQty > 0) { strOrderDetail += "<LineItem lineNumber=\"" + nIndex + "\">" + "<ItemCode>" + strFemaleItemCode + "</ItemCode>" + "<Quantity>" + nFemaleQty + "</Quantity>" + "<UnitPrice>" + dFemaleUnitPrice + "</UnitPrice>" + "</LineItem>"; nIndex++; } // generate free Female line items if (nFreeFemale > 0) { strOrderDetail += "<LineItem lineNumber=\"" + nIndex + "\">" + "<ItemCode>" + strFemaleItemCode + "</ItemCode>" + "<Quantity>" + nFreeFemale + "</Quantity>" + "<UnitPrice>0.0</UnitPrice>" + "</LineItem>"; } strOrderDetail += "</OrderDetail>"; strOrderDetail += "<Check><TotalAmount>" + order.OrderTotal + "</TotalAmount></Check>"; strPost += strOrderDetail + "</UDOARequest>"; //******************************************** // Post to OrderMotion //******************************************** StreamWriter myWriter = null; String strOMServerURL = "https://members.ordermotion.com/hdde/xml/udi.asp"; HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(strOMServerURL); objRequest.Method = "POST"; objRequest.ContentLength = strPost.Length; objRequest.ContentType = "text/xml"; try { myWriter = new StreamWriter(objRequest.GetRequestStream()); myWriter.Write(strPost); } catch (Exception e) { LovRubLogger.LogException(e); // KPL 04/05/08 throw e; } finally { myWriter.Close(); } Commerce.Common.Transaction trans = new Commerce.Common.Transaction(); HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse(); try { XmlReader reader = XmlReader.Create((Stream)objResponse.GetResponseStream()); reader.MoveToContent(); while (reader.Read()) { if (XmlNodeType.Element == reader.NodeType) { if (reader.Name.Equals("Success")) { reader.Read(); if (false == reader.Value.Equals("1")) { // failure; throw new Exception("OM Failure:<Success>= " + reader.Value); } } if (reader.Name.Equals("ErrorData")) { reader.Read(); if (false == reader.Value.Equals("\n")) { // failure; throw new Exception("OM Failure:<ErrorData>= " + reader.Value); } } } } } catch (Exception e) { LovRubLogger.LogException(e); // KPL 04/05/08 throw e; } }
public Commerce.Common.Transaction DoDirectCheckout(Commerce.Common.Order order, bool AuthOnly) { PayPalSvc.DoDirectPaymentReq req = new DoDirectPaymentReq(); req.DoDirectPaymentRequest = new DoDirectPaymentRequestType(); req.DoDirectPaymentRequest.Version = PayPalServiceUtility.PayPalAPIVersionNumber; DoDirectPaymentRequestDetailsType details = new DoDirectPaymentRequestDetailsType(); details.CreditCard = new CreditCardDetailsType(); details.CreditCard.CardOwner = new PayerInfoType(); details.CreditCard.CardOwner.Address = new AddressType(); details.CreditCard.CardOwner.PayerName = new PersonNameType(); details.PaymentDetails = new PaymentDetailsType(); CountryCodeType payerCountry = CountryCodeType.US; if (order.BillingAddress.Country != "US") { try { payerCountry = (CountryCodeType)StringToEnum(typeof(CountryCodeType), order.BillingAddress.Country); } catch { } } details.CreditCard.CardOwner.Address.Country = payerCountry; details.CreditCard.CardOwner.PayerCountry = payerCountry; details.CreditCard.CardOwner.Address.CountrySpecified = true; details.CreditCard.CardOwner.Address.Street1 = order.BillingAddress.Address1; details.CreditCard.CardOwner.Address.Street2 = order.BillingAddress.Address2; details.CreditCard.CardOwner.Address.CityName = order.BillingAddress.City; details.CreditCard.CardOwner.Address.StateOrProvince = order.BillingAddress.StateOrRegion; details.CreditCard.CardOwner.Address.PostalCode = order.BillingAddress.Zip; details.CreditCard.CardOwner.PayerName.FirstName = order.BillingAddress.FirstName; details.CreditCard.CardOwner.PayerName.LastName = order.BillingAddress.LastName; //the basics int roundTo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits; decimal dTotal = Math.Round(order.CalculateSubTotal(), roundTo) + Math.Round(order.TaxAmount, roundTo) + Math.Round(order.ShippingAmount, roundTo); details.PaymentDetails.OrderTotal = GetBasicAmount(dTotal); details.PaymentDetails.ShippingTotal = this.GetBasicAmount(Math.Round(order.ShippingAmount, roundTo)); details.PaymentDetails.TaxTotal = this.GetBasicAmount(Math.Round(order.TaxAmount, roundTo)); details.PaymentDetails.Custom = order.OrderNumber; details.PaymentDetails.ItemTotal = GetBasicAmount(Math.Round(order.CalculateSubTotal(), roundTo)); details.PaymentDetails.ButtonSource = DP_BN_ID; //credit card details.CreditCard.CreditCardNumber = order.CreditCardNumber; CreditCardTypeType ccType = CreditCardTypeType.Visa; switch (order.CreditCardType) { case Commerce.Common.CreditCardType.MasterCard: ccType = CreditCardTypeType.MasterCard; break; case Commerce.Common.CreditCardType.Amex: ccType = CreditCardTypeType.Amex; break; } details.CreditCard.CreditCardType = ccType; details.CreditCard.ExpMonth = Convert.ToInt16(order.CreditCardExpireMonth); details.CreditCard.ExpYear = Convert.ToInt16(order.CreditCardExpireYear); details.CreditCard.CVV2 = order.CreditCardSecurityNumber; //set the IP - required details.IPAddress = order.UserIP; //set the req var to details req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details; //sale type if (AuthOnly) { details.PaymentAction = PaymentActionCodeType.Authorization; } else { details.PaymentAction = PaymentActionCodeType.Sale; } //send the request DoDirectPaymentResponseType response = service2.DoDirectPayment(req); string errors = this.CheckErrors(response); Commerce.Common.Transaction trans = new Commerce.Common.Transaction(); trans.OrderID = order.OrderID; string sOut = ""; if (errors == string.Empty) { trans.GatewayResponse = response.Ack.ToString(); trans.AuthorizationCode = response.TransactionID; trans.CVV2Code = response.CVV2Code; } else { trans.GatewayResponse = errors; throw new Exception(errors); } return(trans); }
//************************************************************ // // GetFreeBottleQty // //************************************************************ public void GetFreeBottleQty(Commerce.Common.Order order, int nTotalQty, int nMaleQty, int nFemaleQty, out int nFreeBottles, out int nFreeMale, out int nFreeFemale) { nFreeFemale = 0; nFreeMale = 0; nFreeBottles = 0; String strKeycode = ""; GetKeyCode(order, out strKeycode); if (strKeycode.Equals("")) { throw new Exception("Empty OM Keycode value"); } if (strKeycode.Equals("CALLCENTER")) //if ("CALLCENTER" == order.SpecialInstructions) { // count the # of free items in cart: nFreeBottles // determine total qty ordered // count the # of free male items in cart: nFreeMale // count the # of free female items in cart: nFreeFemale int nIndex = 0; int nItems = order.Items.Count; for (nIndex = 0; nIndex < nItems; nIndex++) { if (("LRFreeMale" == order.Items[nIndex].Sku)) { nFreeMale++; nFreeBottles++; } if (("LRFreeFemale" == order.Items[nIndex].Sku)) { nFreeFemale++; nFreeBottles++; } } return; } // determine how many free bottles to send if (nTotalQty < 3) { nFreeBottles = 0; } else { nFreeBottles = (nTotalQty / 3); } // determine whether free s/b M or F if (1 == nFreeBottles) { // if all ordered were male then free one s/b male if (nMaleQty == nTotalQty) { nFreeMale = 1; } // if all ordered were female then free one s/b female if (nFemaleQty == nTotalQty) { nFreeFemale = 1; } // if male was ordered more than female, send male. if (nMaleQty > nFemaleQty) { nFreeMale = 1; } else { // if female was ordered more than male, send female. nFreeFemale = 1; } } if (2 == nFreeBottles) { // if all ordered were equally male and female, then all s/b split if (nMaleQty == nFemaleQty) { nFreeMale = 1; nFreeFemale = 1; } // if all ordered were male, then all free s/b male if (nMaleQty == nTotalQty) { nFreeMale = nFreeBottles; } // if all ordered were female, then all free s/b female if (nFemaleQty == nTotalQty) { nFreeFemale = nFreeBottles; } // if order was mix, the split the freebies if (nMaleQty != nFemaleQty) { nFreeMale = 1; nFreeFemale = 1; } } if (3 == nFreeBottles) { // if all ordered were male, then all free s/b male if (nMaleQty == nTotalQty) { nFreeMale = nFreeBottles; } // if all ordered were female, then all free s/b female if (nFemaleQty == nTotalQty) { nFreeFemale = nFreeBottles; } // if order was mix, the split the freebies if ((nMaleQty > nFemaleQty) && (nFemaleQty != 0)) { nFreeMale = 2; nFreeFemale = 1; } if ((nFemaleQty > nMaleQty) && (nMaleQty != 0)) { nFreeMale = 1; nFreeFemale = 2; } } // keep it simple here. if (4 == nFreeBottles) { nFreeMale = 2; nFreeFemale = 2; } }
public override Commerce.Common.Transaction Charge(Commerce.Common.Order order) { //string sOut = ""; decimal dTotal = order.OrderTotal; int roundTo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits; dTotal = Math.Round(dTotal, roundTo); //make sure that the ExpMonth has a leading 0 string sExpMonth = order.CreditCardExpireMonth.ToString(); if (order.CreditCardExpireMonth < 10) { sExpMonth = "0" + sExpMonth; } bool useTestServer = serverURL.IndexOf("test") >= 0; String strPost = "x_login="******"&x_tran_key=" + transactionKey + "&x_method=CC" + //"&x_type=AUTH_CAPTURE" + KPL commented out 12/30/07 "&x_type=AUTH_ONLY" + // KPL Added 12/30/07 "&x_amount=" + dTotal.ToString() + "&x_delim_data=TRUE" + "&x_delim_char=|" + "&x_relay_response=FALSE" + "&x_card_num=" + order.CreditCardNumber + "&x_exp_date=" + sExpMonth + order.CreditCardExpireYear.ToString() + "&x_version=3.1" + //the following is optional however it's good to have for records "&x_first_name=" + order.BillingAddress.FirstName + "&x_last_name=" + order.BillingAddress.LastName + "&x_address=" + order.BillingAddress.Address1 + "&x_city=" + order.BillingAddress.City + "&x_state=" + order.BillingAddress.StateOrRegion + "&x_zip=" + order.BillingAddress.Zip + "&x_currency_code=" + currencyCode + "&x_country=" + order.BillingAddress.Country + "&x_card_code=" + order.CreditCardSecurityNumber; //you can set this up to send you an email if you like //by adding this: //&[email protected] //you can also have them send you customer an email //&[email protected]&x_email_customer=TRUE if (useTestServer) { strPost += "&x_test_request=TRUE"; } //******************************************************* // Post to AUTHORIZE.NET and get response. //******************************************************* Commerce.Common.Transaction trans = new Commerce.Common.Transaction(); WebClient wc = new WebClient(); try { byte[] response = wc.UploadData(serverURL, System.Text.ASCIIEncoding.UTF8.GetBytes(strPost)); String result = System.Text.ASCIIEncoding.UTF8.GetString(response); string[] lines = result.Split('|'); //the response flag is the first item //1=success, 2=declined, 3=error string sFlag = lines[0]; if (sFlag == "1") { trans.GatewayResponse = lines[37]; trans.AuthorizationCode = lines[4]; //return the transactionID trans.GatewayResponse = result; } else if (sFlag == "2") { trans.GatewayResponse = lines[3]; throw new Exception("Declined: " + lines[3]); } else { trans.GatewayResponse = lines[3]; throw new Exception("Error: " + lines[3]); } } catch (Exception e) { LovRubLogger.LogException(e, strPost); // KPL 04/05/08 throw e; } // Call OrderMotion to submit order to them. string strKeycode = ""; GetKeyCode(order, out strKeycode); /*************** Commented out for new price change KPL 09/20/08 * if (strKeycode.Equals("CALLCENTER") ) // Added for new CallCenter KPL 06/06/08 * CallCenterOrderMotion(order, trans.AuthorizationCode, trans.TransactionID); * else * OrderMotion(order, trans.AuthorizationCode, trans.TransactionID); ****************/ CallCenterOrderMotion(order, trans.AuthorizationCode, trans.TransactionID); return(trans); }
/// <summary> /// Applies a coupon to an order /// </summary> /// <param name="order">Order to apply the coupon to</param> public abstract void ApplyCouponToOrder(Commerce.Common.Order order);
public override string Refund(Commerce.Common.Order order) { throw new Exception("This method not enabled for Authorize.NET"); }
/************************************************************ * CallCenterGetTotalBottlesOrdered() * determine total quantity ordered * get nFullMaleQty * get nDiscountMaleQty * get nFullFemaleQty * get nDiscountFemaleQty * get nFreeBottle *******************/ public void CallCenterGetTotalBottlesOrdered(Commerce.Common.Order order, out int nTotalQty, out int nFullMaleQty, out int nDiscountMaleQty, out int nFullFemaleQty, out int nDiscountFemaleQty, out int nRL6FullQty, out int nRLG6DiscountQty, out int nHHValQty, out int nFemaleValQty, out int nMaleValQty, out int nFreeQty, out int nLipLovFullQty, out int nLipLovDiscountQty, out int nSurvivalFullQty) { int nIndex = 0; nFreeQty = 0; nTotalQty = 0; nFullMaleQty = 0; nDiscountMaleQty = 0; nFullFemaleQty = 0; nDiscountFemaleQty = 0; nRL6FullQty = 0; nRLG6DiscountQty = 0; nFemaleValQty = nMaleValQty = 0; nHHValQty = 0; nLipLovFullQty = 0; nLipLovDiscountQty = 0; nSurvivalFullQty = 0; int nItems = order.Items.Count; for (nIndex = 0; nIndex < nItems; nIndex++) { if ("LRM1" == order.Items[nIndex].Sku) { nFullMaleQty = (int)order.Items[nIndex].Quantity; dMaleUnitPrice = order.Items[nIndex].PricePaid; } if ("LRSURV" == order.Items[nIndex].Sku) { nSurvivalFullQty = (int)order.Items[nIndex].Quantity; dSurvivalUnitPrice = order.Items[nIndex].PricePaid; } if ("LRW1" == order.Items[nIndex].Sku) { nFullFemaleQty = order.Items[nIndex].Quantity; dFemaleUnitPrice = order.Items[nIndex].PricePaid; } if ("RLG6" == order.Items[nIndex].Sku) { nRL6FullQty = order.Items[nIndex].Quantity; dRLG6UnitPrice = order.Items[nIndex].PricePaid; } if ("LRLL" == order.Items[nIndex].Sku) { nLipLovFullQty = order.Items[nIndex].Quantity; dLipLovUnitPrice = order.Items[nIndex].PricePaid; } if ("RLG6CC1" == order.Items[nIndex].Sku) { nRLG6DiscountQty = order.Items[nIndex].Quantity; dRLG6DiscountPrice = order.Items[nIndex].PricePaid; } if ("LRMCC1" == order.Items[nIndex].Sku) { nDiscountMaleQty = order.Items[nIndex].Quantity; dMaleDiscountPrice = order.Items[nIndex].PricePaid; } if ("LRWCC1" == order.Items[nIndex].Sku) { nDiscountFemaleQty = order.Items[nIndex].Quantity; dFemaleDiscountPrice = order.Items[nIndex].PricePaid; } if ("LRLLCC1" == order.Items[nIndex].Sku) { nLipLovDiscountQty = order.Items[nIndex].Quantity; dLipLovDiscountPrice = order.Items[nIndex].PricePaid; } if ("DFDF" == order.Items[nIndex].Sku) { nFreeQty = order.Items[nIndex].Quantity; } // Valentine's Day Gifts if (("LRHHVAL" == order.Items[nIndex].Sku)) { nHHValQty += order.Items[nIndex].Quantity; dValentinePrice = order.Items[nIndex].PricePaid; } if (("LRFEMALEVAL" == order.Items[nIndex].Sku)) { nFemaleValQty += order.Items[nIndex].Quantity; dValentinePrice = order.Items[nIndex].PricePaid; } if (("LRMALEVAL" == order.Items[nIndex].Sku)) { nMaleValQty += order.Items[nIndex].Quantity; dValentinePrice = order.Items[nIndex].PricePaid; } } nTotalQty = nFullMaleQty + nDiscountMaleQty + nFullFemaleQty + nDiscountFemaleQty + nRL6FullQty + nRLG6DiscountQty + nHHValQty + nMaleValQty + nFemaleValQty + nFreeQty + nLipLovFullQty + nLipLovDiscountQty; }