示例#1
0
 private static bool HasValue(AccountDataDictionary data, string varName)
 {
     return(data.ContainsKey(varName) && !string.IsNullOrEmpty(data[varName]));
 }
        private string InitializeAuthRecurringRequest(AuthorizeRecurringTransactionRequest authRequest, string payPeriod, Dictionary <string, string> sensitiveData)
        {
            Payment payment = authRequest.Payment;
            Order   order   = payment.Order;
            User    user    = order.User;

            XmlDocument xmlRequest = new XmlDocument();

            xmlRequest.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TranxRequest />");

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "MerchantNumber", MerchantNumber);

            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);

            /*string sCurrencyCode = payment.CurrencyCode;
             * if (!("USD".Equals(sCurrencyCode)))
             * {
             *  sCurrencyCode = "CAD";
             * }*/
            string sCurrencyCode = "CAD";

            if (IsUSD)
            {
                sCurrencyCode = "USD";
            }

            string    recurrFlag    = "{RB ";
            LSDecimal recurAmount   = authRequest.RecurringChargeSpecified ? authRequest.RecurringCharge : authRequest.Amount;
            string    startDtString = GetNextPaymentDateStr(authRequest);
            string    duration      = ((int)(authRequest.NumberOfPayments - 1)).ToString();

            recurrFlag += recurAmount.ToString("F2") + " " + startDtString + " " + payPeriod + " " + duration + " email=2}";

            string ccFlag   = "{" + sCurrencyCode + "}";
            string testFlag = (UseTestMode ? "{TEST}" : "");

            string sFlags       = ccFlag + testFlag + recurrFlag;
            string sDescription = authRequest.SubscriptionName; //order.Notes;
            string sAmount      = String.Format("{0:F2}", authRequest.Amount);

            string pline;

            System.Collections.Generic.List <string> arrProducts = new System.Collections.Generic.List <string>();
            if (IncludeOrderItems)
            {
                OrderItemCollection orderItems = order.Items;
                if (orderItems != null && orderItems.Count > 0)
                {
                    foreach (OrderItem orderItem in orderItems)
                    {
                        if (orderItem.OrderItemType == OrderItemType.Product)
                        {
                            pline = "0.00::" + orderItem.Quantity + "::" + MakeSafe(orderItem.Sku, 30) + "::" + MakeSafe(orderItem.Name, 150) + "::" + sFlags;
                            arrProducts.Add(pline);
                        }
                    }
                }
            }

            pline = sAmount + "::1::" + order.OrderNumber + "::" + sDescription + "::" + sFlags;
            arrProducts.Add(pline);

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "Products", string.Join("|", (string[])arrProducts.ToArray()));
            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxName", accountData["AccountName"]);
            }
            else
            {
                XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxName", order.BillToFirstName + " " + order.BillToLastName);
            }

            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCompany", order.BillToCompany);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxAddress", order.BillToAddress1);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCity", order.BillToCity);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxProvince", order.BillToProvince);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxPostal", order.BillToPostalCode);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxCountry", order.BillToCountryCode);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxPhone", order.BillToPhone);
            XmlUtility.SetElementValue(xmlRequest.DocumentElement, "xxxEmail", order.BillToEmail);


            SetupCreditCardData(xmlRequest, payment, accountData, sensitiveData);

            StringBuilder formData = new StringBuilder();

            formData.Append("xxxRequestMode=X&xxxRequestData=" + HttpUtility.UrlEncode(XmlToString(xmlRequest)));

            return(formData.ToString());
        }
        private RecurringRequest InitializeAuthRecurringRequest(AuthorizeRecurringTransactionRequest authRequest, int payPeriod)
        {
            VerifyPaymentInstrument(authRequest.Payment);
            RecurringRequest request = new RecurringRequest();

            Payment payment = authRequest.Payment;
            Order   order   = payment.Order;
            User    user    = payment.Order.User;
            //Address address = user.PrimaryAddress;

            //credit card data
            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
            string accountNumber   = accountData.GetValue("AccountNumber");
            string expirationMonth = accountData.GetValue("ExpirationMonth");

            if (expirationMonth.Length == 1)
            {
                expirationMonth.Insert(0, "0");
            }
            string expirationYear = accountData.GetValue("ExpirationYear");

            request.setCommand(RecurringRequest.COMMAND_ADD_CUSTOMER_ACCOUNT_AND_RECURRENCE);
            request.setAccountType(RecurringRequest.ACCOUNT_TYPE_CREDIT_CARD);
            request.setCreditCardNumber(accountNumber);
            request.setExpireMonth(expirationMonth);
            request.setExpireYear(expirationYear);

            request.setBillingAddress(order.BillToAddress1 + ", " + order.BillToAddress2 + "," + order.BillToCity);
            request.setZipOrPostalCode(order.BillToPostalCode);
            request.setCountryCode(order.BillToCountryCode);

            LSDecimal amount = authRequest.RecurringChargeSpecified ? authRequest.RecurringCharge : authRequest.Amount;

            request.setChargeTotal((double)amount);

            request.setCustomerId(user.UserId.ToString());
            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                request.setCustomerName(accountData["AccountName"]);
            }
            else
            {
                request.setCustomerName(order.BillToFirstName + " " + order.BillToLastName);
            }
            request.setDescription(authRequest.SubscriptionName);

            string strEmail = string.IsNullOrEmpty(order.BillToEmail) ? user.Email : order.BillToEmail;

            request.setEmailAddress(user.Email);

            request.setNotifyCustomer(true);
            request.setNumberOfRetries(3);
            request.setRecurrenceId(authRequest.Payment.OrderId.ToString());
            request.setPeriod(payPeriod);

            DateTime startDt = LocaleHelper.LocalNow;

            if (authRequest.RecurringChargeSpecified)
            {
                startDt = GetNextPaymentDate(payPeriod);
            }
            request.setStartDay(startDt.Day);
            request.setStartMonth(startDt.Month);
            request.setStartYear(startDt.Year);

            DateTime endDt = GetEndDate(startDt, payPeriod, authRequest.NumberOfPayments);

            request.setEndDay(endDt.Day);
            request.setEndMonth(endDt.Month);
            request.setEndYear(endDt.Year);

            return(request);
        }
        private CreditCardRequest InitializeAuthRequest(AuthorizeTransactionRequest authorizeRequest)
        {
            Payment payment = authorizeRequest.Payment;
            Order   order   = payment.Order;
            User    user    = order.User;

            VerifyPaymentInstrument(payment);
            CreditCardRequest request = new CreditCardRequest();

            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);

            //set user info
            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                string[] names = accountData["AccountName"].Split(" ".ToCharArray());
                request.setBillFirstName(names[0]);
                if (names.Length > 1)
                {
                    request.setBillLastName(string.Join(" ", names, 1, names.Length - 1));
                }
                else
                {
                    //no last name. what to do? send empty string? TODO : check the API
                    request.setBillLastName(string.Empty);
                }
            }
            else
            {
                request.setBillFirstName(order.BillToFirstName);
                request.setBillLastName(order.BillToLastName);
            }

            request.setBillEmail(order.BillToEmail);
            request.setBillCompany(order.BillToCompany);
            request.setBillAddressOne(order.BillToAddress1);
            request.setBillAddressTwo(order.BillToAddress2);
            request.setBillCity(order.BillToCity);
            request.setBillStateOrProvince(order.BillToProvince);
            request.setBillPostalCode(order.BillToPostalCode);
            request.setBillCountryCode(order.BillToCountryCode);
            request.setBillPhone(order.BillToPhone);
            request.setBillFax(order.BillToFax);
            request.setOrderUserId(user.UserId.ToString());

            SetCreditCardData(request, payment, accountData);

            // set charge details
            if (this.UseAuthCapture)
            {
                request.setChargeType(CreditCardRequest.SALE);
            }
            else
            {
                request.setChargeType(CreditCardRequest.AUTH);
            }
            request.setChargeTotal((double)authorizeRequest.Amount);
            //TODO set tax and shipping
            //request.setTaxAmount();
            //request.setShippingCharge();
            if (!string.IsNullOrEmpty(payment.CurrencyCode))
            {
                request.setCurrency(payment.CurrencyCode);
            }

            request.setOrderId(order.OrderId.ToString());
            request.setInvoiceNumber(order.OrderNumber.ToString());
            //TODO add description if present
            //if(!string.IsNullOrEmpty(order.Notes)) {
            //    request.setOrderDescription(order.Notes);
            //}

            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                request.setCustomerIpAddress(context.Request.ServerVariables["REMOTE_HOST"]);
            }

            return(request);
        }
示例#5
0
        private string InitializeAuthRecurringRequest(AuthorizeRecurringTransactionRequest authRequest, Dictionary <string, string> sensitiveData)
        {
            Payment payment = authRequest.Payment;
            User    user    = payment.Order.User;
            Order   order   = payment.Order;

            VerifyPaymentInstrument(payment);
            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
            string accountNumber   = accountData.GetValue("AccountNumber");
            string expirationMonth = accountData.GetValue("ExpirationMonth");
            string expirationYear  = accountData.GetValue("ExpirationYear");

            if (expirationMonth.Length == 1)
            {
                expirationMonth = "0" + expirationMonth;
            }
            if (expirationYear.Length > 2)
            {
                expirationYear = expirationYear.Substring(expirationYear.Length - 2);
            }
            string expireDate   = expirationMonth + expirationYear;
            string amount       = String.Format("{0:F2}", authRequest.RecurringChargeSpecified? authRequest.RecurringCharge : authRequest.Amount);
            string securityCode = accountData.GetValue("SecurityCode");

            //authentication data
            string data = "dc_logon=" + HttpUtility.UrlEncode(this.LoginName, System.Text.Encoding.UTF8);

            data += Encode("dc_password", this.Password);
            if (this.UseDebugMode)
            {
                sensitiveData[this.Password] = "xxxxxxxx";
            }

            //address data
            data += Encode("dc_address", order.BillToAddress1 + " " + order.BillToAddress2);
            data += Encode("dc_city", order.BillToCity);
            data += Encode("dc_zip", order.BillToPostalCode);
            data += Encode("dc_country", order.BillToCountryCode);

            //transaction data
            data += Encode("dc_transaction_type", "AUTHORIZATION_CAPTURE");
            data += Encode("dc_transaction_amount", amount);
            data += Encode("dc_version", "1.2");

            //cc data
            string fullName;

            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                fullName = accountData["AccountName"];
            }
            else
            {
                fullName = order.BillToFirstName + " " + order.BillToLastName;
            }
            data += Encode("dc_name", fullName);
            data += Encode("dc_number", accountNumber);
            if (this.UseDebugMode)
            {
                sensitiveData[accountNumber] = MakeReferenceNumber(accountNumber);
            }
            data += Encode("dc_expiration_month", expirationMonth);
            data += Encode("dc_expiration_year", expirationYear);

            if (!string.IsNullOrEmpty(securityCode))
            {
                data += Encode("dc_verification_number", securityCode);
                if (this.UseDebugMode)
                {
                    sensitiveData["dc_verification_number=" + securityCode] = "dc_verification_number=" + (new string('x', securityCode.Length));
                }
            }

            //schedule data
            data += Encode("dc_schedule_create", "true");
            int remainingPayments = authRequest.NumberOfPayments;

            if (authRequest.RecurringChargeSpecified)
            {
                remainingPayments -= 1;
            }
            data += Encode("dc_schedule_limit", remainingPayments.ToString());
            if (authRequest.PaymentFrequencyUnit == CommerceBuilder.Products.PaymentFrequencyUnit.Day)
            {
                data += Encode("dc_schedule_periodic_type", "day");
            }
            else
            {
                data += Encode("dc_schedule_periodic_type", "month");
            }
            data += Encode("dc_schedule_periodic_number", authRequest.PaymentFrequency.ToString());

            DateTime startDt = GetNextPaymentDate(authRequest);

            data += Encode("dc_schedule_start", startDt.ToString("yyyy-MM-dd"));

            return(data);
        }
示例#6
0
        private string InitializeRefundRequest(Payment payment, RefundTransactionRequest refundRequest, Transaction authorizeTransaction, LSDecimal dAmount, Dictionary <string, string> sensitiveData)
        {
            Order order = payment.Order;
            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
            string accountNumber   = refundRequest.CardNumber;
            string expirationMonth = refundRequest.ExpirationMonth.ToString();
            string expirationYear  = refundRequest.ExpirationYear.ToString();

            if (expirationMonth.Length == 1)
            {
                expirationMonth = "0" + expirationMonth;
            }
            if (expirationYear.Length > 2)
            {
                expirationYear = expirationYear.Substring(expirationYear.Length - 2);
            }
            string expireDate   = expirationMonth + expirationYear;
            string amount       = String.Format("{0:F2}", dAmount);
            string securityCode = accountData.GetValue("SecurityCode");

            string fullName;

            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                fullName = accountData["AccountName"];
            }
            else
            {
                fullName = order.BillToFirstName + " " + order.BillToLastName;
            }

            string data = "dc_logon=" + HttpUtility.UrlEncode(this.LoginName, System.Text.Encoding.UTF8);

            data += Encode("dc_password", this.Password);
            if (this.UseDebugMode)
            {
                sensitiveData[this.Password] = "xxxxxxxx";
            }
            data += Encode("dc_transaction_type", "CREDIT");
            data += Encode("dc_version", "1.2");
            data += Encode("dc_transaction_id", authorizeTransaction.ProviderTransactionId);
            data += Encode("dc_address", order.BillToAddress1 + " " + order.BillToAddress2);
            data += Encode("dc_city", order.BillToCity);
            data += Encode("dc_zip", order.BillToPostalCode);
            data += Encode("dc_transaction_amount", amount);
            data += Encode("dc_name", fullName);
            data += Encode("dc_number", accountNumber);
            if (this.UseDebugMode)
            {
                sensitiveData[accountNumber] = MakeReferenceNumber(accountNumber);
            }
            data += Encode("dc_expiration_month", expirationMonth);
            data += Encode("dc_expiration_year", expirationYear);
            if (!string.IsNullOrEmpty(securityCode))
            {
                data += Encode("dc_verification_number", securityCode);
                if (this.UseDebugMode)
                {
                    sensitiveData["dc_verification_number=" + securityCode] = "dc_verification_number=" + (new string('x', securityCode.Length));
                }
            }

            return(data);
        }
示例#7
0
        private string InitializeAuthRequest(Payment payment, Order order, User user, Dictionary <string, string> sensitiveData, bool capture)
        {
            VerifyPaymentInstrument(payment);
            //Address address = user.PrimaryAddress;
            AccountDataDictionary accountData = new AccountDataDictionary(payment.AccountData);
            string accountNumber   = accountData.GetValue("AccountNumber");
            string expirationMonth = accountData.GetValue("ExpirationMonth");
            string expirationYear  = accountData.GetValue("ExpirationYear");

            if (expirationMonth.Length == 1)
            {
                expirationMonth = "0" + expirationMonth;
            }
            if (expirationYear.Length > 2)
            {
                expirationYear = expirationYear.Substring(expirationYear.Length - 2);
            }
            string expireDate   = expirationMonth + expirationYear;
            string amount       = String.Format("{0:F2}", payment.Amount);
            string securityCode = accountData.GetValue("SecurityCode");

            string data = "dc_logon=" + HttpUtility.UrlEncode(this.LoginName, System.Text.Encoding.UTF8);

            data += Encode("dc_password", this.Password);
            if (this.UseDebugMode)
            {
                sensitiveData[this.Password] = "xxxxxxxx";
            }
            if (capture)
            {
                data += Encode("dc_transaction_type", "AUTHORIZATION_CAPTURE");
            }
            else
            {
                data += Encode("dc_transaction_type", "AUTHORIZATION");
            }

            string fullName;

            if (accountData.ContainsKey("AccountName") && !string.IsNullOrEmpty(accountData["AccountName"]))
            {
                fullName = accountData["AccountName"];
            }
            else
            {
                fullName = order.BillToFirstName + " " + order.BillToLastName;
            }

            data += Encode("dc_version", "1.2");
            data += Encode("dc_address", order.BillToAddress1 + " " + order.BillToAddress2);
            data += Encode("dc_city", order.BillToCity);
            data += Encode("dc_zip", order.BillToPostalCode);
            data += Encode("dc_country", order.BillToCountryCode);
            data += Encode("dc_transaction_amount", amount);
            data += Encode("dc_name", fullName);
            data += Encode("dc_number", accountNumber);
            if (this.UseDebugMode)
            {
                sensitiveData[accountNumber] = MakeReferenceNumber(accountNumber);
            }
            data += Encode("dc_expiration_month", expirationMonth);
            data += Encode("dc_expiration_year", expirationYear);

            if (!string.IsNullOrEmpty(securityCode))
            {
                data += Encode("dc_verification_number", securityCode);
                if (this.UseDebugMode)
                {
                    sensitiveData["dc_verification_number=" + securityCode] = "dc_verification_number=" + (new string('x', securityCode.Length));
                }
            }

            return(data);
        }