diff --git a/.version b/.version index 238d6e8..1cc5f65 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.0.7 +1.1.0 \ No newline at end of file diff --git a/README.md b/README.md index 480e428..7a945bb 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ The author of this plugin can NEVER be held responsible for this software. There is no warranty what so ever. You accept this by using this software. ## Changelog +* 1.1.0 - Added iframe option * 1.0.7 - Supports Prestashop 1.7 * 1.0.1 - Improve Prestashop versions support * 1.0.0 - Initial Release diff --git a/modules/payxpert/config.xml b/modules/payxpert/config.xml index f11969b..1ae818a 100644 --- a/modules/payxpert/config.xml +++ b/modules/payxpert/config.xml @@ -1,13 +1,13 @@ - payxpert - - - - - - - 1 - 1 - + payxpert + + + + + + + 1 + 1 + \ No newline at end of file diff --git a/modules/payxpert/controllers/front/iframe.php b/modules/payxpert/controllers/front/iframe.php new file mode 100644 index 0000000..881285e --- /dev/null +++ b/modules/payxpert/controllers/front/iframe.php @@ -0,0 +1,71 @@ +context->controller->addCSS(($this->module->getPath()) . 'css/iframe.css', 'all'); + $cart = $this->context->cart; + + $params = array(); + + // These should be filled only with Prestashop >= 1.7 + $paymentType = Tools::getValue('payment_type', null); + $paymentProvider = Tools::getValue('payment_provider', null); + + if (version_compare(_PS_VERSION_, '1.7', '>=')) { + if ($paymentType !== null && PayXpert\Connect2Pay\C2PValidate::isPayment($paymentType)) { + + $payment = $this->module->getPaymentClient($cart, $paymentType, $paymentProvider); + + if ($payment->preparePayment() == false) { + $message = "PayXpert : can't prepare transaction - " . $payment->getClientErrorMessage(); + $this->module->addLog($message, 3); + header('Location: ' . $this->module->getPageLinkCompat('order', true, NULL, "step=3")); + } + + $src = $payment->getCustomerRedirectURL(); + } + } + + $this->context->smarty->assign( + array(/* */ + 'src' => $src, /* */ + 'this_link_back' => $this->module->getPageLinkCompat('order', true, NULL, "step=3") + ) /* */ + ); + + $this->setTemplate('module:payxpert/views/templates/hook/iframe.tpl'); + } +} \ No newline at end of file diff --git a/modules/payxpert/controllers/front/return.php b/modules/payxpert/controllers/front/return.php new file mode 100644 index 0000000..1c02fa0 --- /dev/null +++ b/modules/payxpert/controllers/front/return.php @@ -0,0 +1,56 @@ +context->cart)) { + $this->context->cart = new Cart(); + } + + $url = $this->module->getPageLinkCompat('order-confirmation'); + + $cart = $this->context->cart; + $customer = new Customer((int) ($cart->id_customer)); + $ctrlURLPrefix = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://'; + + $url .= '?id_cart=' . (int) ($cart->id) . '&id_module=' . (int) ($this->module->id) . '&key=' . $customer->secure_key; + + $this->context->smarty->assign( + array(/* */ + 'url' => $url + ) /* */ + ); + + $this->setTemplate('module:' . $this->module->name . '/views/templates/hook/return.tpl'); + } +} diff --git a/modules/payxpert/css/iframe.css b/modules/payxpert/css/iframe.css new file mode 100644 index 0000000..f5df611 --- /dev/null +++ b/modules/payxpert/css/iframe.css @@ -0,0 +1,20 @@ +.js-payment-your-module-name.disabled iframe { + display: none; +} + +.fluidIframe { + position: relative; + padding-bottom: 56.25%; /* proportion value to aspect ratio 16:9 (9 / 16 = 0.5625 or 56.25%) */ + padding-top: 30px; + height: 0; + overflow: hidden; +} + +.fluidIframe iframe { + border: none; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; +} \ No newline at end of file diff --git a/modules/payxpert/payxpert.php b/modules/payxpert/payxpert.php index 8936968..d73c434 100644 --- a/modules/payxpert/payxpert.php +++ b/modules/payxpert/payxpert.php @@ -33,7 +33,7 @@ class PayXpert extends PaymentModule { */ public function __construct() { $this->name = 'payxpert'; - $this->version = '1.0.8'; + $this->version = '1.1.0'; $this->tab = 'payments_gateways'; @@ -148,6 +148,7 @@ private function getModuleParameters() { $moduleParameters[] = 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT'; $moduleParameters[] = 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24'; $moduleParameters[] = 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL'; + $moduleParameters[] = 'PAYXPERT_IS_IFRAME'; } return $moduleParameters; @@ -184,23 +185,29 @@ public function hookPaymentOptions($params) { return; } + $controller = 'payment'; + + if ($this->isIframeMode()) { + $controller = 'iframe'; + } + $this->smarty->assign($this->getTemplateVarInfos()); $payment_options = array(); - $ccOption = $this->getCreditCardPaymentOption(); + $ccOption = $this->getCreditCardPaymentOption($controller); if ($ccOption != null) { $payment_options[] = $ccOption; } - $sofortOption = $this->getBankTransferViaSofortPaymentOption(); + $sofortOption = $this->getBankTransferViaSofortPaymentOption($controller); if ($sofortOption != null) { $payment_options[] = $sofortOption; } - $przelewy24Option = $this->getBankTransferViaPrzelewy24PaymentOption(); + $przelewy24Option = $this->getBankTransferViaPrzelewy24PaymentOption($controller); if ($przelewy24Option != null) { $payment_options[] = $przelewy24Option; } - $idealOption = $this->getBankTransferViaIDealPaymentOption(); + $idealOption = $this->getBankTransferViaIDealPaymentOption($controller); if ($idealOption != null) { $payment_options[] = $idealOption; } @@ -212,12 +219,12 @@ public function hookPaymentOptions($params) { * * @since Prestashop 1.7 */ - public function getCreditCardPaymentOption() { + public function getCreditCardPaymentOption($controller) { if (Configuration::get('PAYXPERT_PAYMENT_TYPE_CREDIT_CARD') == "true") { $option = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $option->setCallToActionText($this->l('Pay by Credit Card')); $option->setAction( - $this->context->link->getModuleLink($this->name, 'payment', + $this->context->link->getModuleLink($this->name, $controller, array('payment_type' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_CREDITCARD), true)); $this->context->smarty->assign('pxpCCLogo', @@ -235,12 +242,12 @@ public function getCreditCardPaymentOption() { * * @since Prestashop 1.7 */ - public function getBankTransferViaSofortPaymentOption() { + public function getBankTransferViaSofortPaymentOption($controller) { if (Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT') == "true") { $option = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $option->setCallToActionText($this->l('Pay by Bank Transfer via Sofort')); $option->setAction( - $this->context->link->getModuleLink($this->name, 'payment', + $this->context->link->getModuleLink($this->name, $controller, array('payment_type' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER, 'payment_provider' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_SOFORT), true)); @@ -259,12 +266,12 @@ public function getBankTransferViaSofortPaymentOption() { * * @since Prestashop 1.7 */ - public function getBankTransferViaPrzelewy24PaymentOption() { + public function getBankTransferViaPrzelewy24PaymentOption($controller) { if (Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24') == "true") { $option = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $option->setCallToActionText($this->l('Pay by Bank Transfer via Przelewy24')); $option->setAction( - $this->context->link->getModuleLink($this->name, 'payment', + $this->context->link->getModuleLink($this->name, $controller, array('payment_type' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER, 'payment_provider' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_PRZELEWY24), true)); @@ -283,12 +290,12 @@ public function getBankTransferViaPrzelewy24PaymentOption() { * * @since Prestashop 1.7 */ - public function getBankTransferViaIDealPaymentOption() { + public function getBankTransferViaIDealPaymentOption($controller) { if (Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL') == "true") { $option = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $option->setCallToActionText($this->l('Pay by Bank Transfer via iDeal')); $option->setAction( - $this->context->link->getModuleLink($this->name, 'payment', + $this->context->link->getModuleLink($this->name, $controller, array('payment_type' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER, 'payment_provider' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_IDEALKP), true)); @@ -323,7 +330,6 @@ public function hookPayment($params) { if (!$this->checkPaymentOption($params)) { return; } - $this->assignSmartyVariable('this_path', $this->_path); $this->assignSmartyVariable('this_path_ssl', (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . @@ -414,6 +420,30 @@ public function redirect($cart, $paymentType = null, $paymentProvider = null) { return "Payment type or provider is not enabled"; } + $payment = $this->getPaymentClient($cart, $paymentType, $paymentProvider); + + // prepare API + if ($payment->preparePayment() == false) { + $message = "PayXpert : can't prepare transaction - " . $payment->getClientErrorMessage(); + $this->addLog($message, 3); + return $message; + } + + header('Location: ' . $payment->getCustomerRedirectURL()); + exit(); + } + + /** + * Generates the Connect2Pay payment URL + * + * For Prestashop >= 1.5 + * + * @global type $cookie + * @param Cart $cart + * @return type + */ + public function getPaymentClient($cart, $paymentType = null, $paymentProvider = null) { + // get all informations $customer = new Customer((int) ($cart->id_customer)); $currency = new Currency((int) ($cart->id_currency)); @@ -495,20 +525,10 @@ public function redirect($cart, $paymentType = null, $paymentProvider = null) { (int) ($this->id) . '&key=' . $customer->secure_key); } else { $c2pClient->setCtrlCallbackURL($this->context->link->getModuleLink('payxpert', 'validation')); - $c2pClient->setCtrlRedirectURL( - $ctrlURLPrefix . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . (int) ($cart->id) . - '&id_module=' . (int) ($this->id) . '&key=' . $customer->secure_key); - } - - // prepare API - if ($c2pClient->preparePayment() == false) { - $message = "PayXpert : can't prepare transaction - " . $c2pClient->getClientErrorMessage(); - $this->addLog($message, 3); - return $message; + $c2pClient->setCtrlRedirectURL($this->getModuleLinkCompat('payxpert', 'return')); } - header('Location: ' . $c2pClient->getCustomerRedirectURL()); - exit(); + return $c2pClient; } /** @@ -599,11 +619,14 @@ public function getConfigFieldsValues() { Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24')); $idealPaymentType = Tools::getValue('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL', Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL')); + $isIframe = Tools::getValue('PAYXPERT_IS_IFRAME', + Configuration::get('PAYXPERT_IS_IFRAME')); $result['PAYXPERT_PAYMENT_TYPE_CREDIT_CARD'] = ($creditCardPaymentType === "true" || $creditCardPaymentType == 1) ? 1 : 0; $result['PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT'] = ($sofortPaymentType === "true" || $sofortPaymentType == 1) ? 1 : 0; $result['PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24'] = ($przelewy24PaymentType === "true" || $przelewy24PaymentType == 1) ? 1 : 0; $result['PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL'] = ($idealPaymentType === "true" || $idealPaymentType == 1) ? 1 : 0; + $result['PAYXPERT_IS_IFRAME'] = ($isIframe === "true" || $isIframe == 1) ? 1 : 0; } return $result; @@ -730,6 +753,18 @@ public function renderForm() { array('id' => 'ideal_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ ) /* */ ); + $fields_form['form']['input'][] = array( /* */ + 'type' => 'switch', /* */ + 'name' => 'PAYXPERT_IS_IFRAME', /* */ + 'label' => $this->l('Iframe mode'), /* */ + 'desc' => $this->l('Enable iframe mode'), /* */ + 'required' => false, /* */ + 'is_bool' => true, /* */ + 'values' => array(/* */ + array('id' => 'iframe_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ + array('id' => 'iframe_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ + ) /* */ + ); } $helper = new HelperForm(); @@ -805,6 +840,7 @@ protected function _postProcess() { $checkboxes[] = 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT'; $checkboxes[] = 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24'; $checkboxes[] = 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL'; + $checkboxes[] = 'PAYXPERT_IS_IFRAME'; } foreach ($checkboxes as $checkbox) { @@ -881,6 +917,26 @@ public function getPayXpertUrl() { return $url; } + /** + * Get the iframe config value + * + * @return boolean + */ + public function isIframeMode() { + $is_iframe = Configuration::get('PAYXPERT_IS_IFRAME'); + + return $is_iframe === 'true' ? true : false; + } + + /** + * Returns the modules path + * + * @return string + */ + public function getPath() { + return $this->_path; + } + /* Theses functions are used to support all versions of Prestashop */ public function assignSmartyVariable($name, $value) { diff --git a/modules/payxpert/views/templates/hook/iframe.tpl b/modules/payxpert/views/templates/hook/iframe.tpl new file mode 100644 index 0000000..a27fbf7 --- /dev/null +++ b/modules/payxpert/views/templates/hook/iframe.tpl @@ -0,0 +1,26 @@ +{* +* Copyright 2013-2017 PayXpert +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* @author Regis Vidal +* +*} + +{extends "$layout"} +{block name="content"} + {l s='Other payment methods' mod='payxpert'} +
+ +
+{/block} \ No newline at end of file diff --git a/modules/payxpert/views/templates/hook/return.tpl b/modules/payxpert/views/templates/hook/return.tpl new file mode 100644 index 0000000..5c1f907 --- /dev/null +++ b/modules/payxpert/views/templates/hook/return.tpl @@ -0,0 +1,20 @@ +{* +* Copyright 2013-2017 PayXpert +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* @author Regis Vidal +* +*} + + \ No newline at end of file