Example #1
0
        public ActionResult FormularioHibrido(InfoModel info)
        {
            TPConnector connector = initConnector(info);

            executeSendAuthorizeRequest(connector, info);

            return(View(info));
        }
Example #2
0
        public ActionResult Result(InfoModel info)
        {
            TPConnector connector = initConnector(info);

            if (info.StatusCode == "-1")
            {
                executeGetAuthorizeAnswer(connector, info);
            }

            return(View(info));
        }
Example #3
0
        public void GetEndpointFormProdTest()
        {
            var    headers       = new Dictionary <String, String>();
            string authorization = "TODOPAGO ABCDEF1234567890";

            headers.Add("Authorization", authorization);

            TPConnector connector = new TPConnector(TPConnector.productionEndpoint, headers);

            string endpoint = connector.GetEndpointForm();

            Assert.AreEqual(true, !String.IsNullOrEmpty(endpoint));
            Assert.AreEqual("https://forms.todopago.com.ar/resources/TPHybridForm-v0.1.js", endpoint);
        }
Example #4
0
        private TPConnector InitializeConnector(string ambiente)
        {
            TPConnector connector;

            if (ambiente.Equals("prod"))
            {
                connector = new TPConnector(TPConnector.productionEndpoint);
            }
            else
            {
                connector = new TPConnector(TPConnector.developerEndpoint);
            }

            return(connector);
        }
Example #5
0
        private Dictionary <String, Object> executeSendAuthorizeRequest(TPConnector connector, InfoModel info)
        {
            Dictionary <string, string> sendAuthorizeRequestParams  = new Dictionary <string, string>();
            Dictionary <string, string> sendAuthorizeRequestPayload = new Dictionary <string, string>();
            Dictionary <String, Object> res = new Dictionary <String, Object>();

            initSendAuthorizeRequestParams(sendAuthorizeRequestParams, sendAuthorizeRequestPayload, info);

            try
            {
                res = connector.SendAuthorizeRequest(sendAuthorizeRequestParams, sendAuthorizeRequestPayload);

                if (res.ContainsKey("PublicRequestKey") && res["PublicRequestKey"] != null)
                {
                    info.PublicRequestKey = res["PublicRequestKey"].ToString();
                }

                if (res.ContainsKey("RequestKey") && res["RequestKey"] != null)
                {
                    info.RequestKey = res["RequestKey"].ToString();
                }
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    WebResponse resp = ex.Response;
                    using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
                    {
                        res.Add("exception", "\r\n" + sr.ReadToEnd() + " - " + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                res.Add("exception", "\r\n" + ex.Message);
            }

            return(res);
        }
Example #6
0
        internal CredentialsResponse GetCredentials(User user, string ambiente)
        {
            User resultUser = new User();
            CredentialsResponse response  = new CredentialsResponse();
            TPConnector         connector = InitializeConnector(ambiente);

            try
            {
                resultUser = connector.getCredentials(user);
                string[] securityD = resultUser.getApiKey().Split(' ');
                response.security   = securityD[1];
                response.success    = true;
                response.merchandid = resultUser.getMerchant();
                response.apikey     = resultUser.getApiKey();
            }
            catch (Exception ex)
            {
                response.success = false;
                response.message = ex.Message;
            }

            return(response);
        }
Example #7
0
        protected void TodoPagoConnectorPrepare()
        {
            String authorization = string.Empty;
            var    headers       = new Dictionary <String, String>();

            if (_todoPagoPaymentSettings.Ambiente == Ambiente.Production)
            {
                authorization = _todoPagoPaymentSettings.ApiKeyProduction;
                this.security = _todoPagoPaymentSettings.SecurityProduction;
                this.merchant = _todoPagoPaymentSettings.MerchantProduction;
                headers.Add("Authorization", authorization);
                this.connector = new TPConnector(TPConnector.productionEndpoint, headers);
            }
            else
            {
                authorization = _todoPagoPaymentSettings.ApiKeyDeveloper;
                headers.Add("Authorization", authorization);
                this.security = _todoPagoPaymentSettings.SecurityDeveloper;
                this.merchant = _todoPagoPaymentSettings.MerchantDeveloper;

                this.connector = new TPConnector(TPConnector.developerEndpoint, headers);
            }
        }
Example #8
0
 //Constructor
 public TodoPagoConnectorSample()
 {
     connector = initConnector();
 }
Example #9
0
 //Constructor
 public TodoPagoConnectorSample()
 {
     connector = initConnector();
     //connector = initConnectorForCredetials();
 }
Example #10
0
        private Dictionary <String, Object> executeGetAuthorizeAnswer(TPConnector connector, InfoModel info)
        {
            Dictionary <string, string> getAuthorizeAnswerParams = new Dictionary <string, string>();

            info.ResultadoGAA = String.Empty;

            initGetAuthorizeAnswer(getAuthorizeAnswerParams, info);

            var res = new Dictionary <String, Object>();

            try
            {
                res = connector.GetAuthorizeAnswer(getAuthorizeAnswerParams);

                if (res.ContainsKey("StatusCode") && res["StatusCode"] != null)
                {
                    info.StatusCode = res["StatusCode"].ToString();
                }

                if (res.ContainsKey("StatusMessage") && res["StatusMessage"] != null)
                {
                    info.StatusMessage = res["StatusMessage"].ToString();
                }

                foreach (var key in res.Keys)
                {
                    info.ResultadoGAA += "- " + key + ": " + res[key];
                    if (key.Equals("Payload"))
                    {
                        XmlNode[] aux = (XmlNode[])res["Payload"];
                        if (aux != null)
                        {
                            for (int i = 0; i < aux.Length; i++)
                            {
                                XmlNodeList inner = aux[i].ChildNodes;
                                for (int j = 0; j < inner.Count; j++)
                                {
                                    info.ResultadoGAA += "     " + inner.Item(j).Name + " : " + inner.Item(j).InnerText;
                                }
                            }
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    WebResponse resp = ex.Response;
                    using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
                    {
                        info.ResultadoGAA = sr.ReadToEnd() + " - " + ex.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                info.ResultadoGAA = ex.Message + " - " + ex.InnerException.Message + " - " + ex.HelpLink;
            }

            return(res);
        }