function onPaymentNotification(&$statuses) { $this->pluginParams(); $configKey = $this->plugin_params->user_id . ':' . $this->plugin_params->project_id . ':' . $this->plugin_params->token; require_once dirname(__FILE__) . '/library/sofortLib.php'; $notification = new SofortLib_Notification(); $notification->getNotification(); echo $notification->getTime(); $transactionId = $notification->getTransactionId(); //$return_url = HIKASHOP_LIVE.'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id='.$order_id.$this->url_itemid; // fetch some information for the transaction id retrieved above $transactionData = new SofortLib_TransactionData($configKey); $transactionData->setTransaction($transactionId); $transactionData->sendRequest(); $method_id = $transactionData->getUserVariable(1); $this->pluginParams($method_id); $this->payment_params =& $this->plugin_params; global $Itemid; $this->url_itemid = empty($Itemid) ? '' : '&Itemid=' . $Itemid; $cancel_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=order&task=cancel_order' . $this->url_itemid; if (empty($this->payment_params)) { $this->redirect($cancel_url); return false; } $order_id = $transactionData->getUserVariable(0); echo $order_id; $dbOrder = $this->getOrder($order_id); if (empty($dbOrder)) { $this->redirect_url = $cancel_url; return false; } $history = new stdClass(); $history->history_data = 'TransactionId: ' . $transactionId; $history->notified = 0; if ($transactionData->getStatus() == 'pending') { $email = new stdClass(); $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Sofort', $transactionData->getStatus(), $dbOrder->order_number); $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Sofort', $transactionData->getStatus())) . "\r\n\r\n" . $transactionData->getStatusReason(); $action = false; $order_status = $this->payment_params->pending_status; $this->modifyOrder($order_id, $order_status, $history, $email); return false; } if ($transactionData->getStatus() != 'received') { $order_status = 'created'; $email = new stdClass(); $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Sofort', $order_status)) . ' ' . JText::_('STATUS_NOT_CHANGED') . "\r\n\r\n" . $transactionData->getStatusReason(); $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Sofort', $order_status, $dbOrder->order_number); $this->modifyOrder($order_id, $order_status, $history, $email); return false; } $order_status = $this->payment_params->verified_status; $history->history_data = 'TransactionId: ' . $transactionId; $history->notified = 1; $email = new stdClass(); $email->subject = JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Sofort', $transactionData->getStatus(), $dbOrder->order_number); $email->body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Sofort', $order_status)) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $order_status) . "\r\n\r\n" . $transactionData->getStatusReason(); $this->modifyOrder($order_id, $order_status, $history, $email); return true; }
function sofort_ipn() { global $edd_options; if (isset($_GET['sofort']) && $_GET['sofort'] == 'ipn') { require_once 'library/sofortLib.php'; $notification = new SofortLib_Notification(); $notification->getNotification(); $transactionId = $notification->getTransactionId(); if ($transactionId) { // fetch some information for the transaction id retrieved above $transactionData = new SofortLib_TransactionData(trim($edd_options['sofort_config_id'])); $transactionData->setTransaction($transactionId); $transactionData->sendRequest(); $reason = $transactionData->getReason(); $payment_id = str_replace('CartId ', '', $reason[0]); edd_update_payment_status($payment_id, 'publish'); edd_insert_payment_note($payment_id, 'Payment Successful. Transaction ID is ' . $transactionId); } exit; } }
/** * @return bool|null */ function plgVmOnPaymentNotification() { //$this->_debug = true; if (!class_exists('VirtueMartModelOrders')) { require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php'; } $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'); $this->_currentMethod = $this->getVmPluginMethod($payments[0]->virtuemart_paymentmethod_id); if (!$this->selectedThisElement($this->_currentMethod->payment_element)) { return FALSE; } 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(); $transactionId = $sofortLib_Notification->getNotification(); //no valid parameters/xml if (empty($transactionId) || $sofortLib_Notification->isError()) { $this->debugLog('no transaction ID for order number' . $order_number, 'plgVmOnPaymentNotification', 'error'); return FALSE; } $this->debugLog($transactionId, 'plgVmOnPaymentNotification Transaction ID ', 'debug'); $sofortLib_TransactionData = new SofortLib_TransactionData(trim($this->_currentMethod->configuration_key)); $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); }
/** * notification about status change */ public function notificationAction() { set_error_handler('sofort_notification_error'); // prevent to submit confirm/cancel back $GLOBALS['isNotificationAction'] = true; $response = $this->getRequest()->getParams(); $orderId = $response['orderId']; $secret = $response['secret']; // read notofication $sofort = new SofortLib_Notification(); $transaction = $sofort->getNotification(); //no valid parameters/xml if (empty($orderId) || empty($transaction)) { Mage::log('Notification invalid: ' . __CLASS__ . ' ' . __LINE__ . " - " . $orderId . " - " . $transaction); return; } if ($sofort->isError()) { Mage::log($sofort->getError(), Zend_Log::ERR, 'sofort_error.log'); } // load current transaction data $transData = new SofortLib_TransactionData(Mage::getStoreConfig('payment/sofort/configkey')); $transData->setTransaction($transaction)->sendRequest(); if ($transData->isError()) { Mage::log('Notification invalid: ' . __CLASS__ . ' ' . __LINE__ . $transData->getError()); return; } $order = Mage::getModel('sales/order'); $order->loadByIncrementId($orderId); $paymentObj = $order->getPayment()->getMethodInstance(); $payment = $order->getPayment(); //data of transaction doesn't match order if ($payment->getAdditionalInformation('sofort_transaction') != $transaction || $payment->getAdditionalInformation('sofort_secret') != $secret) { Mage::log('Notification invalid: ' . __CLASS__ . ' ' . __LINE__); return; } // BUGFIX // if notification for confirm + refund got the same, we need to confirm first if ($transData->isSofortrechnung() && $transData->isRefunded() && !$order->hasInvoices()) { $this->_transactionConfirmed($transData, $order, true); // reload order $order = Mage::getModel('sales/order'); $order->loadByIncrementId($orderId); } // check if order was edit $sofortRechnung = Mage::getModel('pnsofortueberweisung/sofortrechnung'); $sofortRechnung->updateOrderFromTransactionData($transData, $order); // check if something other change if ($payment->getAdditionalInformation('sofort_lastchanged') === $this->_getLastChanged($transData)) { return; } $payment->setAdditionalInformation('sofort_lastchanged', $this->_getLastChanged($transData))->save(); // kauf auf Rechnung if ($transData->isSofortrechnung()) { if ($transData->isLoss()) { $this->_transactionLoss($transData, $order); } elseif ($transData->isPending() && $transData->getStatusReason() == 'confirm_invoice') { $this->_transactionUnconfirmed($transData, $order); } elseif ($transData->isPending()) { $this->_transactionConfirmed($transData, $order); } elseif ($transData->isReceived()) { //don't do anything } elseif ($transData->isRefunded()) { $this->_transactionRefunded($transData, $order); } else { //uups $order->addStatusHistoryComment($transData->getStatus() . " " . $transData->getStatusReason()); } // sofortueberweisung, lastschrift } else { if ($transData->isLoss()) { $this->_transactionLoss($transData, $order); } elseif ($transData->isPending()) { $this->_transactionConfirmed($transData, $order); } elseif ($transData->isReceived()) { // no status change on received $this->_transactionReceived($transData, $order); } elseif ($transData->isRefunded()) { $this->_transactionRefunded($transData, $order); } else { //uups $order->addStatusHistoryComment($transData->getStatus() . " " . $transData->getStatusReason()); } } $order->save(); }
$transactionId = $SofortLib_ClassicNotification->getTransaction(); if (empty($transactionId)) { exit('TransID empty!'); } $time = $SofortLib_ClassicNotification->getTime(); $time = strftime('%Y-%m-%d %H:%M:%S', strtotime($time)); $statusReason = $SofortLib_ClassicNotification->getStatusReason(); $status = $SofortLib_ClassicNotification->getStatus(); $xOrderId = $SofortLib_ClassicNotification->getUserVariable(0); $xCustomerId = $SofortLib_ClassicNotification->getUserVariable(1); $paymentMethod = 'ideal'; } elseif ($_GET['action'] == 'su') { // SU-classic } elseif ($_GET['action'] == 'multipay' || !$_GET['action']) { // Multipay $SofortLib_Notification = new SofortLib_Notification(); $transactionId = $SofortLib_Notification->getNotification(); if (empty($transactionId)) { exit('TransID empty!'); } $time = $SofortLib_Notification->getTime(); $time = strftime('%Y-%m-%d %H:%M:%S', strtotime($time)); $SofortLib_TransactionData = new SofortLib_TransactionData(MODULE_PAYMENT_SOFORT_MULTIPAY_APIKEY); if (!is_object($SofortLib_TransactionData) || !$SofortLib_TransactionData instanceof SofortLib_TransactionData) { exit('Error: TransactionData-Object corrupt.'); } $SofortLib_TransactionData->setTransaction($transactionId); $SofortLib_TransactionData->sendRequest(); if ($SofortLib_TransactionData->isError()) { exit($SofortLib_TransactionData->getError()); }
/** * @return bool|null */ function plgVmOnPaymentNotification() { //$this->_debug = true; if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $order_number = JRequest::getString('on', ''); if (empty($order_number)) { $this->logInfo('plgVmOnPaymentNotification EMPTY order number' . $order_number, 'message'); return FALSE; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { $this->logInfo('plgVmOnPaymentNotification NO getOrderIdByOrderNumber ' . $order_number, 'message'); return FALSE; } if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { $this->logInfo('plgVmOnPaymentNotification NO getDatasByOrderId ' . $virtuemart_order_id, 'message'); return FALSE; } $this->logInfo('plgVmOnPaymentNotification OK ', 'message'); $method = $this->getVmPluginMethod($payments[0]->virtuemart_paymentmethod_id); if (!$this->selectedThisElement($method->payment_element)) { return FALSE; } if (!class_exists('SofortLib')) { require JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'sofort' . DS . 'sofort' . DS . 'library' . DS . 'sofortLib.php'; } $sofortLib_Notification = new SofortLib_Notification(); $transactionId = $sofortLib_Notification->getNotification(); //no valid parameters/xml if (empty($transactionId) || $sofortLib_Notification->isError()) { $this->logInfo('plgVmOnPaymentNotification NO transaaction or $sofortLib_Notification is error \\n', 'message'); return FALSE; } $this->logInfo('plgVmOnPaymentNotification transaction ' . $transactionId, 'message'); $sofortLib_TransactionData = new SofortLib_TransactionData($method->configuration_key); $sofortLib_TransactionData->setTransaction($transactionId)->sendRequest(); $this->logInfo('plgVmOnPaymentNotification setTransaction OK', 'message'); // check that secret , and order are identical $security = JRequest::getString('security', ''); if ($security != $payments[0]->security) { $this->logInfo('plgVmOnPaymentNotification SECURITY not the one expected GOT: ' . $security . ' stored: ' . $payments[0]->security, 'message'); $emailBody = "Hello,\n\nerror while receiving a SOFORT NOTIFICATION" . "\n"; $emailBody .= "for order number: " . $order_number . "\n"; $emailBody .= "security token received: " . $security . "\n"; $emailBody .= "security token expected: " . $payments[0]->security . "\n"; $this->sendEmailToVendorAndAdmins(JText::_('VMPAYMENT_SOFORT_ERROR_NOTIFICATION'), $emailBody); return false; } $paymentMethod = $sofortLib_TransactionData->getPaymentMethod(); if ($paymentMethod != self::SU_SOFORTBANKING) { // answer not expected $this->logInfo('plgVmOnPaymentNotification not the one one expected?' . $paymentMethod . ' ' . self::SU_SOFORTBANKING, 'message'); $emailBody = "Hello,\n\nerror while receiving a SOFORT NOTIFICATION" . "\n"; $emailBody .= "Payment method is " . $paymentMethod . " Should be SU \n"; $this->sendEmailToVendorAndAdmins(JText::_('VMPAYMENT_SOFORT_ERROR_NOTIFICATION'), $emailBody); return false; } $this->logInfo('plgVmOnPaymentNotification so', 'message'); $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 = array(); $status = 'status_' . $sofortLib_TransactionData->getStatus(); //$this->logInfo('plgVmOnPaymentNotification getStatus:' .$status. ' '.var_export($method, true) , 'message'); $order['customer_notified'] = true; $order['order_status'] = $method->{$status}; $order['comments'] = JText::_('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($method)); $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->logInfo('storePSPluginInternalData before storePSPluginInternalData ' . var_export($sofort_data, true), 'message'); $this->storePSPluginInternalData($sofort_data); $modelOrder->updateStatusForOneOrder($payments[0]->virtuemart_order_id, $order, TRUE); }
/** * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date$ * @version SofortLib 1.5.0rc $Id$ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ // read the notification from php://input (http://php.net/manual/en/wrappers.php.php) // this class should be used as a callback function require_once '../../library/sofortLib.php'; $notification = new SofortLib_Notification(); $notification->getNotification(); echo $notification->getTime(); $transactionId = $notification->getTransactionId(); // fetch some information for the transaction id retrieved above $transactionData = new SofortLib_TransactionData(); $transactionData->setTransaction($transactionId); $transactionData->sendRequest(); echo '<table border="1">'; echo '<tr><td>transaction was: </td><td align="right">' . $transactionData->getTransaction() . '</td></tr>'; echo '<tr><td>start date is: </td><td align="right">' . $transactionData->getSofortaboStartDate() . '</td></tr>'; echo '<tr><td>amount is: </td><td align="right">' . $transactionData->getAmount() . ' ' . $transactionData->getCurrency() . '</td></tr>'; echo '<tr><td>interval is: </td><td align="right">' . $transactionData->getSofortaboInterval() . '</td></tr>'; echo '<tr><td>minimum payments: </td><td align="right">' . $transactionData->getSofortaboMinimumPayments() . '</td></tr>'; echo '<tr><td>status is: </td><td align="right">' . $transactionData->getStatus() . ' - ' . $transactionData->getStatusReason() . '</td></tr>'; echo '</table>';