{"action":"opened","issue":{"url":"https://api.github.com/repos/culqi/culqi-php/issues/1","labels_url":"https://api.github.com/repos/culqi/culqi-php/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/culqi/culqi-php/issues/1/comments","events_url":"https://api.github.com/repos/culqi/culqi-php/issues/1/events","html_url":"https://github.com/culqi/culqi-php/issues/1","id":118498451,"number":1,"title":"Sugiero una mejora para el codigo del javascript","user":{"login":"CarlosZarate","id":1760164,"avatar_url":"https://avatars.githubusercontent.com/u/1760164?v=3","gravatar_id":"","url":"https://api.github.com/users/CarlosZarate","html_url":"https://github.com/CarlosZarate","followers_url":"https://api.github.com/users/CarlosZarate/followers","following_url":"https://api.github.com/users/CarlosZarate/following{/other_user}","gists_url":"https://api.github.com/users/CarlosZarate/gists{/gist_id}","starred_url":"https://api.github.com/users/CarlosZarate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CarlosZarate/subscriptions","organizations_url":"https://api.github.com/users/CarlosZarate/orgs","repos_url":"https://api.github.com/users/CarlosZarate/repos","events_url":"https://api.github.com/users/CarlosZarate/events{/privacy}","received_events_url":"https://api.github.com/users/CarlosZarate/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-23T23:31:41Z","updated_at":"2015-11-23T23:31:41Z","closed_at":null,"body":"```javascript\r\nfunction CulqiCheckout($params) {\r\n\r\n    var closeCallback = $params.callback,\r\n        codigo_comercio = $params.comerce_id,\r\n        informacion_venta = \"\",\r\n        respuesta = \"\",\r\n        iframe = null;\r\n\r\n    window.addEventListener(\"message\", receiveMessage, false);\r\n\r\n    return {\r\n        abrir:      abrir,\r\n        autorizado: autorizado,\r\n        denegado:   denegado,\r\n        cerrar:     cerrar,\r\n        setInformation: setInformation\r\n    };\r\n\r\n    function setInformation(information)\r\n    {\r\n        informacion_venta = information;\r\n    }\r\n\r\n    function abrir() {\r\n\r\n        if (informacion_venta == \"\") {\r\n\r\n            alert(\"Intente nuevamente. Si el problema persiste, contáctese con el Comercio.\");\r\n\r\n        } else {\r\n            var product = \"web\";\r\n            var url = \"/api/v1/form/\" + product + \"/\" + codigo_comercio + \"/\" + informacion_venta;\r\n            iframe = document.createElement(\"IFRAME\");\r\n\r\n            iframe.setAttribute(\"src\", \"https://integ-pago.culqi.com\" + url);\r\n\r\n            iframe.setAttribute(\"id\", \"culqi_checkout_frame\");\r\n            iframe.setAttribute(\"name\", \"checkout_frame\");\r\n            iframe.setAttribute(\"class\", \"culqi_checkout\");\r\n            iframe.setAttribute(\"allowtransparency\", \"true\");\r\n            iframe.setAttribute(\"frameborder\", \"0\");\r\n\r\n            iframe.style.zIndex = 99999;\r\n            iframe.style.display = \"block\";\r\n            iframe.style.backgroundColor = \"rgba(0,0,0,0)\";\r\n            iframe.style.border = \"0px none trasparent\";\r\n            iframe.style.overflowX = \"hidden\";\r\n            iframe.style.overflowY = \"auto\";\r\n            iframe.style.visibility = \"visible\";\r\n            iframe.style.margin = \"0px\";\r\n            iframe.style.position = \"fixed\";\r\n            iframe.style.left = \"0px\";\r\n            iframe.style.top = \"0px\";\r\n            iframe.style.width = \"100%\";\r\n            iframe.style.height = \"100%\";\r\n            iframe.style.backgroundPosition = \"initial initial\";\r\n            iframe.style.backgroundRepeat = \"initial initial\";\r\n            document.body.appendChild(iframe);\r\n        }\r\n    }\r\n\r\n    function autorizado() {\r\n\r\n        iframe = document.getElementById('culqi_checkout_frame');\r\n        iframe.contentWindow.postMessage(\"autorizado\", \"*\");\r\n    }\r\n\r\n    function denegado() {\r\n        iframe = document.getElementById('culqi_checkout_frame');\r\n        iframe.contentWindow.postMessage(\"denegado\", \"*\");\r\n    }\r\n    function cerrar() {\r\n        var element = document.getElementById(\"culqi_checkout_frame\");\r\n        if (element == null){\r\n        } else {\r\n            element.parentNode.removeChild(element);\r\n        }\r\n    }\r\n\r\n    function receiveMessage(event){\r\n\r\n        if(event.data == \"checkout_cerrado\"){\r\n\r\n            respuesta = event.data;\r\n            closeCallback(respuesta);\r\n            cerrar();\r\n//console.log(\"Cerrando checkout:\" + event.data);\r\n\r\n        } else {\r\n            respuesta = event.data;\r\n//console.log(\"Informacion recibida desde el checkout:\" + event.data);\r\n            closeCallback(respuesta);\r\n        }\r\n\r\n    }\r\n\r\n}\r\n```"}}