protected function _updateManifest($module) { $file = dirname(__FILE__) . '/settings/manifest.php'; $manifest = (include $file); $dir = Engine_Api::inflect($module); $manifest['package']['callback'] = array('path' => 'application/modules/' . $dir . '/settings/install.php', 'class' => $dir . '_Package_Installer'); $this->_writeFile($manifest, $file); }
/** * Process an IPN * * @param Engine_Payment_Ipn $ipn * @return Engine_Payment_Plugin_Abstract */ public function onIpn(Engine_Payment_Ipn $ipn) { $rawData = $ipn->getRawData(); $ordersTable = Engine_Api::_()->getDbtable('orders', 'payment'); $transactionsTable = Engine_Api::_()->getDbtable('transactions', 'payment'); // Find transactions ------------------------------------------------------- $transactionId = null; $transaction = null; // Fetch by invoice_id if (!empty($rawData['invoice_id'])) { $transaction = $transactionsTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_transaction_id = ?' => $rawData['invoice_id'])); } if ($transaction && !empty($transaction->gateway_transaction_id)) { $transactionId = $transaction->gateway_transaction_id; } else { $transactionId = @$rawData['invoice_id']; } // Fetch order ------------------------------------------------------------- $order = null; // Get order by vendor_order_id if (!$order && !empty($rawData['vendor_order_id'])) { $order = $ordersTable->find($rawData['vendor_order_id'])->current(); } // Get order by invoice_id if (!$order && $transactionId) { $order = $ordersTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_transaction_id = ?' => $transactionId)); } // Get order by sale_id if (!$order && !empty($rawData['sale_id'])) { $order = $ordersTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_order_id = ?' => $rawData['sale_id'])); } // Get order by order_id through transaction if (!$order && $transaction && !empty($transaction->order_id)) { $order = $ordersTable->find($transaction->order_id)->current(); } // Update order with order/transaction id if necessary $orderUpdated = false; if (!empty($rawData['invoice_id']) && empty($order->gateway_transaction_id)) { $orderUpdated = true; $order->gateway_transaction_id = $rawData['invoice_id']; } if (!empty($rawData['sale_id']) && empty($order->gateway_order_id)) { $orderUpdated = true; $order->gateway_order_id = $rawData['sale_id']; } if ($orderUpdated) { $order->save(); } // Process generic IPN data ------------------------------------------------ // Build transaction info if (!empty($rawData['invoice_id'])) { $transactionData = array('gateway_id' => $this->_gatewayInfo->gateway_id); // Get timestamp if (!empty($rawData['payment_date'])) { $transactionData['timestamp'] = date('Y-m-d H:i:s', strtotime($rawData['timestamp'])); } else { $transactionData['timestamp'] = new Zend_Db_Expr('NOW()'); } // Get amount if (!empty($rawData['invoice_list_amount'])) { $transactionData['amount'] = $rawData['invoice_list_amount']; } else { if ($transaction) { $transactionData['amount'] = $transaction->amount; } else { if (!empty($rawData['item_list_amount_1'])) { // For recurring success $transactionData['amount'] = $rawData['item_list_amount_1']; } } } // Get currency if (!empty($rawData['list_currency'])) { $transactionData['currency'] = $rawData['list_currency']; } else { if ($transaction) { $transactionData['currency'] = $transaction->currency; } } // Get order/user if ($order) { $transactionData['user_id'] = $order->user_id; $transactionData['order_id'] = $order->order_id; } // Get transactions if ($transactionId) { $transactionData['gateway_transaction_id'] = $transactionId; } if (!empty($rawData['sale_id'])) { $transactionData['gateway_order_id'] = $rawData['sale_id']; } // Get payment_status if (!empty($rawData['invoice_status'])) { if ($rawData['invoice_status'] == 'declined') { $transactionData['type'] = 'payment'; $transactionData['state'] = 'failed'; } else { if ($rawData['fraud_status'] == 'fail') { $transactionData['type'] = 'payment'; $transactionData['state'] = 'failed-fraud'; } else { if ($rawData['fraud_status'] == 'wait') { $transactionData['type'] = 'payment'; $transactionData['state'] = 'pending-fraud'; } else { $transactionData['type'] = 'payment'; $transactionData['state'] = 'okay'; } } } } if ($transaction && ($transaction->type == 'refund' || $transaction->state == 'refunded')) { $transactionData['type'] = $transaction->type; $transactionData['state'] = $transaction->state; } // Special case for refund_issued $childTransactionData = array(); if ($rawData['message_type'] == 'REFUND_ISSUED') { $childTransactionData = $transactionData; $childTransactionData['gateway_parent_transaction_id'] = $childTransactionData['gateway_transaction_id']; //unset($childTransactionData['gateway_transaction_id']); // Should we unset this? $childTransactionData['amount'] = -$childTransactionData['amount']; $childTransactionData['type'] = 'refund'; $childTransactionData['state'] = 'refunded'; // Update parent transaction $transactionData['state'] = 'refunded'; } // Insert or update transactions if (!$transaction) { $transactionsTable->insert($transactionData); } else { unset($transactionData['timestamp']); $transaction->setFromArray($transactionData); $transaction->save(); } // Insert new child transaction if ($childTransactionData) { $childTransactionExists = $transactionsTable->select()->from($transactionsTable, new Zend_Db_Expr('TRUE'))->where('gateway_transaction_id = ?', $childTransactionData['gateway_transaction_id'])->where('type = ?', $childTransactionData['type'])->where('state = ?', $childTransactionData['state'])->limit(1)->query()->fetchColumn(); if (!$childTransactionExists) { $transactionsTable->insert($childTransactionData); } } } // Process specific IPN data ----------------------------------------------- if ($order) { $ipnProcessed = false; // Subscription IPN if ($order->source_type == 'payment_subscription') { $this->onSubscriptionTransactionIpn($order, $ipn); $ipnProcessed = true; } else { // Custom item-type IPN if (Engine_Api::_()->hasItemType($order->source_type) && !empty($order->source_id)) { $orderSourceObject = Engine_Api::_()->getItem($order->source_type, $order->source_id); if (method_exists($orderSourceObject, 'onPaymentIpn')) { $ipnProcessed = (bool) $orderSourceObject->onPaymentIpn($order, $ipn); } else { throw new Engine_Payment_Plugin_Exception(sprintf('Custom order ' . 'item "%s" does not implement onPaymentIpn() method', $order->source_type)); } } else { $eventName = 'onPaymentIpn_' . Engine_Api::inflect($order->source_type); $response = Engine_Hooks_Dispatcher::getInstance()->callEvent($eventName, array('order' => $order, 'ipn' => $ipn)); if (false != $response->getResponse()) { // Okay $ipnProcessed = true; } } } // Unknown IPN - could not be processed if (!$ipnProcessed) { throw new Engine_Payment_Plugin_Exception('Unknown order type for IPN'); } } else { throw new Engine_Payment_Plugin_Exception('Unknown or unsupported IPN ' . 'type, or missing transaction or order ID'); } return $this; }
/** * Process an IPN * * @param Engine_Payment_Ipn $ipn * @return Engine_Payment_Plugin_Abstract */ public function onIpn(Engine_Payment_Ipn $ipn) { $rawData = $ipn->getRawData(); $ordersTable = Engine_Api::_()->getDbtable('orders', 'payment'); $transactionsTable = Engine_Api::_()->getDbtable('transactions', 'payment'); // Find transactions ------------------------------------------------------- $transactionId = null; $parentTransactionId = null; $transaction = null; $parentTransaction = null; // Fetch by txn_id if (!empty($rawData['txn_id'])) { $transaction = $transactionsTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_transaction_id = ?' => $rawData['txn_id'])); $parentTransaction = $transactionsTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_parent_transaction_id = ?' => $rawData['txn_id'])); } // Fetch by parent_txn_id if (!empty($rawData['parent_txn_id'])) { if (!$transaction) { $parentTransaction = $transactionsTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_parent_transaction_id = ?' => $rawData['parent_txn_id'])); } if (!$parentTransaction) { $parentTransaction = $transactionsTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_transaction_id = ?' => $rawData['parent_txn_id'])); } } // Fetch by transaction->gateway_parent_transaction_id if ($transaction && !$parentTransaction && !empty($transaction->gateway_parent_transaction_id)) { $parentTransaction = $transactionsTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_parent_transaction_id = ?' => $transaction->gateway_parent_transaction_id)); } // Fetch by parentTransaction->gateway_transaction_id if ($parentTransaction && !$transaction && !empty($parentTransaction->gateway_transaction_id)) { $transaction = $transactionsTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_parent_transaction_id = ?' => $parentTransaction->gateway_transaction_id)); } // Get transaction id if ($transaction) { $transactionId = $transaction->gateway_transaction_id; } else { if (!empty($rawData['txn_id'])) { $transactionId = $rawData['txn_id']; } } // Get parent transaction id if ($parentTransaction) { $parentTransactionId = $parentTransaction->gateway_transaction_id; } else { if ($transaction && !empty($transaction->gateway_parent_transaction_id)) { $parentTransactionId = $transaction->gateway_parent_transaction_id; } else { if (!empty($rawData['parent_txn_id'])) { $parentTransactionId = $rawData['parent_txn_id']; } } } // Fetch order ------------------------------------------------------------- $order = null; // Transaction IPN - get order by invoice if (!$order && !empty($rawData['invoice'])) { $order = $ordersTable->find($rawData['invoice'])->current(); } // Subscription IPN - get order by recurring_payment_id if (!$order && !empty($rawData['recurring_payment_id'])) { // Get attached order $order = $ordersTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_order_id = ?' => $rawData['recurring_payment_id'])); } // Subscription IPN - get order by rp_invoice_id //if( !$order && !empty($rawData['rp_invoice_id']) ) { // //} // Transaction IPN - get order by parent_txn_id if (!$order && $parentTransactionId) { $order = $ordersTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_transaction_id = ?' => $parentTransactionId)); } // Transaction IPN - get order by txn_id if (!$order && $transactionId) { $order = $ordersTable->fetchRow(array('gateway_id = ?' => $this->_gatewayInfo->gateway_id, 'gateway_transaction_id = ?' => $transactionId)); } // Transaction IPN - get order through transaction if (!$order && !empty($transaction->order_id)) { $order = $ordersTable->find($parentTransaction->order_id)->current(); } // Transaction IPN - get order through parent transaction if (!$order && !empty($parentTransaction->order_id)) { $order = $ordersTable->find($parentTransaction->order_id)->current(); } // Process generic IPN data ------------------------------------------------ // Build transaction info if (!empty($rawData['txn_id'])) { $transactionData = array('gateway_id' => $this->_gatewayInfo->gateway_id); // Get timestamp if (!empty($rawData['payment_date'])) { $transactionData['timestamp'] = date('Y-m-d H:i:s', strtotime($rawData['payment_date'])); } else { $transactionData['timestamp'] = new Zend_Db_Expr('NOW()'); } // Get amount if (!empty($rawData['mc_gross'])) { $transactionData['amount'] = $rawData['mc_gross']; } // Get currency if (!empty($rawData['mc_currency'])) { $transactionData['currency'] = $rawData['mc_currency']; } // Get order/user if ($order) { $transactionData['user_id'] = $order->user_id; $transactionData['order_id'] = $order->order_id; } // Get transactions if ($transactionId) { $transactionData['gateway_transaction_id'] = $transactionId; } if ($parentTransactionId) { $transactionData['gateway_parent_transaction_id'] = $parentTransactionId; } // Get payment_status switch ($rawData['payment_status']) { case 'Canceled_Reversal': // @todo make sure this works // @todo make sure this works case 'Completed': case 'Created': case 'Processed': $transactionData['type'] = 'payment'; $transactionData['state'] = 'okay'; break; case 'Denied': case 'Expired': case 'Failed': case 'Voided': $transactionData['type'] = 'payment'; $transactionData['state'] = 'failed'; break; case 'Pending': $transactionData['type'] = 'payment'; $transactionData['state'] = 'pending'; break; case 'Refunded': $transactionData['type'] = 'refund'; $transactionData['state'] = 'refunded'; break; case 'Reversed': $transactionData['type'] = 'reversal'; $transactionData['state'] = 'reversed'; break; default: $transactionData = 'unknown'; break; } // Insert new transaction if (!$transaction) { $transactionsTable->insert($transactionData); } else { unset($transactionData['timestamp']); $transaction->setFromArray($transactionData); $transaction->save(); } // Update parent transaction on refund? if ($parentTransaction && in_array($transactionData['type'], array('refund', 'reversal'))) { $parentTransaction->state = $transactionData['state']; $parentTransaction->save(); } } // Process specific IPN data ----------------------------------------------- if ($order) { $ipnProcessed = false; // Subscription IPN if ($order->source_type == 'payment_subscription') { $this->onSubscriptionTransactionIpn($order, $ipn); $ipnProcessed = true; } else { // Custom item-type IPN if (Engine_Api::_()->hasItemType($order->source_type) && !empty($order->source_id)) { $orderSourceObject = Engine_Api::_()->getItem($order->source_type, $order->source_id); if (method_exists($orderSourceObject, 'onPaymentIpn')) { $ipnProcessed = (bool) $orderSourceObject->onPaymentIpn($order, $ipn); } else { throw new Engine_Payment_Plugin_Exception(sprintf('Custom order ' . 'item "%s" does not implement onPaymentIpn() method', $order->source_type)); } } else { $eventName = 'onPaymentIpn_' . Engine_Api::inflect($order->source_type); $response = Engine_Hooks_Dispatcher::getInstance()->callEvent($eventName, array('order' => $order, 'ipn' => $ipn)); if (false != $response->getResponse()) { // Okay $ipnProcessed = true; } } } // Unknown IPN - could not be processed if (!$ipnProcessed) { throw new Engine_Payment_Plugin_Exception('Unknown order type for IPN'); } } else { throw new Engine_Payment_Plugin_Exception('Unknown or unsupported IPN ' . 'type, or missing transaction or order ID'); } return $this; }
protected function _initModules() { //$front = null; //$default = 'core'; //if( isset($this->getContainer()->frontcontroller) ) { $front = $this->getContainer()->frontcontroller; $default = $front->getDefaultModule(); //} $bootstraps = new ArrayObject(); // Prepare data $enabledModuleNames = Engine_Api::_()->getDbtable('modules', 'core')->getEnabledModuleNames(); $baseDir = APPLICATION_PATH; //$baseUrl = preg_replace('/[\/]*index\.php[\/]*/', '/', $front->getBaseUrl()); foreach ($enabledModuleNames as $module) { $moduleInflected = Engine_Api::inflect($module); $moduleDir = $baseDir . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleInflected; // Default module is already bootstrapped, but bootstrap others if (strtolower($module) === strtolower($default)) { continue; } $bootstrapClass = $moduleInflected . '_Bootstrap'; if (!class_exists($bootstrapClass, false)) { $bootstrapPath = $moduleDir . '/Bootstrap.php'; if (file_exists($bootstrapPath)) { include_once $bootstrapPath; if (!class_exists($bootstrapClass, false)) { throw new Zend_Application_Resource_Exception('Bootstrap file found for module "' . $module . '" but bootstrap class "' . $bootstrapClass . '" not found'); } } else { continue; } } $moduleBootstrap = new $bootstrapClass($this); $moduleBootstrap->bootstrap(); $bootstraps[$module] = $moduleBootstrap; } return $bootstraps; }
protected function _writeEnabledModulesFile() { $db = $this->getDb(); // get enabled modules list $enabledModuleNames = $db->select()->from('engine4_core_modules', 'name')->where('enabled = ?', 1)->query()->fetchAll(Zend_Db::FETCH_COLUMN); $enabled_modules_file = APPLICATION_PATH . '/application/settings/enabled_module_directories.php'; if (is_file($enabled_modules_file) && is_writable($enabled_modules_file) || is_dir(dirname($enabled_modules_file)) && is_writable(dirname($enabled_modules_file))) { foreach ($enabledModuleNames as $module) { $modulesInflected[] = Engine_Api::inflect($module); } $file_contents = "<?php defined('_ENGINE') or die('Access Denied'); return "; $file_contents .= var_export($modulesInflected, true); $file_contents .= "; ?>"; file_put_contents($enabled_modules_file, $file_contents); chmod($enabled_modules_file, 0777); } }
protected function _initFrontControllerModules() { $frontController = Zend_Controller_Front::getInstance(); $path = APPLICATION_PATH . DIRECTORY_SEPARATOR . "modules"; $enabledModuleNames = Khcn_Api::_()->getDbtable('modules', 'default')->getEnabledModuleNames(); var_dump($enabledModuleNames); die; foreach ($enabledModuleNames as $module) { $moduleInflected = Engine_Api::inflect($module); $moduleDir = $path . DIRECTORY_SEPARATOR . $moduleInflected; if (is_dir($moduleDir)) { $moduleDir .= DIRECTORY_SEPARATOR . $frontController->getModuleControllerDirectoryName(); $frontController->addControllerDirectory($moduleDir, $module); } else { // Maybe we should log modules that fail to load? if (APPLICATION_ENV == 'development') { throw new Engine_Exception('failed to load module "' . $module . '"'); } } } $frontController->setDefaultModule('default'); }