Files
b2bpayments/controllers/front/validation.php

79 lines
3.4 KiB
PHP

<?php
class B2BPaymentsValidationModuleFrontController extends ModuleFrontController
{
public function postProcess()
{
if ($this->context->cart->id_customer == 0 || $this->context->cart->id_address_delivery == 0 || $this->context->cart->id_address_invoice == 0 || !$this->module->active) {
Tools::redirect($this->context->link->getPageLink('order', true, $this->context->language->id, [
'step' => 1
]));
return false;
}
if (!$this->context->customer->id) {
// Handle unauthenticated access, maybe redirect to login
Tools::redirect($this->context->link->getPageLink('authentication', true, $this->context->language->id, [
'back' => $_SERVER['HTTP_REFERER']
]));
}
$total = $this->context->cart->getOrderTotal(true, Cart::BOTH);
// Refresh cart prices based on the customer's default group. Crucial step!
$this->context->cart->getProducts(true); // Force refresh of product prices.
$this->context->cart->update();
Cart::resetStaticCache();
// Re-calculate the total
$total = $this->context->cart->getOrderTotal(true, Cart::BOTH);
// Determine payment status based on customer group (for example):
$this->context->customer->id;
$b2b_postpaid_group_id = (int)Configuration::get('B2BPAYMENTS_POSTPAID_GROUP');
$b2b_prepaid_group_id = (int)Configuration::get('B2BPAYMENTS_PREPAID_GROUP');
//$payment_status = Configuration::get('PS_OS_PAYMENT'); // Default: Payment accepted
$payment_status = 16; // Default for Prepaid (Avans) - custom status ID 16
if ($this->module->isDefaultCustomerGroup($this->context->customer->id, $b2b_postpaid_group_id) && $this->module->isCustomerInGroup($this->context->customer->id, $b2b_postpaid_group_id)) {
//$payment_status = Configuration::get('PS_OS_PREPARATION'); // Order processing in progress. Adjust as needed.
$payment_status = 15; // For Postpaid (Odgoda) - custom status ID 15
$payment_method = $this->module->b2b_postpaid_payment_name;
} else if ($this->module->isDefaultCustomerGroup($this->context->customer->id, $b2b_prepaid_group_id) && $this->module->isCustomerInGroup($this->context->customer->id, $b2b_prepaid_group_id)) {
//Payment Status Already fine.
$payment_method = $this->module->b2b_prepaid_payment_name;
} else {
// Handle the case where the customer is not in either B2B group, or it's their default group
Tools::redirect($this->context->link->getPageLink('order', true, $this->context->language->id, [
'step' => 1
]));
return false;
}
$this->module->validateOrder(
(int)$this->context->cart->id,
$payment_status,
$total,
$payment_method,
null,
[],
null,
false,
$this->context->customer->secure_key
);
Tools::redirect($this->context->link->getPageLink('order-confirmation', true, $this->context->language->id, [
'id_cart' => $this->context->cart->id,
'id_module' => $this->module->id,
'id_order' => $this->module->currentOrder,
'key' => $this->context->customer->secure_key,
]));
return true;
}
}