public PairingResponse Pair(string companyKey, Guid orderId, string cardToken, int autoTipPercentage)
        {
            try
            {
                _pairingService.Pair(orderId, cardToken, autoTipPercentage);

                return(new PairingResponse
                {
                    IsSuccessful = true,
                    Message = "Success"
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e);
                return(new PairingResponse
                {
                    IsSuccessful = false,
                    Message = e.Message
                });
            }
        }
Ejemplo n.º 2
0
 public Task <PairingDto> Pair(string name)
 {
     return(pairingService.Pair(name));
 }
Ejemplo n.º 3
0
        public PairingResponse Pair(string companyKey, Guid orderId, string cardToken, int autoTipPercentage)
        {
            try
            {
                if (_serverPaymentSettings.PaymentMode == PaymentMethod.RideLinqCmt)
                {
                    // CMT RideLinq flow

                    var orderStatusDetail = _orderDao.FindOrderStatusById(orderId);
                    if (orderStatusDetail == null)
                    {
                        throw new Exception("Order not found");
                    }

                    var pairingMethod = _serverPaymentSettings.CmtPaymentSettings.PairingMethod;
                    if (pairingMethod == RideLinqPairingMethod.NotSet && companyKey.HasValueTrimmed())
                    {
                        // we are on a company that wasn't migrated to the new pairing method setting, use the old one
                        pairingMethod = _serverPaymentSettings.CmtPaymentSettings.UsePairingCode
                            ? RideLinqPairingMethod.PairingCode
                            : RideLinqPairingMethod.VehicleMedallion;
                    }

                    if (pairingMethod == RideLinqPairingMethod.PairingCode &&
                        !orderStatusDetail.RideLinqPairingCode.HasValue())
                    {
                        // We haven't received the pairing code from IBS yet, set the ignore response false
                        // so that the caller can exit without interpreting the response as a failure
                        return(new PairingResponse {
                            IgnoreResponse = true
                        });
                    }

                    _logger.LogMessage("Starting pairing with RideLinq for Order {0}", orderId);

                    if (orderStatusDetail.IBSOrderId == null)
                    {
                        throw new Exception("Order has no IBSOrderId");
                    }

                    // We need to extract the errorCode and resend it as a pairing response failed if necessary to prevent redoing a pairing after terminal error.
                    var savedPairingErrorCode = CmtErrorCodes.ExtractTerminalError(orderStatusDetail.PairingError);

                    if (savedPairingErrorCode.HasValue)
                    {
                        _logger.LogMessage("An attempt to pair order {0} after previous pairing ended in terminal error has been detected. Returning original pairing error {1}.", orderStatusDetail.OrderId, savedPairingErrorCode);
                        return(new PairingResponse
                        {
                            IsSuccessful = false,
                            ErrorCode = savedPairingErrorCode
                        });
                    }

                    var response = PairWithVehicleUsingRideLinq(pairingMethod, orderStatusDetail, cardToken, autoTipPercentage);

                    if (response.ErrorCode.HasValue)
                    {
                        return(new PairingResponse
                        {
                            IsSuccessful = false,
                            ErrorCode = response.ErrorCode
                        });
                    }

                    // send a command to save the pairing state for this order
                    _commandBus.Send(new PairForPayment
                    {
                        OrderId      = orderId,
                        Medallion    = response.Medallion,
                        DriverId     = response.DriverId.ToString(),
                        PairingToken = response.PairingToken,
                        PairingCode  = response.PairingCode,
                        TokenOfCardToBeUsedForPayment = cardToken,
                        AutoTipPercentage             = autoTipPercentage
                    });

                    return(new PairingResponse
                    {
                        IsSuccessful = true,
                        Message = "Success",
                        PairingToken = response.PairingToken,
                        PairingCode = response.PairingCode,
                        Medallion = response.Medallion,
                        TripId = response.TripId,
                        DriverId = response.DriverId
                    });
                }
                else
                {
                    // Normal CMT flow
                    _pairingService.Pair(orderId, cardToken, autoTipPercentage);

                    return(new PairingResponse
                    {
                        IsSuccessful = true,
                        Message = "Success"
                    });
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e);

                return(new PairingResponse
                {
                    IsSuccessful = false,
                    Message = e.Message,
                    ErrorCode = CmtErrorCodes.UnableToPair
                });
            }
        }