Files
2024-10-25 14:16:28 +02:00

94 lines
2.0 KiB
PHP

<?php
use Imoje\Payment\Util;
/**
* Class IMojeNotificationModuleFrontController
*
* @property bool display_column_left
* @property bool display_column_right
* @property bool display_footer
* @property bool display_header
*/
class IMojeNotificationModuleFrontController extends ModuleFrontController
{
/**
* Initialize controller.
*
* @see FrontController::init()
*/
public function init()
{
$this->display_column_left = false;
$this->display_column_right = false;
$this->display_footer = false;
$this->display_header = false;
parent::init();
}
/**
* Verify signature, json, create signature and change status if its okay
*
* @throws PrestaShopException
* @throws Exception
*/
public function process()
{
if(($payloadDecoded = Util::checkRequestNotification(Configuration::get('IMOJE_SERVICE_KEY'), Configuration::get('IMOJE_SERVICE_ID')))
&& ($payloadDecoded['transaction']['status'] === 'settled')) {
$cartIdFromNotification = (int) $payloadDecoded['transaction']['orderId'];
$cart = new Cart($cartIdFromNotification);
if(!$cart->id) {
header("HTTP/1.1 404 Not Found");
exit;
}
$orderId = Order::getOrderByCartId($cartIdFromNotification);
if($orderId !== false) {
header("HTTP/1.1 404 Not Found");
exit;
}
$currencyInfo = Currency::getCurrency($cart->id_currency);
$cartTotal = $cart->getOrderTotal();
if(Util::checkRequestAmount(
$payloadDecoded,
Util::convertAmountToFractional($cartTotal),
$currencyInfo["iso_code"])) {
$customer = new Customer((int) $cart->id_customer);
$cartId = (int) $cart->id;
$imoje = new iMoje();
$imoje->validateOrder($cartId,
_PS_OS_PAYMENT_,
$cartTotal,
$imoje->displayName,
null,
[],
null,
false,
$customer->secure_key
);
$history = new OrderHistory();
$history->id_order = intval($orderId);
$history->addWithemail(true);
header("HTTP/1.1 200 OK");
exit();
}
}
header("HTTP/1.1 404 Not Found");
exit;
}
}