120 lines
4.4 KiB
PHP
120 lines
4.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @since 1.5.0
|
|
*/
|
|
include_once(dirname(__FILE__).'/../../classes/PaybynetCore.php');
|
|
|
|
class PaybynetSubmitModuleFrontController extends ModuleFrontController
|
|
{
|
|
public $display_column_left = false;
|
|
public $ssl = true;
|
|
public $display_column_right = false;
|
|
|
|
public function postProcess()
|
|
{
|
|
$bankId = Tools::getValue('bank_id');
|
|
$cart = $this->context->cart;
|
|
if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
|
|
Tools::redirect('index.php?controller=order');
|
|
}
|
|
$customer = new Customer($cart->id_customer);
|
|
if (!Validate::isLoadedObject($customer))
|
|
Tools::redirect('index.php?controller=order&step=1');
|
|
|
|
$currency = $this->context->currency;
|
|
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
|
|
|
|
$authorized = false;
|
|
foreach (Module::getPaymentModules() as $module)
|
|
if ($module['name'] == 'paybynet')
|
|
{
|
|
$authorized = true;
|
|
break;
|
|
}
|
|
|
|
if (!$authorized)
|
|
die($this->module->l('This payment method is not available.', 'validation'));
|
|
|
|
try {
|
|
$this->module->validateOrder((int)$cart->id, Configuration::get('PAYBYNET_ORDERSTATE_WAITING_PAYMENT'), $total, $this->module->displayName, NULL, array(), (int)$currency->id, false, $customer->secure_key);
|
|
} catch(Exception $e) {
|
|
$config = array(
|
|
'sandbox' => Configuration::get('PAYBYNET_SANDBOX'),
|
|
'log' => 1
|
|
);
|
|
|
|
$pbn_core = new PaybynetCore($config);
|
|
$pbn_core->logOperation($e->getMessage(), 'Error');
|
|
}
|
|
}
|
|
|
|
public function initContent()
|
|
{
|
|
parent::initContent();
|
|
$this->context = Context::getContext();
|
|
|
|
$cart = $this->context->cart;
|
|
|
|
$id_order = Order::getOrderByCartId((int)$cart->id);
|
|
|
|
$order = new Order($id_order);
|
|
// $order_state = new OrderState($order->current_state);
|
|
|
|
$customer = new Customer($order->id_customer);
|
|
|
|
|
|
$config_values = $this->getConfigValues();
|
|
|
|
$config = array(
|
|
'sandbox' => Configuration::get('PAYBYNET_SANDBOX'),
|
|
'log' => Configuration::get('PAYBYNET_SORAGE_LOGS')
|
|
);
|
|
|
|
$pbn_core = new PaybynetCore($config);
|
|
|
|
|
|
$config_values['id_trans'] = $id_order;
|
|
$config_values['amount'] = $order->total_paid_tax_incl;
|
|
$config_values['email'] = $customer->email;
|
|
$config_values['backpage'] = $this->context->link->getModuleLink('paybynet', 'return', array('type' => 'success'), true);
|
|
$config_values['backpage_reject'] = $this->context->link->getModuleLink('paybynet', 'return', array('type' => 'reject'), true);
|
|
|
|
$form_elements = $pbn_core->getFormElements($config_values);
|
|
|
|
$pbn_form_link = $pbn_core->getBankFormLink();
|
|
|
|
if (Tools::getValue('bank_id')) {
|
|
$pbn_form_link .= '?idbank='.Tools::getValue('bank_id');
|
|
}
|
|
|
|
$this->context->smarty->assign(array(
|
|
'form_data' => $form_elements,
|
|
'form_action' => $pbn_form_link,
|
|
'logo' => Media::getMediaPath(_PS_MODULE_DIR_.'paybynet/views/img/KIR_Paybynet_logo250.jpg')
|
|
));
|
|
|
|
$this->setTemplate('module:paybynet/views/templates/front/submit.tpl');
|
|
}
|
|
|
|
private function getConfigValues()
|
|
{
|
|
$config = array();
|
|
$config['paybynet_name'] = Configuration::get('PAYBYNET_NAME');
|
|
$config['paybynet_zip_code'] = Configuration::get('PAYBYNET_ZIP_CODE');
|
|
$config['paybynet_city'] = Configuration::get('PAYBYNET_CITY');
|
|
$config['paybynet_street'] = Configuration::get('PAYBYNET_STREET');
|
|
$config['paybynet_country'] = Configuration::get('PAYBYNET_COUNTRY');
|
|
$config['paybynet_account'] = Configuration::get('PAYBYNET_ACCOUNT');
|
|
$config['paybynet_currency'] = Configuration::get('PAYBYNET_CURRENCY');
|
|
$config['paybynet_date_valid'] = Configuration::get('PAYBYNET_DATE_VALID');
|
|
$config['paybynet_id_client'] = Configuration::get('PAYBYNET_ID_CLIENT');
|
|
$config['paybynet_password'] = Configuration::get('PAYBYNET_PASSWORD');
|
|
$config['paybynet_show_banks'] = Configuration::get('PAYBYNET_SHOW_BANKS');
|
|
$config['paybynet_cc_active'] = Configuration::get('PAYBYNET_CC_ACTIVE');
|
|
$config['paybynet_sandbox'] = Configuration::get('PAYBYNET_SANDBOX');
|
|
$config['paybynet_sorage_logs'] = Configuration::get('PAYBYNET_SORAGE_LOGS');
|
|
return $config;
|
|
}
|
|
}
|