128 lines
3.2 KiB
PHP
128 lines
3.2 KiB
PHP
<?php
|
|
|
|
use Imoje\Payment\Payment;
|
|
use Imoje\Payment\Twisto;
|
|
use Imoje\Payment\Util;
|
|
|
|
/**
|
|
* Class IMojeTwistoModuleFrontController
|
|
*
|
|
* @property bool display_column_left
|
|
* @property bool display_column_right
|
|
*/
|
|
class IMojeTwistoModuleFrontController extends ModuleFrontController
|
|
{
|
|
|
|
/**
|
|
* Initialize controller
|
|
*
|
|
* @throws PrestaShopException
|
|
* @see FrontController::init()
|
|
*/
|
|
public function init()
|
|
{
|
|
$this->display_column_left = false;
|
|
$this->display_column_right = false;
|
|
parent::init();
|
|
}
|
|
|
|
/**
|
|
* @throws PrestaShopException
|
|
* @throws Exception
|
|
*/
|
|
public function initContent()
|
|
{
|
|
|
|
parent::initContent();
|
|
|
|
$environment = Configuration::get('IMOJE_SANDBOX') == 1
|
|
? Util::ENVIRONMENT_SANDBOX
|
|
: Util::ENVIRONMENT_PRODUCTION;
|
|
|
|
$payment = new Payment(
|
|
$environment,
|
|
Configuration::get('IMOJE_SERVICE_KEY'),
|
|
Configuration::get('IMOJE_SERVICE_ID'),
|
|
Configuration::get('IMOJE_MERCHANT_ID')
|
|
);
|
|
|
|
$cart = $this->context->cart;
|
|
|
|
if(!$cart->date_upd) {
|
|
Tools::redirect('/');
|
|
|
|
return;
|
|
}
|
|
|
|
$paymentMethods = json_decode(Configuration::get('IMOJE_PAYMENT_METHODS'), true);
|
|
|
|
$twistoData = '';
|
|
|
|
$imoje = new iMoje();
|
|
|
|
if(
|
|
Twisto::isActive(
|
|
$paymentMethods,
|
|
Configuration::get('IMOJE_TWISTO_ENABLED')
|
|
)
|
|
&& !Configuration::get('IMOJE_SANDBOX')
|
|
) {
|
|
|
|
if(isset($_POST['twistoData'])
|
|
&& $_POST['twistoData']
|
|
&& Util::isJson($_POST['twistoData'])) {
|
|
|
|
$twistoData = $_POST['twistoData'];
|
|
}
|
|
|
|
if(Configuration::get('IMOJE_TWISTO_ARRANGEMENT_CALL_JS')) {
|
|
|
|
$customer = new Customer((int) $cart->id_customer);
|
|
|
|
$previousOrders = [];
|
|
|
|
if(Configuration::get('IMOJE_TWISTO_PURCHASE_HISTORY')) {
|
|
$previousOrders = $imoje->getPreviousOrders($customer);
|
|
}
|
|
|
|
$twistoData = Twisto::getPayload(
|
|
$paymentMethods['twisto']['sk'],
|
|
$cart->getOrderTotal(true),
|
|
$imoje->getCart($cart),
|
|
$customer->email,
|
|
DateTime::createFromFormat('Y-m-d H:i:s', $cart->date_upd),
|
|
$previousOrders);
|
|
}
|
|
}
|
|
|
|
$this->context->smarty->assign([
|
|
'form' => $payment->buildOrderForm(
|
|
$imoje->getDataForRequestToPaywall($cart, $twistoData)
|
|
),
|
|
'checkout_link' => $this->context->link->getPageLink(Configuration::get('PS_ORDER_PROCESS_TYPE')
|
|
? 'order-opc'
|
|
: 'order'),
|
|
'text_return_to_checkout' => $this->module->l('Please wait, you will be returned to checkout.', 'payment'),
|
|
'imoje_twisto_payload' => $twistoData,
|
|
'imoje_twisto_script_url' => Twisto::getUrlScript(
|
|
$environment
|
|
),
|
|
|
|
'imoje_twisto_arrangement_call_js' => Configuration::get('IMOJE_TWISTO_ARRANGEMENT_CALL_JS'),
|
|
'imoje_payment_methods' => $paymentMethods,
|
|
|
|
'imoje_signature_link' => $this->context->link->getModuleLink('imoje', 'signature'),
|
|
'signature' => Util::hashSignature('sha256', $cart->id_customer, Configuration::get('IMOJE_SERVICE_KEY')),
|
|
|
|
'loading_gif' => Media::getMediaPath(_PS_MODULE_DIR_ . $imoje->name . '/assets/img/loading.gif'),
|
|
'twisto_hint' => $this->l('Please wait, the connection with the Twisto is being established'),
|
|
|
|
'blik_msg' => false,
|
|
]);
|
|
|
|
$this->setTemplate(IMoje::buildTemplatePath('pay', 'front'));
|
|
|
|
return;
|
|
}
|
|
}
|