$params['invoiceID'] = $invoiceID;
$params['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']);
- $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
+ $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
$token = $payment->setExpressCheckout($params);
if (is_a($token, 'CRM_Core_Error')) {
CRM_Core_Error::displaySessionError($token);
* @var array
*/
public $_paymentProcessor;
+
public $_paymentObject = NULL;
/**
$isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values);
$isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values);
- //FIXME: to support multiple payment processors
if ($isMonetary &&
(!$isPayLater || !empty($this->_values['payment_processor']))
) {
- $ppID = CRM_Utils_Array::value('payment_processor', $this->_values);
- if (!$ppID) {
- CRM_Core_Error::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).'));
- }
-
- $paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID);
-
- $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($paymentProcessorIDs, $this->_mode);
-
- $this->set('paymentProcessors', $this->_paymentProcessors);
-
- if (!empty($this->_paymentProcessors)) {
- foreach ($this->_paymentProcessors as $paymentProcessorID => $paymentProcessorDetail) {
- if (($processor = Civi\Payment\System::singleton()->getByProcessor($paymentProcessorDetail)) != FALSE) {
- // We don't really know why we do this.
- $this->_paymentObject = $processor;
- }
+ $this->_paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value
+ ('payment_processor', $this->_values)
+ );
- if (empty($this->_paymentProcessor) && $paymentProcessorDetail['is_default'] == 1 || (count($this->_paymentProcessors) == 1)
- ) {
- $this->_paymentProcessor = $paymentProcessorDetail;
- $this->assign('paymentProcessor', $this->_paymentProcessor);
- }
- }
- if (empty($this->_paymentObject)) {
- throw new CRM_Core_Exception(ts('No valid payment processor'));
- }
- }
- else {
- throw new CRM_Core_Exception(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
- }
+ $this->assignPaymentProcessor();
}
// get price info
*/
protected $_action;
+ /**
+ * Available payment processors.
+ *
+ * As part of trying to consolidate various payment pages we store processors here & have functions
+ * at this level to manage them.
+ *
+ * @var array
+ * An array of payment processor details with objects loaded in the 'object' field.
+ */
+ public $_paymentProcessors;
+
+ /**
+ * Available payment processors (IDS).
+ *
+ * As part of trying to consolidate various payment pages we store processors here & have functions
+ * at this level to manage them.
+ *
+ * @var array
+ * An array of the IDS available on this form.
+ */
+ public $_paymentProcessorIDs;
+
/**
* The renderer used for this form
*
$this->assign('bltID', $this->_bltID);
}
+ /**
+ * This if a front end form function for setting the payment processor.
+ *
+ * It would be good to sync it with the back-end function on abstractEditPayment & use one everywhere.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ protected function assignPaymentProcessor() {
+ $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors(
+ array(ucfirst($this->_mode) . 'Mode'),
+ $this->_paymentProcessorIDs
+ );
+
+ if (!empty($this->_paymentProcessors)) {
+ foreach ($this->_paymentProcessors as $paymentProcessorID => $paymentProcessorDetail) {
+ if (empty($this->_paymentProcessor) && $paymentProcessorDetail['is_default'] == 1 || (count($this->_paymentProcessors) == 1)
+ ) {
+ $this->_paymentProcessor = $paymentProcessorDetail;
+ $this->assign('paymentProcessor', $this->_paymentProcessor);
+ // Setting this is a bit of a legacy overhang.
+ $this->_paymentObject = $paymentProcessorDetail['object'];
+ }
+ }
+ // It's not clear why we set this on the form.
+ $this->set('paymentProcessors', $this->_paymentProcessors);
+ }
+ else {
+ throw new CRM_Core_Exception(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).'));
+ }
+ }
+
+
/**
* Setter function for options.
*
$this->_processorName = ts('PayPal Express');
}
- if (!$this->_paymentProcessor['user_name']) {
- CRM_Core_Error::fatal(ts('Could not find user name for payment processor'));
- }
}
/**
public function checkConfig() {
$error = array();
$paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(FALSE, NULL, 'name');
- if (
- $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('PayPal_Standard', $paymentProcessorType) ||
- $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('PayPal', $paymentProcessorType)
- ) {
- if (empty($this->_paymentProcessor['user_name'])) {
- $error[] = ts('User Name is not set in the Administer » System Settings » Payment Processors.');
- }
- }
if ($this->_paymentProcessor['payment_processor_type_id'] != CRM_Utils_Array::key('PayPal_Standard', $paymentProcessorType)) {
if (empty($this->_paymentProcessor['signature'])) {
$error[] = ts('Password is not set in the Administer » System Settings » Payment Processors.');
}
}
+ if (!$this->_paymentProcessor['user_name']) {
+ $error[] = ts('User Name is not set in the Administer » System Settings » Payment Processors.');
+ }
if (!empty($error)) {
return implode('<p>', $error);
}
/**
+ * User getPaymentProcessors.
+ *
+ * @deprecated
+ *
* @param $paymentProcessorIDs
* @param $mode
*
}
$processors = self::getAllPaymentProcessors($mode);
- if ($capabilities) {
- foreach ($processors as $index => $processor) {
- if (!empty($ids) && !in_array($processor['id'], $ids)) {
- unset ($processors[$index]);
- continue;
- }
- // Invalid processors will store a null value in 'object' (e.g. if not all required config fields are present).
- // This is determined by calling when loading the processor via the $processorObject->checkConfig() function.
- if (!is_a($processor['object'], 'CRM_Core_Payment')) {
+ foreach ($processors as $index => $processor) {
+ if (!empty($ids) && !in_array($processor['id'], $ids)) {
+ unset ($processors[$index]);
+ continue;
+ }
+ // Invalid processors will store a null value in 'object' (e.g. if not all required config fields are present).
+ // This is determined by calling when loading the processor via the $processorObject->checkConfig() function.
+ if (!is_a($processor['object'], 'CRM_Core_Payment')) {
+ unset ($processors[$index]);
+ continue;
+ }
+ foreach ($capabilities as $capability) {
+ if (($processor['object']->supports($capability)) == FALSE) {
unset ($processors[$index]);
- continue;
- }
- foreach ($capabilities as $capability) {
- if (($processor['object']->supports($capability)) == FALSE) {
- unset ($processors[$index]);
- }
+ continue 1;
}
}
}
+
return $processors;
}
/**
* @param int $id
+ *
+ * @return \Civi\Payment\CRM_Core_Payment|NULL
* @throws \CiviCRM_API3_Exception
*/
public function getById($id) {
/**
* @param string $name
* @param bool $is_test
+ *
+ * @return \Civi\Payment\CRM_Core_Payment|NULL
* @throws \CiviCRM_API3_Exception
*/
public function getByName($name, $is_test) {