Пример #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.QueryString["id"] != null)
      {
     m_oIARequestEstimate = DataAccess.IARequestEstimates.SingleOrDefault(row => row.IARequestEstimateID == MemberProtect.Utility.ValidateInteger(Request.QueryString["id"]));
      }
 }
        protected void OnSendEstimate(object sender, EventArgs e)
        {
            var isNewRequestEstimate = true;
             var isPrePay = false;
             var requestEstimate = new IARequestEstimate();

             if (_iaRequest.IARequestEstimates.Any())
             {
            isNewRequestEstimate = false;
            requestEstimate = _iaRequest.IARequestEstimates[0];
             }
             else
             {
            requestEstimate.CreatedDateTime = DateTime.Now;
            DataAccess.IARequestEstimates.InsertOnSubmit(requestEstimate);
             }

             requestEstimate.IARequestID = _iaRequest.IARequestID;
             requestEstimate.MPUserID = MemberProtect.CurrentUser.UserID;
             requestEstimate.EmailRecipient = m_txtRecipientEmail.Text;
             requestEstimate.EmailCC = m_txtRecipientCCEmails.Text;
             requestEstimate.EmailSubject = m_txtSubject.Text;
             requestEstimate.EmailBody = m_txtBody.Content;
             switch (m_radCharge.SelectedValue)
             {
            case "RequiresPayment":
               requestEstimate.Charge = MemberProtect.Utility.ValidateDecimal(m_txtCharge.Text);
               requestEstimate.IsPaymentRequired = true;
               requestEstimate.IsApproved = false;
               requestEstimate.ApprovedDateTime = new DateTime(1900, 1, 1, 0, 0, 0, 0);
               _iaRequest.IARequestStatusID = ApplicationContext.GetRequestStatusID(RequestStatus.WaitingEstimateApproval);
               break;
            case "RequiresApproval":
               requestEstimate.Charge = 0;
               requestEstimate.IsPaymentRequired = false;
               requestEstimate.IsApproved = false;
               requestEstimate.ApprovedDateTime = new DateTime(1900, 1, 1, 0, 0, 0, 0);
               _iaRequest.IARequestStatusID = ApplicationContext.GetRequestStatusID(RequestStatus.WaitingEstimateApproval);
               break;
            case "PrePay":
               requestEstimate.Charge = MemberProtect.Utility.ValidateDecimal(m_txtCharge.Text);
               requestEstimate.IsPaymentRequired = false;
               requestEstimate.IsApproved = true;
               requestEstimate.ApprovedDateTime = DateTime.Now;
               _iaRequest.IARequestStatusID = ApplicationContext.GetRequestStatusID(RequestStatus.Submitted);

               var service = GetCardServiceForCustomer();
               var cardId = MemberProtect.Utility.ValidateInteger(PaymentSourceCombo.SelectedValue);
               var card = service.GetCreditCard(cardId);
               if (card == null)
               {
                  ShowMessage("Unable to access that credit card.", MessageTone.Negative);
                  return;
               }

               requestEstimate.PreAuthorizedPaymentCharged = true;
               var response = service.PayEstimate(card, ApplicationContext.RootUrlBuilder(this), _iaRequest, requestEstimate);
               isPrePay = response.SuccessfulCharge;

               break;
            default:
               requestEstimate.Charge = 0;
               requestEstimate.IsPaymentRequired = false;
               requestEstimate.IsApproved = true;
               requestEstimate.ApprovedDateTime = DateTime.Now;
               _iaRequest.IARequestStatusID = ApplicationContext.GetRequestStatusID(RequestStatus.Submitted);
               if (_iaRequest.IAJobs.Any())
               {
                  _iaRequest.IARequestStatusID = ApplicationContext.GetRequestStatusID(RequestStatus.Processing);
               }
               break;
             }

             ApplicationContext.RequestAssignStaff(_iaRequest, MemberProtect.CurrentUser.UserID);
             DataAccess.SubmitChanges();

             if (isPrePay)
             {
            RedirectMessage(string.Format("~/create-job.aspx?rid={0}", IARequest.IARequestID),
                            "The estimate has been charged to the customers credit card.",
                            MessageTone.Positive);
             }
             else
             {
            _iaRequest.CreateNote(MemberProtect.CurrentUser.UserID, isNewRequestEstimate ? "Sent estimate" : "Re-issued estimate");
            DataAccess.SubmitChanges();

            SendEstimateEmail();

            RedirectMessage(string.Format("~/create-job.aspx?rid={0}", IARequest.IARequestID),
                            "The estimate has been saved and sent to the customer.",
                            MessageTone.Positive);
             }
        }
Пример #3
0
        private void SendCustomerReceipt(CreditCardViewModel cardProfile, IARequest request, IARequestEstimate estimate)
        {
            var thankYouEmail = new StringBuilder();
             thankYouEmail.AppendLine(string.Format("Thank you for making your estimate payment for request # {0} requested by {1} {2}.<br/>",
                                                request.RequestIdForDisplay, _memberProtect.User.GetDataItem(request.MPUserID, "FirstName"),
                                                _memberProtect.User.GetDataItem(request.MPUserID, "LastName")));
             thankYouEmail.AppendLine("<br/>");
             thankYouEmail.AppendLine("Payment Details<br/>");
             foreach (var job in request.IAJobs)
             {
            thankYouEmail.AppendLine(string.Format("Job: {0}<br />", job.Name));
             }
             thankYouEmail.AppendLine(string.Format("Amount: {0:c}<br/>", estimate.Charge));
             thankYouEmail.AppendLine(string.Format("When: {0:g}<br/>", DateTime.Now));
             thankYouEmail.AppendLine(string.Format("Card: {0} ending in {1}<br/>", cardProfile.CardType,
                                                _memberProtect.Utility.Right(cardProfile.CreditCardNumber, 4)));
             thankYouEmail.AppendLine("<br/>");
             thankYouEmail.AppendLine("Thank you,<br/>");
             thankYouEmail.AppendLine("<a href='http://www.speedyspots.com'>SpeedySpots.com</a><br/>");
             thankYouEmail.AppendLine("<a href='mailto:[email protected]'>[email protected]</a><br/>");
             thankYouEmail.AppendLine("(734) 475-9327<br/>");
             thankYouEmail.AppendLine("Customer Email: " + cardProfile.ReceiptEmailAddressCsv); //ADDED THIS LINE FOR EMAIL FIx

             var subject = string.Format("Estimate payment received for request {0}.", request.RequestIdForDisplay);
             EmailCommunicationService.EstimatePaymentCustomerReceiptSend(subject, thankYouEmail, cardProfile.ReceiptEmailAddressCsv);
        }
Пример #4
0
        private void RecordOrder(CreditCardViewModel paymentDetails, PaymentGatewayResponse response, IARequestEstimate estimate)
        {
            var iaOrder = new IAOrder
             {
            MPUserID = _customerMemberProtectUserId,
            CreditCardType = _memberProtect.Cryptography.Encrypt(paymentDetails.CardType),
            CreditCardNumber = _memberProtect.Cryptography.Encrypt(paymentDetails.CreditCardNumber),
            CreditCardExpirationMonth = _memberProtect.Cryptography.Encrypt(paymentDetails.ExpirationMonth),
            CreditCardExpirationYear = _memberProtect.Cryptography.Encrypt(paymentDetails.ExpirationYear),
            CreditCardFirstName = _memberProtect.Cryptography.Encrypt(paymentDetails.FirstName),
            CreditCardLastName = _memberProtect.Cryptography.Encrypt(paymentDetails.LastName),
            CreditCardZip = "",
            AuthorizeNetResponse = string.Empty,
            AuthorizeNetTransactionID = response.GetValue(PaymentGatewayResponse.FieldNames.TransactionId),
            AuthorizeNetProcessDatetime = DateTime.Now,
            AuthorizeNetProcessResponse = response.GetValue(PaymentGatewayResponse.FieldNames.ResponseCode),
            AuthorizeNetProcessUsername = _dataContext.MPUsers.First(u => u.MPUserID == _customerMemberProtectUserId).Username,
            AuthorizeNetProcessCaptureAmount = estimate.Charge,
            AuthorizeNetProcessCaptureAmountChangeReason = string.Empty,
            AuthorizeNetProcessStatus = "Captured",
            CreatedDateTime = DateTime.Now
             };
             _dataContext.IAOrders.InsertOnSubmit(iaOrder);
             _dataContext.SubmitChanges();

             var iaOrderLineItem = new IAOrderLineItem
             {
            IAOrderID = iaOrder.IAOrderID,
            Description = "Request Estimate",
            Quantity = 1,
            Price = estimate.Charge,
            IsSynched = false
             };
             _dataContext.IAOrderLineItems.InsertOnSubmit(iaOrderLineItem);

             estimate.IAOrderID = iaOrder.IAOrderID;
             _dataContext.SubmitChanges();
        }
Пример #5
0
 private void MarkEstimateAsPaid(IARequest request, IARequestEstimate estimate, DateTime approved)
 {
     estimate.IsApproved = true;
      estimate.ApprovedDateTime = approved;
      request.CreateNote(_customerMemberProtectUserId, estimate.PreAuthorizedPaymentCharged
                                                      ? string.Format("Estimate payment pre-approved and paid: {0:c}", estimate.Charge)
                                                      : string.Format("Estimate approved and paid: {0:c}", estimate.Charge));
      _dataContext.SubmitChanges();
 }
Пример #6
0
        public CreditCardServiceResponse PayEstimate(CreditCardViewModel cardProfile, Func<string, string> urlBuilder, IARequest request, IARequestEstimate estimate)
        {
            var response = new CreditCardServiceResponse {SuccessfulCharge = true};

             var transaction = new AuthorizeNETTransactionInformation(cardProfile.CreditCardNumber, estimate.Charge, cardProfile.ExpirationDate)
             {
            FirstName = cardProfile.FirstName,
            LastName = cardProfile.LastName,
            CreditCardCode = cardProfile.CardVerificationCode,
            Email = cardProfile.ReceiptEmailAddressCsv,
            InvoiceNumber = string.Format("Est-{0}", request.RequestIdForDisplay),
            Description = "Request Estimate",
            Company = cardProfile.CompanyName.PadRight(50).Substring(0, 50).Trim(),
            Zip = ""
             };

             var paymentGatewayResponse = new PaymentGatewayResponse(string.Empty);

             if (cardProfile.CreditCardId == 0)
             {
            var authorizeNetDirect = new AuthorizeNET(_enableDebug, _loginId, _transactionKey);

            if (!authorizeNetDirect.ProcessAuthorizationAndCapture(transaction))
            {
               response.SuccessfulCharge = false;
               response.ErrorMessage = authorizeNetDirect.Error;
            }

            response.PaymentGatewayResponse = authorizeNetDirect.PaymentGatewayResponse;
             }
             else
             {
            // go through CIM to process transaction
            paymentGatewayResponse = CIMAuthorizationAndCapture(transaction,
                                                                cardProfile.CIMProfileId,
                                                                cardProfile.CIMPaymentProfileId);
            if (paymentGatewayResponse.Errors.Any() || paymentGatewayResponse.GetValue(PaymentGatewayResponse.FieldNames.ResponseCode) != "1")
            {
               var message = paymentGatewayResponse.Errors.Any()
                                ? paymentGatewayResponse.Errors.Aggregate((messages, error) => messages + ", " + error)
                                : paymentGatewayResponse.GetValue(PaymentGatewayResponse.FieldNames.ResponseReasonText);

               response.SuccessfulCharge = false;
               response.ErrorMessage = message;
            }
             }

             if (!response.SuccessfulCharge) return response;

             RecordOrder(cardProfile, paymentGatewayResponse, estimate);

             var requestStatusLookup = new RequestStatusLookup(_dataContext);
             request.IARequestStatusID = requestStatusLookup.GetRequestStatus(RequestStatus.Processing).IARequestStatusID;
             _dataContext.SubmitChanges();

             var approved = DateTime.Now;
             MarkEstimateAsPaid(request, estimate, approved);

             SendCustomerReceipt(cardProfile, request, estimate);

             InformBillingThatCustomerPaid(cardProfile, paymentGatewayResponse, urlBuilder, request, approved, estimate.Charge);

             return response;
        }