<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
* Note that this code is written to accommodate the possibility CiviCRM will switch to implementing pay later as a manual processor in future
*
* @param CRM_Contribute_Form_AbstractEditPayment|CRM_Contribute_Form_Contribution_Main $form
- * @param array $processor array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors
- * @param bool $forceBillingFieldsForPayLater display billing fields even for pay later
+ * @param array $processor
+ * Array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors.
+ * @param bool $forceBillingFieldsForPayLater
+ * Display billing fields even for pay later.
*/
static public function setPaymentFieldsByProcessor(&$form, $processor, $forceBillingFieldsForPayLater = FALSE) {
$form->billingFieldSets = array();
// @todo - replace this section with one similar to above per discussion - probably use a manual processor shell class to stand in for that capability
//return without adding billing fields if billing_mode = 4 (@todo - more the ability to set that to the payment processor)
// or payment processor is NULL (pay later)
- if (($processor == NULL && !$forceBillingFieldsForPayLater) || $processor['billing_mode'] == 4) {
+ if (($processor == NULL && !$forceBillingFieldsForPayLater) || CRM_Utils_Array::value('billing_mode', $processor) == 4) {
return;
}
//@todo setPaymentFields defines the billing fields - this should be moved to the processor class & renamed getBillingFields
}
/**
- * add general billing fields
+ * Add general billing fields
* @todo set these like processor fields & let payment processors alter them
*
- * @param $form
+ * @param CRM_Core_Form $form
*
* @return void
- * @access protected
*/
static protected function setBillingDetailsFields(&$form) {
$bltID = $form->_bltID;
));
}
- /**
- * create all fields needed for a credit card transaction
- * @deprecated - use the setPaymentFieldsByProcessor which leverages the processor to determine the fields
- * @param CRM_Core_Form $form
- *
- * @return void
- * @access public
- */
- static function setCreditCardFields(&$form) {
- CRM_Core_Payment_Form::setBillingDetailsFields($form);
-
- $form->_paymentFields['credit_card_number'] = array(
- 'htmlType' => 'text',
- 'name' => 'credit_card_number',
- 'title' => ts('Card Number'),
- 'cc_field' => TRUE,
- 'attributes' => array('size' => 20, 'maxlength' => 20, 'autocomplete' => 'off'),
- 'is_required' => TRUE,
- );
-
- $form->_paymentFields['cvv2'] = array(
- 'htmlType' => 'text',
- 'name' => 'cvv2',
- 'title' => ts('Security Code'),
- 'cc_field' => TRUE,
- 'attributes' => array('size' => 5, 'maxlength' => 10, 'autocomplete' => 'off'),
- 'is_required' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME,
- 'cvv_backoffice_required',
- NULL
- ,1
- ),
- );
-
- $form->_paymentFields['credit_card_exp_date'] = array(
- 'htmlType' => 'date',
- 'name' => 'credit_card_exp_date',
- 'title' => ts('Expiration Date'),
- 'cc_field' => TRUE,
- 'attributes' => CRM_Core_SelectValues::date('creditCard'),
- 'is_required' => TRUE,
- );
-
- $creditCardType = array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::creditCard();
- $form->_paymentFields['credit_card_type'] = array(
- 'htmlType' => 'select',
- 'name' => 'credit_card_type',
- 'title' => ts('Card Type'),
- 'cc_field' => TRUE,
- 'attributes' => $creditCardType,
- 'is_required' => FALSE,
- );
- //CRM-15509 this is probably a temporary resting place for these form assignments but we are working towards putting this
- // in an option group & having php / payment processors define the billing form rather than the tpl
- $smarty = CRM_Core_Smarty::singleton();
- $smarty->assign('paymentTypeName', 'credit_card');
- $smarty->assign('paymentTypeLabel', ts('Credit Card Information'));
- $smarty->assign('paymentFields', self::getPaymentFields($form->_paymentProcessor));
- }
-
/**
* @param CRM_Core_Form $form
* @param bool $useRequired
}
}
- /**
- * create all fields needed for direct debit transaction
- * @deprecated - use the setPaymentFieldsByProcessor which leverages the processor to determine the fields
- * @param $form
- *
- * @return void
- * @access public
- */
- static function setDirectDebitFields(&$form) {
- CRM_Core_Payment_Form::setBillingDetailsFields($form);
-
- $form->_paymentFields['account_holder'] = array(
- 'htmlType' => 'text',
- 'name' => 'account_holder',
- 'title' => ts('Account Holder'),
- 'cc_field' => TRUE,
- 'attributes' => array('size' => 20, 'maxlength' => 34, 'autocomplete' => 'on'),
- 'is_required' => TRUE,
- );
-
- //e.g. IBAN can have maxlength of 34 digits
- $form->_paymentFields['bank_account_number'] = array(
- 'htmlType' => 'text',
- 'name' => 'bank_account_number',
- 'title' => ts('Bank Account Number'),
- 'cc_field' => TRUE,
- 'attributes' => array('size' => 20, 'maxlength' => 34, 'autocomplete' => 'off'),
- 'is_required' => TRUE,
- );
-
- //e.g. SWIFT-BIC can have maxlength of 11 digits
- $form->_paymentFields['bank_identification_number'] = array(
- 'htmlType' => 'text',
- 'name' => 'bank_identification_number',
- 'title' => ts('Bank Identification Number'),
- 'cc_field' => TRUE,
- 'attributes' => array('size' => 20, 'maxlength' => 11, 'autocomplete' => 'off'),
- 'is_required' => TRUE,
- );
-
- $form->_paymentFields['bank_name'] = array(
- 'htmlType' => 'text',
- 'name' => 'bank_name',
- 'title' => ts('Bank Name'),
- 'cc_field' => TRUE,
- 'attributes' => array('size' => 20, 'maxlength' => 64, 'autocomplete' => 'off'),
- 'is_required' => TRUE,
- );
- //CRM-15509 this is probably a temporary resting place for these form assignments but we are working towards putting this
- // in an option group & having php / payment processors define the billing form rather than the tpl
- $smarty = CRM_Core_Smarty::singleton();
- // 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', self::getPaymentFields($form->_paymentProcessor));
- }
-
/**
* @param array $paymentProcessor
* @todo it will be necessary to set details that affect it - mostly likely take Country as a param. Should we add generic
*
* @return array
*/
- static function getPaymentFields($paymentProcessor) {
+ public static function getPaymentFields($paymentProcessor) {
$paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
return $paymentProcessorObject->getPaymentFormFields();
}
*
* @return array
*/
- static function getPaymentFieldMetadata($paymentProcessor) {
+ public static function getPaymentFieldMetadata($paymentProcessor) {
$paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
return $paymentProcessorObject->getPaymentFormFieldsMetadata();
}
*
* @return string
*/
- static function getPaymentTypeName($paymentProcessor) {
+ public static function getPaymentTypeName($paymentProcessor) {
$paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
return $paymentProcessorObject->getPaymentTypeName();
}
*
* @return string
*/
- static function getPaymentTypeLabel($paymentProcessor) {
+ public static function getPaymentTypeLabel($paymentProcessor) {
$paymentProcessorObject = CRM_Core_Payment::singleton(($paymentProcessor['is_test'] ? 'test' : 'live'), $paymentProcessor);
return ts(($paymentProcessorObject->getPaymentTypeLabel()) . ' Information');
}
/**
- * @param CRM_Contribute_Form_AbstractEditPayment|CRM_Contribute_Form_Contribution_Main|CRM_Core_Payment_ProcessorForm $form
- * @param array $processor array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors
- * @param bool $isBillingDataOptional This manifests for 'NULL' (pay later) payment processor as the addition of billing fields to the form and
+ * @param CRM_Contribute_Form_AbstractEditPayment|CRM_Contribute_Form_Contribution_Main|CRM_Core_Payment_ProcessorForm|CRM_Contribute_Form_UpdateBilling $form
+ * @param array $processor
+ * Array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors.
+ * @param bool $isBillingDataOptional
+ * This manifests for 'NULL' (pay later) payment processor as the addition of billing fields to the form and.
* for payment processors that gather payment data on site as rendering the fields as not being required. (not entirely sure why but this
* is implemented for back office forms)
*
* @return bool
*/
- static function buildPaymentForm($form, $processor, $isBillingDataOptional){
+ public static function buildPaymentForm($form, $processor, $isBillingDataOptional) {
//if the form has address fields assign to the template so the js can decide what billing fields to show
$profileAddressFields = $form->get('profileAddressFields');
if (!empty($profileAddressFields)) {
/**
* @param CRM_Core_Form $form
- * @param array $paymentFields array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors
+ * @param array $paymentFields
+ * Array of properties including 'object' as loaded from CRM_Financial_BAO_PaymentProcessor::getPaymentProcessors.
* @param $paymentFields
*/
}
/**
- * billing mode button is basically synonymous with paypal express - this is probably a good example of 'odds & sods' code we
+ * Billing mode button is basically synonymous with paypal express - this is probably a good example of 'odds & sods' code we
* need to find a way for the payment processor to assign. A tricky aspect is that the payment processor may need to set the order
*
* @param $form
*/
protected static function addPaypalExpressCode(&$form) {
if (empty($form->isBackOffice)) {
- if ($form->_paymentProcessor['billing_mode'] &
- CRM_Core_Payment::BILLING_MODE_BUTTON
+ if (CRM_Utils_Array::value('billing_mode', $form->_paymentProcessor) == 3
) {
$form->_expressButtonName = $form->getButtonName('upload', 'express');
$form->assign('expressButtonName', $form->_expressButtonName);
}
}
}
- /**
- * Function to add all the credit card fields
- * @deprecated Use BuildPaymentForm
- * @param $form
- * @param bool $useRequired
- *
- * @return void
- * @access public
- */
- static function buildCreditCard(&$form, $useRequired = FALSE) {
- if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) {
- self::setCreditCardFields($form);
- self::addCommonFields($form, $useRequired, $form->_paymentFields);
-
- $form->addRule('cvv2',
- ts('Please enter a valid value for your card security code. This is usually the last 3-4 digits on the card\'s signature panel.'),
- 'integer'
- );
-
- $form->addRule('credit_card_exp_date',
- ts('Card expiration date cannot be a past date.'),
- 'currentDate', TRUE
- );
-
- }
-
-
- if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
- $form->_expressButtonName = $form->getButtonName('upload', 'express');
- $form->assign('expressButtonName', $form->_expressButtonName);
- $form->add('image',
- $form->_expressButtonName,
- $form->_paymentProcessor['url_button'],
- array('class' => 'crm-form-submit')
- );
- }
- }
/**
* The credit card pseudo constant results only the CC label, not the key ID
* So we normalize the name to use it as a CSS class.
*/
- static function getCreditCardCSSNames() {
+ public static function getCreditCardCSSNames() {
$creditCardTypes = array();
foreach (CRM_Contribute_PseudoConstant::creditCard() as $key => $name) {
// Replace anything not css-friendly by an underscore
return $creditCardTypes;
}
- /**
- * Function to add all the direct debit fields
- * @deprecated use buildPaymentForm
- *
- * @param $form
- * @param bool $useRequired
- * @return void
- * @access public
- */
- static function buildDirectDebit(&$form, $useRequired = FALSE) {
- if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) {
- self::setDirectDebitFields($form);
- self::addCommonFields($form, $useRequired, $form->_paymentFields);
-
- $form->addRule('bank_identification_number',
- ts('Please enter a valid Bank Identification Number (value must not contain punctuation characters).'),
- 'nopunctuation'
- );
-
- $form->addRule('bank_account_number',
- ts('Please enter a valid Bank Account Number (value must not contain punctuation characters).'),
- 'nopunctuation'
- );
- }
- }
-
/**
* Make sure that credit card number and cvv are valid
* Called within the scope of a QF formRule function
*/
- static function validateCreditCard($values, &$errors) {
+ public static function validateCreditCard($values, &$errors) {
if (!empty($values['credit_card_type'])) {
if (!empty($values['credit_card_number']) &&
!CRM_Utils_Rule::creditCardNumber($values['credit_card_number'], $values['credit_card_type'])
}
/**
- * function to map address fields
+ * Map address fields
*
- * @param $id
+ * @param int $id
* @param $src
* @param $dst
* @param bool $reverse
* @return void
* @static
*/
- static function mapParams($id, &$src, &$dst, $reverse = FALSE) {
+ public static function mapParams($id, &$src, &$dst, $reverse = FALSE) {
static $map = NULL;
if (!$map) {
$map = array(
}
/**
- * function to get the credit card expiration month
+ * Get the credit card expiration month
* The date format for this field should typically be "M Y" (ex: Feb 2011) or "m Y" (02 2011)
* See CRM-9017
*
* @return int
* @static
*/
- static function getCreditCardExpirationMonth($src) {
+ public static function getCreditCardExpirationMonth($src) {
if ($month = CRM_Utils_Array::value('M', $src['credit_card_exp_date'])) {
return $month;
}
}
/**
- * function to get the credit card expiration year
+ * Get the credit card expiration year
* The date format for this field should typically be "M Y" (ex: Feb 2011) or "m Y" (02 2011)
* This function exists only to make it consistent with getCreditCardExpirationMonth
*
* @return int
* @static
*/
- static function getCreditCardExpirationYear($src) {
+ public static function getCreditCardExpirationYear($src) {
return CRM_Utils_Array::value('Y', $src['credit_card_exp_date']);
}
}