public void CreatePaymentForVisitTest() { PaymentService target = CreateNewPaymentService(); Visit visit = InsertVisit(EntityEnums.VisitStatusEnum.EndSuccess, EntityEnums.PaymentStatusEnum.NotStarted); PaymentCreatePaymentForVisitSP p = new PaymentCreatePaymentForVisitSP(); p.VisitID = visit.VisitID; p.Amount = 100; p.ServiceChargeAmount = 1; target.CreatePaymentForVisit(p); // Making sure that record saved in the database var filter = new FilterExpression(new Filter(vPayment.ColumnNames.AppEntityRecordIDValue, visit.VisitID)); filter.AddFilter(new Filter(vPayment.ColumnNames.AppEntityID, (int)EntityEnums.PaymentEntityEnum.Visit)); var list = target.GetByFilter(new GetByFilterParameters(filter, new SortExpression(), 0, 1, null, GetSourceTypeEnum.View)); DeleteVisit(visit.VisitID); Assert.AreEqual(list.Count, 1); foreach (vPayment payment in list) { Assert.AreEqual(payment.PaymentStatusID, (int)EntityEnums.PaymentStatusEnum.PendingWithoutPayKey); } }
//Please write your properties and functions here. This part will not be replaced. // Doctor selected a visit record, then CreatePaymentForVisit // Patient gets a notification to pay the amount // Patient selected payment method like Paypal (it uses UpdatePayPalKey to get Key from the bank) // Patient pays the money for the payment and // /// <summary> /// Precondition: /// Have Visit record in database with PaymentStatusID = NotStarted /// Steps: /// 1- Select a visit record (visitID) and enter amount and description required /// 2- CreatePaymentForVisit (PaymentStatusID = PendingWithoutPayKey) /// 3- UpdatePayPalKey (payment records in database PaymentStatusID = PendingWithPayKey) /// 4- PaymentReceived (PaymentStatusID = Done) /// </summary> public Payment CreatePaymentForVisit(PaymentCreatePaymentForVisitSP p) { PaymentBR biz = (PaymentBR)this.BusinessLogicObject; IVisitService visitService = (IVisitService)EntityFactory.GetEntityServiceByName(vVisit.EntityName, ""); vVisit visit = (vVisit)visitService.GetByID(p.VisitID, new GetByIDParameters(GetSourceTypeEnum.View)); Visit visitForUpdate = (Visit)visitService.GetByID(p.VisitID, new GetByIDParameters()); biz.CreatePaymentForVisit(visit); Payment paymentForDoctor = new Payment(); paymentForDoctor.SenderUserID = visit.PatientUserID; paymentForDoctor.ReceiverUserID = visit.DoctorID; paymentForDoctor.AppEntityID = (int)EntityEnums.PaymentEntityEnum.Visit; paymentForDoctor.PaymentStatusID = (int)EntityEnums.PaymentStatusEnum.PendingWithoutPayKey; paymentForDoctor.AppEntityRecordIDValue = visit.VisitID; paymentForDoctor.CreatedDateTime = DateTime.UtcNow; paymentForDoctor.CompletedDateTime = null; paymentForDoctor.PayKey = ""; paymentForDoctor.Amount = p.Amount; paymentForDoctor.ServiceChargeAmount = p.ServiceChargeAmount; paymentForDoctor.PaymentMethodID = (int)EntityEnums.PaymentMethodEnum.Undefined; paymentForDoctor.Description = null; InsertParameters insertParameters = new InsertParameters(); //visitForUpdate.PaymentStatusID = (int)EntityEnums.PaymentStatusEnum.PendingWithoutPayKey; DetailObjectInfo visitDetail = new DetailObjectInfo() { EntitySet = visitForUpdate, EntityName = vVisit.EntityName, AdditionalDataKey = "", FnName = RuleFunctionSEnum.Update, FKColumnNameForAutoSet = "" }; insertParameters.DetailEntityObjects.Add(visitDetail); // At this time, we just have one record for each visit. // We don't keep data for each receiver. So, it simplifies the problem. // ServiceChargeAmount is to show how much the user paid to us //Payment paymentForProvider = new Payment(); //paymentForProvider.SenderUserID = visit.PatientUserID; //paymentForProvider.ReceiverUserID = visit.DoctorUserID; //paymentForProvider.PaymentEntityID = (int)EntityEnums.PaymentEntityEnum.Visit; //paymentForProvider.RelatedEntityRecordID = visit.VisitID; //paymentForProvider.CreatedDateTime = DateTime.UtcNow; //paymentForProvider.CompletedDateTime = null; //paymentForProvider.PayKey = ""; //paymentForProvider.Amount = amount; //paymentForProvider.Description = null; //DetailObjectInfo companyPayment = new DetailObjectInfo() { // EntitySet = paymentForProvider, // EntityName = Payment.EntityName, // AdditionalDataKey = this.AdditionalDataKey, // FnName = RuleFunctionSEnum.Insert, // FKColumnNameForAutoSet = "" }; //insertParameters.DetailEntityObjects.Add(companyPayment); Insert(paymentForDoctor, insertParameters); return(paymentForDoctor); }