public void AddQueueItemIsSuccessful() { var queueDaoMock = new Mock<IQueueDao>(); var payment = new Model.Booking.Payment { OrderId = 5, CreatedByUserId = new Guid("00000000-0000-0000-0000-000000000000") }; var invoiceRequest = new SettlementInvoiceRequest { BusinessId = 10, OrderId = payment.OrderId, BookingId = 2, OrderSourceCode = SourceType.Online.GetCode() }; queueDaoMock.Setup(q => q.AddQueueItem(It.Is<QueueItem>(qi => qi.PayloadType == PayloadTypeEnum.BookingInv && qi.QueueCode == QueueCodeType.SettlementInvoiceRequest && qi.UserId == payment.CreatedByUserId && qi.Key == payment.OrderId.ToString() && qi.Payload.IndexOf("10") > 0))).Returns(new QueueItem()); QueueManager manager = new QueueManager { QueueDao = queueDaoMock.Object }; QueueItem item = new PaymentManager().GetSettlementQueueItemFromPayment(payment, invoiceRequest); manager.AddQueueItem(item); queueDaoMock.VerifyAll(); }
/// <summary> /// Add a queueItem based on the payment and invoice request /// </summary> /// <param name="payment">payment information</param> /// <param name="payload">invoice request</param> /// <returns>queue item with id set</returns> virtual internal QueueItem GetSettlementQueueItemFromPayment(Payment payment, SettlementInvoiceRequest payload) { QueueItem queItem = null; if (payload.IsValid()) { // create queue item from payment sent in queItem = new QueueItem { Key = payment.OrderId.ToString(), PayloadType = PayloadTypeEnum.BookingInv, QueueCode = QueueCodeType.SettlementInvoiceRequest, UserId = payment.CreatedByUserId, Payload = XmlSerialization.XmlSerializeToString(payload) }; } return queItem; }
/// <summary> /// Create the eagle payment and queue item for settlement after payment through service /// </summary> /// <param name="result">result of payment service</param> /// <param name="order">order paid to with bookings</param> /// <param name="note">note for payment</param> /// <returns>true if successful</returns> internal bool CreatePaymentAndQueueToSettlement(PreAuthPaymentResult result, Model.Order.Order order, string note) { if (result.Success) { if (order != null) { Model.Booking.Booking firstBooking = order.Bookings.FirstOrDefault(); var paymentType = result.Amount > 0 ? PaymentTypeEnum.Payment : PaymentTypeEnum.Refund; Payment payment = new Payment { Amount = result.Amount, OrderId = order.Id.Value, CreatedByUserId = order.UpdatedByUserId, PaymentMethodEnum = PaymentMethodEnum.CreditCard, // assume credit card for now PaymentMethod = new PaymentMethod { Code = PaymentMethodEnum.CreditCard.GetCode() }, CardLast4Digits = result.LastCardDigits, PaymentSource = new PaymentSource { Code = PaymentSourceEnum.Online.GetCode() }, PaymentSourceEnum = PaymentSourceEnum.Online, PaymentType = new PaymentType { Code = paymentType.GetCode() }, PaymentTypeEnum = paymentType, PaymentStatus = new PaymentStatus { Code = PaymentStatusEnum.Created.GetCode() }, PaymentStatusEnum = PaymentStatusEnum.Created, Currency = new Model.Common.Currency(order.CustomerCurrencyCode, string.Empty, string.Empty, 2), ReceivedDate = result.TransactionDate, MerchantType = null, // needs to be null in order to be filled in when being created Notes = note, TransactionSequence = result.Sequence }; CardTypeEnum cardType = CardType.ConvertOgoneCardTypeToEagleCardType(result.CardTypeCode); payment.CardType = cardType != CardTypeEnum.Unknown ? new CardType {Code = cardType.GetCode()} : null; // add this payment to the order CreatePaymentForOrder(payment, firstBooking.BusinessId); SettlementInvoiceRequest invoiceRequest = new SettlementInvoiceRequest { OrderSourceCode = order.OrderSourceCode, BusinessId = firstBooking.BusinessId, BookingId = firstBooking.Id.Value, OrderId = order.Id.Value }; QueueItem queItem = GetSettlementQueueItemFromPayment(payment, invoiceRequest); if (queItem == null || queueManager.AddQueueItem(queItem) == null) { // failed to create the queue item throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30139, "PaymentManager.ChargePreAuth", additionalDescriptionParameters: new object[] { order.OrderReference }, arguments: new object[] { order.OrderReference })); } return true; } } return false; }