X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FContribution.php;h=00aa5ccbdb78f79c026ee22f1c3adb8ad69a59ce;hb=a91cec11302c355761e565df00836fec56cf7ccb;hp=1f393bbaae800ff3673e3b1374b8b5ec57f2d8d6;hpb=3b49385c20114fac86e200e28224bc7c1999e8d5;p=civicrm-core.git diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 1f393bbaae..13b5357f83 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -1,9 +1,9 @@ 'soft_credit_to', 'title' => 'Soft Credit contact ID (legacy)', - 'type' => 1, + 'type' => CRM_Utils_Type::T_INT, 'description' => 'ID of Contact to be Soft credited to (deprecated - use contribution_soft api)', 'FKClassName' => 'CRM_Contact_DAO_Contact', ); $params['honor_contact_id'] = array( 'name' => 'honor_contact_id', 'title' => 'Honoree contact ID (legacy)', - 'type' => 1, + 'type' => CRM_Utils_Type::T_INT, 'description' => 'ID of honoree contact (deprecated - use contribution_soft api)', 'FKClassName' => 'CRM_Contact_DAO_Contact', ); $params['honor_type_id'] = array( 'name' => 'honor_type_id', 'title' => 'Honoree Type (legacy)', - 'type' => 1, + 'type' => CRM_Utils_Type::T_INT, 'description' => 'Type of honoree contact (deprecated - use contribution_soft api)', 'pseudoconstant' => TRUE, ); @@ -140,9 +156,14 @@ function _civicrm_api3_contribution_create_spec(&$params) { ); $params['batch_id'] = array( 'title' => 'Batch', - 'type' => 1, + 'type' => CRM_Utils_Type::T_INT, 'description' => 'Batch which relevant transactions should be added to', ); + $params['refund_trxn_id'] = array( + 'title' => 'Refund Transaction ID', + 'type' => CRM_Utils_Type::T_STRING, + 'description' => 'Transaction ID specific to the refund taking place', + ); } /** @@ -183,6 +204,15 @@ function _civicrm_api3_contribution_create_legacy_support_45(&$params) { function civicrm_api3_contribution_delete($params) { $contributionID = !empty($params['contribution_id']) ? $params['contribution_id'] : $params['id']; + // First check contribution financial type + $financialType = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionID, 'financial_type_id'); + // Now check permissioned lineitems & permissioned contribution + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() + && !CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($financialType)) || + !CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributionID, 'delete', FALSE) + ) { + return civicrm_api3_create_error('You do not have permission to delete this contribution'); + } if (CRM_Contribute_BAO_Contribution::deleteContribution($contributionID)) { return civicrm_api3_create_success(array($contributionID => 1)); } @@ -214,18 +244,29 @@ function _civicrm_api3_contribution_delete_spec(&$params) { function civicrm_api3_contribution_get($params) { $mode = CRM_Contact_BAO_Query::MODE_CONTRIBUTE; - list($dao, $query) = _civicrm_api3_get_query_object($params, $mode, 'Contribution'); - - $contribution = array(); - while ($dao->fetch()) { - //CRM-8662 - $contribution_details = $query->store($dao); - $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($dao->contribution_id, TRUE); - $contribution[$dao->contribution_id] = array_merge($contribution_details, $softContribution); + $returnProperties = CRM_Contribute_BAO_Query::defaultReturnProperties($mode); + + $contributions = _civicrm_api3_get_using_query_object('Contribution', $params, array(), NULL, $mode, $returnProperties); + + foreach ($contributions as $id => $contribution) { + $softContribution = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($id, TRUE); + $contributions[$id] = array_merge($contribution, $softContribution); // format soft credit for backward compatibility - _civicrm_api3_format_soft_credit($contribution[$dao->contribution_id]); + _civicrm_api3_format_soft_credit($contributions[$id]); } - return civicrm_api3_create_success($contribution, $params, 'Contribution', 'get', $dao); + return civicrm_api3_create_success($contributions, $params, 'Contribution', 'get'); +} + +/** + * Get number of contacts matching the supplied criteria. + * + * @param array $params + * + * @return int + */ +function civicrm_api3_contribution_getcount($params) { + $count = _civicrm_api3_get_using_query_object('Contribution', $params, array(), TRUE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE); + return (int) $count; } /** @@ -345,14 +386,22 @@ function civicrm_api3_contribution_transact($params) { * @throws Exception */ function civicrm_api3_contribution_sendconfirmation($params) { - $contribution = new CRM_Contribute_BAO_Contribution(); - $contribution->id = $params['id']; - if (!$contribution->find(TRUE)) { - throw new Exception('Contribution does not exist'); + $input = $ids = $values = array(); + $passThroughParams = array( + 'receipt_from_email', + 'receipt_from_name', + 'receipt_update', + 'cc_receipt', + 'bcc_receipt', + 'receipt_text', + 'payment_processor_id', + ); + foreach ($passThroughParams as $key) { + if (isset($params[$key])) { + $input[$key] = $params[$key]; + } } - $input = $ids = $cvalues = array('receipt_from_email' => $params['receipt_from_email']); - $contribution->loadRelatedObjects($input, $ids, TRUE); - $contribution->composeMessageArray($input, $ids, $cvalues, FALSE, FALSE); + CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $params['id'], $values); } /** @@ -366,30 +415,38 @@ function civicrm_api3_contribution_sendconfirmation($params) { function _civicrm_api3_contribution_sendconfirmation_spec(&$params) { $params['id'] = array( 'api.required' => 1, - 'title' => 'Contribution ID', + 'title' => ts('Contribution ID'), 'type' => CRM_Utils_Type::T_INT, ); $params['receipt_from_email'] = array( - 'api.required' => 1, - 'title' => 'From Email address (string) required until someone provides a patch :-)', + 'title' => ts('From Email address (string)'), 'type' => CRM_Utils_Type::T_STRING, ); $params['receipt_from_name'] = array( - 'title' => 'From Name (string)', + 'title' => ts('From Name (string)'), 'type' => CRM_Utils_Type::T_STRING, ); $params['cc_receipt'] = array( - 'title' => 'CC Email address (string)', + 'title' => ts('CC Email address (string)'), 'type' => CRM_Utils_Type::T_STRING, ); $params['bcc_receipt'] = array( - 'title' => 'BCC Email address (string)', + 'title' => ts('BCC Email address (string)'), 'type' => CRM_Utils_Type::T_STRING, ); $params['receipt_text'] = array( - 'title' => 'Message (string)', + 'title' => ts('Message (string)'), 'type' => CRM_Utils_Type::T_STRING, ); + $params['receipt_update'] = array( + 'title' => ts('Update the Receipt Date'), + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'api.default' => TRUE, + ); + $params['payment_processor_id'] = array( + 'title' => ts('Payment processor Id (avoids mis-guesses)'), + 'type' => CRM_Utils_Type::T_INT, + ); } /** @@ -404,8 +461,11 @@ function _civicrm_api3_contribution_sendconfirmation_spec(&$params) { * @param array $params * Input parameters. * - * @throws API_Exception - * Api result array. + * @return array + * API result array + * @throws \API_Exception + * @throws \CRM_Core_Exception + * @throws \Exception */ function civicrm_api3_contribution_completetransaction(&$params) { @@ -427,7 +487,10 @@ function civicrm_api3_contribution_completetransaction(&$params) { throw new API_Exception(ts('Contribution already completed'), 'contribution_completed'); } $input['trxn_id'] = !empty($params['trxn_id']) ? $params['trxn_id'] : $contribution->trxn_id; - $params = _ipn_process_transaction($params, $contribution, $input, $ids); + if (!empty($params['fee_amount'])) { + $input['fee_amount'] = $params['fee_amount']; + } + return _ipn_process_transaction($params, $contribution, $input, $ids); } @@ -460,12 +523,21 @@ function _civicrm_api3_contribution_completetransaction_spec(&$params) { 'description' => '. If not provided this will default to domain mail or contribution page', 'type' => CRM_Utils_Type::T_STRING, ); - $params['payment_processor_id'] = array( 'title' => 'Payment processor ID', - 'description' => '. Providing this is strongly recommended, as not possible to calculate it accurately always', + 'description' => 'Providing this is strongly recommended, as not possible to calculate it accurately always', 'type' => CRM_Utils_Type::T_INT, ); + $params['fee_amount'] = array( + 'title' => 'Fee charged on transaction', + 'description' => 'If a fee has been charged then the amount', + 'type' => CRM_Utils_Type::T_FLOAT, + ); + $params['trxn_date'] = array( + 'title' => 'Transaction Date', + 'description' => 'Date this transaction occurred', + 'type' => CRM_Utils_Type::T_DATE, + ); } /** @@ -485,6 +557,14 @@ function _civicrm_api3_contribution_completetransaction_spec(&$params) { */ function civicrm_api3_contribution_repeattransaction(&$params) { $input = $ids = array(); + civicrm_api3_verify_one_mandatory($params, NULL, array('contribution_recur_id', 'original_contribution_id')); + if (empty($params['original_contribution_id'])) { + $params['original_contribution_id'] = civicrm_api3('contribution', 'getvalue', array( + 'return' => 'id', + 'contribution_recur_id' => $params['contribution_recur_id'], + 'options' => array('limit' => 1, 'sort' => 'id DESC'), + )); + } $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $params['original_contribution_id']; if (!$contribution->find(TRUE)) { @@ -498,13 +578,19 @@ function civicrm_api3_contribution_repeattransaction(&$params) { } unset($contribution->id, $contribution->receive_date, $contribution->invoice_id); - $contribution->contribution_status_id = $params['contribution_status_id']; $contribution->receive_date = $params['receive_date']; - $passThroughParams = array('trxn_id', 'total_amount', 'campaign_id', 'fee_amount'); + $passThroughParams = array( + 'trxn_id', + 'total_amount', + 'campaign_id', + 'fee_amount', + 'financial_type_id', + 'contribution_status_id', + ); $input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL)); - $params = _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution); + return _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution); } catch(Exception $e) { throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString()); @@ -541,6 +627,9 @@ function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstC if (isset($params['is_email_receipt'])) { $input['is_email_receipt'] = $params['is_email_receipt']; } + if (!empty($params['trxn_date'])) { + $input['trxn_date'] = $params['trxn_date']; + } if (empty($contribution->contribution_page_id)) { static $domainFromName; static $domainFromEmail; @@ -551,9 +640,9 @@ function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstC $input['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $params, $domainFromEmail); } $transaction = new CRM_Core_Transaction(); - CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, !empty($contribution->contribution_recur_id), $contribution, + return CRM_Contribute_BAO_Contribution::completeOrder($input, $ids, $objects, $transaction, !empty + ($contribution->contribution_recur_id), $contribution, FALSE, FALSE); - return $params; } /** @@ -564,8 +653,12 @@ function _ipn_process_transaction(&$params, $contribution, $input, $ids, $firstC function _civicrm_api3_contribution_repeattransaction_spec(&$params) { $params['original_contribution_id'] = array( 'title' => 'Original Contribution ID', + 'description' => 'Contribution ID to copy (will be calculated from recurring contribution if not provided)', + 'type' => CRM_Utils_Type::T_INT, + ); + $params['contribution_recur_id'] = array( + 'title' => 'Recurring contribution ID', 'type' => CRM_Utils_Type::T_INT, - 'api.required' => TRUE, ); $params['trxn_id'] = array( 'title' => 'Transaction ID', @@ -595,6 +688,26 @@ function _civicrm_api3_contribution_repeattransaction_spec(&$params) { 'name' => 'trxn_id', 'type' => CRM_Utils_Type::T_STRING, ); + $params['campaign_id'] = array( + 'title' => 'Campaign ID', + 'name' => 'campaign_id', + 'type' => CRM_Utils_Type::T_INT, + 'pseudoconstant' => array( + 'table' => 'civicrm_campaign', + 'keyColumn' => 'id', + 'labelColumn' => 'title', + ), + ); + $params['financial_type_id'] = array( + 'title' => 'Financial ID (ignored if more than one line item)', + 'name' => 'financial_type_id', + 'type' => CRM_Utils_Type::T_INT, + 'pseudoconstant' => array( + 'table' => 'civicrm_financial_type', + 'keyColumn' => 'id', + 'labelColumn' => 'name', + ), + ); $params['payment_processor_id'] = array( 'description' => ts('Payment processor ID, will be loaded from contribution_recur if not provided'), 'title' => 'Payment processor ID',