コード例 #1
0
        public static SendReceipt GetSendReceiptCommand(OrderDetail order, AccountDetail account, int?orderId, string vehicleNumber, DriverInfos driverInfos,
                                                        double?fare, double?toll, double?extra, double?surcharge, double?bookingFees, double?tip, double?tax, OrderPaymentDetail orderPayment = null, double?amountSavedByPromotion = null,
                                                        PromotionUsageDetail promotionUsed = null, CreditCardDetails creditCard = null, SendReceipt.CmtRideLinqReceiptFields cmtRideLinqFields = null)
        {
            var command = new SendReceipt
            {
                Id                 = Guid.NewGuid(),
                OrderId            = order.Id,
                EmailAddress       = account.Email,
                IBSOrderId         = orderId ?? 0,
                PickupDate         = order.PickupDate,
                UtcDropOffDate     = order.DropOffDate,
                VehicleNumber      = vehicleNumber,
                DriverInfos        = driverInfos,
                Fare               = fare.GetValueOrDefault(),
                Extra              = extra.GetValueOrDefault(),
                Tip                = tip.GetValueOrDefault(),
                Tax                = tax.GetValueOrDefault(),
                Toll               = toll.GetValueOrDefault(),
                Surcharge          = surcharge.GetValueOrDefault(),
                BookingFees        = bookingFees.GetValueOrDefault(),
                PickupAddress      = order.PickupAddress,
                DropOffAddress     = order.DropOffAddress,
                ClientLanguageCode = order.ClientLanguageCode,
                CmtRideLinqFields  = cmtRideLinqFields
            };

            if (promotionUsed != null)
            {
                command.AmountSavedByPromotion = amountSavedByPromotion.GetValueOrDefault();
                command.PromoCode          = promotionUsed.Code;
                command.PromoDiscountType  = promotionUsed.DiscountType;
                command.PromoDiscountValue = promotionUsed.DiscountValue;
            }

            if (orderPayment != null)
            {
                command.PaymentInfo = new SendReceipt.Payment(
                    orderPayment.Amount,
                    orderPayment.TransactionId,
                    orderPayment.AuthorizationCode,
                    orderPayment.Type == PaymentType.CreditCard ? "Credit Card" : orderPayment.Type.ToString());

                if ((orderPayment.CardToken.HasValue()) && (creditCard != null))
                {
                    command.PaymentInfo.Last4Digits     = creditCard.Last4Digits;
                    command.PaymentInfo.Company         = creditCard.CreditCardCompany;
                    command.PaymentInfo.NameOnCard      = creditCard.NameOnCard;
                    command.PaymentInfo.ExpirationMonth = creditCard.ExpirationMonth;
                    command.PaymentInfo.ExpirationYear  = creditCard.ExpirationYear;
                }
            }
            return(command);
        }
コード例 #2
0
        private void SendTripReceipt(Guid orderId, decimal meter, decimal tip, decimal tax, decimal amountSavedByPromotion = 0m,
                                     decimal toll = 0m, decimal extra = 0m, decimal surcharge = 0m, decimal bookingFees = 0m, SendReceipt.CmtRideLinqReceiptFields cmtRideLinqFields = null)
        {
            using (var context = _contextFactory.Invoke())
            {
                var order       = _orderDao.FindById(orderId);
                var orderStatus = _orderDao.FindOrderStatusById(orderId);

                if (orderStatus != null)
                {
                    var account      = context.Find <AccountDetail>(orderStatus.AccountId);
                    var orderPayment = context.Set <OrderPaymentDetail>().FirstOrDefault(p => p.OrderId == orderStatus.OrderId && p.IsCompleted);

                    CreditCardDetails card = null;
                    if (orderPayment != null && orderPayment.CardToken.HasValue())
                    {
                        card = _creditCardDao.FindByToken(orderPayment.CardToken);
                    }

                    // Payment was handled by app, send receipt
                    if (orderStatus.IsPrepaid && orderPayment != null)
                    {
                        // Order was prepaid, all the good amounts are in OrderPaymentDetail
                        meter = orderPayment.Meter;
                        tip   = orderPayment.Tip;
                        tax   = orderPayment.Tax;
                    }

                    var promoUsed  = _promotionDao.FindByOrderId(orderId);
                    var ibsOrderId = order.IBSOrderId;


                    decimal fare;
                    if (order.IsManualRideLinq)
                    {
                        var manualRideLinqDetail = context.Find <OrderManualRideLinqDetail>(orderStatus.OrderId);
                        ibsOrderId = manualRideLinqDetail.TripId;

                        fare = meter;
                    }
                    else
                    {
                        if (cmtRideLinqFields != null)
                        {
                            fare = meter;
                        }
                        else
                        {
                            // Meter also contains toll and surcharge, to send an accurate receipt, we need to remove both toll and surcharge.
                            fare = orderPayment.SelectOrDefault(payment => payment.Meter - payment.Toll - surcharge, meter - toll - surcharge);
                        }
                    }

                    if (cmtRideLinqFields != null && cmtRideLinqFields.DriverId.HasValue())
                    {
                        orderStatus.DriverInfos.DriverId = cmtRideLinqFields.DriverId;
                    }

                    var command = SendReceiptCommandBuilder.GetSendReceiptCommand(
                        order,
                        account,
                        ibsOrderId,
                        orderStatus.VehicleNumber,
                        orderStatus.DriverInfos,
                        Convert.ToDouble(fare),
                        Convert.ToDouble(toll),
                        Convert.ToDouble(extra),
                        Convert.ToDouble(surcharge),
                        Convert.ToDouble(bookingFees),
                        orderPayment.SelectOrDefault(payment => Convert.ToDouble(payment.Tip), Convert.ToDouble(tip)),
                        Convert.ToDouble(tax),
                        orderPayment,
                        Convert.ToDouble(amountSavedByPromotion),
                        promoUsed,
                        card,
                        cmtRideLinqFields);

                    _commandBus.Send(command);
                }
            }
        }