diff --git a/extras/novalnet_callback.php b/extras/novalnet_callback.php new file mode 100644 index 0000000..7e3c9d1 --- /dev/null +++ b/extras/novalnet_callback.php @@ -0,0 +1,856 @@ + array('CREDITCARD','CREDITCARD_BOOKBACK','CREDITCARD_CHARGEBACK','CREDIT_ENTRY_CREDITCARD','DEBT_COLLECTION_CREDITCARD','TRANSACTION_CANCELLATION'), + 'novalnet_sepa' => array('DIRECT_DEBIT_SEPA','RETURN_DEBIT_SEPA','CREDIT_ENTRY_SEPA','DEBT_COLLECTION_SEPA','REFUND_BY_BANK_TRANSFER_EU','TRANSACTION_CANCELLATION'), + 'novalnet_guarantee_sepa' => array('RETURN_DEBIT_SEPA','GUARANTEED_DIRECT_DEBIT_SEPA','GUARANTEED_SEPA_BOOKBACK','REFUND_BY_BANK_TRANSFER_EU','TRANSACTION_CANCELLATION'), + 'novalnet_ideal'=> array('IDEAL','REFUND_BY_BANK_TRANSFER_EU','ONLINE_TRANSFER_CREDIT','REVERSAL','CREDIT_ENTRY_DE','DEBT_COLLECTION_DE'), + 'novalnet_eps' => array('EPS','REFUND_BY_BANK_TRANSFER_EU','ONLINE_TRANSFER_CREDIT','REVERSAL','CREDIT_ENTRY_DE','DEBT_COLLECTION_DE'), + 'novalnet_giropay' => array('GIROPAY','REFUND_BY_BANK_TRANSFER_EU','ONLINE_TRANSFER_CREDIT','REVERSAL','CREDIT_ENTRY_DE','DEBT_COLLECTION_DE'), + 'novalnet_banktransfer' => array('ONLINE_TRANSFER','REFUND_BY_BANK_TRANSFER_EU','ONLINE_TRANSFER_CREDIT','REVERSAL','CREDIT_ENTRY_DE','DEBT_COLLECTION_DE'), + 'novalnet_PayPal' => array('PAYPAL','PAYPAL_BOOKBACK','TRANSACTION_CANCELLATION'), + 'novalnet_prepayment' => array('INVOICE_START','INVOICE_CREDIT','REFUND_BY_BANK_TRANSFER_EU'), + 'novalnet_invoice' => array('INVOICE_START','INVOICE_CREDIT','REFUND_BY_BANK_TRANSFER_EU','TRANSACTION_CANCELLATION','CREDIT_ENTRY_DE','DEBT_COLLECTION_DE'), + 'novalnet_guarantee_invoice' => array('GUARANTEED_INVOICE','GUARANTEED_INVOICE_BOOKBACK','REFUND_BY_BANK_TRANSFER_EU','TRANSACTION_CANCELLATION'), + 'novalnet_przelewy24' => array('PRZELEWY24','PRZELEWY24_REFUND'), + 'novalnet_cashpayment' => array('CASHPAYMENT','CASHPAYMENT_REFUND','CASHPAYMENT_CREDIT'), + 'novalnet_instalment_invoice' => array('INSTALMENT_INVOICE','INSTALMENT_INVOICE_BOOKBACK','TRANSACTION_CANCELLATION'), + 'novalnet_instalment_sepa' => array('INSTALMENT_DIRECT_DEBIT_SEPA','INSTALMENT_SEPA_BOOKBACK', + 'TRANSACTION_CANCELLATION'), + 'novalnet_postfinance' => array('POSTFINANCE', 'POSTFINANCE_REFUND'), + 'novalnet_postfinance_card' => array('POSTFINANCE_CARD', 'POSTFINANCE_REFUND'), + ); + + /** + * Mandatory Parameters. + * + * @var array + */ + protected $required_params = array( + 'vendor_id', + 'status', + 'payment_type', + 'tid_status', + 'tid', + ); + + /** + * Novalnet success codes. + * + * @var array + */ + protected $success_code = array( + 'PAYPAL' => array('100', '90','85'), + 'INVOICE_START' => array('100','91'), + 'INSTALMENT_INVOICE' => array('100','91','75'), + 'GUARANTEED_INVOICE' => array('100','91','75'), + 'CREDITCARD' => array('100','98'), + 'DIRECT_DEBIT_SEPA' => array('100','99'), + 'INSTALMENT_DIRECT_DEBIT_SEPA' => array('100','99','75'), + 'GUARANTEED_DIRECT_DEBIT_SEPA' => array('100','99','75'), + 'ONLINE_TRANSFER' => array('100'), + 'ONLINE_TRANSFER_CREDIT' => array('100'), + 'GIROPAY' => array('100'), + 'IDEAL' => array('100'), + 'EPS' => array('100'), + 'PRZELEWY24' => array('100','86'), + 'CASHPAYMENT' => array('100'), + 'POSTFINANCE_CARD' => array('100','83'), + 'POSTFINANCE' => array('100','83'), + ); + + /** + * construct + * + * @return none + */ + public function __construct($request) + { + $this->validate_ipaddress(); + + $this->server_request = $this->validate_server_request($request); + + $this->order_reference = $this->get_order_reference(); + include_once( DIR_FS_CATALOG . DIR_WS_INCLUDES .'languages/' . $this->order_reference['nn_order_lang'] . '/modules/payment/novalnet.php'); + $this->transaction_cancellation($this->order_reference); + + $payment_type_level = $this->get_payment_type(); + + $this->formatted_amount = sprintf('%0.2f', $this->server_request['amount'] / 100) .' '. $this->server_request['currency']; + + switch($payment_type_level) { + case 0: + $this->zero_level_process(); + break; + case 1: + $this->first_level_process(); + break; + case 2: + $this->second_level_process(); + break; + default: + $this->display_message('Novalnet Callbackscript received. Payment type ( ' . $this->server_request['payment_type'] . ' ) is not applicable for this process!'); + break; + } + $this->display_message(($this->server_request['tid_status'] != '100' || $this->server_request['status'] != '100') ? 'Novalnet callback received. Status is not valid.' : 'Novalnet callback received. Callback Script executed already.'); + } + + /** + * Payment types of Level 0 - Initial level payments processing + * + * @return none + */ + public function zero_level_process() + { + global $db; + + if (in_array($this->server_request['payment_type'], $this->payments, true ) && $this->server_request['status'] == '100' && in_array($this->server_request['tid_status'], $this->success_code[$this->server_request['payment_type']], true)) { + if (in_array( $this->server_request['payment_type'], array('INSTALMENT_INVOICE', 'INSTALMENT_DIRECT_DEBIT_SEPA')) && isset($this->server_request['instalment_billing']) && $this->server_request['instalment_billing'] == '1' && $this->server_request['tid_status'] == '100' && $this->server_request['status'] == '100' ) { + $comments = NovalnetUtil::formPaymentComments($this->server_request['tid'], $this->server_request['test_mode']); + $amount = sprintf('%0.2f', $this->server_request['amount'] / 100); + if ($this->server_request['payment_type'] == 'INSTALMENT_INVOICE') { + $comments .= PHP_EOL . PHP_EOL . NovalnetUtil::formInvoicePrepaymentComments($this->server_request, $amount); + $comments .= PHP_EOL . NovalnetUtil::novalnetReferenceComments($this->server_request['order_no'],$this->server_request, $this->order_reference['payment_type']); + } + if ($this->server_request['payment_type'] == 'INSTALMENT_DIRECT_DEBIT_SEPA') { + $comments .= PHP_EOL.PHP_EOL . sprintf(MODULE_PAYMENT_NOVALNET_INSTALMENT_SEPA_INFO, $amount, $this->server_request['currency']); + } + + $comments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_INFO; + $comments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_PROCESSED . (!empty($this->server_request['instalment_cycles_executed']) ? $this->server_request['instalment_cycles_executed'] : '') ; + $comments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_DUE . (isset($this->server_request['due_instalment_cycles']) ? $this->server_request['due_instalment_cycles'] : ''); + + $amount = (!empty($this->server_request['instalment_cycle_amount']) ? $this->server_request['instalment_cycle_amount'] : $this->server_request['amount']); + $amount = sprintf('%0.2f', $amount / 100); + + $comments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_NXT_AMOUNT .$amount. ' '.$this->server_request['currency'] ; + + $instalment = unserialize($this->order_reference['instalment_details']); + + $instalment[$this->server_request['instalment_cycles_executed']] = array( + 'amount' => ($this->server_request['amount']) ? sprintf('%0.2f', $this->server_request['amount'] / 100) : '', + 'nextCycle' => ($this->server_request['next_instalment_date']) ? $this->server_request['next_instalment_date'] : '', + 'paidDate' => ($this->server_request['tid_status'] == '100') ? date('Y-m-d') : '', + 'status' => 'Paid', + 'reference' => !empty($this->server_request['tid']) ? $this->server_request['tid'] : '' + ); + + $instalment_details = serialize($instalment); + + $param['gateway_status'] = $this->server_request['tid_status']; + $param['instalment_details'] = serialize($instalment); + zen_db_perform('novalnet_transaction_detail', $param, "update", "tid='" . $this->server_request['shop_tid'] . "'"); + + $payment_name = strtoupper($this->order_reference['payment_type']); + + $order_status = NovalnetUtil::checkDefaultOrderStatus(constant('MODULE_PAYMENT_' . $payment_name . '_ORDER_STATUS_ID')); + + $db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status= " . $order_status . " where orders_id=" . $this->order_reference['order_no']); + + $this->update_final_comments($this->server_request, $comments, $order_status, $this->order_reference['order_no']); + } + $this->update_pending_payments(); + + // After execution. + $this->display_message('Novalnet Callbackscript received. Payment type ( ' . $this->server_request['payment_type'] . ' ) is not applicable for this process!'); + } + } + + /** + * Payment types of Level 1 - Chargeback payments processing + * + * @return none + */ + public function first_level_process() + { + if (in_array( $this->server_request['payment_type'], $this->chargebacks, true ) && $this->server_request['tid_status'] == '100' && $this->server_request['status'] == '100') { + $comments = MODULE_PAYMENT_NOVALNET_CALLBACK_CHARGEBACK; + if ( in_array( $this->server_request['payment_type'], array( 'PAYPAL_BOOKBACK', 'CREDITCARD_BOOKBACK', 'REFUND_BY_BANK_TRANSFER_EU', 'PRZELEWY24_REFUND', 'POSTFINANCE_REFUND', 'CASHPAYMENT_REFUND', 'GUARANTEED_INVOICE_BOOKBACK', 'GUARANTEED_SEPA_BOOKBACK', 'INSTALMENT_SEPA_BOOKBACK', 'INSTALMENT_INVOICE_BOOKBACK' ), true ) ) { + $comments = MODULE_PAYMENT_NOVALNET_CALLBACK_BOOKBACK; + } + $callback_comments = sprintf($comments, $this->server_request['shop_tid'], $this->formatted_amount, date('Y-m-d H:i:s'), $this->server_request['tid']) . PHP_EOL; + //Update the comments , order id and status id in Novalnet table + $this->update_final_comments($this->server_request, $callback_comments, $this->order_reference['order_current_status'], $this->order_reference['order_no']); + } + } + + /** + * Payment types of Level 2 - Credit entry and collection payments processing + * + * @return none + */ + public function second_level_process() + { + if (in_array($this->server_request['payment_type'], $this->collections) && $this->server_request['tid_status'] == '100' && $this->server_request['status'] == '100') { + + if (in_array($this->server_request['payment_type'], array('INVOICE_CREDIT', 'ONLINE_TRANSFER_CREDIT', 'CASHPAYMENT_CREDIT'))) { + + if ($this->order_reference['order_paid_amount'] < $this->order_reference['order_total_amount']) { + $callback_comments = sprintf(MODULE_PAYMENT_NOVALNET_CALLBACK_CREDIT, $this->server_request['shop_tid'], $this->formatted_amount, date('Y-m-d H:i:s'), $this->server_request['tid']); + + $callback_status_id = NovalnetUtil::checkDefaultOrderStatus(constant('MODULE_PAYMENT_'.strtoupper($this->order_reference['payment_type']).'_ORDER_STATUS_ID')); + + $total_amount = $this->order_reference['order_paid_amount'] + $this->server_request['amount']; + if ($this->order_reference['order_total_amount'] <= $total_amount) { + $callback_status_id = NovalnetUtil::checkDefaultOrderStatus(constant('MODULE_PAYMENT_'.strtoupper($this->order_reference['payment_type']).'_CALLBACK_STATUS_ID')); + $callback_comments .= ($this->order_reference['order_total_amount'] < $total_amount) ? ' Paid amount is greater than Order amount.' : ''; + } + + //Update callback order status due to full payment + zen_db_perform(TABLE_ORDERS, array( + 'orders_status' => $callback_status_id + ), 'update', 'orders_id="' . $this->order_reference['order_no'] . '"'); + + $this->update_final_comments($this->server_request, $callback_comments, $callback_status_id, $this->order_reference['order_no'], $total_amount); + } + $this->display_message('Novalnet callback script executed already'); + } else { + $callback_comments = sprintf(MODULE_PAYMENT_NOVALNET_CALLBACK_CREDIT, $this->server_request['shop_tid'], $this->formatted_amount, date('Y-m-d H:i:s'), $this->server_request['tid']); + + $callback_status_id = $this->order_reference['order_current_status']; + + $this->update_final_comments($this->server_request, $callback_comments, $callback_status_id, $this->order_reference['order_no']); + } + $this->display_message('Novalnet Callbackscript received. Payment type ( ' . $this->server_request['payment_type'] . ' ) is not applicable for this process!' ); + } + } + + /** + * Update pending payments. + * + * @return none + */ + public function update_pending_payments() + { + global $db; + if (isset($this->order_reference['gateway_status'] ) && $this->order_reference['gateway_status'] != 100 ) { + $comments = $callback_comments = ''; + $param = array(); + $paymentName = strtoupper($this->order_reference['payment_type']); + + if ($this->server_request['payment_type'] =='PAYPAL' && in_array($this->order_reference['gateway_status'] , array(85, 90))){ + if ($this->order_reference['gateway_status'] == 85 && $this->server_request['tid_status'] == 90) { + $order_status = MODULE_PAYMENT_NOVALNET_PAYPAL_PENDING_ORDER_STATUS_ID; + $callback_comments .= PHP_EOL . sprintf(MODULE_PAYMENT_NOVALNET_CALLBACK_HOLD_TO_PENDING, $this->server_request['shop_tid'], date('Y-m-d H:i:s') ) . PHP_EOL; + } elseif (in_array($this->order_reference['gateway_status'], array(85, 90)) && $this->server_request['tid_status'] == 100) { + $order_status = MODULE_PAYMENT_NOVALNET_PAYPAL_ORDER_STATUS_ID; + $callback_comments = PHP_EOL . sprintf(MODULE_PAYMENT_NOVALNET_CALLBACK_CONFIRM, date('Y-m-d H:i:s')) . PHP_EOL; + } + $order_status = NovalnetUtil::checkDefaultOrderStatus($order_status); + + $db->Execute("UPDATE novalnet_transaction_detail SET gateway_status= " . $this->server_request['tid_status'] . " where order_no=" . $this->order_reference['order_no']); + + $db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status= " . $order_status . " where orders_id=" . $this->order_reference['order_no']); + + $this->update_final_comments($this->server_request, $callback_comments, $order_status, $this->order_reference['order_no']); + } elseif (in_array($this->server_request['payment_type'], array('PAYPAL', 'PRZELEWY24')) && $this->server_request['tid_status'] == 100) { + if ($this->order_reference['callback_amount'] <= 0 ) { + $callback_comments = PHP_EOL . sprintf(MODULE_PAYMENT_NOVALNET_CALLBACK_EXECUTE, $this->server_request['shop_tid'], $this->formatted_amount, date('Y-m-d H:i:s')) . PHP_EOL; + + $order_status = NovalnetUtil::checkDefaultOrderStatus(constant('MODULE_PAYMENT_' . $paymentName . '_ORDER_STATUS_ID')); + + $db->Execute("UPDATE novalnet_transaction_detail SET gateway_status= " . $this->server_request['tid_status'] . " where order_no=" . $this->order_reference['order_no']); + + $db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status= " . $order_status . " where orders_id=" . $this->order_reference['order_no']); + + $this->update_final_comments($this->server_request, $callback_comments, $order_status, $this->order_reference['order_no']); + } + $this->display_message('Novalnet Callbackscript received. Order already Paid'); + + } else if (in_array($this->server_request['payment_type'], array('POSTFINANCE','POSTFINANCE_CARD')) && $this->order_reference['gateway_status'] == 83 && $this->server_request['tid_status'] == 100 && $this->server_request['status'] == 100) { + $callback_comments = PHP_EOL . sprintf(MODULE_PAYMENT_NOVALNET_CALLBACK_CONFIRM, date('Y-m-d H:i:s')) . PHP_EOL; + + $order_status = NovalnetUtil::checkDefaultOrderStatus(constant('MODULE_PAYMENT_' . $paymentName . '_ORDER_STATUS_ID')); + + $db->Execute("UPDATE novalnet_transaction_detail SET gateway_status= " . $this->server_request['tid_status'] . " where order_no=" . $this->order_reference['order_no']); + + $db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status= " . $order_status . " where orders_id=" . $this->order_reference['order_no']); + + $this->update_final_comments($this->server_request, $callback_comments, $order_status, $this->order_reference['order_no']); + } elseif ($this->server_request['payment_type'] == 'PRZELEWY24' && $this->server_request['tid_status'] != '86') { + //Handle Przelewy cancel + $message = $this->updatePrzelewyCancelcomments($this->order_reference); + $this->display_message($message); + } elseif (in_array($this->server_request['payment_type'], $this->payments)) { + if (in_array($this->server_request['tid_status'], array(99, 91) ) && $this->order_reference['gateway_status'] == 75) { + $order_status = NovalnetUtil::checkDefaultOrderStatus(MODULE_PAYMENT_NOVALNET_ONHOLD_ORDER_COMPLETE_STATUS_ID); + $callback_comments .= sprintf(MODULE_PAYMENT_NOVALNET_CALLBACK_PENDING_TO_HOLD, $this->server_request['shop_tid'], date('Y-m-d H:i:s') ); + $callback_comments .= NovalnetUtil::formPaymentComments($this->server_request['shop_tid'], $this->server_request['test_mode']); + + if (in_array($this->server_request['payment_type'], array('INSTALMENT_INVOICE', 'GUARANTEED_INVOICE'))) { + $amount = sprintf('%0.2f', $this->server_request['amount'] / 100); + $callback_comments .= PHP_EOL . PHP_EOL . NovalnetUtil::formInvoicePrepaymentComments($this->server_request, $amount); + + $callback_comments .= NovalnetUtil::novalnetReferenceComments($this->server_request['order_no'],$this->server_request, $this->order_reference['payment_type']); + } + + } elseif($this->server_request['tid_status'] == 100 && in_array($this->order_reference['gateway_status'], array(75,98,91,99))) { + $order_status = NovalnetUtil::checkDefaultOrderStatus(constant('MODULE_PAYMENT_'.$paymentName.'_ORDER_STATUS_ID')); + $comments = ''; + if (in_array($this->server_request['payment_type'],array('INSTALMENT_INVOICE', 'INSTALMENT_DIRECT_DEBIT_SEPA', 'GUARANTEED_INVOICE', 'GUARANTEED_DIRECT_DEBIT_SEPA'))) { + $comments .= NovalnetUtil::formPaymentComments($this->server_request['shop_tid'], $this->server_request['test_mode']); + + if (in_array($this->server_request['payment_type'], array ('INSTALMENT_INVOICE', 'GUARANTEED_INVOICE'))) { + $amount = sprintf('%0.2f', $this->server_request['amount'] / 100); + $comments .= PHP_EOL . PHP_EOL . NovalnetUtil::formInvoicePrepaymentComments($this->server_request, $amount); + + $comments .= NovalnetUtil::novalnetReferenceComments($this->server_request['order_no'],$this->server_request, $this->order_reference['payment_type']); + } + if(in_array($this->server_request['payment_type'],array('INSTALMENT_INVOICE', 'INSTALMENT_DIRECT_DEBIT_SEPA'))) { + $comments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_INFO; + $comments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_PROCESSED . (!empty($this->server_request['instalment_cycles_executed']) ? $this->server_request['instalment_cycles_executed'] : '') ; + $comments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_DUE . (isset($this->server_request['due_instalment_cycles']) ? $this->server_request['due_instalment_cycles'] : ''); + $amount = (!empty($this->server_request['instalment_cycle_amount']) ? $this->server_request['instalment_cycle_amount'] : $this->server_request['amount']); + $amount = sprintf('%0.2f', $amount / 100); + + $comments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_NXT_AMOUNT .$amount. ' '.$this->server_request['currency'] ; + if ($future_instalment = $this->server_request['future_instalment_dates']) { + $future_instalments = explode('|', $future_instalment); + foreach ($future_instalments as $future_instalment) { + $cycle = strtok($future_instalment, "-"); + $cycle_date = explode('-', $future_instalment, 2); + $instalment_details[$cycle] = [ + 'amount' => ($this->server_request['amount']) ? sprintf('%0.2f', $this->server_request['amount'] / 100) : '', + 'nextCycle' => $cycle_date[1], + 'paidDate' => ($cycle == 1) ? date('Y-m-d') : '', + 'status' => ($cycle == 1) ? 'Paid' : 'Pending', + 'reference' => ($cycle == 1) ? $this->server_request['shop_tid'] : '' + ]; + } + } + $instalment_details = serialize($instalment_details); + $param['gateway_status'] = $this->server_request['tid_status']; + $param['instalment_details'] = $instalment_details; + zen_db_perform('novalnet_transaction_detail', $param, "update", "tid='" . $this->server_request['shop_tid'] . "'"); + } + } + $callback_comments .= $comments . PHP_EOL. sprintf(MODULE_PAYMENT_NOVALNET_CALLBACK_CONFIRM, date('Y-m-d H:i:s')) . PHP_EOL; + } + + if(in_array($this->server_request['payment_type'],array('INSTALMENT_INVOICE', 'GUARANTEED_INVOICE', 'INVOICE_START')) && in_array($this->order_reference['gateway_status'], array(75, 91)) && $this->server_request['tid_status'] == 100) { + $this->sentPaymentConfirmationMail($callback_comments); + } + + $param ['gateway_status'] = $this->server_request['tid_status']; + $order_status = NovalnetUtil::checkDefaultOrderStatus($order_status); + + zen_db_perform('novalnet_transaction_detail', $param, "update", "tid='" . $this->server_request['shop_tid'] . "'"); + // Update the order status in shop + zen_db_perform(TABLE_ORDERS, array( + 'orders_status' => $order_status + ), 'update', 'orders_id="' . $this->order_reference['order_no'] . '"'); + // To update order details in shop + $this->update_callback_comments(array( + 'order_no' => $this->order_reference['order_no'], + 'orders_status_id' => $order_status, + 'comments' => $callback_comments + )); + // Send notification mail to Merchant + $this->send_notify_mail(array( + 'comments' => $callback_comments, + 'order_no' => $this->order_reference['order_no'], + )); + } else { + + $this->display_message('Novalnet Callbackscript received Payment type ( ' . $this->server_request['payment_type'] . ' ) is not applicable for this process!'); + } + } + } + + /** + * Validate ip address + * + * @return none + */ + public function validate_ipaddress() + { + $remote_ip = zen_get_ip_address(); + + $remote_ip = (filter_var($remote_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || empty($remote_ip)) ? '127.0.0.1' : $remote_ip; + + $get_host_name = gethostbyname('pay-nn.de'); + if (empty($get_host_name)) { + $this->display_message('Novalnet HOST IP missing'); + } + + if ($remote_ip != $get_host_name && MODULE_PAYMENT_NOVALNET_CALLBACK_TEST_MODE == 'False') { + $this->display_message("Novalnet callback received. Unauthorised access from the IP " . $remote_ip); + } + } + + /** + * Validate callback request param + * + * @param $request array + * + * @return none + */ + public function validate_server_request($request) + { + $this->required_params[] = $shop_tid = $this->get_required_tid($request); + + // Validate the callback mandatory request parameters. + $this->validate_required_fields($this->required_params, $request); + + if (!empty($request['payment_type']) && !in_array($request['payment_type'], array_merge($this->payments, $this->chargebacks, $this->collections, $this->cancellation), true)) { + $this->display_message('Novalnet callback received. Payment type ( ' . $request['payment_type'] . ' ) is mismatched!'); + } + + $request['shop_tid'] = $request[$shop_tid]; + + return $request; + } + + /** + * Validate request param + * + * @param $required_params array + * @param $request array + * + * @return none + */ + public function validate_required_fields($required_params, $request) { + + foreach ($required_params as $params) { + if (empty($request[$params])) { + $this->display_message( "Required param ( $params ) missing!" ); + } elseif (in_array($params, array( 'tid', 'tid_payment', 'instalment_tid' ), true ) && ! preg_match( '/^\d{17}$/', $request[ $params])) { + $this->display_message('Novalnet callback received. Invalid TID [ ' . $request[$params] . ' ] for Order.'); + } + } + } + + /** + * Get tid details + * + * @param $request array + * + * @return integer + */ + public function get_required_tid( $request ) { + + $shop_tid = 'tid'; + if (in_array($request['payment_type'], array_merge( $this->chargebacks, $this->collections ), true ) ) { // Collection Payments or Chargeback Payments + if (in_array($request['payment_type'], array('INSTALMENT_INVOICE_BOOKBACK', 'INSTALMENT_SEPA_BOOKBACK' ))) { + $shop_tid = 'instalment_tid'; + } else { + $shop_tid = 'tid_payment'; + } + } + if (in_array($request['payment_type'], array( 'INSTALMENT_DIRECT_DEBIT_SEPA', 'INSTALMENT_INVOICE' )) && $request['instalment_billing'] == '1' ) { // Instalment Payments + $shop_tid = 'instalment_tid'; + } + return $shop_tid; + } + + /** + * Get order details + * + * @return array + */ + public function get_order_reference() { + global $db; + + if (in_array($this->server_request['payment_type'], array_merge($this->payments,$this->cancellation))) { + $tid = zen_db_input($this->server_request['shop_tid']); + } elseif (in_array($this->server_request['payment_type'], $this->chargebacks)) { + $tid = zen_db_input($this->server_request['shop_tid']); + } elseif (in_array($this->server_request['payment_type'], $this->collections)) { + $tid = zen_db_input($this->server_request['tid_payment']); + } + if (!empty($this->server_request['order_no'])){ + $db_val = $db->Execute("SELECT order_no, amount, payment_id, payment_type,language,callback_amount,gateway_status,instalment_details from novalnet_transaction_detail where order_no = '" .$this->server_request['order_no']. "'"); + } else { + $db_val = $db->Execute("SELECT order_no, amount, payment_id, payment_type,language,callback_amount,gateway_status,instalment_details from novalnet_transaction_detail where tid = '" .$tid. "'"); + } + $db_val = $db_val->fields; + $db_val['tid'] = $this->server_request['shop_tid']; + + if (!empty($db_val)) { + if(is_array($this->payment_groups[$db_val['payment_type']])) { + if (!in_array($this->server_request['payment_type'], $this->payment_groups[$db_val['payment_type']])) { + $this->display_message('Novalnet callback received. Payment Type [' . $this->server_request['payment_type'] . '] is not valid.'); + } + } + + $order_no = (!empty($this->server_request['order_no']) ? $this->server_request['order_no'] : ''); + if (!empty($order_no)) { + $order_detail = $db->Execute('SELECT orders_id FROM '.TABLE_ORDERS.' WHERE orders_id = '.zen_db_input($order_no)); + if ( empty($order_detail) ) { + $this->sentCriticalMail(); + } + } + + if (!empty($order_no) && $order_no != $db_val['order_no']) { + $this->display_message('Novalnet callback received. Order Number is not valid.'); + } + + $db_val['nn_order_lang'] = $db_val['language']; + $db_val['order_current_status'] = $this->getOrderCurrentStatus($db_val['order_no']); + + if (in_array($db_val['payment_type'], array('novalnet_invoice', 'novalnet_prepayment'))) { + $db_val['callback_script_status'] = constant('MODULE_PAYMENT_' . strtoupper($db_val['payment_type']) . '_CALLBACK_STATUS_ID'); + } + $db_val['order_total_amount'] = $db_val['amount']; + $db_val['order_paid_amount'] = isset($db_val['callback_amount']) ? $db_val['callback_amount'] : 0; + + } else { + $this->display_message('Novalnet callback script order number not valid'); + } + + return $db_val; + } + + /** + * Get orders_status from the orders table on shop database + * + * @param $order_id integer + * + * @return array + */ + function getOrderCurrentStatus($order_id = '') + { + global $db; + $db_val = $db->Execute("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . $order_id . "'"); + return NovalnetUtil::checkDefaultOrderStatus($db_val->fields['orders_status']); + } + + /** + * Update Przelewy24 cancel status + * + * @param $nntrans_history array + * + * @return string + */ + function updatePrzelewyCancelcomments($nntrans_history) + { + $nncapture_params = $this->server_request(); + $callback_status_id = NovalnetUtil::checkDefaultOrderStatus($nntrans_history['callback_script_status']); + + // Assign przelewy24 payment status + zen_db_perform(TABLE_ORDERS, array( + 'orders_status' => $callback_status_id + ), 'update', 'orders_id="' . $nntrans_history['order_no'] . '"'); + + // Form failure comments + $comments = !empty($nncapture_params['status_text']) ? PHP_EOL . $nncapture_params['status_text'] : (!empty($nncapture_params['status_desc']) ? PHP_EOL . $nncapture_params['status_desc'] : (!empty($nncapture_params['status_message']) ? PHP_EOL . $nncapture_params['status_message'] : '')); + $callback_comments = sprintf('The transaction has been canceled due to: %s', $comments); + + $this->update_callback_comments(array('order_no' => $nntrans_history['order_no'], 'comments' => $callback_comments, + 'orders_status_id' => $callback_status_id)); + + return $callback_comments; + } + + /** + * Handle transaction_cancellation process + * + * $param $order_reference array + * + * @return none + */ + function transaction_cancellation($order_reference) + { + if ($this->server_request['payment_type'] == 'TRANSACTION_CANCELLATION') { + + // To form the callback comments + $callback_comments = sprintf(MODULE_PAYMENT_NOVALNET_CALLBACK_CANCEL, date('Y-m-d H:i:s')); + + $param ['gateway_status'] = $this->server_request['tid_status']; + zen_db_perform('novalnet_transaction_detail', $param, "update", "tid='" . $this->server_request['shop_tid'] . "'"); + $order_status = NovalnetUtil::checkDefaultOrderStatus(MODULE_PAYMENT_NOVALNET_ONHOLD_ORDER_CANCELLED_STATUS_ID); + //Update callback order status due to full payment + zen_db_perform(TABLE_ORDERS, array( + 'orders_status' => $order_status + ), 'update', 'orders_id="' . $order_reference['order_no'] . '"'); + + // To update order details in shop + $this->update_callback_comments(array( + 'order_no' => $order_reference['order_no'], + 'orders_status_id' => $order_status, + 'comments' => $callback_comments + )); + // Send notification mail to Merchant + $this->send_notify_mail(array( + 'comments' => $callback_comments, + 'order_no' => $order_reference['order_no'], + )); + } + } + + /** + * Get given payment_type level for process + * + * @return integer + */ + function get_payment_type() + { + if (in_array($this->server_request['payment_type'], $this->payments)) + return 0; + if (in_array($this->server_request['payment_type'], $this->chargebacks)) + return 1; + if (in_array($this->server_request['payment_type'], $this->collections)) + return 2; + } + + /** + * update callback comments + * + * @param $server_request + * @param $comments + * @param $callback_status_id + * @param $order_id + * @param $total_amount + * + * @return none + */ + function update_final_comments($server_request, $comments, $callback_status_id, $order_id, $total_amount = '') + { + $this->update_callback_comments(array('order_no' => $order_id, 'comments' => $comments, 'orders_status_id' => $callback_status_id)); + $this->logCallbackProcess($server_request, $order_id, $total_amount); + $this->send_notify_mail(array('comments' => $comments, 'order_no' => $order_id)); + } + + /** + * Log callback process in novalnet_transaction_detail table + * @param $datas + * @param $order_no + * @param $total_amount + * + * @return none + */ + function logCallbackProcess($datas, $order_no, $total_amount) + { + global $db; + if (!empty($datas['amount'])) { + $datas['amount'] = !empty($total_amount) ? $total_amount : $datas['amount']; + $db->Execute("UPDATE novalnet_transaction_detail SET callback_amount= " . $datas['amount'] . " where order_no=$order_no"); + } + } + + /** + * Update Callback comments in orders_status_history table + * @param $datas + * + * @return none + */ + function update_callback_comments($datas) + { + global $db; + $comments = ((!empty($datas['comments'])) ? $datas['comments'] : ''); + $db->Execute("INSERT INTO " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) VALUES ('" . $datas['order_no'] . "', '" . $datas['orders_status_id'] . "', NOW(), '1','$comments')"); + } + + /** + * Send notify mail + * + * @param $message + * + * @return none + */ + function send_notify_mail($message) { + // Check for callback notification + if (MODULE_PAYMENT_NOVALNET_CALLBACK_MAIL_SEND == 'True' && NovalnetUtil::validateEmail(strip_tags(MODULE_PAYMENT_NOVALNET_CALLBACK_MAIL_TO))) { + // Get E-mail to address + $email_to = ((strip_tags(MODULE_PAYMENT_NOVALNET_CALLBACK_MAIL_TO) != '') ? strip_tags(MODULE_PAYMENT_NOVALNET_CALLBACK_MAIL_TO) : STORE_OWNER_EMAIL_ADDRESS); + + // Get E-mail to name + $email_to_name = (strpos($email_to,',')) ? '' : STORE_OWNER; + + // Assign Mail subject + $email_subject = 'Novalnet Callback script notification - '. STORE_NAME; + + if ($email_to != '') { + // Send E-mail + zen_mail($email_to_name ,$email_to, $email_subject, $message['comments'] , STORE_NAME, EMAIL_FROM); + echo 'Mail sent!
'; + } else { + echo 'Mail not sent!'; + } + } + + // Display message + $this->display_message($message['comments']); + } + + /** + * sent payment confirmation mail to customer. + * + * @param $comments string + * + * @return string + */ + function sentPaymentConfirmationMail($comments) + { + $customer_details = $this->get_customer_details($this->server_request['customer_id']); + $customer_name = $customer_details['customers_firstname'] . ' ' . $customer_details['customers_lastname']; + $email_subject = sprintf(MODULE_PAYMENT_GUARANTEE_PAYMENT_MAIL_SUBJECT, $this->order_reference['order_no'],STORE_NAME); + $email_content = 'Dear Mr./Ms./Mrs. '. $customer_name .'

' . MODULE_PAYMENT_GUARANTEE_PAYMENT_MAIL_MESSAGE.'

Payment Information:

' . nl2br($comments) .'
'; + + zen_mail($customer_name, $customer_details['customers_email_address'], $email_subject, str_replace(PHP_EOL,'
',$email_content), STORE_NAME, EMAIL_FROM); + } + + /** + * Get customer details from customer table. + * + * @param $customer_id interger + * + * @return array + */ + public static function get_customer_details($customer_id) + { + global $db; + $customer_value = $db->Execute("SELECT customers_firstname, customers_lastname, customers_email_address FROM " . TABLE_CUSTOMERS . " WHERE customers_id='" . $customer_id ."'"); + return $customer_value->fields; + } + + /** + * Send critical mail + * + * @return none + */ + public static function sentCriticalMail() + { + $subject = 'Critical error on shop system '.STORE_NAME.': order not found for TID: ' . $this->server_request['shop_tid']; + $message = "Dear Technic team,

Please evaluate this transaction and contact our payment module team at Novalnet.

"; + $message .= 'Merchant ID: ' . $this->server_request['vendor_id'] . '
'; + $message .= 'Project ID: ' . $this->server_request['product_id'] . '
'; + $message .= 'TID: ' . $this->server_request['shop_tid'] . '
'; + $message .= 'TID status: ' . $this->server_request['tid_status'] . '
'; + $message .= 'Order no: ' . $this->server_request['order_no'] . '
'; + $message .= 'Payment type: ' . $this->server_request['payment_type'] . '
'; + $message .= 'E-mail: ' . $this->server_request['email'] . '
'; + + $message .= '

Regards,
Novalnet Team'; + + zen_mail('Technic team' ,'technic@novalnet.de', $subject, $message ,STORE_NAME, EMAIL_FROM); + } + + /** + * Display message + * + * @param $message string + * @param $order_no integer + * + * @return none + */ + public static function display_message($message, $order_no = '') + { + echo !empty($order_no) ? 'message='. $message.'&order_no='.$order_no : 'message='.$message; + exit; + } +} +?> diff --git a/images/icons/novalnet/novalnet_PayPal.png b/images/icons/novalnet/novalnet_PayPal.png new file mode 100644 index 0000000..9defac5 Binary files /dev/null and b/images/icons/novalnet/novalnet_PayPal.png differ diff --git a/images/icons/novalnet/novalnet_cashpayment.png b/images/icons/novalnet/novalnet_cashpayment.png new file mode 100644 index 0000000..1eb4d4b Binary files /dev/null and b/images/icons/novalnet/novalnet_cashpayment.png differ diff --git a/images/icons/novalnet/novalnet_cc_amex.png b/images/icons/novalnet/novalnet_cc_amex.png new file mode 100644 index 0000000..0939d76 Binary files /dev/null and b/images/icons/novalnet/novalnet_cc_amex.png differ diff --git a/images/icons/novalnet/novalnet_cc_maestro.png b/images/icons/novalnet/novalnet_cc_maestro.png new file mode 100644 index 0000000..3e77c51 Binary files /dev/null and b/images/icons/novalnet/novalnet_cc_maestro.png differ diff --git a/images/icons/novalnet/novalnet_cc_master.png b/images/icons/novalnet/novalnet_cc_master.png new file mode 100644 index 0000000..ee6c1a2 Binary files /dev/null and b/images/icons/novalnet/novalnet_cc_master.png differ diff --git a/images/icons/novalnet/novalnet_cc_visa.png b/images/icons/novalnet/novalnet_cc_visa.png new file mode 100644 index 0000000..6b94ca8 Binary files /dev/null and b/images/icons/novalnet/novalnet_cc_visa.png differ diff --git a/images/icons/novalnet/novalnet_eps.png b/images/icons/novalnet/novalnet_eps.png new file mode 100644 index 0000000..02875ae Binary files /dev/null and b/images/icons/novalnet/novalnet_eps.png differ diff --git a/images/icons/novalnet/novalnet_giropay.png b/images/icons/novalnet/novalnet_giropay.png new file mode 100644 index 0000000..5bcd509 Binary files /dev/null and b/images/icons/novalnet/novalnet_giropay.png differ diff --git a/images/icons/novalnet/novalnet_ideal.png b/images/icons/novalnet/novalnet_ideal.png new file mode 100644 index 0000000..9d08251 Binary files /dev/null and b/images/icons/novalnet/novalnet_ideal.png differ diff --git a/images/icons/novalnet/novalnet_instantbank.png b/images/icons/novalnet/novalnet_instantbank.png new file mode 100644 index 0000000..e42c46e Binary files /dev/null and b/images/icons/novalnet/novalnet_instantbank.png differ diff --git a/images/icons/novalnet/novalnet_invoice.png b/images/icons/novalnet/novalnet_invoice.png new file mode 100644 index 0000000..15e0a37 Binary files /dev/null and b/images/icons/novalnet/novalnet_invoice.png differ diff --git a/images/icons/novalnet/novalnet_postfinance.png b/images/icons/novalnet/novalnet_postfinance.png new file mode 100644 index 0000000..0b34416 Binary files /dev/null and b/images/icons/novalnet/novalnet_postfinance.png differ diff --git a/images/icons/novalnet/novalnet_postfinance_card.png b/images/icons/novalnet/novalnet_postfinance_card.png new file mode 100644 index 0000000..e704b07 Binary files /dev/null and b/images/icons/novalnet/novalnet_postfinance_card.png differ diff --git a/images/icons/novalnet/novalnet_prepayment.png b/images/icons/novalnet/novalnet_prepayment.png new file mode 100644 index 0000000..9104281 Binary files /dev/null and b/images/icons/novalnet/novalnet_prepayment.png differ diff --git a/images/icons/novalnet/novalnet_przelewy24.png b/images/icons/novalnet/novalnet_przelewy24.png new file mode 100644 index 0000000..331d7b3 Binary files /dev/null and b/images/icons/novalnet/novalnet_przelewy24.png differ diff --git a/images/icons/novalnet/novalnet_sepa.png b/images/icons/novalnet/novalnet_sepa.png new file mode 100644 index 0000000..7daf3ca Binary files /dev/null and b/images/icons/novalnet/novalnet_sepa.png differ diff --git a/includes/classes/class.novalnetutil.php b/includes/classes/class.novalnetutil.php new file mode 100644 index 0000000..90296e3 --- /dev/null +++ b/includes/classes/class.novalnetutil.php @@ -0,0 +1,935 @@ + MODULE_PAYMENT_NOVALNET_VENDOR_ID, + 'product' => MODULE_PAYMENT_NOVALNET_PRODUCT_ID, + 'tariff' => $tariff, + 'auth_code' => MODULE_PAYMENT_NOVALNET_AUTH_CODE, + 'test_mode' => ($testMode == 'True') ? 1 : 0, + ); + + } + + /** + * Get customer details + * + * @return array + */ + public static function getCustomerfields() + { + global $db; + + $customerId = (isset($_SESSION['customer_id'])) ? $_SESSION['customer_id'] : ''; + if (!empty($customerId)) { + $customer = $db->Execute("SELECT customers_gender, customers_dob, customers_fax FROM " . TABLE_CUSTOMERS . " WHERE customers_id='" . (int) $customerId . "'"); + + if ($customer->RecordCount() > 0) { + $customer = $customer->fields; + } + return $customer; + } + } + + /** + * Form Customer details + * + * @param $request array + * @param $data array + * + * @return none + */ + public static function getCustomerDetails(&$request, $data) + { + $customer = self::getCustomerfields(); + + $nn_customer_id = (isset($_SESSION['customer_id'])) ? $_SESSION['customer_id'] : ''; + $customer_birthdate = ($customer['customers_dob'] != '0001-01-01 00:00:00') ? date('Y-m-d', strtotime($customer['customers_dob'])) : ''; + $request['first_name'] = !empty($data['billing']['firstname']) ? $data['billing']['firstname'] : $data['customer']['firstname']; + $request['last_name'] = !empty($data['billing']['lastname']) ? $data['billing']['lastname'] : $data['customer']['lastname']; + $request['street'] = !empty($data['billing']['street_address']) ? $data['billing']['street_address'] : $data['customer']['street_address']; + $request['search_in_street'] = 1; + $request['city'] = !empty($data['billing']['city']) ? $data['billing']['city'] : $data['customer']['city']; + $request['zip'] = !empty($data['billing']['postcode']) ? $data['billing']['postcode'] : $data['customer']['postcode']; + $request['email'] = !empty($data['billing']['email_address']) ? $data['billing']['email_address'] : $data['customer']['email_address']; + $request['country_code'] = !empty($data['billing']['country']['iso_code_2']) ? $data['billing']['country']['iso_code_2'] : $data['customer']['country']['iso_code_2']; + $request['customer_no'] = !empty($nn_customer_id) ? $nn_customer_id : 'guest'; + $request['tel'] = !empty($data['billing']['telephone']) ? $data['billing']['telephone'] : $data['customer']['telephone']; $request['lang'] = ((isset($_SESSION['language']) && $_SESSION['language'] == 'english') ? 'EN' : 'DE'); + $company = !empty($data['billing']['company']) ? $data['billing']['company'] : $data['customer']['company']; + + if (!empty($company)) + $request['company'] = !empty($data['billing']['company']) ? $data['billing']['company'] : $data['customer']['company']; + + if (!empty($customer['customers_gender'])) + $request['gender'] = $customer['customers_gender']; + + if (!empty($customer_birthdate)) + $request['birth_date'] = $customer_birthdate; + + if (!empty($customer['customers_fax'])) + $request['fax'] = $customer['customers_fax']; + + } + + /** + * Get Order details + * + * @param $request array + * @param $data array + * + * @return none + */ + public static function getOrderDetails(&$request, $data) + { + $request['amount'] = $data['order_amount']; + $request['currency'] = $data['info']['currency']; + } + + /** + * Get Payment details + * + * @param $request array + * @param $data array + * @param $payment string + * + * @return none + */ + public static function getPaymentDetails(&$request, $data, $payment) + { + $redirectPayments = array('novalnet_cc','novalnet_ideal', 'novalnet_PayPal', 'novalnet_banktransfer', 'novalnet_eps', 'novalnet_giropay', 'novalnet_przelewy24', 'novalnet_postfinance', 'novalnet_postfinance_card'); + + $request['payment_type'] = self::getPaymentTypeKey($payment,'type'); + $request['key'] = self::getPaymentTypeKey($payment,'key'); + + if (in_array($payment, array('novalnet_invoice', 'novalnet_cc', 'novalnet_sepa', 'novalnet_PayPal', 'novalnet_instalment_sepa', 'novalnet_instalment_invoice', 'novalnet_guarantee_invoice', 'novalnet_guarantee_sepa'))) { + $paymentName = strtoupper($payment); + $onholdLimit = constant('MODULE_PAYMENT_'.$paymentName.'_ONHOLD_LIMIT'); + // To process on hold product + if ((constant('MODULE_PAYMENT_'.$paymentName.'_ONHOLD') == 'Authorize') && (!empty($onholdLimit) && ($request['amount'] >= trim($onholdLimit)) || empty($onholdLimit))) { + $request['on_hold'] = 1; + } + } + + if ($payment == 'novalnet_invoice') { + $dueDate = MODULE_PAYMENT_NOVALNET_INVOICE_DUE_DATE; + $dueDate = trim($dueDate); + if ($dueDate != '') { + $request['due_date'] = date('Y-m-d', strtotime('+' .$dueDate . ' days')); + } + } + + if (in_array($payment, array('novalnet_sepa', 'novalnet_guarantee_sepa'))) { + $sepaDueDate = self::sepaDuedate($paymentName); + + if( !empty($sepaDueDate) ) { + $request['sepa_due_date'] = date('Y-m-d', strtotime('+'.$sepaDueDate.' days')); + } + } + + if (in_array($payment, array('novalnet_sepa', 'novalnet_guarantee_sepa', 'novalnet_instalment_sepa'))) { + $request['bank_account_holder'] = strip_tags($data[$payment.'_bank_account_holder']); + $request['iban'] = $data[$payment.'_bank_iban']; + } + + if (in_array($payment, array('novalnet_guarantee_invoice', 'novalnet_guarantee_sepa', 'novalnet_instalment_invoice', 'novalnet_instalment_sepa'))) { + if (isset($data[$payment.'_birthdate']) && !empty($data[$payment.'_birthdate'])) { + $request['birth_date'] = date('Y-m-d', strtotime($data[$payment.'_birthdate'])); + } + if (in_array($payment, array('novalnet_instalment_invoice', 'novalnet_instalment_sepa'))) { + $period = constant('MODULE_PAYMENT_'.$paymentName.'_PERIOD'); + $request['instalment_cycles'] = $data[$payment.'_period']; + $request['instalment_period'] = strtolower($period); + } + } + + if ($payment == 'novalnet_invoice') { + $request['invoice_type'] = 'INVOICE'; + } elseif ($payment == 'novalnet_prepayment') { + $request['invoice_type'] = 'PREPAYMENT'; + } elseif ($payment == 'novalnet_cashpayment') { + $dueDate = trim(MODULE_PAYMENT_NOVALNET_CASHPAYMENT_SLIP_EXPIRY_DATE); + $barzahlenDueDate = ($dueDate) ? (date('Y-m-d', strtotime('+' . $dueDate . ' days'))) : ''; + if ($barzahlenDueDate != '') { + $request['cp_due_date'] = $barzahlenDueDate; + } + } elseif ($payment == 'novalnet_cc') { + $request['unique_id'] = $data['nn_cc_uniqueid']; + $request['pan_hash'] = $data['nn_cc_pan_hash']; + $request['nn_it'] = 'iframe'; + $request['cc_3d'] = 1; + } + if (in_array($payment, $redirectPayments)) { + self::getRedirectParams($request, $payment); + } + } + + /** + * Get SEPA due date + * + * @param $paymentName string + * + * @return string + */ + public static function sepaDuedate($paymentName) + { + $sepaDueDate = constant('MODULE_PAYMENT_'.$paymentName. '_PAYMENT_DUE_DATE'); + $sepaDueDate = trim($sepaDueDate); + + if ($sepaDueDate != '' && $sepaDueDate <= 14 && $sepaDueDate >= 2) { + return $sepaDueDate; + } + } + + /** + * Get payment key & payment type + * + * @param $paymentName string + * @param $field string + * + * @return string + */ + public static function getPaymentTypeKey($paymentName, $field) + { + $payment = array( + 'novalnet_sepa' => array('key' =>37, 'type' => "DIRECT_DEBIT_SEPA"), + 'novalnet_cc' => array('key' => 6, 'type' => "CREDITCARD"), + 'novalnet_invoice' => array('key' => 27, 'type' => "INVOICE"), + 'novalnet_prepayment' => array('key' => 27, 'type' => "PREPAYMENT"), + 'novalnet_guarantee_invoice' => array('key' => 41, 'type' => "GUARANTEED_INVOICE"), + 'novalnet_guarantee_sepa' => array('key' => 40, 'type' => "GUARANTEED_DIRECT_DEBIT_SEPA"), + 'novalnet_ideal' => array('key' => 49, 'type' => "IDEAL"), + 'novalnet_banktransfer' => array('key' => 33, 'type' => "ONLINE_TRANSFER"), + 'novalnet_giropay' => array('key' => 69, 'type' => "GIROPAY"), + 'novalnet_cashpayment' => array('key' => 59, 'type' => "CASHPAYMENT"), + 'novalnet_przelewy24' => array('key' => 78, 'type' => "PRZELEWY24"), + 'novalnet_eps' => array('key' => 50, 'type' => "EPS"), + 'novalnet_instalment_invoice' => array('key' => 96, 'type' => "INSTALMENT_INVOICE"), + 'novalnet_instalment_sepa' => array('key' => 97, 'type' => "INSTALMENT_DIRECT_DEBIT_SEPA"), + 'novalnet_PayPal' => array('key' => 34, 'type' => "PAYPAL"), + 'novalnet_postfinance_card' => array('key' => 87, 'type' => "POSTFINANCE_CARD"), + 'novalnet_postfinance' => array('key' => 88, 'type' => "POSTFINANCE"), + ); + return $payment[$paymentName][$field]; + } + + /** + * Get system details + * + * @param $request array + * @param $data array + * + * @return none + */ + public static function getSystemDetails(&$request, $data) + { + $remoteIp = zen_get_ip_address(); + $systemIp = $_SERVER['SERVER_ADDR']; + $request['system_name'] = 'Zencart'; + $request['system_version'] = PROJECT_VERSION_MAJOR.'.'.PROJECT_VERSION_MINOR . '-NN-2.0.0'; + $request['remote_ip'] = (filter_var($remoteIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || empty($remoteIp)) ? '127.0.0.1' : $remoteIp; + $request['system_ip'] = (filter_var($systemIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) || empty($systemIp)) ? '127.0.0.1' : $systemIp; + $request['system_url'] = ((ENABLE_SSL == true) ? HTTPS_SERVER : HTTP_SERVER); + $notifyUrl = trim(MODULE_PAYMENT_NOVALNET_CALLBACK_NOTIFY_URL); + if (!empty($notifyUrl)) + $request['notify_url'] = $notifyUrl; + } + + /** + * Return payment amount of given order + * + * @param $data array + * @param $payment string + * + * @return integer + */ + public static function getPaymentAmount($data, $payment) + { + global $currencies, $messageStack; + + $total = ((isset($_SESSION['customers_status']) && $_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 1)) ? ($data['info']['total'] + $data['info']['tax']) : $data['info']['total']; + + $totalAmount = number_format($total * $currencies->get_value($data['info']['currency']), 2); + $amount = str_replace(',', '', $totalAmount); + $amount = intval(round($amount * 100)); + + if (preg_match('/[^\d\.]/', $amount)) { + $messageStack->add_session('checkout_payment', MODULE_PAYMENT_NOVALNET_AMOUNT_ERROR_MESSAGE . '', 'error'); + zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false)); + } + + return $amount; + } + + /** + * Get Redirect request + * + * @param $request array + * @param $payment string + * + * @return none + */ + public static function getRedirectParams(&$request, $payment) + { + $request['return_method'] = $request['error_return_method'] = 'POST'; + $request['return_url'] = $request['error_return_url'] = zen_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL'); + $request['user_variable_0'] = ((ENABLE_SSL == true) ? HTTPS_SERVER:HTTP_SERVER); + $request['implementation'] = 'ENC'; + $request['input3'] = 'cart_id'; + $request['inputval3'] = $_SESSION['cartID']; + $request['uniqid'] = self::getUniqueid(); + } + + /** + * Generate encode data + * + * @param $request array + * + * @return none + */ + public static function generateEncodeValue(&$request) + { + foreach (array('auth_code', 'product', 'tariff', 'amount', 'test_mode') as $key) { + if (isset($request[$key])) { + // Encoding process + $request[$key] = htmlentities(base64_encode(openssl_encrypt($request[$key], "aes-256-cbc", MODULE_PAYMENT_NOVALNET_PAYMENT_ACCESS_KEY, true, $request['uniqid']))); + } + } + + // Generate hash value + $request['hash'] = self::generateHashValue($request); + } + + /** + * Generate decode data + * @param $data + * + * @return none + */ + public static function decodePaygateResponse(&$data) + { + foreach (array('auth_code','product','tariff','amount','test_mode') as $key) { + if (isset($data[$key])) { + // Decoding process + $data[$key] = openssl_decrypt(base64_decode($data[$key]), "aes-256-cbc", MODULE_PAYMENT_NOVALNET_PAYMENT_ACCESS_KEY, true, $data['uniqid']); + } + } + + return $data; + } + + /** + * Perform HASH Validation with paygate response + * + * @param $data array + * + * @return boolean + */ + public static function validateHashResponse($data) + { + // Check for hash error + return ($data['hash2'] != self::generateHashValue($data)); + } + + /** + * Get hash value + * + * @param $request array + * + * @return mixed + */ + public static function generateHashValue($request) + { + // Hash generation using sha256 and encoded merchant details + return hash('sha256', ($request['auth_code'].$request['product'].$request['tariff'].$request['amount'].$request['test_mode'].$request['uniqid'].strrev(MODULE_PAYMENT_NOVALNET_PAYMENT_ACCESS_KEY))); + + } + + /** + * Gets the Unique Id + * + * @return string + */ + public static function getUniqueid() + { + $randomArray = array('8','7','6','5','4','3','2','1','9','0','9','7','6','1','2','3','4','5','6','7','8','9','0'); + shuffle($randomArray); + return substr(implode($randomArray, ''), 0, 16); + } + + /** + * Function to communicate transaction parameters with Novalnet Paygate + * + * @param $paygateUrl string + * @param $data array + * @param $payment string + * + * @return array + */ + public static function doPaymentCurlCall($paygateUrl, $data, $payment = '') + { + // Initiate cURL. + $curlProcess = curl_init($paygateUrl); + // Set cURL options. + curl_setopt($curlProcess, CURLOPT_POST, 1); + curl_setopt($curlProcess, CURLOPT_POSTFIELDS, http_build_query($data)); + curl_setopt($curlProcess, CURLOPT_FOLLOWLOCATION, 0); + curl_setopt($curlProcess, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curlProcess, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curlProcess, CURLOPT_RETURNTRANSFER, 1); + + // Custom CURL time-out. + curl_setopt($curlProcess, CURLOPT_TIMEOUT, 240); + + // Execute cURL. + $response = curl_exec($curlProcess); + + // Handle cURL error. + if (curl_errno($curlProcess)) { + $messageStack->add_session('checkout_payment', utf8_decode('error_message=' .curl_error($curlProcess)) . '', 'error'); + zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false)); + } + + // Close cURL. + curl_close($curlProcess); + + return $response; + } + + /** + * Check order status + * + * @param $orderStatus integer + * + * @return integer + */ + public static function checkDefaultOrderStatus($orderStatus) + { + return !empty($orderStatus) ? $orderStatus : DEFAULT_ORDERS_STATUS_ID; + } + + /** + * Form transaction comments + * + * @param $tid integer + * @param $testMode integer + * + * @return string + */ + public static function formPaymentComments($tid, $testMode) + { + $transactionComments = ''; + if ($tid) { + $transactionComments .= PHP_EOL.MODULE_PAYMENT_NOVALNET_TRANSACTION_DETAILS.PHP_EOL.MODULE_PAYMENT_NOVALNET_TRANSACTION_ID . $tid; + } + + // Add test_mode text + if ($testMode) { + $transactionComments .= PHP_EOL.MODULE_PAYMENT_NOVALNET_TEST_ORDER_MESSAGE.PHP_EOL; + } + + return $transactionComments; + } + + /** + * Return Invoice / Prepayment comments + * + * @param $data array + * @param $amount integer + * + * @return string + */ + public static function formInvoicePrepaymentComments($data, $amount = '') + { + $amount = !empty($amount) ? $amount : number_format($data['amount'], 2, ',', ''); + + $transComments = PHP_EOL. MODULE_PAYMENT_NOVALNET_INVOICE_COMMENTS_PARAGRAPH.PHP_EOL; + $dueDate = $data['due_date']; + $transComments .= ($dueDate != '') ? MODULE_PAYMENT_NOVALNET_DUE_DATE.': '.date(DATE_FORMAT, strtotime($dueDate)).PHP_EOL : ''; + $transComments .= MODULE_PAYMENT_NOVALNET_ACCOUNT_HOLDER.': '.$data['invoice_account_holder']. PHP_EOL; + $transComments .= MODULE_PAYMENT_NOVALNET_IBAN.': '.$data['invoice_iban']. PHP_EOL; + $transComments .= MODULE_PAYMENT_NOVALNET_SWIFT_BIC.': '.$data['invoice_bic'].PHP_EOL; + $transComments .= MODULE_PAYMENT_NOVALNET_BANK.': '.$data['invoice_bankname'].' '.$data['invoice_bankplace'].PHP_EOL; + $transComments .= MODULE_PAYMENT_NOVALNET_AMOUNT.': '. $amount. ' ' . $data['currency'].PHP_EOL; + return $transComments; + } + + /** + * Check transaction status message + * + * @param $response array + * + * @return string + */ + public static function getTransactionMessage($response) + { + return (!empty($response['status_message']) ? $response['status_message'] : !empty($response['status_desc']) ? $response['status_desc'] : (!empty($response['status_text']) ? $response['status_text'] : '')); + } + + /** + * Return Invoice / Prepayment payment reference comments + * + * @param $orderId integer + * @param $data array + * @param $payment string + * + * @return string + */ + public static function novalnetReferenceComments($orderId, $data, $payment) + { + $comments = MODULE_PAYMENT_NOVALNET_PAYMENT_MULTI_TEXT . PHP_EOL; + $comments .= MODULE_PAYMENT_NOVALNET_INVPRE_REF1. ': TID'.' '. $data['tid'] . PHP_EOL; + if ($payment != 'novalnet_instalment_invoice') { + $comments .= MODULE_PAYMENT_NOVALNET_INVPRE_REF2 .': BNR-' . (!empty($data['product']) ? $data['product'] : MODULE_PAYMENT_NOVALNET_PRODUCT_ID) . '-' . $orderId. PHP_EOL; + } + + + return $comments; + } + + /** + * Build the postback call for updating order_no + * + * @param $data array + * + * @return none + */ + public static function postBackCall($data) + { + $payment = $data['payment']; + // Second call for updating order_no + $urlparam = array( + 'vendor' => $_SESSION['novalnet'][$payment]['vendor'], + 'product' => $_SESSION['novalnet'][$payment]['product'], + 'tariff' => $_SESSION['novalnet'][$payment]['tariff'], + 'auth_code' => $_SESSION['novalnet'][$payment]['auth_code'], + 'key' => $_SESSION['novalnet'][$payment]['payment_id'], + 'status' => 100, + 'tid' => $_SESSION['novalnet'][$payment]['tid'], + 'order_no' => $data['order_no'], + ); + + // Add invoice_ref parameter for Invoice and Prepayment + if (in_array($_SESSION['novalnet'][$payment], array('novalnet_invoice', 'novalnet_guarantee_invoice'))) { + $urlparam['invoice_ref'] .= 'BNR-'.$_SESSION['novalnet'][$payment]['product'].'-'.$data['order_no']; + } + + // Send parameters to Novalnet paygate + self::doPaymentCurlCall('https://payport.novalnet.de/paygate.jsp', $urlparam, $payment); + + // Unset all Novalnet session value + if (isset($_SESSION['novalnet'])) { + unset($_SESSION['novalnet']); + } + } + + /** + * Merchant details + * + * @param $inputParams array + * + * @return array + */ + public static function paymentInitialParams($inputParams) + { + return array( + 'vendor' => $inputParams['vendor'], + 'product' => $inputParams['product'], + 'tariff' => $inputParams['tariff'], + 'auth_code' => $inputParams['auth_code'], + 'payment_id' => !empty($inputParams['key']) ? $inputParams['key'] : $inputParams['payment_id'], + ); + } + + /** + * Built Cashpayment comments + * + * @param $response array + * + * @return string + */ + public static function formCashpaymentComments($response) + { + global $db; + $barzahlenComments = ''; + + $slipDueDate = !empty($response['cp_due_date']) ? $response['cp_due_date']: $response['due_date']; + + $barzahlenComments .= MODULE_PAYMENT_NOVALNET_CASHPAYMENT_SLIP_EXPIRY_DATE_TEXT . ': '.date('d.m.Y', strtotime($slipDueDate)).PHP_EOL; + + $nearestStore = self::getNearestStore($response); + $nearestStore['nearest_store'] = $nearestStore; + if (!empty($nearestStore)) { + $barzahlenComments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_CASHPAYMENT_NEAREST_STORE_DETAILS_TEXT.PHP_EOL; + } + + $nearestStore['cp_due_date'] = $slipDueDate; + $i =0; + foreach ($nearestStore as $key => $values) { + $i++; + if (!empty($nearestStore['nearest_store_title_'.$i])) { + $barzahlenComments .= PHP_EOL . $nearestStore['nearest_store_title_'.$i]; + } + if (!empty($nearestStore['nearest_store_street_'.$i])) { + $barzahlenComments .= PHP_EOL . $nearestStore['nearest_store_street_'.$i]; + } + if (!empty($nearestStore['nearest_store_city_'.$i])) { + $barzahlenComments .= PHP_EOL . $nearestStore['nearest_store_city_'.$i]; + } + if (!empty($nearestStore['nearest_store_zipcode_'.$i])) { + $barzahlenComments .= PHP_EOL . $nearestStore['nearest_store_zipcode_'.$i]; + } + + if (!empty($nearestStore['nearest_store_country_'.$i])) { + $result = $db->Execute("select countries_name from countries where countries_iso_code_2='". $nearestStore['nearest_store_country_'.$i] ."'"); + $barzahlenComments .= PHP_EOL . $result->fields['countries_name'].PHP_EOL; + } + } + + return $barzahlenComments; + } + + /** + * Get nearest store details + * @param $response + * + * @return array + */ + public static function getNearestStore($response) + { + $stores = array(); + foreach ($response as $sKey => $values) { + if (stripos($sKey, 'nearest_store')!==false) { + $stores[$sKey] = $values; + } + } + return $stores; + } + + /** + * Get Instalment Cycles from Instalment payment settings. + * + * @param $payment string + * @param $order object + * + * @return array + */ + public static function getInstalmentCycles($payment, $order) + { + $paymentName = strtoupper($payment); + + $paymentCycle = constant('MODULE_PAYMENT_' . $paymentName . '_PERIOD'); + $totalPeriod = constant('MODULE_PAYMENT_' . $paymentName . '_CYCLE'); + + if (!empty($totalPeriod)) { + $totalPeriod = explode(',',$totalPeriod); + + $i = 0; + $cycles = array(array('id'=> $i,'text'=>'Select')); + if ( 1 == $paymentCycle ) { + $paymentCycle = ''; + } + sort($totalPeriod); + + $clength=count($totalPeriod); + for($x=0;$x<$clength;$x++){ + $totalPeriod[$x]; + } + + $totalPeriod = array_unique($totalPeriod); + + foreach ( $totalPeriod as $period ) { + $amount = self::getPaymentAmount((array)$order, $payment); + $cycle = ($amount / $period); + if ( $cycle >= 999 ) { + $cycles[] = array('id' => $period,'text' => sprintf(MODULE_PAYMENT_NOVALNET_CYCLES, $period ) . ' / ' . sprintf( '%0.2f', $cycle/100 ).' ' . $order->info['currency'] . sprintf(MODULE_PAYMENT_NOVALNET_PER_MONTH, $paymentCycle )); + $i++; + } + } + } + + if ( $i == 0 ) { + return $i; + } else { + return $cycles; + } + } + + /** + * Get Instalment PlanF Details. + * + * @param $payment string + * + * @return array + */ + public static function getInstalmentPlanDetails($payment) + { + $paymentName = strtoupper($payment); + $cyclePeriod = constant('MODULE_PAYMENT_' . $paymentName . '_PERIOD'); + $totalPeriod = constant('MODULE_PAYMENT_' . $paymentName . '_CYCLE'); + $totalPeriod = explode(',',$totalPeriod); + sort($totalPeriod); + + $clength=count($totalPeriod); + for($x=0;$x<$clength;$x++){ + $totalPeriod[$x]; + } + + $totalInstalmentCycle = !empty( $totalPeriod ) ? $totalPeriod[count($totalPeriod)-1]:''; + $currentMonthInvoice = date('m'); + + for ( $i=0; $i<$totalInstalmentCycle; $i++ ) { + $lastDay = date('Y-m-d', strtotime( '+'.$cyclePeriod * $i.'months' ) ); + $instlmentDateMonth[] = date('m', strtotime( '+'.$cyclePeriod * $i.'months' ) ); + if( $currentMonthInvoice > 12 ) { + $currentMonthInvoice = $currentMonthInvoice - 12; + } + if ( $currentMonthInvoice == $instlmentDateMonth[$i] ) { + $instlmentDateInvoice[] = date('Y-m-d', strtotime( '+'.$cyclePeriod * $i.'months' ) ); + } else { + $instlmentDateInvoice[] = date('Y-m-d', strtotime( $instlmentDateInvoice[$i].' last day of previous month' , strtotime ( $lastDay ) ) ); + } + $currentMonthInvoice = $currentMonthInvoice + $cyclePeriod; + } + + return $currentMonthInvoice; + } + + /** + * Form guarantee field + * + * @param $name string + * @param $customerDetails array + * + * @return string + */ + public static function getGuaranteeField($name, $customerDetails) + { + $birthDate = (isset($customerDetails['customers_dob']) && $customerDetails['customers_dob'] != '0001-01-01 00:00:00') ? date('Y-m-d', strtotime($customerDetails['customers_dob'])) : ''; + + return zen_draw_input_field($name, $birthDate, 'id="'.$name.'" placeholder="'.MODULE_PAYMENT_NOVALNET_GUARANTEE_DOB_FORMAT.'" autocomplete="OFF" maxlength="10" ') . '
'; + } + + /** + * Check guarantee payment condition + * + * @param $order array + * @param $payment string + * + * @return string + */ + public static function checkGuaranteeConditions($order, $payment) + { + // Get payment name in caps + $paymentName = strtoupper($payment); + + $min_amount = (in_array($payment, array('novalnet_instalment_invoice', 'novalnet_instalment_sepa'))) ? '1998' : '999'; + + // Get guarantee minimum and maximum amount value + $minimumAmount = trim(constant('MODULE_PAYMENT_'.$paymentName.'_MIN_AMOUNT_LIMIT')) ? trim(constant('MODULE_PAYMENT_'.$paymentName.'_MIN_AMOUNT_LIMIT')) : $min_amount; + + // Get order details + $customerIsoCode = strtoupper($order['customer']['country']['iso_code_2']); + $amount = self::getPaymentAmount((array)$order, $payment); + + // Delivery address + $deliveryAddress = array( + 'street_address' => $order['delivery']['street_address'], + 'city' => $order['delivery']['city'], + 'postcode' => $order['delivery']['postcode'], + 'country' => $order['delivery']['country']['iso_code_2'], + ); + + // Billing address + $billingAddress = array( + 'street_address' => $order['billing']['street_address'], + 'city' => $order['billing']['city'], + 'postcode' => $order['billing']['postcode'], + 'country' => $order['billing']['country']['iso_code_2'], + ); + + if ((((int) $amount >= (int) $minimumAmount) && in_array($customerIsoCode, array('DE', 'AT', 'CH')) && $order['info']['currency'] == 'EUR' && $deliveryAddress === $billingAddress)) { + return array('guarantee', ''); + } else { + $guaranteeError = ''; + if (!in_array($customerIsoCode, array('DE', 'AT', 'CH'))) { + $guaranteeError .= MODULE_PAYMENT_NOVALNET_FORCE_GUARANTEE_ERROR_MESSAGE_COUNTRY; + } + if ($order['info']['currency'] !== 'EUR' ) { + $guaranteeError .= '
'.MODULE_PAYMENT_NOVALNET_FORCE_GUARANTEE_ERROR_MESSAGE_CURRENCY; + } + if ( ! empty( array_diff( $billingAddress, $deliveryAddress ) ) ) { + $guaranteeError .= '
'.MODULE_PAYMENT_NOVALNET_FORCE_GUARANTEE_ERROR_MESSAGE_ADDRESS; + } + if ( (int) $amount < (int) $minimumAmount ) { + $guaranteeError .= '
'.sprintf(MODULE_PAYMENT_NOVALNET_FORCE_GUARANTEE_ERROR_MESSAGE_AMOUNT, str_replace('.', ',', $minimumAmount/100) .' '. $order['info']['currency']); + } + $errorMessage = PHP_EOL.$guaranteeError; + + return array('error', $errorMessage); + } + } + + /** + * Validate for users over 18 only + * + * @param $birthDate integer + * + * @return boolean + */ + public static function validateAge($birthDate) + { + return (empty($birthDate) || time() < strtotime('+18 years', strtotime($birthDate))); + } + + /** + * Prepare Instalment payment transaction detail comments + * + * @param $response array + * @param $payment string + * + * @return string + */ + public static function instalmentComments($response, $payment) + { + $transactionComments = ''; + if (!empty($response['next_instalment_date'])) { + if (!in_array( $response ['tid_status'], array( '91', '99' ), true ) ) { + if ($payment == 'novalnet_instalment_sepa') { + $comments .= PHP_EOL.PHP_EOL . sprintf(MODULE_PAYMENT_NOVALNET_INSTALMENT_SEPA_INFO, $response['amount'], $response['currency']); + } + $transactionComments .= MODULE_PAYMENT_NOVALNET_INSTALMENT_INFO; + $transactionComments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_PROCESSED . ( ! empty( $response ['instalment_cycles_executed'] ) ? $response ['instalment_cycles_executed'] : ( ! empty ( $response ['instalment1']['instalment_cycles_executed'] ) ? $response ['instalment1']['instalment_cycles_executed'] : '' ) ); + $transactionComments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_DUE . ( isset( $response ['due_instalment_cycles'] ) ? $response ['due_instalment_cycles'] : ( ! empty ( $response ['instalment1']['due_instalment_cycles'] ) ? $response ['instalment1']['due_instalment_cycles'] : '' ) ); + + $transactionComments .= PHP_EOL . MODULE_PAYMENT_NOVALNET_INSTALMENT_NXT_AMOUNT . ( ! empty( $response ['instalment_cycle_amount'] ) ? $response ['instalment_cycle_amount'] : $response ['amount'] ); + + if ( $response ['payment_id'] == '97' && $response['instalment_billing'] == '1' ) { + $transactionComments .= PHP_EOL . PHP_EOL . sprintf( MODULE_PAYMENT_NOVALNET_INSTALMENT_DEBIT_TEXT, $response ['amount']); + } + } + return $transactionComments; + } + return $transactionComments; + } + + /** + * Update the transaction details in novalnet table. + * + * @param $data array + * + * @return none + */ + public static function logInitialTransaction($data) + { + $payment = $data['payment']; + $sessionValue = $_SESSION['novalnet'][$payment]; + + $tableValues = array( + 'tid' => $sessionValue['tid'], + 'order_no' => $data['order_no'], + 'payment_id' => $sessionValue['payment_id'], + 'payment_type' => $data['payment'], + 'amount' => $sessionValue['amount'], + 'callback_amount' => $sessionValue['total_amount'], + 'gateway_status' => $sessionValue['gateway_status'], + 'date' => date('Y-m-d H:i:s'), + 'language' => $_SESSION['language'], + 'instalment_details' => (in_array($payment, array('novalnet_instalment_sepa', 'novalnet_instalment_invoice'))) ? $sessionValue['instalment_details'] : '' + ); + + zen_db_perform('novalnet_transaction_detail', $tableValues, "insert"); + } +} +?> diff --git a/includes/ext/novalnet/css/novalnet.css b/includes/ext/novalnet/css/novalnet.css new file mode 100644 index 0000000..dc2716a --- /dev/null +++ b/includes/ext/novalnet/css/novalnet.css @@ -0,0 +1,18 @@ + +#novalnet_instalment_table_invoice table, td, th { + border: 1px solid #907e7e !important; + text-align: left; + padding: 10px; +} + +#novalnet_instalment_table_invoice th, #novalnet_instalment_table_sepa th { + background-color:#a2a2a2; +} + +.autocomplete-items { + background: #fff; + border: 1px solid #66afe9; + position: absolute; + width: 86%; + z-index: 99; +} diff --git a/includes/ext/novalnet/install/install.sql b/includes/ext/novalnet/install/install.sql new file mode 100644 index 0000000..ecf79af --- /dev/null +++ b/includes/ext/novalnet/install/install.sql @@ -0,0 +1,20 @@ + +CREATE TABLE IF NOT EXISTS novalnet_transaction_detail ( + id int(11) AUTO_INCREMENT COMMENT 'Auto Increment ID', + tid bigint(20) unsigned COMMENT 'Novalnet Transaction Reference ID', + order_no int(11) COMMENT 'Order number from shop', + payment_id int(11) unsigned COMMENT 'Payment ID', + payment_type varchar(50) COMMENT 'Executed Payment type of this order', + amount int(11) unsigned COMMENT 'Transaction amount', + callback_amount int(11) unsigned COMMENT 'Callback amount', + gateway_status int(11) unsigned COMMENT 'Novalnet transaction status', + instalment_details text COMMENT 'Stored instalment details', + `date` datetime COMMENT 'Transaction Date for reference', + `language` varchar(10) COMMENT 'Shop language', + PRIMARY KEY (id), + KEY tid (tid), + KEY payment_type (payment_type), + KEY order_no (order_no) +) COMMENT='Novalnet Transaction History'; + +ALTER TABLE orders_status_history MODIFY comments text; diff --git a/includes/ext/novalnet/js/novalnet_admin.js b/includes/ext/novalnet/js/novalnet_admin.js new file mode 100644 index 0000000..6b003c2 --- /dev/null +++ b/includes/ext/novalnet/js/novalnet_admin.js @@ -0,0 +1,116 @@ +/* + * Novalnet API script + * By Novalnet (https://www.novalnet.de) + * Copyright (c) Novalnet + */ + +if (window.addEventListener) { + window.addEventListener("load", novalnet_admin); +} else if (window.attachEvent) { + window.attachEvent("load", novalnet_admin); +} + +function novalnet_admin() { + + jQuery('input[type="text"]').on('keyup',function(e){ + let selected_name = jQuery(this).attr('name'); + if( ! selected_name.match( /CUSTOMER_INFO/g ) && ! selected_name.match( /STYLE/g )) { + if ( this.value != '' && isNaN( this.value ) ) { + this.value = 0; + } + } + }); + //capture authorize + jQuery('#set_limit_title, #set_limit_desc').hide(); + jQuery('[name*="_ONHOLD_LIMIT]"]').hide(); + jQuery('[name*="_ONHOLD]"]').click(function () { + if (jQuery('[name*="_ONHOLD]"]').prop('checked') == true) { + jQuery('#set_limit_title, #set_limit_desc').hide(); + jQuery('[name*="_ONHOLD_LIMIT]"]').hide().val(''); + } + if (jQuery('[name*="_ONHOLD]"]').prop('checked') == false) { + jQuery('#set_limit_title, #set_limit_desc').show(); + jQuery('[name*="_ONHOLD_LIMIT]"]').show(); + } + + }); + if (jQuery('[name*="_ONHOLD]"]').prop('checked') == false) { + jQuery('#set_limit_title, #set_limit_desc').show(); + jQuery('[name*="_ONHOLD_LIMIT]"]').show(); + } + +jQuery('button[id=saveButton]').on('click', function(event){ + jQuery('input[name="configuration[MODULE_PAYMENT_NOVALNET_SEPA_PAYMENT_DUE_DATE]"]').attr('id', 'sepa_due_date'); + jQuery('input[name="configuration[MODULE_PAYMENT_NOVALNET_GUARANTEE_SEPA_PAYMENT_DUE_DATE]"]').attr('id', 'guarantee_sepa_due_date'); + performAdminValidations(event); + }); +function performAdminValidations(event) { + + if (jQuery('#sepa_due_date').val() != undefined && jQuery.trim(jQuery('#sepa_due_date').val()) != '') { + if (isNaN(jQuery('#sepa_due_date').val()) || jQuery('#sepa_due_date').val() < 2 || jQuery('#sepa_due_date').val() > 14) { + event.preventDefault(); + alert(jQuery('#sepa_due_date_error').val()); + } + } else if(jQuery('#guarantee_sepa_due_date').val() != undefined && jQuery.trim(jQuery('#guarantee_sepa_due_date').val()) != '') { + if ( isNaN(jQuery('#guarantee_sepa_due_date').val()) || jQuery('#guarantee_sepa_due_date').val() < 2 || jQuery('#guarantee_sepa_due_date').val() > 14) { + event.preventDefault(); + alert(jQuery('#sepa_due_date_error').val()); + } + } +} + +} + + +/** +* Creates Installment Select Fields +* @param config_name string +* @param id string +*/ +function create_installment_fields( config_name, id ) { + + let config_period_name = "configuration["+ config_name + "_PERIOD]"; + let config_cycle_name = "configuration["+ config_name + "_CYCLE]"; + let period_id = id + '_period'; + let cycle_id = id + '_cycle'; + + jQuery('input[name="' + config_period_name + '"]').attr('id', period_id ); + jQuery('input[name="' + config_cycle_name + '"]').attr('id', cycle_id ); + console.log( 'input[name="' + config_cycle_name + '"]' ); + + var selected_period = jQuery('#'+ period_id).val(); + var selected_instalment_cycles = jQuery('#'+ cycle_id).val() || ''; + jQuery('#'+ period_id ).replaceWith(''); + var lang = jQuery('#nn_lang').val(); + var instalment_periods = {'1M':'per month', '2M':'per 2 months', '3M':'per 3 months', '4M':'per 4 months', '6M':'per 6 months'}; + if (lang == 'de') + instalment_periods = {'1M':'pro Monate', '2M':'pro 2 Monate', '3M':'pro 3 Monate', '4M':'pro 4 Monate', '6M':'pro 6 Monate'}; + + jQuery.each(instalment_periods, function( index, value ) { + jQuery('#'+period_id).append(jQuery('