Exemple #1
0
        public TrayCheckoutPaymentResponse CriarTransacao(TrayCheckoutPayment tcp, string codpagamento, string opttoken, out string formpost, out string urltrans, out string qstring)
        {
            TrayCheckoutPaymentResponse tcpret = new TrayCheckoutPaymentResponse();

            var form    = formData(tcp, codpagamento, opttoken);
            var content = new FormUrlEncodedContent(form);

            formpost = string.Empty;
            foreach (KeyValuePair <string, string> item in form)
            {
                formpost += item.Key + " " + item.Value + Environment.NewLine;
            }

            qstring = getqueryparam(form);
            //Método pode ser excluido, utilizado apenas para quebrar linha dos dados do form para melhor visualização
            //formatForm(form);
            TrayCheckout tc = new TrayCheckout();

            urltrans = ConfigTrayCheckout.UrlCreateTransaction();
            tc.RequestTrayCheckout(content, string.Format(ConfigTrayCheckout.UrlCreateTransaction(), codpagamento, opttoken));
            if (tc.getHttpStatusCode().Equals(HttpStatusCode.OK))
            {
                XmlDocument xml = new XmlDocument();
                xmlResponse = tc.getContent();
                xml.LoadXml(xmlResponse);
                tc.setXml(xml);
                tcpret = this.BuildRequest(tc);
            }
            return(tcpret);
        }
        private TrayCheckouttransactionRet Notification(out int statusret)
        {
            TrayCheckouttransactionRet rett = new TrayCheckouttransactionRet();

            statusret = 200;
            var form    = formData();
            var content = new FormUrlEncodedContent(form);

            //Método pode ser excluido, utilizado apenas para quebrar linha dos dados do form para melhor visualização
            formatForm(form);
            TrayCheckout tc = new TrayCheckout();

            tc.RequestTrayCheckout(content, ConfigTrayCheckout.UrlGetByToken());
            if (tc.getHttpStatusCode().Equals(HttpStatusCode.OK))
            {
                //Response.StatusCode = 200;
                XmlDocument xml = new XmlDocument();
                xmlResponse = tc.getContent();
                xml.LoadXml(xmlResponse);
                tc.setXml(xml);
                if (!tc.sucessResponse())
                {
                    message = tc.getMessage();
                    rett.lsterros.AddRange(tc.getGeneralError());
                    rett.lsterros.AddRange(tc.getValidationError());
                    statusret = 206;
                }
                else
                {
                    message = tc.getMessage();
                    XmlNodeList transaction = xml.GetElementsByTagName("transaction");
                    rett.order_number   = transaction[0]["order_number"].InnerText;
                    rett.transaction_id = transaction[0]["transaction_id"].InnerText;
                    rett.status_id      = transaction[0]["status_id"].InnerText;
                    rett.status_name    = transaction[0]["status_name"].InnerText;
                    XmlNodeList payment = xml.GetElementsByTagName("payment");
                    rett.price_original              = payment[0]["price_original"].InnerText;
                    rett.payment_response            = payment[0]["payment_response"].InnerText;
                    rett.payment_split               = payment[0]["split"].InnerText;
                    rett.payment_payment_method_id   = payment[0]["payment_method_id"].InnerText;
                    rett.price_original              = payment[0]["price_original"].InnerText;
                    rett.payment_payment_method_name = payment[0]["payment_method_name"].InnerText;
                }
            }
            return(rett);
        }