diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php
index c267c74e5..62dd3c54b 100644
--- a/classes/PaymentModule.php
+++ b/classes/PaymentModule.php
@@ -430,7 +430,7 @@ abstract class PaymentModuleCore extends Module
if ($order_status->logable
&& number_format($cart_total_paid, _PS_PRICE_COMPUTE_PRECISION_) != number_format($amount_paid, _PS_PRICE_COMPUTE_PRECISION_)
&& $this->name != 'wsorder'
- && !(isset($this->hasPartialPayment) && $this->hasPartialPayment)
+ && $this->name != 'bo_order'
) {
// if customer is paying full payment amount
$id_order_state = Configuration::get('PS_OS_ERROR');
@@ -479,7 +479,7 @@ abstract class PaymentModuleCore extends Module
}
// Register Payment only if the order status validate the order
- if ($order_status->logable || (isset($this->hasPartialPayment) && $this->hasPartialPayment && $amount_paid)) {
+ if ($order_status->logable) {
// $order is the last order loop in the foreach
// The method addOrderPayment of the class Order make a create a paymentOrder
// linked to the order reference and not to the order id
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 52d1f159a..387571829 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -962,11 +962,12 @@ class AdminOrdersControllerCore extends AdminController
$moduleName = trim(Tools::getValue('payment_module_name'));
$paymentType = Tools::getValue('payment_type');
$paymentTransactionId = trim(Tools::getValue('payment_transaction_id'));
+ $isFullPayment = Tools::getValue('is_full_payment');
$paymentAmount = trim(Tools::getValue('payment_amount'));
if (!$moduleName) {
$this->errors[] = Tools::displayError('Please enter Payment method.');
- } elseif ($moduleName && !((Validate::isModuleName($moduleName) && ($paymentModuleInstance = Module::getInstanceByName($moduleName))) || Validate::isGenericName($moduleName))) {
+ } elseif ($moduleName && !Validate::isGenericName($moduleName)) {
$this->errors[] = Tools::displayError('Payment method is invalid. Please enter a valid payment method.');
}
@@ -980,18 +981,17 @@ class AdminOrdersControllerCore extends AdminController
$this->errors[] = Tools::displayError('Payment amount is invalid. Please enter correct amount.');
}
- if ($paymentAmount && !Validate::isPrice($paymentAmount)) { // $paymentAmount = '' means no payment
- $this->errors[] = Tools::displayError('Payment amount is invalid. Please enter correct amount.');
+ if (!$isFullPayment) {
+ if ($paymentAmount == '') {
+ $this->errors[] = Tools::displayError('Please enter Payment amount.');
+ } elseif ($paymentAmount && !Validate::isPrice($paymentAmount)) {
+ $this->errors[] = Tools::displayError('Payment amount is invalid. Please enter correct amount.');
+ }
}
if (!count($this->errors)) {
- if ($paymentModuleInstance) {
- $payment_module = $paymentModuleInstance;
- } else {
- $payment_module = new BoOrder();
- $payment_module->displayName = $moduleName;
- }
-
+ $payment_module = new BoOrder();
+ $payment_module->displayName = $moduleName;
$payment_module->payment_type = $paymentType;
$cart = new Cart((int)$id_cart);
@@ -1000,7 +1000,8 @@ class AdminOrdersControllerCore extends AdminController
$bad_delivery = false;
if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$cart->id_address_delivery))
- || !Address::isCountryActiveById((int)$cart->id_address_invoice)) {
+ || !Address::isCountryActiveById((int)$cart->id_address_invoice)
+ ) {
if ($bad_delivery) {
$this->errors[] = Tools::displayError('This booking address country is not active.');
} else {
@@ -1008,12 +1009,8 @@ class AdminOrdersControllerCore extends AdminController
}
} else {
$amountPaid = $cart->getOrderTotal(true, Cart::BOTH);
- if (((float) $paymentAmount != 0) && Validate::isPrice($paymentAmount)) { // $paymentAmount != {'', '0', '0.00'}
- $objOrderState = new OrderState($id_order_state);
- if (!$objOrderState->is_logable && !$objOrderState->paid) {
- $amountPaid = Tools::ps_round($paymentAmount, 6);
- $payment_module->hasPartialPayment = true;
- }
+ if (!$isFullPayment) {
+ $amountPaid = Tools::ps_round($paymentAmount, 6);
}
$employee = new Employee((int)Context::getContext()->cookie->id_employee);
@@ -1030,6 +1027,39 @@ class AdminOrdersControllerCore extends AdminController
$cart->secure_key
);
+ // add order payment if required
+ $objOrderState = new OrderState($id_order_state);
+ if (!$objOrderState->logable && !$objOrderState->paid) {
+ $objOrder = new Order($payment_module->currentOrder);
+
+ if ($objOrder->hasInvoice()) {
+ $invoices = $objOrder->getInvoicesCollection();
+
+ $dateTimeNow = date('Y-m-d H:i:s');
+ foreach ($invoices as $invoice) {
+ $objOrder->addOrderPayment(
+ $amountPaid,
+ $payment_module->displayName,
+ $paymentTransactionId,
+ new Currency($objOrder->id_currency),
+ $dateTimeNow,
+ $invoice,
+ $paymentType
+ );
+ }
+ } else {
+ $objOrder->addOrderPayment(
+ $amountPaid,
+ $payment_module->displayName,
+ $paymentTransactionId,
+ new Currency($objOrder->id_currency),
+ date('Y-m-d H:i:s'),
+ null,
+ $paymentType
+ );
+ }
+ }
+
if (isset($this->context->cookie->id_cart)) {
unset($this->context->cookie->id_cart);
}