display_column_left = false; $this->display_column_right = false; $this->display_footer = false; $this->display_header = false; parent::init(); } /** * Send request for activated payment methods */ public function process() { $isDebugMode = Configuration::get('IMOJE_DEBUG_MODE'); $createOrderArrangement = Configuration::get('IMOJE_CREATE_ORDER_ARRANGEMENT'); if(!function_exists('curl_init')) { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_CURL_IS_NOT_INSTALLED, $isDebugMode, null, null, $createOrderArrangement); die(); } if($_SERVER['REQUEST_METHOD'] !== 'POST') { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_REQUEST_IS_NOT_POST, $isDebugMode, null, null, $createOrderArrangement); die(); } if(empty($_POST['twistoResponse'])) { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_MISSING_TWISTO_RESPONSE_IN_POST, $isDebugMode, null, null, $createOrderArrangement); die(); } if(empty($_POST['orderId'])) { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_MISSING_ORDER_ID_IN_POST, $isDebugMode, null, null, $createOrderArrangement); die(); } if(empty($_POST['signature'])) { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_MISSING_SIGNATURE_IN_POST, $isDebugMode, null, null, $createOrderArrangement); die(); } if(!Util::isJson($_POST['twistoResponse'])) { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_INVALID_JSON_STRUCTURE, $isDebugMode, null, null, $createOrderArrangement); die(); } $imoje = new iMoje(); $payment = new Payment( Configuration::get('IMOJE_SANDBOX') ? Util::ENVIRONMENT_SANDBOX : Util::ENVIRONMENT_PRODUCTION, Configuration::get('IMOJE_SERVICE_KEY'), Configuration::get('IMOJE_SERVICE_ID'), Configuration::get('IMOJE_MERCHANT_ID') ); if(Configuration::get('IMOJE_CREATE_ORDER_ARRANGEMENT')) { $cart = new Cart($_POST['orderId']); if(empty($cart->id)) { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_CART_NOT_FOUND, $isDebugMode, null, null, $createOrderArrangement); die(); } if(Util::hashSignature( 'sha256', $cart->id_customer, Configuration::get('IMOJE_SERVICE_KEY')) !== $_POST['signature']) { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_INVALID_SIGNATURE, $isDebugMode, null, null, $createOrderArrangement); die(); } $customer = new Customer(intval($cart->id_customer)); $addressBilling = new Address((int) $cart->id_address_invoice); $addressDelivery = new Address((int) $cart->id_address_delivery); $currencyInfo = Currency::getCurrency($cart->id_currency); echo $payment->buildOrderForm( Util::prepareData( Util::convertAmountToFractional($cart->getOrderTotal()), $currencyInfo['iso_code'], $cart->id, null, $customer->firstname, $customer->lastname, $customer->email, ($addressDelivery->phone_mobile ?: ($addressBilling->phone_mobile ?: '')), $this->context->link->getModuleLink('imoje', 'success'), $this->context->link->getModuleLink('imoje', 'failure'), $this->context->link->getModuleLink('imoje', 'confirmation'), $imoje->version . ';prestashop_' . _PS_VERSION_, $_POST['twistoResponse'] ) ); die(); } $order = new Order($_POST['orderId']); if(Util::hashSignature( 'sha256', $order->id_customer, Configuration::get('IMOJE_SERVICE_KEY')) !== $_POST['signature']) { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_INVALID_SIGNATURE, $isDebugMode, null, null, $createOrderArrangement); die(); } if(empty($order->id)) { echo Util::notificationResponse(Util::NS_ERROR, Util::NC_ORDER_NOT_FOUND, $isDebugMode, null, null, $createOrderArrangement); die(); } $cart = Cart::getCartByOrderId($_POST['orderId']); $customer = new Customer($order->id_customer); $addressBilling = new Address($order->id_address_invoice); $addressDelivery = new Address($order->id_address_delivery); $currencyInfo = Currency::getCurrency($order->id_currency); echo $payment->buildOrderForm(Util::prepareData( Util::convertAmountToFractional($order->total_paid), $currencyInfo['iso_code'], $_POST['orderId'], null, $customer->firstname, $customer->lastname, $customer->email, ($addressDelivery->phone_mobile ?: ($addressBilling->phone_mobile ?: '')), _PS_BASE_URL_ . __PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $imoje->id . '&id_order=' . $_POST['orderId'] . '&key=' . $customer->secure_key, $this->context->link->getModuleLink('imoje', 'failure'), $this->context->link->getModuleLink('imoje', 'confirmation'), $imoje->version . ';prestashop_' . _PS_VERSION_, $_POST['twistoResponse'] )); die(); } }