//Service for making Payment with ADMIN
        public bool AdminPaymentService(PaymentRequest model)
        {
            string nonceFromTheClient = model.ExternalCardIdNonce;

            int currentTransactionId = 0;

            //Temporary code below
            ITransactionLogService _transactionLogService = UnityConfig.GetContainer().Resolve <ITransactionLogService>();

            currentTransactionId = _transactionLogService.BillingTransactionInsert(model);

            TransactionRequest request = new TransactionRequest
            {
                Amount             = model.ItemCost,
                PaymentMethodToken = nonceFromTheClient,
                Options            = new TransactionOptionsRequest
                {
                    SubmitForSettlement = true
                }
            };

            Result <Transaction> result = _Gateway.Transaction.Sale(request);

            var transactionJson = new JavaScriptSerializer().Serialize(result);

            //Instantiate values into Transaction Log Model
            BillingTransactionLog LogModel = new BillingTransactionLog();

            LogModel.Id          = currentTransactionId;
            LogModel.RawResponse = transactionJson;


            if (result.Message == null && result.Errors == null)
            {
                //Instatiate Success Values
                LogModel.AmountConfirmed    = result.Target.Amount;
                LogModel.TransactionId      = result.Target.Id;
                LogModel.CardExpirationDate = result.Target.CreditCard.ExpirationDate;
                LogModel.CardLastFour       = result.Target.CreditCard.LastFour;

                ActivityLogRequest Activity = new ActivityLogRequest();

                Activity.ActivityType = ActivityTypeId.MadePayment;


                _ActivityLogService.InsertActivityToLog(model.UserId, Activity);



                return(_transactionLogService.TransactionLogUpdateSuccess(LogModel));
            }
            else
            {
                //Instatiate Error Values
                LogModel.ErrorCode = result.Message;

                bool response = _transactionLogService.TransactionLogUpdateError(LogModel);
                throw new System.ArgumentException(result.Message, "CreditCard");
            }
        }
Exemple #2
0
        public HttpResponseMessage JobEdit(JobUpdateRequest model, int id)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            model.Id = id;

            bool isSuccessful = _JobsService.UpdateJob(model);

            ItemResponse <bool> response = new ItemResponse <bool>();

            response.Item = isSuccessful;

            //Activity Log Service
            ActivityLogRequest Activity = new ActivityLogRequest();

            Activity.ActivityType = ActivityTypeId.JobUpdated;
            Activity.JobId        = id;
            Activity.TargetValue  = (int)JobStatus.BringgCreated;

            _ActivityLogService.InsertActivityToLog(model.UserId, Activity);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Exemple #3
0
        public HttpResponseMessage JobDelete(int Id)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            JobDeleteRequest model = new JobDeleteRequest();

            model.Id = Id;

            Job JobList = new Job();

            JobList = _JobsService.GetJobById(Id);

            bool isSuccessful = _JobsService.DeleteJob(model);

            ItemResponse <bool> response = new ItemResponse <bool>();

            response.Item = isSuccessful;

            //Activity Log Service
            ActivityLogRequest Activity = new ActivityLogRequest();

            Activity.ActivityType = ActivityTypeId.JobDeleted;
            Activity.JobId        = Id;

            _ActivityLogService.InsertActivityToLog(JobList.UserId, Activity);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        public HttpResponseMessage JobEdit(JobUpdateRequest model, int id)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            model.Id = id;

            //JobsService jobService = new JobsService();
            //can you do a get and update the payment nonce in here - you will have the job ID

            bool isSuccessful = _JobsService.UpdateJob(model);

            ItemResponse <bool> response = new ItemResponse <bool>();

            response.Item = isSuccessful;

            //Activity Log Service - Needs to be fixed - the value for model.UserId is null
            ActivityLogRequest Activity = new ActivityLogRequest();

            Activity.ActivityType = ActivityTypeId.JobUpdated;
            Activity.JobId        = id;
            Activity.TargetValue  = (int)JobStatus.BringgCreated;

            _ActivityLogService.InsertActivityToLog(model.UserId, Activity);

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        public HttpResponseMessage JobInsert(JobInsertRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            ItemResponse <int> response = new ItemResponse <int>();
            UserProfile        user     = null;

            // Check to see if user is logged use userservice.isloggedin
            if (UserService.IsLoggedIn())
            {
                user = _UserProfileService.GetUserById(UserService.GetCurrentUserId());

                model.UserId = user.UserId;
                model.Phone  = user.Phone;

                if (user.ExternalUserId != null)
                {
                    int extId = 0;

                    int.TryParse(user.ExternalUserId, out extId);

                    if (extId > 0)
                    {
                        model.ExternalCustomerId = extId;
                    }
                    else
                    {
                        //  TODO: get user by phone number from bringg, grab their id, update userProfile table so we have it for this user
                        //  if they do not exist at bringg we must create them, link their acct to externalCustomerId in our db and use that customer id
                    }
                }
            }
            //we need an email

            int tempJobId = _JobsService.InsertJob(model);

            response.Item = tempJobId;

            //Activity Log Service


            if (user != null && user.UserId != null)
            {
                ActivityLogRequest Activity = new ActivityLogRequest();

                Activity.ActivityType = ActivityTypeId.CreatedJob;

                Activity.JobId       = tempJobId;
                Activity.TargetValue = (int)JobStatus.BringgCreated;

                _ActivityLogService.InsertActivityToLog(model.UserId, Activity);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Exemple #6
0
        public HttpResponseMessage JobInsert(JobInsertRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            ItemResponse <int> response = new ItemResponse <int>();
            UserProfile        user     = null;

            // Check to see if user is logged use userservice.isloggedin
            if (UserService.IsLoggedIn())
            {
                user = _UserProfileService.GetUserById(UserService.GetCurrentUserId());

                model.UserId = user.UserId;
                model.Phone  = user.Phone;

                if (user.ExternalUserId != null)
                {
                    int extId = 0;

                    int.TryParse(user.ExternalUserId, out extId);

                    if (extId > 0)
                    {
                        model.ExternalCustomerId = extId;
                    }
                }
            }

            int tempJobId = _JobsService.InsertJob(model);

            response.Item = tempJobId;

            //Activity Log Service
            if (user != null && user.UserId != null)
            {
                ActivityLogRequest Activity = new ActivityLogRequest();

                Activity.ActivityType = ActivityTypeId.CreatedJob;

                Activity.JobId       = tempJobId;
                Activity.TargetValue = (int)JobStatus.BringgCreated;

                _ActivityLogService.InsertActivityToLog(model.UserId, Activity);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        public HttpResponseMessage GuestPayment(CustomerPaymentRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            string paymentNonce;

            try
            {
                paymentNonce = _BrainTreeService.GuestPayment(model);
            }
            catch (ArgumentException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }


            JobUpdateRequest jobUpdate = new JobUpdateRequest
            {
                Id           = model.JobId,
                Phone        = model.Phone,
                ContactName  = string.Format("{0} {1}", model.FirstName, model.LastName),
                PaymentNonce = paymentNonce
            };


            ActivityLogRequest Activity = new ActivityLogRequest
            {
                ActivityType = ActivityTypeId.CreatedJob,
                JobId        = model.JobId,
                TargetValue  = (int)JobStatus.BringgCreated
            };

            //For guest check out we use the phone number as the userID
            _ActivityLogService.InsertActivityToLog(model.Phone, Activity);

            bool isSuccessful = _JobsService.UpdateJob(jobUpdate);


            ItemResponse <bool> response = new ItemResponse <bool>();

            response.Item = isSuccessful;



            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        public HttpResponseMessage Add([FromBody] ActivityLogRequest activityLogRequest)
        {
            // Get the UserId of the logged in user.
            int userId = int.Parse(User.Identity.GetUserId());

            //TODO Verify that a valid activity and valid user have been passed.
            User     user     = (User)_Database.Users.SingleOrDefault(usr => usr.UserId == userId);
            Activity activity = (Activity)_Database.Activities.SingleOrDefault(act => act.ActivityId == activityLogRequest.ActivityId);

            // Create a new ActivityLog entry in the database.
            ActivityLog newLog = new ActivityLog {
                Activity = activity, User = user, StartTime = activityLogRequest.StartTime, EndTime = activityLogRequest.EndTime
            };

            System.Diagnostics.Debug.WriteLine("Adding a new ActivityLog...");

            // Add the ActivityLog to the database.
            _Database.ActivityLogs.Add(newLog);
            _Database.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        //Service ran for creating a new user - pass in users id and request model
        public void CreateUserProfile(string userId, CreateUserRequest model)
        {
            //Updated the create user so that it can take in the tokenHash param if there is one provided
            DataProvider.ExecuteNonQuery(GetConnection, "UserProfiles_Insert" // stored procedure
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {                                                                 //input fields
                paramCollection.AddWithValue("@UserId", userId);
                paramCollection.AddWithValue("@FirstName", model.FirstName);
                paramCollection.AddWithValue("@LastName", model.LastName);
                paramCollection.AddWithValue("@TokenHash", model.TokenHash);     //this is provided if they were referred by a current customer
            }
                                         );
            //referral coupon
            //if TokenHash referral is null, they're making a new account.
            //if TokenHash referral is NOT null, we want to give them (new user) a Coupon value and add it to their Credit.
            // we also want to give the original user (one who referred) the same Coupon value and add it to their Credit.
            if (model.TokenHash != null)
            {
                //retrieve coupon information + token information based on the token hash.
                CouponsDomain userCoupon = TokenService.GetReferralTokenByGuid(model.TokenHash);
                if (userCoupon.Token.Used == null)
                {
                    //send token to Credit service
                    UserCreditsRequest insertRefferalCredits = new UserCreditsRequest();
                    UserCreditsRequest insertFriendCredits   = new UserCreditsRequest();

                    //send credits to new User who was referred
                    insertRefferalCredits.Amount          = userCoupon.CouponValue;
                    insertRefferalCredits.TransactionType = "Add";
                    insertRefferalCredits.UserId          = userId;
                    _CreditsService.InsertUserCredits(insertRefferalCredits);
                }

                else
                {
                    //send error message that token has already been used.
                }
            }

            //Activity Services
            ActivityLogRequest Activity = new ActivityLogRequest();

            Activity.ActivityType = ActivityTypeId.NewAccount;
            _ActivityLogService.InsertActivityToLog(userId, Activity);

            //----------//create a new Website Id ---------updated the AddUserToWebsite using the updated domain with int[]
            //getting the websiteId via the website Slug
            Website w    = null;
            string  Slug = model.Slug;

            w = WebsiteService.GetWebsiteIdBySlug(Slug);

            int[] WebsiteIds = new int[1];
            WebsiteIds[0] = w.Id;
            //populating userwebsite object
            UserWebsite userWebsite = new UserWebsite();

            userWebsite.UserId     = userId;
            userWebsite.WebsiteIds = WebsiteIds;
            WebsiteService.AddUserToWebsite(userWebsite);

            //creae a new Customer role
            //set role as customer by default - change role by admin panel
            UserProfile aspUser = new UserProfile();

            aspUser.FirstName = model.FirstName;
            aspUser.LastName  = model.LastName;
            aspUser.RoleId    = ConfigService.CustomerRole;
            _AdminService.CreateUserRole(userId, aspUser);

            //create a new Braintree account using UserID
            //braintree used for handling credit card transactions
            CustomerPaymentRequest Payment = new CustomerPaymentRequest();

            Payment.FirstName = model.FirstName;
            Payment.LastName  = model.LastName;
            Payment.UserId    = userId;
            Payment.Phone     = model.Phone;

            //Send a confirmation Text Msg
            string UserSMSToken = TokenSMSService.TokenSMSInsert(userId);
            //send a text msg
            NotifySMSRequest NotifyCustomer = new NotifySMSRequest();

            NotifyCustomer.Phone    = model.Phone;
            NotifyCustomer.TokenSMS = UserSMSToken;

            try
            {
                NotifySMSService.SendConfirmText(NotifyCustomer);
            }
            catch (ArgumentException ex)
            {
                //if phone number is already registered will not send a registration check
                //should never get this far
                throw new System.ArgumentException(ex.Message);
            }

            //bringg create account
            RegisterBringgRequest bringgRequest = new RegisterBringgRequest();

            bringgRequest.Name   = model.FirstName + " " + model.LastName;
            bringgRequest.Phone  = model.Phone;
            bringgRequest.Email  = model.Email;
            bringgRequest.UserId = userId;
            this._CreateCustomerTask.Execute(bringgRequest);

            _CreateCustomerTask.Execute(bringgRequest);

            BrainTreeService brainTree = new BrainTreeService();

            brainTree.newCustomerInsert(Payment);

            ////generate a new token
            Guid userTokenGuid = TokenService.tokenInsert(userId);

            //send a confirmation email
            _EmailService.SendProfileEmail(userTokenGuid, model.Email);
        }
        //BrainTree Customer Creation for maybe if GUEST wants to become member before Checkout.
        public bool CreateCustomerTransaction(CustomerPaymentRequest model)
        {
            //get user id with currentuserId
            string gotUserId = UserService.GetCurrentUserId();

            model.UserId = gotUserId;

            //Grab email from UserProfileService
            UserProfile userObject = _UserProfileService.GetUserById(model.UserId);

            string userEmail = userObject.Email;

            //Add the new card nonce & info into credit cards table
            UserCreditCards CardModel = new UserCreditCards();

            CardModel.UserId = model.UserId;
            CardModel.ExternalCardIdNonce = model.ExternalCardIdNonce;
            CardModel.Last4DigitsCC       = model.Last4DigitsCC;
            CardModel.CardType            = model.CardType;
            CreditCardService NewCardService = new CreditCardService();

            NewCardService.creditCardInsertModel(CardModel);

            int currentTransactionId = 0;

            //Post first Transaction log before result
            currentTransactionId = _TransactionLogService.BillingTransactionInsert(model);

            bool DuplicateBool = false;

            bool.TryParse(ConfigService.DuplicatePaymentMethod, out DuplicateBool);

            bool VerifyBool = false;

            bool.TryParse(ConfigService.VerifyCard, out VerifyBool);

            //create transaction and create customer in braintree system
            //***NEED TO ADD THE JOB_ID AS WELL LATER***
            TransactionRequest request = new TransactionRequest
            {
                Amount             = model.ItemCost,
                PaymentMethodNonce = model.ExternalCardIdNonce,
                Customer           = new CustomerRequest
                {
                    Id        = model.UserId,
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Email     = userEmail,

                    CreditCard = new CreditCardRequest
                    {
                        Options = new CreditCardOptionsRequest
                        {
                            FailOnDuplicatePaymentMethod = DuplicateBool,
                            VerifyCard = VerifyBool
                        }
                    }
                },
                Options = new TransactionOptionsRequest
                {
                    SubmitForSettlement   = true,
                    StoreInVaultOnSuccess = true,
                }
            };
            Result <Transaction> result = _Gateway.Transaction.Sale(request);

            //serialize the whole result object for backup purposes
            var transactionJson = new JavaScriptSerializer().Serialize(result);

            //Instantiate values into Transaction Log Model
            BillingTransactionLog LogModel = new BillingTransactionLog();

            LogModel.Id          = currentTransactionId;
            LogModel.RawResponse = transactionJson;

            //if else for whether the payment was successful or not
            if (result.Message == null && result.Errors == null)
            {
                //Instatiate Success Values
                LogModel.AmountConfirmed    = result.Target.Amount;
                LogModel.TransactionId      = result.Target.Id;
                LogModel.CardExpirationDate = result.Target.CreditCard.ExpirationDate;
                LogModel.CardLastFour       = result.Target.CreditCard.LastFour;

                ActivityLogRequest Activity = new ActivityLogRequest();

                Activity.ActivityType = ActivityTypeId.MadePayment;

                _ActivityLogService.InsertActivityToLog(model.UserId, Activity);



                return(_TransactionLogService.TransactionLogUpdateSuccess(LogModel));
            }
            else
            {
                //Instatiate Error Values
                LogModel.ErrorCode = result.Message;

                bool response = _TransactionLogService.TransactionLogUpdateError(LogModel);
                throw new System.ArgumentException(result.Message, "CreditCard");
            }
        }
        public void CreateUserProfile(string userId, CreateUserRequest model)
        {
            //Updated the create user so that it can take in the tokenHash param if there is one provided --Anna

            DataProvider.ExecuteNonQuery(GetConnection, "UserProfiles_Insert"
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@UserId", userId);
                paramCollection.AddWithValue("@FirstName", model.FirstName);
                paramCollection.AddWithValue("@LastName", model.LastName);
                paramCollection.AddWithValue("@TokenHash", model.TokenHash);     //this is provided if they were referred by a current customer
            }
                                         );

            //referral coupon
            //if TokenHash referral is null, they're making a new account.
            //if TokenHash referral is NOT null, give new user a Coupon value and add it to their Credit.
            // we also want to give the original user (one who referred) the same Coupon value and add it to their Credit.
            if (model.TokenHash != null)
            {
                //retrieve coupon information + token information based on the token hash.
                CouponsDomain userCoupon = TokenService.GetReferralTokenByGuid(model.TokenHash);
                if (userCoupon.Token.Used == null)
                {
                    //send token to Credit service
                    UserCreditsRequest insertRefferalCredits = new UserCreditsRequest();

                    //send credits to new User who was referred
                    insertRefferalCredits.Amount          = userCoupon.CouponValue;
                    insertRefferalCredits.TransactionType = "Add";
                    insertRefferalCredits.UserId          = userId;
                    _CreditsService.InsertUserCredits(insertRefferalCredits);

                    //send credits to Friend who referred new user BUT ONLY AFTER THE REFERRED FRIEND HAS COMPLETED THEIR FIRST ORDER----
                    //see BrainTreeService, Line 130
                }
            }

            //Activity Services - update the activity log
            ActivityLogRequest Activity = new ActivityLogRequest();

            Activity.ActivityType = ActivityTypeId.NewAccount;
            _ActivityLogService.InsertActivityToLog(userId, Activity);

            //Associating a User to website(s)
            Website w    = null;
            string  Slug = model.Slug;

            w = WebsiteService.GetWebsiteIdBySlug(Slug);

            int[] WebsiteIds = new int[1];
            WebsiteIds[0] = w.Id;

            UserWebsite userWebsite = new UserWebsite();

            userWebsite.UserId     = userId;
            userWebsite.WebsiteIds = WebsiteIds;
            WebsiteService.AddUserToWebsite(userWebsite);

            //creae a new Customer role
            UserProfile aspUser = new UserProfile();

            aspUser.FirstName = model.FirstName;
            aspUser.LastName  = model.LastName;
            aspUser.RoleId    = ConfigService.CustomerRole;

            _AdminService.CreateUserRole(userId, aspUser);

            //create a new Braintree account using UserID
            CustomerPaymentRequest Payment = new CustomerPaymentRequest();

            Payment.FirstName = model.FirstName;
            Payment.LastName  = model.LastName;
            Payment.UserId    = userId;
            Payment.Phone     = model.Phone;

            //Send a confirmation Text Msg
            string UserSMSToken = TokenSMSService.TokenSMSInsert(userId);
            //send a text msg
            NotifySMSRequest NotifyCustomer = new NotifySMSRequest();

            NotifyCustomer.Phone    = model.Phone;
            NotifyCustomer.TokenSMS = UserSMSToken;

            try
            {
                NotifySMSService.SendConfirmText(NotifyCustomer);
            }
            catch (ArgumentException /*ex*/)
            {
                DeleteUserProfileByUserId(userId);
                DeleteUserWebsiteByUserId(userId);
                DeleteAspNetUserByUserId(userId);

                throw new System.ArgumentException(ex.Message);
            }

            //send a confirmation email
            _EmailService.SendProfileEmail(userTokenGuid, model.Email);

            //bringg create account
            RegisterBringgRequest bringgRequest = new RegisterBringgRequest();

            bringgRequest.Name   = model.FirstName + " " + model.LastName;
            bringgRequest.Phone  = model.Phone;
            bringgRequest.Email  = model.Email;
            bringgRequest.UserId = userId;
            this._CreateCustomerTask.Execute(bringgRequest);



            _CreateCustomerTask.Execute(bringgRequest);

            BrainTreeService brainTree = new BrainTreeService();

            brainTree.newCustomerInsert(Payment);

            ////generate a new token
            Guid userTokenGuid = TokenService.tokenInsert(userId);

            //send a confirmation email

            _EmailService.SendProfileEmail(userTokenGuid, model.Email, model.Slug);
        }