Esempio n. 1
0
/**
 * Complete an existing (pending) transaction.
 *
 * This will update related entities (participant, membership, pledge etc)
 * and take any complete actions from the contribution page (e.g. send receipt).
 *
 * @todo - most of this should live in the BAO layer but as we want it to be an addition
 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
 *
 * @param array $params
 *   Input parameters.
 *
 * @throws API_Exception
 *   Api result array.
 */
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)) {
        throw new API_Exception('A valid original contribution ID is required', 'invalid_data');
    }
    $original_contribution = clone $contribution;
    try {
        if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
            throw new API_Exception('failed to load related objects');
        }
        unset($contribution->id, $contribution->receive_date, $contribution->invoice_id);
        $contribution->receive_date = $params['receive_date'];
        $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);
    } catch (Exception $e) {
        throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
    }
}
/**
 * Complete an existing (pending) transaction.
 *
 * This will update related entities (participant, membership, pledge etc)
 * and take any complete actions from the contribution page (e.g. send receipt).
 *
 * @todo - most of this should live in the BAO layer but as we want it to be an addition
 * to 4.3 which is already stable we should add it to the api layer & re-factor into the BAO layer later
 *
 * @param array $params
 *   Input parameters.
 *
 * @throws API_Exception
 *   Api result array.
 */
function civicrm_api3_contribution_repeattransaction(&$params)
{
    $input = $ids = array();
    $contribution = new CRM_Contribute_BAO_Contribution();
    $contribution->id = $params['original_contribution_id'];
    if (!$contribution->find(TRUE)) {
        throw new API_Exception('A valid original contribution ID is required', 'invalid_data');
    }
    $original_contribution = clone $contribution;
    try {
        if (!$contribution->loadRelatedObjects($input, $ids, TRUE)) {
            throw new API_Exception('failed to load related objects');
        }
        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');
        $input = array_intersect_key($params, array_fill_keys($passThroughParams, NULL));
        $params = _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());
    }
}