Add full payment switch

This commit is contained in:
Abhishek Kumar
2024-02-13 17:18:55 +05:30
parent 7fb3a5574c
commit b2d791c565
4 changed files with 72 additions and 28 deletions

View File

@@ -28,6 +28,6 @@
<option value="{l s='Back office order'}" data-name="{l s='Back office order'}" data-payment-type="{OrderPayment::PAYMENT_TYPE_PAY_AT_HOTEL}">
{/if}
{foreach from=$payment_modules item=payment_module}
<option value="{$payment_module->displayName}" data-name="{$payment_module->name}">
<option value="{$payment_module->displayName}" data-name="{$payment_module->name}" data-payment-type="{$payment_module->payment_type}">
{/foreach}
</datalist>

View File

@@ -360,7 +360,6 @@
{
$('#cart_detail_form').show();//line added by webkul
$('#payment_method_options').replaceWith(data.view)
$('#payment_module_name_display').val('')
}
}
});
@@ -1587,8 +1586,8 @@
}
});
$(document).on('keyup', '#payment_module_name_display', function() {
let paymentMethod = $('#payment_module_name_display').val().trim().toLowerCase();
$(document).on('keyup', '#payment_module_name', function() {
let paymentMethod = $('#payment_module_name').val().trim().toLowerCase();
let selectedMethod;
$('#payment_module_name_list option').each(function (index, element) {
@@ -1600,15 +1599,19 @@
});
if ($(selectedMethod).length) {
$('#payment_module_name').val($(selectedMethod).attr('data-name'));
// set Payment source
let paymentType = $(selectedMethod).attr('data-payment-type');
if ($('select#payment_type option[value="' + paymentType + '"]').length) {
$('#payment_type').val(paymentType);
}
}
});
$(document).on('change', 'input[name="is_full_payment"]', function() {
if (parseInt($('input[name="is_full_payment"]:checked').val())) {
$('#payment_amount').closest('.form-group').hide(200);
} else {
$('#payment_module_name').val($('#payment_module_name_display').val());
$('#payment_amount').closest('.form-group').show(200);
}
});
@@ -2116,8 +2119,7 @@
<div class="form-group">
<label class="control-label col-lg-3 required">{l s='Payment method'}</label>
<div class="col-lg-9">
<input name="payment_module_name_display" id="payment_module_name_display" list="payment_module_name_list" class="form-control fixed-width-xxl" {if isset($smarty.post.payment_module_name_display) && $smarty.post.payment_module_name_display}value="{$smarty.post.payment_module_name_display}"{/if}>
<input type="hidden" name="payment_module_name" id="payment_module_name" {if isset($smarty.post.payment_module_name) && $smarty.post.payment_module_name}value="{$smarty.post.payment_module_name}"{/if}>
<input name="payment_module_name" id="payment_module_name" list="payment_module_name_list" class="form-control fixed-width-xxl" {if isset($smarty.post.payment_module_name) && $smarty.post.payment_module_name}value="{$smarty.post.payment_module_name}"{/if}>
<datalist id="payment_module_name_list">
{if $PS_CATALOG_MODE}
<option value="{l s='Back office order'}" data-name="{l s='Back office order'}" data-payment-type="{OrderPayment::PAYMENT_TYPE_PAY_AT_HOTEL}">
@@ -2147,6 +2149,18 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-3">{l s="Full payment"}</label>
<div class="col-lg-9">
<span class="switch prestashop-switch fixed-width-lg">
<input type="radio" name="is_full_payment" id="is_full_payment_on" value="1" {if (isset($smarty.post.is_full_payment) && $smarty.post.is_full_payment == '1') || !isset($smarty.post.is_full_payment)}checked="checked"{/if}>
<label for="is_full_payment_on">{l s="Yes"}</label>
<input type="radio" name="is_full_payment" id="is_full_payment_off" value="0" {if isset($smarty.post.is_full_payment) && $smarty.post.is_full_payment == '0'}checked="checked"{/if}>
<label for="is_full_payment_off">{l s="No"}</label>
<a class="slide-button btn"></a>
</span>
</div>
</div>
<div class="form-group" {if (isset($smarty.post.is_full_payment) && $smarty.post.is_full_payment == '1') || !isset($smarty.post.is_full_payment)}style="display: none;"{/if}>
<label class="control-label col-lg-3">{l s='Payment amount'}</label>
<div class="col-lg-9">
<div class="input-group fixed-width-xxl">

View File

@@ -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

View File

@@ -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);
}