public function getOrderDetails() { $orderModel = VmModel::getModel('orders'); $orderDetails = 0; // If the user is not logged in, we will check the order number and order pass if ($orderPass = JRequest::getString('order_pass', false) and $orderNumber = JRequest::getString('order_number', false)) { $orderId = $orderModel->getOrderIdByOrderPass($orderNumber, $orderPass); if (empty($orderId)) { vmDebug('Invalid order_number/password ' . JText::_('COM_VIRTUEMART_RESTRICTED_ACCESS')); return 0; } $orderDetails = $orderModel->getOrder($orderId); } if ($orderDetails == 0) { $_currentUser = JFactory::getUser(); $cuid = $_currentUser->get('id'); // If the user is logged in, we will check if the order belongs to him $virtuemart_order_id = JRequest::getInt('virtuemart_order_id', 0); if (!$virtuemart_order_id) { $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber(JRequest::getString('order_number')); } $orderDetails = $orderModel->getOrder($virtuemart_order_id); JLoader::register('Permissions', JPATH_VM_ADMINISTRATOR . '/helpers/permissions.php'); if (!Permissions::getInstance()->check("admin")) { if (!empty($orderDetails['details']['BT']->virtuemart_user_id)) { if ($orderDetails['details']['BT']->virtuemart_user_id != $cuid) { echo 'view ' . JText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'); return; } } } } return $orderDetails; }
/** * This is a proxy function to return an order safely, we may set the getOrder function to private * Maybe the right place would be the controller, cause there are JRequests in it. But for a fast solution, * still better than to have it 3-4 times in the view.html.php of the views. * @author Max Milbers * * @return array */ public function getMyOrderDetails($orderID = 0, $orderNumber = false, $orderPass = false) { $_currentUser = JFactory::getUser(); $cuid = $_currentUser->get('id'); $orderDetails = false; // If the user is not logged in, we will check the order number and order pass if (empty($cuid)) { $sess = JFactory::getSession(); $orderNumber = vRequest::getString('order_number', $orderNumber); $tries = $sess->get('getOrderDetails.' . $orderNumber, 0); if ($tries > 5) { vmDebug('Too many tries, Invalid order_number/password ' . vmText::_('COM_VIRTUEMART_RESTRICTED_ACCESS')); return false; } // If the user is not logged in, we will check the order number and order pass if ($orderPass = vRequest::getString('order_pass', $orderPass)) { $orderId = $this->getOrderIdByOrderPass($orderNumber, $orderPass); if (empty($orderId)) { echo vmText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'); vmdebug('getMyOrderDetails COM_VIRTUEMART_RESTRICTED_ACCESS', $orderNumber, $orderPass, $tries); $tries++; $sess->set('getOrderDetails.' . $orderNumber, $tries); return false; } $orderDetails = $this->getOrder($orderId); } } else { // If the user is logged in, we will check if the order belongs to him $virtuemart_order_id = vRequest::getInt('virtuemart_order_id', $orderID); if (!$virtuemart_order_id) { $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber(vRequest::getString('order_number')); } $orderDetails = $this->getOrder($virtuemart_order_id); $user = JFactory::getUser(); if (!vmAccess::manager('orders')) { if (!isset($orderDetails['details']['BT']->virtuemart_user_id)) { $orderDetails['details']['BT']->virtuemart_user_id = 0; } if ($orderDetails['details']['BT']->virtuemart_user_id != $cuid) { echo vmText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'); return false; } } } return $orderDetails; }
/** * @return bool|null */ function plgVmOnPaymentNotification() { //$this->_debug = true; if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $paypal_data = JRequest::get('post'); if (!isset($paypal_data['invoice'])) { return FALSE; } $order_number = $paypal_data['invoice']; if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($paypal_data['invoice']))) { return FALSE; } if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { return FALSE; } $method = $this->getVmPluginMethod($payments[0]->virtuemart_paymentmethod_id); if (!$this->selectedThisElement($method->payment_element)) { return FALSE; } $this->_debug = $method->debug; $this->logInfo('paypal_data ' . implode(' ', $paypal_data), 'message'); // _processIPN checks that $res== "VERIFIED" if (!$this->_processIPN($paypal_data, $method)) { $this->logInfo('paypal_data _processIPN FALSE', 'message'); return FALSE; } //$this->_storePaypalInternalData ($method, $paypal_data, $virtuemart_order_id, $payment->virtuemart_paymentmethod_id); $modelOrder = VmModel::getModel('orders'); $order = array(); /* * https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables * The status of the payment: * Canceled_Reversal: A reversal has been canceled. For example, you won a dispute with the customer, and the funds for the transaction that was reversed have been returned to you. * Completed: The payment has been completed, and the funds have been added successfully to your account balance. * Created: A German ELV payment is made using Express Checkout. * Denied: You denied the payment. This happens only if the payment was previously pending because of possible reasons described for the pending_reason variable or the Fraud_Management_Filters_x variable. * Expired: This authorization has expired and cannot be captured. * Failed: The payment has failed. This happens only if the payment was made from your customer’s bank account. * Pending: The payment is pending. See pending_reason for more information. * Refunded: You refunded the payment. * Reversed: A payment was reversed due to a chargeback or other type of reversal. The funds have been removed from your account balance and returned to the buyer. The reason for the reversal is specified in the ReasonCode element. * Processed: A payment has been accepted. * Voided: This authorization has been voided. * */ $lang = JFactory::getLanguage(); $order['customer_notified'] = 1; // 1. check the payment_status is Completed if (strcmp($paypal_data['payment_status'], 'Completed') == 0) { // 2. check that txn_id has not been previously processed if ($this->_check_txn_id_already_processed($payments, $paypal_data['txn_id'], $method)) { return FALSE; } // 3. check email and amount currency is correct if (!$this->_check_email_amount_currency($payments, $this->_getMerchantEmail($method), $paypal_data)) { return FALSE; } // now we can process the payment $order['order_status'] = $method->status_success; $order['comments'] = JText::sprintf('VMPAYMENT_PAYPAL_PAYMENT_STATUS_CONFIRMED', $order_number); } elseif (strcmp($paypal_data['payment_status'], 'Pending') == 0) { $key = 'VMPAYMENT_PAYPAL_PENDING_REASON_FE_' . strtoupper($paypal_data['pending_reason']); if (!$lang->hasKey($key)) { $key = 'VMPAYMENT_PAYPAL_PENDING_REASON_FE_DEFAULT'; } $order['comments'] = JText::sprintf('VMPAYMENT_PAYPAL_PAYMENT_STATUS_PENDING', $order_number) . JText::_($key); $order['order_status'] = $method->status_pending; } elseif (strcmp($paypal_data['payment_status'], 'Refunded') == 0 and isset($method->status_refunded)) { if ($this->_is_full_refund($payments, $paypal_data)) { $order['comments'] = JText::sprintf('VMPAYMENT_PAYPAL_PAYMENT_STATUS_REFUNDED', $order_number); $order['order_status'] = $method->status_refunded; } else { $order['comments'] = JText::sprintf('VMPAYMENT_PAYPAL_PAYMENT_STATUS_PARTIAL_REFUNDED', $order_number); $order['order_status'] = isset($method->status_partial_refunded) ? $method->status_partial_refunded : 'R'; } } elseif (isset($paypal_data['payment_status'])) { $order['order_status'] = $method->status_canceled; } else { /* * a notification was received that concerns one of the payment (since $paypal_data['invoice'] is found in our table), * but the IPN notification has no $paypal_data['payment_status'] * We just log the info in the order, and do not change the status, do not notify the customer */ $order['comments'] = JText::_('VMPAYMENT_PAYPAL_IPN_NOTIFICATION_RECEIVED'); $order['customer_notified'] = 0; } $this->_storePaypalInternalData($method, $paypal_data, $virtuemart_order_id, $payments[0]->virtuemart_paymentmethod_id); $this->logInfo('plgVmOnPaymentNotification return new_status:' . $order['order_status'], 'message'); $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, TRUE); //// remove vmcart if (isset($paypal_data['custom'])) { $this->emptyCart($paypal_data['custom'], $order_number); } //die(); }
function plgVmOnPaymentNotification() { //https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/ if (!class_exists('VirtueMartModelOrders')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'); } $paypal_data = JRequest::get('post'); //Recuring payment return rp_invoice_id instead of invoice if (array_key_exists('rp_invoice_id', $paypal_data)) { $paypal_data['invoice'] = $paypal_data['rp_invoice_id']; } if (!isset($paypal_data['invoice'])) { return FALSE; } $order_number = $paypal_data['invoice']; if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($paypal_data['invoice']))) { return FALSE; } if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { return FALSE; } $this->_currentMethod = $this->getVmPluginMethod($payments[0]->virtuemart_paymentmethod_id); if (!$this->selectedThisElement($this->_currentMethod->payment_element)) { return FALSE; } $orderModel = VmModel::getModel('orders'); $order = $orderModel->getOrder($virtuemart_order_id); $paypalInterface = $this->_loadPayPalInterface(); $paypalInterface->setOrder($order); $paypalInterface->debugLog($paypal_data, 'PaymentNotification, paypal_data:', 'debug'); $paypalInterface->debugLog($order_number, 'PaymentNotification, order_number:', 'debug'); $paypalInterface->debugLog($payments[0]->virtuemart_paymentmethod_id, 'PaymentNotification, virtuemart_paymentmethod_id:', 'debug'); $order_history = $paypalInterface->processIPN($paypal_data, $payments); if (!$order_history) { return false; } else { $this->_storePaypalInternalData( $paypal_data, $virtuemart_order_id, $payments[0]->virtuemart_paymentmethod_id); $paypalInterface->debugLog('order_number:'.$order_number.' new_status:' . $order_history['order_status'], 'plgVmOnPaymentNotification', 'debug'); $orderModel->updateStatusForOneOrder($virtuemart_order_id, $order_history, TRUE); //// remove vmcart if (isset($paypal_data['custom'])) { $this->emptyCart( $paypal_data['custom'], $order_number ); } } }
/** * @return bool|null */ function plgVmOnPaymentNotification () { if (!class_exists ('VirtueMartModelOrders')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'); } $paypal_data = JRequest::get ('post'); if (!isset($paypal_data['invoice'])) { return NULL; } $order_number = $paypal_data['invoice']; if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber ($paypal_data['invoice']))) { return NULL; } $vendorId = 0; if (!($payment = $this->getDataByOrderId ($virtuemart_order_id))) { return NULL; } $method = $this->getVmPluginMethod ($payment->virtuemart_paymentmethod_id); if (!$this->selectedThisElement ($method->payment_element)) { return FALSE; } $this->_debug = $method->debug; if (!$payment) { $this->logInfo ('getDataByOrderId payment not found: exit ', 'ERROR'); return NULL; } $this->logInfo ('paypal_data ' . implode (' ', $paypal_data), 'message'); $this->_storePaypalInternalData ($method, $paypal_data, $virtuemart_order_id, $payment->virtuemart_paymentmethod_id); $modelOrder = VmModel::getModel ('orders'); $order = array(); $error_msg = $this->_processIPN ($paypal_data, $method, $virtuemart_order_id); $this->logInfo ('process IPN ' . $error_msg, 'message'); if (!(empty($error_msg))) { $order['customer_notified'] = 0; $order['order_status'] = $method->status_canceled; $order['comments'] = 'process IPN ' . $error_msg; /** @var $modelOrder array() */ $modelOrder->updateStatusForOneOrder ($virtuemart_order_id, $order, TRUE); $this->logInfo ('process IPN ' . $error_msg . ' ' . $order['order_status'] , 'ERROR'); return NULL; } else { $this->logInfo ('process IPN OK', 'message'); } /* * https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables * The status of the payment: * Canceled_Reversal: A reversal has been canceled. For example, you won a dispute with the customer, and the funds for the transaction that was reversed have been returned to you. * Completed: The payment has been completed, and the funds have been added successfully to your account balance. * Created: A German ELV payment is made using Express Checkout. * Denied: You denied the payment. This happens only if the payment was previously pending because of possible reasons described for the pending_reason variable or the Fraud_Management_Filters_x variable. * Expired: This authorization has expired and cannot be captured. * Failed: The payment has failed. This happens only if the payment was made from your customer’s bank account. * Pending: The payment is pending. See pending_reason for more information. * Refunded: You refunded the payment. * Reversed: A payment was reversed due to a chargeback or other type of reversal. The funds have been removed from your account balance and returned to the buyer. The reason for the reversal is specified in the ReasonCode element. * Processed: A payment has been accepted. * Voided: This authorization has been voided. * */ if (empty($paypal_data['payment_status']) || ($paypal_data['payment_status'] != 'Completed' && $paypal_data['payment_status'] != 'Pending')) { //return false; } $lang = JFactory::getLanguage (); $order['customer_notified'] = 1; if (strcmp ($paypal_data['payment_status'], 'Completed') == 0) { $order['order_status'] = $method->status_success; $order['comments'] = JText::sprintf ('VMPAYMENT_PAYPAL_PAYMENT_STATUS_CONFIRMED', $order_number); } elseif (strcmp ($paypal_data['payment_status'], 'Pending') == 0) { $key = 'VMPAYMENT_PAYPAL_PENDING_REASON_FE_' . strtoupper ($paypal_data['pending_reason']); if (!$lang->hasKey ($key)) { $key = 'VMPAYMENT_PAYPAL_PENDING_REASON_FE_DEFAULT'; } $order['comments'] = JText::sprintf ('VMPAYMENT_PAYPAL_PAYMENT_STATUS_PENDING', $order_number) . JText::_ ($key); $order['order_status'] = $method->status_pending; } else { $order['order_status'] = $method->status_canceled; } $this->logInfo ('plgVmOnPaymentNotification return new_status:' . $order['order_status'], 'message'); $modelOrder->updateStatusForOneOrder ($virtuemart_order_id, $order, TRUE); //// remove vmcart $this->emptyCart ($paypal_data['custom'], $order_number); //die(); }
/** * @return bool|null */ function plgVmOnPaymentNotification() { //$this->_debug = true; if (!class_exists('VirtueMartModelOrders')) { require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php'; } $virtuemart_paymentmethod_id = vRequest::getInt('pm', 0); //$this->_debug=true; if (!($this->_currentMethod = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($this->_currentMethod->payment_element)) { return FALSE; } $order_number = vRequest::getString('on', ''); if (empty($order_number)) { return FALSE; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { return FALSE; } if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { return FALSE; } $this->debugLog('OK', 'plgVmOnPaymentNotification', 'debug'); if (!class_exists('SofortLib')) { require VMPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'sofort' . DS . 'sofort' . DS . 'library' . DS . 'sofortLib.php'; } $sofortLib_Notification = new SofortLib_Notification(); $this->sofortLog($sofortLib_Notification); $transactionId = $sofortLib_Notification->getNotification(); if ($sofortLib_Notification->isError()) { $this->debugLog('SOFORT notification return Error ' . $sofortLib_Notification->getError(), 'plgVmOnPaymentNotification', 'error'); } //no valid parameters/xml if (empty($transactionId)) { $this->debugLog('no transaction ID for order number ' . $order_number, 'plgVmOnPaymentNotification', 'error'); } if (empty($transactionId) || $sofortLib_Notification->isError()) { return FALSE; } $this->debugLog($transactionId, 'plgVmOnPaymentNotification Transaction ID ', 'debug'); $sofortLib_TransactionData = new SofortLib_TransactionData(trim($this->_currentMethod->configuration_key)); $this->sofortLog($sofortLib_TransactionData); $sofortLib_TransactionData->setTransaction($transactionId)->sendRequest(); // check that secret , and order are identical $security = vRequest::getString('security', ''); if ($security != $payments[0]->security) { $this->debugLog("security token received: " . $security . " security token expected: " . $payments[0]->security, 'plgVmOnPaymentNotification', 'error'); return false; } $paymentMethod = $sofortLib_TransactionData->getPaymentMethod(); if ($paymentMethod != self::SU_SOFORTBANKING) { $this->debugLog("Payment method is " . $paymentMethod . " Should be SU" . 'plgVmOnPaymentNotification', 'error'); return false; } $sofort_data['sofort_response_amount'] = $sofortLib_TransactionData->getAmount(); $sofort_data['sofort_response_currency'] = $sofortLib_TransactionData->getCurrency(); // check that the amount is the same if (!$this->_checkAmountAndCurrency($sofort_data, $payments)) { return false; } $modelOrder = VmModel::getModel('orders'); $order_history = array(); $status = 'status_' . $sofortLib_TransactionData->getStatus(); //$this->debugLog('plgVmOnPaymentNotification getStatus:' .$status. ' '.var_export($method, true) , 'message'); $order_history['customer_notified'] = true; $order_history['order_status'] = $this->_currentMethod->{$status}; $order_history['comments'] = vmText::_('VMPAYMENT_SOFORT_RESPONSE_STATUS_REASON_' . $sofortLib_TransactionData->getStatusReason()); $sofort_data['sofort_response_status_reason'] = $sofortLib_TransactionData->getStatusReason(); $sofort_data['sofort_response_transaction'] = $sofortLib_TransactionData->getTransaction(); $sofort_data['payment_name'] = str_replace(array('\\t', '\\n'), '', $this->renderPluginName($this->_currentMethod)); $sofort_data['virtuemart_order_id'] = $payments[0]->virtuemart_order_id; $sofort_data['order_number'] = $payments[0]->order_number; $sofort_data['virtuemart_paymentmethod_id'] = $payments[0]->virtuemart_paymentmethod_id; $sofort_data['sofort_response_status'] = $sofortLib_TransactionData->getStatus(); $sofort_data['sofort_response_status_reason'] = $sofortLib_TransactionData->getStatusReason(); $this->debugLog(var_export($sofort_data, true), 'plgVmOnPaymentNotification storePSPluginInternalData ', 'debug'); $this->storePSPluginInternalData($sofort_data); $modelOrder->updateStatusForOneOrder($payments[0]->virtuemart_order_id, $order_history, false); }
function plgVmOnPaymentNotification() { if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } outToLog('#plgVmOnPaymentNotification: started'); $merchant_key = $this->getMerchantKeyForOos(); if (!$merchant_key) { $msg = "No OOS secret key found in configuration"; outToLog($msg); throw new Exception($msg); } $encrypted_request = file_get_contents('php://input'); //$encrypted_request = $_POST['encrypted_request']; outToLog('#plgVmOnPaymentNotification: encrypted_request base64 = ' . base64_encode($encrypted_request)); //$encrypted_request = base64_decode($encrypted_request); $decrypted_request = $this->decrypt_aes128_ecb_pkcs5($encrypted_request, $merchant_key); outToLog("#plgVmOnPaymentNotification: using secret key {$merchant_key}"); outToLog("#plgVmOnPaymentNotification: decrypted_request: [{$decrypted_request}]"); $json_request = json_decode($decrypted_request, true); if (!$json_request) { $msg = 'Failed decrypting secret text or decoding JSON'; outToLog("#plgVmOnPaymentNotification: {$msg}"); throw new Exception($msg); } $ordersArray = $json_request['payments']; outToLog('#plgVmOnPaymentNotification: num orders = ' . count($ordersArray)); if (!$ordersArray) { return false; } $jsonResponsePayments = array(); for ($i = 0; $i < count($ordersArray); $i++) { $orderRecord = $ordersArray[$i]; outToLog('RESPONSE: order ' . ($i + 1) . ' = ' . $orderRecord["orderId"]); $oosPayment = array("pay_for" => $orderRecord["orderId"], "order_amount" => $orderRecord["amount"], "order_currency" => "RUB", "paymentDateTime" => date('l jS \\of F Y h:i:s A'), "state" => $orderRecord['state']); $order_amount = $this->to_float($oosPayment['order_amount']); $orderId = $oosPayment['pay_for']; if (!$orderId) { continue; } $vmOrderId = VirtueMartModelOrders::getOrderIdByOrderNumber($orderId); if (!$vmOrderId) { array_push($jsonResponsePayments, array("orderId" => $orderId, "action" => RESPONSE_ACTION_REJECT)); continue; } $vmPayments = $this->getDatasByOrderId($vmOrderId); if (!$vmPayments) { continue; } $vmPM = $this->getVmPluginMethod($vmPayments[0]->virtuemart_paymentmethod_id); if (!$this->selectedThisElement($vmPM->payment_element)) { continue; } $this->logInfo('oos_data ' . implode(' ', $oosPayment), 'message'); $error = ''; //$pay_for = $order_number; $order_currency = $oosPayment['order_currency']; //проверяем pay запрос $localOrder = array('customer_notified' => 1, 'order_status' => $vmPM->status_pending); //получаем данные outToLog('RESPONSE: virtuemart_order_id = ' . $vmOrderId . ' order_number = ' . $orderId . '$order_amount = ' . $order_amount); if ($merchant_key != $this->_getSecretWord($vmPM)) { $error .= JText::_('PLG_OOS_VM2_ERROR_3') . '<br>'; } if (empty($order_amount)) { $error .= JText::_('PLG_OOS_VM2_ERROR_5') . '<br>'; } else { if (!is_numeric($order_amount)) { $error .= JText::_('PLG_OOS_VM2_ERROR_4') . '<br>'; } } if (empty($order_currency)) { $error .= JText::_('PLG_OOS_VM2_ERROR_6') . '<br>'; } else { if (strlen($order_currency) > 4) { $error .= JText::_('PLG_OOS_VM2_ERROR_7') . '<br>'; } } //если нет ошибок if (!$error) { if ($orderId) { //сверяем строчки хеша (присланную и созданную нами) $state = $oosPayment['state']; $responseAction = null; if ($state == 'err') { $jtext = JText::_('PLG_OOS_VM2_ERROR_11'); $localOrder['order_status'] = $vmPM->status_canceled; outToLog('RESPONSE: order[order_status] = ' . $localOrder['order_status'] . ', comment = ' . $jtext); $localOrder['comments'] = sprintf($jtext, $orderId); $responseAction = RESPONSE_ACTION_CONFIRM; } else { if ($state == 'rej') { $jtext = JText::_('PLG_OOS_VM2_ERROR_12'); $localOrder['order_status'] = $vmPM->status_canceled; outToLog('RESPONSE: order[order_status] = ' . $localOrder['order_status'] . ', comment = ' . $jtext); $localOrder['comments'] = sprintf($jtext, $orderId); $responseAction = RESPONSE_ACTION_CONFIRM; } else { if ($state == 'ref') { $jtext = JText::_('PLG_OOS_VM2_ERROR_13'); $localOrder['order_status'] = $vmPM->status_success; outToLog('RESPONSE: order[order_status] = ' . $localOrder['order_status'] . ', comment = ' . $jtext); $localOrder['comments'] = sprintf($jtext, $orderId); $responseAction = RESPONSE_ACTION_CONFIRM; } else { if ($state == 'exp') { $jtext = JText::_('PLG_OOS_VM2_ERROR_14'); $localOrder['order_status'] = $vmPM->status_pending; outToLog('RESPONSE: order[order_status] = ' . $localOrder['order_status'] . ', comment = ' . $jtext); $localOrder['comments'] = sprintf($jtext, $orderId); $responseAction = RESPONSE_ACTION_CONFIRM; } else { if ($state == 'end') { $jtext = JText::_('PLG_OOS_VM2_ERROR_15'); $localOrder['order_status'] = $vmPM->status_success; outToLog('RESPONSE: order[order_status] = ' . $localOrder['order_status'] . ', comment = ' . $jtext); $localOrder['comments'] = sprintf($jtext, $orderId); $responseAction = RESPONSE_ACTION_CONFIRM; } } } } } if ($responseAction) { array_push($jsonResponsePayments, array("orderId" => $orderId, "action" => $responseAction)); } } else { // вобщем-то сюда попасть уже не можем $localOrder['order_status'] = $vmPM->status_canceled; $localOrder['comments'] = JText::_('PLG_OOS_VM2_ERROR_9'); } } else { outToLog('$error = ' . $error); //если есть ошибки $localOrder['order_status'] = $vmPM->status_canceled; $localOrder['comments'] = JText::_('PLG_OOS_VM2_ERROR_9') . ': ' . $error; } $this->_storeOosInternalData($vmPM, $oosPayment, $vmOrderId, $vmPayments[0]->virtuemart_paymentmethod_id); $this->logInfo('plgVmOnPaymentNotification return new_status: ' . $localOrder['order_status'], 'message'); $modelOrder = VmModel::getModel('orders'); $modelOrder->updateStatusForOneOrder($vmOrderId, $localOrder, true); if (isset($oosPayment['return_context'])) { $this->emptyCart($oosPayment['return_context'], $orderId); } } if ($jsonResponsePayments) { $jsonResponse = array("payments" => $jsonResponsePayments); $jsonResponseStr = json_encode($jsonResponse); outToLog("json respone: {$jsonResponseStr}"); echo "<!-- JSON BEGIN"; echo $jsonResponseStr; echo "JSON END -->"; } }
public function display($tpl = null) { $mainframe = JFactory::getApplication(); $pathway = $mainframe->getPathway(); $task = JRequest::getWord('task', 'list'); $layoutName = JRequest::getWord('layout', 'list'); $this->setLayout($layoutName); $_currentUser = JFactory::getUser(); $document = JFactory::getDocument(); if (!empty($tpl)) { $format = $tpl; } else { $format = JRequest::getWord('format', 'html'); } $this->assignRef('format', $format); if ($format == 'pdf') { $document->setTitle(JText::_('COM_VIRTUEMART_INVOICE')); //PDF needs more RAM than usual $memory_limit = ini_get('memory_limit'); if ($memory_limit < 40) { @ini_set('memory_limit', '40M'); } } else { if ($layoutName == 'details') { $document->setTitle(JText::_('COM_VIRTUEMART_ACC_ORDER_INFO')); $pathway->additem(JText::_('COM_VIRTUEMART_ACC_ORDER_INFO')); } else { $document->setTitle(JText::_('COM_VIRTUEMART_ORDERS_VIEW_DEFAULT_TITLE')); $pathway->additem(JText::_('COM_VIRTUEMART_ORDERS_VIEW_DEFAULT_TITLE')); } } $orderModel = VmModel::getModel('orders'); if ($layoutName == 'details') { $order_list_link = FALSE; $cuid = $_currentUser->get('id'); // if(!empty($cuid)){ $order_list_link = JRoute::_('index.php?option=com_virtuemart&view=orders&layout=list'); // } else { // $order_list_link = false; // $order_list_link = JRoute::_('index.php?option=com_virtuemart&view=orders');; // } $this->assignRef('order_list_link', $order_list_link); if (empty($cuid)) { // If the user is not logged in, we will check the order number and order pass if ($orderPass = JRequest::getString('order_pass', false)) { $orderNumber = JRequest::getString('order_number', false); $orderId = $orderModel->getOrderIdByOrderPass($orderNumber, $orderPass); if (empty($orderId)) { echo JText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'); return; } $orderDetails = $orderModel->getOrder($orderId); } } else { // If the user is logged in, we will check if the order belongs to him $virtuemart_order_id = JRequest::getInt('virtuemart_order_id', 0); if (!$virtuemart_order_id) { $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber(JRequest::getString('order_number')); } $orderDetails = $orderModel->getOrder($virtuemart_order_id); if (!class_exists('Permissions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php'; } if (!Permissions::getInstance()->check("admin")) { if (!empty($orderDetails['details']['BT']->virtuemart_user_id)) { if ($orderDetails['details']['BT']->virtuemart_user_id != $cuid) { echo JText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'); return; } } } } if (empty($orderDetails['details'])) { echo JText::_('COM_VIRTUEMART_ORDER_NOTFOUND'); return; } $userFieldsModel = VmModel::getModel('userfields'); $_userFields = $userFieldsModel->getUserFields('account', array('captcha' => true, 'delimiters' => true), array('delimiter_userinfo', 'user_is_vendor', 'username', 'password', 'password2', 'agreed', 'address_type')); $orderbt = $orderDetails['details']['BT']; $orderst = array_key_exists('ST', $orderDetails['details']) ? $orderDetails['details']['ST'] : $orderbt; $userfields = $userFieldsModel->getUserFieldsFilled($_userFields, $orderbt); $_userFields = $userFieldsModel->getUserFields('shipment', array(), array('delimiter_userinfo', 'username', 'email', 'password', 'password2', 'agreed', 'address_type')); $shipmentfields = $userFieldsModel->getUserFieldsFilled($_userFields, $orderst); $shipment_name = ''; if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmshipment'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEShipment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_shipmentmethod_id, &$shipment_name)); $payment_name = ''; if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); $dispatcher = JDispatcher::getInstance(); $returnValues = $dispatcher->trigger('plgVmOnShowOrderFEPayment', array($orderDetails['details']['BT']->virtuemart_order_id, $orderDetails['details']['BT']->virtuemart_paymentmethod_id, &$payment_name)); if ($format == 'pdf') { $invoiceNumberDate = array(); $return = $orderModel->createInvoiceNumber($orderDetails['details']['BT'], $invoiceNumberDate); if (empty($invoiceNumberDate)) { $invoiceNumberDate[0] = 'no invoice number accessible'; $invoiceNumberDate[1] = 'no invoice date accessible'; } $this->assignRef('invoiceNumber', $invoiceNumberDate[0]); $this->assignRef('invoiceDate', $invoiceNumberDate[1]); } $this->assignRef('userfields', $userfields); $this->assignRef('shipmentfields', $shipmentfields); $this->assignRef('shipment_name', $shipment_name); $this->assignRef('payment_name', $payment_name); $this->assignRef('orderdetails', $orderDetails); $tmpl = JRequest::getWord('tmpl'); $print = false; if ($tmpl) { $print = true; } $this->prepareVendor(); $this->assignRef('print', $print); $vendorId = 1; $emailCurrencyId = 0; $exchangeRate = FALSE; if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('plgVmgetEmailCurrency', array($orderDetails['details']['BT']->virtuemart_paymentmethod_id, $orderDetails['details']['BT']->virtuemart_order_id, &$emailCurrencyId)); if (!class_exists('CurrencyDisplay')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'; } $currency = CurrencyDisplay::getInstance($emailCurrencyId, $vendorId); if ($emailCurrencyId) { vmdebug('exchangerate', $orderDetails['details']['BT']->user_currency_rate); $currency->exchangeRateShopper = $orderDetails['details']['BT']->user_currency_rate; } $this->assignRef('currency', $currency); // Implement the Joomla panels. If we need a ShipTo tab, make it the active one. // In tmpl/edit.php, this is the 4th tab (0-based, so set to 3 above) // jimport('joomla.html.pane'); // $pane = JPane::getInstance((__VM_ORDER_USE_SLIDERS?'Sliders':'Tabs')); // $this->assignRef('pane', $pane); } else { // 'list' -. default $useSSL = VmConfig::get('useSSL', 0); $useXHTML = true; $this->assignRef('useSSL', $useSSL); $this->assignRef('useXHTML', $useXHTML); if ($_currentUser->get('id') == 0) { // getOrdersList() returns all orders when no userID is set (admin function), // so explicetly define an empty array when not logged in. $orderList = array(); } else { $orderList = $orderModel->getOrdersList($_currentUser->get('id'), TRUE); foreach ($orderList as $order) { $vendorId = 1; $emailCurrencyId = 0; $exchangeRate = FALSE; if (!class_exists('vmPSPlugin')) { require JPATH_VM_PLUGINS . DS . 'vmpsplugin.php'; } JPluginHelper::importPlugin('vmpayment'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('plgVmgetEmailCurrency', array($order->virtuemart_paymentmethod_id, $order->virtuemart_order_id, &$emailCurrencyId)); if (!class_exists('CurrencyDisplay')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'; } $currency = CurrencyDisplay::getInstance($emailCurrencyId, $vendorId); if ($emailCurrencyId) { vmdebug('exchangerate', $order->user_currency_rate); $currency->exchangeRateShopper = $order->user_currency_rate; } $order->currency = $currency; } } $this->assignRef('orderlist', $orderList); } /* if (!class_exists('CurrencyDisplay')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'currencydisplay.php'); $currency = CurrencyDisplay::getInstance(); $this->assignRef('currency', $currency); */ $orderStatusModel = VmModel::getModel('orderstatus'); $_orderstatuses = $orderStatusModel->getOrderStatusList(); $orderstatuses = array(); foreach ($_orderstatuses as $_ordstat) { $orderstatuses[$_ordstat->order_status_code] = JText::_($_ordstat->order_status_name); } $this->assignRef('orderstatuses', $orderstatuses); if (!class_exists('ShopFunctions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php'; } // this is no setting in BE to change the layout ! //shopFunctionsF::setVmTemplate($this,0,0,$layoutName); parent::display($tpl); }
function plgVmOnPaymentNotification() { if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $mb_data = JRequest::get('post'); if (!isset($mb_data['transaction_id'])) { //$this->logInfo (__FUNCTION__ . ' transaction_id not set: ' . $mb_data['transaction_id'], 'message'); return; } $order_number = $mb_data['transaction_id']; if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($mb_data['transaction_id']))) { $this->logInfo(__FUNCTION__ . ' Can\'t get VirtueMart order id', 'message'); return; } if (!($payment = $this->getDataByOrderId($virtuemart_order_id))) { $this->logInfo(__FUNCTION__ . ' Can\'t get payment type', 'message'); return; } $method = $this->getVmPluginMethod($payment->virtuemart_paymentmethod_id); if (!$this->selectedThisElement($method->payment_element)) { $this->logInfo(__FUNCTION__ . ' payment method not selected', 'message'); return FALSE; } if (!$payment) { $this->logInfo('getDataByOrderId payment not found: exit ', 'ERROR'); return NULL; } $this->_storeInternalData($method, $mb_data, $virtuemart_order_id); $modelOrder = VmModel::getModel('orders'); $vmorder = $modelOrder->getOrder($virtuemart_order_id); $order = array(); $error_msg = $this->_processStatus($mb_data, $vmorder, $method); if ($error_msg) { $order['customer_notified'] = 0; $order['order_status'] = $method->status_canceled; $order['comments'] = 'process IPN ' . $error_msg; $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, TRUE); $this->logInfo('process IPN ' . $error_msg, 'ERROR'); } else { $this->logInfo('process IPN OK', 'message'); } if (empty($mb_data['payment_status']) || $mb_data['payment_status'] != 'Completed' && $mb_data['payment_status'] != 'Pending') { // can't get status or payment failed //return false; } $order['customer_notified'] = 1; if (strcmp($mb_data['payment_status'], 'Completed') == 0) { $order['order_status'] = $method->status_success; $order['comments'] = JText::sprintf('VMPAYMENT_MONEYBOOKERS_PAYMENT_STATUS_CONFIRMED', $order_number); } elseif (strcmp($mb_data['payment_status'], 'Pending') == 0) { $order['comments'] = JText::sprintf('VMPAYMENT_MONEYBOOKERS_PAYMENT_STATUS_PENDING', $order_number); $order['order_status'] = $method->status_pending; } else { $order['order_status'] = $method->status_canceled; } $this->logInfo('plgVmOnPaymentNotification return new_status:' . $order['order_status'], 'message'); $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, TRUE); //// remove vmcart $this->emptyCart($payment->user_session, $mb_data['transaction_id']); }
/** * IPN_Handler * * This trigger is invoked whenever a new notification needs to be processed, * and will call the IPN API * * */ private function ipn () { // ERP mode turns off all automated authorization and capture functionality // as well as IPN reception and / or polling, and disables any admin UI functionality that may trigger //If the authorization is done by ERP then the IPN URL set in amazon should not be this one. // we keep it anyway, for testing purposes if ($this->isERPModeEnabled() and $this->isAuthorizationDoneByErp()) { return; } // Fetch all HTTP request headers $headers = getallheaders(); $body = file_get_contents('php://input'); $this->debugLog($headers, 'AMAZON IPN HEADERS debug', 'debug'); $this->debugLog($body, 'AMAZON IPN BODY debug', 'debug'); $this->loadAmazonClass('OffAmazonPaymentsNotifications_Client'); $this->loadVmClass('VirtueMartModelOrders', JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'); try { $client = new OffAmazonPaymentsNotifications_Client(); $notification = $client->parseRawMessage($headers, $body); } catch (OffAmazonPaymentsNotifications_InvalidMessageException $e) { $this->debugLog($e->getMessage() . __FUNCTION__ . ' $body', 'error'); header("HTTP/1.1 503 Service Unavailable"); exit(0); } $notificationType = $notification->getNotificationType(); $this->debugLog($notificationType, 'ipn', 'debug'); if (!$this->isValidNotificationtype($notificationType)) { $this->debugLog($notificationType, 'ipn NOT isValidNotificationtype', 'error'); return; } $notificationClass = 'amazonHelper' . $notificationType; $notificationFile = JPATH_SITE . DS . 'plugins' . DS . 'vmpayment' . DS . 'amazon' . DS . 'helpers' . DS . strtolower($notificationType . '.php'); if (!file_exists($notificationFile)) { $this->debugLog("Unknown notification Type: " . $notificationType, __FUNCTION__, 'error'); return false; } if (!class_exists($notificationClass)) { require(JPATH_SITE . DS . 'plugins' . DS . 'vmpayment' . DS . 'amazon' . DS . 'helpers' . DS . 'helper.php'); require($notificationFile); } $this->debugLog($notificationType, 'ipn', 'debug'); $notificationResponse = new $notificationClass($notification, $this->_currentMethod); $this->debugLog("<pre>" . var_export($notificationResponse->amazonData, true) . "</pre>", __FUNCTION__, 'debug'); if (!($order_number = $notificationResponse->getReferenceId())) { $this->debugLog('no ReferenceId IPN received', $notificationClass, 'error'); return true; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { $this->debugLog('Received a ' . $notificationClass . ' with order number ' . $order_number . ' but no order in DB with that number', $notificationClass, 'error'); return true; } $orderModel = VmModel::getModel('orders'); $order = $orderModel->getOrder($virtuemart_order_id); if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { // we ignore it because we receive also notification when refund/capture is done in the Amazon BE, and there is no valid reference //$this->debugLog('Received a ' . $newClass . ' with order number ' . $order_number . 'but no order in DB with that number in AMAZON payment table', $newClass, 'error'); return true; } $amazonState = $notificationResponse->onNotificationUpdateOrderHistory($order, $payments); $this->storeAmazonInternalData($order, NULL, NULL, $notification, NULL, $notificationResponse->getStoreInternalData()); $nextOperation = $notificationResponse->onNotificationNextOperation($order, $payments, $amazonState); if ($nextOperation === false) { return; } if (!function_exists($nextOperation)) { //$this->debugLog('Trying to call ' . $nextOperation . ' but the function does not exists: Programming error', $notificationClass, 'error'); } $this->$nextOperation($payments, $order); }
function update_status($status, $order_id, $text = 'VMPAYMENT_SEB_PAYMENT_CANCELED') { if ($order_id) { // send the email only if payment has been accepted if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $modelOrder = new VirtueMartModelOrders(); $order['order_status'] = $status; $order['virtuemart_order_id'] = $order_id; $order['customer_notified'] = 1; $order['comments'] = JTExt::sprintf($text, $order_id); $modelOrder->updateStatusForOneOrder($order_id, $order, true); } }
function plgVmOnPaymentResponseReceived (&$html) { if (!class_exists ('VirtueMartCart')) { require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'); } if (!class_exists ('shopFunctionsF')) { require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php'); } if (!class_exists ('VirtueMartModelOrders')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'); } $virtuemart_paymentmethod_id = JRequest::getInt ('pm', 0); $order_number = JRequest::getString ('on', 0); if (!($method = $this->getVmPluginMethod ($virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement ($method->payment_element)) { return NULL; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber ($order_number))) { return NULL; } $db = JFactory::getDBO (); $_q = 'SELECT * FROM `' . $this->_tablename . '` ' . 'WHERE `virtuemart_order_id` = ' . $virtuemart_order_id; $db->setQuery ($_q); if (!($paymentData = $db->loadObject ())) { // JError::raiseWarning(500, $db->getErrorMsg()); } vmdebug ('HEIDELPAY paymentdata', $paymentData); $cart = VirtueMartCart::getCart (); $cart->emptyCart (); if ($paymentData->processing_result == "NOK") { vmError ('VMPAYMENT_HEIDELPAY_PAYMENT_FAILED','VMPAYMENT_HEIDELPAY_PAYMENT_FAILED'); vmError (" - " . $paymentData->comment," - " . $paymentData->comment); } else { vmInfo ('VMPAYMENT_HEIDELPAY_PAYMENT_SUCESS'); $html = "<h3>".JText::sprintf ('VMPAYMENT_HEIDELPAY_ORDER_NR') . ': ' . $order_number . " </h3>" ; $tmpkom = preg_replace("/\(-/", '<a href="', $paymentData->comment); $tmpkom = preg_replace('/-\)/', '" target="_blank">Barcode runterladen</a>', $tmpkom ); $html .= $tmpkom; } // if payment is in test mode if ($paymentData->transaction_mode != "LIVE") { vmInfo('VMPAYMENT_HEIDELPAY_PAYMENT_TESTMODE'); } $orgSecret = $this->createSecretHash ($order_number, $method->HEIDELPAY_SECRET); $order['comments']=""; if ($virtuemart_order_id) { $order['customer_notified'] = 0; $order['order_status'] = $this->getStatus ($method, $paymentData->processing_result); $modelOrder = VmModel::getModel ('orders'); $orderitems = $modelOrder->getOrder ($virtuemart_order_id); $nb_history = count ($orderitems['history']); if ($orderitems['history'][$nb_history - 1]->order_status_code != $order['order_status']) { if ($method->HEIDELPAY_CONFIRM_EMAIL == 1 or ($method->HEIDELPAY_CONFIRM_EMAIL == 2 and $paymentData->processing_result == "ACK")) { $order['customer_notified'] = 1; $order['comments'] = JText::sprintf ('VMPAYMENT_HEIDELPAY_EMAIL_SENT') . "<br />"; } $order['comments'] .= $paymentData->comment; /* * Verify Payment response */ if ($orgSecret != $paymentData->secret_hash) { $order['customer_notified'] = 0; $order['comments'] = "Hash verification error, suspecting manipulation. IP: " . $paymentData->response_ip; $order['order_status'] = ''; } $modelOrder->updateStatusForOneOrder ($virtuemart_order_id, $order, TRUE); } } return TRUE; }
function check() { if (empty($this->order_number)) { if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $this->order_number = VirtueMartModelOrders::generateOrderNumber((string) time()); } if (empty($this->order_pass)) { $this->order_pass = '******' . substr(md5((string) time() . $this->order_number), 0, 5); } return parent::check(); }
/** * Save updated order data to the method specific table * * @param array $_formData Form data * @return mixed, True on success, false on failures (the rest of the save-process will be * skipped!), or null when this method is not actived. * public function plgVmOnUpdateOrderPayment( $_formData) { return null; } /** * Save updated orderline data to the method specific table * * @param array $_formData Form data * @return mixed, True on success, false on failures (the rest of the save-process will be * skipped!), or null when this method is not actived. * public function plgVmOnUpdateOrderLine( $_formData) { return null; } /** * plgVmOnEditOrderLineBE * This method is fired when editing the order line details in the backend. * It can be used to add line specific package codes * * @param integer $_orderId The order ID * @param integer $_lineId * @return mixed Null for method that aren't active, text (HTML) otherwise * public function plgVmOnEditOrderLineBEPayment( $_orderId, $_lineId) { return null; } /** * This method is fired when showing the order details in the frontend, for every orderline. * It can be used to display line specific package codes, e.g. with a link to external tracking and * tracing systems * * @param integer $_orderId The order ID * @param integer $_lineId * @return mixed Null for method that aren't active, text (HTML) otherwise * public function plgVmOnShowOrderLineFE( $_orderId, $_lineId) { return null; } /** * This event is fired when the method notifies you when an event occurs that affects the order. * Typically, the events represents for payment authorizations, Fraud Management Filter actions and other actions, * such as refunds, disputes, and chargebacks. * * NOTE for Plugin developers: * If the plugin is NOT actually executed (not the selected payment method), this method must return NULL * * @param $return_context: it was given and sent in the payment form. The notification should return it back. * Used to know which cart should be emptied, in case it is still in the session. * @param int $virtuemart_order_id : payment order id * @param char $new_status : new_status for this order id. * @return mixed Null when this method was not selected, otherwise the true or false * * @author Valerie Isaksen * * public function plgVmOnPaymentNotification() { return null; } /** * plgVmOnPaymentResponseReceived * This event is fired when the method returns to the shop after the transaction * * the method itself should send in the URL the parameters needed * NOTE for Plugin developers: * If the plugin is NOT actually executed (not the selected payment method), this method must return NULL * * @param int $virtuemart_order_id : should return the virtuemart_order_id * @param text $html: the html to display * @return mixed Null when this method was not selected, otherwise the true or false * * @author Valerie Isaksen * * function plgVmOnPaymentResponseReceived(, &$virtuemart_order_id, &$html) { return null; } */ function plgVmOnPaymentNotification() { if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $virtuemart_paymentmethod_id = JRequest::getInt('virtuemart_paymentmethod_id', ''); $order_number = JRequest::getString('mer_txn', ''); $status = JRequest::getString('f_code', ''); if (!isset($order_number)) { return; } $method = $this->getVmPluginMethod($virtuemart_paymentmethod_id); if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { return; } $modelOrder = VmModel::getModel('orders'); $vmorder = $modelOrder->getOrder($virtuemart_order_id); $order = array(); $order['customer_notified'] = 1; if (strtolower($status) == "ok") { $order['order_status'] = "C"; $order['comments'] = JText::sprintf('VMPAYMENT_PAYNETZ_PAYMENT_STATUS_CONFIRMED', $virtuemart_order_id); } else { $order['comments'] = JText::sprintf('VMPAYMENT_PAYNETZ_PAYMENT_STATUS_FAILED', $virtuemart_order_id); $order['order_status'] = "X"; $this->_handlePaymentCancel($virtuemart_order_id, $html); return; } $this->logInfo('plgVmOnPaymentNotification return new_status:' . $order['order_status'], 'message'); $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, TRUE); //// remove vmcart $this->emptyCart($payment->user_session, $mb_data['transaction_id']); $html = 'Thank you for order. Your transaction ID is ' . $virtuemart_order_id . "\n"; JRequest::setVar('html', $html); $mainframe = JFactory::getApplication(); $mainframe->enqueueMessage($html); $mainframe->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart&task=confirm', FALSE)); return; }
/** * This is a proxy function to return an order safely, we may set the getOrder function to private * Maybe the right place would be the controller, cause there are JRequests in it. But for a fast solution, * still better than to have it 3-4 times in the view.html.php of the views. * @author Max Milbers * * @return array */ public function getMyOrderDetails($orderID = 0, $orderNumber = false, $orderPass = false){ $_currentUser = JFactory::getUser(); $cuid = $_currentUser->get('id'); $orderDetails = false; // If the user is not logged in, we will check the order number and order pass if(empty($orderID) and empty($cuid)){ // If the user is not logged in, we will check the order number and order pass if ($orderPass = vRequest::getString('order_pass',$orderPass)){ $orderNumber = vRequest::getString('order_number',$orderNumber); $orderId = $this->getOrderIdByOrderPass($orderNumber,$orderPass); if(empty($orderId)){ echo vmText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'); vmdebug('getMyOrderDetails COM_VIRTUEMART_RESTRICTED_ACCESS',$orderPass,$orderNumber); return false; } $orderDetails = $this->getOrder($orderId); } } else { // If the user is logged in, we will check if the order belongs to him $virtuemart_order_id = vRequest::getInt('virtuemart_order_id',$orderID) ; if (!$virtuemart_order_id) { $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber(vRequest::getString('order_number')); } $orderDetails = $this->getOrder($virtuemart_order_id); $user = JFactory::getUser(); if(!$user->authorise('core.admin','com_virtuemart')){ if(!isset($orderDetails['details']['BT']->virtuemart_user_id)){ $orderDetails['details']['BT']->virtuemart_user_id = 0; } //if(!empty($orderDetails['details']['BT']->virtuemart_user_id)){ vmdebug('getMyOrderDetails',$cuid,$orderDetails['details']['BT']->virtuemart_user_id); if ($orderDetails['details']['BT']->virtuemart_user_id != $cuid) { echo vmText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'); return false; } //} } } return $orderDetails; }
function onShowOrderBE_activate($payment) { if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $html = $this->getHtmlRowBE(vmText::_('VMPAYMENT_KLARNACHECKOUT_STATUS'), $payment->klarna_status); $activate_data = $this->getStoredData($payment); $html .= $this->getHtmlRowBE(vmText::_('VMPAYMENT_KLARNACHECKOUT_INVOICE_NUMBER'), $activate_data->InvoiceNumber); if (!empty($activate_data->InvoicePdf)) { $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($payment->order_number); $invoicePdfLink = $this->getInvoicePdfLink($virtuemart_order_id); $value = '<a target="_blank" href="' . $invoicePdfLink . '">' . vmText::_('VMPAYMENT_KLARNACHECKOUT_VIEW_INVOICE') . '</a>'; $html .= $this->getHtmlRowBE("", $value); } return $html; }
/** * @param $html * @return bool|null|string */ function plgVmOnPaymentResponseReceived(&$html) { $jinput = JFactory::getApplication()->input; if (empty($jinput->get('vmethod')) || !$jinput->get('vmethod') == "pagantis") { return NULL; } if (!class_exists('VirtueMartCart')) { require JPATH_VM_SITE . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'cart.php'; } if (!class_exists('shopFunctionsF')) { require JPATH_VM_SITE . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'shopfunctionsf.php'; } if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'models' . DIRECTORY_SEPARATOR . 'orders.php'; } // Recuperamos Identificador de pedido $virtuemart_paymentmethod_id = $jinput->get('pm', 0); if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) { return NULL; } $json = file_get_contents('php://input'); $data = json_decode($json, true); if (!empty($data["event"])) { //CallBack URL $this->log("Entramos en el CallBack"); //Account Settings $environment = $method->pagamastarde_env; if ($environment == 'test') { $key = $method->pagamastarde_test_key; } else { $key = $method->pagamastarde_real_key; } if ($data["event"] == 'charge.created' && !empty($data["data"]["order_id"])) { $signature_check = sha1($key . $data['account_id'] . $data['api_version'] . $data['event'] . $data['data']['id']); $signature_check_512 = hash('sha512', $key . $data['account_id'] . $data['api_version'] . $data['event'] . $data['data']['id']); if ($signature_check != $data['signature'] && $signature_check_512 != $data['signature']) { //hack detected $this->log("Hack detected"); exit; } $virtuemart_order_id = $data["data"]["order_id"]; $orderModel = VmModel::getModel('orders'); $order_number = $orderModel->getOrderIdByOrderNumber($virtuemart_order_id); $order = $orderModel->getOrder($order_number); $order['order_status'] = "C"; $order['customer_notified'] = 1; $updated = $orderModel->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, TRUE); $msg = $updated ? "Actualizado pedido " . $order['details']['BT']->virtuemart_order_id . " a estado C" : "No se ha actualizado el pedido " . $order['details']['BT']->virtuemart_order_id . " a estado C"; $this->log($msg); //Se eliminan productos del carrito $cart = VirtueMartCart::getCart(); $cart->emptyCart(); } else { if ($data["event"] == 'charge.failed' && !empty($data["data"]["order_id"])) { $virtuemart_order_id = $data["data"]["order_id"]; $orderModel = VmModel::getModel('orders'); //Don't lose cart $order_number = $orderModel->getOrderIdByOrderNumber($virtuemart_order_id); $order = $orderModel->getOrder($order_number); $order['order_status'] = "X"; $order['customer_notified'] = 1; $cart = VirtueMartCart::getCart(); $cart->emptyCart(); $orderModel->updateStatusForOneOrder($order['details']['BT']->virtuemart_order_id, $order, TRUE); } } } else { //URL OK Y KO $status = $jinput->get("status"); $order_number = $jinput->get("on"); if (!$this->selectedThisElement($method->payment_element)) { return NULL; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { return NULL; } if ($status == "ok") { $this->log("PAGA+TARDE Pedido Number: " . $order_number . ", Pedido Id: " . $virtuemart_order_id . ' Finalizado correctamente, mostrando pantalla de éxito'); $html = '<img src="' . JURI::root() . 'plugins/vmpayment/pagamastarde/pagamastarde/assets/images/pagamastarde.png" width="225"><br><br><br>'; $html .= '<h3>El pedido con referencia ' . $order_number . ' ha finalizado correctamente. Gracias por utilizar Paga+Tarde.</h3>'; //Flush cart $cart = VirtueMartCart::getCart(); $cart->emptyCart(); } else { $this->log("PAGA+TARDE Pedido Number: " . $order_number . ", Pedido Id: " . $virtuemart_order_id . ' Finalizado con error, mostrando pantalla de error '); $html = '<img src="' . JURI::root() . 'plugins/vmpayment/pagamastarde/pagamastarde/assets/images/pagamastarde.png" width="225"><br><br><br>'; $html .= '<h3>El pedido con referencia ' . $order_number . ' ha finalizado con error en la respuesta. Gracias por utilizar Paga+Tarde.</h3>'; $html .= '<h3>Su carrito no se ha borrado, puede reintentar su compra.</h3>'; } } return TRUE; }
/** * plgVmOnPaymentNotification() -It can be used to validate the payment data as entered by the user. * Return: * Parameters: * None * @author Valerie Isaksen */ function plgVmOnPaymentNotification() { if (!class_exists('VirtueMartModelOrders')) { require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php'; } $po = vRequest::getString('po', ''); if (!$po) { return; } $retourParams = $this->getRetourParams($po); $virtuemart_paymentmethod_id = $retourParams['virtuemart_paymentmethod_id']; $order_number = $retourParams['order_number']; $context = $retourParams['context']; $this->_currentMethod = $this->getVmPluginMethod($virtuemart_paymentmethod_id); if (!$this->selectedThisElement($this->_currentMethod->payment_element)) { //$this->debugLog('Not this one', 'selectedThisElement', 'debug', false); return; } $this->debugLog(var_export($retourParams, true), 'plgVmOnPaymentNotification getRetourParams', 'debug', false); $interface = $this->_loadKlikandpayInterface($this); if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { return FALSE; } if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { $this->debugLog('no payments found', 'getDatasByOrderId', 'debug', false); return FALSE; } if ($payments[0]->klikandpay_custom != $context) { $this->debugLog('Wrong context', 'plgVmOnPaymentNotification', 'debug', false); return NULL; } $orderModel = VmModel::getModel('orders'); $order = $orderModel->getOrder($virtuemart_order_id); $klikandpay_data = vRequest::getGet(); $this->debugLog(var_export($klikandpay_data, true), 'plgVmOnPaymentNotification getGet', 'debug', false); $order_history = $this->updateOrderStatus($interface, $klikandpay_data, $order, $payments); $this->emptyCart($payments[0]->klikandpay_custom, $order['details']['BT']->order_number); $this->setEmptyCartDone($payments[0]); return TRUE; }
/** * This is a proxy function to return an order safely, we may set the getOrder function to private * Maybe the right place would be the controller, cause there are JRequests in it. But for a fast solution, * still better than to have it 3-4 times in the view.html.php of the views. * @author Max Milbers * * @return array */ public function getMyOrderDetails($orderID = 0, $orderNumber = false, $orderPass = false) { $_currentUser = JFactory::getUser(); $cuid = $_currentUser->get('id'); $orderDetails = false; // If the user is not logged in, we will check the order number and order pass if (empty($orderID) and empty($cuid)) { // If the user is not logged in, we will check the order number and order pass if ($orderPass = JRequest::getString('order_pass', $orderPass)) { $orderNumber = JRequest::getString('order_number', $orderNumber); $orderId = $this->getOrderIdByOrderPass($orderNumber, $orderPass); if (empty($orderId)) { echo JText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'); return false; } $orderDetails = $this->getOrder($orderId); } } else { // If the user is logged in, we will check if the order belongs to him $virtuemart_order_id = JRequest::getInt('virtuemart_order_id', $orderID); if (!$virtuemart_order_id) { $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber(JRequest::getString('order_number')); } $orderDetails = $this->getOrder($virtuemart_order_id); if (!class_exists('Permissions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php'; } if (!Permissions::getInstance()->check("admin,storeadmin")) { if (!isset($orderDetails['details']['BT']->virtuemart_user_id)) { $orderDetails['details']['BT']->virtuemart_user_id = 0; } //if(!empty($orderDetails['details']['BT']->virtuemart_user_id)){ vmdebug('getMyOrderDetails', $cuid, $orderDetails['details']['BT']->virtuemart_user_id); if ($orderDetails['details']['BT']->virtuemart_user_id != $cuid) { echo JText::_('COM_VIRTUEMART_RESTRICTED_ACCESS'); return false; } //} } } return $orderDetails; }
/** * @return bool','null */ function plgVmOnPaymentNotification() { /* $this->_debug = true; $this->logInfo('plgVmOnPaymentNotification '.var_export($_POST, true) , 'message') ; $this->logInfo('plgVmOnPaymentNotification '.var_export($_REQUEST, true) , 'message'); // $paymentmethod_id = vRequest::getString('reason_2'); */ $order_number = vRequest::getString('reason_1'); // is order number if (!class_exists('VirtueMartModelOrders')) { require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php'; } if (empty($order_number)) { return FALSE; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { return FALSE; } if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { return FALSE; } $method = $this->getVmPluginMethod($payments[0]->virtuemart_paymentmethod_id); if (!$this->selectedThisElement($method->payment_element)) { return false; } $hash_keys = array('transaction', 'user_id', 'project_id', 'sender_holder', 'sender_account_number', 'sender_bank_name', 'sender_bank_bic', 'sender_iban', 'sender_country_id', 'recipient_holder', 'recipient_account_number', 'recipient_bank_code', 'recipient_bank_name', 'recipient_bank_bic', 'recipient_iban', 'recipient_country_id', 'amount', 'currency_id', 'reason_1', 'reason_2', 'user_variable_0', 'user_variable_1', 'user_variable_2', 'user_variable_3', 'user_variable_4', 'user_variable_5', 'created', 'status', 'status_modified', 'notification_password'); foreach ($hash_keys as $key) { $hash_data[$key] = vRequest::getString($key, ''); } $hash_data['notification_password'] = $method->notification_password; if (!$this->checkHash($hash_data)) { return false; } if (!class_exists('VirtueMartModelOrders')) { require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php'; } $db = JFactory::getDBO(); $query = 'SHOW COLUMNS FROM `' . $this->_tablename . '` '; $db->setQuery($query); $columns = $db->loadColumn(0); $prefix = 'sofort_ideal_response_'; $prefix_hidden = 'sofort_ideal_hidden_response_'; $prefix_len = strlen($prefix); $prefix_hidden_len = strlen($prefix_hidden); foreach ($columns as $key) { if (substr($key, 0, $prefix_len) == $prefix) { $postKey = substr($key, $prefix_len); $dbvalues[$key] = vRequest::getString($postKey, ''); } elseif (substr($key, 0, $prefix_hidden_len) == $prefix_hidden) { $postKey = substr($key, $prefix_hidden_len); $dbvalues[$key] = vRequest::getString($postKey, ''); } } $dbvalues['hidden_hash'] = vRequest::getString('hash', ''); $dbvalues['virtuemart_paymentmethod_id'] = $payments[0]->virtuemart_paymentmethod_id; $dbvalues['virtuemart_order_id'] = $virtuemart_order_id; $dbvalues['order_number'] = $order_number; $modelOrder = VmModel::getModel('orders'); $order = array(); $this->logInfo('before getNewOrderStatus ' . var_export($dbvalues, true), 'message'); $status = $this->getNewOrderStatus($dbvalues); $order['order_status'] = $method->{$status}; $order['comments'] = vmText::_('VMPAYMENT_SOFORT_IDEAL_RESPONSE_' . $status); $order['customer_notified'] = 1; //$this->logInfo('before storePSPluginInternalData ' , 'message'); $this->storePSPluginInternalData($dbvalues); $this->logInfo('after storePSPluginInternalData ' . var_export($dbvalues, true), 'message'); $this->logInfo('plgVmOnPaymentNotification return new_status:' . $order['order_status'], 'message'); $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, false); //// remove vmcart if (isset($payments[0]->sofort_custom)) { $this->emptyCart($payments[0]->sofort_custom, $order_number); } }
/** * Proceeds the simple payment * * @param string $resp * @param array $submitted_values * @return object Message object * */ function _handleResponse($response, $submitted_values, $order, $payment_name) { $delimiter = $this->_authorizenet_params['delim_char']; $encap_char = $this->_authorizenet_params['encap_char']; if ($response) { // Split Array if ($encap_char) { //$response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); $response_array = explode($encap_char, $response); } else { $response_array = explode($delimiter, $response); } /** * If AuthorizeNet doesn't return a delimited response. */ if (count($response_array) < 10) { $this->approved = FALSE; $this->error = TRUE; $error_message = JText::_('VMPAYMENT_AUTHORIZENET_UNKNOWN') . $response; // send email to vendor $this->sendEmailToVendorAndAdmins(JText::_('VMPAYMENT_AUTHORIZENET_ERROR_EMAIL_SUBJECT'), $error_message); return $error_message; } $authorizeNetResponse['response_code'] = $response_array[0]; $this->approved = $authorizeNetResponse['response_code'] == self::APPROVED; $this->declined = $authorizeNetResponse['response_code'] == self::DECLINED; $this->error = $authorizeNetResponse['response_code'] == self::ERROR; $this->held = $authorizeNetResponse['response_code'] == self::HELD; $authorizeNetResponse['response_subcode'] = $response_array[1]; $authorizeNetResponse['response_reason_code'] = $response_array[2]; $authorizeNetResponse['response_reason_text'] = $response_array[3]; $authorizeNetResponse['authorization_code'] = $response_array[4]; $authorizeNetResponse['avs_response'] = $response_array[5]; //Address Verification Service $authorizeNetResponse['transaction_id'] = $response_array[6]; $authorizeNetResponse['invoice_number'] = $response_array[7]; $authorizeNetResponse['description'] = $response_array[8]; if ($this->approved) { $authorizeNetResponse['amount'] = $response_array[9]; $authorizeNetResponse['method'] = $response_array[10]; $authorizeNetResponse['transaction_type'] = $response_array[11]; $authorizeNetResponse['customer_id'] = $response_array[12]; $authorizeNetResponse['first_name'] = $response_array[13]; $authorizeNetResponse['last_name'] = $response_array[14]; $authorizeNetResponse['company'] = $response_array[15]; $authorizeNetResponse['address'] = $response_array[16]; $authorizeNetResponse['city'] = $response_array[17]; $authorizeNetResponse['state'] = $response_array[18]; $authorizeNetResponse['zip_code'] = $response_array[19]; $authorizeNetResponse['country'] = $response_array[20]; $authorizeNetResponse['phone'] = $response_array[21]; $authorizeNetResponse['fax'] = $response_array[22]; $authorizeNetResponse['email_address'] = $response_array[23]; $authorizeNetResponse['ship_to_first_name'] = $response_array[24]; $authorizeNetResponse['ship_to_last_name'] = $response_array[25]; $authorizeNetResponse['ship_to_company'] = $response_array[26]; $authorizeNetResponse['ship_to_address'] = $response_array[27]; $authorizeNetResponse['ship_to_city'] = $response_array[28]; $authorizeNetResponse['ship_to_state'] = $response_array[29]; $authorizeNetResponse['ship_to_zip_code'] = $response_array[30]; $authorizeNetResponse['ship_to_country'] = $response_array[31]; $authorizeNetResponse['tax'] = $response_array[32]; $authorizeNetResponse['duty'] = $response_array[33]; $authorizeNetResponse['freight'] = $response_array[34]; $authorizeNetResponse['tax_exempt'] = $response_array[35]; $authorizeNetResponse['purchase_order_number'] = $response_array[36]; $authorizeNetResponse['md5_hash'] = $response_array[37]; $authorizeNetResponse['card_code_response'] = $response_array[38]; $authorizeNetResponse['cavv_response'] = $response_array[39]; //// cardholder_authentication_verification_response $authorizeNetResponse['account_number'] = $response_array[50]; $authorizeNetResponse['card_type'] = $response_array[51]; $authorizeNetResponse['split_tender_id'] = $response_array[52]; $authorizeNetResponse['requested_amount'] = $response_array[53]; $authorizeNetResponse['balance_on_card'] = $response_array[54]; } /* * check the amount is the same as the amount sent */ /* SUBCODE?? */ $this->approved = $authorizeNetResponse['response_code'] == self::APPROVED; $this->declined = $authorizeNetResponse['response_code'] == self::DECLINED; $this->error = $authorizeNetResponse['response_code'] == self::ERROR; $this->held = $authorizeNetResponse['response_code'] == self::HELD; // Set custom fields: not used yet: could put the return context /* if ($count = count($custom_fields)) { $custom_fields_response = array_slice($response_array, -$count, $count); $i = 0; foreach ($custom_fields as $key => $value) { $this->$key = $custom_fields_response[$i]; $i++; } } */ $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($authorizeNetResponse['invoice_number']); if (!$virtuemart_order_id) { $this->approved = FALSE; $this->error = TRUE; $this->logInfo(JText::sprintf('VMPAYMENT_AUTHORIZENET_NO_ORDER_NUMBER', $authorizeNetResponse['invoice_number']), 'ERROR'); //$this->sendEmailToVendorAndAdmins(JText::sprintf('VMPAYMENT_AUTHORIZENET_NO_ORDER_NUMBER', $authorizeNetResponse['invoice_number']), JText::sprintf('VMPAYMENT_AUTHORIZENET_ERROR_WHILE_PROCESSING_PAYMENT', $authorizeNetResponse['invoice_number'])); $html = Jtext::sprintf('VMPAYMENT_AUTHORIZENET_ERROR', $authorizeNetResponse['response_reason_text'], $authorizeNetResponse['response_code']) . "<br />"; $this->logInfo($html, 'PAYMENT DECLINED'); return $html; } if ($this->error or $this->declined) { // Prepare data that should be stored in the database $dbValues['authorizenet_response_response_code'] = $authorizeNetResponse['response_code']; $dbValues['authorizenet_response_response_subcode'] = $authorizeNetResponse['response_subcode']; $dbValues['authorizenet_response_response_reason_code'] = $authorizeNetResponse['response_reason_code']; $dbValues['authorizenet_response_response_reason_text'] = $authorizeNetResponse['response_reason_text']; //$this->storePSPluginInternalData($dbValues, 'id', true); $html = Jtext::sprintf('VMPAYMENT_AUTHORIZENET_ERROR', $authorizeNetResponse['response_reason_text'], $authorizeNetResponse['response_code']) . "<br />"; $this->logInfo($html, 'PAYMENT DECLINED'); return $html; } } else { $this->approved = FALSE; $this->error = TRUE; $this->logInfo(JText::_('VMPAYMENT_AUTHORIZENET_CONNECTING_ERROR'), 'ERROR'); $this->sendEmailToVendorAndAdmins(JText::_('VMPAYMENT_AUTHORIZENET_ERROR_EMAIL_SUBJECT'), JText::_('VMPAYMENT_AUTHORIZENET_CONNECTING_ERROR')); return JText::_('VMPAYMENT_AUTHORIZENET_CONNECTING_ERROR'); } // Prep // get all know columns of the table $db = JFactory::getDBO(); $query = 'SHOW COLUMNS FROM `' . $this->_tablename . '` '; $db->setQuery($query); $columns = $db->loadResultArray(0); foreach ($authorizeNetResponse as $key => $value) { $table_key = 'authorizenet_response_' . $key; if (in_array($table_key, $columns)) { $response_fields[$table_key] = $value; } } $response_fields['virtuemart_order_id'] = $virtuemart_order_id; $response_fields['invoice_number'] = $authorizeNetResponse['invoice_number']; $response_fields['authorizeresponse_raw'] = $response; $this->storePSPluginInternalData($response_fields, 'virtuemart_order_id', TRUE); $currencyModel = VmModel::getModel('Currency'); $currency = $currencyModel->getCurrency($order['details']['BT']->user_currency_id); $html = '<table class="adminlist">' . "\n"; $html .= $this->getHtmlRow('AUTHORIZENET_PAYMENT_NAME', $payment_name); $html .= $this->getHtmlRow('AUTHORIZENET_ORDER_NUMBER', $authorizeNetResponse['invoice_number']); $html .= $this->getHtmlRow('AUTHORIZENET_AMOUNT', $authorizeNetResponse['amount'] . ' ' . $currency->currency_name); //$html .= $this->getHtmlRow('AUTHORIZENET_RESPONSE_AUTHORIZATION_CODE', $authorizeNetResponse['authorization_code']); $html .= $this->getHtmlRow('AUTHORIZENET_RESPONSE_TRANSACTION_ID', $authorizeNetResponse['transaction_id']); $html .= '</table>' . "\n"; $this->logInfo(JText::_('VMPAYMENT_AUTHORIZENET_ORDER_NUMBER') . " " . $authorizeNetResponse['invoice_number'] . ' payment approved', 'message'); return $html; }
function portOrders() { if (microtime(true) - $this->starttime >= $this->maxScriptTime) { return; } if (!class_exists('VirtueMartModelOrderstatus')) { require VMPATH_ADMIN . DS . 'models' . DS . 'orderstatus.php'; } if (!class_exists('ShopFunctions')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'shopfunctions.php'; } $this->_db->setQuery('select `order_status_code` FROM `#__virtuemart_orderstates` '); $vm2Fields = $this->_db->loadColumn(); $this->_db->setQuery('select * FROM `#__vm_order_status`'); $oldfields = $this->_db->loadObjectList(); $migratedfields = ''; foreach ($oldfields as $field) { if (!in_array($field->order_status_code, $vm2Fields)) { $q = 'INSERT INTO `#__virtuemart_orderstates` ( `virtuemart_vendor_id`, `order_status_code`, `order_status_name`, `order_status_description`, `order_stock_handle`, `ordering`, `published`) VALUES ( "' . $field->vendor_id . '","' . $field->order_status_code . '","' . $field->order_status_name . '","' . $field->order_status_description . '","A","' . $field->list_order . '", 1 )'; $this->_db->setQuery($q); $this->_db->execute(); if ($this->_db->getErrorNum()) { vmError($this->_db->getErrorMsg()); } $migratedfields .= '[' . $field->order_status_code . '-' . $field->order_status_name . '] '; } } if ($migratedfields) { vminfo('order states declaration ' . $migratedfields . ' Migrated'); } $oldtonewOrders = array(); //Looks like there is a problem, when the data gets tooo big, //solved now with query directly ignoring already ported orders. $alreadyKnownIds = $this->getMigrationProgress('orders'); $newproductIds = $this->getMigrationProgress('products'); $orderCodeToId = $this->createOrderStatusAssoc(); //approximatly 100 products take a 1 MB $maxItems = $this->_getMaxItems('Orders'); $startLimit = $this->_getStartLimit('orders_start'); vmdebug('portOrders $startLimit ' . $startLimit); $i = 0; if (count($alreadyKnownIds) == $startLimit + $maxItems) { $continue = false; } else { $continue = true; } $reWriteOrderNumber = vRequest::getInt('reWriteOrderNumber', 0); $userOrderId = vRequest::getInt('userOrderId', 0); if (!class_exists('VirtueMartModelOrders')) { VmModel::getModel('orders'); } while ($continue) { $q = 'SELECT `o`.*, `op`.*, `o`.`order_number` as `vm1_order_number`, `o2`.`order_number` as `nr2`,`o`.order_id FROM `#__vm_orders` as `o` LEFT OUTER JOIN `#__vm_order_payment` as `op` ON `op`.`order_id` = `o`.`order_id` LEFT JOIN `#__virtuemart_orders` as `o2` ON `o2`.`order_number` = `o`.`order_number` WHERE (o2.order_number) IS NULL ORDER BY o.order_id LIMIT ' . $startLimit . ',' . $maxItems; $doneStart = $startLimit; $res = self::loadCountListContinue($q, $startLimit, $maxItems, 'port Orders'); $oldOrders = $res[0]; $startLimit = $res[1]; $continue = $res[2]; foreach ($oldOrders as $order) { if (!array_key_exists($order['order_id'], $alreadyKnownIds)) { $orderData = new stdClass(); $orderData->virtuemart_order_id = null; $orderData->virtuemart_user_id = $order['user_id']; $orderData->virtuemart_vendor_id = $order['vendor_id']; if ($reWriteOrderNumber == 0) { if ($userOrderId == 1) { $orderData->order_number = $order['order_id']; } else { $orderData->order_number = $order['vm1_order_number']; } } $orderData->order_pass = VirtueMartModelOrders::genStdOrderPass(); //Note as long we do not have an extra table only storing addresses, the virtuemart_userinfo_id is not needed. //The virtuemart_userinfo_id is just the id of a stored address and is only necessary in the user maintance view or for choosing addresses. //the saved order should be an snapshot with plain data written in it. // $orderData->virtuemart_userinfo_id = 'TODO'; // $_cart['BT']['virtuemart_userinfo_id']; // TODO; Add it in the cart... but where is this used? Obsolete? $orderData->order_total = $order['order_total']; $orderData->order_subtotal = $order['order_subtotal']; $orderData->order_tax = empty($order['order_tax']) ? 0 : $order['order_tax']; $orderData->order_shipment = empty($order['order_shipping']) ? 0 : $order['order_shipping']; $orderData->order_shipment_tax = empty($order['order_shipping_tax']) ? 0 : $order['order_shipping_tax']; if (!empty($order['coupon_code'])) { $orderData->coupon_code = $order['coupon_code']; $orderData->coupon_discount = $order['coupon_discount']; } $orderData->order_discount = $order['order_discount']; $orderData->order_status = $order['order_status']; if (isset($order['order_currency'])) { $orderData->user_currency_id = $this->getCurrencyIdByCode($order['order_currency']); //$orderData->user_currency_rate = $order['order_status']; } $orderData->virtuemart_paymentmethod_id = $order['payment_method_id']; $orderData->virtuemart_shipmentmethod_id = $order['ship_method_id']; //$orderData->order_status_id = $oldToNewOrderstates[$order['order_status']] $_filter = JFilterInput::getInstance(array('br', 'i', 'em', 'b', 'strong'), array(), 0, 0, 1); $orderData->customer_note = $_filter->clean($order['customer_note']); $orderData->ip_address = $order['ip_address']; $orderData->created_on = $this->_changeToStamp($order['cdate']); $orderData->modified_on = $this->_changeToStamp($order['mdate']); //we could remove this to set modified_on today $orderTable = $this->getTable('orders'); $continue = $orderTable->bindChecknStore($orderData); if (empty($continue)) { break; } $i++; $newId = $alreadyKnownIds[$order['order_id']] = $orderTable->virtuemart_order_id; $q = 'SELECT * FROM `#__vm_order_item` WHERE `order_id` = "' . $order['order_id'] . '" '; $this->_db->setQuery($q); $oldItems = $this->_db->loadAssocList(); //$this->_app->enqueueMessage('Migration orderhistories: ' . $newId); foreach ($oldItems as $item) { $item['virtuemart_order_id'] = $newId; if (!empty($newproductIds[$item['product_id']])) { $item['virtuemart_product_id'] = $newproductIds[$item['product_id']]; } else { vmWarn('Attention, order is pointing to deleted product (not found in the array of old products)'); } //$item['order_status'] = $orderCodeToId[$item['order_status']]; $item['created_on'] = $this->_changeToStamp($item['cdate']); $item['modified_on'] = $this->_changeToStamp($item['mdate']); //we could remove this to set modified_on today $item['product_attribute'] = $this->_attributesToJson($item['product_attribute']); //we could remove this to set modified_on today $item['product_discountedPriceWithoutTax'] = $item['product_final_price'] - $item['product_tax']; $item['product_subtotal_with_tax'] = $item['product_final_price'] * $item['product_quantity']; $orderItemsTable = $this->getTable('order_items'); $continue = $orderItemsTable->bindChecknStore($item); if (empty($continue)) { $continue = false; break; } } $q = 'SELECT * FROM `#__vm_order_history` WHERE `order_id` = "' . $order['order_id'] . '" '; $this->_db->setQuery($q); $oldItems = $this->_db->loadAssocList(); foreach ($oldItems as $item) { $item['virtuemart_order_id'] = $newId; //$item['order_status_code'] = $orderCodeToId[$item['order_status_code']]; $orderHistoriesTable = $this->getTable('order_histories'); $orderHistoriesTable->bindChecknStore($item); } $q = 'SELECT * FROM `#__vm_order_user_info` WHERE `order_id` = "' . $order['order_id'] . '" '; $this->_db->setQuery($q); $oldItems = $this->_db->loadAssocList(); if ($oldItems) { foreach ($oldItems as $item) { $item['virtuemart_order_id'] = $newId; $item['virtuemart_user_id'] = $item['user_id']; $item['virtuemart_country_id'] = $this->getCountryIDByName($item['country']); $item['virtuemart_state_id'] = $this->getStateIDByName($item['state']); $item['email'] = $item['user_email']; $orderUserinfoTable = $this->getTable('order_userinfos'); $orderUserinfoTable->bindChecknStore($item); } } //$this->_app->enqueueMessage('Migration: '.$i.' order processed new id '.$newId); } // $this->storeMigrationProgress('orders',$alreadyKnownIds); // else { // $oldtonewOrders[$order['order_id']] = $alreadyKnownIds[$order['order_id']]; // } if (microtime(true) - $this->starttime >= $this->maxScriptTime) { $continue = false; break; } } } $limitStartToStore = ', orders_start = "' . ($doneStart + $i) . '" '; $this->storeMigrationProgress('orders', $alreadyKnownIds, $limitStartToStore); vmInfo('Migration: ' . $i . ' orders processed ' . ($doneStart + $i) . ' done.'); return true; }
function plgVmOnUserPaymentCancel() { if (!class_exists('VirtueMartModelOrders')) { require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php'; } $virtuemart_paymentmethod_id = JRequest::getInt('pm', 0); $order_number = JRequest::getString('on', 0); if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($method->payment_element)) { return NULL; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { return NULL; } $db = JFactory::getDBO(); $_q = 'SELECT * FROM `' . $this->_tablename . '` ' . 'WHERE `virtuemart_order_id` = ' . $virtuemart_order_id; $db->setQuery($_q); if (!($paymentData = $db->loadObject())) { // JError::raiseWarning(500, $db->getErrorMsg()); } vmdebug('HEIDELPAY paymentdata', $paymentData); if ($paymentData->processing_result == "NOK") { vmError('VMPAYMENT_HEIDELPAY_PAYMENT_FAILED', 'VMPAYMENT_HEIDELPAY_PAYMENT_FAILED'); vmError(" - " . $paymentData->comment, " - " . $paymentData->comment); $order['comments'] = ""; if ($virtuemart_order_id) { $order['customer_notified'] = 0; $order['order_status'] = $this->getStatus($method, $paymentData->processing_result); $modelOrder = VmModel::getModel('orders'); $orderitems = $modelOrder->getOrder($virtuemart_order_id); $nb_history = count($orderitems['history']); if ($orderitems['history'][$nb_history - 1]->order_status_code != $order['order_status']) { if ($method->HEIDELPAY_CONFIRM_EMAIL == 1 or $method->HEIDELPAY_CONFIRM_EMAIL == 2 and $paymentData->processing_result == "ACK") { $order['customer_notified'] = 1; $order['comments'] = vmText::sprintf('VMPAYMENT_HEIDELPAY_EMAIL_SENT') . "<br />"; } $order['comments'] .= $paymentData->comment; $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, TRUE); } } } $order_number = JRequest::getVar('on'); if (!$order_number) { return FALSE; } $virtuemart_paymentmethod_id = vRequest::getInt('pm', ''); if (empty($order_number) or empty($virtuemart_paymentmethod_id) or !$this->selectedThisByMethodId($virtuemart_paymentmethod_id)) { return NULL; } $db = JFactory::getDBO(); $query = 'SELECT ' . $this->_tablename . '.`virtuemart_order_id` FROM ' . $this->_tablename . " WHERE `order_number`= '" . $order_number . "'"; $db->setQuery($query); $virtuemart_order_id = $db->loadResult(); if (!$virtuemart_order_id) { return NULL; } return TRUE; }
function plgVmOnPaymentResponseReceived(&$html) { // the payment itself should send the parameter needed. $virtuemart_paymentmethod_id = JRequest::getInt('pm', 0); $vendorId = 0; if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) { return null; // Another method was selected, do nothing } if (!$this->selectedThisElement($method->payment_element)) { return false; } if (!class_exists('VirtueMartCart')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'; } $payment_data = JRequest::get('post'); $payment_name = $this->renderPluginName($method); $html = $this->_getPaymentResponseHtml($payment_data, $payment_name); if (!empty($payment_data)) { vmdebug('plgVmOnPaymentResponseReceived', $payment_data); $order_number = $payment_data['invoice']; $return_context = $payment_data['custom']; if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number); $payment_name = $this->renderPluginName($method); $html = $this->_getPaymentResponseHtml($payment_data, $payment_name); if ($virtuemart_order_id) { // send the email ONLY if payment has been accepted if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $modelOrder = new VirtueMartModelOrders(); $orderitems = $modelOrder->getOrder($virtuemart_order_id); $nb_history = count($orderitems['history']); //vmdebug('history', $orderitems); if (!class_exists('shopFunctionsF')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php'; } if ($nb_history == 1) { if (!class_exists('shopFunctionsF')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php'; } shopFunctionsF::sentOrderConfirmedEmail($orderitems); $this->logInfo('plgVmOnPaymentResponseReceived, sentOrderConfirmedEmail ' . $order_number, 'message'); $order['order_status'] = $orderitems['items'][$nb_history - 1]->order_status; $order['virtuemart_order_id'] = $virtuemart_order_id; $order['customer_notified'] = 0; $order['comments'] = JText::sprintf('VMPAYMENT_PAYPAL_EMAIL_SENT'); $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, true); } } } //We delete the old stuff // get the correct cart / session $cart = VirtueMartCart::getCart(); $cart->emptyCart(); return true; }
/** * Proceeds the simple payment * http://developer.authorize.net/guides/AIM/wwhelp/wwhimpl/js/html/wwhelp.htm#href=4_TransResponse.6.4.html * @param string $resp * @param array $submitted_values * @return object Message object * */ function _handleResponse($response, $submitted_values, $order, $payment_name) { $delimiter = $this->_authorizenet_params['delim_char']; $encap_char = $this->_authorizenet_params['encap_char']; if ($response) { // Split Array if ($encap_char) { //$response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); $response_array = explode($encap_char, $response); } else { $response_array = explode($delimiter, $response); } /** * If AuthorizeNet doesn't return a delimited response. */ if (count($response_array) < 10) { $this->approved = FALSE; $this->error = TRUE; $error_message = vmText::_('VMPAYMENT_AUTHORIZENET_UNKNOWN') . $response; $this->debugLog($error_message, 'getOrderIdByOrderNumber', 'error'); return $error_message; } $authorizeNetResponse['response_code'] = $response_array[0]; $this->approved = $authorizeNetResponse['response_code'] == self::APPROVED; $this->declined = $authorizeNetResponse['response_code'] == self::DECLINED; $this->error = $authorizeNetResponse['response_code'] == self::ERROR; $this->held = $authorizeNetResponse['response_code'] == self::HELD; $authorizeNetResponse['response_subcode'] = $response_array[1]; $authorizeNetResponse['response_reason_code'] = $response_array[2]; $authorizeNetResponse['response_reason_text'] = $response_array[3]; $authorizeNetResponse['authorization_code'] = $response_array[4]; $authorizeNetResponse['avs_response'] = $response_array[5]; //Address Verification Service $authorizeNetResponse['transaction_id'] = $response_array[6]; $authorizeNetResponse['invoice_number'] = $response_array[7]; $authorizeNetResponse['description'] = $response_array[8]; if ($this->approved) { $authorizeNetResponse['amount'] = $response_array[9]; $authorizeNetResponse['method'] = $response_array[10]; $authorizeNetResponse['transaction_type'] = $response_array[11]; $authorizeNetResponse['customer_id'] = $response_array[12]; $authorizeNetResponse['first_name'] = $response_array[13]; $authorizeNetResponse['last_name'] = $response_array[14]; $authorizeNetResponse['company'] = $response_array[15]; $authorizeNetResponse['address'] = $response_array[16]; $authorizeNetResponse['city'] = $response_array[17]; $authorizeNetResponse['state'] = $response_array[18]; $authorizeNetResponse['zip_code'] = $response_array[19]; $authorizeNetResponse['country'] = $response_array[20]; $authorizeNetResponse['phone'] = $response_array[21]; $authorizeNetResponse['fax'] = $response_array[22]; $authorizeNetResponse['email_address'] = $response_array[23]; $authorizeNetResponse['ship_to_first_name'] = $response_array[24]; $authorizeNetResponse['ship_to_last_name'] = $response_array[25]; $authorizeNetResponse['ship_to_company'] = $response_array[26]; $authorizeNetResponse['ship_to_address'] = $response_array[27]; $authorizeNetResponse['ship_to_city'] = $response_array[28]; $authorizeNetResponse['ship_to_state'] = $response_array[29]; $authorizeNetResponse['ship_to_zip_code'] = $response_array[30]; $authorizeNetResponse['ship_to_country'] = $response_array[31]; $authorizeNetResponse['tax'] = $response_array[32]; $authorizeNetResponse['duty'] = $response_array[33]; $authorizeNetResponse['freight'] = $response_array[34]; $authorizeNetResponse['tax_exempt'] = $response_array[35]; $authorizeNetResponse['purchase_order_number'] = $response_array[36]; $authorizeNetResponse['md5_hash'] = $response_array[37]; $authorizeNetResponse['card_code_response'] = $response_array[38]; $authorizeNetResponse['cavv_response'] = $response_array[39]; //// cardholder_authentication_verification_response $authorizeNetResponse['account_number'] = $response_array[50]; $authorizeNetResponse['card_type'] = $response_array[51]; $authorizeNetResponse['split_tender_id'] = $response_array[52]; $authorizeNetResponse['requested_amount'] = $response_array[53]; $authorizeNetResponse['balance_on_card'] = $response_array[54]; } if ($this->error or $this->declined) { // Prepare data that should be stored in the database $dbValues['authorizenet_response_response_code'] = $authorizeNetResponse['response_code']; $dbValues['authorizenet_response_response_subcode'] = $authorizeNetResponse['response_subcode']; $dbValues['authorizenet_response_response_reason_code'] = $authorizeNetResponse['response_reason_code']; $dbValues['authorizenet_response_response_reason_text'] = $authorizeNetResponse['response_reason_text']; //$this->storePSPluginInternalData($dbValues, 'id', true); $html = vmText::sprintf('VMPAYMENT_AUTHORIZENET_ERROR', $authorizeNetResponse['response_reason_text'], $authorizeNetResponse['response_code']) . "<br />"; $this->debugLog($html, '_handleResponse PAYMENT DECLINED', 'message'); return $html; } $virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($authorizeNetResponse['invoice_number']); if (!$virtuemart_order_id) { $this->approved = FALSE; $this->error = TRUE; $this->debugLog(vmText::sprintf('VMPAYMENT_AUTHORIZENET_NO_ORDER_NUMBER', $authorizeNetResponse['invoice_number']), 'getOrderIdByOrderNumber', 'error'); $html = vmText::sprintf('VMPAYMENT_AUTHORIZENET_ERROR', $authorizeNetResponse['response_reason_text'], $authorizeNetResponse['response_code']) . "<br />"; $this->debugLog($html, '_handleResponse PAYMENT DECLINED', 'message'); return $html; } } else { $this->approved = FALSE; $this->error = TRUE; $this->debugLog(vmText::_('VMPAYMENT_AUTHORIZENET_CONNECTING_ERROR'), '_handleResponse', 'error'); return vmText::_('VMPAYMENT_AUTHORIZENET_CONNECTING_ERROR'); } // Prep // get all know columns of the table $db = JFactory::getDBO(); $query = 'SHOW COLUMNS FROM `' . $this->_tablename . '` '; $db->setQuery($query); $columns = $db->loadColumn(0); foreach ($authorizeNetResponse as $key => $value) { $table_key = 'authorizenet_response_' . $key; if (in_array($table_key, $columns)) { $response_fields[$table_key] = $value; } } $response_fields['virtuemart_order_id'] = $virtuemart_order_id; $response_fields['invoice_number'] = $authorizeNetResponse['invoice_number']; $response_fields['authorizeresponse_raw'] = $response; $this->storePSPluginInternalData($response_fields, 'virtuemart_order_id', TRUE); $html = '<table class="adminlist table">' . "\n"; $html .= $this->getHtmlRow('AUTHORIZENET_PAYMENT_NAME', $payment_name); $html .= $this->getHtmlRow('AUTHORIZENET_ORDER_NUMBER', $authorizeNetResponse['invoice_number']); $html .= $this->getHtmlRow('AUTHORIZENET_AMOUNT', $authorizeNetResponse['amount'] . ' ' . self::AUTHORIZE_DEFAULT_PAYMENT_CURRENCY); //$html .= $this->getHtmlRow('AUTHORIZENET_RESPONSE_AUTHORIZATION_CODE', $authorizeNetResponse['authorization_code']); $html .= $this->getHtmlRow('AUTHORIZENET_RESPONSE_TRANSACTION_ID', $authorizeNetResponse['transaction_id']); $html .= '</table>' . "\n"; $this->debugLog(vmText::_('VMPAYMENT_AUTHORIZENET_ORDER_NUMBER') . " " . $authorizeNetResponse['invoice_number'] . ' payment approved', '_handleResponse', 'debug'); return $html; }
/** * Extends the standard function in vmplugin. Extendst the input data by virtuemart_order_id * Calls the parent to execute the write operation * * @author Max Milbers * @param array $_values * @param string $_table */ protected function storePSPluginInternalData($values, $primaryKey = 0, $preload = FALSE) { if (!class_exists('VirtueMartModelOrders')) { require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php'; } if (!isset($values['virtuemart_order_id'])) { $values['virtuemart_order_id'] = VirtueMartModelOrders::getOrderIdByOrderNumber($values['order_number']); } return $this->storePluginInternalData($values, $primaryKey, 0, $preload); }
/** * @param $html * @return bool * @throws Exception */ function plgVmOnPaymentResponseReceived(&$html) { if (!class_exists('VirtueMartCart')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'; } if (!class_exists('shopFunctionsF')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php'; } if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } // check we are in the good payment plugin $virtuemart_paymentmethod_id = vRequest::getInt('pm', 0); if (!($this->_currentMethod = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($this->_currentMethod->payment_element)) { return NULL; } $klarna_checkout_id = JRequest::getString('klarna_order', ''); if (empty($klarna_checkout_id)) { // not the good payment ? $this->debugLog(' because no klarna_order ', 'plgVmOnPaymentResponseReceived ', 'debug'); return NULL; } // fetch the order at klarna if (!$this->initKlarnaParams($this->_currentMethod)) { return; } $klarnaCheckoutInterface = $this->_loadKlarnaCheckoutInterface($virtuemart_paymentmethod_id); $klarna_checkout_connector = $klarnaCheckoutInterface->getKlarnaConnector(); $klarna_checkout_order = $klarnaCheckoutInterface->checkoutOrder($klarna_checkout_connector, $klarna_checkout_id); $klarna_checkout_order->fetch(); $this->debugLog($klarna_checkout_order['status'], 'plgVmOnPaymentResponseReceived ' . ' klarna status', 'debug'); if (!$klarnaCheckoutInterface->isKlarnaOrderStatusSuccess($klarna_checkout_order)) { JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_virtuemart&view=cart', false), vmText::_('VMPAYMENT_KLARNACHECKOUT_INCOMPLETE')); } // update VM with Klarna Infos $cart = VirtueMartCart::getCart(); $this->updateBTSTAddressInCart($cart, $klarna_checkout_order); //$this->updateCartFields($cart); $cart->prepareCartData(); // force validation $cart->_dataValidated = true; $cart->_confirmDone = true; $cart->confirmedOrder(); $this->debugLog($cart->order_number, 'plgVmOnPaymentResponseReceived ' . ' confirmDone FINAL', 'debug'); $dbValues['virtuemart_order_id'] = $cart->virtuemart_order_id; $dbValues['order_number'] = $cart->order_number; $dbValues['payment_name'] = $this->renderPluginName($this->_currentMethod); $dbValues['virtuemart_paymentmethod_id'] = $virtuemart_paymentmethod_id; $dbValues['klarna_id'] = $klarna_checkout_id; $dbValues['klarna_status'] = $klarna_checkout_order['status']; $dbValues['klarna_reservation'] = $klarna_checkout_order['reservation']; $dbValues['data'] = $klarna_checkout_order; $dbValues['format'] = 'none'; $this->debugLog(var_export($dbValues, true), 'plgVmOnPaymentResponseReceived storePSPluginInternalData before checkoutOrderManagement', 'debug'); $this->storePluginInternalData($dbValues); $dbValues = array(); $dbValues['virtuemart_order_id'] = $cart->virtuemart_order_id; $dbValues['order_number'] = $cart->order_number; $dbValues['payment_name'] = $this->renderPluginName($this->_currentMethod); $dbValues['virtuemart_paymentmethod_id'] = $virtuemart_paymentmethod_id; $dbValues['klarna_id'] = $klarna_checkout_id; $klarna_checkout_ordermanagement = $klarnaCheckoutInterface->checkoutOrderManagement($klarna_checkout_connector, $klarna_checkout_id); if ($klarna_checkout_ordermanagement) { $klarnaCheckoutInterface->acknowledge($klarna_checkout_ordermanagement); $klarna_checkout_ordermanagement->fetch(); $klarna_checkout_ordermanagement->updateMerchantReferences(array("merchant_reference1" => $cart->order_numbe)); $klarnaCheckoutInterface->getStoreInternalData($klarna_checkout_ordermanagement, $dbValues); $this->debugLog(var_export($dbValues, true), 'plgVmOnPaymentResponseReceived storePSPluginInternalData checkoutOrderManagement', 'debug'); $this->storePSPluginInternalData($dbValues); } else { // send order number to klarna $klarna_update['status'] = 'created'; $klarna_update['merchant_reference'] = array('orderid1' => $cart->order_number); $klarna_checkout_order->update($klarna_update); $dbValues['klarna_status'] = $klarna_checkout_order['status']; $dbValues['data'] = json_encode($klarna_update); $dbValues['format'] = 'json'; $this->debugLog(var_export($dbValues, true), 'plgVmOnPaymentResponseReceived storePSPluginInternalData checkoutOrderManagement', 'debug'); $this->storePluginInternalData($dbValues); } // Notify shopper $modelOrder = VmModel::getModel('orders'); $update_history['order_status'] = $this->_currentMethod->status_checkout_complete; $update_history['customer_notified'] = 1; $update_history['comments'] = vmText::sprintf('VMPAYMENT_KLARNACHECKOUT_PAYMENT_STATUS_CONFIRMED', $cart->order_number); if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $orders = new VirtueMartModelOrders(); $virtuemart_order_id = $orders->getOrderIdByOrderNumber($cart->order_number); $modelOrder->updateStatusForOneOrder($virtuemart_order_id, $update_history, TRUE); $order = $modelOrder->getOrder($virtuemart_order_id); /* DONE ALREADY // store data in Klarna payment table $dbValues['order_number'] = $cart->order_number; $dbValues['virtuemart_paymentmethod_id'] = $cart->virtuemart_paymentmethod_id; $dbValues['klarna_id'] = $this->getKlarnaCheckoutIdFromSession(); $dbValues['payment_name'] = $this->renderPluginName($this->_currentMethod, $order); $klarnaCheckoutInterface->getStoreInternalData($klarna_checkout_order,$dbValues); $dbValues['email_currency'] = $this->getEmailCurrency($this->_currentMethod); $this->debugLog(var_export($dbValues, true), 'plgVmOnPaymentResponseReceived storePSPluginInternalData', 'debug'); $this->storePSPluginInternalData($dbValues); */ // render Thank you page $html = $this->renderByLayout('response_received', array('snippet' => $klarnaCheckoutInterface->getSnippet($klarna_checkout_order), 'order_number' => $order['details']['BT']->order_number, 'order_pass' => $order['details']['BT']->order_pass)); // clean everything $this->clearKlarnaParams($cart); $cart->emptyCart(); $cart->removeCartFromSession(); return TRUE; }
/** * @param $paybox_data * @return bool */ function paymentResponseReceived($paybox_data) { if ($payboxResponseValid = $this->isPayboxResponseValid($paybox_data, false, true)) { // we don't do anything actually, it is probably an invalid signature. // we do not update order status and let IPN do his job } $order_number = $this->getOrderNumber($paybox_data['R']); if (empty($order_number)) { $this->plugin->debugLog($order_number, 'getOrderNumber not correct' . $paybox_data['R'], 'debug', false); return FALSE; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { return FALSE; } if (!($payments = $this->plugin->getPluginDatasByOrderId($virtuemart_order_id))) { $this->plugin->debugLog('no payments found', 'getDatasByOrderId', 'debug', false); $this->redirectToCart(); return FALSE; } $orderModel = tmsModel::getModel('orders'); $order = $orderModel->getOrder($virtuemart_order_id); $paybox_data = $this->unsetNonPayboxData($paybox_data); $success = $paybox_data['E'] == self::RESPONSE_SUCCESS; $extra_comment = ""; // The order status is nly updated if the validation is ok if ($payboxResponseValid) { if (count($payments) == 1) { // NOTIFY not received $order_history = $this->updateOrderStatus($paybox_data, $order, $payments); if (isset($order_history['extra_comment'])) { $extra_comment = $order_history['extra_comment']; } } } $html = $this->plugin->getResponseHTML($order, $paybox_data, $success, $extra_comment); $cart = VirtueMartCart::getCart(); $cart->emptyCart(); return $html; }
private function initRealexInterface($loadCDFromPost = true) { // TODO check if cart is empty $virtuemart_paymentmethod_id = vRequest::getInt('pm', false); $this->_currentMethod = $this->getVmPluginMethod($virtuemart_paymentmethod_id); if (!$this->selectedThisElement($this->_currentMethod->payment_element)) { vmError('Programmer error: missing the pm parameter'); $this->redirectToCart(); return FALSE; } $realexInterface = $this->_loadRealexInterface(); $realexInterface->loadCustomerData($loadCDFromPost); $order_number = vRequest::getString('order_number', false); if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { $this->redirectToCart(); return FALSE; } $orderModel = VmModel::getModel('orders'); $order = $orderModel->getOrder($virtuemart_order_id); $realexInterface->setOrder($order); $realexInterface->setPaymentCurrency(); $realexInterface->setTotalInPaymentCurrency($order['details']['BT']->order_total); return $realexInterface; }
function managePaymentResponse ($virtuemart_order_id, $resp, $new_status, $return_context = NULL) { // Save platform response data $this->savePaymentData ($virtuemart_order_id, $resp); if (!class_exists ('VirtueMartModelOrders')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'); } // save order data $modelOrder = new VirtueMartModelOrders(); $order['order_status'] = $new_status; $order['virtuemart_order_id'] = $virtuemart_order_id; $order['customer_notified'] = 1; $date = JFactory::getDate (); $order['comments'] = JText::sprintf ('VMPAYMENT_' . $this->_name . '_NOTIFICATION_RECEVEIVED', $date->toFormat ('%Y-%m-%d %H:%M:%S')); //vmdebug($this->_name . ' - managePaymentResponse', $order); // la fonction updateStatusForOneOrder fait l'envoie de l'email à partir de VM2.0.2 $modelOrder->updateStatusForOneOrder ($virtuemart_order_id, $order, TRUE); if (!class_exists ('VirtueMartCart')) { require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'); } if ($resp->isAcceptedPayment ()) { // Empty cart in session $this->emptyCart ($return_context); } }