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));
            }
        }
예제 #2
0
        public static PaymentGatewayClient CreateClientForIssuer(string serverurl, string issuername, int timeout = 120, WebHttpBehavior behavior = null)
        {
            PaymentGatewayClient pgc = Create(serverurl, timeout, behavior);

            pgc._issuerName = issuername;
            return(pgc);
        }
예제 #3
0
        public static PaymentGatewayClient CreateClient(string serverurl, string clientname, int timeout = 120, WebHttpBehavior behavior = null)
        {
            PaymentGatewayClient pgc = Create(serverurl, timeout, behavior);

            pgc._clientName = clientname;
            return(pgc);
        }
예제 #4
0
 public static PaymentGatewayClient GetClient(string clientname)
 {
     lock (Instances)
     {
         if (!Instances.ContainsKey(clientname))
         {
             Instances[clientname] = PaymentGatewayClient.CreateClient(Properties.Settings.Default.PaymentServerUrl, clientname);
         }
         return(Instances[clientname]);
     }
 }
예제 #5
0
 public static PaymentGatewayClient GetIssuer(string issuername)
 {
     lock (InstancesIssuer)
     {
         if (!InstancesIssuer.ContainsKey(issuername))
         {
             InstancesIssuer[issuername] = PaymentGatewayClient.CreateClientForIssuer(Properties.Settings.Default.PaymentServerUrl, issuername);
         }
         return(InstancesIssuer[issuername]);
     }
 }
예제 #6
0
        internal static PaymentGatewayClient Create(string serverurl, int timeout = 120, WebHttpBehavior behavior = null)
        {
            try
            {
                WebHttpBinding binding = new WebHttpBinding();
                binding.OpenTimeout    = TimeSpan.FromSeconds(timeout);
                binding.CloseTimeout   = TimeSpan.FromSeconds(timeout);
                binding.SendTimeout    = TimeSpan.FromSeconds(timeout);
                binding.ReceiveTimeout = TimeSpan.FromSeconds(timeout);
                if (serverurl.StartsWith("https"))
                {
                    binding.Security.Mode = WebHttpSecurityMode.Transport;
                }
                ServiceEndpoint svc = new ServiceEndpoint(ContractDescription.GetContract(typeof(ISecurePaymentGateway)),
                                                          binding, new EndpointAddress(serverurl));
                binding.ContentTypeMapper = new NewtonsoftJsonContentTypeMapper();
                if (behavior == null)
                {
                    behavior = new NewtonsoftJsonBehavior
                    {
                        DefaultBodyStyle              = WebMessageBodyStyle.Bare,
                        DefaultOutgoingRequestFormat  = WebMessageFormat.Json,
                        DefaultOutgoingResponseFormat = WebMessageFormat.Json
                    };
                }
                svc.Behaviors.Add(behavior);

                PaymentGatewayClient pgc = new PaymentGatewayClient(svc);
                return(pgc);
            }
            catch (Exception e)
            {
                Logger.ErrorException("Unable to create PaymentGatewayClient", e);
                throw;
            }
        }