示例#1
0
        public BasePaymentResponse UpdateAutoTip(string companyKey, Guid orderId, int autoTipPercentage)
        {
            if (_serverPaymentSettings.PaymentMode != PaymentMethod.RideLinqCmt)
            {
                throw new Exception("This method can only be used with CMTRideLinQ as a payment provider.");
            }

            InitializeServiceClient();

            try
            {
                var orderDetail   = _orderDao.FindById(orderId);
                var accountDetail = _accountDao.FindById(orderDetail.AccountId);
                var orderPairing  = _orderDao.FindOrderPairingById(orderId);

                var request = new ManualRideLinqPairingRequest
                {
                    AutoTipPercentage   = autoTipPercentage,
                    CustomerId          = accountDetail.Id.ToString(),
                    CustomerName        = accountDetail.Name,
                    Latitude            = orderDetail.PickupAddress.Latitude,
                    Longitude           = orderDetail.PickupAddress.Longitude,
                    AutoCompletePayment = true
                };

                _logger.LogMessage("Updating CMT RideLinq auto tip. Request: {0}", request.ToJson());

                var response = _cmtMobileServiceClient.Put(string.Format("init/pairing/{0}", orderPairing.PairingToken), request);

                // Wait for trip to be updated
                _cmtTripInfoServiceHelper.WaitForTipUpdated(orderPairing.PairingToken, autoTipPercentage, response.TimeoutSeconds);

                return(new BasePaymentResponse
                {
                    IsSuccessful = true
                });
            }
            catch (Exception ex)
            {
                _logger.LogMessage("Error when trying to update CMT RideLinq auto tip");
                _logger.LogError(ex);

                return(new BasePaymentResponse
                {
                    IsSuccessful = false,
                    Message = ex.Message
                });
            }
        }
        public async Task <OrderManualRideLinqDetail> PairWithManualRideLinq(string pairingCode, Address pickupAddress, string kountSessionId)
        {
            var request = new ManualRideLinqPairingRequest
            {
                PairingCode        = pairingCode,
                PickupAddress      = pickupAddress,
                ClientLanguageCode = _localize.CurrentLanguage,
                KountSessionId     = kountSessionId,
                CustomerIpAddress  = _ipAddressManager.GetIPAddress()
            };

            try
            {
                var response = await UseServiceClientAsync <ManualPairingForRideLinqServiceClient, ManualRideLinqResponse>(
                    service => RunWithRetryAsync(() => service.Pair(request), TimeSpan.FromSeconds(10), IsExceptionStatusCodeBadRequest, 30));

                if (response.IsSuccessful)
                {
                    UserCache.Set("LastOrderId", response.Data.OrderId.ToString());

                    return(response.Data);
                }

                int errorCode = 0;
                int.TryParse(response.ErrorCode, out errorCode);

                throw new ManualPairingException(errorCode);
            }
            catch (AggregateException ex)
            {
                var badRequestException = ex.InnerExceptions
                                          .Select(exception => exception as WebServiceException)
                                          .Where(exception => exception != null)
                                          .LastOrDefault(webException => webException.StatusCode == (int)HttpStatusCode.BadRequest);

                if (badRequestException != null)
                {
                    throw badRequestException;
                }

                _messageService.ShowMessage(_localize["ManualPairing_TimeOut_Title"], _localize["ManualPairing_TimeOut_Message"]).FireAndForget();

                throw new ManualPairingException();
            }
        }
 public Task <ManualRideLinqResponse> Pair(ManualRideLinqPairingRequest manualRideLinqPairingRequest)
 {
     return(Client.PostAsync <ManualRideLinqResponse>("/account/manualridelinq/pair", manualRideLinqPairingRequest, logger: Logger));
 }