private void RebatePayment(decimal?amount, Loan loan, string transId, DateTime now) { if (amount == null || amount <= 0) { return; } var f = new LoanPaymentFacade(); f.PayLoan(loan, transId, amount.Value, Request.UserHostAddress, now, "system-repay"); }
public void TestPaymentFacade() { try { ILoanRepository loanRep = ObjectFactory.GetInstance<LoanRepository>(); var loan = loanRep.Get(3117); NL_Payments nlPayment = new NL_Payments() { LoanID = 1, Amount = 1000, CreatedByUserID = 1, //this._context.UserId, CreationTime = DateTime.UtcNow, PaymentMethodID = (int)NLLoanTransactionMethods.SystemRepay }; var f = new LoanPaymentFacade(); f.PayLoan(loan, "111", 1000, "11.11.11.11", DateTime.UtcNow, "system-repay", false, null, nlPayment); } catch (Exception ex) { m_oLog.Debug(ex); } }
private bool AddPayPointCardToCustomer(string transactionid, string cardno, EZBob.DatabaseLib.Model.Database.Customer customer, string expiry, decimal?amount, PayPointAccount account) { bool paymentAdded = false; customer.TryAddPayPointCard(transactionid, cardno, expiry, customer.PersonalInfo.Fullname, account); bool hasOpenLoans = customer.Loans.Any(x => x.Status != LoanStatus.PaidOff); if (amount > 0 && hasOpenLoans) { Loan loan = customer.Loans.First(x => x.Status != LoanStatus.PaidOff); var nlPayment = new NL_Payments() { Amount = amount.Value, CreatedByUserID = this.context.UserId, //CreationTime = DateTime.UtcNow, // LoanID = nlLoanId, //PaymentTime = DateTime.UtcNow, Notes = "Add paypoint card", //PaymentStatusID = (int)NLPaymentStatuses.Active, PaymentMethodID = (int)NLLoanTransactionMethods.SystemRepay, PaymentSystemType = NLPaymentSystemTypes.Paypoint }; var f = new LoanPaymentFacade(); f.PayLoan(loan, transactionid, amount.Value, Request.UserHostAddress, DateTime.UtcNow, "system-repay", false, null, nlPayment); paymentAdded = true; } if (amount > 0 && !hasOpenLoans) { this.serviceClient.Instance.PayPointAddedWithoutOpenLoan(customer.Id, this.context.UserId, amount.Value, transactionid); } this.serviceClient.Instance.PayPointAddedByUnderwriter(customer.Id, cardno, this.context.User.FullName, this.context.User.Id); return(paymentAdded); }
public void transaction_balances_are_correctly_updated() { var date = new DateTime(2012, 1, 1); var loan1 = new Loan(); _calculator.Calculate(100, loan1, date); _customer.Loans.Add(loan1); loan1.Status = LoanStatus.Live; _loanRepaymentFacade.PayLoan(loan1, "trans_id", 30, null, date); _loanRepaymentFacade.PayLoan(loan1, "trans_id", 30, null, date); _loanRepaymentFacade.PayLoan(loan1, "trans_id", 40, null, date); Assert.That(loan1.Transactions.Count, Is.EqualTo(3)); var transactions = loan1.Transactions.OrderBy(t => t.PostDate).Cast <PaypointTransaction>().ToList(); Assert.That(transactions[0].Amount, Is.EqualTo(30)); Assert.That(transactions[1].Amount, Is.EqualTo(30)); Assert.That(transactions[2].Amount, Is.EqualTo(40)); }
protected void MakePayment(decimal amount, DateTime date) { Console.WriteLine("Making payment {0} on {1}", amount, date); _facade.PayLoan(_loan, "", amount, "", date); Console.WriteLine(_loan); }
private void MakePayment(Loan loan, decimal amount, DateTime date) { Console.WriteLine("Making payment {0} on {1}", amount, date); _facade.PayLoan(loan, "", amount, "", date); Console.WriteLine(loan); }
//----------------------------------------------------------------------------------- /// <summary> /// Make automatic payment for given installment /// Called from PaypointCharger job /// </summary> /// <param name="customerId"></param> /// <param name="loanId"></param> /// <param name="loanScheduleId">Installment Id</param> /// <param name="amount">Amount to pay</param> /// <returns>PayPointReturnData as a result of call to paypoint API</returns> public PayPointReturnData MakeAutomaticPayment( int customerId, int loanId, int loanScheduleId, decimal amount ) { LoanScheduleRepository installments = (LoanScheduleRepository)ObjectFactory.GetInstance <ILoanScheduleRepository>(); var loanPaymentFacade = new LoanPaymentFacade(); PayPointReturnData payPointReturnData = null; installments.BeginTransaction(); try { var installment = installments.Get(loanScheduleId); var loan = installment.Loan; var customer = loan.Customer; var now = DateTime.UtcNow; NL_Payments nlPayment = new NL_Payments() { Amount = amount, PaymentMethodID = (int)NLLoanTransactionMethods.Auto, PaymentStatusID = (int)NLPaymentStatuses.Active, PaymentSystemType = NLPaymentSystemTypes.Paypoint, CreationTime = now, CreatedByUserID = 1, Notes = "autocharger" }; Log.InfoFormat("Making automatic repayment for customer {0}(#{1}) for amount {2} for loan# {3}({4})", customer.PersonalInfo.Fullname, customer.RefNumber, amount, loan.RefNumber, loan.Id); PayPointCard defaultCard = customer.PayPointCards.FirstOrDefault(x => x.IsDefaultCard); if (defaultCard == null && customer.PayPointCards.Any()) { defaultCard = customer.PayPointCards.First(); } if (defaultCard == null) { // ReSharper disable once ThrowingSystemException throw new Exception("Debit card not found"); } var payPointTransactionId = defaultCard.TransactionId; try { payPointReturnData = RepeatTransactionEx(defaultCard.PayPointAccount, payPointTransactionId, amount); // set real charged amount nlPayment.Amount = amount; } catch (PayPointException ex) { loan.Transactions.Add(new PaypointTransaction { Amount = amount, Description = ex.PaypointData.Message ?? "Exception:" + ex.Message, PostDate = now, Status = LoanTransactionStatus.Error, PaypointId = payPointTransactionId, IP = "", Balance = loan.Balance, Principal = loan.Principal, Loan = loan, LoanTransactionMethod = ObjectFactory.GetInstance <DatabaseDataHelper>().LoanTransactionMethodRepository.FindOrDefault("Auto") }); installments.CommitTransaction(); // save failed NL payment + PP transaction long nlLoanId = ObjectFactory.GetInstance <IEzServiceAccessor>().GetLoanByOldID(loanId, customerId); if (nlLoanId > 0) { nlPayment.Amount = 0; nlPayment.PaymentStatusID = (int)NLPaymentStatuses.Error; nlPayment.PaypointTransactions.Clear(); nlPayment.PaypointTransactions.Add(new NL_PaypointTransactions() { TransactionTime = now, Amount = amount, // in the case of Exception amount should be 0 ???? Notes = ex.PaypointData.Message ?? "Exception:" + ex.Message, PaypointTransactionStatusID = (int)NLPaypointTransactionStatuses.Error, IP = string.Empty, PaypointUniqueID = payPointTransactionId, PaypointCardID = defaultCard.Id }); Log.InfoFormat("Failed Paypoint transaction: customerId={0} loanID = {1}, loanScheduleId={2} amount={3}; nlPayment={4}", customerId, loanId, loanScheduleId, amount, nlPayment); ObjectFactory.GetInstance <IEzServiceAccessor>().AddPayment(loan.Customer.Id, nlPayment); } return(ex.PaypointData); } installments.CommitTransaction(); loanPaymentFacade.PayLoan(loan, payPointReturnData.NewTransId, amount, null, now, "auto-charge", false, null, nlPayment); } catch (Exception e) { if (!(e is PayPointException)) { Log.Error(e); } if (payPointReturnData == null) { payPointReturnData = new PayPointReturnData { Error = e.Message } } ; installments.RollbackTransaction(); } return(payPointReturnData); }
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
private static void MakeEarlyPayment(Loan loan, decimal amount, DateTime startDate) { var facade = new LoanPaymentFacade(); facade.PayLoan(loan, "", amount, "", startDate); }
private void CallPayLoan(decimal amountDue, LoanScheduleItem installment, DateTime date) { _facade.PayLoan(_loan, "", amountDue, "", date); }