public static void SetFinalPayment(this Job job, FinalizeJobPaymentSM finalize) { //FutureDev: validation job.FinalPayment = new FinalPayment(); job.FinalPayment.Duration = finalize.Duration; job.FinalPayment.Bonus = finalize.Bonus; job.FinalPayment.RatePerHour = job.AcceptedSitter().RatePerHour; job.FinalPayment.PaidToSitter = job.CalculatePaidSitter(job.AcceptedSitter().RatePerHour, finalize.Bonus); job.FinalPayment.PaidByParent = job.FinalPayment.PaidToSitter*LogicConstants.MySitterHubCut; job.State = JobState.Closed; job.PaymentState = PaymentState.ParentInitiated; }
public MakePaymentResultSM FinalizePayment(FinalizeJobPaymentSM finalize) { // STEP - Save Finalize Payment Job job = _jobDal.GetById(finalize.JobId); job.Duration = finalize.Duration; //job.Start = finalize.Start; //TODO: set start time. ValidateFinalize(job, finalize); job.SetFinalPayment(finalize); _jobDal.Update(job); // STEP - Call payment gateway to make payment var sm = new MarketPayment(); sm.Amount = job.FinalPayment.PaidByParent; sm.MySitterHubFee = job.FinalPayment.MySitterHubFee(); sm.ParentId = job.ParentId; sm.SitterId = job.AcceptedSitter().SitterId; MakePaymentResultSM ret = _paymentManager.MakeMarketplaceTransaction(sm); return ret; }
private void ValidateFinalize(Job job, FinalizeJobPaymentSM finalize) { if (job == null) throw new Exception(string.Format("Job with id '{0}' not found.", finalize.JobId)); if (job.ParentId != finalize.UserId) throw new Exception("Unable to finalize job, parentId is not equal to authenticated user."); if (finalize.Bonus < 0) throw new Exception("bonus is less than 0"); if (finalize.Bonus > 200) throw new Exception("bonus is greater than 200"); if (finalize.Duration > 24) throw new Exception("duration is greater than 24 hours"); }
private void generateJobs(int parentId, List<AppUser> sitters) { DateTime currentDate = TimeUtil.GetCurrentUtcTime(); DateTime currentDate5pm = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, 17, 0, 0).ToUniversalTime(); int countJobs = 5; var jobs = new List<Job>(); for (int i = 0; i < countJobs; i++) { // Create Job. var job = new Job { ParentId = parentId, Notes = "note " + i, }; jobs.Add(job); } List<int> sitterIds = sitters.Select(m => m.Id).ToList(); Job j1 = jobs[0]; j1.State = JobState.Closed; j1.Start = currentDate5pm.AddDays(-3); j1.Duration = 5.5m; j1.Notes = "Closed, 3 days in past, paid successfully with finalized payment"; AddInvites(j1, sitterIds, sitterIds[0]); j1.CloseReason = CloseReason.Paid; var finalize = new FinalizeJobPaymentSM(); //finalize.JobId = j1.Id; finalize.UserId = j1.ParentId; finalize.Duration = j1.Duration; finalize.Bonus = 5; j1.SetFinalPayment(finalize); Job j2 = jobs[1]; j2.State = JobState.Accepted; j2.Start = currentDate5pm.AddDays(-2); j2.Notes = "accepted by SitterId " + sitterIds[1]; AddInvites(j2, sitterIds, sitterIds[1]); j2.Duration = 3m; j2.CloseReason = CloseReason.PaidOffline; Job j3 = jobs[2]; j3.State = JobState.Closed; j3.Start = currentDate5pm.AddDays(-1); j3.Duration = 5; j2.Notes = "Closed, parent cancelled. Accepted by SitterId " + sitterIds[0]; AddInvites(j3, sitterIds, sitterIds[0]); j3.CloseReason = CloseReason.ParentCancelled; j3.AcceptedSitterId = sitterIds[0]; Job j4 = jobs[3]; j4.State = JobState.Accepted; j4.Start = currentDate5pm.AddDays(0); j4.Duration = 2.5m; j4.Notes = "Accepted by sitterId " + sitterIds[0]; AddInvites(j4, sitterIds, sitterIds[0]); Job j5 = jobs[4]; j5.State = JobState.Posted; j5.Start = currentDate5pm.AddDays(1); j5.Duration = 2; j5.Notes = "Posted, pending invite Sitter1 (results in real text message), 2nd sitter pending invite, 3rd sitter declines"; j5.JobInvites = new List<JobInvite>(); j5.JobInvites.Add(new JobInvite {SitterId = sitterIds[0], RatePerHour = 8, InvitedDate = j5.Start.AddDays(-1)}); j5.JobInvites.Add(new JobInvite {SitterId = sitterIds[1], RatePerHour = 9, InvitedDate = j5.Start.AddDays(-1)}); j5.JobInvites[1].State = InvitationState.Declined; // STEP Invites, and Insert into DAL for (int i = 0; i < countJobs; i++) { _jobDal.Insert(jobs[i]); } }