+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016 |
+ | Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2016
+ * @copyright CiviCRM LLC (c) 2004-2017
*/
/**
protected $_ppDAO;
+ /**
+ * Get the name of the base entity being edited.
+ *
+ * @return string
+ */
+ public function getDefaultEntity() {
+ return 'PaymentProcessor';
+ }
+
public function preProcess() {
- if (!CRM_Core_Permission::check('administer payment processors')) {
- CRM_Core_Error::statusBounce('The \'administer payment processors\' permission is required to add or edit a payment processor.');
- }
parent::preProcess();
- CRM_Utils_System::setTitle(ts('Settings - Payment Processor'));
-
- // get the payment processor meta information
-
if ($this->_id) {
$this->_ppType = CRM_Utils_Request::retrieve('pp', 'String', $this, FALSE, NULL);
if (!$this->_ppType) {
$this->_ppDAO = new CRM_Financial_DAO_PaymentProcessorType();
$this->_ppDAO->id = $this->_ppType;
- if (!$this->_ppDAO->find(TRUE)) {
- CRM_Core_Error::fatal(ts('Could not find payment processor meta information'));
- }
+ $this->_ppDAO->find(TRUE);
if ($this->_id) {
$refreshURL = CRM_Utils_System::url('civicrm/admin/paymentProcessor',
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
'CRM_Financial_DAO_PaymentProcessor',
$this->_id,
+ 'name',
+ CRM_Core_Config::domainID(),
));
$this->add('text', 'description', ts('Description'),
// is this processor active ?
$this->add('checkbox', 'is_active', ts('Is this Payment Processor active?'));
$this->add('checkbox', 'is_default', ts('Is this Payment Processor the default?'));
-
+ $creditCardTypes = CRM_Contribute_PseudoConstant::creditCard();
+ $this->addCheckBox('accept_credit_cards', ts('Accepted Credit Card Type(s)'),
+ $creditCardTypes, NULL, NULL, NULL, NULL, ' ');
foreach ($this->_fields as $field) {
if (empty($field['label'])) {
continue;
}
- $this->add('text', $field['name'],
- $field['label'], $attributes[$field['name']]
- );
- $this->add('text', "test_{$field['name']}",
+ $this->addField($field['name'], array('label' => $field['label']));
+
+ $fieldSpec = civicrm_api3($this->getDefaultEntity(), 'getfield', array(
+ 'name' => $field['name'],
+ 'action' => 'create',
+ ));
+ $this->add($fieldSpec['values']['html']['type'], "test_{$field['name']}",
$field['label'], $attributes[$field['name']]
);
if (!empty($field['rule'])) {
if ($this->_ppType) {
$defaults['payment_processor_type_id'] = $this->_ppType;
}
-
+ $cards = json_decode(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor',
+ $this->_id,
+ 'accepted_credit_cards'
+ ), TRUE);
+ $acceptedCards = array();
+ if (!empty($cards)) {
+ foreach ($cards as $card => $val) {
+ $acceptedCards[$card] = 1;
+ }
+ }
+ $defaults['accept_credit_cards'] = $acceptedCards;
+ unset($defaults['accepted_credit_cards']);
// now get testID
$testDAO = new CRM_Financial_DAO_PaymentProcessor();
$testDAO->name = $dao->name;
if (!empty($values['is_default'])) {
$query = "UPDATE civicrm_payment_processor SET is_default = 0 WHERE domain_id = $domainID";
- CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
+ CRM_Core_DAO::executeQuery($query);
}
$this->updatePaymentProcessor($values, $domainID, FALSE);
*/
public function updatePaymentProcessor(&$values, $domainID, $test) {
if ($test) {
- foreach (array('user_name', 'password', 'signature') as $field) {
+ foreach (array('user_name', 'password', 'signature', 'url_site', 'url_recur', 'url_api', 'url_button', 'subject') as $field) {
$values[$field] = empty($values["test_{$field}"]) ? CRM_Utils_Array::value($field, $values) : $values["test_{$field}"];
}
}
+ if (!empty($values['accept_credit_cards'])) {
+ $creditCards = array();
+ $accptedCards = array_keys($values['accept_credit_cards']);
+ $creditCardTypes = CRM_Contribute_PseudoConstant::creditCard();
+ foreach ($creditCardTypes as $type => $val) {
+ if (in_array($type, $accptedCards)) {
+ $creditCards[$type] = $creditCardTypes[$type];
+ }
+ }
+ $creditCards = json_encode($creditCards);
+ }
+ else {
+ $creditCards = "NULL";
+ }
$params = array_merge(array(
'id' => $test ? $this->_testID : $this->_id,
'domain_id' => $domainID,
'payment_type' => $this->_ppDAO->payment_type,
'payment_instrument_id' => $this->_ppDAO->payment_instrument_id,
'financial_account_id' => $values['financial_account_id'],
+ 'accepted_credit_cards' => $creditCards,
), $values);
civicrm_api3('PaymentProcessor', 'create', $params);