private static void AddSubscriptionError(UserSubscriptionRequest req, UserSubscriptionType subscriptionType)
        {
            string ccLast4 = "";
            try { ccLast4 = new string('x', req.CcNum.Length - 4) + req.CcNum.Substring(req.CcNum.Length - 4); }
            catch { ccLast4 = ""; }

            string error = string.Format(@"Error in subscription: {0} \r\n
                                                            Name:{1}\r\n
                                                            Email: {2}\r\n
                                                            Payment Type: {2} \r\n
                                                            CcLast4: {3} \r\n",
                                                subscriptionType.Description + "(" + subscriptionType.SubscriptionTypeID + ")",
                                                req.FirstName + " " + req.LastName,
                                                req.Email,
                                                req.PaymentType.ToString(),
                                                ccLast4);
            LoggingFactory.GetLogger().LogError(error, null);
        }
        public static UserSubscriptionResult ProcessUserSubscriptionRequest(UserSubscriptionRequest req)
        {
            UserSubscriptionResult result = new UserSubscriptionResult();
            List<UserSubscription> subscriptions = GetUserSubscriptions(req.UserID);

            if (subscriptions.Count > 0)
            {
                result.ErrorMessages.Add(UserMessages.AlreadyHaveActiveSubscription);
                return result;
            }

            UserSubscriptionType subscriptionType = GetUserSubscriptionType(req.UserSubscriptionTypeID);

            if (subscriptionType.SubscriptionTypeID == 0)
            {
                result.ErrorMessages.Add(UserMessages.ErrorProcessingRequest);
                return result;
            }

            List<UserSubscription> existingSubscriptions = GetUserSubscriptions(req.UserID);
            if (existingSubscriptions.Count > 0)
            {
                result.ErrorMessages.Add(UserMessages.AlreadyHaveActiveSubscription);
                return result;
            }

            DateTime dateStart = DateTime.UtcNow.Date;
            DateTime dateEnd = subscriptionType.GetDateEnd(dateStart);

            int subscriptionID = AddUserSubscription(req.UserID, req.UserSubscriptionTypeID, dateStart, dateEnd, 0);

            if (subscriptionID == 0)
            {
                result.ErrorMessages.Add(UserMessages.ErrorProcessingRequest);
                return result;
            }

            PayflowPaymentService ccs = new PayflowPaymentService();
            int paymentID = 0;

            CreditCardPaymentResult creditCardTransactionResult = new CreditCardPaymentResult();
            if (req.PaymentMethodID == 0)
                paymentID = ccs.ProcessPaymentUsingActualCcNum(Constants.ExternalTypes.Users, req.UserID, subscriptionID, req.TransactionType, req.PaymentType, req.CcType, req.CcNum, req.ExpDate, req.Csc, subscriptionType.Amount, subscriptionType.Description, req.FirstName, req.LastName, "", req.Email, req.Address1, req.Address2, req.City, req.State, "", req.Zip, req.CountryID, req.Phone, req.MobilePhone, req.IP, req.UserAgent, req.SurferID, ref creditCardTransactionResult);
            else
            {

            }
            if (paymentID == 0)
            {
                AddSubscriptionError(req, subscriptionType);
                result.ErrorMessages.Add(UserMessages.ErrorProcessingRequest);
                return result;
            }

            CreditCardPayment payment = CreditCardService.GetCreditCardPaymentByID(paymentID, Constants.ExternalTypes.Users, req.UserID);

            if (payment.PaymentID == 0)
            {
                AddSubscriptionError(req, subscriptionType);
                result.ErrorMessages.Add(UserMessages.ErrorProcessingRequest);
                return result;
            }

            // Hard Decline
            if (payment.TransactionResult.ResultFinal == Constants.Enumerators.PaymentResultFinal.AVSFailed ||
                payment.TransactionResult.ResultFinal == Constants.Enumerators.PaymentResultFinal.CSCFailed ||
                payment.TransactionResult.ResultFinal == Constants.Enumerators.PaymentResultFinal.Declined)
            {
                result.ErrorMessages.Add(UserMessages.TransactionDeclined);
                return result;
            }
            else if (payment.TransactionResult.ResultFinal == Constants.Enumerators.PaymentResultFinal.CommError)
            {
                result.ErrorMessages.Add(UserMessages.ErrorProcessingRequest);
                return result;
            }

            result.PaymentID = paymentID;

            // Create Transaction Register "Debit" with Order Total Price

            // Update user subscription status
            UpdateUserSubscriptionStatus(subscriptionID, req.UserID, Constants.Enumerators.SubscriptionStatus.Active);

            return result;
        }