From 1e22c6e7d2507ca56ead625364d35af29c12e2e4 Mon Sep 17 00:00:00 2001 From: Michael Dekker Date: Fri, 16 Feb 2018 02:20:52 +0100 Subject: [PATCH] Initial commit --- .gitignore | 2 +- README.md | 6 +- build.sh | 2 +- composer.json | 2 +- controllers/front/payment.php | 91 --------- controllers/front/validation.php | 177 +++++++++--------- logo.gif | Bin 136 -> 1393 bytes logo.png | Bin 1553 -> 3500 bytes omnipaymollie.php => omnipayworldpay.php | 121 +++--------- scoper.inc.php | 10 +- views/css/list.css | 30 --- .../admin/_configure/helpers/form/form.tpl | 10 +- views/templates/hook/confirmation.tpl | 32 ++-- views/templates/hook/payment.tpl | 55 ++++-- 14 files changed, 188 insertions(+), 350 deletions(-) delete mode 100644 controllers/front/payment.php rename omnipaymollie.php => omnipayworldpay.php (74%) delete mode 100644 views/css/list.css diff --git a/.gitignore b/.gitignore index 269a6bd..990d42a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ vendor/ composer.lock -*omnipaymollie*.zip +*OmnipayWorldpay*.zip diff --git a/README.md b/README.md index 48a2d54..12b90b4 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# Mollie Omnipay module +# Worldpay Omnipay module -This module integrates Mollie in thirty bees with the help of the Omnipay library. +This module integrates Worldpay in thirty bees with the help of the Omnipay library. ## Building the module In order to prevent library conflicts in thirty bees this module's dependencies need to be "scoped". For this we use PHP Scoper (https://github.com/humbug/php-scoper) in the build script. -By default everything in the vendor folder is now scoped to `ThirtyBeesMollie`. +By default everything in the vendor folder is now scoped to `ThirtyBeesWorldpay`. You can build the module by running the build script: ```shell diff --git a/build.sh b/build.sh index 8f31ce2..76c4988 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ rm build/ -rf # Composer install and scoping composer install --no-dev --prefer-dist mv vendor/ pre-scoper/ -php ./php-scoper.phar add-prefix -p ThirtyBeesMollie -n +php ./php-scoper.phar add-prefix -p ThirtyBeesWorldpay -n # Cleanup mv build/pre-scoper/ vendor/ diff --git a/composer.json b/composer.json index 2e80fa5..cb4454f 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "require": { - "omnipay/mollie": "^3.2" + "omnipay/worldpay": "~2.0" }, "autoload": { "classmap": [ diff --git a/controllers/front/payment.php b/controllers/front/payment.php deleted file mode 100644 index 2979a5d..0000000 --- a/controllers/front/payment.php +++ /dev/null @@ -1,91 +0,0 @@ - - * @copyright 2017-2018 thirty bees - * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) - */ - -use ThirtyBeesMollie\Omnipay\Omnipay; - -if (!defined('_TB_VERSION_')) { - exit; -} - -/** - * Class OmnipayMolliePaymentModuleFrontController - */ -class OmnipayMolliePaymentModuleFrontController extends ModuleFrontController -{ - /** @var OmnipayMollie $module */ - public $module; - - /** - * @throws PrestaShopDatabaseException - * @throws PrestaShopException - */ - public function initContent() - { - if (!$this->module->active - || strtoupper($this->context->currency->iso_code) !== 'EUR' - ) { - Tools::redirect('index.php?controller=order&step=3'); - } - $cart = $this->context->cart; - if (!$cart->id_customer || !$cart->id_address_delivery || !$cart->id_address_invoice || !$this->module->active) { - Tools::redirect('index.php?controller=order&step=3'); - } - - $customer = new Customer($cart->id_customer); - if (!Validate::isLoadedObject($customer)) { - Tools::redirect('index.php?controller=order&step=3'); - } - - parent::initContent(); - - /** @var \ThirtyBeesMollie\Omnipay\Mollie\Gateway $gateway */ - $gateway = Omnipay::create(OmnipayMollie::GATEWAY_NAME); - foreach (array_keys($gateway->getDefaultParameters()) as $key) { - $gateway->{'set'.ucfirst($key)}(Configuration::get(OmnipayMollie::CREDENTIAL.$key)); - } - /** @var \ThirtyBeesMollie\Omnipay\Mollie\Message\PurchaseResponse $response */ - $response = $gateway->purchase( - [ - 'amount' => number_format($this->context->cart->getOrderTotal(), 2), - 'currency' => strtoupper($this->context->currency->iso_code), - 'description' => $this->context->cart->id, - 'returnUrl' => $this->context->link->getModuleLink($this->module->name, 'validation', [], true), - 'cancelUrl' => $this->context->link->getPageLink('order', true, null, ['step' => 3]), - 'method' => Tools::getValue('method') ?: null - ] - )->send(); - - if ($response->isRedirect()) { - $cookie = new Cookie($this->module->name); - $cookie->amount = (float) $cart->getOrderTotal(); - $cookie->transaction_id = $response->getTransactionId(); - $cookie->transaction_reference = $response->getTransactionReference(); - $cookie->write(); - - $response->redirect(); - exit; - } else { - if (_PS_MODE_DEV_) { - $this->context->controller->errors[] = $response->getMessage(); - } else { - $this->context->controller->errors[] = $this->l('An unknown error occurred.'); - } - } - } -} diff --git a/controllers/front/validation.php b/controllers/front/validation.php index d34714f..06dfe7b 100644 --- a/controllers/front/validation.php +++ b/controllers/front/validation.php @@ -12,129 +12,124 @@ * obtain it through the world-wide-web, please send an email * to license@thirtybees.com so we can send you a copy immediately. * - * @author thirty bees - * @copyright 2017-2018 thirty bees - * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * @author thirty bees + * @copyright 2017-2018 thirty bees + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ -use ThirtyBeesMollie\Omnipay\Omnipay; +use ThirtyBeesWorldpay\Omnipay\Omnipay; if (!defined('_TB_VERSION_')) { exit; } /** - * Class OmnipayMollieValidationModuleFrontController + * Class OmnipayWorldpayValidationModuleFrontController */ -class OmnipayMollieValidationModuleFrontController extends ModuleFrontController +class OmnipayWorldpayValidationModuleFrontController extends ModuleFrontController { - /** @var bool $display_column_left */ - public $display_column_left = false; - /** @var bool $display_column_right */ - public $display_column_right = false; - /** @var OmnipayMollie $module */ + /** @var OmnipayWorldpay $module */ public $module; /** - * OmnipayMollieValidationModuleFrontController constructor. - * + * @throws PrestaShopDatabaseException * @throws PrestaShopException */ - public function __construct() - { - parent::__construct(); - - $this->ssl = Tools::usingSecureMode(); - } - - /** - * Post process - * - * @return void - * - * @throws PrestaShopException - */ - public function postProcess() + public function initContent() { + if (!$this->module->active || strtoupper($this->context->currency->iso_code) !== 'EUR') { + Tools::redirect($this->context->link->getPageLink('order', null, null, ['step' => 3])); + } $cart = $this->context->cart; - $cookie = new Cookie($this->module->name); - if ($cart->id_customer == 0 - || $cart->id_address_delivery == 0 - || $cart->id_address_invoice == 0 - || !$this->module->active - || strtoupper($this->context->currency->iso_code) !== 'EUR' - ) { - Tools::redirect('index.php?controller=order&step=3'); + if (!$cart->id_customer || !$cart->id_address_delivery || !$cart->id_address_invoice || !$this->module->active) { + Tools::redirect($this->context->link->getPageLink('order', null, null, ['step' => 3])); } $customer = new Customer($cart->id_customer); if (!Validate::isLoadedObject($customer)) { - Tools::redirect('index.php?controller=order&step=3'); + Tools::redirect($this->context->link->getPageLink('order', null, null, ['step' => 3])); } - $orderProcess = Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order'; - $this->context->smarty->assign([ - 'orderLink' => $this->context->link->getPageLink($orderProcess, true), - ]); - - if ((float) $cart->getOrderTotal() !== (float) $cookie->amount) { - Tools::redirect('index.php?controller=order&step=3'); - } + parent::initContent(); - /** @var Omnipay $gateway */ - $gateway = Omnipay::create(OmnipayMollie::GATEWAY_NAME); + /** @var \ThirtyBeesWorldpay\Omnipay\Worldpay\Gateway $gateway */ + $gateway = Omnipay::create(OmnipayWorldpay::GATEWAY_NAME); foreach (array_keys($gateway->getDefaultParameters()) as $key) { - $gateway->{'set'.ucfirst($key)}(Configuration::get(OmnipayMollie::CREDENTIAL.$key)); + $gateway->{'set'.ucfirst($key)}(Configuration::get(OmnipayWorldpay::CREDENTIAL.$key)); } - $params = Tools::getAllValues(); - $params['transactionReference'] = $cookie->transaction_reference; - try { - /** @var \ThirtyBeesMollie\Omnipay\Mollie\Message\CompletePurchaseResponse $response */ - $response = $gateway->completePurchase($params)->send(); - if (!$response->isSuccessful()) { - $error = $this->module->l('An error occurred. Please contact us for more information.', 'validation'); - $this->errors[] = $error; - $this->setTemplate('error.tpl'); - - return; - } - } catch (Exception $e) { - if (!empty(_PS_MODE_DEV_)) { - $error = sprintf($this->module->l('An error occurred: %s', 'validation'), $e->getMessage()); - } else { - $error = $this->module->l('An unknown error occurred. Please contact us for more information.', 'validation'); - } - $this->errors[] = $error; - $this->setTemplate('error.tpl'); + $billingAddress = new Address($cart->id_address_invoice); + $shippingAddress = new Address($cart->id_address_delivery); + + $card = new \ThirtyBeesWorldpay\Omnipay\Common\CreditCard([ + 'name' => "{$customer->firstname} {$customer->lastname}", + 'email' => $customer->email, + 'billingAddress1' => $billingAddress->address1, + 'billingAddress2' => $billingAddress->address2, + 'billingPostcode' => $billingAddress->postcode, + 'billingCity' => $billingAddress->city, + 'billingState' => $billingAddress->id_state ? State::getNameById($billingAddress->id_state) : '', + 'billingCountry' => Country::getIsoById($billingAddress->id_country), + 'billingPhone' => $billingAddress->phone ?: $billingAddress->phone_mobile, + 'shippingAddress1' => $shippingAddress->address1, + 'shippingAddress2' => $shippingAddress->address2, + 'shippingPostcode' => $shippingAddress->postcode, + 'shippingCity' => $shippingAddress->city, + 'shippingState' => $shippingAddress->id_state ? State::getNameById($shippingAddress->id_state) : '', + 'shippingCountry' => Country::getIsoById($shippingAddress->id_country), + 'shippingPhone' => $shippingAddress->phone ?: $shippingAddress->phone_mobile, + ]); - return; - } + /** @var \ThirtyBeesWorldpay\Omnipay\Worldpay\Message\PurchaseResponse $response */ + $response = $gateway->purchase( + [ + 'token' => Tools::getValue('token'), + 'amount' => number_format($this->context->cart->getOrderTotal(), 2), + 'currency' => strtoupper($this->context->currency->iso_code), + 'description' => $this->context->cart->id, + 'transactionId' => $this->context->cart->id, + 'name' => 'test', + 'card' => $card, + + ] + )->send(); + + if ($response->isSuccessful()) { + $this->module->validateOrder( + (int) $cart->id, + Configuration::get('PS_OS_PAYMENT'), + (float) $cart->getOrderTotal(), + $this->module->displayName, + null, + [], + (int) $cart->id_currency, + false, + $cart->secure_key + ); - $this->module->validateOrder( - (int) $cart->id, - Configuration::get('PS_OS_PAYMENT'), - (float) $cart->getOrderTotal(), - $this->module->displayName, - null, - [], - (int) $cart->id_currency, - false, - $cart->secure_key - ); - - /** - * If the order has been validated we try to retrieve it - */ - $idOrder = Order::getOrderByCartId((int) $cart->id); - - if ($idOrder) { /** - * The order has been placed so we redirect the customer on the confirmation page. + * If the order has been validated we try to retrieve it */ - Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id - .'&id_module='.$this->module->id.'&id_order='.$idOrder.'&key='.$customer->secure_key); + $idOrder = Order::getOrderByCartId((int) $cart->id); + + if ($idOrder) { + /** + * The order has been placed so we redirect the customer on the confirmation page. + */ + Tools::redirect('index.php?controller=order-confirmation&id_cart='.$cart->id + .'&id_module='.$this->module->id.'&id_order='.$idOrder.'&key='.$customer->secure_key); + } } else { + if (_PS_MODE_DEV_) { + $this->context->controller->errors[] = $response->getMessage(); + } else { + $this->context->controller->errors[] = $this->module->l('An unknown error occurred.', 'payment'); + } + + $this->context->smarty->assign([ + 'orderLink' => $this->context->link->getPageLink('order', null, null, ['step' => 3]), + ]); + /** * An error occurred and is shown on a new page. */ diff --git a/logo.gif b/logo.gif index 9eb0ea990895be0261a221e9de48337c2ee35311..921e5917b759d7f718dcfac0dafec7f50ddadb9a 100644 GIT binary patch literal 1393 zcmb``iCdBf0LSsyV};J`VNaN5XySn;c;JazDdvF(iKQKiiQ2IalghcQGz5=GYHDU% zJ(fBj!>lHYOgHC+3T5^9RFAW1+f2*Ws)zUBeSsHf_&@CTe4g)r@JmWgWJcz@1Ma}m zYXEd5Y1|w^HxlUPs9CpKH8$zHBq0q)KXk$3EDFWKWge{F>!ZA#U6$!HhzmX2-&87L*(ZrNqI@Hp6N0Fed@#BqHfaNIDzlrXbv8#L|ou zcxx)WEe+Y024`}RWm}M}ba;C@VzDCw*_nat+KOavLvk_^UKWzO9m(B+k#Tuko;{{#g1+3{itf^jS(cGYGZq!}A zsQcccNq6Ov?&@V-%MZG1SM?Uxuj<-b^ldG=_Urog>$;9MeP_E~)}im})OXADw{Ply zx}}%jHYntV-n)kT3d8+-hCYR%zt_-z-|%an;kRE5g9G^Bf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ff --git a/omnipaymollie.php b/omnipayworldpay.php similarity index 74% rename from omnipaymollie.php rename to omnipayworldpay.php index fb5a03f..d16c64c 100644 --- a/omnipaymollie.php +++ b/omnipayworldpay.php @@ -18,7 +18,7 @@ * */ -use ThirtyBeesMollie\Omnipay\Omnipay; +use ThirtyBeesWorldpay\Omnipay\Omnipay; require_once __DIR__.'/vendor/autoload.php'; @@ -27,13 +27,13 @@ } /** - * Class OmnipayMollie + * Class OmnipayWorldpay */ -class OmnipayMollie extends PaymentModule +class OmnipayWorldpay extends PaymentModule { - const CREDENTIAL = 'OMNIPAY_MOLLIE_CRED'; + const CREDENTIAL = 'OMNIPAY_WORLDPAY_CRED'; const PAYMENT_METHODS = 'OMNIPAY_PAYMENT_METHODS'; - const GATEWAY_NAME = 'Mollie'; + const GATEWAY_NAME = 'WorldPay_Json'; /** @var string $moduleUrl */ public $moduleUrl; @@ -44,13 +44,13 @@ class OmnipayMollie extends PaymentModule ]; /** - * OmnipayMollie constructor. + * OmnipayWorldpay constructor. * * @throws PrestaShopException */ public function __construct() { - $this->name = 'omnipaymollie'; + $this->name = 'omnipayworldpay'; $this->tab = 'payments_gateways'; $this->version = '1.0.0'; $this->author = 'thirty bees'; @@ -74,8 +74,8 @@ public function __construct() ]); } - $this->displayName = $this->l('Mollie'); - $this->description = $this->l('Mollie payment gateway'); + $this->displayName = $this->l('Worldpay'); + $this->description = $this->l('Worldpay payment gateway'); } /** @@ -108,11 +108,11 @@ public function install() */ public function getContent() { - $this->postProcess(); - - $this->refreshPaymentMethods(); + $this->context->smarty->assign([ + 'moduleUrl' => $this->moduleUrl, + ]); - $this->context->controller->addCSS($this->_path.'views/css/list.css', 'all'); + $this->postProcess(); return $this->renderMainForm(); } @@ -126,14 +126,16 @@ public function getContent() */ public function hookDisplayPayment() { - if (!$this->active - || strtoupper($this->context->currency->iso_code) !== 'EUR' - ) { + if (!$this->active || strtoupper($this->context->currency->iso_code) !== 'EUR') { return ''; } $this->context->smarty->assign([ 'payment_methods' => $this->getPaymentMethods(), + 'credit_card' => array_sum(array_map(function ($key) { + return Configuration::get(static::CREDENTIAL.$key) ? 1 : 0; + }, array_keys(Omnipay::create(static::GATEWAY_NAME)->getDefaultParameters()))) === 3, + 'clientKey' => Configuration::get(static::CREDENTIAL.'clientKey'), ]); return $this->display(__FILE__, 'payment.tpl'); @@ -162,7 +164,7 @@ public function hookPaymentReturn($params) $currency = new Currency($order->id_currency); if (isset($order->reference) && $order->reference) { - $totalToPay = (float) $order->getTotalPaid($currency); + $totalToPay = $order->total_paid_tax_incl; $reference = $order->reference; } else { $totalToPay = $order->total_paid_tax_incl; @@ -213,12 +215,12 @@ protected function renderMainForm() 'fields_value' => $this->getConfigFieldsValues(), ]; - return $helper->generateForm( - array_merge( - [$this->getApiForm()], - [$this->getPaymentMethodsForm()] - ) - ); + $forms = [$this->getApiForm()]; + if ($this->getPaymentMethods()) { + $forms = array_merge($forms, [$this->getPaymentMethodsForm()]); + } + + return $helper->generateForm($forms); } /** @@ -233,26 +235,6 @@ protected function getMainForm() 'icon' => 'icon-puzzle', ], 'input' => [ -// [ -// 'type' => 'select', -// 'label' => $this->l('Module'), -// 'desc' => $this->l('Choose a module'), -// 'name' => static::MODULE, -// 'required' => true, -// 'class' => 'fixed-width-xxl', -// 'options' => [ -// 'query' => $modules, -// 'id' => 'name', -// 'name' => 'name', -// ], -// ], -// [ -// 'type' => 'text', -// 'label' => $this->l('Force version'), -// 'name' => static::VERSION, -// 'class' => 'fixed-width-xxl', -// 'placeholder' => '1.0.0', -// ], ], 'submit' => [ 'title' => $this->l('Save'), @@ -361,7 +343,7 @@ protected function getConfigFieldsValues() ]; $dynamicValues = []; - foreach (Omnipay::create('Mollie')->getDefaultParameters() as $key => $default) { + foreach (Omnipay::create(static::GATEWAY_NAME)->getDefaultParameters() as $key => $default) { $dynamicValues[static::CREDENTIAL.$key] = Configuration::get(static::CREDENTIAL.$key); } @@ -389,57 +371,10 @@ protected function postProcess() } /** - * @return array|mixed|string + * @return array|false */ protected function getPaymentMethods() { - try { - $paymentMethods = Configuration::get(static::PAYMENT_METHODS); - } catch (PrestaShopException $e) { - return []; - } - - if (!$paymentMethods) { - return []; - } - - $paymentMethods = json_decode($paymentMethods, true); - if (!is_array($paymentMethods)) { - return []; - } - - return $paymentMethods; - } - - /** - * Refresh payment methods - * - * @throws PrestaShopException - */ - protected function refreshPaymentMethods() - { - $gateway = Omnipay::create(static::GATEWAY_NAME); - foreach (array_keys($gateway->getDefaultParameters()) as $key) { - $gateway->{'set'.ucfirst($key)}(Configuration::get(static::CREDENTIAL.$key)); - } - - try { - $paymentMethods = []; - foreach ($gateway->fetchPaymentMethods()->send()->getPaymentMethods() as $paymentMethod) { - /** @var \ThirtyBeesMollie\Omnipay\Common\PaymentMethod $paymentMethod */ - $newMethod = [ - 'id' => $paymentMethod->getId(), - 'name' => [], - ]; - foreach (Language::getLanguages() as $language) { - $newMethod['name'][(int) $language['id_lang']] = $paymentMethod->getName(); - } - $paymentMethods[$newMethod['id']] = $newMethod; - } - - Configuration::updateValue(static::PAYMENT_METHODS, json_encode($paymentMethods)); - } catch (Exception $e) { - return; - } + return false; } } diff --git a/scoper.inc.php b/scoper.inc.php index a5efc57..ee4887c 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -40,11 +40,15 @@ function ($filePath, $prefix, $content) { // Change the content here. vendor = pre-scoper at this time if (in_array($filePath, [ __DIR__.'/pre-scoper/omnipay/common/src/Omnipay/Common/Helper.php', - __DIR__.'/pre-scoper/omnipay/mollie/src/Gateway.php', + __DIR__.'/pre-scoper/omnipay/worldpay/src/Gateway.php', + __DIR__.'/pre-scoper/omnipay/worldpay/src/JsonGateway.php', + __DIR__.'/pre-scoper/omnipay/worldpay/src/Message/JsonAbstractRequest.php', + __DIR__.'/pre-scoper/omnipay/worldpay/src/Message/JsonAuthorizeRequest.php', + __DIR__.'/pre-scoper/omnipay/worldpay/src/Message/JsonPurchaseRequest.php', ])) { $content = preg_replace( preg_quote("'\\\\Omnipay\\\\'"), - "\\\\\\\\ThirtyBeesMollie\\\\\\\\Omnipay\\\\\\\\", + "\\\\\\\\ThirtyBeesWorldpay\\\\\\\\Omnipay\\\\\\\\", $content ); @@ -57,7 +61,7 @@ function ($filePath, $prefix, $content) { ])) { $content = preg_replace( preg_quote("'Guzzle\\\\'"), - "ThirtyBeesMollie\\\\\\\\Guzzle\\\\\\\\", + "ThirtyBeesWorldpay\\\\\\\\Guzzle\\\\\\\\", $content ); diff --git a/views/css/list.css b/views/css/list.css deleted file mode 100644 index 2c2457b..0000000 --- a/views/css/list.css +++ /dev/null @@ -1,30 +0,0 @@ -.bootstrap .filter_list .filter_list_item { - display: table; - width: 100%; - padding: 5px 0; - margin-bottom: 4px; - background-color: white; - -webkit-box-shadow: rgba(0, 0, 0, 0.3) 0 0 3px, rgba(0, 0, 0, 0.1) 0 -2px 0 inset; - box-shadow: rgba(0, 0, 0, 0.3) 0 0 3px, rgba(0, 0, 0, 0.1) 0 -2px 0 inset; - -webkit-border-radius: 3px; - -moz-border-radius: 3px; - -ms-border-radius: 3px; - -o-border-radius: 3px; - border-radius: 3px; - cursor: move; -} - -.bootstrap .filter_panel { - min-height: 20px; - padding: 7px 7px 0px 7px; - margin-bottom: 20px; - background-color: #ebebeb; - border: 1px solid #d9d9d9; - border-radius: 3px; - -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05); - box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05); -} - -.bootstrap .filter_panel header { - margin-bottom: 7px; -} diff --git a/views/templates/admin/_configure/helpers/form/form.tpl b/views/templates/admin/_configure/helpers/form/form.tpl index 3346b43..3bc3eeb 100644 --- a/views/templates/admin/_configure/helpers/form/form.tpl +++ b/views/templates/admin/_configure/helpers/form/form.tpl @@ -22,7 +22,7 @@ {if $input.type === 'payment_methods'}
- {l s='Total available' mod='omnipaymollie'}: {$input.payment_methods|count} + {l s='Total available' mod='OmnipayWorldpay'}: {$input.payment_methods|count}
- {l s='Refresh payment methods' mod='omnipaymollie'} + {l s='Refresh payment methods' mod='OmnipayWorldpay'}
@@ -52,14 +52,14 @@ value="1" > diff --git a/views/templates/hook/confirmation.tpl b/views/templates/hook/confirmation.tpl index 658f36d..f861ca9 100644 --- a/views/templates/hook/confirmation.tpl +++ b/views/templates/hook/confirmation.tpl @@ -16,23 +16,29 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) *} {if (isset($status) == true) && ($status == 'ok')} -

{l s='Your order on %s is complete.' sprintf=[$shop_name] mod='omnipaymollie'}

+

{l s='Your order on %s is complete.' sprintf=[$shop_name] mod='omnipayworldpay'}

-
- {l s='Amount' mod='omnipaymollie'} : {$total|escape:'htmlall':'UTF-8'} -
- {l s='Reference' mod='omnipaymollie'} : {$reference|escape:'html':'UTF-8'} -

{l s='An email has been sent with this information.' mod='omnipaymollie'} -

{l s='If you have questions, comments or concerns, please contact our' mod='omnipaymollie'} {l s='expert customer support team.' mod='omnipaymollie'} +
- {l s='Amount' mod='omnipayworldpay'} : {$total|escape:'htmlall':'UTF-8'} +
- {l s='Reference' mod='omnipayworldpay'} : {$reference|escape:'html':'UTF-8'} +
+
+ {l s='An email has been sent with this information.' mod='omnipayworldpay'} +
+
+ {l s='If you have questions, comments or concerns, please contact our' mod='omnipayworldpay'}  + {l s='expert customer support team.' mod='omnipayworldpay'}

{else} -

{l s='Your order on %s has not been accepted.' sprintf=[$shop_name] mod='omnipaymollie'}

+

{l s='Your order on %s has not been accepted.' sprintf=[$shop_name] mod='omnipayworldpay'}

-

-
- {l s='Reference' mod='omnipaymollie'} {$reference|escape:'html':'UTF-8'} -

{l s='Please, try to order again.' mod='omnipaymollie'} -

{l s='If you have questions, comments or concerns, please contact our' mod='omnipaymollie'} {l s='expert customer support team.' mod='omnipaymollie'} +
- {l s='Reference' mod='omnipayworldpay'} {$reference|escape:'html':'UTF-8'} +
+
+ {l s='Please, try to order again.' mod='omnipayworldpay'} +
+
+ {l s='If you have questions, comments or concerns, please contact our' mod='omnipayworldpay'}  + {l s='expert customer support team.' mod='omnipayworldpay'}

{/if}
diff --git a/views/templates/hook/payment.tpl b/views/templates/hook/payment.tpl index 9e6856c..9cfa06a 100644 --- a/views/templates/hook/payment.tpl +++ b/views/templates/hook/payment.tpl @@ -1,20 +1,39 @@ {if !empty($credit_card)} - + +
+
+ +
+ + + {/if} -{foreach $payment_methods as $payment_method} -

- - {if !empty($payment_method['image'])} - {l s='Pay with' mod='omnipaymollie'} {$payment_method['name'][$lang_id]|escape:'htmlall':'UTF-8'} - {/if} - {l s='Pay with' mod='omnipaymollie'} {$payment_method['name'][$lang_id]|escape:'htmlall':'UTF-8'} - -

-{/foreach}