public iDealResponse SendRequest(iDealRequest idealRequest, ISignatureProvider signatureProvider, string url,
            IiDealHttpResponseHandler iDealHttpResponseHandler)
        {
            ServicePointManager.ServerCertificateValidationCallback =
                ((sender, certificate, chain, sslPolicyErrors) => true);

            // Create request
            var request = (HttpWebRequest) WebRequest.Create(url);
            request.ProtocolVersion = HttpVersion.Version11;
            request.ContentType = "text/xml";
            request.Method = "POST";
            // request.Proxy = new WebProxy("192.168.1.8", 8080);

            // Set content
            string xml = idealRequest.ToXml(signatureProvider);
            byte[] postBytes = Encoding.ASCII.GetBytes(xml);

            // Send
            using (Stream requestStream = request.GetRequestStream())
            {
                requestStream.Write(postBytes, 0, postBytes.Length);
            }

            // Return result
            using (WebResponse response = request.GetResponse())
            {
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    return iDealHttpResponseHandler.HandleResponse(reader.ReadToEnd(), signatureProvider);
                }
            }
        }
        public iDealResponse SendRequest(iDealRequest idealRequest, ISignatureProvider signatureProvider, string url, IiDealHttpResponseHandler iDealHttpResponseHandler)
        {
            // Create request
            var request = (HttpWebRequest)WebRequest.Create(url);
            request.ProtocolVersion = HttpVersion.Version11;
            request.ContentType = "text/xml";
            request.Method = "POST";

            // Set content
            var postBytes = Encoding.ASCII.GetBytes(idealRequest.ToXml(signatureProvider));

            // Send
            var requestStream = request.GetRequestStream();
            requestStream.Write(postBytes, 0, postBytes.Length);
            requestStream.Close();

            // Return result
            var response = (HttpWebResponse)request.GetResponse();
            return iDealHttpResponseHandler.HandleResponse(new StreamReader(response.GetResponseStream()).ReadToEnd(), signatureProvider);
        }
Exemple #3
0
        public iDealService(IConfiguration configuration, ISignatureProvider signatureProvider,
            IiDealHttpRequest iDealHttpRequest, IiDealHttpResponseHandler iDealHttpResponseHandler)
        {
            // Configuration guard clauses
            if (string.IsNullOrWhiteSpace(configuration.MerchantId))
            {
                throw new ConfigurationErrorsException("Merchant Id is not set");
            }
            if (configuration.MerchantId.Length > 9)
            {
                throw new ConfigurationErrorsException("Merchant Id cannot contain more as 9 characters");
            }
            if (configuration.MerchantSubId < 0 || configuration.MerchantSubId > 6)
            {
                throw new ConfigurationErrorsException("SubId must contain a value ranging from 0 to 6");
            }
            if (string.IsNullOrWhiteSpace(configuration.AcquirerUrl))
            {
                throw new ConfigurationErrorsException("Url of acquirer is not set");
            }
            if (configuration.AcceptantCertificate == null)
            {
                throw new ConfigurationErrorsException("Acceptant's certificate is not set");
            }
            if (!configuration.AcceptantCertificate.HasPrivateKey)
            {
                throw new ConfigurationErrorsException("Acceptant's certificate does not contain private key");
            }
            if (configuration.AcquirerCertificate == null)
            {
                throw new ConfigurationErrorsException("Acquirer's certificate is not set");
            }

            this.configuration = configuration;
            this.signatureProvider = signatureProvider;
            this.iDealHttpRequest = iDealHttpRequest;
            this.iDealHttpResponseHandler = iDealHttpResponseHandler;
        }