Example #1
0
        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);
        }
Example #2
0
        //************************************************************
        //
        // 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;
            }
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }