コード例 #1
0
        private bool SettleOverduePayment(Guid orderId, AccountDetail accountDetail, decimal amount, string companyKey, bool isFee, string kountSessionId, string customerIpAddress)
        {
            var payment = _orderPaymentDao.FindByOrderId(orderId, companyKey);
            var reAuth  = payment != null;

            var preAuthResponse = _paymentService.PreAuthorize(companyKey, orderId, accountDetail, amount, reAuth, isSettlingOverduePayment: true);

            if (preAuthResponse.IsSuccessful)
            {
                // Wait for payment to be created
                Thread.Sleep(500);

                var commitResponse = _paymentService.CommitPayment(
                    companyKey,
                    orderId,
                    accountDetail,
                    amount,
                    amount,
                    amount,
                    0,
                    preAuthResponse.TransactionId,
                    preAuthResponse.ReAuthOrderId,
                    false,
                    kountSessionId,
                    customerIpAddress);

                if (commitResponse.IsSuccessful)
                {
                    // Go fetch declined order, and send its receipt
                    var paymentDetail = _orderPaymentDao.FindByOrderId(orderId, companyKey);
                    var promotion     = _promotionDao.FindByOrderId(orderId);

                    var orderDetail = _orderDao.FindById(orderId);

                    decimal tipAmount             = 0;
                    decimal meterAmountWithoutTax = amount;
                    decimal taxAmount             = 0;

                    if (!isFee)
                    {
                        if (!orderDetail.IsManualRideLinq)
                        {
                            var pairingInfo = _orderDao.FindOrderPairingById(orderId);
                            tipAmount = FareHelper.GetTipAmountFromTotalIncludingTip(amount, pairingInfo.AutoTipPercentage ?? _serverSettings.ServerData.DefaultTipPercentage);
                            var meterAmount = amount - tipAmount;

                            var fareObject = FareHelper.GetFareFromAmountInclTax(meterAmount,
                                                                                 _serverSettings.ServerData.VATIsEnabled
                                    ? _serverSettings.ServerData.VATPercentage
                                    : 0);

                            meterAmountWithoutTax = fareObject.AmountExclTax;
                            taxAmount             = fareObject.TaxAmount;
                        }
                        else
                        {
                            var ridelinqOrderDetail = _orderDao.GetManualRideLinqById(orderId);
                            taxAmount             = Convert.ToDecimal(ridelinqOrderDetail.Tax ?? 0);
                            meterAmountWithoutTax = amount - taxAmount;
                            tipAmount             = Convert.ToDecimal(ridelinqOrderDetail.Tip);
                        }
                    }

                    _commandBus.Send(new CaptureCreditCardPayment
                    {
                        IsSettlingOverduePayment = true,
                        NewCardToken             = paymentDetail.CardToken,
                        AccountId              = accountDetail.Id,
                        PaymentId              = paymentDetail.PaymentId,
                        Provider               = _paymentService.ProviderType(companyKey, orderId),
                        TotalAmount            = amount,
                        MeterAmount            = meterAmountWithoutTax,
                        TipAmount              = tipAmount,
                        TaxAmount              = taxAmount,
                        TollAmount             = Convert.ToDecimal(orderDetail.Toll ?? 0),
                        SurchargeAmount        = Convert.ToDecimal(orderDetail.Surcharge ?? 0),
                        AuthorizationCode      = commitResponse.AuthorizationCode,
                        TransactionId          = commitResponse.TransactionId,
                        PromotionUsed          = promotion != null ? promotion.PromoId : default(Guid?),
                        AmountSavedByPromotion = promotion != null ? promotion.AmountSaved : 0,
                        FeeType = isFee ? FeeTypes.Booking : FeeTypes.None
                    });

                    _commandBus.Send(new SettleOverduePayment
                    {
                        AccountId    = accountDetail.Id,
                        OrderId      = orderId,
                        CreditCardId = accountDetail.DefaultCreditCard.GetValueOrDefault()
                    });

                    return(true);
                }

                // Payment failed, void preauth
                _paymentService.VoidPreAuthorization(companyKey, orderId);
            }

            return(false);
        }
コード例 #2
0
        internal BasePaymentResponse CapturePaymentForPrepaidOrder(
            string companyKey,
            Guid orderId,
            AccountDetail account,
            decimal appEstimateWithTip,
            int tipPercentage,
            decimal bookingFees,
            string cvv)
        {
            // Note: No promotion on web
            var tipAmount   = FareHelper.GetTipAmountFromTotalIncludingTip(appEstimateWithTip, tipPercentage);
            var totalAmount = appEstimateWithTip + bookingFees;
            var meterAmount = appEstimateWithTip - tipAmount;

            var preAuthResponse = _paymentService.PreAuthorize(companyKey, orderId, account, totalAmount, isForPrepaid: true, cvv: cvv);

            if (preAuthResponse.IsSuccessful)
            {
                // Wait for payment to be created
                Thread.Sleep(500);

                var commitResponse = _paymentService.CommitPayment(
                    companyKey,
                    orderId,
                    account,
                    totalAmount,
                    totalAmount,
                    meterAmount,
                    tipAmount,
                    preAuthResponse.TransactionId,
                    preAuthResponse.ReAuthOrderId,
                    isForPrepaid: true);

                if (commitResponse.IsSuccessful)
                {
                    var paymentDetail = _orderPaymentDao.FindByOrderId(orderId, companyKey);

                    var fareObject = FareHelper.GetFareFromAmountInclTax(meterAmount,
                                                                         _serverSettings.ServerData.VATIsEnabled
                            ? _serverSettings.ServerData.VATPercentage
                            : 0);

                    _commandBus.Send(new CaptureCreditCardPayment
                    {
                        AccountId         = account.Id,
                        PaymentId         = paymentDetail.PaymentId,
                        Provider          = _paymentService.ProviderType(companyKey, orderId),
                        TotalAmount       = totalAmount,
                        MeterAmount       = fareObject.AmountExclTax,
                        TipAmount         = tipAmount,
                        TaxAmount         = fareObject.TaxAmount,
                        AuthorizationCode = commitResponse.AuthorizationCode,
                        TransactionId     = commitResponse.TransactionId,
                        IsForPrepaidOrder = true,
                        BookingFees       = bookingFees
                    });
                }
                else
                {
                    // Payment failed, void preauth
                    _paymentService.VoidPreAuthorization(companyKey, orderId, true);

                    return(new BasePaymentResponse
                    {
                        IsSuccessful = false,
                        Message = commitResponse.Message
                    });
                }
            }
            else
            {
                return(new BasePaymentResponse
                {
                    IsSuccessful = false,
                    Message = preAuthResponse.Message
                });
            }

            return(new BasePaymentResponse {
                IsSuccessful = true
            });
        }