コード例 #1
0
        /// <summary>
        /// Make a payment
        /// It is with this resource that we carry out our purchases.
        /// The checkout resource is used when we want to make a payment from A (buyer) to B (seller) and its validation depends on the stimulus of A.
        /// A checkout has a monetary value in currency (value), acronym for currency (currency), blockchain for transaction (blockchain),
        /// card number (pan), card password (password) and vendor identifier (vendorKey)
        /// </summary>
        /// <param name="makePayment"></param>
        /// <returns>Checkout</returns>
        public Checkout MakePayment(MakePayment makePayment)
        {
            try
            {
                //Convert to Sha256
                makePayment.pan      = Converts.ComputeSha256Hash(makePayment.pan);
                makePayment.password = Converts.ComputeSha256Hash(makePayment.password);

                string urlBase = this.SandBox ? GlobalType.URL_BASE_SANDBOX : GlobalType.URL_BASE_DEFAULT;

                string strJson = JsonConvert.SerializeObject(makePayment);

                byte[] buffer = Encoding.UTF8.GetBytes(strJson);

                HttpWebRequest httpWebRequest = HttpWebRequest.CreateHttp(urlBase + GlobalType.URL_CHECKOUT);
                httpWebRequest.Method        = "POST";
                httpWebRequest.Accept        = "application/json";
                httpWebRequest.ContentType   = "application/json";
                httpWebRequest.ContentLength = buffer.Length;
                httpWebRequest.GetRequestStream().Write(buffer, 0, buffer.Length);

                using (HttpWebResponse objResponse = httpWebRequest.GetResponse() as HttpWebResponse)
                {
                    using (StreamReader strReader = new StreamReader(objResponse.GetResponseStream()))
                        return(JsonConvert.DeserializeObject <Checkout>(strReader.ReadToEnd()));
                }
            }
            catch (Exception ex)
            {
                return(new Checkout()
                {
                    status = new Status()
                    {
                        code = "-1", message = ex.Message
                    }
                });
            }
        }