diff --git a/.version b/.version index 1cc5f65..8cfbc90 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.1.0 \ No newline at end of file +1.1.1 \ No newline at end of file diff --git a/README.md b/README.md index 7a945bb..4500e68 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.1 - Setting module name in payment options selection * 1.1.0 - Added iframe option * 1.0.7 - Supports Prestashop 1.7 * 1.0.1 - Improve Prestashop versions support diff --git a/modules/payxpert/config.xml b/config.xml similarity index 91% rename from modules/payxpert/config.xml rename to config.xml index 1ae818a..54cc887 100644 --- a/modules/payxpert/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ payxpert - + @@ -10,4 +10,4 @@ 1 1 - \ No newline at end of file + diff --git a/controllers/front/iframe.php b/controllers/front/iframe.php new file mode 100644 index 0000000..627977d --- /dev/null +++ b/controllers/front/iframe.php @@ -0,0 +1,72 @@ +context->controller->addCSS(($this->module->getPath()) . 'views/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); + Tools::redirect($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'); + } +} diff --git a/modules/payxpert/controllers/front/index.php b/controllers/front/index.php similarity index 100% rename from modules/payxpert/controllers/front/index.php rename to controllers/front/index.php diff --git a/controllers/front/payment.php b/controllers/front/payment.php new file mode 100644 index 0000000..73c2f3c --- /dev/null +++ b/controllers/front/payment.php @@ -0,0 +1,103 @@ +context->cart; + + // Default value for Prestashop < 1.7 + $template = 'payment_execution.tpl'; + + $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)) { + $params['payment_type'] = $paymentType; + + if ($paymentProvider !== null && PayXpert\Connect2Pay\C2PValidate::isProvider($paymentProvider)) { + $params['payment_provider'] = $paymentProvider; + } + + switch ($paymentType) { + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER: + $template = 'module:' . $this->module->name . '/views/templates/front/payment_execution_bank_transfer.tpl'; + + if (isset($params['payment_provider'])) { + switch ($params['payment_provider']) { + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_SOFORT: + $paymentLogo = 'sofort'; + break; + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_PRZELEWY24: + $paymentLogo = 'przelewy24'; + break; + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_IDEALKP: + $paymentLogo = 'ideal'; + break; + } + } + break; + default: + // Default is Credit Card + $template = 'module:' . $this->module->name . '/views/templates/front/payment_execution_credit_card.tpl'; + $paymentLogo = 'creditcard'; + break; + } + + $this->context->smarty->assign("payment_logo", $paymentLogo); + } + } + + $this->context->smarty->assign( + array(/* */ + 'nbProducts' => $cart->nbProducts(), /* */ + 'cust_currency' => (int)($cart->id_currency), /* */ + 'total' => $cart->getOrderTotal(true, Cart::BOTH), /* */ + 'isoCode' => $this->context->language->iso_code, /* */ + 'this_path' => $this->module->getPathUri(), /* */ + 'this_link' => $this->module->getModuleLinkCompat('payxpert', 'redirect', $params), /* */ + 'this_link_back' => $this->module->getPageLinkCompat('order', true, null, "step=3") /* */ + ) /* */ + ); + + $this->setTemplate($template); + } +} diff --git a/controllers/front/redirect.php b/controllers/front/redirect.php new file mode 100644 index 0000000..4385c53 --- /dev/null +++ b/controllers/front/redirect.php @@ -0,0 +1,67 @@ +context->cart)) { + $this->context->cart = new Cart(); + } + + $cart = $this->context->cart; + + // These should be filled only with Prestashop >= 1.7 + $paymentType = Tools::getValue('payment_type', null); + $paymentProvider = Tools::getValue('payment_provider', null); + + $errorMessage = $this->module->redirect($cart, $paymentType, $paymentProvider); + + $this->display_column_left = false; + parent::initContent(); + + $this->context->smarty->assign( + array(/* */ + 'errorMessage' => $errorMessage, /* */ + 'this_path' => $this->module->getPathUri(), /* */ + 'this_path_ssl' => Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/payxpert/', /* */ + 'this_link_back' => $this->module->getPageLinkCompat('order', true, null, "step=3") /* */ + ) /* */ + ); + + if (version_compare(_PS_VERSION_, '1.7', '>=')) { + $this->setTemplate('module:' . $this->module->name . '/views/templates/front/payment_error17.tpl'); + } else { + $this->setTemplate('payment_error.tpl'); + } + } +} diff --git a/controllers/front/return.php b/controllers/front/return.php new file mode 100644 index 0000000..ca7a91b --- /dev/null +++ b/controllers/front/return.php @@ -0,0 +1,57 @@ +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/controllers/front/validation.php b/controllers/front/validation.php new file mode 100644 index 0000000..178eaf0 --- /dev/null +++ b/controllers/front/validation.php @@ -0,0 +1,153 @@ +display_header = false; + $this->display_footer = false; + } + + /** + * + * @see FrontController::initContent() + */ + public function initContent() + { + // $cart = $this->context->cart; + require_once dirname(__FILE__) . '/../../lib/Connect2PayClient.php'; + + // init api + $c2pClient = new PayXpert\Connect2Pay\Connect2PayClient( + $this->module->getPayXpertUrl(), + Configuration::get('PAYXPERT_ORIGINATOR'), + html_entity_decode(Configuration::get('PAYXPERT_PASSWORD')) + ); + + if ($c2pClient->handleCallbackStatus()) { + $responseStatus = "KO"; + $responseMessage = "Callback validation failed"; + + $status = $c2pClient->getStatus(); + + // get the Error code + $errorCode = $status->getErrorCode(); + $errorMessage = $status->getErrorMessage(); + + $transaction = $status->getLastTransactionAttempt(); + + if ($transaction !== null) { + $transactionId = $transaction->getTransactionID(); + + $orderId = $status->getOrderID(); + $amount = number_format($transaction->getAmount() / 100, 2, '.', ''); + $callbackData = $status->getCtrlCustomData(); + + $severity = 1; + + $message = "PayXpert payment module: "; + $message .= "Received a new transaction status callback from " . $_SERVER["REMOTE_ADDR"] . ". "; + $message .= "Error code: " . $errorCode . " "; + $message .= "Error message: " . $errorMessage . " "; + $message .= "Transaction ID: " . $transactionId . " "; + $message .= "Order ID: " . $orderId . " "; + + $customer = null; + if (version_compare(_PS_VERSION_, '1.5', '>=')) { + Context::getContext()->cart = new Cart((int) $orderId); + $customer = new Customer((int) (Context::getContext()->cart->id_customer)); + } + + // For Prestashop >= 1.7, multi payment types is possible + switch ($transaction->getPaymentType()) { + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER: + $paymentMean = $this->module->l('Bank Transfer'); + break; + default: + $paymentMean = $this->module->l('Credit Card'); + break; + } + + $paymentMean .= ' (PayXpert)'; + + if (!$customer) { + $message .= "Customer not found for order " . $orderId; + error_log($message); + $severity = 3; + } else { + if (!PayXpert::checkCallbackAuthenticityData($callbackData, Context::getContext()->cart->id, $customer->secure_key)) { + $message .= "Invalid callback received for order " . $orderId . ". Validation failed."; + error_log($message); + $severity = 3; + } else { + switch ($errorCode) { + case "000": + // Payment OK + $this->module->validateOrder( + (int) $orderId, + Configuration::get('PS_OS_PAYMENT'), + $amount, + $paymentMean, + $errorMessage, + array(), + null, + false + ); + break; + default: + $this->module->validateOrder( + (int) $orderId, + Configuration::get('PS_OS_ERROR'), + $amount, + $paymentMean, + $errorMessage, + array(), + null, + false + ); + $severity = 2; + break; + } + $responseStatus = "OK"; + $responseMessage = "Payment status recorded"; + } + } + } + + $this->module->addLog($message, $severity, $errorCode); + + // Send a response to mark this transaction as notified + $response = array("status" => $responseStatus, "message" => $responseMessage); + header("Content-type: application/json"); + echo json_encode($response); + exit(); + } else { + $this->module->addLog("PayXpert payment module:\n Callback received an incorrect status from " . $_SERVER["REMOTE_ADDR"], 2); + } + } +} diff --git a/modules/payxpert/controllers/index.php b/controllers/index.php similarity index 100% rename from modules/payxpert/controllers/index.php rename to controllers/index.php diff --git a/modules/payxpert/en.php b/en.php similarity index 100% rename from modules/payxpert/en.php rename to en.php diff --git a/modules/payxpert/fr.php b/fr.php similarity index 100% rename from modules/payxpert/fr.php rename to fr.php diff --git a/modules/payxpert/images/index.php b/index.php similarity index 100% rename from modules/payxpert/images/index.php rename to index.php diff --git a/modules/payxpert/lib/Connect2PayClient.php b/lib/Connect2PayClient.php similarity index 100% rename from modules/payxpert/lib/Connect2PayClient.php rename to lib/Connect2PayClient.php diff --git a/modules/payxpert/views/templates/index.php b/lib/index.php similarity index 100% rename from modules/payxpert/views/templates/index.php rename to lib/index.php diff --git a/logo.gif b/logo.gif new file mode 100644 index 0000000..4a58998 Binary files /dev/null and b/logo.gif differ diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..4a58998 Binary files /dev/null and b/logo.png differ diff --git a/modules/payxpert/controllers/front/iframe.php b/modules/payxpert/controllers/front/iframe.php deleted file mode 100644 index 881285e..0000000 --- a/modules/payxpert/controllers/front/iframe.php +++ /dev/null @@ -1,71 +0,0 @@ -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/payment.php b/modules/payxpert/controllers/front/payment.php deleted file mode 100644 index e2ab92e..0000000 --- a/modules/payxpert/controllers/front/payment.php +++ /dev/null @@ -1,101 +0,0 @@ -context->cart; - - // Default value for Prestashop < 1.7 - $template = 'payment_execution.tpl'; - - $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)) { - $params['payment_type'] = $paymentType; - - if ($paymentProvider !== null && PayXpert\Connect2Pay\C2PValidate::isProvider($paymentProvider)) { - $params['payment_provider'] = $paymentProvider; - } - - switch ($paymentType) { - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER: - $template = 'module:' . $this->module->name . '/views/templates/front/payment_execution_bank_transfer.tpl'; - - if (isset($params['payment_provider'])) { - switch ($params['payment_provider']) { - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_SOFORT: - $paymentLogo = 'sofort'; - break; - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_PRZELEWY24: - $paymentLogo = 'przelewy24'; - break; - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_IDEALKP: - $paymentLogo = 'ideal'; - break; - } - } - break; - default: - // Default is Credit Card - $template = 'module:' . $this->module->name . '/views/templates/front/payment_execution_credit_card.tpl'; - $paymentLogo = 'creditcard'; - break; - } - - $this->context->smarty->assign("payment_logo", $paymentLogo); - } - } - - $this->context->smarty->assign( - array(/* */ - 'nbProducts' => $cart->nbProducts(), /* */ - 'cust_currency' => intval($cart->id_currency), /* */ - 'total' => $cart->getOrderTotal(true, Cart::BOTH), /* */ - 'isoCode' => $this->context->language->iso_code, /* */ - 'this_path' => $this->module->getPathUri(), /* */ - 'this_link' => $this->module->getModuleLinkCompat('payxpert', 'redirect', $params), /* */ - 'this_link_back' => $this->module->getPageLinkCompat('order', true, NULL, "step=3") /* */ - ) /* */ - ); - - $this->setTemplate($template); - } -} \ No newline at end of file diff --git a/modules/payxpert/controllers/front/redirect.php b/modules/payxpert/controllers/front/redirect.php deleted file mode 100644 index acf0e7f..0000000 --- a/modules/payxpert/controllers/front/redirect.php +++ /dev/null @@ -1,67 +0,0 @@ -context->cart)) { - $this->context->cart = new Cart(); - } - - $cart = $this->context->cart; - - // These should be filled only with Prestashop >= 1.7 - $paymentType = Tools::getValue('payment_type', null); - $paymentProvider = Tools::getValue('payment_provider', null); - - $errorMessage = $this->module->redirect($cart, $paymentType, $paymentProvider); - - $this->display_column_left = false; - parent::initContent(); - - $this->context->smarty->assign( - array(/* */ - 'errorMessage' => $errorMessage, /* */ - 'this_path' => $this->module->getPathUri(), /* */ - 'this_path_ssl' => Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . - 'modules/payxpert/', /* */ - 'this_link_back' => $this->module->getPageLinkCompat('order', true, NULL, "step=3") /* */ - ) /* */ - ); - - if (version_compare(_PS_VERSION_, '1.7', '>=')) { - $this->setTemplate('module:' . $this->module->name . '/views/templates/front/payment_error17.tpl'); - } else { - $this->setTemplate('payment_error.tpl'); - } - } -} diff --git a/modules/payxpert/controllers/front/return.php b/modules/payxpert/controllers/front/return.php deleted file mode 100644 index 1c02fa0..0000000 --- a/modules/payxpert/controllers/front/return.php +++ /dev/null @@ -1,56 +0,0 @@ -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/controllers/front/validation.php b/modules/payxpert/controllers/front/validation.php deleted file mode 100644 index 956f67c..0000000 --- a/modules/payxpert/controllers/front/validation.php +++ /dev/null @@ -1,131 +0,0 @@ -display_header = false; - $this->display_footer = false; - } - - /** - * - * @see FrontController::initContent() - */ - public function initContent() { - // $cart = $this->context->cart; - require_once dirname(__FILE__) . '/../../lib/Connect2PayClient.php'; - - // init api - $c2pClient = new PayXpert\Connect2Pay\Connect2PayClient($this->module->getPayXpertUrl(), Configuration::get('PAYXPERT_ORIGINATOR'), - html_entity_decode(Configuration::get('PAYXPERT_PASSWORD'))); - - if ($c2pClient->handleCallbackStatus()) { - $responseStatus = "KO"; - $responseMessage = "Callback validation failed"; - - $status = $c2pClient->getStatus(); - - // get the Error code - $errorCode = $status->getErrorCode(); - $errorMessage = $status->getErrorMessage(); - - $transaction = $status->getLastTransactionAttempt(); - - if ($transaction !== null) { - $transactionId = $transaction->getTransactionID(); - - $orderId = $status->getOrderID(); - $amount = number_format($transaction->getAmount() / 100, 2, '.', ''); - $callbackData = $status->getCtrlCustomData(); - - $severity = 1; - - $message = "PayXpert payment module: "; - $message .= "Received a new transaction status callback from " . $_SERVER["REMOTE_ADDR"] . ". "; - $message .= "Error code: " . $errorCode . " "; - $message .= "Error message: " . $errorMessage . " "; - $message .= "Transaction ID: " . $transactionId . " "; - $message .= "Order ID: " . $orderId . " "; - - $customer = null; - if (version_compare(_PS_VERSION_, '1.5', '>=')) { - Context::getContext()->cart = new Cart((int) $orderId); - $customer = new Customer((int) (Context::getContext()->cart->id_customer)); - } - - // For Prestashop >= 1.7, multi payment types is possible - switch ($transaction->getPaymentType()) { - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER: - $paymentMean = $this->module->l('Bank Transfer'); - break; - default: - $paymentMean = $this->module->l('Credit Card'); - break; - } - $paymentMean .= ' (PayXpert)'; - - if (!$customer) { - $message .= "Customer not found for order " . $orderId; - error_log($message); - $severity = 3; - } else { - if (!PayXpert::checkCallbackAuthenticityData($callbackData, Context::getContext()->cart->id, $customer->secure_key)) { - $message .= "Invalid callback received for order " . $orderId . ". Validation failed."; - error_log($message); - $severity = 3; - } else { - switch ($errorCode) { - case "000": - // Payment OK - $this->module->validateOrder((int) $orderId, Configuration::get('PS_OS_PAYMENT'), $amount, $paymentMean, $errorMessage, - array(), NULL, false); - break; - default: - $this->module->validateOrder((int) $orderId, Configuration::get('PS_OS_ERROR'), $amount, $paymentMean, $errorMessage, - array(), NULL, false); - $severity = 2; - break; - } - $responseStatus = "OK"; - $responseMessage = "Payment status recorded"; - } - } - } - - $this->module->addLog($message, $severity, $errorCode); - - // Send a response to mark this transaction as notified - $response = array("status" => $responseStatus, "message" => $responseMessage); - header("Content-type: application/json"); - echo json_encode($response); - exit(); - } else { - $this->module->addLog("PayXpert payment module:\n Callback received an incorrect status from " . $_SERVER["REMOTE_ADDR"], 2); - } - } -} diff --git a/modules/payxpert/logo.gif b/modules/payxpert/logo.gif deleted file mode 100644 index 69a9bbb..0000000 Binary files a/modules/payxpert/logo.gif and /dev/null differ diff --git a/modules/payxpert/logo.png b/modules/payxpert/logo.png deleted file mode 100644 index b56962e..0000000 Binary files a/modules/payxpert/logo.png and /dev/null differ diff --git a/modules/payxpert/payxpert.php b/modules/payxpert/payxpert.php deleted file mode 100644 index d73c434..0000000 --- a/modules/payxpert/payxpert.php +++ /dev/null @@ -1,1032 +0,0 @@ -name = 'payxpert'; - $this->version = '1.1.0'; - - $this->tab = 'payments_gateways'; - - $this->author = 'PayXpert'; - $this->need_instance = 1; - - $this->controllers = array('payment', 'validation'); - $this->is_eu_compatible = 1; - - if (version_compare(_PS_VERSION_, '1.5', '>=')) { - $this->ps_versions_compliancy = array('min' => '1.4.0.0', 'max' => _PS_VERSION_); - } - - if (version_compare(_PS_VERSION_, '1.6', '>=')) { - $this->bootstrap = true; - } - - parent::__construct(); - - $this->displayName = 'PayXpert Payment Solutions'; - $this->description = $this->l("Accept payments today with PayXpert"); - $this->confirmUninstall = $this->l('Are you sure about removing these details?'); - - if (!count(Currency::checkPaymentCurrencies($this->id))) { - $this->warning = $this->l('No currency has been set for this module.'); - } - - /* For 1.4.3 and less compatibility */ - $updateConfig = array('PS_OS_CHEQUE' => 1, 'PS_OS_PAYMENT' => 2, 'PS_OS_PREPARATION' => 3, 'PS_OS_SHIPPING' => 4, - 'PS_OS_DELIVERED' => 5, 'PS_OS_CANCELED' => 6, 'PS_OS_REFUND' => 7, 'PS_OS_ERROR' => 8, 'PS_OS_OUTOFSTOCK' => 9, - 'PS_OS_BANKWIRE' => 10, 'PS_OS_PAYPAL' => 11, 'PS_OS_WS_PAYMENT' => 12); - - foreach ($updateConfig as $u => $v) { - if (!Configuration::get($u) || (int) Configuration::get($u) < 1) { - if (defined('_' . $u . '_') && (int) constant('_' . $u . '_') > 0) { - Configuration::updateValue($u, constant('_' . $u . '_')); - } else { - Configuration::updateValue($u, $v); - } - } - } - } - - /** - * Install method - */ - public function install() { - // call parents - if (!parent::install()) { - $errorMessage = Tools::displayError($this->l('PayXpert installation : install failed.')); - $this->addLog($errorMessage, 3, '000002'); - return false; - } - - // Add hook methods - $hookResult = $this->registerHook('paymentReturn'); - if (version_compare(_PS_VERSION_, '1.7', '<')) { - $hookResult = $hookResult && $this->registerHook('payment'); - } else { - $hookResult = $hookResult && $this->registerHook('paymentOptions'); - } - - if (!$hookResult) { - $errorMessage = Tools::displayError($this->l('PayXpert installation : hooks failed.')); - $this->addLog($errorMessage, 3, '000002'); - - return false; - } - - // Add configuration parameters - foreach ($this->getModuleParameters() as $parameter) { - if (!Configuration::updateValue($parameter, '')) { - $errorMessage = Tools::displayError($this->l('PayXpert installation : configuration failed.')); - $this->addLog($errorMessage, 3, '000002'); - - return false; - } - } - - $this->addLog($this->l('PayXpert installation : installation successful')); - - return true; - } - - /** - * Uninstall the module - * - * @return boolean - */ - public function uninstall() { - $result = parent::uninstall(); - - foreach ($this->getModuleParameters() as $parameter) { - $result = $result || Configuration::deleteByName($parameter); - } - - return $result; - } - - private function getModuleParameters() { - $moduleParameters = array( /* */ - 'PAYXPERT_ORIGINATOR', /* */ - 'PAYXPERT_PASSWORD', /* */ - 'PAYXPERT_URL', /* */ - 'PAYXPERT_MERCHANT_NOTIF', /* */ - 'PAYXPERT_MERCHANT_NOTIF_TO', /* */ - 'PAYXPERT_MERCHANT_NOTIF_LANG' /* */ - ); - - if (version_compare(_PS_VERSION_, '1.7', '>=')) { - $moduleParameters[] = 'PAYXPERT_PAYMENT_TYPE_CREDIT_CARD'; - $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; - } - - public function checkPaymentOption($params) { - // if module disabled, can't go through - if (!$this->active) { - return false; - } - - // Check if currency ok - if (!$this->checkCurrency($params['cart'])) { - return false; - } - - // Check if module is configured - if (Configuration::get('PAYXPERT_ORIGINATOR') == "" && Configuration::get('PAYXPERT_PASSWORD') == "") { - return false; - } - - return true; - } - - /** - * Hook payment options - * - * @since Prestashop 1.7 - * @param type $params - * @return type - */ - public function hookPaymentOptions($params) { - if (!$this->checkPaymentOption($params)) { - return; - } - - $controller = 'payment'; - - if ($this->isIframeMode()) { - $controller = 'iframe'; - } - - $this->smarty->assign($this->getTemplateVarInfos()); - - $payment_options = array(); - - $ccOption = $this->getCreditCardPaymentOption($controller); - if ($ccOption != null) { - $payment_options[] = $ccOption; - } - $sofortOption = $this->getBankTransferViaSofortPaymentOption($controller); - if ($sofortOption != null) { - $payment_options[] = $sofortOption; - } - $przelewy24Option = $this->getBankTransferViaPrzelewy24PaymentOption($controller); - if ($przelewy24Option != null) { - $payment_options[] = $przelewy24Option; - } - $idealOption = $this->getBankTransferViaIDealPaymentOption($controller); - if ($idealOption != null) { - $payment_options[] = $idealOption; - } - - return $payment_options; - } - - /** - * - * @since Prestashop 1.7 - */ - 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, $controller, - array('payment_type' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_CREDITCARD), true)); - - $this->context->smarty->assign('pxpCCLogo', - Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/images/payment-types/creditcard.png')); - $option->setAdditionalInformation( - $this->context->smarty->fetch('module:payxpert/views/templates/front/payment_infos_credit_card.tpl')); - - return $option; - } - - return null; - } - - /** - * - * @since Prestashop 1.7 - */ - 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, $controller, - array('payment_type' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER, - 'payment_provider' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_SOFORT), true)); - - $this->context->smarty->assign("pxpSofortLogo", - Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/images/payment-types/sofort.png')); - $option->setAdditionalInformation( - $this->context->smarty->fetch('module:payxpert/views/templates/front/payment_infos_bank_transfer_sofort.tpl')); - - return $option; - } - - return null; - } - - /** - * - * @since Prestashop 1.7 - */ - 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, $controller, - array('payment_type' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER, - 'payment_provider' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_PRZELEWY24), true)); - - $this->context->smarty->assign("pxpPrzelewy24Logo", - Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/images/payment-types/przelewy24.png')); - $option->setAdditionalInformation( - $this->context->smarty->fetch('module:payxpert/views/templates/front/payment_infos_bank_transfer_przelewy24.tpl')); - - return $option; - } - - return null; - } - - /** - * - * @since Prestashop 1.7 - */ - 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, $controller, - array('payment_type' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER, - 'payment_provider' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_IDEALKP), true)); - - $this->context->smarty->assign("pxpIdealLogo", Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/images/payment-types/ideal.png')); - $option->setAdditionalInformation( - $this->context->smarty->fetch('module:payxpert/views/templates/front/payment_infos_bank_transfer_ideal.tpl')); - - return $option; - } - - return null; - } - - public function getTemplateVarInfos() { - $cart = $this->context->cart; - - return array(/* */ - 'nbProducts' => $cart->nbProducts(), /* */ - 'cust_currency' => $cart->id_currency, /* */ - 'total' => $cart->getOrderTotal(true, Cart::BOTH), /* */ - 'isoCode' => $this->context->language->iso_code /* */ - ); - } - - /** - * Hook payment for Prestashop < 1.7 - * - * @param type $params - * @return type - */ - 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') . - __PS_BASE_URI__ . 'modules/payxpert/'); - $this->assignSmartyVariable('this_link', $this->getModuleLinkCompat('payxpert', 'payment')); - - if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { - $this->context->controller->addCSS($this->_path . 'css/payxpert.css'); - } - - return $this->display(__FILE__, 'views/templates/hook/payment.tpl'); - } - - /** - * Hook paymentReturn - * - * Displays order confirmation - * - * @param type $params - * @return type - */ - public function hookPaymentReturn($params) { - if (!$this->active) { - return; - } - - if (isset($params['objOrder'])) { - // For Prestashop < 1.7 - $order = $params['objOrder']; - } else { - $order = $params['order']; - } - - switch ($order->getCurrentState()) { - case _PS_OS_PAYMENT_: - case _PS_OS_OUTOFSTOCK_: - $this->assignSmartyVariable('status', 'ok'); - break; - - case _PS_OS_BANKWIRE_: - $this->assignSmartyVariable('status', 'pending'); - break; - - case _PS_OS_ERROR_: - default: - $this->assignSmartyVariable('status', 'failed'); - break; - } - - $this->assignSmartyVariable('this_link_contact', $this->getPageLinkCompat('contact', true)); - - return $this->display(__FILE__, 'views/templates/hook/orderconfirmation.tpl'); - } - - /** - * Init the payment - * - * In this method, we'll start to initialize the transaction - * And redirect the customer - * - * For Prestashop >= 1.5 - * - * @global type $cookie - * @param Cart $cart - * @return type - */ - public function redirect($cart, $paymentType = null, $paymentProvider = null) { - // if module disabled, can't go through - if (!$this->active) { - return "Module is not active"; - } - - // Check if currency ok - if (!$this->checkCurrency($cart)) { - return "Incorrect currency"; - } - - // Check if module is configured - if (Configuration::get('PAYXPERT_ORIGINATOR') == "" && Configuration::get('PAYXPERT_PASSWORD') == "") { - return "Module is not setup"; - } - - if ($paymentType == null || !PayXpert\Connect2Pay\C2PValidate::isPayment($paymentType)) { - $paymentType = PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_CREDITCARD; - } - - if (!$this->checkPaymentTypeAndProvider($paymentType, $paymentProvider)) { - 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)); - $carrier = new Carrier((int) ($cart->id_carrier)); - $addr_delivery = new Address((int) ($cart->id_address_delivery)); - $addr_invoice = new Address((int) ($cart->id_address_invoice)); - - $invoice_state = new State((int) ($addr_invoice->id_state)); - $invoice_country = new Country((int) ($addr_invoice->id_country)); - - $delivery_state = new State((int) ($addr_delivery->id_state)); - $delivery_country = new Country((int) ($addr_delivery->id_country)); - - $invoice_phone = (!empty($addr_invoice->phone)) ? $addr_invoice->phone : $addr_invoice->phone_mobile; - $delivery_phone = (!empty($addr_delivery->phone)) ? $addr_delivery->phone : $addr_delivery->phone_mobile; - - // init api - $c2pClient = new PayXpert\Connect2Pay\Connect2PayClient($this->getPayXpertUrl(), Configuration::get('PAYXPERT_ORIGINATOR'), - html_entity_decode(Configuration::get('PAYXPERT_PASSWORD'))); - - // customer informations - $c2pClient->setShopperID($cart->id_customer); - $c2pClient->setShopperEmail($customer->email); - $c2pClient->setShopperFirstName(substr($customer->firstname, 0, 35)); - $c2pClient->setShopperLastName(substr($customer->lastname, 0, 35)); - $c2pClient->setShopperCompany(substr($addr_invoice->company, 0, 128)); - $c2pClient->setShopperAddress(substr(trim($addr_invoice->address1 . ' ' . $addr_invoice->address2), 0, 255)); - $c2pClient->setShopperZipcode(substr($addr_invoice->postcode, 0, 10)); - $c2pClient->setShopperCity(substr($addr_invoice->city, 0, 50)); - $c2pClient->setShopperState(substr($invoice_state->name, 0, 30)); - $c2pClient->setShopperCountryCode($invoice_country->iso_code); - $c2pClient->setShopperPhone(substr(trim($invoice_phone), 0, 20)); - - // Shipping information - $c2pClient->setShipToFirstName(substr($addr_delivery->firstname, 0, 35)); - $c2pClient->setShipToLastName(substr($addr_delivery->lastname, 0, 35)); - $c2pClient->setShipToCompany(substr($addr_delivery->company, 0, 128)); - $c2pClient->setShipToPhone(substr(trim($delivery_phone), 0, 20)); - $c2pClient->setShipToAddress(substr(trim($addr_delivery->address1 . " " . $addr_delivery->address2), 0, 255)); - $c2pClient->setShipToZipcode(substr($addr_delivery->postcode, 0, 10)); - $c2pClient->setShipToCity(substr($addr_delivery->city, 0, 50)); - $c2pClient->setShipToState(substr($delivery_state->name, 0, 30)); - $c2pClient->setShipToCountryCode($delivery_country->iso_code); - $c2pClient->setShippingName(substr($carrier->name, 0, 50)); - $c2pClient->setShippingType(PayXpert\Connect2Pay\Connect2PayClient::_SHIPPING_TYPE_PHYSICAL); - - // Order informations - $c2pClient->setOrderID(substr(pSQL($cart->id), 0, 100)); - $c2pClient->setOrderDescription(substr($this->l('Invoice:') . pSQL($cart->id), 0, 255)); - $c2pClient->setCustomerIP($_SERVER['REMOTE_ADDR']); - $c2pClient->setCurrency($currency->iso_code); - - $total = number_format($cart->getOrderTotal(true, 3) * 100, 0, '.', ''); - - $c2pClient->setAmount($total); - $c2pClient->setOrderCartContent($this->getProductsApi($cart)); - $c2pClient->setPaymentMode(PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_MODE_SINGLE); - $c2pClient->setPaymentType($paymentType); - if ($paymentProvider != null && PayXpert\Connect2Pay\C2PValidate::isProvider($paymentProvider)) { - $c2pClient->setProvider($paymentProvider); - } - $c2pClient->setCtrlCustomData(PayXpert::getCallbackAuthenticityData($c2pClient->getOrderID(), $customer->secure_key)); - - // Merchant notifications - if (Configuration::get('PAYXPERT_MERCHANT_NOTIF') === "true" && Configuration::get('PAYXPERT_MERCHANT_NOTIF_TO')) { - $c2pClient->setMerchantNotification(true); - $c2pClient->setMerchantNotificationTo(Configuration::get('PAYXPERT_MERCHANT_NOTIF_TO')); - if (Configuration::get('PAYXPERT_MERCHANT_NOTIF_LANG')) { - $c2pClient->setMerchantNotificationLang(Configuration::get('PAYXPERT_MERCHANT_NOTIF_LANG')); - } - } - - $ctrlURLPrefix = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://'; - - if (version_compare(_PS_VERSION_, '1.5', '<')) { - $c2pClient->setCtrlCallbackURL($ctrlURLPrefix . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/payxpert/validation.php'); - $c2pClient->setCtrlRedirectURL( - $ctrlURLPrefix . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . (int) ($cart->id) . '&id_module=' . - (int) ($this->id) . '&key=' . $customer->secure_key); - } else { - $c2pClient->setCtrlCallbackURL($this->context->link->getModuleLink('payxpert', 'validation')); - $c2pClient->setCtrlRedirectURL($this->getModuleLinkCompat('payxpert', 'return')); - } - - return $c2pClient; - } - - /** - * Return array of product to fill Api Product properties - * - * @param Cart $cart - * @return array - */ - protected function getProductsApi($cart) { - $products = array(); - - foreach ($cart->getProducts() as $product) { - $obj = new Product((int) $product['id_product']); - $products[] = array( /* */ - 'CartProductId' => $product['id_product'], /* */ - 'CartProductName' => $product['name'], /* */ - 'CartProductUnitPrice' => $product['price'], /* */ - 'CartProductQuantity' => $product['quantity'], /* */ - 'CartProductBrand' => $obj->manufacturer_name, /* */ - 'CartProductMPN' => $product['ean13'], /* */ - 'CartProductCategoryName' => $product['category'], /* */ - 'CartProductCategoryID' => $product['id_category_default'] /* */ - ); - } - - return $products; - } - - public function getContent() { - if (Tools::isSubmit('btnSubmit')) { - $this->_postValidation(); - - if (!count($this->_postErrors)) { - $this->_postProcess(); - } else { - foreach ($this->_postErrors as $err) { - $this->_html .= $this->displayError($err); - } - } - } else { - $this->_html .= '
'; - } - - $this->_html .= $this->display(__FILE__, '/views/templates/admin/infos.tpl'); - - if (version_compare(_PS_VERSION_, '1.6', '<')) { - /* Prestashop parameter names must not exceed 32 chars for v < 1.6 */ - $this->assignSmartyVariable('PAYXPERT_ORIGINATOR', - Tools::safeOutput(Tools::getValue('PAYXPERT_ORIGINATOR', Configuration::get('PAYXPERT_ORIGINATOR')))); - $this->assignSmartyVariable('PAYXPERT_URL', Tools::safeOutput(Tools::getValue('PAYXPERT_URL', Configuration::get('PAYXPERT_URL')))); - - $merchantNotifications = (Configuration::get('PAYXPERT_MERCHANT_NOTIF') == "true") ? "true" : "false"; - if (Tools::getValue('PAYXPERT_MERCHANT_NOTIF')) { - $merchantNotifications = (in_array(Tools::getValue('PAYXPERT_MERCHANT_NOTIF'), array("true", "1", "on"))) ? "true" : "false"; - } - $this->assignSmartyVariable('PAYXPERT_MERCHANT_NOTIF', $merchantNotifications); - $this->assignSmartyVariable('PAYXPERT_MERCHANT_NOTIF_TO', - Tools::safeOutput(Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO', Configuration::get('PAYXPERT_MERCHANT_NOTIF_TO')))); - $this->assignSmartyVariable('PAYXPERT_MERCHANT_NOTIF_LANG', - Tools::safeOutput(Tools::getValue('PAYXPERT_MERCHANT_NOTIF_LANG', Configuration::get('PAYXPERT_MERCHANT_NOTIF_LANG')))); - - $this->_html .= $this->display(__FILE__, '/views/templates/admin/config.tpl'); - } else { - $this->_html .= $this->renderForm(); - } - - return $this->_html; - } - - public function getConfigFieldsValues() { - // Handle checkboxes - $merchantNotif = Tools::getValue('PAYXPERT_MERCHANT_NOTIF', Configuration::get('PAYXPERT_MERCHANT_NOTIF')); - - $result = array( /* */ - 'PAYXPERT_ORIGINATOR' => Tools::getValue('PAYXPERT_ORIGINATOR', Configuration::get('PAYXPERT_ORIGINATOR')), /* */ - 'PAYXPERT_URL' => Tools::getValue('PAYXPERT_URL', Configuration::get('PAYXPERT_URL')), /* */ - 'PAYXPERT_MERCHANT_NOTIF' => ($merchantNotif === "true" || $merchantNotif == 1) ? 1 : 0, /* */ - 'PAYXPERT_MERCHANT_NOTIF_TO' => Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO', Configuration::get('PAYXPERT_MERCHANT_NOTIF_TO')), /* */ - 'PAYXPERT_MERCHANT_NOTIF_LANG' => Tools::getValue('PAYXPERT_MERCHANT_NOTIF_LANG', - Configuration::get('PAYXPERT_MERCHANT_NOTIF_LANG')), /* */ - ); - - if (version_compare(_PS_VERSION_, '1.7', '>=')) { - $creditCardPaymentType = Tools::getValue('PAYXPERT_PAYMENT_TYPE_CREDIT_CARD', Configuration::get('PAYXPERT_PAYMENT_TYPE_CREDIT_CARD')); - $sofortPaymentType = Tools::getValue('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT', - Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT')); - $przelewy24PaymentType = Tools::getValue('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24', - 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; - } - - public function renderForm() { - $fields_form = array( - 'form' => array( /* */ - 'legend' => array( /* */ - 'title' => $this->l('Settings'), /* */ - 'icon' => 'icon-gears' /* */ - ), /* */ - 'input' => array( /* */ - array( /* */ - 'type' => 'text', /* */ - 'name' => 'PAYXPERT_ORIGINATOR', /* */ - 'label' => $this->l('Originator ID'), /* */ - 'desc' => $this->l('The identifier of your Originator'), /* */ - 'required' => true /* */ - ), - array( /* */ - 'type' => 'password', /* */ - 'name' => 'PAYXPERT_PASSWORD', /* */ - 'label' => $this->l('Originator password'), /* */ - 'desc' => $this->l('The password associated with your Originator (leave empty to keep the current one)'), /* */ - 'hint' => $this->l('Leave empty to keep the current one'), /* */ - 'required' => false /* */ - ), - array( /* */ - 'type' => 'text', /* */ - 'name' => 'PAYXPERT_URL', /* */ - 'label' => $this->l('Payment Page URL'), /* */ - 'desc' => $this->l('Leave this field empty unless you have been given an URL'), /* */ - 'required' => false /* */ - ), - array( /* */ - 'type' => 'switch', /* */ - 'name' => 'PAYXPERT_MERCHANT_NOTIF', /* */ - 'label' => $this->l('Merchant notifications'), /* */ - 'desc' => $this->l('Whether or not to send a notification to the merchant for each processed payment'), /* */ - 'required' => false, /* */ - 'is_bool' => true, /* */ - 'values' => array( /* */ - array('id' => 'notif_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ - array('id' => 'notif_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ - ) /* */ - ), /* */ - array( /* */ - 'type' => 'text', /* */ - 'name' => 'PAYXPERT_MERCHANT_NOTIF_TO', /* */ - 'label' => $this->l('Merchant notifications recipient'), /* */ - 'desc' => $this->l('Recipient email address for merchant notifications'), /* */ - 'required' => false, /* */ - 'size' => 100 /* */ - ), /* */ - array( /* */ - 'type' => 'select', /* */ - 'name' => 'PAYXPERT_MERCHANT_NOTIF_LANG', /* */ - 'label' => $this->l('Merchant notifications lang'), /* */ - 'desc' => $this->l('Language to use for merchant notifications'), /* */ - 'required' => false, /* */ - 'options' => array( /* */ - 'query' => array( /* */ - array('id_option' => 'en', 'name' => $this->l('English')), /* */ - array('id_option' => 'fr', 'name' => $this->l('French')), /* */ - array('id_option' => 'es', 'name' => $this->l('Spanish')), /* */ - array('id_option' => 'it', 'name' => $this->l('Italian')) /* */ - ), /* */ - 'id' => 'id_option', /* */ - 'name' => 'name' /* */ - ) /* */ - ) /* */ - ), /* */ - 'submit' => array('title' => $this->l('Update settings')) /* */ - ) /* */ - ); - - if (version_compare(_PS_VERSION_, '1.7', '>=')) { - $fields_form['form']['input'][] = array( /* */ - 'type' => 'switch', /* */ - 'name' => 'PAYXPERT_PAYMENT_TYPE_CREDIT_CARD', /* */ - 'label' => $this->l('Credit Card'), /* */ - 'desc' => $this->l('Enable payment type: Credit Card'), /* */ - 'required' => false, /* */ - 'is_bool' => true, /* */ - 'values' => array(/* */ - array('id' => 'cc_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ - array('id' => 'cc_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ - ) /* */ - ); - $fields_form['form']['input'][] = array( /* */ - 'type' => 'switch', /* */ - 'name' => 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT', /* */ - 'label' => $this->l('Bank Transfert via Sofort'), /* */ - 'desc' => $this->l('Enable payment type: Bank Transfer via Sofort'), /* */ - 'required' => false, /* */ - 'is_bool' => true, /* */ - 'values' => array(/* */ - array('id' => 'sofort_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ - array('id' => 'sofort_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ - ) /* */ - ); - $fields_form['form']['input'][] = array( /* */ - 'type' => 'switch', /* */ - 'name' => 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24', /* */ - 'label' => $this->l('Bank Transfert via Przelewy24'), /* */ - 'desc' => $this->l('Enable payment type: Bank Transfer via Przelewy24'), /* */ - 'required' => false, /* */ - 'is_bool' => true, /* */ - 'values' => array(/* */ - array('id' => 'przelewy24_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ - array('id' => 'przelewy24_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ - ) /* */ - ); - $fields_form['form']['input'][] = array( /* */ - 'type' => 'switch', /* */ - 'name' => 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL', /* */ - 'label' => $this->l('Bank Transfert via iDeal'), /* */ - 'desc' => $this->l('Enable payment type: Bank Transfer via iDeal'), /* */ - 'required' => false, /* */ - 'is_bool' => true, /* */ - 'values' => array(/* */ - array('id' => 'ideal_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ - 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(); - $helper->show_toolbar = false; - $helper->table = $this->table; - $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT')); - $helper->default_form_language = $lang->id; - $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get( - 'PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; - $this->fields_form = array(); - - $helper->identifier = $this->identifier; - $helper->submit_action = 'btnSubmit'; - $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . - $this->tab . '&module_name=' . $this->name; - $helper->token = Tools::getAdminTokenLite('AdminModules'); - $helper->tpl_vars = array( /* */ - 'fields_value' => $this->getConfigFieldsValues(), /* */ - 'languages' => $this->context->controller->getLanguages(), /* */ - 'id_language' => $this->context->language->id /* */ - ); - - return $helper->generateForm(array($fields_form)); - } - - private function _postValidation() { - if (Tools::isSubmit('btnSubmit')) { - if (!Tools::getValue('PAYXPERT_ORIGINATOR')) { - $this->_postErrors[] = $this->l('Originator is required.'); - } - - if (!Configuration::get('PAYXPERT_PASSWORD') && !Tools::getValue('PAYXPERT_PASSWORD')) { - $this->_postErrors[] = $this->l('Password is required.'); - } - - if (in_array(Tools::getValue('PAYXPERT_MERCHANT_NOTIF'), array("true", "1", "on")) && !Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO')) { - $this->_postErrors[] = $this->l('Merchant notifications recipient is required.'); - } - - if (Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO') && !Validate::isEmail(Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO'))) { - $this->_postErrors[] = $this->l('Merchant notifications recipient must be a valid email address.'); - } - - if (!in_array(Tools::getValue('PAYXPERT_MERCHANT_NOTIF_LANG'), array("en", "fr", "es", "it"))) { - $this->_postErrors[] = $this->l('Merchant notification lang is not valid.'); - } - } - } - - protected function _postProcess() { - if (Tools::isSubmit('btnSubmit')) { - Configuration::updateValue('PAYXPERT_ORIGINATOR', Tools::getValue('PAYXPERT_ORIGINATOR')); - - if (Tools::getValue('PAYXPERT_PASSWORD')) { - // Manually handle HTML special chars to avoid losing them - Configuration::updateValue('PAYXPERT_PASSWORD', htmlentities(Tools::getValue('PAYXPERT_PASSWORD'))); - } - - Configuration::updateValue('PAYXPERT_URL', Tools::getValue('PAYXPERT_URL')); - - Configuration::updateValue('PAYXPERT_MERCHANT_NOTIF_TO', Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO')); - - if (in_array(Tools::getValue('PAYXPERT_MERCHANT_NOTIF_LANG'), array("en", "fr", "es", "it"))) { - Configuration::updateValue('PAYXPERT_MERCHANT_NOTIF_LANG', Tools::getValue('PAYXPERT_MERCHANT_NOTIF_LANG')); - } - - // Handle checkboxes - $checkboxes = array( /* */ - 'PAYXPERT_MERCHANT_NOTIF' /* */ - ); - if (version_compare(_PS_VERSION_, '1.7', '>=')) { - $checkboxes[] = 'PAYXPERT_PAYMENT_TYPE_CREDIT_CARD'; - $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) { - if (in_array(Tools::getValue($checkbox), array("true", "1", "on"))) { - Configuration::updateValue($checkbox, "true"); - } else { - Configuration::updateValue($checkbox, "false"); - } - } - } - - if (version_compare(_PS_VERSION_, '1.6', '>=')) { - $this->_html .= $this->displayConfirmation($this->l('Configuration updated')); - } else { - $this->_html .= '
' . $this->l('Configuration updated') . '
'; - - return true; - } - } - - private function checkPaymentTypeAndProvider($paymentType, $paymentProvider) { - // For Prestashop >=1.7, check that the payment type is enabled - if (version_compare(_PS_VERSION_, '1.7.0', '>=') === true) { - switch ($paymentType) { - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_CREDITCARD: - return Configuration::get('PAYXPERT_PAYMENT_TYPE_CREDIT_CARD') === "true"; - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER: - if ($paymentProvider !== null) { - switch ($paymentProvider) { - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_SOFORT: - return Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT') === "true"; - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_PRZELEWY24: - return Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24') === "true"; - case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_IDEALKP: - return Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL') === "true"; - } - } - break; - } - } else { - return true; - } - - return false; - } - - private function checkCurrency($cart) { - $currency_order = new Currency((int) ($cart->id_currency)); - $currencies_module = $this->getCurrency((int) $cart->id_currency); - - if (is_array($currencies_module)) { - foreach ($currencies_module as $currency_module) { - if ($currency_order->id == $currency_module['id_currency']) { - return true; - } - } - } - - return false; - } - - /** - * Get PayXpert Url depending of the env - * - * @return string Url - */ - public function getPayXpertUrl() { - $url = Configuration::get('PAYXPERT_URL'); - - if (strlen(trim($url)) <= 0) { - $url = 'https://connect2.payxpert.com/'; - } - - 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) { - - // Check if context smarty variable is available - if (isset($this->context->smarty)) { - return $this->context->smarty->assign($name, $value); - } else { - // Use the global variable - global $smarty; - - return $smarty->assign($name, $value); - } - } - - public function getModuleLinkCompat($module, $controller = 'default', $params = null) { - if (class_exists('Context')) { - if (!$params) { - $params = array(); - } - - return Context::getContext()->link->getModuleLink($module, $controller, $params); - } else { - if ($controller == 'default') { - if ($params) { - $params = "?" . $params; - } - - return Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . $module . '.php' . - $params; - } else { - return Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . - 'modules/payxpert/' . $controller . '.php'; - } - } - } - - public function getPageLinkCompat($controller, $ssl = null, $id_lang = null, $request = null, $request_url_encode = false, $id_shop = null) { - if (class_exists('Context')) { - return Context::getContext()->link->getPageLink($controller, $ssl, $id_lang, $request, $request_url_encode, $id_shop); - } else { - if ($controller == 'contact') { - return Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'contact-form.php'; - } else { - $params = (isset($params)) ? "?" . $params : ""; - - return Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . $controller . - '.php' . $params; - } - } - } - - public function addLog($message, $severity = 1, $errorCode = null, $objectType = null, $objectId = null, $allowDuplicate = true) { - if (class_exists('PrestaShopLogger')) { - PrestaShopLogger::addLog($message, $severity, $errorCode, $objectType, $objectId, $allowDuplicate); - } else if (class_exists('Logger')) { - Logger::addLog($message, $severity, $errorCode, $objectType, $objectId, $allowDuplicate); - } else { - error_log($message . "(" . $errorCode . ")"); - } - } - - /* Callback authenticity check methods */ - public static function getCallbackAuthenticityData($orderId, $secure_key) { - return sha1($orderId . $secure_key . html_entity_decode(Configuration::get('PAYXPERT_PASSWORD'))); - } - - public static function checkCallbackAuthenticityData($callbackData, $orderId, $secure_key) { - return (strcasecmp($callbackData, PayXpert::getCallbackAuthenticityData($orderId, $secure_key)) === 0); - } - - /* Theses functions are only used for Prestashop prior to version 1.5 */ - public function execPayment($cart) { - global $cookie; - - $this->assignSmartyVariable('nbProducts', $cart->nbProducts()); - $this->assignSmartyVariable('cust_currency', $cart->id_currency); - $this->assignSmartyVariable('currencies', $this->getCurrency()); - $this->assignSmartyVariable('total', $cart->getOrderTotal(true, 3)); - $this->assignSmartyVariable('isoCode', Language::getIsoById(intval($cookie->id_lang))); - $this->assignSmartyVariable('this_path', $this->_path); - $this->assignSmartyVariable('this_link', $this->getModuleLinkCompat('payxpert', 'redirect')); - $this->assignSmartyVariable('this_link_back', $this->getPageLinkCompat('order', true, NULL, "step=3")); - - return $this->display(__FILE__, '/views/templates/front/payment_execution.tpl'); - } - - public function displayErrorPage($message) { - $this->assignSmartyVariable('errorMessage', $message); - $this->assignSmartyVariable('this_link_back', $this->getPageLinkCompat('order', true, NULL, "step=3")); - - return $this->display(__FILE__, '/views/templates/front/payment_error.tpl'); - } -} \ No newline at end of file diff --git a/modules/payxpert/validation.php b/modules/payxpert/validation.php deleted file mode 100644 index bd3e4c6..0000000 --- a/modules/payxpert/validation.php +++ /dev/null @@ -1,107 +0,0 @@ -getPayXpertUrl(), Configuration::get('PAYXPERT_ORIGINATOR'), - html_entity_decode(Configuration::get('PAYXPERT_PASSWORD'))); - -if ($c2pClient->handleCallbackStatus()) { - - $status = $c2pClient->getStatus(); - - // get the Error code - $errorCode = $status->getErrorCode(); - $errorMessage = $status->getErrorMessage(); - - $transaction = $status->getLastTransactionAttempt(); - - if ($transaction !== null) { - $transactionId = $transaction->getTransactionID(); - - $orderId = $status->getOrderID(); - $amount = number_format($status->getAmount() / 100, 2, '.', ''); - $callbackData = $status->getCtrlCustomData(); - - $message = "PayXpert payment module: "; - - // load the customer cart and perform some checks - $cart = new Cart((int) ($orderId)); - if (!$cart->id) { - $message .= "Cart is empty: " . $orderId; - error_log($message); - } - - $responseStatus = "KO"; - $responseMessage = "Callback validation failed"; - $customer = new Customer((int) ($cart->id_customer)); - - if (!$customer) { - $message .= "Customer is empty for order " . $orderId; - error_log($message); - } else { - if (!PayXpert::checkCallbackAuthenticityData($callbackData, $cart->id, $customer->secure_key)) { - $message .= "Invalid callback received for order " . $orderId . ". Validation failed."; - error_log($message); - } else { - $responseStatus = "OK"; - $responseMessage = "Status recorded"; - - $message .= "Error code: " . $errorCode . "
"; - $message .= "Error message: " . $errorMessage . "
"; - $message .= "Transaction ID: " . $transactionId . "
"; - $message .= "Order ID: " . $orderId . "
"; - - error_log(str_replace("
", " ", $message)); - - // To avoid issue with conversion rate get the amount from the order - $amount = $cart->getOrderTotal(true, 3); - - $paymentMean = $payxpert->l('Credit Card') . ' (PayXpert)'; - - switch ($errorCode) { - case "000": - /* Payment OK */ - $payxpert->validateOrder((int) $orderId, _PS_OS_PAYMENT_, $amount, $paymentMean, $message); - break; - default: - $payxpert->validateOrder((int) $orderId, _PS_OS_ERROR_, $amount, $paymentMean, $message); - break; - } - } - } - } - - // Send a response to mark this transaction as notified - $response = array("status" => $responseStatus, "message" => $responseMessage); - header("Content-type: application/json"); - echo json_encode($response); -} diff --git a/modules/payxpert/views/templates/admin/infos.tpl b/modules/payxpert/views/templates/admin/infos.tpl deleted file mode 100644 index 417d1ad..0000000 --- a/modules/payxpert/views/templates/admin/infos.tpl +++ /dev/null @@ -1,26 +0,0 @@ -{* - 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 Alexandre Chatiron -*} -{if $smarty.const._PS_VERSION_ >= 1.6} -
-{/if} - -

{l s='This module allows you to accept secure payments.' mod='payxpert'}

-





-{if $smarty.const._PS_VERSION_ >= 1.6} -
-{/if} \ No newline at end of file diff --git a/modules/payxpert/views/templates/front/payment_infos_bank_transfer_ideal.tpl b/modules/payxpert/views/templates/front/payment_infos_bank_transfer_ideal.tpl deleted file mode 100644 index 37f2f9c..0000000 --- a/modules/payxpert/views/templates/front/payment_infos_bank_transfer_ideal.tpl +++ /dev/null @@ -1,3 +0,0 @@ -
-

iDeal{l s='Use your bank account information with the iDeal provider to pay your order' mod='payxpert'}

-
\ No newline at end of file diff --git a/modules/payxpert/views/templates/front/payment_infos_bank_transfer_przelewy24.tpl b/modules/payxpert/views/templates/front/payment_infos_bank_transfer_przelewy24.tpl deleted file mode 100644 index 6539034..0000000 --- a/modules/payxpert/views/templates/front/payment_infos_bank_transfer_przelewy24.tpl +++ /dev/null @@ -1,3 +0,0 @@ -
-

Przelewy24{l s='Use your bank account information with the Przelewy24 provider to pay your order' mod='payxpert'}

-
\ No newline at end of file diff --git a/modules/payxpert/views/templates/front/payment_infos_bank_transfer_sofort.tpl b/modules/payxpert/views/templates/front/payment_infos_bank_transfer_sofort.tpl deleted file mode 100644 index b07ab79..0000000 --- a/modules/payxpert/views/templates/front/payment_infos_bank_transfer_sofort.tpl +++ /dev/null @@ -1,3 +0,0 @@ -
-

Sofort{l s='Use your bank account information with the Sofort provider to pay your order' mod='payxpert'}

-
\ No newline at end of file diff --git a/modules/payxpert/views/templates/front/payment_infos_credit_card.tpl b/modules/payxpert/views/templates/front/payment_infos_credit_card.tpl deleted file mode 100644 index b971ee3..0000000 --- a/modules/payxpert/views/templates/front/payment_infos_credit_card.tpl +++ /dev/null @@ -1,3 +0,0 @@ -
-

Credit Card{l s='Use your credit card information in a secured form to pay your order' mod='payxpert'}

-
\ No newline at end of file diff --git a/modules/payxpert/payment.php b/payment.php similarity index 77% rename from modules/payxpert/payment.php rename to payment.php index 8206a57..8b49a74 100644 --- a/modules/payxpert/payment.php +++ b/payment.php @@ -1,6 +1,6 @@ context->cookie; +} + +if (!isset($cart)) { + $cart = $this->context->cart; +} + if (!$cookie->isLogged()) { - Tools::redirect('authentication.php?back=order.php'); + Tools::redirect('authentication.php?back=order.php'); } $payxpert = new PayXpert(); echo $payxpert->execPayment($cart); -require_once(dirname(__FILE__) . '/../../footer.php'); \ No newline at end of file +require_once(dirname(__FILE__) . '/../../footer.php'); diff --git a/payxpert.php b/payxpert.php new file mode 100644 index 0000000..75df3dd --- /dev/null +++ b/payxpert.php @@ -0,0 +1,1176 @@ +name = 'payxpert'; + $this->version = '1.1.1'; + $this->module_key = '36f0012c50e666c56801493e0ad709eb'; + + $this->tab = 'payments_gateways'; + + $this->author = 'PayXpert'; + $this->need_instance = 1; + + $this->controllers = array('payment', 'validation'); + $this->is_eu_compatible = 1; + + if (version_compare(_PS_VERSION_, '1.5', '>=')) { + $this->ps_versions_compliancy = array('min' => '1.4.0.0', 'max' => _PS_VERSION_); + } + + if (version_compare(_PS_VERSION_, '1.6', '>=')) { + $this->bootstrap = true; + } + + parent::__construct(); + + $this->displayName = 'PayXpert Payment Solutions'; + $this->description = $this->l("Accept payments today with PayXpert"); + $this->confirmUninstall = $this->l('Are you sure about removing these details?'); + + if (!count(Currency::checkPaymentCurrencies($this->id))) { + $this->warning = $this->l('No currency has been set for this module.'); + } + + /* For 1.4.3 and less compatibility */ + $updateConfig = array('PS_OS_CHEQUE' => 1, 'PS_OS_PAYMENT' => 2, 'PS_OS_PREPARATION' => 3, 'PS_OS_SHIPPING' => 4, + 'PS_OS_DELIVERED' => 5, 'PS_OS_CANCELED' => 6, 'PS_OS_REFUND' => 7, 'PS_OS_ERROR' => 8, 'PS_OS_OUTOFSTOCK' => 9, + 'PS_OS_BANKWIRE' => 10, 'PS_OS_PAYPAL' => 11, 'PS_OS_WS_PAYMENT' => 12); + + foreach ($updateConfig as $u => $v) { + if (!Configuration::get($u) || (int) Configuration::get($u) < 1) { + if (defined('_' . $u . '_') && (int) constant('_' . $u . '_') > 0) { + Configuration::updateValue($u, constant('_' . $u . '_')); + } else { + Configuration::updateValue($u, $v); + } + } + } + } + + /** + * Install method + */ + public function install() + { + // call parents + if (!parent::install()) { + $errorMessage = Tools::displayError($this->l('PayXpert installation : install failed.')); + $this->addLog($errorMessage, 3, '000002'); + return false; + } + + // Add hook methods + $hookResult = $this->registerHook('paymentReturn'); + if (version_compare(_PS_VERSION_, '1.7', '<')) { + $hookResult = $hookResult && $this->registerHook('payment'); + } else { + $hookResult = $hookResult && $this->registerHook('paymentOptions'); + } + + if (!$hookResult) { + $errorMessage = Tools::displayError($this->l('PayXpert installation : hooks failed.')); + $this->addLog($errorMessage, 3, '000002'); + + return false; + } + + // Add configuration parameters + foreach ($this->getModuleParameters() as $parameter) { + if (!Configuration::updateValue($parameter, '')) { + $errorMessage = Tools::displayError($this->l('PayXpert installation : configuration failed.')); + $this->addLog($errorMessage, 3, '000002'); + + return false; + } + } + + $this->addLog($this->l('PayXpert installation : installation successful')); + + return true; + } + + /** + * Uninstall the module + * + * @return boolean + */ + public function uninstall() + { + $result = parent::uninstall(); + + foreach ($this->getModuleParameters() as $parameter) { + $result = $result || Configuration::deleteByName($parameter); + } + + return $result; + } + + private function getModuleParameters() + { + $moduleParameters = array( /* */ + 'PAYXPERT_ORIGINATOR', /* */ + 'PAYXPERT_PASSWORD', /* */ + 'PAYXPERT_URL', /* */ + 'PAYXPERT_MERCHANT_NOTIF', /* */ + 'PAYXPERT_MERCHANT_NOTIF_TO', /* */ + 'PAYXPERT_MERCHANT_NOTIF_LANG' /* */ + ); + + if (version_compare(_PS_VERSION_, '1.7', '>=')) { + $moduleParameters[] = 'PAYXPERT_PAYMENT_TYPE_CREDIT_CARD'; + $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; + } + + public function checkPaymentOption($params) + { + // if module disabled, can't go through + if (!$this->active) { + return false; + } + + // Check if currency ok + if (!$this->checkCurrency($params['cart'])) { + return false; + } + + // Check if module is configured + if (Configuration::get('PAYXPERT_ORIGINATOR') == "" && Configuration::get('PAYXPERT_PASSWORD') == "") { + return false; + } + + return true; + } + + /** + * Hook payment options + * + * @since Prestashop 1.7 + * @param type $params + * @return type + */ + public function hookPaymentOptions($params) + { + if (!$this->checkPaymentOption($params)) { + return; + } + + $controller = 'payment'; + + if ($this->isIframeMode()) { + $controller = 'iframe'; + } + + $this->smarty->assign($this->getTemplateVarInfos()); + + $payment_options = array(); + + $ccOption = $this->getCreditCardPaymentOption($controller); + if ($ccOption != null) { + $payment_options[] = $ccOption; + } + $sofortOption = $this->getBankTransferViaSofortPaymentOption($controller); + if ($sofortOption != null) { + $payment_options[] = $sofortOption; + } + $przelewy24Option = $this->getBankTransferViaPrzelewy24PaymentOption($controller); + if ($przelewy24Option != null) { + $payment_options[] = $przelewy24Option; + } + $idealOption = $this->getBankTransferViaIDealPaymentOption($controller); + if ($idealOption != null) { + $payment_options[] = $idealOption; + } + + return $payment_options; + } + + /** + * + * @since Prestashop 1.7 + */ + public function getCreditCardPaymentOption($controller) + { + if (Configuration::get('PAYXPERT_PAYMENT_TYPE_CREDIT_CARD') == "true") { + $option = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); + $option->setModuleName($this->name); + $option->setCallToActionText($this->l('Pay by Credit Card')); + $option->setAction( + $this->context->link->getModuleLink( + $this->name, + $controller, + array('payment_type' => PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_CREDITCARD), + true + ) + ); + + $this->context->smarty->assign( + 'pxpCCLogo', + Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/views/img/payment-types/creditcard.png') + ); + + $option->setAdditionalInformation($this->context->smarty->fetch('module:payxpert/views/templates/front/payment_infos_credit_card.tpl')); + + return $option; + } + + return null; + } + + /** + * + * @since Prestashop 1.7 + */ + public function getBankTransferViaSofortPaymentOption($controller) + { + if (Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT') == "true") { + $option = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); + $option->setModuleName($this->name); + $option->setCallToActionText($this->l('Pay by Bank Transfer via Sofort')); + $option->setAction( + $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 + ) + ); + + $this->context->smarty->assign( + "pxpSofortLogo", + Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/views/img/payment-types/sofort.png') + ); + + $option->setAdditionalInformation($this->context->smarty->fetch('module:payxpert/views/templates/front/payment_infos_bank_transfer_sofort.tpl')); + + return $option; + } + + return null; + } + + /** + * + * @since Prestashop 1.7 + */ + public function getBankTransferViaPrzelewy24PaymentOption($controller) + { + if (Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24') == "true") { + $option = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); + $option->setModuleName($this->name); + $option->setCallToActionText($this->l('Pay by Bank Transfer via Przelewy24')); + $option->setAction( + $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 + ) + ); + + $this->context->smarty->assign( + "pxpPrzelewy24Logo", + Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/views/img/payment-types/przelewy24.png') + ); + + $option->setAdditionalInformation($this->context->smarty->fetch('module:payxpert/views/templates/front/payment_infos_bank_transfer_przelewy24.tpl')); + + return $option; + } + + return null; + } + + /** + * + * @since Prestashop 1.7 + */ + public function getBankTransferViaIDealPaymentOption($controller) + { + if (Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL') == "true") { + $option = new PrestaShop\PrestaShop\Core\Payment\PaymentOption(); + $option->setModuleName($this->name); + $option->setCallToActionText($this->l('Pay by Bank Transfer via iDeal')); + $option->setAction( + $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 + ) + ); + + $this->context->smarty->assign( + "pxpIdealLogo", + Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/views/img/payment-types/ideal.png') + ); + + $option->setAdditionalInformation($this->context->smarty->fetch('module:payxpert/views/templates/front/payment_infos_bank_transfer_ideal.tpl')); + + return $option; + } + + return null; + } + + public function getTemplateVarInfos() + { + $cart = $this->context->cart; + + return array(/* */ + 'nbProducts' => $cart->nbProducts(), /* */ + 'cust_currency' => $cart->id_currency, /* */ + 'total' => $cart->getOrderTotal(true, Cart::BOTH), /* */ + 'isoCode' => $this->context->language->iso_code /* */ + ); + } + + /** + * Hook payment for Prestashop < 1.7 + * + * @param type $params + * @return type + */ + 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') . + __PS_BASE_URI__ . 'modules/payxpert/' + ); + + $this->assignSmartyVariable( + 'this_link', + $this->getModuleLinkCompat( + 'payxpert', + 'payment' + ) + ); + + if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { + $this->context->controller->addCSS($this->_path . 'views/css/payxpert.css'); + } + + return $this->display(__FILE__, 'views/templates/hook/payment.tpl'); + } + + /** + * Hook paymentReturn + * + * Displays order confirmation + * + * @param type $params + * @return type + */ + public function hookPaymentReturn($params) + { + if (!$this->active) { + return; + } + + if (isset($params['objOrder'])) { + // For Prestashop < 1.7 + $order = $params['objOrder']; + } else { + $order = $params['order']; + } + + switch ($order->getCurrentState()) { + case _PS_OS_PAYMENT_: + // Ok + case _PS_OS_OUTOFSTOCK_: + $this->assignSmartyVariable('status', 'ok'); + break; + + case _PS_OS_BANKWIRE_: + $this->assignSmartyVariable('status', 'pending'); + break; + + case _PS_OS_ERROR_: + // Error + default: + $this->assignSmartyVariable('status', 'failed'); + break; + } + + $this->assignSmartyVariable('this_link_contact', $this->getPageLinkCompat('contact', true)); + + return $this->display(__FILE__, 'views/templates/hook/orderconfirmation.tpl'); + } + + /** + * Init the payment + * + * In this method, we'll start to initialize the transaction + * And redirect the customer + * + * For Prestashop >= 1.5 + * + * @global type $cookie + * @param Cart $cart + * @return type + */ + public function redirect($cart, $paymentType = null, $paymentProvider = null) + { + // if module disabled, can't go through + if (!$this->active) { + return "Module is not active"; + } + + // Check if currency ok + if (!$this->checkCurrency($cart)) { + return "Incorrect currency"; + } + + // Check if module is configured + if (Configuration::get('PAYXPERT_ORIGINATOR') == "" && Configuration::get('PAYXPERT_PASSWORD') == "") { + return "Module is not setup"; + } + + if ($paymentType == null || !PayXpert\Connect2Pay\C2PValidate::isPayment($paymentType)) { + $paymentType = PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_CREDITCARD; + } + + if (!$this->checkPaymentTypeAndProvider($paymentType, $paymentProvider)) { + 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; + } + + Tools::redirect($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)); + $carrier = new Carrier((int) ($cart->id_carrier)); + $addr_delivery = new Address((int) ($cart->id_address_delivery)); + $addr_invoice = new Address((int) ($cart->id_address_invoice)); + + $invoice_state = new State((int) ($addr_invoice->id_state)); + $invoice_country = new Country((int) ($addr_invoice->id_country)); + + $delivery_state = new State((int) ($addr_delivery->id_state)); + $delivery_country = new Country((int) ($addr_delivery->id_country)); + + $invoice_phone = (!empty($addr_invoice->phone)) ? $addr_invoice->phone : $addr_invoice->phone_mobile; + $delivery_phone = (!empty($addr_delivery->phone)) ? $addr_delivery->phone : $addr_delivery->phone_mobile; + + // init api + $c2pClient = new PayXpert\Connect2Pay\Connect2PayClient( + $this->getPayXpertUrl(), + Configuration::get('PAYXPERT_ORIGINATOR'), + html_entity_decode(Configuration::get('PAYXPERT_PASSWORD')) + ); + + // customer informations + $c2pClient->setShopperID($cart->id_customer); + $c2pClient->setShopperEmail($customer->email); + $c2pClient->setShopperFirstName(Tools::substr($customer->firstname, 0, 35)); + $c2pClient->setShopperLastName(Tools::substr($customer->lastname, 0, 35)); + $c2pClient->setShopperCompany(Tools::substr($addr_invoice->company, 0, 128)); + $c2pClient->setShopperAddress(Tools::substr(trim($addr_invoice->address1 . ' ' . $addr_invoice->address2), 0, 255)); + $c2pClient->setShopperZipcode(Tools::substr($addr_invoice->postcode, 0, 10)); + $c2pClient->setShopperCity(Tools::substr($addr_invoice->city, 0, 50)); + $c2pClient->setShopperState(Tools::substr($invoice_state->name, 0, 30)); + $c2pClient->setShopperCountryCode($invoice_country->iso_code); + $c2pClient->setShopperPhone(Tools::substr(trim($invoice_phone), 0, 20)); + + // Shipping information + $c2pClient->setShipToFirstName(Tools::substr($addr_delivery->firstname, 0, 35)); + $c2pClient->setShipToLastName(Tools::substr($addr_delivery->lastname, 0, 35)); + $c2pClient->setShipToCompany(Tools::substr($addr_delivery->company, 0, 128)); + $c2pClient->setShipToPhone(Tools::substr(trim($delivery_phone), 0, 20)); + $c2pClient->setShipToAddress(Tools::substr(trim($addr_delivery->address1 . " " . $addr_delivery->address2), 0, 255)); + $c2pClient->setShipToZipcode(Tools::substr($addr_delivery->postcode, 0, 10)); + $c2pClient->setShipToCity(Tools::substr($addr_delivery->city, 0, 50)); + $c2pClient->setShipToState(Tools::substr($delivery_state->name, 0, 30)); + $c2pClient->setShipToCountryCode($delivery_country->iso_code); + $c2pClient->setShippingName(Tools::substr($carrier->name, 0, 50)); + $c2pClient->setShippingType(PayXpert\Connect2Pay\Connect2PayClient::_SHIPPING_TYPE_PHYSICAL); + + // Order informations + $c2pClient->setOrderID(Tools::substr(pSQL($cart->id), 0, 100)); + $c2pClient->setOrderDescription(Tools::substr($this->l('Invoice:') . pSQL($cart->id), 0, 255)); + $c2pClient->setCustomerIP($_SERVER['REMOTE_ADDR']); + $c2pClient->setCurrency($currency->iso_code); + + $total = number_format($cart->getOrderTotal(true, 3) * 100, 0, '.', ''); + + $c2pClient->setAmount($total); + $c2pClient->setOrderCartContent($this->getProductsApi($cart)); + $c2pClient->setPaymentMode(PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_MODE_SINGLE); + $c2pClient->setPaymentType($paymentType); + if ($paymentProvider != null && PayXpert\Connect2Pay\C2PValidate::isProvider($paymentProvider)) { + $c2pClient->setProvider($paymentProvider); + } + $c2pClient->setCtrlCustomData(PayXpert::getCallbackAuthenticityData($c2pClient->getOrderID(), $customer->secure_key)); + + // Merchant notifications + if (Configuration::get('PAYXPERT_MERCHANT_NOTIF') === "true" && Configuration::get('PAYXPERT_MERCHANT_NOTIF_TO')) { + $c2pClient->setMerchantNotification(true); + $c2pClient->setMerchantNotificationTo(Configuration::get('PAYXPERT_MERCHANT_NOTIF_TO')); + if (Configuration::get('PAYXPERT_MERCHANT_NOTIF_LANG')) { + $c2pClient->setMerchantNotificationLang(Configuration::get('PAYXPERT_MERCHANT_NOTIF_LANG')); + } + } + + $ctrlURLPrefix = Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://'; + + if (version_compare(_PS_VERSION_, '1.5', '<')) { + $c2pClient->setCtrlCallbackURL($ctrlURLPrefix . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/payxpert/validation.php'); + $c2pClient->setCtrlRedirectURL($ctrlURLPrefix . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . (int) ($cart->id) . '&id_module=' . (int) ($this->id) . '&key=' . $customer->secure_key); + } else { + $c2pClient->setCtrlCallbackURL($this->context->link->getModuleLink('payxpert', 'validation')); + $c2pClient->setCtrlRedirectURL($this->getModuleLinkCompat('payxpert', 'return')); + } + + return $c2pClient; + } + + /** + * Return array of product to fill Api Product properties + * + * @param Cart $cart + * @return array + */ + protected function getProductsApi($cart) + { + $products = array(); + + foreach ($cart->getProducts() as $product) { + $obj = new Product((int) $product['id_product']); + $products[] = array( /* */ + 'CartProductId' => $product['id_product'], /* */ + 'CartProductName' => $product['name'], /* */ + 'CartProductUnitPrice' => $product['price'], /* */ + 'CartProductQuantity' => $product['quantity'], /* */ + 'CartProductBrand' => $obj->manufacturer_name, /* */ + 'CartProductMPN' => $product['ean13'], /* */ + 'CartProductCategoryName' => $product['category'], /* */ + 'CartProductCategoryID' => $product['id_category_default'] /* */ + ); + } + + return $products; + } + + public function getContent() + { + if (Tools::isSubmit('btnSubmit')) { + $this->_postValidation(); + + if (!count($this->_postErrors)) { + $this->_postProcess(); + } else { + foreach ($this->_postErrors as $err) { + $this->_html .= $this->displayError($err); + } + } + } else { + $this->_html .= '
'; + } + + $this->_html .= $this->display(__FILE__, '/views/templates/admin/infos.tpl'); + + if (version_compare(_PS_VERSION_, '1.6', '<')) { + /* Prestashop parameter names must not exceed 32 chars for v < 1.6 */ + $this->assignSmartyVariable( + 'PAYXPERT_ORIGINATOR', + Tools::safeOutput(Tools::getValue( + 'PAYXPERT_ORIGINATOR', + Configuration::get('PAYXPERT_ORIGINATOR') + )) + ); + + $this->assignSmartyVariable( + 'PAYXPERT_URL', + Tools::safeOutput(Tools::getValue( + 'PAYXPERT_URL', + Configuration::get('PAYXPERT_URL') + )) + ); + + $merchantNotifications = (Configuration::get('PAYXPERT_MERCHANT_NOTIF') == "true") ? "true" : "false"; + if (Tools::getValue('PAYXPERT_MERCHANT_NOTIF')) { + $merchantNotifications = (in_array(Tools::getValue('PAYXPERT_MERCHANT_NOTIF'), array("true", "1", "on"))) ? "true" : "false"; + } + + $this->assignSmartyVariable( + 'PAYXPERT_MERCHANT_NOTIF', + $merchantNotifications + ); + + $this->assignSmartyVariable( + 'PAYXPERT_MERCHANT_NOTIF_TO', + Tools::safeOutput(Tools::getValue( + 'PAYXPERT_MERCHANT_NOTIF_TO', + Configuration::get('PAYXPERT_MERCHANT_NOTIF_TO') + )) + ); + + $this->assignSmartyVariable( + 'PAYXPERT_MERCHANT_NOTIF_LANG', + Tools::safeOutput(Tools::getValue( + 'PAYXPERT_MERCHANT_NOTIF_LANG', + Configuration::get('PAYXPERT_MERCHANT_NOTIF_LANG') + )) + ); + + $this->_html .= $this->display( + __FILE__, + '/views/templates/admin/config.tpl' + ); + } else { + $this->_html .= $this->renderForm(); + } + + return $this->_html; + } + + public function getConfigFieldsValues() + { + // Handle checkboxes + $merchantNotif = Tools::getValue('PAYXPERT_MERCHANT_NOTIF', Configuration::get('PAYXPERT_MERCHANT_NOTIF')); + + $result = array( /* */ + 'PAYXPERT_ORIGINATOR' => Tools::getValue('PAYXPERT_ORIGINATOR', Configuration::get('PAYXPERT_ORIGINATOR')), /* */ + 'PAYXPERT_URL' => Tools::getValue('PAYXPERT_URL', Configuration::get('PAYXPERT_URL')), /* */ + 'PAYXPERT_MERCHANT_NOTIF' => ($merchantNotif === "true" || $merchantNotif == 1) ? 1 : 0, /* */ + 'PAYXPERT_MERCHANT_NOTIF_TO' => Tools::getValue( + 'PAYXPERT_MERCHANT_NOTIF_TO', + Configuration::get('PAYXPERT_MERCHANT_NOTIF_TO') + ), + 'PAYXPERT_MERCHANT_NOTIF_LANG' => Tools::getValue( + 'PAYXPERT_MERCHANT_NOTIF_LANG', + Configuration::get('PAYXPERT_MERCHANT_NOTIF_LANG') + ), + ); + + if (version_compare(_PS_VERSION_, '1.7', '>=')) { + $creditCardPaymentType = Tools::getValue( + 'PAYXPERT_PAYMENT_TYPE_CREDIT_CARD', + Configuration::get('PAYXPERT_PAYMENT_TYPE_CREDIT_CARD') + ); + + $sofortPaymentType = Tools::getValue( + 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT', + Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT') + ); + + $przelewy24PaymentType = Tools::getValue( + 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24', + 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; + } + + public function renderForm() + { + $fields_form = array( + 'form' => array( /* */ + 'legend' => array( /* */ + 'title' => $this->l('Settings'), /* */ + 'icon' => 'icon-gears' /* */ + ), /* */ + 'input' => array( /* */ + array( /* */ + 'type' => 'text', /* */ + 'name' => 'PAYXPERT_ORIGINATOR', /* */ + 'label' => $this->l('Originator ID'), /* */ + 'desc' => $this->l('The identifier of your Originator'), /* */ + 'required' => true /* */ + ), + array( /* */ + 'type' => 'password', /* */ + 'name' => 'PAYXPERT_PASSWORD', /* */ + 'label' => $this->l('Originator password'), /* */ + 'desc' => $this->l('The password associated with your Originator (leave empty to keep the current one)'), /* */ + 'hint' => $this->l('Leave empty to keep the current one'), /* */ + 'required' => false /* */ + ), + array( /* */ + 'type' => 'text', /* */ + 'name' => 'PAYXPERT_URL', /* */ + 'label' => $this->l('Payment Page URL'), /* */ + 'desc' => $this->l('Leave this field empty unless you have been given an URL'), /* */ + 'required' => false /* */ + ), + array( /* */ + 'type' => 'switch', /* */ + 'name' => 'PAYXPERT_MERCHANT_NOTIF', /* */ + 'label' => $this->l('Merchant notifications'), /* */ + 'desc' => $this->l('Whether or not to send a notification to the merchant for each processed payment'), /* */ + 'required' => false, /* */ + 'is_bool' => true, /* */ + 'values' => array( /* */ + array('id' => 'notif_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ + array('id' => 'notif_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ + ) /* */ + ), /* */ + array( /* */ + 'type' => 'text', /* */ + 'name' => 'PAYXPERT_MERCHANT_NOTIF_TO', /* */ + 'label' => $this->l('Merchant notifications recipient'), /* */ + 'desc' => $this->l('Recipient email address for merchant notifications'), /* */ + 'required' => false, /* */ + 'size' => 100 /* */ + ), /* */ + array( /* */ + 'type' => 'select', /* */ + 'name' => 'PAYXPERT_MERCHANT_NOTIF_LANG', /* */ + 'label' => $this->l('Merchant notifications lang'), /* */ + 'desc' => $this->l('Language to use for merchant notifications'), /* */ + 'required' => false, /* */ + 'options' => array( /* */ + 'query' => array( /* */ + array('id_option' => 'en', 'name' => $this->l('English')), /* */ + array('id_option' => 'fr', 'name' => $this->l('French')), /* */ + array('id_option' => 'es', 'name' => $this->l('Spanish')), /* */ + array('id_option' => 'it', 'name' => $this->l('Italian')) /* */ + ), /* */ + 'id' => 'id_option', /* */ + 'name' => 'name' /* */ + ) /* */ + ) /* */ + ), /* */ + 'submit' => array('title' => $this->l('Update settings')) /* */ + ) /* */ + ); + + if (version_compare(_PS_VERSION_, '1.7', '>=')) { + $fields_form['form']['input'][] = array( /* */ + 'type' => 'switch', /* */ + 'name' => 'PAYXPERT_PAYMENT_TYPE_CREDIT_CARD', /* */ + 'label' => $this->l('Credit Card'), /* */ + 'desc' => $this->l('Enable payment type: Credit Card'), /* */ + 'required' => false, /* */ + 'is_bool' => true, /* */ + 'values' => array(/* */ + array('id' => 'cc_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ + array('id' => 'cc_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ + ) /* */ + ); + $fields_form['form']['input'][] = array( /* */ + 'type' => 'switch', /* */ + 'name' => 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT', /* */ + 'label' => $this->l('Bank Transfert via Sofort'), /* */ + 'desc' => $this->l('Enable payment type: Bank Transfer via Sofort'), /* */ + 'required' => false, /* */ + 'is_bool' => true, /* */ + 'values' => array(/* */ + array('id' => 'sofort_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ + array('id' => 'sofort_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ + ) /* */ + ); + $fields_form['form']['input'][] = array( /* */ + 'type' => 'switch', /* */ + 'name' => 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24', /* */ + 'label' => $this->l('Bank Transfert via Przelewy24'), /* */ + 'desc' => $this->l('Enable payment type: Bank Transfer via Przelewy24'), /* */ + 'required' => false, /* */ + 'is_bool' => true, /* */ + 'values' => array(/* */ + array('id' => 'przelewy24_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ + array('id' => 'przelewy24_off', 'value' => 0, 'label' => $this->l('Disabled')) /* */ + ) /* */ + ); + $fields_form['form']['input'][] = array( /* */ + 'type' => 'switch', /* */ + 'name' => 'PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL', /* */ + 'label' => $this->l('Bank Transfert via iDeal'), /* */ + 'desc' => $this->l('Enable payment type: Bank Transfer via iDeal'), /* */ + 'required' => false, /* */ + 'is_bool' => true, /* */ + 'values' => array(/* */ + array('id' => 'ideal_on', 'value' => 1, 'label' => $this->l('Enabled')), /* */ + 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(); + $helper->show_toolbar = false; + $helper->table = $this->table; + $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT')); + $helper->default_form_language = $lang->id; + $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; + $this->fields_form = array(); + + $helper->identifier = $this->identifier; + $helper->submit_action = 'btnSubmit'; + $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . + $this->tab . '&module_name=' . $this->name; + $helper->token = Tools::getAdminTokenLite('AdminModules'); + $helper->tpl_vars = array( /* */ + 'fields_value' => $this->getConfigFieldsValues(), /* */ + 'languages' => $this->context->controller->getLanguages(), /* */ + 'id_language' => $this->context->language->id /* */ + ); + + return $helper->generateForm(array($fields_form)); + } + + private function _postValidation() + { + if (Tools::isSubmit('btnSubmit')) { + if (!Tools::getValue('PAYXPERT_ORIGINATOR')) { + $this->_postErrors[] = $this->l('Originator is required.'); + } + + if (!Configuration::get('PAYXPERT_PASSWORD') && !Tools::getValue('PAYXPERT_PASSWORD')) { + $this->_postErrors[] = $this->l('Password is required.'); + } + + if (in_array(Tools::getValue('PAYXPERT_MERCHANT_NOTIF'), array("true", "1", "on")) && !Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO')) { + $this->_postErrors[] = $this->l('Merchant notifications recipient is required.'); + } + + if (Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO') && !Validate::isEmail(Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO'))) { + $this->_postErrors[] = $this->l('Merchant notifications recipient must be a valid email address.'); + } + + if (!in_array(Tools::getValue('PAYXPERT_MERCHANT_NOTIF_LANG'), array("en", "fr", "es", "it"))) { + $this->_postErrors[] = $this->l('Merchant notification lang is not valid.'); + } + } + } + + protected function _postProcess() + { + if (Tools::isSubmit('btnSubmit')) { + Configuration::updateValue('PAYXPERT_ORIGINATOR', Tools::getValue('PAYXPERT_ORIGINATOR')); + + if (Tools::getValue('PAYXPERT_PASSWORD')) { + // Manually handle HTML special chars to avoid losing them + Configuration::updateValue('PAYXPERT_PASSWORD', htmlentities(Tools::getValue('PAYXPERT_PASSWORD'))); + } + + Configuration::updateValue('PAYXPERT_URL', Tools::getValue('PAYXPERT_URL')); + + Configuration::updateValue('PAYXPERT_MERCHANT_NOTIF_TO', Tools::getValue('PAYXPERT_MERCHANT_NOTIF_TO')); + + if (in_array(Tools::getValue('PAYXPERT_MERCHANT_NOTIF_LANG'), array("en", "fr", "es", "it"))) { + Configuration::updateValue('PAYXPERT_MERCHANT_NOTIF_LANG', Tools::getValue('PAYXPERT_MERCHANT_NOTIF_LANG')); + } + + // Handle checkboxes + $checkboxes = array( /* */ + 'PAYXPERT_MERCHANT_NOTIF' /* */ + ); + if (version_compare(_PS_VERSION_, '1.7', '>=')) { + $checkboxes[] = 'PAYXPERT_PAYMENT_TYPE_CREDIT_CARD'; + $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) { + if (in_array(Tools::getValue($checkbox), array("true", "1", "on"))) { + Configuration::updateValue($checkbox, "true"); + } else { + Configuration::updateValue($checkbox, "false"); + } + } + } + + if (version_compare(_PS_VERSION_, '1.6', '>=')) { + $this->_html .= $this->displayConfirmation($this->l('Configuration updated')); + } else { + $this->_html .= ' ' . $this->l('Configuration updated') . ''; + + return true; + } + } + + private function checkPaymentTypeAndProvider($paymentType, $paymentProvider) + { + // For Prestashop >=1.7, check that the payment type is enabled + if (version_compare(_PS_VERSION_, '1.7.0', '>=') === true) { + switch ($paymentType) { + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_CREDITCARD: + return Configuration::get('PAYXPERT_PAYMENT_TYPE_CREDIT_CARD') === "true"; + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_TYPE_BANKTRANSFER: + if ($paymentProvider !== null) { + switch ($paymentProvider) { + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_SOFORT: + return Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_SOFORT') === "true"; + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_PRZELEWY24: + return Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_PRZELEWY24') === "true"; + case PayXpert\Connect2Pay\Connect2PayClient::_PAYMENT_PROVIDER_IDEALKP: + return Configuration::get('PAYXPERT_PAYMENT_TYPE_BANK_TRANSFERT_IDEAL') === "true"; + } + } + break; + } + } else { + return true; + } + + return false; + } + + private function checkCurrency($cart) + { + $currency_order = new Currency((int) ($cart->id_currency)); + $currencies_module = $this->getCurrency((int) $cart->id_currency); + + if (is_array($currencies_module)) { + foreach ($currencies_module as $currency_module) { + if ($currency_order->id == $currency_module['id_currency']) { + return true; + } + } + } + + return false; + } + + /** + * Get PayXpert Url depending of the env + * + * @return string Url + */ + public function getPayXpertUrl() + { + $url = Configuration::get('PAYXPERT_URL'); + + if (Tools::strlen(trim($url)) <= 0) { + $url = 'https://connect2.payxpert.com/'; + } + + 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) + { + // Check if context smarty variable is available + if (isset($this->context->smarty)) { + return $this->context->smarty->assign($name, $value); + } else { + // Use the global variable + if (!isset($smarty)) { + $smarty = $this->context->smarty; + } + + return $smarty->assign($name, $value); + } + } + + public function getModuleLinkCompat($module, $controller = 'default', $params = null) + { + if (class_exists('Context')) { + if (!$params) { + $params = array(); + } + + return Context::getContext()->link->getModuleLink($module, $controller, $params); + } else { + if ($controller == 'default') { + if ($params) { + $params = "?" . $params; + } + + return Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . $module . '.php' . + $params; + } else { + return Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . + 'modules/payxpert/' . $controller . '.php'; + } + } + } + + public function getPageLinkCompat($controller, $ssl = null, $id_lang = null, $request = null, $request_url_encode = false, $id_shop = null) + { + if (class_exists('Context')) { + return Context::getContext()->link->getPageLink($controller, $ssl, $id_lang, $request, $request_url_encode, $id_shop); + } else { + if ($controller == 'contact') { + return Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'contact-form.php'; + } else { + $params = (isset($params)) ? "?" . $params : ""; + + return Configuration::get('PS_SSL_ENABLED') ? 'https' : 'http' . '://' . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . $controller . + '.php' . $params; + } + } + } + + public function addLog($message, $severity = 1, $errorCode = null, $objectType = null, $objectId = null, $allowDuplicate = true) + { + if (class_exists('PrestaShopLogger')) { + PrestaShopLogger::addLog($message, $severity, $errorCode, $objectType, $objectId, $allowDuplicate); + } else if (class_exists('Logger')) { + Logger::addLog($message, $severity, $errorCode, $objectType, $objectId, $allowDuplicate); + } else { + error_log($message . "(" . $errorCode . ")"); + } + } + + /* Callback authenticity check methods */ + public static function getCallbackAuthenticityData($orderId, $secure_key) + { + return sha1($orderId . $secure_key . html_entity_decode(Configuration::get('PAYXPERT_PASSWORD'))); + } + + public static function checkCallbackAuthenticityData($callbackData, $orderId, $secure_key) + { + return (strcasecmp($callbackData, PayXpert::getCallbackAuthenticityData($orderId, $secure_key)) === 0); + } + + /* Theses functions are only used for Prestashop prior to version 1.5 */ + public function execPayment($cart) + { + if (!isset($cookie)) { + $cookie = $this->context->cookie; + } + + $this->assignSmartyVariable('nbProducts', $cart->nbProducts()); + $this->assignSmartyVariable('cust_currency', $cart->id_currency); + $this->assignSmartyVariable('currencies', $this->getCurrency()); + $this->assignSmartyVariable('total', $cart->getOrderTotal(true, 3)); + $this->assignSmartyVariable('isoCode', Language::getIsoById((int)($cookie->id_lang))); + $this->assignSmartyVariable('this_path', $this->_path); + $this->assignSmartyVariable('this_link', $this->getModuleLinkCompat('payxpert', 'redirect')); + $this->assignSmartyVariable('this_link_back', $this->getPageLinkCompat('order', true, null, "step=3")); + + return $this->display(__FILE__, '/views/templates/front/payment_execution.tpl'); + } + + public function displayErrorPage($message) + { + $this->assignSmartyVariable('errorMessage', $message); + $this->assignSmartyVariable('this_link_back', $this->getPageLinkCompat('order', true, null, "step=3")); + + return $this->display(__FILE__, '/views/templates/front/payment_error.tpl'); + } +} diff --git a/modules/payxpert/redirect.php b/redirect.php similarity index 86% rename from modules/payxpert/redirect.php rename to redirect.php index 78a4f87..29590ef 100644 --- a/modules/payxpert/redirect.php +++ b/redirect.php @@ -1,6 +1,6 @@ context->cookie; +} + +if (!isset($cart)) { + $cart = $this->context->cart; +} + if (!$cookie->isLogged()) { Tools::redirect('authentication.php?back=order.php'); } diff --git a/validation.php b/validation.php new file mode 100644 index 0000000..b8602ba --- /dev/null +++ b/validation.php @@ -0,0 +1,107 @@ +getPayXpertUrl(), + Configuration::get('PAYXPERT_ORIGINATOR'), + html_entity_decode(Configuration::get('PAYXPERT_PASSWORD')) +); + +if ($c2pClient->handleCallbackStatus()) { + $status = $c2pClient->getStatus(); + + // get the Error code + $errorCode = $status->getErrorCode(); + $errorMessage = $status->getErrorMessage(); + + $transaction = $status->getLastTransactionAttempt(); + + if ($transaction !== null) { + $transactionId = $transaction->getTransactionID(); + + $orderId = $status->getOrderID(); + $amount = number_format($status->getAmount() / 100, 2, '.', ''); + $callbackData = $status->getCtrlCustomData(); + + $message = "PayXpert payment module: "; + + // load the customer cart and perform some checks + $cart = new Cart((int) ($orderId)); + if (!$cart->id) { + $message .= "Cart is empty: " . $orderId; + error_log($message); + } + + $responseStatus = "KO"; + $responseMessage = "Callback validation failed"; + $customer = new Customer((int) ($cart->id_customer)); + + if (!$customer) { + $message .= "Customer is empty for order " . $orderId; + error_log($message); + } else { + if (!PayXpert::checkCallbackAuthenticityData($callbackData, $cart->id, $customer->secure_key)) { + $message .= "Invalid callback received for order " . $orderId . ". Validation failed."; + error_log($message); + } else { + $responseStatus = "OK"; + $responseMessage = "Status recorded"; + + $message .= "Error code: " . $errorCode . "
"; + $message .= "Error message: " . $errorMessage . "
"; + $message .= "Transaction ID: " . $transactionId . "
"; + $message .= "Order ID: " . $orderId . "
"; + + error_log(str_replace("
", " ", $message)); + + $paymentMean = $payxpert->l('Credit Card') . ' (PayXpert)'; + + switch ($errorCode) { + case "000": + /* Payment OK */ + $payxpert->validateOrder((int) $orderId, _PS_OS_PAYMENT_, $amount, $paymentMean, $message); + break; + default: + $payxpert->validateOrder((int) $orderId, _PS_OS_ERROR_, $amount, $paymentMean, $message); + break; + } + } + } + } + + // Send a response to mark this transaction as notified + $response = array("status" => $responseStatus, "message" => $responseMessage); + header("Content-type: application/json"); + echo json_encode($response); +} diff --git a/modules/payxpert/css/iframe.css b/views/css/iframe.css similarity index 95% rename from modules/payxpert/css/iframe.css rename to views/css/iframe.css index f5df611..64a068c 100644 --- a/modules/payxpert/css/iframe.css +++ b/views/css/iframe.css @@ -11,7 +11,7 @@ } .fluidIframe iframe { - border: none; + border: none; position: absolute; top: 0; left: 0; diff --git a/modules/payxpert/css/index.php b/views/css/index.php similarity index 100% rename from modules/payxpert/css/index.php rename to views/css/index.php diff --git a/modules/payxpert/css/payxpert.css b/views/css/payxpert.css similarity index 76% rename from modules/payxpert/css/payxpert.css rename to views/css/payxpert.css index aa3867e..2552ed7 100644 --- a/modules/payxpert/css/payxpert.css +++ b/views/css/payxpert.css @@ -13,5 +13,5 @@ p.payment_module a.creditcard::after{ } p.payment_module a.creditcard { - background: url(../images/payment-types/creditcard_icon.png) 15px 12px no-repeat #fbfbfb; + background: url(../img/payment-types/creditcard_icon.png) 15px 12px no-repeat #fbfbfb; } \ No newline at end of file diff --git a/modules/payxpert/images/baian.png b/views/img/baian.png similarity index 100% rename from modules/payxpert/images/baian.png rename to views/img/baian.png diff --git a/modules/payxpert/images/fullpass.png b/views/img/fullpass.png similarity index 100% rename from modules/payxpert/images/fullpass.png rename to views/img/fullpass.png diff --git a/modules/payxpert/index.php b/views/img/index.php similarity index 100% rename from modules/payxpert/index.php rename to views/img/index.php diff --git a/modules/payxpert/images/logo-baian.gif b/views/img/logo-baian.gif similarity index 100% rename from modules/payxpert/images/logo-baian.gif rename to views/img/logo-baian.gif diff --git a/modules/payxpert/images/logo-baian.png b/views/img/logo-baian.png similarity index 100% rename from modules/payxpert/images/logo-baian.png rename to views/img/logo-baian.png diff --git a/modules/payxpert/images/logo-fullpass.gif b/views/img/logo-fullpass.gif similarity index 100% rename from modules/payxpert/images/logo-fullpass.gif rename to views/img/logo-fullpass.gif diff --git a/modules/payxpert/images/logo-fullpass.png b/views/img/logo-fullpass.png similarity index 100% rename from modules/payxpert/images/logo-fullpass.png rename to views/img/logo-fullpass.png diff --git a/modules/payxpert/images/logo-payxpert.gif b/views/img/logo-payxpert.gif similarity index 100% rename from modules/payxpert/images/logo-payxpert.gif rename to views/img/logo-payxpert.gif diff --git a/modules/payxpert/images/logo-payxpert.png b/views/img/logo-payxpert.png similarity index 100% rename from modules/payxpert/images/logo-payxpert.png rename to views/img/logo-payxpert.png diff --git a/modules/payxpert/images/logo-payzone.gif b/views/img/logo-payzone.gif similarity index 100% rename from modules/payxpert/images/logo-payzone.gif rename to views/img/logo-payzone.gif diff --git a/modules/payxpert/images/logo-payzone.png b/views/img/logo-payzone.png similarity index 100% rename from modules/payxpert/images/logo-payzone.png rename to views/img/logo-payzone.png diff --git a/modules/payxpert/images/payment-types/creditcard.png b/views/img/payment-types/creditcard.png similarity index 100% rename from modules/payxpert/images/payment-types/creditcard.png rename to views/img/payment-types/creditcard.png diff --git a/modules/payxpert/images/payment-types/creditcard_icon.png b/views/img/payment-types/creditcard_icon.png similarity index 100% rename from modules/payxpert/images/payment-types/creditcard_icon.png rename to views/img/payment-types/creditcard_icon.png diff --git a/modules/payxpert/images/payment-types/ideal.png b/views/img/payment-types/ideal.png similarity index 100% rename from modules/payxpert/images/payment-types/ideal.png rename to views/img/payment-types/ideal.png diff --git a/modules/payxpert/views/templates/admin/index.php b/views/img/payment-types/index.php similarity index 100% rename from modules/payxpert/views/templates/admin/index.php rename to views/img/payment-types/index.php diff --git a/modules/payxpert/images/payment-types/przelewy24.png b/views/img/payment-types/przelewy24.png similarity index 100% rename from modules/payxpert/images/payment-types/przelewy24.png rename to views/img/payment-types/przelewy24.png diff --git a/modules/payxpert/images/payment-types/sofort.png b/views/img/payment-types/sofort.png similarity index 100% rename from modules/payxpert/images/payment-types/sofort.png rename to views/img/payment-types/sofort.png diff --git a/modules/payxpert/images/payxpert.png b/views/img/payxpert.png similarity index 100% rename from modules/payxpert/images/payxpert.png rename to views/img/payxpert.png diff --git a/modules/payxpert/images/payzone.png b/views/img/payzone.png similarity index 100% rename from modules/payxpert/images/payzone.png rename to views/img/payzone.png diff --git a/modules/payxpert/views/index.php b/views/index.php similarity index 100% rename from modules/payxpert/views/index.php rename to views/index.php diff --git a/modules/payxpert/views/templates/admin/config.tpl b/views/templates/admin/config.tpl similarity index 94% rename from modules/payxpert/views/templates/admin/config.tpl rename to views/templates/admin/config.tpl index f3d99ea..ff99a23 100644 --- a/modules/payxpert/views/templates/admin/config.tpl +++ b/views/templates/admin/config.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2017 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,6 @@ * limitations under the License. * * @author Regis Vidal -* *}
@@ -23,7 +22,7 @@
 
- +

{l s='The identifier of your Originator' mod='payxpert'}

 
@@ -37,7 +36,7 @@
- +

{l s='Leave this field empty unless you have been given an URL"' mod='payxpert'}

 
@@ -52,7 +51,7 @@
- +

{l s='Recipient email address for merchant notifications' mod='payxpert'}

 
diff --git a/views/templates/admin/index.php b/views/templates/admin/index.php new file mode 100644 index 0000000..a230e5a --- /dev/null +++ b/views/templates/admin/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; \ No newline at end of file diff --git a/views/templates/admin/infos.tpl b/views/templates/admin/infos.tpl new file mode 100644 index 0000000..b464461 --- /dev/null +++ b/views/templates/admin/infos.tpl @@ -0,0 +1,26 @@ +{* +* Copyright 2013-2018 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 Alexandre Chatiron +*} +{if $smarty.const._PS_VERSION_ >= 1.6} +
+{/if} + +

{l s='This module allows you to accept secure payments.' mod='payxpert'}

+





+{if $smarty.const._PS_VERSION_ >= 1.6} +
+{/if} \ No newline at end of file diff --git a/modules/payxpert/views/templates/front/index.php b/views/templates/front/index.php similarity index 100% rename from modules/payxpert/views/templates/front/index.php rename to views/templates/front/index.php diff --git a/modules/payxpert/views/templates/front/payment_error.tpl b/views/templates/front/payment_error.tpl similarity index 93% rename from modules/payxpert/views/templates/front/payment_error.tpl rename to views/templates/front/payment_error.tpl index ce2df2e..9794379 100644 --- a/modules/payxpert/views/templates/front/payment_error.tpl +++ b/views/templates/front/payment_error.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2017 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -11,7 +11,7 @@ * 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. +* limitations under the License. * * @author Regis Vidal * @@ -37,7 +37,7 @@

Error

{/if} -

{$errorMessage}

+

{$errorMessage|escape:'htmlall':'UTF-8'}

{if $smarty.const._PS_VERSION_ >= 1.6}

diff --git a/modules/payxpert/views/templates/front/payment_error17.tpl b/views/templates/front/payment_error17.tpl similarity index 93% rename from modules/payxpert/views/templates/front/payment_error17.tpl rename to views/templates/front/payment_error17.tpl index c786fa1..29a0638 100644 --- a/modules/payxpert/views/templates/front/payment_error17.tpl +++ b/views/templates/front/payment_error17.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2017 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@

Error

-

{$errorMessage}

+

{$errorMessage|escape:'htmlall':'UTF-8'}

diff --git a/modules/payxpert/views/templates/front/payment_execution.tpl b/views/templates/front/payment_execution.tpl similarity index 91% rename from modules/payxpert/views/templates/front/payment_execution.tpl rename to views/templates/front/payment_execution.tpl index 75f85bd..d664aae 100644 --- a/modules/payxpert/views/templates/front/payment_execution.tpl +++ b/views/templates/front/payment_execution.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2017 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. * * @author Regis Vidal -* @copyright 2013-2017 PayXpert +* @copyright 2013-2018 PayXpert * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 (the "License") *} @@ -41,14 +41,14 @@

{/if} - {l s='Credit Card' mod='payxpert'} + {l s='Credit Card' mod='payxpert'} {l s='You have chosen to pay by Credit Card.' mod='payxpert'} {l s='Here is a short summary of your order:' mod='payxpert'} {if $smarty.const._PS_VERSION_ >= 1.6}{/if}

- {l s='The total amount of your order is' mod='payxpert'} - {Tools::displayPrice($total, $currency, false)} + {Tools::displayPrice($total, $currency, false)|escape:'htmlall':'UTF-8'} {if $use_taxes == 1} {l s='(tax incl.)' mod='payxpert'} {/if} diff --git a/modules/payxpert/views/templates/front/payment_execution_bank_transfer.tpl b/views/templates/front/payment_execution_bank_transfer.tpl similarity index 90% rename from modules/payxpert/views/templates/front/payment_execution_bank_transfer.tpl rename to views/templates/front/payment_execution_bank_transfer.tpl index c06f378..e304360 100644 --- a/modules/payxpert/views/templates/front/payment_execution_bank_transfer.tpl +++ b/views/templates/front/payment_execution_bank_transfer.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2017 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. * * @author Regis Vidal -* @copyright 2013-2017 PayXpert +* @copyright 2013-2018 PayXpert * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 (the "License") *} @@ -31,14 +31,14 @@

{assign var='current_step' value='payment'}
- {l s='Bank Transfer' mod='payxpert'} + {l s='Bank Transfer' mod='payxpert'}
{l s='You have chosen to pay by Bank Transfer.' mod='payxpert'}

- {capture name='amount'}{Tools::displayPrice($total, $cust_currency)}{/capture} + {capture name='amount'}{Tools::displayPrice($total, $cust_currency)|escape:'htmlall':'UTF-8'}{/capture} {assign var='order_amount' value=$smarty.capture.amount} {l s='The total amount of your order is %s.' sprintf=[$order_amount|escape:'html':'UTF-8'] mod='payxpert'}
diff --git a/modules/payxpert/views/templates/front/payment_execution_credit_card.tpl b/views/templates/front/payment_execution_credit_card.tpl similarity index 90% rename from modules/payxpert/views/templates/front/payment_execution_credit_card.tpl rename to views/templates/front/payment_execution_credit_card.tpl index 794eedb..723dbca 100644 --- a/modules/payxpert/views/templates/front/payment_execution_credit_card.tpl +++ b/views/templates/front/payment_execution_credit_card.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2017 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. * * @author Regis Vidal -* @copyright 2013-2017 PayXpert +* @copyright 2013-2018 PayXpert * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 (the "License") *} @@ -31,14 +31,14 @@

{assign var='current_step' value='payment'}
- {l s='Credit Card' mod='payxpert'} + {l s='Credit Card' mod='payxpert'}
{l s='You have chosen to pay by Credit Card.' mod='payxpert'}

- {capture name='amount'}{Tools::displayPrice($total, $cust_currency)}{/capture} + {capture name='amount'}{Tools::displayPrice($total, $cust_currency)|escape:'htmlall':'UTF-8'}{/capture} {assign var='order_amount' value=$smarty.capture.amount} {l s='The total amount of your order is %s.' sprintf=[$order_amount|escape:'html':'UTF-8'] mod='payxpert'}
diff --git a/views/templates/front/payment_infos_bank_transfer_ideal.tpl b/views/templates/front/payment_infos_bank_transfer_ideal.tpl new file mode 100644 index 0000000..90f02e5 --- /dev/null +++ b/views/templates/front/payment_infos_bank_transfer_ideal.tpl @@ -0,0 +1,21 @@ +{* +* Copyright 2013-2018 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 +* +*} +

+

iDeal{l s='Use your bank account information with the iDeal provider to pay your order' mod='payxpert'}

+
\ No newline at end of file diff --git a/views/templates/front/payment_infos_bank_transfer_przelewy24.tpl b/views/templates/front/payment_infos_bank_transfer_przelewy24.tpl new file mode 100644 index 0000000..7219ad6 --- /dev/null +++ b/views/templates/front/payment_infos_bank_transfer_przelewy24.tpl @@ -0,0 +1,21 @@ +{* +* Copyright 2013-2018 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 +* +*} +
+

Przelewy24{l s='Use your bank account information with the Przelewy24 provider to pay your order' mod='payxpert'}

+
\ No newline at end of file diff --git a/views/templates/front/payment_infos_bank_transfer_sofort.tpl b/views/templates/front/payment_infos_bank_transfer_sofort.tpl new file mode 100644 index 0000000..8b661cc --- /dev/null +++ b/views/templates/front/payment_infos_bank_transfer_sofort.tpl @@ -0,0 +1,21 @@ +{* +* Copyright 2013-2018 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 +* +*} +
+

Sofort{l s='Use your bank account information with the Sofort provider to pay your order' mod='payxpert'}

+
\ No newline at end of file diff --git a/views/templates/front/payment_infos_credit_card.tpl b/views/templates/front/payment_infos_credit_card.tpl new file mode 100644 index 0000000..b37a658 --- /dev/null +++ b/views/templates/front/payment_infos_credit_card.tpl @@ -0,0 +1,21 @@ +{* +* Copyright 2013-2018 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 +* +*} +
+

Credit Card{l s='Use your credit card information in a secured form to pay your order' mod='payxpert'}

+
\ No newline at end of file diff --git a/modules/payxpert/views/templates/hook/iframe.tpl b/views/templates/hook/iframe.tpl similarity index 85% rename from modules/payxpert/views/templates/hook/iframe.tpl rename to views/templates/hook/iframe.tpl index a27fbf7..2cec57a 100644 --- a/modules/payxpert/views/templates/hook/iframe.tpl +++ b/views/templates/hook/iframe.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2017 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,6 @@ {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/index.php b/views/templates/hook/index.php similarity index 100% rename from modules/payxpert/views/templates/hook/index.php rename to views/templates/hook/index.php diff --git a/modules/payxpert/views/templates/hook/orderconfirmation.tpl b/views/templates/hook/orderconfirmation.tpl similarity index 82% rename from modules/payxpert/views/templates/hook/orderconfirmation.tpl rename to views/templates/hook/orderconfirmation.tpl index e6ae09b..a7e21b9 100644 --- a/modules/payxpert/views/templates/hook/orderconfirmation.tpl +++ b/views/templates/hook/orderconfirmation.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2017 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,24 @@ * limitations under the License. * * @author Regis Vidal -* @copyright 2013-2017 PayXpert +* @copyright 2013-2018 PayXpert * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 (the "License") *} {if $status == 'ok'}

{l s='Your order has been completed.' mod='payxpert'}

{l s='It will be shipped as soon as possible.' mod='payxpert'} -

{l s='For any questions or for further information, please contact our' mod='payxpert'} {l s='customer support' mod='payxpert'}. +

{l s='For any questions or for further information, please contact our' mod='payxpert'} {l s='customer support' mod='payxpert'}.

{else} {if $status == 'pending'}

{l s='Your order is still pending.' mod='payxpert'}

{l s='Your order will be shipped as soon as we receive your payment.' mod='payxpert'} -

{l s='For any questions or for further information, please contact our' mod='payxpert'} {l s='customer support' mod='payxpert'}. +

{l s='For any questions or for further information, please contact our' mod='payxpert'} {l s='customer support' mod='payxpert'}.

{else}

{l s='We noticed a problem with your order. If you think this is an error, you can contact our' mod='payxpert'} - {l s='customer support' mod='payxpert'}. + {l s='customer support' mod='payxpert'}.

{/if} {/if} \ No newline at end of file diff --git a/modules/payxpert/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl similarity index 82% rename from modules/payxpert/views/templates/hook/payment.tpl rename to views/templates/hook/payment.tpl index 1d5e112..a85c6ab 100644 --- a/modules/payxpert/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2014 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. * * @author Regis Vidal -* @copyright 2013-2017 PayXpert +* @copyright 2013-2018 PayXpert * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 (the "License") *} @@ -25,7 +25,7 @@

{if $smarty.const._PS_VERSION_ < 1.6} - {l s='Pay by Credit Card' mod='payxpert'} + {l s='Pay by Credit Card' mod='payxpert'} {/if} {l s='Pay by Credit Card' mod='payxpert'} diff --git a/modules/payxpert/views/templates/hook/return.tpl b/views/templates/hook/return.tpl similarity index 82% rename from modules/payxpert/views/templates/hook/return.tpl rename to views/templates/hook/return.tpl index 5c1f907..fdfd4c5 100644 --- a/modules/payxpert/views/templates/hook/return.tpl +++ b/views/templates/hook/return.tpl @@ -1,5 +1,5 @@ {* -* Copyright 2013-2017 PayXpert +* Copyright 2013-2018 PayXpert * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,4 +17,4 @@ * *} - \ No newline at end of file + \ No newline at end of file diff --git a/views/templates/index.php b/views/templates/index.php new file mode 100644 index 0000000..54b3024 --- /dev/null +++ b/views/templates/index.php @@ -0,0 +1,36 @@ + +* @copyright 2007-2013 PrestaShop SA + +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../../'); +exit; \ No newline at end of file