From 1a09ee7289bf61270ef80910f7e918afa31c9b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Beltra=CC=81n=20Soli=CC=81s?= Date: Thu, 20 Dec 2018 18:45:12 -0600 Subject: [PATCH 1/2] Update and integrate ComproPago PHP-SDK 5.0 Update ComproPago SDK Fix cash create order Update README.md Add access to ComproPago panel in settings Fix javascript error on create order Add files for translation --- .gitignore | 5 + README.md | 34 + .../extension/payment/compropago_cash.php | 515 +-- .../extension/payment/compropago_spei.php | 459 ++- .../extension/payment/compropago_cash.php | 25 +- .../extension/payment/compropago_spei.php | 19 +- .../extension/payment/compropago_cash.php | 44 + .../extension/payment/compropago_spei.php | 43 + .../extension/payment/compropago_cash.php | 23 +- .../extension/payment/compropago_cash.twig | 369 +- .../extension/payment/compropago_spei.twig | 254 +- .../extension/payment/compropago.php | 593 +-- .../extension/payment/compropago_cash.php | 264 +- .../extension/payment/compropago_spei.php | 437 +- .../en-gb/extension/payment/compropago.php | 9 +- .../extension/payment/compropago_cash.php | 5 +- .../extension/payment/compropago_spei.php | 10 +- .../es-mx/extension/payment/compropago.php | 10 + .../extension/payment/compropago_cash.php | 15 + .../extension/payment/compropago_spei.php | 9 + .../extension/payment/compropago_cash.php | 30 +- .../extension/payment/compropago_spei.php | 78 +- .../payment/compropago_cash_form.twig | 38 +- .../extension/payment/compropago_receipt.twig | 3 +- .../payment/compropago_spei_form.twig | 40 +- .../system/library/compropago/composer.json | 24 +- .../system/library/compropago/composer.lock | 73 +- .../vendor/composer/ClassLoader.php | 4 +- .../vendor/composer/autoload_namespaces.php | 1 + .../vendor/composer/autoload_psr4.php | 2 +- .../vendor/composer/autoload_static.php | 13 +- .../compropago/vendor/composer/installed.json | 75 +- .../vendor/compropago/php-sdk/.gitignore | 1 - .../php-sdk/CompropagoSdk/Client.php | 76 - .../php-sdk/CompropagoSdk/Factory/Factory.php | 76 - .../Factory/Models/CpOrderInfo.php | 37 - .../CompropagoSdk/Factory/Models/Customer.php | 16 - .../Factory/Models/EvalAuthInfo.php | 18 - .../CompropagoSdk/Factory/Models/Exchange.php | 20 - .../Factory/Models/FeeDetails.php | 19 - .../Factory/Models/InstructionDetails.php | 25 - .../Factory/Models/Instructions.php | 26 - .../Factory/Models/NewOrderInfo.php | 39 - .../Factory/Models/OrderInfo.php | 28 - .../Factory/Models/PlaceOrderInfo.php | 70 - .../CompropagoSdk/Factory/Models/Provider.php | 24 - .../CompropagoSdk/Factory/Models/SmsData.php | 19 - .../CompropagoSdk/Factory/Models/SmsInfo.php | 21 - .../Factory/Models/SmsObject.php | 16 - .../CompropagoSdk/Factory/Models/Webhook.php | 18 - .../CompropagoSdk/Factory/Serialize.php | 413 -- .../php-sdk/CompropagoSdk/Service.php | 215 - .../php-sdk/CompropagoSdk/Tools/Http.php | 179 - .../CompropagoSdk/Tools/HttpResponse.php | 11 - .../php-sdk/CompropagoSdk/Tools/Request.php | 93 - .../CompropagoSdk/Tools/Validations.php | 92 - .../php-sdk/CompropagoSdk/Tools/cacerts.pem | 2183 ---------- .../vendor/compropago/php-sdk/README.md | 367 +- .../vendor/compropago/php-sdk/composer.json | 21 +- .../vendor/compropago/php-sdk/src/Client.php | 86 + .../php-sdk/src/Helpers/ValidationHelper.php | 27 + .../src/Resources/AbstractResource.php | 64 + .../php-sdk/src/Resources/Payments/Cash.php | 110 + .../php-sdk/src/Resources/Payments/Spei.php | 63 + .../compropago/php-sdk/src/Resources/Sms.php | 46 + .../php-sdk/src/Resources/Webhook.php | 117 + .../vendor/compropago/php-sdk/tests/Test.php | 292 -- .../compropago/php-sdk/tests/TestRequest.php | 70 - .../vendor/compropago/php-sdk/unittest.xml | 7 - .../vendor/rmccue/requests/.coveralls.yml | 4 + .../vendor/rmccue/requests/.gitignore | 6 + .../vendor/rmccue/requests/CHANGELOG.md | 315 ++ .../compropago/vendor/rmccue/requests/LICENSE | 49 + .../vendor/rmccue/requests/README.md | 152 + .../requests/bin/create_pear_package.php | 55 + .../vendor/rmccue/requests/composer.json | 23 + .../rmccue/requests/library/Requests.php | 980 +++++ .../rmccue/requests/library/Requests/Auth.php | 33 + .../requests/library/Requests/Auth/Basic.php | 88 + .../requests/library/Requests/Cookie.php | 500 +++ .../requests/library/Requests/Cookie/Jar.php | 175 + .../requests/library/Requests/Exception.php | 62 + .../library/Requests/Exception/HTTP.php | 71 + .../library/Requests/Exception/HTTP/304.php | 27 + .../library/Requests/Exception/HTTP/305.php | 27 + .../library/Requests/Exception/HTTP/306.php | 27 + .../library/Requests/Exception/HTTP/400.php | 27 + .../library/Requests/Exception/HTTP/401.php | 27 + .../library/Requests/Exception/HTTP/402.php | 27 + .../library/Requests/Exception/HTTP/403.php | 27 + .../library/Requests/Exception/HTTP/404.php | 27 + .../library/Requests/Exception/HTTP/405.php | 27 + .../library/Requests/Exception/HTTP/406.php | 27 + .../library/Requests/Exception/HTTP/407.php | 27 + .../library/Requests/Exception/HTTP/408.php | 27 + .../library/Requests/Exception/HTTP/409.php | 27 + .../library/Requests/Exception/HTTP/410.php | 27 + .../library/Requests/Exception/HTTP/411.php | 27 + .../library/Requests/Exception/HTTP/412.php | 27 + .../library/Requests/Exception/HTTP/413.php | 27 + .../library/Requests/Exception/HTTP/414.php | 27 + .../library/Requests/Exception/HTTP/415.php | 27 + .../library/Requests/Exception/HTTP/416.php | 27 + .../library/Requests/Exception/HTTP/417.php | 27 + .../library/Requests/Exception/HTTP/418.php | 29 + .../library/Requests/Exception/HTTP/428.php | 29 + .../library/Requests/Exception/HTTP/429.php | 29 + .../library/Requests/Exception/HTTP/431.php | 29 + .../library/Requests/Exception/HTTP/500.php | 27 + .../library/Requests/Exception/HTTP/501.php | 27 + .../library/Requests/Exception/HTTP/502.php | 27 + .../library/Requests/Exception/HTTP/503.php | 27 + .../library/Requests/Exception/HTTP/504.php | 27 + .../library/Requests/Exception/HTTP/505.php | 27 + .../library/Requests/Exception/HTTP/511.php | 29 + .../Requests/Exception/HTTP/Unknown.php | 44 + .../library/Requests/Exception/Transport.php | 5 + .../Requests/Exception/Transport/cURL.php | 56 + .../requests/library/Requests/Hooker.php | 33 + .../requests/library/Requests/Hooks.php | 68 + .../requests/library/Requests/IDNAEncoder.php | 388 ++ .../rmccue/requests/library/Requests/IPv6.php | 190 + .../rmccue/requests/library/Requests/IRI.php | 1084 +++++ .../requests/library/Requests/Proxy.php | 35 + .../requests/library/Requests/Proxy/HTTP.php | 151 + .../requests/library/Requests/Response.php | 121 + .../library/Requests/Response/Headers.php | 98 + .../rmccue/requests/library/Requests/SSL.php | 152 + .../requests/library/Requests/Session.php | 266 ++ .../requests/library/Requests/Transport.php | 41 + .../library/Requests/Transport/cURL.php | 542 +++ .../library/Requests/Transport/cacert.pem | 3554 +++++++++++++++++ .../library/Requests/Transport/fsockopen.php | 444 ++ .../Utility/CaseInsensitiveDictionary.php | 103 + .../Requests/Utility/FilteredIterator.php | 45 + .../vendor/rmccue/requests/package.xml.tpl | 60 + 136 files changed, 13367 insertions(+), 6028 deletions(-) create mode 100644 upload/admin/language/es-mx/extension/payment/compropago_cash.php create mode 100644 upload/admin/language/es-mx/extension/payment/compropago_spei.php create mode 100644 upload/catalog/language/es-mx/extension/payment/compropago.php create mode 100644 upload/catalog/language/es-mx/extension/payment/compropago_cash.php create mode 100644 upload/catalog/language/es-mx/extension/payment/compropago_spei.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Client.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Factory.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/CpOrderInfo.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/Customer.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/EvalAuthInfo.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/Exchange.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/FeeDetails.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/InstructionDetails.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/Instructions.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/NewOrderInfo.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/OrderInfo.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/PlaceOrderInfo.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/Provider.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/SmsData.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/SmsInfo.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/SmsObject.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Models/Webhook.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Factory/Serialize.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Service.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Tools/Http.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Tools/HttpResponse.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Tools/Request.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Tools/Validations.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/CompropagoSdk/Tools/cacerts.pem create mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/src/Client.php create mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/src/Helpers/ValidationHelper.php create mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/src/Resources/AbstractResource.php create mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/src/Resources/Payments/Cash.php create mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/src/Resources/Payments/Spei.php create mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/src/Resources/Sms.php create mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/src/Resources/Webhook.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/tests/Test.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/tests/TestRequest.php delete mode 100644 upload/system/library/compropago/vendor/compropago/php-sdk/unittest.xml create mode 100755 upload/system/library/compropago/vendor/rmccue/requests/.coveralls.yml create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/.gitignore create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/CHANGELOG.md create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/LICENSE create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/README.md create mode 100755 upload/system/library/compropago/vendor/rmccue/requests/bin/create_pear_package.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/composer.json create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Auth.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Auth/Basic.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Cookie.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Cookie/Jar.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/304.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/305.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/306.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/400.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/401.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/402.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/403.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/404.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/405.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/406.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/407.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/408.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/409.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/410.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/411.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/412.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/413.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/414.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/415.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/416.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/417.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/418.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/428.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/429.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/431.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/500.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/501.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/502.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/503.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/504.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/505.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/511.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/HTTP/Unknown.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/Transport.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Exception/Transport/cURL.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Hooker.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Hooks.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/IDNAEncoder.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/IPv6.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/IRI.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Proxy.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Proxy/HTTP.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Response.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Response/Headers.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/SSL.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Session.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Transport.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Transport/cURL.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Transport/cacert.pem create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Transport/fsockopen.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Utility/CaseInsensitiveDictionary.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/library/Requests/Utility/FilteredIterator.php create mode 100644 upload/system/library/compropago/vendor/rmccue/requests/package.xml.tpl diff --git a/.gitignore b/.gitignore index 61a911a..eb1bf21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ .DS_Store .vscode/ +.travis.yml *.zip +phpunit.xml +tests/ +examples/ +docs/ diff --git a/README.md b/README.md index 33b4021..308c59a 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,13 @@ Con ComproPago puede recibir pagos en OXXO, 7Eleven y muchas tiendas más en tod [Registrarse en ComproPago](https://compropago.com/) [Comisiones](https://www.compropago.com/comisiones/) +## Ayuda + +- [Centro de ayuda y soporte](https://compropago.com/ayuda-y-soporte) +- [Solicitar integración](https://compropago.com/integracion) +- [Guía para empezar a usar ComproPago](https://compropago.com/ayuda-y-soporte/como-comenzar-a-usar-compropago) +- [Información de contacto](https://compropago.com/contacto) + ## Requerimientos * [OpenCart 3.x](https://www.opencart.com/) @@ -20,3 +27,30 @@ Con ComproPago puede recibir pagos en OXXO, 7Eleven y muchas tiendas más en tod ## Instalación Por favor revisar la siguiente [documentación](http://demo.compropago.com/plugins/opencart-3) + +## Documentación + +**[API de ComproPago](https://compropago.com/documentacion/api)** + +ComproPago te ofrece un API REST para integrar pagos en efectivo en tu comercio electrónico o aplicaciones. + +**[General](https://compropago.com/documentacion)** + +Información de comisiones y horarios, como transferir tu dinero y la seguridad que proporciona ComproPago. + +**[Otras formas de integración](https://compropago.com/soluciones/)** + +- [Botón de pago](https://compropago.com/documentacion/boton-pago) +- [Librerías > sección SDK](http://demo.compropago.com/) +- [Plugins > sección Plugins](http://demo.compropago.com/) + +## Soporte + +En caso de tener alguna pregunta o requerir el apoyo técnico, por favor contactar al correo: **soporte@compropago.com**, proporcionando la siguiente información: + +- Nombre completo (Propietario de la cuenta). +- Url del sitio web de la tienda. +- Teléfono local y celular. +- Correo electrónico del propietario de la cuenta. +- Texto detallado de la duda o requerimiento. +- En caso de presentar algún problema técnico, por favor enviar capturas de pantalla o evidencia para una respuesta más rápida. diff --git a/upload/admin/controller/extension/payment/compropago_cash.php b/upload/admin/controller/extension/payment/compropago_cash.php index 0506f2f..ee866cc 100644 --- a/upload/admin/controller/extension/payment/compropago_cash.php +++ b/upload/admin/controller/extension/payment/compropago_cash.php @@ -1,252 +1,269 @@ load->language('extension/payment/compropago_cash'); - $this->document->setTitle($this->language->get('heading_title')); - $this->load->model('setting/setting'); - - $data = []; - - $this->save_config(); - $this->add_warnings($data); - $this->add_breadcrums($data); - $this->add_buttons($data); - $this->add_data($data); - - $this->add_sections($data); - - $this->response->setOutput($this->load->view('extension/payment/compropago_cash', $data)); - } - - /** - * Save configurations of the panel - */ - private function save_config() { - if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { - $this->model_setting_setting->editSetting('payment_compropago', $this->request->post); - $this->model_setting_setting->editSetting('payment_compropago_cash', $this->request->post); - $this->session->data['success'] = $this->language->get('text_success'); - - $this->register_webhook( - $this->request->post['payment_compropago_publickey'], - $this->request->post['payment_compropago_privatekey'], - $this->request->post['payment_compropago_mode'] === '1' - ); - - $linkParams = 'user_token=' . $this->session->data['user_token'] . '&type=payment'; - $this->response->redirect($this->url->link('marketplace/extension', $linkParams, true)); - } - } - - /** - * Add warnings to render - * @param $data - */ - private function add_warnings(&$data) { - if (isset($this->error['warning'])) { - $data['error_warning'] = $this->error['warning']; - } else { - $data['error_warning'] = ''; - } - } - - /** - * Add breadcrums to the config page - * @param $data - */ - private function add_breadcrums(&$data) { - $data['breadcrumbs'] = array(); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_home'), - 'href' => $this->url->link( - 'common/dashboard', - 'user_token=' . $this->session->data['user_token'], - true - ) - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_extension'), - 'href' => $this->url->link( - 'marketplace/extension', - 'user_token=' . $this->session->data['user_token'] . '&type=payment', - true - ) - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('heading_title'), - 'href' => $this->url->link( - 'extension/payment/compropago_cash', - 'user_token=' . $this->session->data['user_token'], - true - ) - ); - } - - /** - * Add link buttons to the page - * @param $data - */ - private function add_buttons(&$data) { - $data['action'] = $this->url->link( - 'extension/payment/compropago_cash', - 'user_token=' . $this->session->data['user_token'], - true - ); - - $data['cancel'] = $this->url->link( - 'marketplace/extension', - 'user_token=' . $this->session->data['user_token'] . '&type=payment', - true - ); - } - - /** - * Add page sections to render in view - * @param $data - */ - private function add_sections(&$data) { - $data['header'] = $this->load->controller('common/header'); - $data['column_left'] = $this->load->controller('common/column_left'); - $data['footer'] = $this->load->controller('common/footer'); - } - - /** - * Add the config data saved to render in view - * @param $data - */ - private function add_data(&$data) { - if (isset($this->request->post['payment_compropago_mode'])) { - $data['payment_compropago_mode'] = $this->request->post['payment_compropago_mode']; - } else { - $data['payment_compropago_mode'] = $this->config->get('payment_compropago_mode'); - } - - if (isset($this->request->post['payment_compropago_publickey'])) { - $data['payment_compropago_publickey'] = $this->request->post['payment_compropago_publickey']; - } else { - $data['payment_compropago_publickey'] = $this->config->get('payment_compropago_publickey'); - } - - if (isset($this->request->post['payment_compropago_privatekey'])) { - $data['payment_compropago_privatekey'] = $this->request->post['payment_compropago_privatekey']; - } else { - $data['payment_compropago_privatekey'] = $this->config->get('payment_compropago_privatekey'); - } - - if (isset($this->request->post['payment_compropago_cash_status'])) { - $data['payment_compropago_cash_status'] = $this->request->post['payment_compropago_cash_status']; - } else { - $data['payment_compropago_cash_status'] = $this->config->get('payment_compropago_cash_status'); - } - - if (isset($this->request->post['payment_compropago_cash_title'])) { - $data['payment_compropago_cash_title'] = $this->request->post['payment_compropago_cash_title']; - } else { - $data['payment_compropago_cash_title'] = $this->config->get('payment_compropago_cash_title'); - } - - if (isset($this->request->post['payment_compropago_cash_sort_order'])) { - $data['payment_compropago_cash_sort_order'] = $this->request->post['payment_compropago_cash_sort_order']; - } else { - $data['payment_compropago_cash_sort_order'] = $this->config->get('payment_compropago_cash_sort_order'); - } - - if (isset($this->request->post['payment_compropago_cash_providers'])) { - $providers = $this->request->post['payment_compropago_cash_providers']; - } else { - $providers = $this->config->get('payment_compropago_cash_providers'); - } - - $client = new Client( - $data['payment_compropago_publickey'], - $data['payment_compropago_privatekey'], - $data['payment_compropago_mode'] === '1' - ); - - $data['payment_compropago_cash_providers'] = $providers; - - try { - $all_providers = $client->api->listDefaultProviders(); - } catch (Exception $e) { - $all_providers = []; - } - - if (empty($providers)) { - $data['active_providers'] = []; - $data['deactive_providers'] = $all_providers; - } else { - $active = explode(',', $providers); - - foreach ($all_providers as $provider) { - if (in_array($provider->internal_name, $active)) { - $data['active_providers'][] = $provider; - } else { - $data['deactive_providers'][] = $provider; - } - } - } - } - - /** - * Validate if the usar has access to mody the plugin - * @return bool - */ - protected function validate() { - if (!$this->user->hasPermission('modify', 'extension/payment/compropago_cash')) { - $this->error['warning'] = $this->language->get('error_permission'); - } - - return !$this->error; - } - - /** - * Register webhook in ComproPago - * @param $public_key - * @param $private_key - * @param $mode - */ - private function register_webhook($public_key, $private_key, $mode) { - try { - $uri = explode("admin/index.php",$_SERVER["REQUEST_URI"]); - $uri = $uri[0]; - $webhook_url = $this->site_url() . $uri . "index.php?route=extension/payment/cp_cash/webhook"; - - $client = new Client($public_key, $private_key, $mode); - $client->api->createWebhook($webhook_url); - } catch(Exception $e) { - if ($e->getMessage() != 'Error: 409') { - $this->error['warning'] = 'Webhook error: ' . $e->getMessage(); - } - } - } - - /** - * Install secuence - */ - public function install() { - $this->load->model('extension/payment/compropago_cash'); - $this->model_extension_payment_compropago_cash->install(); - } - - /** - * Get the base path url of the site - * @return string - */ - private function site_url() { - $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; - $domainName = $_SERVER['HTTP_HOST']; - return $protocol.$domainName; - } -} \ No newline at end of file +use CompropagoSdk\Resources\Payments\Cash as sdkCash; +use CompropagoSdk\Resources\Webhook; + + +class ControllerExtensionPaymentCompropagoCash extends Controller +{ + private $error = []; + private $gateway_name = 'compropago_cash'; + + /** + * Main actions + */ + public function index() + { + $this->load->language("extension/payment/{$this->gateway_name}"); + $this->document->setTitle($this->language->get('heading_title')); + $this->load->model('setting/setting'); + + $data = []; + + $this->save_config(); + $this->add_warnings($data); + $this->add_breadcrums($data); + $this->add_buttons($data); + $this->add_data($data); + $this->add_sections($data); + + $this->response->setOutput($this->load->view( + "extension/payment/{$this->gateway_name}", + $data + )); + } + + /** + * Save configurations of the panel + */ + private function save_config() + { + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) + { + $this->model_setting_setting->editSetting('payment_compropago', $this->request->post); + $this->model_setting_setting->editSetting("payment_{$this->gateway_name}", $this->request->post); + $this->session->data['success'] = $this->language->get('text_success'); + + $this->register_webhook( + $this->request->post['payment_compropago_publickey'], + $this->request->post['payment_compropago_privatekey'], + $this->request->post['payment_compropago_mode'] === '1' + ); + + $linkParams = 'user_token=' . $this->session->data['user_token'] . '&type=payment'; + $this->response->redirect($this->url->link('marketplace/extension', $linkParams, true)); + } + } + + /** + * Add warnings to render + * @param $data + */ + private function add_warnings(&$data) + { + $data['error_warning'] = isset($this->error['warning']) + ? $this->error['warning'] + : ''; + } + + /** + * Add breadcrums to the config page + * @param $data + */ + private function add_breadcrums(&$data) + { + $data['breadcrumbs'] = []; + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link( + 'common/dashboard', + 'user_token=' . $this->session->data['user_token'], + true + ) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link( + 'marketplace/extension', + 'user_token=' . $this->session->data['user_token'] . '&type=payment', + true + ) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link( + "extension/payment/{$this->gateway_name}", + 'user_token=' . $this->session->data['user_token'], + true + ) + ); + } + + /** + * Add link buttons to the page + * @param $data + */ + private function add_buttons(&$data) + { + $data['action'] = $this->url->link( + "extension/payment/{$this->gateway_name}", + 'user_token=' . $this->session->data['user_token'], + true + ); + + $data['cancel'] = $this->url->link( + 'marketplace/extension', + 'user_token=' . $this->session->data['user_token'] . '&type=payment', + true + ); + } + + /** + * Add page sections to render in view + * @param $data + */ + private function add_sections(&$data) + { + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + } + + /** + * Add the config data saved to render in view + * @param $data + */ + private function add_data(&$data) + { + $params = [ + 'payment_compropago_mode', + 'payment_compropago_publickey', + 'payment_compropago_privatekey', + 'payment_compropago_cash_status', + 'payment_compropago_cash_title', + 'payment_compropago_cash_sort_order', + 'payment_compropago_cash_providers' + ]; + foreach($params as $param) + { + $data[$param] = isset($this->request->post[$param]) + ? $this->request->post[$param] + : $this->config->get($param); + } + + try + { + $client = (new sdkCash)->withKeys( + $data['payment_compropago_publickey'], + $data['payment_compropago_privatekey'] + ); + $all_providers = $client->getDefaultProviders(); + } + catch (Exception $e) + { + $all_providers = []; + } + + if (empty($providers)) + { + $data['active_providers'] = []; + $data['deactive_providers'] = $all_providers; + } + else + { + $active = explode(',', $providers); + foreach ($all_providers as $provider) + { + if (in_array($provider->internal_name, $active)) + { + $data['active_providers'][] = $provider; + } + else + { + $data['deactive_providers'][] = $provider; + } + } + } + } + + /** + * Validate if the usar has access to mody the plugin + * @return bool + */ + protected function validate() + { + if (!$this->user->hasPermission('modify', "extension/payment/{$this->gateway_name}")) + { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + /** + * Register webhook in ComproPago + * @param $public_key + * @param $private_key + * @param $mode + */ + private function register_webhook($public_key, $private_key, $mode) + { + try + { + $uri = explode("admin/index.php", $_SERVER["REQUEST_URI"]); + $uri = $uri[0]; + $webhook_url = $this->site_url() . "{$uri}index.php?route=extension/payment/compropago/webhook"; + + $client = (new Webhook)->withKeys( + $public_key, + $private_key + ); + $response = $client->create( $webhook_url ); + } + catch(Exception $e) + { + $errors = [ + 'Request Error [409]: ', + ]; + $response = json_decode(str_replace($errors, '', $e->getMessage()), true); + + # Ignore Webhook registered + if ( isset($response['code']) && $response['code']==409 ) + { + } + else + { + $this->error['warning'] = isset($response['message']) + ? $response['message'] + : 'Webhook error: ' . $e->getMessage(); + } + } + } + + /** + * Install secuence + */ + public function install() + { + $this->load->model("extension/payment/{$this->gateway_name}"); + $this->model_extension_payment_compropago_cash->install(); + } + + /** + * Get the base path url of the site + * @return string + */ + private function site_url() + { + $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) + ? "https://" + : "http://"; + $domainName = $_SERVER['HTTP_HOST']; + return $protocol.$domainName; + } +} diff --git a/upload/admin/controller/extension/payment/compropago_spei.php b/upload/admin/controller/extension/payment/compropago_spei.php index 55fef9e..2a9d263 100644 --- a/upload/admin/controller/extension/payment/compropago_spei.php +++ b/upload/admin/controller/extension/payment/compropago_spei.php @@ -1,222 +1,243 @@ load->language('extension/payment/compropago_spei'); - $this->document->setTitle($this->language->get('heading_title')); - $this->load->model('setting/setting'); - - $data = []; - - $this->save_config(); - $this->add_warnings($data); - $this->add_breadcrums($data); - $this->add_buttons($data); - $this->add_data($data); - $this->add_sections($data); - - $this->response->setOutput($this->load->view('extension/payment/compropago_spei', $data)); - } - - /** - * Save configurations of the panel - */ - private function save_config() { - if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { - $this->model_setting_setting->editSetting('payment_compropago', $this->request->post); - $this->model_setting_setting->editSetting('payment_compropago_spei', $this->request->post); - $this->session->data['success'] = $this->language->get('text_success'); - - $this->register_webhook( - $this->request->post['payment_compropago_publickey'], - $this->request->post['payment_compropago_privatekey'], - $this->request->post['payment_compropago_mode'] === '1' - ); - - $linkParams = 'user_token=' . $this->session->data['user_token'] . '&type=payment'; - $this->response->redirect($this->url->link('marketplace/extension', $linkParams, true)); - } - } - - /** - * Add warnings to render - * @param $data - */ - private function add_warnings(&$data) { - if (isset($this->error['warning'])) { - $data['error_warning'] = $this->error['warning']; - } else { - $data['error_warning'] = ''; - } - } - - /** - * Add breadcrums to the config page - * @param $data - */ - private function add_breadcrums(&$data) { - $data['breadcrumbs'] = array(); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_home'), - 'href' => $this->url->link( - 'common/dashboard', - 'user_token=' . $this->session->data['user_token'], - true - ) - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_extension'), - 'href' => $this->url->link( - 'marketplace/extension', - 'user_token=' . $this->session->data['user_token'] . '&type=payment', - true - ) - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('heading_title'), - 'href' => $this->url->link( - 'extension/payment/compropago_spei', - 'user_token=' . $this->session->data['user_token'], - true - ) - ); - } - - /** - * Add link buttons to the page - * @param $data - */ - private function add_buttons(&$data) { - $data['action'] = $this->url->link( - 'extension/payment/compropago_spei', - 'user_token=' . $this->session->data['user_token'], - true - ); - - $data['cancel'] = $this->url->link( - 'marketplace/extension', - 'user_token=' . $this->session->data['user_token'] . '&type=payment', - true - ); - } - - /** - * Add page sections to render in view - * @param $data - */ - private function add_sections(&$data) { - $data['header'] = $this->load->controller('common/header'); - $data['column_left'] = $this->load->controller('common/column_left'); - $data['footer'] = $this->load->controller('common/footer'); - } - - /** - * Add the config data saved to render in view - * @param $data - */ - private function add_data(&$data) { - if (isset($this->request->post['payment_compropago_mode'])) { - $data['payment_compropago_mode'] = $this->request->post['payment_compropago_mode']; - } else { - $data['payment_compropago_mode'] = $this->config->get('payment_compropago_mode'); - } - - if (isset($this->request->post['payment_compropago_publickey'])) { - $data['payment_compropago_publickey'] = $this->request->post['payment_compropago_publickey']; - } else { - $data['payment_compropago_publickey'] = $this->config->get('payment_compropago_publickey'); - } - - if (isset($this->request->post['payment_compropago_privatekey'])) { - $data['payment_compropago_privatekey'] = $this->request->post['payment_compropago_privatekey']; - } else { - $data['payment_compropago_privatekey'] = $this->config->get('payment_compropago_privatekey'); - } - - if (isset($this->request->post['payment_compropago_spei_status'])) { - $data['payment_compropago_spei_status'] = $this->request->post['payment_compropago_spei_status']; - } else { - $data['payment_compropago_spei_status'] = $this->config->get('payment_compropago_spei_status'); - } - - if (isset($this->request->post['payment_compropago_spei_title'])) { - $data['payment_compropago_spei_title'] = $this->request->post['payment_compropago_spei_title']; - } else { - $data['payment_compropago_spei_title'] = $this->config->get('payment_compropago_spei_title'); - } - - if (isset($this->request->post['payment_compropago_spei_sort_order'])) { - $data['payment_compropago_spei_sort_order'] = $this->request->post['payment_compropago_spei_sort_order']; - } else { - $data['payment_compropago_spei_sort_order'] = $this->config->get('payment_compropago_spei_sort_order'); - } - - $data['payment_compropago_spei_title'] = empty($data['payment_compropago_spei_title']) ? - $this->language->get('entry_default_spei_title') : $data['payment_compropago_spei_title']; - - $data['payment_compropago_spei_sort_order'] = empty($data['payment_compropago_spei_sort_order']) ? - 1 : $data['payment_compropago_spei_sort_order']; - } - - /** - * Validate if the usar has access to mody the plugin - * @return bool - */ - protected function validate() { - if (!$this->user->hasPermission('modify', 'extension/payment/compropago_spei')) { - $this->error['warning'] = $this->language->get('error_permission'); - } - - return !$this->error; - } - - /** - * Register webhook in ComproPago - * @param $public_key - * @param $private_key - * @param $mode - */ - private function register_webhook($public_key, $private_key, $mode) { - try { - $uri = explode("admin/index.php",$_SERVER["REQUEST_URI"]); - $uri = $uri[0]; - $webhook_url = $this->site_url() . $uri . "index.php?route=extension/payment/compropago/webhook"; - - $client = new Client($public_key, $private_key, $mode); - $client->api->createWebhook($webhook_url); - } catch(Exception $e) { - if ($e->getMessage() != 'Error: 409') { - $this->error['warning'] = 'Webhook error: ' . $e->getMessage(); - } - } - } - - /** - * Install secuence - */ - public function install() { - $this->load->model('extension/payment/compropago_cash'); - $this->model_extension_payment_compropago_cash->install(); - } - - /** - * Get the base path url of the site - * @return string - */ - private function site_url() { - $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; - $domainName = $_SERVER['HTTP_HOST']; - return $protocol.$domainName; - } -} \ No newline at end of file +use CompropagoSdk\Resources\Payments\Spei as sdkSpei; +use CompropagoSdk\Resources\Webhook; + + +class ControllerExtensionPaymentCompropagoSpei extends Controller +{ + private $error = []; + private $gateway_name = 'compropago_spei'; + + /** + * Main actions + */ + public function index() + { + $this->load->language("extension/payment/{$this->gateway_name}"); + $this->document->setTitle($this->language->get('heading_title')); + $this->load->model('setting/setting'); + + $data = []; + + $this->save_config(); + $this->add_warnings($data); + $this->add_breadcrums($data); + $this->add_buttons($data); + $this->add_data($data); + $this->add_sections($data); + + $this->response->setOutput($this->load->view( + "extension/payment/{$this->gateway_name}", + $data + )); + } + + /** + * Save configurations of the panel + */ + private function save_config() + { + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) + { + $this->model_setting_setting->editSetting('payment_compropago', $this->request->post); + $this->model_setting_setting->editSetting('payment_compropago_spei', $this->request->post); + $this->session->data['success'] = $this->language->get('text_success'); + + $this->register_webhook( + $this->request->post['payment_compropago_publickey'], + $this->request->post['payment_compropago_privatekey'], + $this->request->post['payment_compropago_mode'] === '1' + ); + + $linkParams = 'user_token=' . $this->session->data['user_token'] . '&type=payment'; + $this->response->redirect($this->url->link('marketplace/extension', $linkParams, true)); + } + } + + /** + * Add warnings to render + * @param $data + */ + private function add_warnings(&$data) + { + $data['error_warning'] = isset($this->error['warning']) + ? $this->error['warning'] + : ''; + } + + /** + * Add breadcrums to the config page + * @param $data + */ + private function add_breadcrums(&$data) + { + $data['breadcrumbs'] = []; + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link( + 'common/dashboard', + 'user_token=' . $this->session->data['user_token'], + true + ) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link( + 'marketplace/extension', + 'user_token=' . $this->session->data['user_token'] . '&type=payment', + true + ) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link( + "extension/payment/{$this->gateway_name}", + 'user_token=' . $this->session->data['user_token'], + true + ) + ); + } + + /** + * Add link buttons to the page + * @param $data + */ + private function add_buttons(&$data) + { + $data['action'] = $this->url->link( + "extension/payment/{$this->gateway_name}", + 'user_token=' . $this->session->data['user_token'], + true + ); + + $data['cancel'] = $this->url->link( + 'marketplace/extension', + 'user_token=' . $this->session->data['user_token'] . '&type=payment', + true + ); + } + + /** + * Add page sections to render in view + * @param $data + */ + private function add_sections(&$data) + { + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + } + + /** + * Add the config data saved to render in view + * @param $data + */ + private function add_data(&$data) + { + $params = [ + 'payment_compropago_mode', + 'payment_compropago_publickey', + 'payment_compropago_privatekey', + 'payment_compropago_spei_status', + 'payment_compropago_spei_title', + 'payment_compropago_spei_sort_order' + ]; + foreach($params as $param) + { + $data[$param] = isset($this->request->post[$param]) + ? $this->request->post[$param] + : $this->config->get($param); + } + + $data['payment_compropago_spei_title'] = empty($data['payment_compropago_spei_title']) + ? $this->language->get('entry_default_spei_title') + : $data['payment_compropago_spei_title']; + + $data['payment_compropago_spei_sort_order'] = empty($data['payment_compropago_spei_sort_order']) + ? 1 + : $data['payment_compropago_spei_sort_order']; + } + + /** + * Validate if the usar has access to mody the plugin + * @return bool + */ + protected function validate() + { + if (!$this->user->hasPermission('modify', "extension/payment/{$this->gateway_name}")) + { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + /** + * Register webhook in ComproPago + * @param $public_key + * @param $private_key + * @param $mode + */ + private function register_webhook($public_key, $private_key, $mode) + { + try + { + $uri = explode("admin/index.php", $_SERVER["REQUEST_URI"]); + $uri = $uri[0]; + $webhook_url = $this->site_url() . "{$uri}index.php?route=extension/payment/compropago/webhook"; + + $client = (new Webhook)->withKeys( + $public_key, + $private_key + ); + $response = $client->create( $webhook_url ); + } + catch(Exception $e) + { + $errors = [ + 'Request Error [409]: ', + ]; + $response = json_decode(str_replace($errors, '', $e->getMessage()), true); + + # Ignore Webhook registered + if ( isset($response['code']) && $response['code']==409 ) + { + } + else + { + $this->error['warning'] = isset($response['message']) + ? $response['message'] + : 'Webhook error: ' . $e->getMessage(); + } + } + } + + /** + * Install secuence + */ + public function install() + { + $this->load->model('extension/payment/compropago_cash'); + $this->model_extension_payment_compropago_cash->install(); + } + + /** + * Get the base path url of the site + * @return string + */ + private function site_url() + { + $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) + ? "https://" + : "http://"; + $domainName = $_SERVER['HTTP_HOST']; + + return $protocol.$domainName; + } +} diff --git a/upload/admin/language/en-gb/extension/payment/compropago_cash.php b/upload/admin/language/en-gb/extension/payment/compropago_cash.php index 2ae48da..403a826 100644 --- a/upload/admin/language/en-gb/extension/payment/compropago_cash.php +++ b/upload/admin/language/en-gb/extension/payment/compropago_cash.php @@ -1,26 +1,35 @@ " . "ComproPago" . ""; +$_['text_compropago_link_panel'] = "You can see this setting in ". + "" . + "ComproPago Panel" . + ""; -// Entry generals +# Entry generals $_['entry_compropago_mode'] = 'Mode'; $_['entry_compropago_mode_active'] = 'Active mode'; $_['entry_compropago_mode_test'] = 'Test mode'; $_['entry_compropago_publickey'] = 'Public key'; $_['entry_compropago_privatekey'] = 'Private key'; -// Entry for cash +# Entry for cash $_['entry_cash_status'] = 'Status'; $_['entry_cash_title'] = 'Title'; $_['entry_cash_providers'] = 'Providers'; @@ -28,8 +37,8 @@ $_['entry_cash_deactive_providers'] = 'Deactive'; $_['entry_cash_sort_order'] = 'Sort Order'; -// Help +# Help $_['help_mode'] = 'This is the mode of your compropago account'; -// Error -$_['error_permission'] = 'Warning: You do not have permission to modify payment Cash On Delivery!'; \ No newline at end of file +# Error +$_['error_permission'] = 'Warning: You do not have permission to modify payment Cash On Delivery!'; diff --git a/upload/admin/language/en-gb/extension/payment/compropago_spei.php b/upload/admin/language/en-gb/extension/payment/compropago_spei.php index 9b6a2b6..17422af 100644 --- a/upload/admin/language/en-gb/extension/payment/compropago_spei.php +++ b/upload/admin/language/en-gb/extension/payment/compropago_spei.php @@ -1,4 +1,9 @@ " . - "ComproPago" . - ""; +$_['text_compropago_spei'] = "" . + "ComproPago" . + ""; +$_['text_compropago_link_panel'] = "You can see this setting in ". + "" . + "ComproPago Panel" . + ""; // Entry generals $_['entry_compropago_mode'] = 'Mode'; @@ -31,4 +40,4 @@ $_['help_mode'] = 'This is the mode of your compropago account'; // Error -$_['error_permission'] = 'Warning: You do not have permission to modify payment Cash On Delivery!'; \ No newline at end of file +$_['error_permission'] = 'Warning: You do not have permission to modify payment Cash On Delivery!'; diff --git a/upload/admin/language/es-mx/extension/payment/compropago_cash.php b/upload/admin/language/es-mx/extension/payment/compropago_cash.php new file mode 100644 index 0000000..aac6d21 --- /dev/null +++ b/upload/admin/language/es-mx/extension/payment/compropago_cash.php @@ -0,0 +1,44 @@ +" . + "ComproPago" . + ""; +$_['text_compropago_link_panel'] = "Puede consultar esta configuración en el ". + "" . + "Panel de ComproPago" . + ""; + +# Entry generals +$_['entry_compropago_mode'] = 'Modo'; +$_['entry_compropago_mode_active'] = 'Modo activo'; +$_['entry_compropago_mode_test'] = 'Modo pruebas'; +$_['entry_compropago_publickey'] = 'Llave pública'; +$_['entry_compropago_privatekey'] = 'Llave privada'; + +# Entry for cash +$_['entry_cash_status'] = 'Estatus'; +$_['entry_cash_title'] = 'Título'; +$_['entry_cash_providers'] = 'Providers'; +$_['entry_cash_active_providers'] = 'Activos'; +$_['entry_cash_deactive_providers'] = 'Desactivados'; +$_['entry_cash_sort_order'] = 'Orden'; + +# Help +$_['help_mode'] = 'Este es el modo de su cuenta ComproPago'; + +# Error +$_['error_permission'] = 'Warning: You do not have permission to modify payment Cash On Delivery!'; diff --git a/upload/admin/language/es-mx/extension/payment/compropago_spei.php b/upload/admin/language/es-mx/extension/payment/compropago_spei.php new file mode 100644 index 0000000..9b757fc --- /dev/null +++ b/upload/admin/language/es-mx/extension/payment/compropago_spei.php @@ -0,0 +1,43 @@ +" . + "ComproPago" . + ""; +$_['text_compropago_link_panel'] = "Puede consultar esta configuración en el ". + "" . + "Panel de ComproPago" . + ""; + +// Entry generals +$_['entry_compropago_mode'] = 'Modo'; +$_['entry_compropago_mode_active'] = 'Modo activo'; +$_['entry_compropago_mode_test'] = 'Modo pruebas'; +$_['entry_compropago_publickey'] = 'Llave pública'; +$_['entry_compropago_privatekey'] = 'Llave privada'; + +$_['entry_default_spei_title'] = 'Transferencia bancaria'; + +// Entry for cash +$_['entry_spei_status'] = 'Status'; +$_['entry_spei_title'] = 'Título'; +$_['entry_spei_sort_order'] = 'Orden'; + +// Help +$_['help_mode'] = 'Este es el modo de su cuenta ComproPago'; + +// Error +$_['error_permission'] = 'Warning: You do not have permission to modify payment Cash On Delivery!'; diff --git a/upload/admin/model/extension/payment/compropago_cash.php b/upload/admin/model/extension/payment/compropago_cash.php index d76b6b4..8a253ee 100644 --- a/upload/admin/model/extension/payment/compropago_cash.php +++ b/upload/admin/model/extension/payment/compropago_cash.php @@ -1,13 +1,22 @@ db->query("ALTER TABLE `" . DB_PREFIX . "order` ADD COLUMN compropago_data TEXT DEFAULT NULL"); - } catch (Exception $e) { + public function install() + { + $query = "ALTER TABLE " . DB_PREFIX . "order + ADD COLUMN compropago_data TEXT DEFAULT NULL"; + + try + { + $this->db->query( $query ); + } + catch (Exception $e) + { } } -} \ No newline at end of file +} diff --git a/upload/admin/view/template/extension/payment/compropago_cash.twig b/upload/admin/view/template/extension/payment/compropago_cash.twig index f7004d3..c348ab6 100644 --- a/upload/admin/view/template/extension/payment/compropago_cash.twig +++ b/upload/admin/view/template/extension/payment/compropago_cash.twig @@ -1,194 +1,187 @@ -{{ header }}{{ column_left }} +{{ header }} +{{ column_left }}
- -
- {% if error_warning %} -
{{ error_warning }} - -
- {% endif %} - -
-
-
-

{{ text_edit }}

-
-
-
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
-
-
- -
-
- ComproPago - - {{ text_cash_section }} -
-
-
- -
- -
-
- -
- -
- -
-
- -
- -
- -
- - {{ entry_cash_active_providers }} -
- -
- -
- {{ entry_cash_deactive_providers }} -
- - -
- -
- -
- -
-
-
-
-
-
+ + +
+ {% if error_warning %} +
+ {{ error_warning }} + +
+ {% endif %} + +
+
+
+

+ {{ text_edit }} + - {{ text_edit }} +

+
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+ ComproPago - + {{ text_cash_section }} +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+ + {{ entry_cash_active_providers }} +
+ +
+ +
+ {{ entry_cash_deactive_providers }} +
+ + +
+ +
+ +
+ +
+
+
+
+
+
{{ footer }} \ No newline at end of file diff --git a/upload/admin/view/template/extension/payment/compropago_spei.twig b/upload/admin/view/template/extension/payment/compropago_spei.twig index 1e1510a..79efcf9 100644 --- a/upload/admin/view/template/extension/payment/compropago_spei.twig +++ b/upload/admin/view/template/extension/payment/compropago_spei.twig @@ -1,148 +1,134 @@ -{{ header }}{{ column_left }} +{{ header }} +{{ column_left }}
- -
- {% if error_warning %} -
{{ error_warning }} - -
- {% endif %} + +
-
-
-
-

{{ text_edit }}

-
-
-
- -
- -
-
+ {% if error_warning %} +
+ {{ error_warning }} + +
+ {% endif %} -
- -
- -
-
+ +
+
+

+ {{ text_edit }} + - {{ text_edit }} +

+
-
- -
- -
-
-
-
+
+
+ +
+ +
+
-
-
- ComproPago - - {{ text_spei_section }} -
-
-
- -
- -
-
+
+ +
+ +
+
-
- -
- -
-
+
+ +
+ +
+
+
+ +
-
- -
- -
-
-
-
-
-
+
+
+ ComproPago - + {{ text_spei_section }} +
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+ +
{{ footer }} \ No newline at end of file diff --git a/upload/catalog/controller/extension/payment/compropago.php b/upload/catalog/controller/extension/payment/compropago.php index 656d38e..465cf40 100644 --- a/upload/catalog/controller/extension/payment/compropago.php +++ b/upload/catalog/controller/extension/payment/compropago.php @@ -2,287 +2,312 @@ require_once __DIR__ . '/../../../../system/library/compropago/vendor/autoload.php'; -use CompropagoSdk\Client; -use CompropagoSdk\Factory\Factory; - -class ControllerExtensionPaymentCompropago extends Controller { - /** - * Webhook to approve an order of Cash or SPEI methods - * @throws Exception - */ - public function webhook() { - $this->response->addHeader('Content-Type: application/json'); - - $this->load->model('extension/payment/compropago_spei'); - $this->load->model('setting/setting'); - $this->load->model('checkout/order'); - - $json = [ - 'status' => 'success', - 'message' => '', - 'short_id' => null, - 'reference' => null, - ]; - - $request = @file_get_contents('php://input'); - - try { - $orderInfo = Factory::getInstanceOf('CpOrderInfo', $request); - - if (empty($request) || empty($orderInfo->id)) { - $message = 'Invalid request'; - throw new \Exception($message); - } - - if ($orderInfo->short_id == '000000') { - $json ['message'] = 'OK - TEST'; - - $this->response->setOutput(json_encode($json)); - return; - } - - $order = $this->model_checkout_order->getOrder($orderInfo->order_info->order_id); - - if (empty($order)) { - $message = 'Order not found'; - throw new \Exception($message); - } - - $transaction = $this->getTransaction($order, $orderInfo->id); - - switch ($transaction['method']) { - case 'spei': - $this->proccessSpei($json, $order, $transaction); - break; - case 'cash': - $this->proccessCash($json, $order, $transaction); - break; - default: - $message = "Invalid payment method {$transaction['method']}"; - throw new \Exception($message); - } - } catch (\Exception $e) { - http_response_code(500); - $json['status'] = 'error'; - $json['message'] = $e->getMessage(); - } - - $this->response->setOutput(json_encode($json)); - return; - } - - /** - * GEt transaction info of an order - * @param array $order - * @return array - * @throws Exception - */ - private function getTransaction($order, $cpid) { - $query = "SELECT compropago_data FROM `" . DB_PREFIX . "order` WHERE order_id = {$order['order_id']}"; - - $result = $this->db->query($query); - - if ($result->num_rows < 1 || empty($result->row['compropago_data'])) { - $message = 'Can\'t find order transaction'; - throw new \Exception($message); - } - - $transaction = unserialize($result->row['compropago_data']); - - if ($cpid != $transaction['compropago_id']) { - $message = 'Order not found'; - throw new \Exception($message); - } - - return $transaction; - } - - /** - * Proccess SPEI payment - * @param array $json - * @param array $order - * @throws Exception - */ - private function proccessSpei(&$json, $order, $transaction) { - $verified = $this->model_extension_payment_compropago_spei->verifyOrder($transaction['compropago_id']); - - switch ($verified->status) { - case 'PENDING': - $status = 'charge.pending'; - break; - case 'ACCEPTED': - $status = 'charge.success'; - break; - case 'EXPIRED': - $status = 'charge.expired'; - break; - } - - $this->updateOrderStatus($json, $status, $order, $transaction); - } - - /** - * Proccess Cash payment - * @param array $json - * @param array $order - * @param array $transaction - * @throws Exception - */ - private function proccessCash(&$json, $order, $transaction) { - $client = new Client( - $this->config->get('payment_compropago_publickey'), - $this->config->get('payment_compropago_privatekey'), - $this->config->get('payment_compropago_mode') === '1' - ); - - $verified = $client->api->verifyOrder($transaction['compropago_id']); - - $this->updateOrderStatus($json, $verified->type, $order, $transaction); - } - - /** - * Update order status - * @param array $json - * @param string $status - * @param array $order - * @param array $transaction - * @throws Exception - */ - private function updateOrderStatus(&$json, $status, $order, $transaction) { - switch ($status) { - case 'charge.success': - $status_id = 2; - break; - case 'charge.pending': - $json['message'] = 'OK - ' . $status; - $json['short_id'] = $transaction['compropago_short_id']; - $json['reference'] = $order['order_id']; - return; - case 'charge.expired': - $status_id = 14; - break; - default: - $message = 'Invalid webhook type ' . $status; - throw new \Exception($message); - } - - $query = "UPDATE ". DB_PREFIX . "order SET order_status_id = ".$status_id." WHERE order_id = {$order['order_id']}"; - - $this->db->query($query); - - $json['message'] = 'OK - ' . $status; - $json['short_id'] = $transaction['compropago_short_id']; - $json['reference'] = $order['order_id']; - return; - } - - /** - * Render success page of ComproPago - */ - public function success() { - $this->language->load('extension/payment/compropago'); - - $data['cpid'] = isset($_GET['cpid']) ? $_GET['cpid'] : ''; - $method = isset($_GET['method']) ? $_GET['method'] : ''; - - $this->clear_session(); - $this->add_breadcrums($data, $method); - $this->add_data($data); - $this->add_sections($data); - - $response = $this->load->view('extension/payment/compropago_receipt', $data); - - return $this->response->setOutput($response); - } - - /** - * Clear checkout session - */ - private function clear_session() { - if (isset($this->session->data['order_id'])) { - $this->cart->clear(); - - unset($this->session->data['shipping_method']); - unset($this->session->data['shipping_methods']); - unset($this->session->data['payment_method']); - unset($this->session->data['payment_methods']); - unset($this->session->data['guest']); - unset($this->session->data['comment']); - unset($this->session->data['order_id']); - unset($this->session->data['coupon']); - unset($this->session->data['reward']); - unset($this->session->data['voucher']); - unset($this->session->data['vouchers']); - unset($this->session->data['totals']); - } - } - - /** - * Add breadcrums to the success page - * @param $data - */ - private function add_breadcrums(&$data, $method) { - $checkout_link = $this->url->link( - "extension/payment/compropago/success&method=$method&cpid={$data['cpid']}" - ); - - $data['breadcrumbs'] = array(); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_home'), - 'href' => $this->url->link('common/home') - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_basket'), - 'href' => $this->url->link('checkout/cart') - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_checkout'), - 'href' => $this->url->link('checkout/checkout', '', true) - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_success'), - 'href' => $checkout_link - ); - } - - /** - * Add user data to success page - * @param $data - */ - private function add_data(&$data) { - $this->language->load('extension/payment/compropago'); - - if ($this->customer->isLogged()) { - $data['text_message'] = sprintf( - $this->language->get('text_customer'), - $this->url->link('account/account', '', true), - $this->url->link('account/order', '', true), - $this->url->link('account/download', '', true), - $this->url->link('information/contact') - ); - } else { - $data['text_message'] = sprintf( - $this->language->get('text_guest'), - $this->url->link('information/contact') - ); - } - } - - /** - * Add view sections - * @param $data - */ - private function add_sections(&$data) { - $data['continue'] = $this->url->link('common/home'); - $data['column_left'] = $this->load->controller('common/column_left'); - $data['column_right'] = $this->load->controller('common/column_right'); - $data['content_top'] = $this->load->controller('common/content_top'); - $data['content_bottom'] = $this->load->controller('common/content_bottom'); - $data['footer'] = $this->load->controller('common/footer'); - $data['header'] = $this->load->controller('common/header'); - } -} \ No newline at end of file + +class ControllerExtensionPaymentCompropago extends Controller +{ + /** + * Webhook to approve an order of Cash or SPEI methods + * @throws Exception + */ + public function webhook() + { + $this->response->addHeader('Content-Type: application/json'); + + $this->load->model('extension/payment/compropago_spei'); + $this->load->model('setting/setting'); + $this->load->model('checkout/order'); + + $json = [ + 'status' => 'success', + 'message' => '', + 'short_id' => null, + 'reference' => null, + ]; + $request = file_get_contents('php://input'); + + try + { + $orderInfo = json_decode($request, true); + + if (empty($request) || empty($orderInfo['id'])) + { + throw new \Exception('Invalid request'); + } + + if ($orderInfo['short_id'] == '000000') + { + $json ['message'] = 'OK - TEST'; + $json ['short_id'] = $orderInfo['short_id']; + + $this->response->setOutput(json_encode($json)); + return; + } + + $order = $this->model_checkout_order->getOrder($orderInfo['order_info']['order_id']); + if (empty($order)) + { + throw new \Exception("Order not found"); + } + + $transaction = $this->getTransaction($order, $orderInfo['id']); + + switch ($transaction['method']) + { + case 'spei': + $this->proccessSpei($json, $order, $transaction); + break; + case 'cash': + $this->proccessCash($json, $order, $transaction); + break; + default: + $message = "Invalid payment method {$transaction['method']}"; + throw new \Exception($message); + } + } + catch (\Exception $e) + { + http_response_code(500); + $json['status'] = 'error'; + $json['message'] = $e->getMessage(); + } + + $this->response->setOutput(json_encode($json)); + return; + } + + /** + * GEt transaction info of an order + * @param array $order + * @return array + * @throws Exception + */ + private function getTransaction($order, $cpid) + { + $query = "SELECT compropago_data + FROM " . DB_PREFIX . "order + WHERE order_id = {$order['order_id']}"; + + $result = $this->db->query($query); + + if ($result->num_rows < 1 || empty($result->row['compropago_data'])) + { + throw new \Exception("Can't find order transaction"); + } + + $transaction = unserialize($result->row['compropago_data']); + + if ($cpid != $transaction['compropago_id']) + { + throw new \Exception("Order not found"); + } + + return $transaction; + } + + /** + * Proccess SPEI payment + * @param array $json + * @param array $order + * @throws Exception + */ + private function proccessSpei(&$json, $order, $transaction) + { + $verified = $this->model_extension_payment_compropago_spei->verifyOrder($transaction['compropago_id']); + + switch ($verified->status) + { + case 'PENDING': + $status = 'charge.pending'; + break; + case 'ACCEPTED': + $status = 'charge.success'; + break; + case 'EXPIRED': + $status = 'charge.expired'; + break; + } + + $this->updateOrderStatus($json, $status, $order, $transaction); + } + + /** + * Proccess Cash payment + * @param array $json + * @param array $order + * @param array $transaction + * @throws Exception + */ + private function proccessCash(&$json, $order, $transaction) + { + $client = new Client( + $this->config->get('payment_compropago_publickey'), + $this->config->get('payment_compropago_privatekey'), + $this->config->get('payment_compropago_mode') === '1' + ); + + $verified = $client->api->verifyOrder($transaction['compropago_id']); + + $this->updateOrderStatus($json, $verified->type, $order, $transaction); + } + + /** + * Update order status + * @param array $json + * @param string $status + * @param array $order + * @param array $transaction + * @throws Exception + */ + private function updateOrderStatus(&$json, $status, $order, $transaction) + { + switch ($status) + { + case 'charge.success': + $status_id = 2; + break; + case 'charge.pending': + $json['message'] = "OK - $status"; + $json['short_id'] = $transaction['compropago_short_id']; + $json['reference'] = $order['order_id']; + return; + case 'charge.expired': + $status_id = 14; + break; + default: + throw new \Exception("Invalid webhook type $status"); + } + + $query = "UPDATE ". DB_PREFIX . "order + SET order_status_id = {$status_id} + WHERE order_id = {$order['order_id']}"; + + $this->db->query($query); + + $json['message'] = "OK - $status"; + $json['short_id'] = $transaction['compropago_short_id']; + $json['reference'] = $order['order_id']; + + return; + } + + /** + * Render success page of ComproPago + */ + public function success() + { + $this->language->load('extension/payment/compropago'); + + $data['cpid'] = isset($_GET['cpid']) ? $_GET['cpid'] : ''; + $method = isset($_GET['method']) ? $_GET['method'] : ''; + + $this->clear_session(); + $this->add_breadcrums($data, $method); + $this->add_data($data); + $this->add_sections($data); + + $response = $this->load->view('extension/payment/compropago_receipt', $data); + + return $this->response->setOutput($response); + } + + /** + * Clear checkout session + */ + private function clear_session() + { + $session_data = [ + 'shipping_method', + 'shipping_methods', + 'payment_method', + 'payment_methods', + 'guest', + 'comment', + 'order_id', + 'coupon', + 'reward', + 'voucher', + 'vouchers', + 'totals' + ]; + if (isset($this->session->data['order_id'])) + { + $this->cart->clear(); + foreach ($session_data as $data) unset($this->session->data[$data]); + } + } + + /** + * Add breadcrums to the success page + * @param $data + */ + private function add_breadcrums(&$data, $method) + { + $checkout_link = $this->url->link( + "extension/payment/compropago/success&method=$method&cpid={$data['cpid']}" + ); + + $data['breadcrumbs'] = []; + + $data['breadcrumbs'][] = [ + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/home') + ]; + + $data['breadcrumbs'][] = [ + 'text' => $this->language->get('text_basket'), + 'href' => $this->url->link('checkout/cart') + ]; + + $data['breadcrumbs'][] = [ + 'text' => $this->language->get('text_checkout'), + 'href' => $this->url->link('checkout/checkout', '', true) + ]; + + $data['breadcrumbs'][] = [ + 'text' => $this->language->get('text_success'), + 'href' => $checkout_link + ]; + } + + /** + * Add user data to success page + * @param $data + */ + private function add_data(&$data) + { + $this->language->load('extension/payment/compropago'); + + if ($this->customer->isLogged()) + { + $data['text_message'] = sprintf( + $this->language->get('text_customer'), + $this->url->link('account/account', '', true), + $this->url->link('account/order', '', true), + $this->url->link('account/download', '', true), + $this->url->link('information/contact') + ); + } + else + { + $data['text_message'] = sprintf( + $this->language->get('text_guest'), + $this->url->link('information/contact') + ); + } + } + + /** + * Add view sections + * @param $data + */ + private function add_sections(&$data) + { + $data['continue'] = $this->url->link('common/home'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['column_right'] = $this->load->controller('common/column_right'); + $data['content_top'] = $this->load->controller('common/content_top'); + $data['content_bottom'] = $this->load->controller('common/content_bottom'); + $data['footer'] = $this->load->controller('common/footer'); + $data['header'] = $this->load->controller('common/header'); + } +} diff --git a/upload/catalog/controller/extension/payment/compropago_cash.php b/upload/catalog/controller/extension/payment/compropago_cash.php index 425642e..e7481a2 100644 --- a/upload/catalog/controller/extension/payment/compropago_cash.php +++ b/upload/catalog/controller/extension/payment/compropago_cash.php @@ -5,131 +5,141 @@ require_once __DIR__ . '/../../../../system/library/compropago/vendor/autoload.php'; -use CompropagoSdk\Client; -use CompropagoSdk\Factory\Factory; - -class ControllerExtensionPaymentCompropagoCash extends Controller { - - /** - * Render form in checkout - * @return mixed - */ - public function index() { - $this->language->load('extension/payment/compropago_cash'); - $this->load->model('checkout/order'); - - $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); - - $client = new Client( - $this->config->get('payment_compropago_publickey'), - $this->config->get('payment_compropago_privatekey'), - $this->config->get('payment_compropago_mode') == '1' - ); - - $allow_providers = explode(',', $this->config->get('payment_compropago_cash_providers')); - - - var_dump($order_info['total']); - - try { - $all_providers = $client->api->listProviders( - floatval($order_info['total']), - $order_info['currency_code'] - ); - } catch (Exception $e) { - $all_providers = []; - } - - $data['providers'] = []; - - foreach ($all_providers as $provider) { - if (in_array($provider->internal_name, $allow_providers)) { - $data['providers'][] = $provider; - } - } - - return $this->load->view('extension/payment/compropago_cash_form', $data); - } - - /** - * Action to create the cash order - */ - public function confirm() { - $this->response->addHeader('Content-Type: application/json'); - - $json = array(); - - if ($this->session->data['payment_method']['code'] == 'compropago_cash') { - $this->load->model('checkout/order'); - - $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); - - try { - $new_order = $this->create_order($order); - $json['status'] = 'success'; - $json['redirect'] = $this->url->link( - 'extension/payment/compropago/success&method=cash&cpid='. $new_order->id - ); - }catch (Exception $e) { - $json['status'] = 'error'; - $json['message'] = $e->getMessage(); - } - } - - $this->response->setOutput(json_encode($json)); - return; - } - - /** - * Create compropago order - * @param array $order - * @return \CompropagoSdk\Factory\Models\NewOrderInfo - * @throws Exception - */ - private function create_order($order) { - $client = new Client( - $this->config->get('payment_compropago_publickey'), - $this->config->get('payment_compropago_privatekey'), - $this->config->get('payment_compropago_mode') == '1' - ); - - $order_info = [ - 'order_id' => "{$this->session->data['order_id']}", - 'order_name' => "{$this->session->data['order_id']}", - 'order_price' => floatval($order['total']), - 'customer_name' => $order['payment_firstname'] . ' ' . $order['payment_lastname'], - 'customer_email' => $order['email'], - 'currency' => strtoupper($order['currency_code']), - 'payment_type' => $this->request->post['provider'], - 'app_client_name' => 'opencart', - 'app_client_version' => VERSION - ]; - - $cp_order = Factory::getInstanceOf('PlaceOrderInfo', $order_info); - $new_order = $client->api->placeOrder($cp_order); - - $this->add_transaction($new_order); - - return $new_order; - } - - /** - * Add transaction information to the order - * @param $order - */ - private function add_transaction($order) { - $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], 1); - - $data = [ - 'compropago_id' => $order->id, - 'compropago_short_id' => $order->short_id, - 'method' => 'cash' - ]; - - $data = serialize($data); - - $query = "UPDATE " . DB_PREFIX . "order SET compropago_data = '{$data}' WHERE order_id = {$order->order_info->order_id}"; - - $this->db->query($query); - } +use CompropagoSdk\Resources\Payments\Cash as sdkCash; + + +class ControllerExtensionPaymentCompropagoCash extends Controller +{ + /** + * Render form in checkout + * @return mixed + */ + public function index() + { + $this->language->load('extension/payment/compropago_cash'); + $this->load->model('checkout/order'); + $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']); + + try + { + $client = (new sdkCash)->withKeys( + $this->config->get('payment_compropago_publickey'), + $this->config->get('payment_compropago_privatekey') + ); + $all_providers = $client->getProviders( + floatval($order_info['total']), + $order_info['currency_code'] + ); + } + catch (Exception $e) + { + $all_providers = []; + } + + $data['providers'] = []; + $allow_providers = explode(',', $this->config->get('payment_compropago_cash_providers')); + foreach ($all_providers as $provider) + { + if (in_array($provider['internal_name'], $allow_providers)) + { + $data['providers'][] = $provider; + } + } + + return $this->load->view('extension/payment/compropago_cash_form', $data); + } + + /** + * Action to create the cash order + */ + public function confirm() + { + $this->response->addHeader('Content-Type: application/json'); + $json = [ + 'status' => null, + 'message' => '', + 'redirect' => false + ]; + + if ($this->session->data['payment_method']['code'] == 'compropago_cash') + { + $this->load->model('checkout/order'); + $order = $this->model_checkout_order->getOrder( + $this->session->data['order_id'] + ); + + try + { + $new_order = $this->create_order($order); + + $json['status'] = 'success'; + $json['redirect'] = $this->url->link( + 'extension/payment/compropago/success&method=cash&cpid='. $new_order->id + ); + } + catch (Exception $e) + { + $json['status'] = 'error'; + $json['message'] = $e->getMessage(); + } + } + + $this->response->setOutput(json_encode($json)); + return; + } + + /** + * Create compropago order + * @param array $order + * @return \CompropagoSdk\Factory\Models\NewOrderInfo + * @throws Exception + */ + private function create_order($order) + { + $order_info = [ + 'order_id' => "{$this->session->data['order_id']}", + 'order_name' => "{$this->session->data['order_id']}", + 'order_price' => floatval($order['total']), + 'customer_name' => "{$order['payment_firstname']} {$order['payment_lastname']}", + 'customer_email' => $order['email'], + 'customer_phone' => "{$oder['telephone']}", + 'currency' => strtoupper($order['currency_code']), + 'payment_type' => $this->request->post['provider'], + 'app_client_name' => 'opencart', + 'app_client_version' => VERSION + ]; + + $client = (new sdkCash)->withKeys( + $this->config->get('payment_compropago_publickey'), + $this->config->get('payment_compropago_privatekey') + ); + $new_order = $client->createOrder( $order_info ); + + $this->add_transaction($new_order); + + return $new_order; + } + + /** + * Add transaction information to the order + * @param $order + */ + private function add_transaction($order) + { + $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], 1); + + $data = [ + 'compropago_id' => $order['id'], + 'compropago_short_id' => $order['short_id'], + 'method' => 'cash' + ]; + + $data = serialize($data); + + $query = "UPDATE " . DB_PREFIX . "order + SET compropago_data = '{$data}' + WHERE order_id = {$order['order_info']['order_id']}"; + + $this->db->query($query); + } } diff --git a/upload/catalog/controller/extension/payment/compropago_spei.php b/upload/catalog/controller/extension/payment/compropago_spei.php index 8377316..8c08f58 100644 --- a/upload/catalog/controller/extension/payment/compropago_spei.php +++ b/upload/catalog/controller/extension/payment/compropago_spei.php @@ -3,205 +3,238 @@ * @author Eduardo Aguilar */ -class ControllerExtensionPaymentCompropagoSpei extends Controller { - /** - * Render form in checkout - * @return mixed - */ - public function index() { - $this->language->load('extension/payment/compropago_spei'); - - $data['text_spei_details'] = $this->language->get('text_spei_details'); - - return $this->load->view('extension/payment/compropago_spei_form', $data); - } - - /** - * Action to create the cash order - */ - public function confirm() { - $this->response->addHeader('Content-Type: application/json'); - - $json = array(); - - if ($this->session->data['payment_method']['code'] == 'compropago_spei') { - $this->load->model('checkout/order'); - - $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); - - try { - $new_order = $this->create_order($order); - $json['status'] = 'success'; - $json['redirect'] = $this->url->link( - 'extension/payment/compropago/success&method=spei&cpid='. $new_order->id - ); - }catch (Exception $e) { - $json['status'] = 'error'; - $json['message'] = $e->getMessage(); - } - } - - $this->response->setOutput(json_encode($json)); - return; - } - - /** - * Success page for cash payments - * @return mixed - */ - public function success() { - $data['cpid'] = isset($_GET['cpid']) ? $_GET['cpid'] : ''; - - $this->clear_session(); - $this->add_breadcrums($data); - $this->add_data($data); - $this->add_sections($data); - - $response = $this->load->view('extension/payment/compropago_cash_receipt', $data); - - return $this->response->setOutput($response); - } - - /** - * Add user data to success page - * @param $data - */ - private function add_data(&$data) { - $this->language->load('extension/payment/compropago_spei'); - - if ($this->customer->isLogged()) { - $data['text_message'] = sprintf( - $this->language->get('text_customer'), - $this->url->link('account/account', '', true), - $this->url->link('account/order', '', true), - $this->url->link('account/download', '', true), - $this->url->link('information/contact') - ); - } else { - $data['text_message'] = sprintf( - $this->language->get('text_guest'), - $this->url->link('information/contact') - ); - } - } - - /** - * Add view sections - * @param $data - */ - private function add_sections(&$data) { - $data['continue'] = $this->url->link('common/home'); - $data['column_left'] = $this->load->controller('common/column_left'); - $data['column_right'] = $this->load->controller('common/column_right'); - $data['content_top'] = $this->load->controller('common/content_top'); - $data['content_bottom'] = $this->load->controller('common/content_bottom'); - $data['footer'] = $this->load->controller('common/footer'); - $data['header'] = $this->load->controller('common/header'); - } - - /** - * Clear checkout session - */ - private function clear_session() { - if (isset($this->session->data['order_id'])) { - $this->cart->clear(); - - unset($this->session->data['shipping_method']); - unset($this->session->data['shipping_methods']); - unset($this->session->data['payment_method']); - unset($this->session->data['payment_methods']); - unset($this->session->data['guest']); - unset($this->session->data['comment']); - unset($this->session->data['order_id']); - unset($this->session->data['coupon']); - unset($this->session->data['reward']); - unset($this->session->data['voucher']); - unset($this->session->data['vouchers']); - unset($this->session->data['totals']); - } - } - - /** - * Add breadcrums to the success page - * @param $data - */ - private function add_breadcrums(&$data) { - $data['breadcrumbs'] = array(); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_home'), - 'href' => $this->url->link('common/home') - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_basket'), - 'href' => $this->url->link('checkout/cart') - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_checkout'), - 'href' => $this->url->link('checkout/checkout', '', true) - ); - - $data['breadcrumbs'][] = array( - 'text' => $this->language->get('text_success'), - 'href' => $this->url->link('extension/payment/compropago_spei/success') - ); - } - - /** - * Create compropago order - * @param array $order - * @return \CompropagoSdk\Factory\Models\NewOrderInfo - * @throws Exception - */ - private function create_order($order) { - $this->load->model('extension/payment/compropago_spei'); - - $customer_name = $order['payment_firstname'] . ' ' . $order['payment_lastname']; - - $order_info = array( - "product" => [ - "id" => "{$this->session->data['order_id']}", - "price" => floatval($order['total']), - "name" => "{$this->session->data['order_id']}", - "url" => "", - "currency" => strtoupper($order['currency_code']) - ], - "customer" => [ - "name" => $customer_name, - "email" => $order['email'], - "phone" => "" - ], - "payment" => [ - "type" => "SPEI" - ] - ); - - $new_order = $this->model_extension_payment_compropago_spei->createOrder($order_info); - - $this->add_transaction($new_order); - - return $new_order; - } - - /** - * Add transaction information to the order - * @param $order - */ - private function add_transaction($order) { - $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], 1); - - $data = [ - 'compropago_id' => $order->id, - 'compropago_short_id' => $order->shortId, - 'method' => 'spei' - ]; - - $data = serialize($data); - - $query = "UPDATE " . DB_PREFIX . "order SET compropago_data = '{$data}' WHERE order_id = {$this->session->data['order_id']}"; - - $this->db->query($query); - } -} \ No newline at end of file +require_once __DIR__ . '/../../../../system/library/compropago/vendor/autoload.php'; + +use CompropagoSdk\Resources\Payments\Spei as sdkSpei; + + +class ControllerExtensionPaymentCompropagoSpei extends Controller +{ + /** + * Render form in checkout + * @return mixed + */ + public function index() + { + $this->language->load('extension/payment/compropago_spei'); + + $data['text_spei_details'] = $this->language->get('text_spei_details'); + + return $this->load->view('extension/payment/compropago_spei_form', $data); + } + + /** + * Action to create the cash order + */ + public function confirm() + { + $this->response->addHeader('Content-Type: application/json'); + $json = [ + 'status' => null, + 'message' => '', + 'redirect' => false + ]; + + if ($this->session->data['payment_method']['code'] == 'compropago_spei') + { + $this->load->model('checkout/order'); + $order = $this->model_checkout_order->getOrder( + $this->session->data['order_id'] + ); + + try + { + $new_order = $this->create_order($order); + + $json['status'] = 'success'; + $json['redirect'] = $this->url->link( + 'extension/payment/compropago/success&method=spei&cpid='. $new_order->id + ); + } + catch (Exception $e) + { + $json['status'] = 'error'; + $json['message'] = $e->getMessage(); + } + } + + $this->response->setOutput(json_encode($json)); + return; + } + + /** + * Success page for cash payments + * @return mixed + */ + public function success() + { + $data['cpid'] = isset($_GET['cpid']) ? $_GET['cpid'] : ''; + + $this->clear_session(); + $this->add_breadcrums($data); + $this->add_data($data); + $this->add_sections($data); + + $response = $this->load->view('extension/payment/compropago_cash_receipt', $data); + + return $this->response->setOutput($response); + } + + /** + * Add user data to success page + * @param $data + */ + private function add_data(&$data) + { + $this->language->load('extension/payment/compropago_spei'); + + if ($this->customer->isLogged()) + { + $data['text_message'] = sprintf( + $this->language->get('text_customer'), + $this->url->link('account/account', '', true), + $this->url->link('account/order', '', true), + $this->url->link('account/download', '', true), + $this->url->link('information/contact') + ); + } + else + { + $data['text_message'] = sprintf( + $this->language->get('text_guest'), + $this->url->link('information/contact') + ); + } + } + + /** + * Add view sections + * @param $data + */ + private function add_sections(&$data) + { + $data['continue'] = $this->url->link('common/home'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['column_right'] = $this->load->controller('common/column_right'); + $data['content_top'] = $this->load->controller('common/content_top'); + $data['content_bottom'] = $this->load->controller('common/content_bottom'); + $data['footer'] = $this->load->controller('common/footer'); + $data['header'] = $this->load->controller('common/header'); + } + + /** + * Clear checkout session + */ + private function clear_session() + { + $session_data = [ + 'shipping_method', + 'shipping_methods', + 'payment_method', + 'payment_methods', + 'guest', + 'comment', + 'order_id', + 'coupon', + 'reward', + 'voucher', + 'vouchers', + 'totals' + ]; + if (isset($this->session->data['order_id'])) + { + $this->cart->clear(); + foreach ($session_data as $data) unset($this->session->data[$data]); + } + } + + /** + * Add breadcrums to the success page + * @param $data + */ + private function add_breadcrums(&$data) + { + $data['breadcrumbs'] = []; + + $data['breadcrumbs'][] = [ + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/home') + ]; + + $data['breadcrumbs'][] = [ + 'text' => $this->language->get('text_basket'), + 'href' => $this->url->link('checkout/cart') + ]; + + $data['breadcrumbs'][] = [ + 'text' => $this->language->get('text_checkout'), + 'href' => $this->url->link('checkout/checkout', '', true) + ]; + + $data['breadcrumbs'][] = [ + 'text' => $this->language->get('text_success'), + 'href' => $this->url->link('extension/payment/compropago_spei/success') + ]; + } + + /** + * Create compropago order + * @param array $order + * @return \CompropagoSdk\Factory\Models\NewOrderInfo + * @throws Exception + */ + private function create_order($order) + { + $this->load->model('extension/payment/compropago_spei'); + + $order_info = [ + "product" => [ + "id" => "{$this->session->data['order_id']}", + "price" => floatval($order['total']), + "name" => "{$this->session->data['order_id']}", + "url" => "", + "currency" => strtoupper($order['currency_code']) + ], + "customer" => [ + "name" => "{$order['payment_firstname']} {$order['payment_lastname']}", + "email" => $order['email'], + "phone" => "{$oder['telephone']}" + ], + "payment" => [ + "type" => "SPEI" + ] + ]; + + $client = (new sdkSpei)->withKeys( + $this->config->get('payment_compropago_publickey'), + $this->config->get('payment_compropago_privatekey') + ); + $new_order = $client->createOrder( $order_info ); + $this->add_transaction($new_order); + + return $new_order; + } + + /** + * Add transaction information to the order + * @param $order + */ + private function add_transaction($order) + { + $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], 1); + + $data = [ + 'compropago_id' => $order['id'], + 'compropago_short_id' => $order['shortId'], + 'method' => 'spei' + ]; + + $data = serialize($data); + + $query = "UPDATE " . DB_PREFIX . "order + SET compropago_data = '{$data}' + WHERE order_id = {$this->session->data['order_id']}"; + + $this->db->query($query); + } +} diff --git a/upload/catalog/language/en-gb/extension/payment/compropago.php b/upload/catalog/language/en-gb/extension/payment/compropago.php index aac0bf1..c75f671 100644 --- a/upload/catalog/language/en-gb/extension/payment/compropago.php +++ b/upload/catalog/language/en-gb/extension/payment/compropago.php @@ -1,5 +1,10 @@ Your order has been successfully processed!

You can view your order history by going to the my account page and by clicking on history.

If your purchase has an associated download, you can go to the account downloads page to view them.

Please direct any questions you have to the store owner.

Thanks for shopping with us online!

'; -$_['text_guest'] = '

Your order has been successfully processed!

Please direct any questions you have to the store owner.

Thanks for shopping with us online!

'; \ No newline at end of file +$_['text_customer'] = '

Your order has been successfully processed!

'. + '

You can view your order history by going to the my account page and by clicking on history.

If your purchase has an associated download, you can go to the account downloads page to view them.

Please direct any questions you have to the store owner.

Thanks for shopping with us online!

'; +$_['text_guest'] = '

Your order has been successfully processed!

'. + '

Please direct any questions you have to the store owner.

Thanks for shopping with us online!

'; diff --git a/upload/catalog/language/en-gb/extension/payment/compropago_cash.php b/upload/catalog/language/en-gb/extension/payment/compropago_cash.php index fd3f44b..5752309 100644 --- a/upload/catalog/language/en-gb/extension/payment/compropago_cash.php +++ b/upload/catalog/language/en-gb/extension/payment/compropago_cash.php @@ -1,5 +1,9 @@ " . @@ -8,5 +12,4 @@ "" . ""; - $_['error_no_providers'] = 'No providers available at the moment'; diff --git a/upload/catalog/language/en-gb/extension/payment/compropago_spei.php b/upload/catalog/language/en-gb/extension/payment/compropago_spei.php index ac02f93..0743a6c 100644 --- a/upload/catalog/language/en-gb/extension/payment/compropago_spei.php +++ b/upload/catalog/language/en-gb/extension/payment/compropago_spei.php @@ -1,5 +1,9 @@ " . - "Crea la orden y recibiras las instrucciones a tu email para dar de alta la cuenta y realizar la". - "transferencia desde tu banca en linea."; +/** + * English + */ + +$_['text_spei_details'] = "Realiza tu pago a través de SPEI para cualquier banco, es muy rapido y sencillo.
" . + "Crea la orden y recibiras las instrucciones a tu email para dar de alta la cuenta y". + "realizar la transferencia desde tu banca en linea."; diff --git a/upload/catalog/language/es-mx/extension/payment/compropago.php b/upload/catalog/language/es-mx/extension/payment/compropago.php new file mode 100644 index 0000000..e50860f --- /dev/null +++ b/upload/catalog/language/es-mx/extension/payment/compropago.php @@ -0,0 +1,10 @@ +¡Tu orden ha sido procesada correctamente!

'. + '

You can view your order history by going to the my account page and by clicking on history.

If your purchase has an associated download, you can go to the account downloads page to view them.

Please direct any questions you have to the store owner.

Thanks for shopping with us online!

'; +$_['text_guest'] = '

¡Tu orden ha sido procesada correctamente!

'. + '

Please direct any questions you have to the store owner.

Thanks for shopping with us online!

'; diff --git a/upload/catalog/language/es-mx/extension/payment/compropago_cash.php b/upload/catalog/language/es-mx/extension/payment/compropago_cash.php new file mode 100644 index 0000000..fdeee38 --- /dev/null +++ b/upload/catalog/language/es-mx/extension/payment/compropago_cash.php @@ -0,0 +1,15 @@ +" . + "" . + "* Comisionistas autorizados por la CNBV como corresponsales bancarios" . + "" . + ""; + +$_['error_no_providers'] = 'No hay proveedores disponibles en este momento'; diff --git a/upload/catalog/language/es-mx/extension/payment/compropago_spei.php b/upload/catalog/language/es-mx/extension/payment/compropago_spei.php new file mode 100644 index 0000000..7203c14 --- /dev/null +++ b/upload/catalog/language/es-mx/extension/payment/compropago_spei.php @@ -0,0 +1,9 @@ +" . + "Crea la orden y recibiras las instrucciones a tu email para dar de alta la cuenta y realizar la". + "transferencia desde tu banca en linea."; diff --git a/upload/catalog/model/extension/payment/compropago_cash.php b/upload/catalog/model/extension/payment/compropago_cash.php index 6f5019d..3cf0859 100644 --- a/upload/catalog/model/extension/payment/compropago_cash.php +++ b/upload/catalog/model/extension/payment/compropago_cash.php @@ -1,21 +1,31 @@ language->load('extension/payment/compropago_cash'); + public function getMethod($address, $total) + { + $this->language->load( 'extension/payment/' . self::GATEWAY_NAME ); - $title = ''; - $title .= ' - ' . $this->config->get('payment_compropago_cash_title'); + $title = '' + . ' ' . $this->config->get('payment_' . self::GATEWAY_NAME . '_title'); - return array( - 'code' => 'compropago_cash', + return [ + 'code' => self::GATEWAY_NAME, 'title' => $title, 'terms' => '', - 'sort_order' => $this->config->get('payment_compropago_cash_cash_sort_order') - ); + 'sort_order' => $this->config->get('payment_' . self::GATEWAY_NAME . '_sort_order') + ]; } -} \ No newline at end of file +} diff --git a/upload/catalog/model/extension/payment/compropago_spei.php b/upload/catalog/model/extension/payment/compropago_spei.php index 9ac298c..d9bf872 100644 --- a/upload/catalog/model/extension/payment/compropago_spei.php +++ b/upload/catalog/model/extension/payment/compropago_spei.php @@ -1,79 +1,31 @@ language->load('extension/payment/compropago_spei'); + public function getMethod($address, $total) + { + $this->language->load( 'extension/payment/' . self::GATEWAY_NAME ); - $title = ''; - $title .= ' - ' . $this->config->get('payment_compropago_spei_title'); + $title = '' + . ' ' . $this->config->get('payment_' . self::GATEWAY_NAME . '_title'); - return array( - 'code' => 'compropago_spei', + return [ + 'code' => self::GATEWAY_NAME, 'title' => $title, 'terms' => '', - 'sort_order' => $this->config->get('payment_compropago_spei_sort_order') - ); - } - - /** - * Create SPEI order - * @param array $orderInfo - * @return object - * @throws Exception - */ - public function createOrder($orderInfo) { - $this->load->model('setting/setting'); - - $auth = [ - 'user' => $this->config->get('payment_compropago_privatekey'), - 'pass' => $this->config->get('payment_compropago_publickey') + 'sort_order' => $this->config->get('payment_' . self::GATEWAY_NAME . '_sort_order') ]; - - $url = 'https://api.compropago.com/v2/orders'; - $response = Request::post($url, $orderInfo, array(), $auth); - - if ($response->statusCode != 200) { - throw new \Exception("SPEI Error #: {$response->statusCode}"); - } - $body = json_decode($response->body); - - return $body->data; - } - - /** - * Verify the status of a SPEI payment - * @param string $orderId - * @return object - * @throws Exception - */ - public function verifyOrder($orderId) { - $this->load->model('setting/setting'); - - $auth = [ - 'user' => $this->config->get('payment_compropago_privatekey'), - 'pass' => $this->config->get('payment_compropago_publickey') - ]; - - $url = 'https://api.compropago.com/v2/orders/' . $orderId; - - $response = Request::get($url, array(), $auth); - - if ($response->statusCode != 200) { - $message = "Can't verify order"; - throw new \Exception($message); - } - - $body = json_decode($response->body); - - return $body->data; } -} \ No newline at end of file +} diff --git a/upload/catalog/view/theme/default/template/extension/payment/compropago_cash_form.twig b/upload/catalog/view/theme/default/template/extension/payment/compropago_cash_form.twig index b9452a9..e6fc257 100644 --- a/upload/catalog/view/theme/default/template/extension/payment/compropago_cash_form.twig +++ b/upload/catalog/view/theme/default/template/extension/payment/compropago_cash_form.twig @@ -11,7 +11,7 @@ {{ text_cnbv }} {% else %} - + {{ error_no_providers }} {% endif %} @@ -22,32 +22,40 @@ +