Beispiel #1
0
        private void HandleOnePayment(LoanAutoChargeModel loan, NLLoanAutoChargeModel nlLoan = null)
        {
            string   message;
            int      loanScheduleId    = loan.LoanScheduleId;
            int      loanId            = loan.LoanId;
            int      customerId        = loan.CustomerId;
            string   customerMail      = loan.Email;
            string   fullname          = loan.Fullname;
            string   typeOfBusinessStr = loan.TypeOfBusiness;
            DateTime dueDate           = loan.DueDate;         // PlannedDate
            bool     reductionFee      = loan.ReductionFee;
            string   refNum            = loan.RefNum;          // of loan
            bool     lastInstallment   = loan.LastInstallment; // bit

            TypeOfBusiness typeOfBusiness = (TypeOfBusiness)Enum.Parse(typeof(TypeOfBusiness), typeOfBusinessStr);
            bool           isNonRegulated = IsRegulated(typeOfBusiness);

            DateTime now      = DateTime.UtcNow;
            TimeSpan span     = now.Subtract(dueDate);
            int      daysLate = (int)span.TotalDays;

            // amount due.
            decimal amountDue = this.payPointApi.GetAmountToPay(loanScheduleId);

            if (nlLoan == null)
            {
                NL_AddLog(LogType.Info, string.Format("nlloan for oldLoan {0} not found", loanId), this.strategyArgs, null, null, null);
            }
            else
            {
                // new loan amount due.
                decimal nlAmountDue = GetAmountToPay(nlLoan.CustomerId, nlLoan.LoanId, nlLoan.LoanScheduleId);

                message = string.Format("LoanID={0} oldLoanID={1} amountDue= {2} nlAmountDue={3}", nlLoan.LoanId, nlLoan.OldLoanID, amountDue, nlAmountDue);
                Log.Debug(message);
                NL_AddLog(LogType.Info, "AmountDue", this.strategyArgs, message, null, null);
            }

            if (!ShouldCharge(lastInstallment, amountDue))
            {
                message = string.Format("Will not charge loan schedule id {0} (amount {1}): the minimal amount for collection is {2}.", loanScheduleId, amountDue, this.amountToChargeFrom);
                Log.Info(message);
                NL_AddLog(LogType.Info, "Exit 1", this.strategyArgs, message, null, null);
                return;
            }            //if

            decimal initialAmountDue = amountDue;

            if ((!isNonRegulated && daysLate > 3) || !this.dueChargingDays.Contains(daysLate))
            {
                message = string.Format("Will not charge loan schedule id {0} (amount {1}): the charging is not scheduled today", loanScheduleId, amountDue);
                Log.Info(message);
                NL_AddLog(LogType.Info, "Exit 2", this.strategyArgs, message, null, null);
                return;
            }

            // step 2 - charging
            AutoPaymentResult autoPaymentResult = TryToMakeAutoPayment(
                loanId,
                loanScheduleId,
                initialAmountDue,
                customerId,
                customerMail,
                fullname,
                reductionFee,
                isNonRegulated
                );

            if (autoPaymentResult.IsException || autoPaymentResult.PaymentFailed)
            {
                Error = string.Format("Failed collection from customer:{0} amount:{1}, loanID={2}", customerId, initialAmountDue, loanId);
                Log.Warn(Error);
                NL_AddLog(LogType.Info, "Exit 3", this.strategyArgs, Error, null, null);
                return;
            }             // if

            // step 4 - notifications
            if (autoPaymentResult.PaymentCollectedSuccessfully)
            {
                // send mail to customer from template "Mandrill - Repayment confirmation"
                PayEarly payEarly = new PayEarly(customerId, autoPaymentResult.ActualAmountCharged, refNum);
                payEarly.Execute();

                SendLoanStatusMail(customerId, loanId, customerMail, autoPaymentResult.ActualAmountCharged); // Will send mail for paid off loans
            }                                                                                                //if
        }                                                                                                    //HandleOnePayment
Beispiel #2
0
        public void PayEarly()
        {
            var s = new PayEarly(3060, 2500, "dfsgfsdg");

            s.Execute();
        }