';
+ $request = $_REQUEST;
+
+if (method_exists($this, '_doRefund')) {
+ // Refund process
+ if (isRefund($transaction_details->fields)) {
+ $avail_refund = $refund_value = 0;
+ $avail_refund = (!empty($transaction_details->fields['callback_amount'])) ? $transaction_details->fields['callback_amount'] : $transaction_details->fields['amount'];
+ $refund_value = (!empty($transaction_details->fields['refund_amount'])) ? ($avail_refund - $transaction_details->fields['refund_amount']) : $avail_refund;
+
+ $outputRefund .= '';
+ $outputRefund .= $nn_html;
+ $outputRefund .= ' | | '."\n";
+ $outputRefund .= zen_draw_form('novalnet_trans_refund', FILENAME_ORDERS, zen_get_all_get_params(array('action')) . 'action=doRefund', 'post', '', true) ;
+ $outputRefund .= $nn_script ;
+ $outputRefund .= $nn_html.'';
+ $outputRefund .= ' | | ';
+ $outputRefund .= '';
+ $outputRefund .= ''.MODULE_PAYMENT_NOVALNET_REFUND_AMT_TITLE . ' | ';
+ $outputRefund .= zen_draw_hidden_field('oID', $request['oID']);
+ $outputRefund .= zen_draw_hidden_field('nn_amount_error', MODULE_PAYMENT_NOVALNET_AMOUNT_ERROR_MESSAGE);
+ $outputRefund .= zen_draw_hidden_field('nn_refund_amount_confirm', MODULE_PAYMENT_NOVALNET_PAYMENT_REFUND_CONFIRM);
+ $outputRefund .= '';
+ $outputRefund .= zen_draw_input_field('refund_trans_amount', $refund_value, 'id="refund_trans_amount" onkeypress="isNumber(event)" style="width:100px;margin:0 0 0 2%" autocomplete="off"') . MODULE_PAYMENT_NOVALNET_AMOUNT_EX . ' | ';
+ $outputRefund .= ''.MODULE_PAYMENT_NOVALNET_REFUND_REASON_TITLE . ' | ';
+ $outputRefund .= '' . zen_draw_input_field('refund_reason', '', 'id="refund_reason" style="margin:0 0 0 2%;" autocomplete="off"').' | ';
+ $outputRefund .= ''.zen_draw_input_field('nn_refund_confirm', html_entity_decode(MODULE_PAYMENT_NOVALNET_CONFIRM_TEXT), 'class="btn btn-primary" onclick="return refund_amount_validation();" style="float:left"', false, 'submit').' | | ';
+ $outputRefund .= '';
+ $outputRefund .=' | '."\n";
+ }
+}
+
+// On-hold process
+if (method_exists($this, '_doVoid') && method_exists($this, '_doCapt')) {
+ if ($transaction_details->fields['status'] == 'ON_HOLD') {
+ $options = array (
+ array('id'=> '', 'text' => MODULE_PAYMENT_NOVALNET_SELECT_STATUS_OPTION),
+ array('id'=> 'CONFIRM', 'text' => MODULE_PAYMENT_NOVALNET_CONFIRM_TEXT),
+ array('id'=> 'CANCEL', 'text' => MODULE_PAYMENT_NOVALNET_CANCEL_TEXT),
+ );
+
+ $outputVoidCapt .= '';
+ $outputVoidCapt .= $nn_html;
+ $outputVoidCapt .= ' | | '."\n";
+ $outputVoidCapt .= zen_draw_form('novalnet_status_change', FILENAME_ORDERS, zen_get_all_get_params(array('action')), 'post', 'id="novalnet_status_change"', true) ;
+ $outputVoidCapt .= $nn_script ;
+ $outputVoidCapt .= $nn_html.'';
+ $outputVoidCapt .= ' | | ';
+ $outputVoidCapt .= '';
+ $outputVoidCapt .= zen_draw_hidden_field('oID', $request['oID']);
+ $outputVoidCapt .= zen_draw_hidden_field('nn_capture_update', MODULE_PAYMENT_NOVALNET_PAYMENT_CAPTURE_CONFIRM);
+ $outputVoidCapt .= zen_draw_hidden_field('nn_void_update', MODULE_PAYMENT_NOVALNET_PAYMENT_VOID_CONFIRM);
+ $outputVoidCapt .= zen_draw_hidden_field('nn_select_status', MODULE_PAYMENT_NOVALNET_SELECT_STATUS_TEXT);
+ $outputVoidCapt .= ''.MODULE_PAYMENT_NOVALNET_SELECT_STATUS_TEXT;
+ $outputVoidCapt .= ' | ';
+ $outputVoidCapt .= zen_draw_pull_down_menu('trans_status', $options, '', 'id="trans_status"').' | ';
+ $outputVoidCapt .= ''.zen_draw_input_field('nn_manage_confirm', html_entity_decode(MODULE_PAYMENT_NOVALNET_CONFIRM_TEXT), 'class="btn btn-primary" onclick="return void_capture_status();" style="float:left"', false, 'submit').' | | ';
+ $outputVoidCapt .= '';
+ $outputVoidCapt .=' | '."\n";
+ }
+}
+
+// prepare output based on suitable content components
+$output = '';
+
+if (defined('MODULE_PAYMENT_NOVALNET_STATUS') && MODULE_PAYMENT_NOVALNET_STATUS == 'True') {
+
+ if (method_exists($this, '_doRefund')) {
+ $output .= $outputRefund;
+ }
+
+ if (method_exists($this, '_doVoid') && method_exists($this, '_doCapt')) {
+ $output .= $outputVoidCapt;
+ }
+}
+
+$output .= '';
+
+
+/**
+* Check whether refund block shown or not in admin panel
+*
+* @param array $txn_details
+*
+* @return boolean
+*/
+function isRefund($txn_details) {
+ if (($txn_details['amount'] > 0) &&
+ (($txn_details['status'] == 'CONFIRMED' && ($txn_details['amount'] != $txn_details['refund_amount'])) ||
+ ($txn_details['status']=='PENDING' &&
+ ($txn_details['amount'] > $txn_details['refund_amount']) &&
+ in_array($txn_details['payment_type'], array('INVOICE','PREPAYMENT','CASHPAYMENT')))
+ ) &&
+ !in_array($txn_details['payment_type'], array('MULTIBANCO','INSTALMENT_INVOICE','INSTALMENT_DIRECT_DEBIT_SEPA'))) {
+ return true;
+
+ } else {
+ return false;
+ }
+}
diff --git a/includes/modules/payment/novalnet/novalnet_extension.js b/includes/modules/payment/novalnet/novalnet_extension.js
new file mode 100644
index 0000000..a583f18
--- /dev/null
+++ b/includes/modules/payment/novalnet/novalnet_extension.js
@@ -0,0 +1,100 @@
+/**
+ * Novalnet payment module
+ * This script is used for handling validation of post process of
+ * Novalnet payment orders
+ *
+ * @author Novalnet AG
+ * @copyright Copyright (c) Novalnet
+ * @license https://www.novalnet.de/payment-plugins/kostenlos/lizenz
+ * @link https://www.novalnet.de
+ *
+ * Script : novalnet_extension.js
+ *
+ */
+
+jQuery(document).ready(function () {
+ let elements = jQuery(".refundBtns"),
+ nn_instalment_refund_function = function () {
+ let cycle = this.getAttribute("data-instalment"),
+ refund_id = jQuery('#instalment_refund_'+ cycle);
+
+ if (refund_id.style.display == "none") {
+ refund_id.style.display = "block";
+ } else {
+ refund_id.style.display = "none";
+ }
+ };
+
+ for (let i = 0; i < elements.length; i++) {
+ elements[i].addEventListener('click', nn_instalment_refund_function, false);
+ }
+ $(document).on('click', '#nn_instacancel_allcycles, #nn_instacancel_remaincycles, #nn_instalment_cancel', function (event) {
+ if ($("#novalnet_instalment_cancel").css({"display": "none"})) {
+ $("#novalnet_instalment_cancel").css({"display": "inline-flex"});
+ $("#nn_instalment_cancel").css({"display": "none"});
+ } else {
+ $("#novalnet_instalment_cancel").css({"display": "none"});
+ $("#nn_instalment_cancel").css({"display": "block"});
+ }
+ if (this.id == 'nn_instacancel_allcycles') {
+ if (!confirm(jQuery("[name=nn_insta_allcycles]").val())) {
+ return false;
+ }
+ } else if (this.id == 'nn_instacancel_remaincycles') {
+ if (!confirm(jQuery("[name=nn_insta_remainingcycles]").val())) {
+ return false;
+ }
+ }
+ });
+});
+
+function void_capture_status()
+{
+ if (jQuery('#trans_status').val() == '') {
+ jQuery('#nn_void_capture_error').html(jQuery("[name=nn_select_status]").val());
+ return false;
+ }
+
+ let display_status = jQuery("#trans_status").val() == 'CONFIRM' ? jQuery("[name=nn_capture_update]").val() : jQuery("[name=nn_void_update]").val();
+ if (!confirm(display_status)) {
+ return false;
+ }
+
+ let url = jQuery('#novalnet_status_change').attr('action');
+ if (jQuery("#trans_status").val() == 'CONFIRM') {
+ jQuery('#novalnet_status_change').attr('action', url + '&action=doCapture');
+ } else {
+ jQuery('#novalnet_status_change').attr('action', url + '&action=doVoid');
+ }
+ return true;
+}
+
+function refund_amount_validation()
+{
+ if (jQuery('#refund_trans_amount').val() != undefined) {
+ let amount = jQuery('#refund_trans_amount').val();
+ if (amount.trim() == '' || amount == 0 || isNaN(amount)) {
+ jQuery('#nn_refund_error').html(jQuery("[name=nn_amount_error]").val());
+ return false;
+ }
+ }
+ if (jQuery('#refund_trans_amount').val() != null) {
+ if (!confirm(jQuery("[name=nn_refund_amount_confirm]").val())) {
+ return false;
+ }
+ }
+ if (jQuery('#book_amount').val() != null) {
+ if (!confirm(jQuery("[name=nn_zero_amount_book_confirm]").val())) {
+ return false;
+ }
+ }
+}
+
+function isNumber(event) {
+ var charCode = (event.which) ? event.which : event.keyCode;
+ if (charCode > 31 && (charCode < 48 || charCode > 57)) {
+ event.preventDefault();
+ return false;
+ }
+ return true;
+}
diff --git a/includes/modules/payment/novalnet/novalnet_extension.php b/includes/modules/payment/novalnet/novalnet_extension.php
new file mode 100644
index 0000000..52c251d
--- /dev/null
+++ b/includes/modules/payment/novalnet/novalnet_extension.php
@@ -0,0 +1,195 @@
+';
+
+// Prepare output based on suitable content components
+if (defined('MODULE_PAYMENT_NOVALNET_STATUS') && MODULE_PAYMENT_NOVALNET_STATUS == 'True') {
+ $request = $_REQUEST;
+ $output = '';
+ $output .= '';
+ // Zero amount booking process
+ $order_total = $db->Execute("SELECT value FROM " . TABLE_ORDERS_TOTAL . " where class = 'ot_total' AND orders_id = " . zen_db_input($request['oID']));
+ if ($transaction_details->fields['amount'] == 0 &&
+ isset($payment_details['zero_amount_booking']) &&
+ $transaction_details->fields['status'] == 'CONFIRMED'
+ ) {
+ $amount = round($order_total->fields['value'], 2) * 100;
+ $output .= '';
+ $output .= $nn_html;
+ $output .= ' | | '."\n";
+ $output .= zen_draw_form('novalnet_book_amount', 'novalnet_extension_helper.php');
+ $output .= $nn_html. '';
+ $output .= ' | | ';
+ $output .= '';
+ $output .= ''.MODULE_PAYMENT_NOVALNET_BOOK_AMT_TITLE . ' | ';
+ $output .= zen_draw_hidden_field('oID', $request['oID']);
+ $output .= zen_draw_hidden_field('nn_zero_amount_book_confirm', MODULE_PAYMENT_NOVALNET_PAYMENT_ZERO_AMOUNT_BOOK_CONFIRM);
+ $output .= zen_draw_hidden_field('nn_amount_error', MODULE_PAYMENT_NOVALNET_AMOUNT_ERROR_MESSAGE);
+ $output .= '';
+ $output .= zen_draw_input_field('book_amount', $amount, 'id="book_amount" autocomplete="off" onkeypress="isNumber(event)" style="margin:0% 0% 0% 2%"') . MODULE_PAYMENT_NOVALNET_AMOUNT_EX . ' | ';
+ $output .= ''.zen_draw_input_field('nn_book_confirm', html_entity_decode(MODULE_PAYMENT_NOVALNET_CONFIRM_TEXT), 'class="btn btn-primary" onclick="return refund_amount_validation();" style="float:left"', false, 'submit').' | | ';
+ $output .= '';
+ $output .=' | '."\n";
+ }
+
+ // Instalment refund and cancel process
+ if (!empty($transaction_details->fields['instalment_cycle_details'])) {
+ $instalment_details = json_decode($transaction_details->fields['instalment_cycle_details'], true);
+ if (!empty($instalment_details)) {
+ $output .= '
+ ';
+ $output .= '';
+ $output .= $nn_html;
+ $output .= ' | | '."\n";
+ $output .= '';
+ $instalment_status = [];
+
+ foreach ($instalment_details as $key => $instalment_details_data) {
+ array_push($instalment_status, $instalment_details_data['status']);
+ }
+
+ $nn_instalment_canceled = false;
+ $nn_instacancel_remaining = 'style="display:block"';
+ $nn_instacancel_allcycles = 'style="display:block"';
+
+ if (in_array('Canceled', $instalment_status)) {
+ $nn_instalment_canceled = true;
+ } elseif (in_array('Refunded', $instalment_status)) {
+ $nn_instacancel_remaining = 'style="display:block"';
+ $nn_instacancel_allcycles = 'style="display:none"';
+ } elseif (in_array('Paid', $instalment_status) && !empty($instalment_details_data['reference_tid'])) {
+ $nn_instacancel_remaining = 'style="display:none"';
+ $nn_instacancel_allcycles = 'style="display:block"';
+ }
+ if (in_array('Refunded', $instalment_status) && !empty($instalment_details_data['reference_tid'])) {
+ $nn_instalment_canceled = true;
+ }
+
+ if ($nn_instalment_canceled == false) {
+ $output .= '';
+ }
+
+ $foundConfirm = true;
+ if (in_array('Refunded', $instalment_status)) {
+ foreach ($instalment_status as $status) {
+ if ($status === 'Paid') {
+ $foundConfirm = true;
+ }
+ }
+ if($foundConfirm == true){
+ $nn_instacancel_allcycles = 'style="display:block"';
+ }
+ }
+
+ if ($nn_instalment_canceled == true) {
+ foreach ($instalment_status as $status) {
+ if ($status === 'Paid') {
+ $foundConfirm = true;
+ }
+ }
+ if($foundConfirm == true){
+ $output .= '';
+ $nn_instacancel_remaining = 'style="display:none"';
+ }
+ }
+
+ $output .= zen_draw_form('nn_instalment_cancel', 'novalnet_extension_helper.php');
+ $output .= ' ' ;
+ $output .= zen_draw_hidden_field('nn_insta_allcycles', MODULE_PAYMENT_NOVALNET_ALLCYCLES_ERROR_MESSAGE);
+ $output .= zen_draw_hidden_field('nn_insta_remainingcycles', MODULE_PAYMENT_NOVALNET_REMAINING_CYCLES_ERROR_MESSAGE);
+ $output .= zen_draw_hidden_field('oID', $request['oID']);
+ $output .= zen_draw_input_field('nn_instacancel_remaincycles', html_entity_decode(MODULE_PAYMENT_NOVALNET_INSTALMENT_CANCEL_REMAINING_CYCLES), 'id="nn_instacancel_remaincycles" class="btn btn-primary" '.$nn_instacancel_remaining, false, 'submit')." ";
+ $output .= zen_draw_input_field('nn_instacancel_allcycles', html_entity_decode(MODULE_PAYMENT_NOVALNET_INSTALMENT_CANCEL_ALLCYCLES), 'id="nn_instacancel_allcycles" class="btn btn-primary" '.$nn_instacancel_allcycles, false, 'submit');
+ $output .= ' | | ';
+ $output .= '
+ S.No |
+ '.MODULE_PAYMENT_NOVALNET_INSTALMENT_REFERENCE_BACKEND.' |
+ '.MODULE_PAYMENT_NOVALNET_INSTALMENT_AMOUNT_BACKEND.' |
+ '.MODULE_PAYMENT_NOVALNET_INSTALMENT_NEXT_DATE_BACKEND.' |
+ '.MODULE_PAYMENT_NOVALNET_INSTALMENT_STATUS_BACKEND.' |
+ '.MODULE_PAYMENT_NOVALNET_INSTALMENT_REFUND_BACKEND.' |
+
+
+ | ';
+ $nn_instalment_table = '';
+ $instalment_amount = 0;
+ $status = [];
+ $sno = 1;
+
+ // Custom sorting function
+ function sortByNextInstalmentDate($a, $b) {
+ // If next_instalment_date is empty or '-', set it to PHP_INT_MAX
+ $instalmentdateA = empty($a['next_instalment_date']) || $a['next_instalment_date'] == '-' ? PHP_INT_MAX : strtotime($a['next_instalment_date']);
+ $instalmentdateB = empty($b['next_instalment_date']) || $b['next_instalment_date'] == '-' ? PHP_INT_MAX : strtotime($b['next_instalment_date']);
+ return $instalmentdateA - $instalmentdateB;
+ }
+
+ // Sorting the array using usort
+ usort($instalment_details, 'sortByNextInstalmentDate');
+
+ foreach ($instalment_details as $key => $instalment_details_data) {
+ $instalment_amount = (strpos((string) $instalment_details_data['instalment_cycle_amount'], '.')) ? $instalment_details_data['instalment_cycle_amount'] * 100 : $instalment_details_data['instalment_cycle_amount'];
+
+ if (!empty($instalment_details_data['status'])) {
+ $status = $instalment_details_data['status'];
+ } else {
+ $status = (empty($instalment_details_data['reference_tid'])) ? 'Pending' : (($instalment_amount > 0) ? 'Paid' : 'Refunded');
+ }
+
+ $status = constant('MODULE_PAYMENT_NOVALNET_INSTALMENT_STATUS_' . strtoupper($status));
+ $href = (isset($instalment_details_data['reference_tid']) && !empty($instalment_details_data['reference_tid']) != '' && $instalment_amount != '0' && $instalment_amount > 0 && $status != constant('MODULE_PAYMENT_NOVALNET_INSTALMENT_STATUS_REFUNDED')) ? " " : '';
+ $instalment_amount_formatted = !empty($instalment_amount) ? $currencies->format($instalment_amount/100, 1, $order->info['currency']) : '-';
+
+
+ $instalment_original_amount= isset($instalment_details_data['instalment_cycle_amount_orginal_amount']) ? $currencies->format($instalment_details_data['instalment_cycle_amount_orginal_amount']/100, 1, $order->info['currency']) : '';
+
+ $nn_instalment_table .= "".$sno++." |
+ ".(isset($instalment_details_data['reference_tid']) ? $instalment_details_data['reference_tid'] : '')." |
+ ".$instalment_original_amount." |
+ ".(isset($instalment_details_data['next_instalment_date']) && !empty(trim($instalment_details_data['next_instalment_date'])) && trim($instalment_details_data['next_instalment_date']) != "-" ? NovalnetHelper::format_date( $instalment_details_data['next_instalment_date']) : '').
+ " | $status |
+ ".$href." | ";
+ $nn_instalment_table .= ''.zen_draw_form('nn_refund_confirm', 'novalnet_extension_helper.php');
+ $nn_instalment_table .= '' ;
+ $nn_instalment_table .= zen_draw_hidden_field('oID', $request['oID']);
+ $nn_instalment_table .= zen_draw_hidden_field('refund_tid', (isset($instalment_details_data['reference_tid']) ? $instalment_details_data['reference_tid'] : ''));
+ $nn_instalment_table .= zen_draw_hidden_field('instalment_cycle', ''.$key.'');
+ $nn_instalment_table .= zen_draw_hidden_field('nn_amount_error', MODULE_PAYMENT_NOVALNET_AMOUNT_ERROR_MESSAGE);
+ $nn_instalment_table .= zen_draw_hidden_field('nn_refund_amount_confirm', MODULE_PAYMENT_NOVALNET_PAYMENT_REFUND_CONFIRM);
+ $nn_instalment_table .= zen_draw_input_field('refund_trans_amount', $instalment_amount, 'id="refund_trans_amount" onkeypress="isNumber(event)" style="width:100px;margin:0 0 0 2%" autocomplete="off"')." ";
+ $nn_instalment_table .= zen_draw_input_field('nn_refund_confirm', html_entity_decode(MODULE_PAYMENT_NOVALNET_CONFIRM_TEXT), 'class="btn btn-primary"', false, 'submit')." " ;
+ $nn_instalment_table .= " " . MODULE_PAYMENT_NOVALNET_INSTALMENT_CANCEL_TEXT . "";
+ $nn_instalment_table .= ' | ';
+ }
+
+ $nn_instalment_table .=' | '."\n";
+ $output .= $nn_instalment_table;
+ }
+ }
+
+ $output .= '';
+}