示例#1
0
        public ActionResult PayPointCallback(bool valid, string trans_id, string code, string auth_code, decimal?amount, string ip, string test_status, string hash, string message, string card_no, string customer, string expiry, int customerId)
        {
            var cus = this.customersRepository.GetChecked(customerId);

            if (test_status == "true")
            {
                // Use last 4 random digits as card number (to enable useful tests)
                string random4Digits = string.Format("{0}{1}", DateTime.UtcNow.Second, DateTime.UtcNow.Millisecond);
                if (random4Digits.Length > 4)
                {
                    random4Digits = random4Digits.Substring(random4Digits.Length - 4);
                }
                card_no = random4Digits;
                expiry  = string.Format("{0}{1}", "01", DateTime.Now.AddYears(2).Year.ToString().Substring(2, 2));
            }
            if (!valid || code != "A")
            {
                TempData["code"]    = code;
                TempData["message"] = message;
                return(View("Error"));
            }

            PayPointFacade payPointFacade = new PayPointFacade(cus.MinOpenLoanDate(), cus.CustomerOrigin.Name);

            if (!payPointFacade.CheckHash(hash, Request.Url))
            {
                throw new Exception("check hash failed");
            }

            bool paymentAdded = AddPayPointCardToCustomer(trans_id, card_no, cus, expiry, amount, payPointFacade.PayPointAccount);

            return(View("PayPointAdded", new PaypointAddedModel {
                Amount = amount ?? 0, PaymentAdded = paymentAdded
            }));
        }
示例#2
0
        public JsonResult AddPayPointCard(int customerId, string transactionid, string cardno, DateTime expiredate)
        {
            var            customer       = this.customersRepository.GetChecked(customerId);
            var            expiry         = expiredate.ToString("MMyy");
            PayPointFacade payPointFacade = new PayPointFacade(customer.MinOpenLoanDate(), customer.CustomerOrigin.Name);

            AddPayPointCardToCustomer(transactionid, cardno, customer, expiry, 0, payPointFacade.PayPointAccount);

            return(Json(new { }));
        }
示例#3
0
        public ActionResult Pay(decimal amount, string type, int loanId, int rolloverId)
        {
            try {
                log.Msg("Payment request for customer id {0}, amount {1}", this.context.Customer.Id, amount);

                amount = CalculateRealAmount(type, loanId, amount);
                if (amount < 0)
                {
                    return(View("Error"));
                }

                var oCustomer = this.context.Customer;

                PayPointFacade payPointFacade = new PayPointFacade(
                    oCustomer.MinOpenLoanDate(),
                    oCustomer.CustomerOrigin.Name
                    );

                int      payPointCardExpiryMonths = payPointFacade.PayPointAccount.CardExpiryMonths;
                DateTime cardMinExpiryDate        = DateTime.UtcNow.AddMonths(payPointCardExpiryMonths);

                var callback = Url.Action("Callback", "Paypoint", new {
                    Area = "Customer",
                    loanId,
                    type,
                    username          = (this.context.User != null ? this.context.User.Name : ""),
                    cardMinExpiryDate = FormattingUtils.FormatDateToString(cardMinExpiryDate),
                    hideSteps         = true,
                    payEarly          = true,
                    origin            = oCustomer.CustomerOrigin.Name
                }, "https");

                var url = payPointFacade.GeneratePaymentUrl(oCustomer, amount, callback);

                this.logRepository.Log(
                    this.context.UserId,
                    DateTime.UtcNow,
                    "Paypoint Pay Redirect to " + url,
                    "Successful",
                    ""
                    );

                return(Redirect(url));
            } catch (Exception e) {
                log.Alert(
                    e,
                    "Error while executing Pay(amount = {0}, type = '{1}', loan id = {2}, rollover id = {3}).",
                    amount,
                    type,
                    loanId,
                    rolloverId
                    );
                return(View("Error"));
            }     // try
        }         // Pay
示例#4
0
        public RedirectResult AddPayPoint(int id)
        {
            var            oCustomer                = this.customersRepository.Get(id);
            PayPointFacade payPointFacade           = new PayPointFacade(oCustomer.MinOpenLoanDate(), oCustomer.CustomerOrigin.Name);
            int            payPointCardExpiryMonths = payPointFacade.PayPointAccount.CardExpiryMonths;
            DateTime       cardMinExpiryDate        = DateTime.UtcNow.AddMonths(payPointCardExpiryMonths);
            var            callback = Url.Action("PayPointCallback", "PaymentAccounts", new { Area = "Underwriter", customerId = id, cardMinExpiryDate = FormattingUtils.FormatDateToString(cardMinExpiryDate), hideSteps = true }, "https");

            var url = payPointFacade.GeneratePaymentUrl(oCustomer, 5.00m, callback);

            return(Redirect(url));
        }
示例#5
0
        public RedirectResult GetTransactionId(decimal loan_amount, int loanType, int repaymentPeriod)
        {
            Customer customer = this.context.Customer;

            CheckCustomerStatus(customer);

            if (loan_amount < 0)
            {
                loan_amount = (int)Math.Floor(customer.CreditSum ?? 0);
            }

            var cr = customer.LastCashRequest;

            PayPointFacade payPointFacade = new PayPointFacade(customer.MinOpenLoanDate(), customer.CustomerOrigin.Name);

            if (customer.IsLoanTypeSelectionAllowed == 1)
            {
                var oDBHelper = ObjectFactory.GetInstance <IDatabaseDataHelper>() as DatabaseDataHelper;
                cr.RepaymentPeriod = repaymentPeriod;
                cr.LoanType        = oDBHelper.LoanTypeRepository.Get(loanType);
            } // if

            DateTime cardMinExpiryDate = DateTime.UtcNow.AddMonths(payPointFacade.PayPointAccount.CardExpiryMonths);

            var fee = new SetupFeeCalculator(cr.ManualSetupFeePercent, cr.BrokerSetupFeePercent).Calculate(loan_amount).Total;

            string callback = Url.Action("PayPointCallback", "GetCash",
                                         new {
                Area = "Customer",
                loan_amount,
                fee,
                username          = this.context.User.Name,
                cardMinExpiryDate = FormattingUtils.FormatDateToString(cardMinExpiryDate),
                origin            = customer.CustomerOrigin.Name
            },
                                         "https");

            string url = payPointFacade.GeneratePaymentUrl(customer, 5.00m, callback);

            this.logRepository.Log(this.context.UserId, DateTime.Now, "Paypoint GetCash Redirect to " + url, "Successful", "");
            return(Redirect(url));
        }
示例#6
0
        }         // SetDefaultCard

        public RedirectResult AddPayPoint()
        {
            var            oCustomer                = m_oContext.Customer;
            PayPointFacade payPointFacade           = new PayPointFacade(oCustomer.MinOpenLoanDate(), oCustomer.CustomerOrigin.Name);
            int            payPointCardExpiryMonths = payPointFacade.PayPointAccount.CardExpiryMonths;
            DateTime       cardMinExpiryDate        = DateTime.UtcNow.AddMonths(payPointCardExpiryMonths);
            var            callback = Url.Action("PayPointCallback", "Profile",
                                                 new {
                Area              = "Customer",
                customerId        = oCustomer.Id,
                cardMinExpiryDate = FormattingUtils.FormatDateToString(cardMinExpiryDate),
                hideSteps         = true,
                origin            = oCustomer.CustomerOrigin.Name
            }, "https");



            var url = payPointFacade.GeneratePaymentUrl(oCustomer, 5.00m, callback);

            return(Redirect(url));
        }         // AddPayPoint
示例#7
0
        public RedirectToRouteResult PayPointCallback(bool valid, string trans_id, string code, string auth_code, decimal?amount, string ip, string test_status, string hash, string message, decimal loan_amount, string card_no, string customer, string expiry)
        {
            //Session.Lock(_context.Customer, LockMode.Upgrade);

            if (test_status == "true")
            {
                // Use last 4 random digits as card number (to enable useful tests)
                string random4Digits = string.Format("{0}{1}", DateTime.UtcNow.Second, DateTime.UtcNow.Millisecond);
                if (random4Digits.Length > 4)
                {
                    random4Digits = random4Digits.Substring(random4Digits.Length - 4);
                }
                card_no = random4Digits;
                expiry  = string.Format("{0}{1}", "01", DateTime.Now.AddYears(2).Year.ToString().Substring(2, 2));
            }

            DateTime now = DateTime.UtcNow;
            Customer cus = this.context.Customer;

            try {
                if (!valid || code != "A")
                {
                    if (code == "N")
                    {
                        log.WarnFormat("Invalid transaction. Id = {0}, Code: {1}, Message: {2}", trans_id, code, message);
                    }
                    else
                    {
                        log.ErrorFormat("Invalid transaction. Id = {0}, Code: {1}, Message: {2}", trans_id, code, message);
                    }

                    // continue to log paypoint and pacnet transactions also for NL, i.e. do nothig new
                    this.logRepository.Log(this.context.UserId, DateTime.Now, "Paypoint GetCash Callback", "Falied",
                                           String.Format("Invalid transaction. Id = {0}, Code: {1}, Message: {2}", trans_id,
                                                         code, message));

                    this.context.Customer.PayPointErrorsCount++;

                    try {
                        // sending mail "Mandrill - Debit card authorization problem"
                        this.serviceClient.Instance.GetCashFailed(this.context.User.Id);
                    }
                    catch (Exception e) {
                        log.Error("Failed to send 'get cash failed' email.", e);
                    } // try

                    TempData["code"]    = code;
                    TempData["message"] = message;

                    return(RedirectToAction("Error", "Paypoint", new { Area = "Customer" }));
                }

                PayPointFacade payPointFacade = new PayPointFacade(cus.MinOpenLoanDate(), cus.CustomerOrigin.Name);
                if (!payPointFacade.CheckHash(hash, Request.Url))
                {
                    log.ErrorFormat("Paypoint callback is not authenticated for user {0}", this.context.Customer.Id);
                    // continue to log paypoint transaction also for NL
                    this.logRepository.Log(this.context.UserId, DateTime.Now, "Paypoint GetCash Callback", "Falied",
                                           String.Format("Paypoint callback is not authenticated for user {0}",
                                                         this.context.Customer.Id));
                    //return View("Error");
                    throw new Exception("check hash failed");
                }

                ValidateCustomerName(customer, cus);

                // "x rebate" pounds charged successfully, continue to save PayPointCard, create new loan, and make "rebate" payment

                // continue to log paypoint transaction also for NL
                this.logRepository.Log(this.context.UserId, DateTime.Now, "Paypoint GetCash Callback", "Successful", "");

                // save new PayPointCard
                var card = cus.TryAddPayPointCard(trans_id, card_no, expiry, customer, payPointFacade.PayPointAccount);

                Loan loan = this.loanCreator.CreateLoan(cus, loan_amount, card, now);

                RebatePayment(amount, loan, trans_id, now);

                cus.PayPointErrorsCount = 0;

                TempData["amount"]     = loan_amount;
                TempData["bankNumber"] = cus.BankAccount.AccountNumber;
                TempData["card_no"]    = card_no;

                this.customerRepository.Update(cus);

                // el: TODO save NL_Payments -> NL_PaypointTransactions for this PayPointCard; "AssignPaymentToLoan" strategy;

                /*
                 * 1. save NL_Payments with PaymentStatusID (NL_PaymentStatuses ("rebate"? / "system-repay" ?)), PaymentMethodID ([LoanTransactionMethod] 'Auto' ID 2)
                 *
                 * 2. save NL_PaypointTransactions with:
                 * PaypointCardID - from just created PayPointCard.Id,
                 * PaypointTransactionStatusID =1 (Done) NL_PaypointTransactionStatuses
                 * IP - from LoanTransaction IP
                 * Amount - from the method argument amount if not null, otherwise 5 pounds
                 * PaymentID - from 1.
                 *
                 * 3. new strategy AssignPaymentToLoan: argument: NL_Model with Loan.LoanID; decimal amount; output: NL_Model containing list of fees/schedules that covered by the amount/payment
                 * closest unpaid loan fees and schedules (1.fee if exists; 2.interest; 3.principal)
                 *
                 * 4. save into NL_LoanSchedulePayments : PaymentID just created + NL_LoanSchedules from AssignPaymentToLoan strategy
                 */

                return(RedirectToAction("Index", "PacnetStatus", new { Area = "Customer" }));
            }
            catch (OfferExpiredException) {
                this.logRepository.Log(this.context.UserId, DateTime.Now, "Paypoint GetCash Callback", "Falied",
                                       "Invalid apply for a loan period");
                return(RedirectToAction("ErrorOfferDate", "Paypoint", new { Area = "Customer" }));
            }
            catch (PacnetException) {
                try {
                    this.serviceClient.Instance.TransferCashFailed(this.context.User.Id);
                }
                catch (Exception e) {
                    log.Error("Failed to send 'transfer cash failed' email.", e);
                } // try
                return(RedirectToAction("Error", "Pacnet", new { Area = "Customer" }));
            }
            catch (TargetInvocationException) {
                return(RedirectToAction("ErrorOfferDate", "Paypoint", new { Area = "Customer" }));
            }
        }
示例#8
0
        public ActionResult Callback(
            bool valid,
            string trans_id,
            string code,
            string auth_code,
            decimal?amount,
            string ip,
            string test_status,
            string hash,
            string message,
            string type,
            int loanId,
            string card_no,
            string customer,
            string expiry
            )
        {
            if (test_status == "true")
            {
                // Use last 4 random digits as card number (to enable useful tests)
                string random4Digits = string.Format("{0}{1}", DateTime.UtcNow.Second, DateTime.UtcNow.Millisecond);

                if (random4Digits.Length > 4)
                {
                    random4Digits = random4Digits.Substring(random4Digits.Length - 4);
                }

                card_no = random4Digits;

                expiry = string.Format(
                    "{0}{1}",
                    "01",
                    DateTime.UtcNow.AddYears(2).Year.ToString().Substring(2, 2)
                    );
            }             // if

            var customerContext = this.context.Customer;

            PayPointFacade payPointFacade = new PayPointFacade(
                customerContext.MinOpenLoanDate(),
                customerContext.CustomerOrigin.Name
                );

            if (!payPointFacade.CheckHash(hash, Request.Url))
            {
                log.Alert("Paypoint callback is not authenticated for user {0}", customerContext.Id);

                this.logRepository.Log(
                    this.context.UserId,
                    DateTime.UtcNow,
                    "Paypoint Pay Redirect to ",
                    "Failed",
                    String.Format("Paypoint callback is not authenticated for user {0}", customerContext.Id)
                    );

                return(View("Error"));
            }             // if

            var statusDescription = PayPointStatusTranslator.TranslateStatusCode(code);

            if (!valid || code != "A")
            {
                if (code == "N")
                {
                    log.Warn(
                        "Paypoint result code is : {0} ({1}). Message: {2}",
                        code,
                        string.Join(", ", statusDescription.ToArray()),
                        message
                        );
                }
                else
                {
                    log.Alert(
                        "Paypoint result code is : {0} ({1}). Message: {2}",
                        code,
                        string.Join(", ", statusDescription.ToArray()),
                        message
                        );
                }                 // if

                this.logRepository.Log(
                    this.context.UserId,
                    DateTime.UtcNow,
                    "Paypoint Pay Redirect to ",
                    "Failed",
                    string.Format(
                        "Paypoint result code is : {0} ({1}). Message: {2}",
                        code,
                        string.Join(", ", statusDescription.ToArray()),
                        message
                        )
                    );

                return(View("Error"));
            }             // if

            if (!amount.HasValue)
            {
                log.Alert("Paypoint amount is null. Message: {0}", message);

                this.logRepository.Log(
                    this.context.UserId,
                    DateTime.UtcNow,
                    "Paypoint Pay Redirect to ",
                    "Failed",
                    String.Format("Paypoint amount is null. Message: {0}", message)
                    );

                return(View("Error"));
            }             // if

            // If there is transaction with such id in database,
            // it means that customer refreshes page
            // show in this case cashed result
            if (this.paypointTransactionRepository.ByGuid(trans_id).Any())
            {
                var data = TempData.Get <PaymentConfirmationModel>();

                if (data == null)
                {
                    return(RedirectToAction("Index", "Profile", new { Area = "Customer" }));
                }

                return(View(TempData.Get <PaymentConfirmationModel>()));
            }             // if

            NL_Payments nlPayment = new NL_Payments()
            {
                CreatedByUserID   = this.context.UserId,
                Amount            = amount.Value,
                PaymentMethodID   = (int)NLLoanTransactionMethods.CustomerAuto,
                PaymentSystemType = NLPaymentSystemTypes.Paypoint
            };

            log.Debug("Callback: Sending nlPayment: {0} for customer {1}, oldloanId {2}", nlPayment, this.context.UserId, loanId);

            LoanPaymentFacade loanRepaymentFacade = new LoanPaymentFacade();
            PaymentResult     res = loanRepaymentFacade.MakePayment(trans_id, amount.Value, ip, type, loanId, customerContext, null, "payment from customer", null, null, nlPayment);

            SendEmails(loanId, amount.Value, customerContext);

            this.logRepository.Log(this.context.UserId, DateTime.UtcNow, "Paypoint Pay Callback", "Successful", "");

            var refNumber = "";

            bool isEarly = false;

            if (loanId > 0)
            {
                var loan = customerContext.GetLoan(loanId);

                if (loan != null)
                {
                    refNumber = loan.RefNumber;

                    if (loan.Schedule != null)
                    {
                        List <LoanScheduleItem> scheduledPayments = loan.Schedule
                                                                    .Where(
                            x => x.Status == LoanScheduleStatus.StillToPay ||
                            x.Status == LoanScheduleStatus.Late ||
                            x.Status == LoanScheduleStatus.AlmostPaid
                            ).ToList();

                        if (scheduledPayments.Any())
                        {
                            DateTime earliestSchedule = scheduledPayments.Min(x => x.Date);

                            bool scheduleIsEarly = earliestSchedule.Date >= DateTime.UtcNow && (
                                earliestSchedule.Date.Year != DateTime.UtcNow.Year ||
                                earliestSchedule.Date.Month != DateTime.UtcNow.Month ||
                                earliestSchedule.Date.Day != DateTime.UtcNow.Day
                                );

                            if (scheduleIsEarly)
                            {
                                isEarly = true;
                            }
                        } // if
                    }     // if has schedule
                }         // if loan
            }             // if loan id

            if (string.IsNullOrEmpty(customer))
            {
                customer = customerContext.PersonalInfo.Fullname;
            }

            customerContext.TryAddPayPointCard(trans_id, card_no, expiry, customer, payPointFacade.PayPointAccount);

            var confirmation = new PaymentConfirmationModel {
                amount         = amount.Value.ToString(CultureInfo.InvariantCulture),
                saved          = res.Saved,
                savedPounds    = res.SavedPounds,
                card_no        = card_no,
                email          = customerContext.Name,
                surname        = customerContext.PersonalInfo.Surname,
                name           = customerContext.PersonalInfo.FirstName,
                refnum         = refNumber,
                transRefnums   = res.TransactionRefNumbersFormatted,
                hasLateLoans   = customerContext.HasLateLoans,
                isRolloverPaid = res.RolloverWasPaid,
                IsEarly        = isEarly
            };

            TempData.Put(confirmation);
            return(View(confirmation));
        }         // Callback
示例#9
0
        public ActionResult PayPointCallback(
            bool valid,
            string trans_id,
            string code,
            string auth_code,
            decimal?amount,
            string ip,
            string test_status,
            string hash,
            string message,
            string card_no,
            string customer,
            string expiry,
            int customerId
            )
        {
            ms_oLog.Debug(
                "PayPointCallback with args:" +
                "\n\tvalid: '{0}'" +
                "\n\ttrans_id: '{1}'" +
                "\n\tcode: '{2}'" +
                "\n\tauth_code: '{3}'" +
                "\n\tamount: '{4}'" +
                "\n\tip: '{5}'" +
                "\n\ttest_status: '{6}'" +
                "\n\thash: '{7}'" +
                "\n\tmessage: '{8}'" +
                "\n\tcard_no: '{9}'" +
                "\n\tcustomer: '{10}'" +
                "\n\texpiry: '{11}'" +
                "\n\tcustomer id: '{12}'",
                valid,
                trans_id,
                code,
                auth_code,
                amount,
                ip,
                test_status,
                hash,
                message,
                card_no,
                customer,
                expiry,
                customerId
                );

            if (test_status == "true")
            {
                // Use last 4 random digits as card number (to enable useful tests)
                string random4Digits = string.Format("{0}{1}", DateTime.UtcNow.Second, DateTime.UtcNow.Millisecond);

                if (random4Digits.Length > 4)
                {
                    random4Digits = random4Digits.Substring(random4Digits.Length - 4);
                }

                card_no = random4Digits;
                expiry  = string.Format("{0}{1}", "01", DateTime.Now.AddYears(2).Year.ToString().Substring(2, 2));
            }             // if

            if (!valid || code != "A")
            {
                ms_oLog.Debug("Failed to add debit card: invalid or code ain't no 'A'.");

                TempData["code"]    = code;
                TempData["message"] = message;
                return(View(new { error = "Failed to add debit card" }));
            }             // if

            var cust = m_oContext.Customer;

            PayPointFacade payPointFacade = new PayPointFacade(cust.MinOpenLoanDate(), cust.CustomerOrigin.Name);

            if (!payPointFacade.CheckHash(hash, Request.Url))
            {
                ms_oLog.Debug("Failed to add debit card: failed to CheckHash(\n\t hash: '{0}',\n\t Url: '{1}'\n).", hash, Request.Url);

                return(View(new { error = "Failed to add debit card" }));
            }             // if

            cust.TryAddPayPointCard(
                trans_id,
                card_no,
                expiry,
                cust.PersonalInfo.Fullname,
                payPointFacade.PayPointAccount
                );

            bool hasOpenLoans = cust.Loans.Any(x => x.Status != LoanStatus.PaidOff);

            if (amount > 0 && hasOpenLoans)
            {
                Loan loan = cust.Loans.First(x => x.Status != LoanStatus.PaidOff);

                NL_Payments nlPayment = new NL_Payments()
                {
                    Amount          = amount.Value,
                    CreatedByUserID = this.m_oContext.UserId,
                    //	LoanID = nlLoanId,
                    //PaymentStatusID = (int)NLPaymentStatuses.Active,
                    PaymentSystemType = NLPaymentSystemTypes.Paypoint,
                    PaymentMethodID   = (int)NLLoanTransactionMethods.SystemRepay,
                    PaymentTime       = DateTime.UtcNow,
                    Notes             = "add payPoint card",
                    CreationTime      = DateTime.UtcNow
                };

                var f = new LoanPaymentFacade();
                f.PayLoan(loan, trans_id, amount.Value, Request.UserHostAddress, DateTime.UtcNow, "system-repay", false, null, nlPayment);
            }

            if (amount > 0 && !hasOpenLoans)
            {
                this.m_oServiceClient.Instance.PayPointAddedWithoutOpenLoan(cust.Id, cust.Id, amount.Value, trans_id);
            }
            return(View(new { success = true }));
        }         // PayPointCallback