X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FPayment.php;h=56249840903185d4f2f806e43a08b0e0daa56e21;hb=5da97e99f4ee7507cb2f4f91177c021229b6010e;hp=64ef5c59f1521a8d15ebffda051eac1f87e9b60b;hpb=49d5eaa5f3ff9f843c8ba4cc2383426ea58e7aec;p=civicrm-core.git diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 64ef5c59f1..5624984090 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1,7 +1,7 @@ @$_GET['processor_name'], + 'processor_id' => @$_GET['processor_id'], 'mode' => @$_GET['mode'], ) ); } /** - * Payment callback handler + * Payment callback handler. The processor_name or processor_id is passed in. + * Note that processor_id is more reliable as one site may have more than one instance of a + * processor & ideally the processor will be validating the results * Load requested payment processor and call that processor's handle<$method> method * * @public */ static function handlePaymentMethod($method, $params = array( )) { - - if (!isset($params['processor_name'])) { - CRM_Core_Error::fatal("Missing 'processor_name' param for payment callback"); + if (!isset($params['processor_id']) && !isset($params['processor_name'])) { + CRM_Core_Error::fatal("Either 'processor_id' or 'processor_name' param is required for payment callback"); } // Query db for processor .. $mode = @$params['mode']; - $dao = CRM_Core_DAO::executeQuery(" - SELECT ppt.class_name, ppt.name as processor_name, pp.id AS processor_id - FROM civicrm_payment_processor_type ppt - INNER JOIN civicrm_payment_processor pp - ON pp.payment_processor_type_id = ppt.id - AND pp.is_active - AND pp.is_test = %1 - WHERE ppt.name = %2 - ", - array( - 1 => array($mode == 'test' ? 1 : 0, 'Integer'), - 2 => array($params['processor_name'], 'String'), - ) - ); + $sql = "SELECT ppt.class_name, ppt.name as processor_name, pp.id AS processor_id + FROM civicrm_payment_processor_type ppt + INNER JOIN civicrm_payment_processor pp + ON pp.payment_processor_type_id = ppt.id + AND pp.is_active + AND pp.is_test = %1"; + $args[1] = array($mode == 'test' ? 1 : 0, 'Integer'); + + if (isset($params['processor_id'])) { + $sql .= " WHERE pp.id = %2"; + $args[2] = array($params['processor_id'], 'Integer'); + $notfound = "No active instances of payment processor ID#'{$params['processor_id']}' were found."; + } + else { + $sql .= " WHERE ppt.name = %2"; + $args[2] = array($params['processor_name'], 'String'); + $notfound = "No active instances of the '{$params['processor_name']}' payment processor were found."; + } + + $dao = CRM_Core_DAO::executeQuery($sql, $args); // Check whether we found anything at all .. if (!$dao->N) { - CRM_Core_Error::fatal("No active instances of the '{$params['processor_name']}' payment processor were found."); + CRM_Core_Error::fatal($notfound); } $method = 'handle' . $method; @@ -247,15 +255,12 @@ abstract class CRM_Core_Payment { // Check pp is extension $ext = CRM_Extension_System::singleton()->getMapper(); if ($ext->isExtensionKey($dao->class_name)) { - $extension_instance_found = TRUE; $paymentClass = $ext->keyToClass($dao->class_name, 'payment'); require_once $ext->classToPath($paymentClass); } else { - // Legacy instance - but there may also be an extension instance, so - // continue on to the next instance and check that one. We'll raise an - // error later on if none are found. - continue; + // Legacy or extension as module instance + $paymentClass = 'CRM_Core_' . $dao->class_name; } $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($dao->processor_id, $mode); @@ -272,13 +277,14 @@ abstract class CRM_Core_Payment { if (!method_exists($processorInstance, $method) || !is_callable(array($processorInstance, $method)) ) { - // No? This will be the case in all instances, so let's just die now - // and not prolong the agony. - CRM_Core_Error::fatal("Payment processor does not implement a '$method' method"); + // on the off chance there is a double implementation of this processor we should keep looking for another + // note that passing processor_id is more reliable & we should work to deprecate processor_name + continue; } // Everything, it seems, is ok - execute pp callback handler $processorInstance->$method(); + $extension_instance_found = TRUE; } if (!$extension_instance_found) CRM_Core_Error::fatal( @@ -367,8 +373,9 @@ INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) */ static function allowBackofficeCreditCard($template = NULL, $variableName = 'newCredit') { $newCredit = FALSE; + // restrict to type=1 (credit card) payment processor payment_types and only include billing mode types 1 and 3 $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, - "billing_mode IN ( 1, 3 )" + "billing_mode IN ( 1, 3 ) AND payment_type = 1" ); if (count($processors) > 0) { $newCredit = TRUE; @@ -380,4 +387,3 @@ INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) } } -