/** * Function to run hooks in the payment processor class * Load requested payment processor and call the method specified. * * @param string $method - the method to call in the payment processor class * @private */ private function _runPaymentHook(CRM_Extension_Info $info, $method) { // Not concerned about performance at this stage, as these are seldomly performed tasks // (payment processor enable/disable/install/uninstall). May wish to implement some // kind of registry/caching system if more hooks are added. try { $paymentClass = $this->mapper->keyToClass($info->key, 'payment'); $file = $this->mapper->classToPath($paymentClass); if (!file_exists($file)) { CRM_Core_Session::setStatus(ts('Failed to load file (%3) for payment processor (%1) while running "%2"', array(1 => $info->key, 2 => $method, 3 => $file)), '', 'error'); return; } else { require_once $file; } } catch (CRM_Extension_Exception $e) { CRM_Core_Session::setStatus(ts('Failed to determine file path for payment processor (%1) while running "%2"', array(1 => $info->key, 2 => $method)), '', 'error'); return; } // See if we have any instances of this PP defined .. if ($processor_id = CRM_Core_DAO::singleValueQuery("\n SELECT pp.id\n FROM civicrm_extension ext\n INNER JOIN civicrm_payment_processor_type ppt\n ON ext.name = ppt.name\n INNER JOIN civicrm_payment_processor pp\n ON ppt.id = pp.payment_processor_type_id\n WHERE ext.type = 'payment'\n AND ext.full_name = %1\n ", array(1 => array($info->key, 'String')))) { // If so, load params in the usual way .. $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($processor_id, NULL); } else { // Otherwise, do the best we can to construct some .. $dao = CRM_Core_DAO::executeQuery("\n SELECT ppt.*\n FROM civicrm_extension ext\n INNER JOIN civicrm_payment_processor_type ppt\n ON ppt.name = ext.name\n WHERE ext.name = %1\n AND ext.type = 'payment'\n ", array(1 => array($info->name, 'String'))); if ($dao->fetch()) { $paymentProcessor = array('id' => -1, 'name' => $dao->title, 'payment_processor_type_id' => $dao->id, 'user_name' => 'nothing', 'password' => 'nothing', 'signature' => '', 'url_site' => $dao->url_site_default, 'url_api' => $dao->url_api_default, 'url_recur' => $dao->url_recur_default, 'url_button' => $dao->url_button_default, 'subject' => '', 'class_name' => $dao->class_name, 'is_recur' => $dao->is_recur, 'billing_mode' => $dao->billing_mode, 'payment_type' => $dao->payment_type); } else { CRM_Core_Error::fatal("Unable to find payment processor in " . __CLASS__ . '::' . __METHOD__); } } // In the case of uninstall, check for instances of PP first. // Don't run hook if any are found. if ($method == 'uninstall' && $paymentProcessor['id'] > 0) { return; } switch ($method) { case 'install': case 'uninstall': case 'enable': case 'disable': // Instantiate PP $processorInstance = $paymentClass::singleton(NULL, $paymentProcessor); // Does PP implement this method, and can we call it? if (method_exists($processorInstance, $method) && is_callable(array($processorInstance, $method))) { // If so, call it ... $processorInstance->{$method}(); } break; default: CRM_Core_Session::setStatus(ts("Unrecognized payment hook (%1) in %2::%3", array(1 => $method, 2 => __CLASS__, 3 => __METHOD__)), '', 'error'); } }
/** * Run hooks in the payment processor class. * Load requested payment processor and call the method specified. * * @param CRM_Extension_Info $info * @param string $method * The method to call in the payment processor class. */ private function _runPaymentHook(CRM_Extension_Info $info, $method) { // Not concerned about performance at this stage, as these are seldom performed tasks // (payment processor enable/disable/install/uninstall). May wish to implement some // kind of registry/caching system if more hooks are added. try { $paymentClass = $this->mapper->keyToClass($info->key, 'payment'); $file = $this->mapper->classToPath($paymentClass); if (!file_exists($file)) { CRM_Core_Session::setStatus(ts('Failed to load file (%3) for payment processor (%1) while running "%2"', array(1 => $info->key, 2 => $method, 3 => $file)), '', 'error'); return; } else { require_once $file; } } catch (CRM_Extension_Exception $e) { CRM_Core_Session::setStatus(ts('Failed to determine file path for payment processor (%1) while running "%2"', array(1 => $info->key, 2 => $method)), '', 'error'); return; } $processorDAO = CRM_Core_DAO::executeQuery(" SELECT pp.id, ppt.class_name\n FROM civicrm_extension ext\n INNER JOIN civicrm_payment_processor_type ppt\n ON ext.name = ppt.name\n LEFT JOIN civicrm_payment_processor pp\n ON ppt.id = pp.payment_processor_type_id\n WHERE ext.type = 'payment'\n AND ext.full_name = %1\n ", array(1 => array($info->key, 'String'))); while ($processorDAO->fetch()) { $class_name = $processorDAO->class_name; $processor_id = $processorDAO->id; } if (empty($class_name)) { CRM_Core_Error::fatal("Unable to find payment processor in " . __CLASS__ . '::' . __METHOD__); } // In the case of uninstall, check for instances of PP first. // Don't run hook if any are found. if ($method == 'uninstall' && $processor_id > 0) { return; } switch ($method) { case 'install': case 'uninstall': case 'enable': case 'disable': // Instantiate PP - the getClass function allows us to do this when no payment processor instances exist. $processorInstance = Civi\Payment\System::singleton()->getByClass($class_name); // Does PP implement this method, and can we call it? if (method_exists($processorInstance, $method) && is_callable(array($processorInstance, $method))) { // If so, call it ... $processorInstance->{$method}(); } break; default: CRM_Core_Session::setStatus(ts("Unrecognized payment hook (%1) in %2::%3", array(1 => $method, 2 => __CLASS__, 3 => __METHOD__)), '', 'error'); } }