name = 'bankwire';
$this->tab = 'Payment';
$this->version = '0.5';
$this->currencies = true;
$this->currencies_mode = 'checkbox';
$config = Configuration::getMultiple(array('BANK_WIRE_DETAILS', 'BANK_WIRE_OWNER', 'BANK_WIRE_ADDRESS'));
if (isset($config['BANK_WIRE_OWNER']))
$this->owner = $config['BANK_WIRE_OWNER'];
if (isset($config['BANK_WIRE_DETAILS']))
$this->details = $config['BANK_WIRE_DETAILS'];
if (isset($config['BANK_WIRE_ADDRESS']))
$this->address = $config['BANK_WIRE_ADDRESS'];
parent::__construct();
$this->displayName = $this->l('Bank Wire');
$this->description = $this->l('Accept payments by bank wire');
$this->confirmUninstall = $this->l('Are you sure you want to delete your details?');
if (!isset($this->owner) OR !isset($this->details) OR !isset($this->address))
$this->warning = $this->l('Account owner and details must be configured in order to use this module correctly');
if (!sizeof(Currency::checkPaymentCurrencies($this->id)))
$this->warning = $this->l('No currency set for this module');
}
public function install()
{
if (!parent::install() OR !$this->registerHook('payment') OR !$this->registerHook('paymentReturn'))
return false;
return true;
}
public function uninstall()
{
if (!Configuration::deleteByName('BANK_WIRE_DETAILS')
OR !Configuration::deleteByName('BANK_WIRE_OWNER')
OR !Configuration::deleteByName('BANK_WIRE_ADDRESS')
OR !parent::uninstall())
return false;
return true;
}
private function _postValidation()
{
if (isset($_POST['btnSubmit']))
{
if (empty($_POST['details']))
$this->_postErrors[] = $this->l('account details are required.');
elseif (empty($_POST['owner']))
$this->_postErrors[] = $this->l('Account owner is required.');
}
}
private function _postProcess()
{
if (isset($_POST['btnSubmit']))
{
Configuration::updateValue('BANK_WIRE_DETAILS', $_POST['details']);
Configuration::updateValue('BANK_WIRE_OWNER', $_POST['owner']);
Configuration::updateValue('BANK_WIRE_ADDRESS', $_POST['address']);
}
$this->_html .= '

'.$this->l('Settings updated').'
';
}
private function _displayBankWire()
{
$this->_html .= '
'.$this->l('This module allows you to accept payments by bank wire.').'
'.$this->l('If the client chooses this payment mode, the order will change its status into a \'Waiting for payment\' status.').'
'.$this->l('Therefore, you will need to manually confirm the order as soon as you receive a wire..').'
';
}
private function _displayForm()
{
$this->_html .=
'';
}
public function getContent()
{
$this->_html = ''.$this->displayName.'
';
if (!empty($_POST))
{
$this->_postValidation();
if (!sizeof($this->_postErrors))
$this->_postProcess();
else
foreach ($this->_postErrors AS $err)
$this->_html .= ''. $err .'
';
}
else
$this->_html .= '
';
$this->_displayBankWire();
$this->_displayForm();
return $this->_html;
}
public function execPayment($cart)
{
if (!$this->active)
return ;
if (!$this->_checkCurrency($cart))
return ;
global $cookie, $smarty;
$smarty->assign(array(
'nbProducts' => $cart->nbProducts(),
'cust_currency' => $cookie->id_currency,
'currencies' => $this->getCurrency(),
'total' => $cart->getOrderTotal(true, 3),
'isoCode' => Language::getIsoById(intval($cookie->id_lang)),
'bankwireDetails' => nl2br2($this->details),
'bankwireAddress' => nl2br2($this->address),
'bankwireOwner' => $this->owner,
'this_path' => $this->_path,
'this_path_ssl' => Tools::getHttpHost(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
));
return $this->display(__FILE__, 'payment_execution.tpl');
}
public function hookPayment($params)
{
if (!$this->active)
return ;
if (!$this->_checkCurrency($params['cart']))
return ;
global $smarty;
$smarty->assign(array(
'this_path' => $this->_path,
'this_path_ssl' => Tools::getHttpHost(true, true).__PS_BASE_URI__.'modules/'.$this->name.'/'
));
return $this->display(__FILE__, 'payment.tpl');
}
public function hookPaymentReturn($params)
{
if (!$this->active)
return ;
global $smarty;
$state = $params['objOrder']->getCurrentState();
if ($state == _PS_OS_BANKWIRE_ OR $state == _PS_OS_OUTOFSTOCK_)
$smarty->assign(array(
'total_to_pay' => Tools::displayPrice($params['total_to_pay'], $params['currencyObj'], false, false),
'bankwireDetails' => nl2br2($this->details),
'bankwireAddress' => nl2br2($this->address),
'bankwireOwner' => $this->owner,
'status' => 'ok',
'id_order' => $params['objOrder']->id
));
else
$smarty->assign('status', 'failed');
return $this->display(__FILE__, 'payment_return.tpl');
}
private function _checkCurrency($cart)
{
$currency_order = new Currency(intval($cart->id_currency));
$currencies_module = $this->getCurrency();
$currency_default = Configuration::get('PS_CURRENCY_DEFAULT');
if (is_array($currencies_module))
foreach ($currencies_module AS $currency_module)
if ($currency_order->id == $currency_module['id_currency'])
return true;
}
}