/** * takes an associative array and creates a contribution object * * the function extract all the params it needs to initialize the create a * contribution object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * * @return object CRM_Contribute_BAO_Contribution object * @access public * @static */ function add(&$params, &$ids) { require_once 'CRM/Utils/Hook.php'; $duplicates = array(); if (CRM_Contribute_BAO_Contribution::checkDuplicate($params, $duplicates)) { $error =& CRM_Core_Error::singleton(); $d = implode(', ', $duplicates); $error->push(CRM_CORE_ERROR_DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Found matching contribution(s): {$d}"); return $error; } if (CRM_Utils_Array::value('contribution', $ids)) { CRM_Utils_Hook::pre('edit', 'Contribution', $ids['contribution'], $params); } else { CRM_Utils_Hook::pre('create', 'Contribution', null, $params); } $contribution =& new CRM_Contribute_BAO_Contribution(); $contribution->copyValues($params); $contribution->domain_id = CRM_Utils_Array::value('domain', $ids, CRM_Core_Config::domainID()); $contribution->id = CRM_Utils_Array::value('contribution', $ids); require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::currencyCode($contribution->currency)) { require_once 'CRM/Core/Config.php'; $config =& CRM_Core_Config::singleton(); $contribution->currency = $config->defaultCurrency; } $result = $contribution->save(); if (CRM_Utils_Array::value('contribution', $ids)) { CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution); } else { CRM_Utils_Hook::post('create', 'Contribution', $contribution->id, $contribution); } return $result; }
protected static function rules($params, $files, $self) { $errors = array(); $secondaryContactId = CRM_Utils_Array::value('secondary_contact_id', $params); $sendConfirmation = CRM_Utils_Array::value('send_confirmation', $params); if ($sendConfirmation) { $emailTo = CRM_Utils_Array::value('email_to', $params); if (!$emailTo) { $errors['email_to'] = ts('Please select a contact(s) to send email to.'); } if (!$self->_id) { if ($emailTo == 2 && !$secondaryContactId || $emailTo == 3 && !$secondaryContactId) { $errors['email_to'] = ts('Please select a secondary contact.'); } } $fromEmailAddreess = CRM_Utils_Array::value('from_email_address', $params); if (!$fromEmailAddreess) { $errors['from_email_address'] = ts('Please select a from email address.'); } } $recordContribution = CRM_Utils_Array::value('record_contribution', $params); if ($recordContribution) { $selectPaymentContact = CRM_Utils_Array::value('select_payment_contact', $params); if (!$selectPaymentContact) { $errors['select_payment_contact'] = ts('Please select a contact for recording payment.'); } if (!$self->_id) { if ($selectPaymentContact == 2 && !$secondaryContactId) { $errors['select_payment_contact'] = ts('Please select a contact for recording payment'); } } $financialTypeId = CRM_Utils_Array::value('financial_type_id', $params); if (!$financialTypeId) { $errors['financial_type_id'] = ts('Please select a financial type.'); } $trxnId = CRM_Utils_Array::value('trxn_id', $params); $duplicates = array(); if ($trxnId && CRM_Contribute_BAO_Contribution::checkDuplicate(array('trxn_id' => $trxnId), $duplicates)) { $d = implode(', ', $duplicates); $errors['trxn_id'] = "Duplicate error - existing contribution record(s) have a matching Transaction ID. Contribution record ID is: {$d}"; } $receivedDate = CRM_Utils_Array::value('receive_date', $params); if (!$receivedDate) { $errors['receive_date'] = ts('This field is required.'); } $paymentInstrumentId = CRM_Utils_Array::value('payment_instrument_id', $params); if (!$paymentInstrumentId) { $errors['payment_instrument_id'] = ts('Please select a payment instrument.'); } $contributionStatusId = CRM_Utils_Array::value('contribution_status_id', $params); if (!$contributionStatusId) { $errors['contribution_status_id'] = ts('Please select a valid payment status.'); } } return $errors; }
function &_crm_duplicate_formatted_contribution(&$params) { require_once 'CRM/Contribute/BAO/Contribution.php'; return CRM_Contribute_BAO_Contribution::checkDuplicate($params, $duplicate); }
/** * Check if there is a contribution with the same trxn_id or invoice_id * * @param array $params Associative array of property name/value * pairs to insert in new contribution. * * @return array|CRM_Error * @access private */ function _civicrm_contribute_duplicate_check(&$params) { require_once 'CRM/Contribute/BAO/Contribution.php'; $duplicates = array(); $result = CRM_Contribute_BAO_Contribution::checkDuplicate($params, $duplicates); if ($result) { $d = implode(', ', $duplicates); $error = CRM_Core_Error::createError("Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: {$d}", CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', $d); return civicrm_create_error($error->pop(), $d); } else { return array(); } }