*/
protected $_paymentProcessors = [];
- /**
- * Instance of the payment processor object.
- *
- * @var CRM_Core_Payment
- */
- protected $_paymentObject;
-
/**
* Entity that $this->_id relates to.
*
class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditPayment {
use CRM_Contact_Form_ContactFormTrait;
use CRM_Contribute_Form_ContributeFormTrait;
+ use CRM_Financial_Form_PaymentProcessorFormTrait;
/**
* The id of the contribution that we are processing.
$this->_lineItem = $lineItem;
}
- $this->_paymentObject = Civi\Payment\System::singleton()->getById($submittedValues['payment_processor_id']);
- $this->_paymentProcessor = $this->_paymentObject->getPaymentProcessor();
+ $paymentObject = Civi\Payment\System::singleton()->getById($submittedValues['payment_processor_id']);
+ $this->_paymentProcessor = $paymentObject->getPaymentProcessor();
// Set source if not set
if (empty($submittedValues['source'])) {
$form->assign('is_recur_interval', $form->_values['is_recur_interval'] ?? NULL);
$form->assign('is_recur_installments', $form->_values['is_recur_installments'] ?? NULL);
- $paymentObject = $form->getVar('_paymentObject');
+ $paymentObject = $this->getPaymentProcessorObject();
if ($paymentObject) {
$form->assign('recurringHelpText', $paymentObject->getText('contributionPageRecurringHelp', [
'is_recur_installments' => !empty($form->_values['is_recur_installments']),
$form->assign('is_recur_interval', $this->getContributionPageValue('is_recur_interval'));
$form->assign('is_recur_installments', $this->getContributionPageValue('is_recur_installments'));
- $paymentObject = $form->getVar('_paymentObject');
+ $paymentObject = $this->_paymentProcessor['object'];
if ($paymentObject) {
$form->assign('recurringHelpText', $paymentObject->getText('contributionPageRecurringHelp', [
'is_recur_installments' => !empty($form->_values['is_recur_installments']),
class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
use CRM_Financial_Form_FrontEndPaymentFormTrait;
use CRM_Contribute_Form_ContributeFormTrait;
+ use CRM_Financial_Form_PaymentProcessorFormTrait;
/**
* The id of the contribution page that we are processing.
*/
public $_paymentProcessor;
- public $_paymentObject = NULL;
-
/**
* Order object, used to calculate amounts, line items etc.
*
// The concept of contributeMode is deprecated.
// The payment processor object can provide info about the fields it shows.
- if ($isMonetary && $this->_paymentProcessor['object'] instanceof \CRM_Core_Payment) {
- $paymentProcessorObject = $this->_paymentProcessor['object'];
+ if ($isMonetary) {
+ $paymentProcessorObject = $this->getPaymentProcessorObject();
$this->assign('paymentAgreementTitle', $paymentProcessorObject->getText('agreementTitle', []));
$this->assign('paymentAgreementText', $paymentProcessorObject->getText('agreementText', []));
$paymentFields = $paymentProcessorObject->getPaymentFormFields();
}
}
- /**
- * Get the payment processor object for the submission, returning the manual one for offline payments.
- *
- * @return CRM_Core_Payment
- */
- protected function getPaymentProcessorObject() {
- if (!empty($this->_paymentProcessor)) {
- return $this->_paymentProcessor['object'];
- }
- return new CRM_Core_Payment_Manual();
- }
-
/**
* Get the amount for the main contribution.
*
) {
$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.
return;
}
$form->set('paymentProcessor', $form->_paymentProcessor);
- $form->_paymentObject = System::singleton()->getByProcessor($form->_paymentProcessor);
+ $paymentObject = System::singleton()->getByProcessor($form->_paymentProcessor);
if ($form->paymentInstrumentID) {
- $form->_paymentObject->setPaymentInstrumentID($form->paymentInstrumentID);
+ $paymentObject->setPaymentInstrumentID($form->paymentInstrumentID);
}
- $form->_paymentObject->setBackOffice($form->isBackOffice);
+ $paymentObject->setBackOffice($form->isBackOffice);
$form->assign('isBackOffice', $form->isBackOffice);
- $form->assign('suppressSubmitButton', $form->_paymentObject->isSuppressSubmitButtons());
+ $form->assign('suppressSubmitButton', $paymentObject->isSuppressSubmitButtons());
CRM_Financial_Form_Payment::addCreditCardJs($form->getPaymentProcessorID());
$form->assign('paymentProcessorID', $form->getPaymentProcessorID());
// also set cancel subscription url
if (!empty($form->_paymentProcessor['is_recur']) && !empty($form->_values['is_recur'])) {
- $form->_values['cancelSubscriptionUrl'] = $form->_paymentObject->subscriptionURL(NULL, NULL, 'cancel');
+ $form->_values['cancelSubscriptionUrl'] = $paymentObject->subscriptionURL(NULL, NULL, 'cancel');
}
$paymentProcessorBillingFields = array_keys($form->_paymentProcessor['object']->getBillingAddressFields());
if (!empty($form->_membershipBlock) && !empty($form->_membershipBlock['is_separate_payment']) &&
(!empty($form->_paymentProcessor['class_name']) &&
- !$form->_paymentObject->supports('MultipleConcurrentPayments')
+ !$paymentObject->supports('MultipleConcurrentPayments')
)
) {
* This class generates form components for processing Event.
*/
class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
+ use CRM_Financial_Form_PaymentProcessorFormTrait;
/**
* The fields involved in this page.
--- /dev/null
+<?php
+
+/**
+ * Trait implements functions to retrieve payment processor related values.
+ *
+ * Note that any functions on this class that are supported to be used from
+ * outside of core are specifically tagged.
+ */
+trait CRM_Financial_Form_PaymentProcessorFormTrait {
+
+ /**
+ * Get the payment processors that are available on the form.
+ *
+ * @return array
+ * @throws \CRM_Core_Exception
+ */
+ protected function getAvailablePaymentProcessors(): array {
+ return CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors([ucfirst($this->getPaymentProcessorMode()) . 'Mode'], $this->getAvailablePaymentProcessorIDS());
+ }
+
+ /**
+ * Get the payment processor IDs available on the form.
+ *
+ * @return false|array
+ */
+ protected function getAvailablePaymentProcessorIDS() {
+ return FALSE;
+ }
+
+ /**
+ * Get the mode (test or live) of the payment processor.
+ *
+ * @api This function will not change in a minor release and is supported for
+ * use outside of core. This annotation / external support for properties
+ * is only given where there is specific test cover.
+ *
+ * @return string|null
+ * test or live
+ * @throws \CRM_Core_Exception
+ */
+ public function getPaymentProcessorMode(): ?string {
+ return CRM_Utils_Request::retrieve('mode', 'Alphanumeric', $this);
+ }
+
+ /**
+ * Get the payment processor object for the submission, returning the manual one for offline payments.
+ *
+ * @return CRM_Core_Payment
+ */
+ protected function getPaymentProcessorObject() {
+ if (!empty($this->_paymentProcessor)) {
+ return $this->_paymentProcessor['object'];
+ }
+ return new CRM_Core_Payment_Manual();
+ }
+
+}
) {
$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.