$capabilities[] = 'LiveMode';
}
$processors = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors($capabilities);
- foreach ($processors as $id => $processor) {
- if ($processor['is_default']) {
- $defaultID = $id;
- }
- $validProcessors[$id] = ts($processor['name']);
- }
- if (empty($validProcessors)) {
- throw new CRM_Core_Exception(ts('You will need to configure the %1 settings for your Payment Processor before you can submit a credit card transactions.', array(1 => $this->_mode)));
- }
- else {
- return array($validProcessors, $processors[$defaultID]['object']);
- }
+ return $processors;
+
}
/**
* Assign billing type id to bltID
*
+ * @throws CRM_Core_Exception
* @return void
*/
public function assignBillingType() {
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
$this->_bltID = array_search('Billing', $locationTypes);
if (!$this->_bltID) {
- CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
+ throw new CRM_Core_Exception(ts('Please set a location type of %1', array(1 => 'Billing')));
}
$this->set('bltID', $this->_bltID);
$this->assign('bltID', $this->_bltID);
public function assignProcessors() {
//ensure that processor has a valid config
//only valid processors get display to user
+
if ($this->_mode) {
$this->assign(CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting(array('supportsFutureRecurStartDate')), TRUE);
- list($this->_processors, $paymentProcessor) = $this->getValidProcessors();
-
+ $processors = $this->getValidProcessors();
+ if (empty($processors)) {
+ throw new CRM_Core_Exception(ts('You will need to configure the %1 settings for your Payment Processor before you can submit a credit card transactions.', array(1 => $this->_mode)));
+ }
+ $this->_processors = array();
+ foreach ($processors as $id => $processor) {
+ $this->_processors[$id] = ts($processor['name']);
+ }
//get the valid recurring processors.
$recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
$this->_recurPaymentProcessors = array_intersect_assoc($this->_processors, $recurring);
// this required to show billing block
// @todo remove this assignment the billing block is now designed to be always included but will not show fieldsets unless those sets of fields are assigned
- $this->assign_by_ref('paymentProcessor', $paymentProcessor);
+ $this->assign_by_ref('paymentProcessor', $processor);
}
/**
CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
}
+ //@todo - if anyone ever figures out what this cdtype subroutine is about (or even if it still applies) please add comments
$this->_cdType = CRM_Utils_Array::value('type', $_GET);
-
$this->assign('cdType', FALSE);
if ($this->_cdType) {
$this->assign('cdType', TRUE);
$this->assign('showCheckNumber', TRUE);
$this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
- $this->assignProcessors();
-
- if ($this->_contactID) {
- list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
- $this->assign('displayName', $this->userDisplayName);
- }
-
- // also check for billing information
- // get the billing location type
- $this->assignBillingType();
-
- $this->_fields = array();
+ try {
+ $this->assignProcessors();
+ if ($this->_contactID) {
+ list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
+ $this->assign('displayName', $this->userDisplayName);
+ }
- CRM_Core_Payment_Form::setPaymentFieldsByType(CRM_Utils_Array::value('payment_type', $this->_processors), $this);
+ $this->assignBillingType();
+ $this->_fields = array();
+ CRM_Core_Payment_Form::setPaymentFieldsByType(CRM_Utils_Array::value('payment_type', $this->_processors), $this);
+ }
+ catch (CRM_Core_Exception $e) {
+ CRM_Core_Error::fatal($e->getMessage());
+ }
if ($this->_action & CRM_Core_Action::DELETE) {
return;
}
* @return bool
*/
static function isEnabledBackOfficeCreditCardPayments() {
- return CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting('BackOffice');
+ return CRM_Financial_BAO_PaymentProcessor::hasPaymentProcessorSupporting(array('BackOffice'));
}
}
return isset($this->$name) ? $this->$name : NULL;
}
+ /**
+ * get array of fields that should be displayed on the payment form
+ * @todo make payment type an option value & use it in the function name - currently on debit & credit card work
+ * @return array
+ * @throws CiviCRM_API3_Exception
+ */
+ public function getPaymentFormFields() {
+ if ($this->_paymentProcessor['payment_type'] == 4) {
+ return array();
+ }
+ return $this->_paymentProcessor['payment_type'] == 1 ? $this->getCreditCardFormFields() : $this->getDirectDebitFormFields();
+ }
+
+ /**
+ * get array of fields that should be displayed on the payment form for credit cards
+ * @return array
+ */
+ protected function getCreditCardFormFields() {
+ return array(
+ 'credit_card_type',
+ 'credit_card_number',
+ 'cvv2',
+ 'credit_card_exp_date',
+ );
+ }
+
+ /**
+ * get array of fields that should be displayed on the payment form for direct debits
+ * @return array
+ */
+ protected function getDirectDebitFormFields() {
+ return array(
+ 'account_holder',
+ 'bank_account_number',
+ 'bank_identification_number',
+ 'bank_name',
+ );
+ }
+
+
/**
* This function collects all the information from a web/api form and invokes
* the relevant payment processor specific functions to perform the transaction
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('paymentTypeName', 'credit_card');
$smarty->assign('paymentTypeLabel', ts('Credit Card Information'));
- $smarty->assign('paymentFields', array(
- 'credit_card_type',
- 'credit_card_number',
- 'cvv2',
- 'credit_card_exp_date',
- ));
+ $smarty->assign('paymentFields', self::getPaymentFields($form->_paymentProcessor));
}
/**
// replace these payment type names with an option group - moving name & label assumptions out of the tpl is a step towards that
$smarty->assign('paymentTypeName', 'direct_debit');
$smarty->assign('paymentTypeLabel', ts('Direct Debit Information'));
- $smarty->assign('paymentFields', array(
- 'account_holder',
- 'bank_account_number',
- 'bank_identification_number',
- 'bank_name',
- ));
+ $smarty->assign('paymentFields', self::getPaymentFields($form->_paymentProcessor));
+ }
+
+ /**
+ * @param array $paymentProcessor
+ * @todo it may be necessary to set details that affect it - mostly likely take Country as a param
+ *
+ * @return mixed
+ */
+ static function getPaymentFields($paymentProcessor) {
+ return array();
+ $paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
+ return $paymentProcessorObject->getPaymentFields();
+ }
+
+ /**
+ * @param $form
+ *
+ * @param array $paymentProcessor
+ * @todo it may be necessary to set details that affect it - mostly likely take Country as a param
+ *
+ * @return mixed
+ */
+ protected static function setPaymentFields(&$form, $paymentProcessor) {
+ $fields = self::getPaymentFields($paymentProcessor);
+
+ }
+
+ static function buildPaymentForm(&$form, $useRequired = FALSE) {
+
}
/**