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);
        }
Exemple #2
0
        private List <KeyValuePair <string, string> > formData(TrayCheckoutPayment tcp, string codpagamento, string opttoken)
        {
            Random rand = new Random();


            methodPayment = PAYMENT_CARD;
            var list = new List <KeyValuePair <string, string> >();

            list.Add(new KeyValuePair <string, string>("token_account", ConfigTrayCheckout.tokenAccount));
            list.Add(new KeyValuePair <string, string>("transaction[url_notification]", string.Format(ConfigTrayCheckout.urlNotification, codpagamento, opttoken)));
            list.Add(new KeyValuePair <string, string>("transaction[order_number]", tcp.transaction_order_number));

            /*
             *
             *  shipping_type	Texto / 15	Tipo de envio
             *  shipping_price	Decimal / Ex: 0.00	Valor do envio
             */
            //frete
            if (tcp.shipping_price > 0)
            {
                list.Add(new KeyValuePair <string, string>("transaction[shipping_type]", tcp.shipping_type));
                list.Add(new KeyValuePair <string, string>("transaction[shipping_price]", tcp.shipping_price.ToString().Replace(',', '.')));
            }


            list.Add(new KeyValuePair <string, string>("customer[name]", tcp.customer_name));
            list.Add(new KeyValuePair <string, string>("customer[cpf]", tcp.customer_cpf));
            if (!string.IsNullOrEmpty(tcp.customer_email))
            {
                list.Add(new KeyValuePair <string, string>("customer[email]", tcp.customer_email));
            }


            list.Add(new KeyValuePair <string, string>("customer[contacts][][number_contact]", tcp.customer_contacts_number_contact));
            list.Add(new KeyValuePair <string, string>("customer[contacts][][type_contact]", tcp.customer_contacts_type_contact));

            /*type_contact
             * Residencial	H
             * Celular	M
             * Comercial	W
             */
            list.Add(new KeyValuePair <string, string>("customer[addresses][][type_address]", tcp.customer_addresses_type_address));

            /*type_address
             * Cobrança	B
             * Entrega	D
             */
            list.Add(new KeyValuePair <string, string>("customer[addresses][][postal_code]", tcp.customer_addresses_postal_code));

            list.Add(new KeyValuePair <string, string>("customer[addresses][][street]", tcp.customer_addresses_street));
            list.Add(new KeyValuePair <string, string>("customer[addresses][][number]", tcp.customer_addresses_number));
            list.Add(new KeyValuePair <string, string>("customer[addresses][][neighborhood]", tcp.customer_addresses_neighborhood));
            list.Add(new KeyValuePair <string, string>("customer[addresses][][city]", tcp.customer_addresses_city));
            list.Add(new KeyValuePair <string, string>("customer[addresses][][state]", tcp.customer_addresses_state));


            //string price = "";
            // Consulte todas formas de pagamento em: http://wiki.traycheckout.com.br/index.php/Integra%C3%A7%C3%A3o#Tabelas_Auxiliares

            if (tcp.payment_payment_method_id == "6")//boleto
            {
                list.Add(new KeyValuePair <string, string>("payment[payment_method_id]", "6"));
                list.Add(new KeyValuePair <string, string>("payment[split]", "1"));
            }
            else
            {
                /*
                 * Diners Club	2
                 * Visa	3
                 * Mastercard	4
                 * American Express	5
                 * Discover	15
                 * Elo	16
                 * Aura	18
                 * JCB	19
                 * Hipercard	20
                 * Hiper (Itaú)	25
                 */
                list.Add(new KeyValuePair <string, string>("payment[payment_method_id]", tcp.payment_payment_method_id));
                list.Add(new KeyValuePair <string, string>("payment[split]", tcp.payment_split));
                list.Add(new KeyValuePair <string, string>("payment[card_name]", tcp.payment_card_name));
                list.Add(new KeyValuePair <string, string>("payment[card_number]", tcp.payment_card_number));
                list.Add(new KeyValuePair <string, string>("payment[card_expdate_month]", tcp.payment_card_expdate_month));
                list.Add(new KeyValuePair <string, string>("payment[card_expdate_year]", tcp.payment_card_expdate_year));
                list.Add(new KeyValuePair <string, string>("payment[card_cvv]", tcp.payment_card_cvv));
            }
            //else if (methodPayment.Equals(PAYMENT_TRANSFER))
            //{
            //    price = "185.50"; //desconto para pagamento com transferência
            //    list.Add(new KeyValuePair<string, string>("payment[payment_method_id]", "7"));
            //    list.Add(new KeyValuePair<string, string>("payment[split]", "1"));
            //}
            //else if (methodPayment.Equals(PAYMENT_BANK_SLIP))
            //{
            //    price = "180.10"; //desconto para pagamento com boleto
            //    list.Add(new KeyValuePair<string, string>("payment[payment_method_id]", "6"));
            //    list.Add(new KeyValuePair<string, string>("payment[split]", "1"));
            //}

            for (int i = 0; i < tcp.Products.Count; i++)
            {
                list.Add(new KeyValuePair <string, string>("transaction_product[][description]", tcp.Products[i].description));
                list.Add(new KeyValuePair <string, string>("transaction_product[][quantity]", tcp.Products[i].quantity.ToString()));
                list.Add(new KeyValuePair <string, string>("transaction_product[][price_unit]", tcp.Products[i].price_unit.ToString().Replace(',', '.')));
                list.Add(new KeyValuePair <string, string>("transaction_product[][sku_code]", "AF" + tcp.Products[i].sku_code));
                list.Add(new KeyValuePair <string, string>("transaction_product[][code]", tcp.Products[i].sku_code));
            }



            return(list);
        }