public PaymentDto CreateRefundForOrder(PaymentDto paymentDto, long businessId) { Payment payment = CreatePayment(paymentDto, PaymentStatusEnum.Created, PaymentTypeEnum.Refund, businessId); //return updated payment Dto return Mapper.Map<PaymentDto>(payment); }
public void VerifyIfDeletedPaymentIsSuccessful() { // Arrange var paymentDto = new PaymentDto { Id = 1, Amount = new decimal(10.00), ReceivedDate = DateTime.Today, Currency = new CurrencyDto { ISOCode = "GBP" }, PaymentMethod = new PaymentMethodDto { Code = PaymentMethodEnum.CreditCard.GetCode() }, PaymentSource = new PaymentSourceDto { Code = PaymentSourceEnum.Pms.GetCode() }, CardType = new CardTypeDto { Code = CardTypeEnum.Visa.GetCode() }, CardLast4Digits = "1234", PaymentName = "John", Notes = "New Payment" }; var existingPayment = new Model.Booking.Payment { Id = 1, Amount = new decimal(10.00), ReceivedDate = DateTime.Today, Currency = new Currency("GBP"), PaymentMethod = new PaymentMethod(), PaymentSource = new PaymentSource(), CardType = new CardType(), PaymentStatus = new PaymentStatus(), PaymentType = new PaymentType(), Notes = "New Payment" }; var paymentManager = MockRepository.GenerateStub<IPaymentManager>(); paymentManager.Expect(x => x.GetPaymentByKey(paymentDto.Id)).Return(existingPayment); paymentManager.Expect(x => x.DeletePayment(Arg<Model.Booking.Payment>.Is.Anything)).Return(true); PropertyManagementSystemService.PaymentManager = paymentManager; // Act var result = PropertyManagementSystemService.DeletePaymentForOrder(paymentDto); // Assert Assert.IsTrue(result, "The payment wasn't deleted"); }
public void CreateRefundForBookingCreatesRefund() { // Arrange var paymentDto = new PaymentDto { Amount = new decimal(10.00), ReceivedDate = DateTime.Today, Currency = new CurrencyDto { ISOCode = "GBP" }, PaymentMethod = new PaymentMethodDto { Code = PaymentMethodEnum.CreditCard.GetCode() }, PaymentSource = new PaymentSourceDto { Code = PaymentSourceEnum.Pms.GetCode() }, CardType = new CardTypeDto { Code = CardTypeEnum.Visa.GetCode() }, CardLast4Digits = "1234", PaymentName = "Johno", Notes = "New Payment" }; var newPayment = new Model.Booking.Payment { Amount = new decimal(10.00), ReceivedDate = DateTime.Today, Currency = new Currency("GBP"), PaymentMethod = new PaymentMethod(), PaymentSource = new PaymentSource(), CardType = new CardType(), PaymentStatus = new PaymentStatus(), PaymentType = new PaymentType(), Notes = "New Payment" }; var paymentManager = MockRepository.GenerateMock<IPaymentManager>(); paymentManager.Expect(x => x.CreatePaymentForOrder(Arg<Model.Booking.Payment>.Is.Anything, Arg<long>.Is.Anything)); paymentManager.Expect(x => x.GetPaymentByKey(Arg<int>.Is.Anything)).Return(newPayment); PropertyManagementSystemService.PaymentManager = paymentManager; // Act PropertyManagementSystemService.CreateRefundForOrder(paymentDto, 1); // Assert paymentManager.VerifyAllExpectations(); }
public void CreatePaymentForBookingInvalidPaymentMethodThrowsValidationException() { // Arrange var paymentDto = new PaymentDto { Amount = new decimal(10.00), ReceivedDate = DateTime.Today, Currency = new CurrencyDto { ISOCode = "GBP" }, PaymentMethod = new PaymentMethodDto { Code = "ABC" }, PaymentSource = new PaymentSourceDto { Code = PaymentSourceEnum.Pms.GetCode() }, CardType = new CardTypeDto { Code = CardTypeEnum.Visa.GetCode() }, CardLast4Digits = "1234", PaymentName = "Johno", Notes = "New Payment" }; try { // Act PropertyManagementSystemService.CreatePaymentForOrder(paymentDto, 1); // Assert Assert.Fail("An exception SRVEX30083 of type ValidationException should have been thrown"); } catch (AutoMapperMappingException ex) { if (ex.InnerException == null | !ex.InnerException.Message.Contains("is invalid for Enum type 'PaymentMethodEnum'")) { // Assert Assert.Fail("The mapping exception is not returning the right error message"); } } }
public bool DeletePaymentForOrder(PaymentDto paymentDto) { //make sure payment object is valid if (paymentDto == null) { throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30072, "PropertyManagementSystemService.DeletePaymentForOrder")); } //see if the payment we're trying to delete exists Payment payment = paymentManager.GetPaymentByKey(paymentDto.Id); if (payment == null) { throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30106, "PropertyManagementSystemService.DeletePaymentForOrder")); } return paymentManager.DeletePayment(payment); }
/// <summary> /// This method contains the base service logic needed to make a payment /// </summary> /// <param name="paymentDto">Payment Dto</param> /// <param name="paymentStatus">Payment Status</param> /// <param name="paymentType">Payment Type</param> private Payment CreatePayment(PaymentDto paymentDto, PaymentStatusEnum paymentStatus, PaymentTypeEnum paymentType, long businessId) { Payment payment; //make sure payment object is valid if (paymentDto == null) { throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30072, "PropertyManagementSystemService.CreatePayment")); } // Convert to Model try { payment = Mapper.Map<Payment>(paymentDto); } catch (InvalidEnumArgumentException ex) { throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30083, "PropertyManagementSystemService.CreatePayment", additionalDescriptionParameters: (new object[] { ex.Message }))); } payment.PaymentStatusEnum = paymentStatus; payment.PaymentTypeEnum = paymentType; //Create the payment paymentManager.CreatePaymentForOrder(payment, businessId); return paymentManager.GetPaymentByKey(payment.Id); }