);
}
+
+/**
+ * Complete an existing (pending) transaction, updating related entities (participant, membership, pledge etc)
+ * and taking 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
+ * {@getfields Contribution_completetransaction}
+ * @return array Api result array
+ * @static void
+ * @access public
+ *
+ */
+function civicrm_api3_contribution_completetransaction(&$params) {
+
+ $input = $ids = array();
+ $contribution = new CRM_Contribute_BAO_Contribution();
+ $contribution->id = $params['id'];
+ $contribution->find(TRUE);
+ if(!$contribution->id == $params['id']){
+ throw new API_Exception('A valid contribution ID is required', 'invalid_data');
+ }
+ try {
+ if(!$contribution->loadRelatedObjects($input, $ids, FALSE, TRUE)){
+ throw new API_Exception('failed to load related objects');
+ }
+ $objects = $contribution->_relatedObjects;
+ $objects['contribution'] = &$contribution;
+ $input['component'] = $contribution->_component;
+ $input['is_test'] = $contribution->is_test;
+ $input['trxn_id']= $contribution->trxn_id;
+ $input['amount'] = $contribution->total_amount;
+ if(isset($params['is_email_receipt'])){
+ $input['is_email_receipt'] = $params['is_email_receipt'];
+ }
+ // @todo required for base ipn but problematic as api layer handles this
+ $transaction = new CRM_Core_Transaction();
+ $ipn = new CRM_Core_Payment_BaseIPN();
+ $ipn->completeTransaction($input, $ids, $objects, $transaction);
+ }
+ catch(Exception$e) {
+ throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
+ }
+}
+
+function _civicrm_api3_contribution_completetransaction(&$params) {
+
+}