コード例 #1
0
        public AcquiringBankResponse ProcessPayment(AcquiringBankRequest acquiringBankRequest)
        {
            var result = new AcquiringBankResponse {
                PaymentStatus = "Failed"
            };
            var request = CreateRequest(acquiringBankRequest);

            try
            {
                var response = (HttpWebResponse)request.GetResponse();
                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    var responseString = GetResponseAsString(reader.BaseStream);

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        result.PaymentStatus = responseString;
                    }
                    else
                    {
                        result = JsonConvert.DeserializeObject <AcquiringBankResponse>(responseString);
                    }
                }
            }
            catch (WebException e)
            {
                result.PaymentStatus = e.Message;
            }

            return(result);
        }
コード例 #2
0
        private HttpWebRequest CreateRequest(AcquiringBankRequest postData)
        {
            var request = (HttpWebRequest)WebRequest.Create(_acquiringBankUrl);
            var json    = JsonConvert.SerializeObject(postData);

            request.Method        = "POST";
            request.ContentType   = "application/json";
            request.ContentLength = json.Length;
            using (var writter = new StreamWriter(request.GetRequestStream()))
            {
                writter.Write(json);
            }

            return(request);
        }