예제 #1
0
        public async Task <ClientResponse> Payment(TransactionCallback transaction)
        {
            try
            {
                if (_wsdlclient != null)
                {
                    return(await _wsdlclient.Payment(transaction));
                }
                if (_restclient != null)
                {
                    RestRequest req = new RestRequest(Method.POST);
                    req.SetJsonContent(transaction);
                    IRestResponse <ClientResponse> resp = await _restclient.ExecuteTaskAsync <ClientResponse>(req);

                    if (resp.Data == null)
                    {
                        throw new ResultCodeException(ResultCodes.ClientServerError, ("en", $"Error executing callback: {resp.StatusCode} {resp.ErrorMessage ?? ""}"), ("es", $"Error ejecutando callback: {resp.StatusCode} {resp.ErrorMessage ?? ""}"));
                    }
                    return(resp.Data);
                }
                throw new ResultCodeException(ResultCodes.SystemError, ("en", "Error executing callback, callback is not configured properly"), ("es", "Error ejecutando callback, el callback no esta configurado correctamente"));
            }
            catch (Exception e)
            {
                ClientResponse r = new ClientResponse();
                r.PopulateFromException(e, Logger);
                return(r);
            }
        }
        private async Task <ClientSignedResponse> SignWrapper <T>(ServerSignedRequest <T> request, Func <T, Task <ClientResponse> > func) where T : IClientCallback
        {
            ServerResponse <T> sins = new ServerResponse <T>();

            try
            {
                PaymentGatewayClient cl = PaymentGatewayClientFactory.GetClient(request.Object.Object.Client);
                if (cl == null)
                {
                    throw new ResultCodeException(ResultCodes.ClientServerError, ("en", $"Unable to locate PaymentGatewayClient for client '{request.Object.Object.Client}'."), ("es", $"No puedo encontrar una clase que defina a PaymentGatewayClient con el client '{request.Object.Object.Client}'."));
                }
                using (var scope = new FlowingOperationContextScope(cl.InnerChannel))
                {
                    sins = await cl.UnwrapRequest(request).ContinueOnScope(scope);
                }
                if (sins.ResultCode != ResultCodes.Ok)
                {
                    return(GenerateError(sins, request.Object.Object.Client));
                }
                if (CallbackImplementation == null)
                {
                    throw new ResultCodeException(ResultCodes.ClientServerError, ("en", "Callback message lost.There is no ICallback implementation"), ("es", "Mensaje del callback pedido. No hay implementacion de ICallback"));
                }
                ClientResponse cr = await func(sins.Response);

                cr.Client = request.Object.Object.Client;
                return(CertificateHelperFactory.Instance.SignClient <ClientSignedResponse, ClientResponse>(cr.Client, cr));
            }
            catch (Exception e)
            {
                sins.PopulateFromException(e, Logger);
                return(GenerateError(sins, request.Object.Object.Client));
            }
        }
 private async Task <ServerResponse> OnlyRunOnIntranet(Func <Task <ServerResponse> > func)
 {
     if (Properties.Settings.Default.EnableTesting)
     {
         return(await func());
     }
     try
     {
         string            ip   = null;
         MessageProperties prop = OperationContext.Current?.IncomingMessageProperties;
         if (prop != null)
         {
             if (prop.ContainsKey(RemoteEndpointMessageProperty.Name))
             {
                 RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                 if (endpoint != null)
                 {
                     ip = endpoint.Address;
                 }
             }
         }
         if (ip == null)
         {
             ip = HttpContext.Current.Request.UserHostAddress;
         }
         if (ip == null)
         {
             throw new ResultCodeException(ResultCodes.SystemError, ("en", "Unable to get incoming ip"), ("es", "No puedo obtener el ip de origen"));
         }
         if (IsIntranet(ip))
         {
             return(await func());
         }
         throw new ResultCodeException(ResultCodes.Forbidden, ("en", "Not allowed to request from Internet"), ("es", "No se puede llamar a este servicio desde internet"));
     }
     catch (Exception e)
     {
         ServerResponse s = new ServerResponse();
         s.PopulateFromException(e, Logger);
         return(s);
     }
 }
예제 #4
0
 public static void PopulateFromException(this ServerResponse resp, ResultCodeException exception, ILog log = null)
 {
     resp.I18NErrorMessages = exception.I18NErrorMessages;
     resp.ErrorMessage      = exception.ErrorMessage;
     resp.ResultCode        = exception.Code;
     if (log != null)
     {
         if (exception.IsErrorLogged || exception.OriginalException != null)
         {
             if (exception.OriginalException != null)
             {
                 log.ErrorException(resp.ErrorMessage, exception.OriginalException);
             }
             else
             {
                 log.ErrorException(resp.ErrorMessage, exception);
             }
         }
         else
         {
             log.Debug(resp.ErrorMessage);
         }
     }
 }