Files
hutko/controllers/front/redirect.php
T
2025-06-02 11:24:18 +03:00

65 lines
2.8 KiB
PHP

<?php
/**
* Hutko - Платіжний сервіс, який рухає бізнеси вперед.
*
* Запускайтесь, набирайте темп, масштабуйтесь – ми підстрахуємо всюди.
*
* @author panariga
* @copyright 2025 Hutko
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
use Symfony\Component\Serializer\Encoder\JsonEncode;
if (!defined('_PS_VERSION_')) {
exit;
}
/**
* Class HutkoRedirectModuleFrontController
*
* @property \Hutko $module
*/
class HutkoRedirectModuleFrontController extends ModuleFrontController
{
/**
* Initializes the content of the redirect page for the Hutko payment gateway.
*
* This method is responsible for preparing the necessary data and assigning
* it to the Smarty template that handles the redirection to the Hutko payment
* service. It calls the parent class's `initContent` method first and then
* assigns the Hutko checkout URL and the payment input parameters to the template.
*/
public function initContent()
{
// Set the template to be used for displaying the redirection form.
$this->setTemplate('module:' . $this->module->name . '/views/templates/front/redirect.tpl');
// Call the parent class's initContent method to perform default initializations.
parent::initContent();
$idState = (int) Configuration::get('HUTKO_NEW_ORDER_STATUS_ID', null, null, null, Configuration::get('PS_OS_PREPARATION'));
$validationResult = $this->module->validateOrder($this->context->cart->id, $idState, 0, $this->module->displayName);
if ($validationResult) {
$order = new Order((int)$this->module->currentOrder);
$requestData = $this->module->buildPaymentRequestData($order, null, null, null);
$responseData = $this->module->sendAPICall($this->module->checkout_url, $requestData);
if (isset($responseData['response']['response_status']) && $responseData['response']['response_status'] === 'success') {
$orderPayment = new OrderPayment();
$orderPayment->order_reference = $order->reference;
$orderPayment->id_currency = $order->id_currency;
$orderPayment->amount = 0;
$orderPayment->payment_method = $this->module->displayName;
$orderPayment->transaction_id = $requestData['order_id'];
$orderPayment->card_holder = $responseData['response']['checkout_url'];
$orderPayment->add();
Tools::redirect($responseData['response']['checkout_url']);
return;
}
$this->context->smarty->assign([
'hutko_response' => $responseData['response'], // The URL of the Hutko payment gateway.
]);
}
}
}