/** * Add or update a link between contribution and membership * * @param array $params (reference ) input parameters * * @return array (reference ) membership_payment_id of created or updated record * @static void * @access public */ function &civicrm_membershipcontributionlink_create(&$params) { _civicrm_initialize(); if (empty($params)) { return civicrm_create_error(ts('No input parameters present')); } if (!is_array($params)) { return civicrm_create_error(ts('Input parameters is not an array')); } if (!isset($params['contribution_id']) || !isset($params['membership_id'])) { return civicrm_create_error(ts('Required parameters missing')); } require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); require_once 'CRM/Member/DAO/MembershipPayment.php'; $mpDAO = new CRM_Member_DAO_MembershipPayment(); $mpDAO->copyValues($params); $result = $mpDAO->save(); if (is_a($result, 'CRM_Core_Error')) { $transaction->rollback(); return civicrm_create_error($result->_errors[0]['message']); } $transaction->commit(); _civicrm_object_to_array($mpDAO, $mpArray); return $mpArray; }
/** * Add the membership Payments. * * @param array $params * Reference array contains the values submitted by the form. * * * @return object */ public static function create($params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'MembershipPayment', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_Member_DAO_MembershipPayment(); $dao->copyValues($params); $dao->id = CRM_Utils_Array::value('id', $params); //Fixed for avoiding duplicate entry error when user goes //back and forward during payment mode is notify if (!$dao->find(TRUE)) { $dao->save(); } CRM_Utils_Hook::post($hook, 'MembershipPayment', $dao->id, $dao); // CRM-14197 we are in the process on phasing out membershipPayment in favour of storing both contribution_id & entity_id (membership_id) on the line items // table. However, at this stage we have both - there is still quite a bit of refactoring to do to set the line_iten entity_id right the first time // however, we can assume at this stage that any contribution id will have only one line item with that membership type in the line item table // OR the caller will have taken responsibility for updating the line items themselves so we will update using SQL here if (!isset($params['membership_type_id'])) { $membership_type_id = civicrm_api3('membership', 'getvalue', array('id' => $dao->membership_id, 'return' => 'membership_type_id')); } else { $membership_type_id = $params['membership_type_id']; } $sql = "UPDATE civicrm_line_item li\n LEFT JOIN civicrm_price_field_value pv ON pv.id = li.price_field_value_id\n SET entity_table = 'civicrm_membership', entity_id = %1\n WHERE pv.membership_type_id = %2\n AND contribution_id = %3"; CRM_Core_DAO::executeQuery($sql, array(1 => array($dao->membership_id, 'Integer'), 2 => array($membership_type_id, 'Integer'), 3 => array($dao->contribution_id, 'Integer'))); return $dao; }
/** * function to add the membership Payments * * @param array $params reference array contains the values submitted by the form * * @access public * @static * * @return object */ static function create(&$params) { $hook = empty($params['id']) ? 'create' : 'edit'; CRM_Utils_Hook::pre($hook, 'MembershipPayment', CRM_Utils_Array::value('id', $params), $params); $dao = new CRM_Member_DAO_MembershipPayment(); $dao->copyValues($params); $dao->id = CRM_Utils_Array::value('id', $params); $dao->save(); CRM_Utils_Hook::post($hook, 'MembershipPayment', $dao->id, $dao); return $dao; }
/** * Add or update a link between contribution and membership * * @param array $params (reference ) input parameters * * @return array (reference ) membership_payment_id of created or updated record * {@getfields MembershipPayment_create} * @example MembershipPaymentCreate.php * @access public */ function civicrm_api3_membership_payment_create($params) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $mpDAO = new CRM_Member_DAO_MembershipPayment(); $mpDAO->copyValues($params); $result = $mpDAO->save(); if (is_a($result, 'CRM_Core_Error')) { $transaction->rollback(); return civicrm_api3_create_error($result->_errors[0]['message']); } $transaction->commit(); _civicrm_api3_object_to_array($mpDAO, $mpArray[$mpDAO->id]); return civicrm_api3_create_success($mpArray, $params); }