/**
* Update contribution as well as related objects.
*
+ * @deprecated
+ *
+ * Use api contribute.completetransaction
+ * For failures use failPayment (preferably exposing by api in the process).
+ *
* @param array $params
* @param bool $processContributionObject
*
if (!empty($memberships)) {
$membershipsUpdate = array();
foreach ($memberships as $membershipTypeIdKey => $membership) {
+ $membershipParams = (array) $membership;
if ($membership) {
$format = '%Y%m%d';
- $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id,
- $membership->membership_type_id,
- $membership->is_test, $membership->id
+ $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'],
+ $membershipParams['membership_type_id'],
+ $membershipParams['is_test'],
+ $membershipParams['id']
);
// CRM-8141 update the membership type with the value recorded in log when membership created/renewed
$sql = "
SELECT membership_type_id
FROM civicrm_membership_log
-WHERE membership_id=$membership->id
+WHERE membership_id={$membershipParams['id']}
ORDER BY id DESC
LIMIT 1;";
- $dao = new CRM_Core_DAO();
- $dao->query($sql);
+ $dao = CRM_Core_DAO::executeQuery($sql);
if ($dao->fetch()) {
if (!empty($dao->membership_type_id)) {
- $membership->membership_type_id = $dao->membership_type_id;
- $membership->save();
+ $membershipParams['membership_type_id'] = $dao->membership_type_id;
}
- // else fall back to using current membership type
}
- // else fall back to using current membership type
$dao->free();
- $num_terms = $contribution->getNumTermsByContributionAndMembershipType($membership->membership_type_id, $primaryContributionID);
+ $num_terms = $contribution->getNumTermsByContributionAndMembershipType($membershipParams['membership_type_id'], $primaryContributionID);
if ($currentMembership) {
/*
* Fixed FOR CRM-4433
// @todo - we should pass membership_type_id instead of null here but not
// adding as not sure of testing
- $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id,
+ $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membershipParams['id'],
$changeDate, NULL, $num_terms
);
- $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format);
+ $dates['join_date'] = $currentMembership['join_date'];
}
else {
- $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, NULL, NULL, NULL, $num_terms);
+ $membershipParams = array_merge($membershipParams,
+ CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipParams['membership_type_id'], NULL, NULL, NULL, $num_terms)
+ );
}
//get the status for membership.
$dates['join_date'],
'today',
TRUE,
- $membership->membership_type_id,
- (array) $membership
+ $membershipParams['membership_type_id'],
+ $membershipParams
);
- $formatedParams = array(
- 'status_id' => CRM_Utils_Array::value('id', $calcStatus, 2),
- 'join_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $dates), $format),
- 'start_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $dates), $format),
- 'end_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $dates), $format),
- );
+ $membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 2);
//we might be renewing membership,
//so make status override false.
- $formatedParams['is_override'] = FALSE;
- $membership->copyValues($formatedParams);
- $membership->save();
+ $membershipParams['is_override'] = FALSE;
+ civicrm_api3('Membership', 'create', $membershipParams);
- //updating the membership log
- $membershipLog = array();
- $membershipLog = $formatedParams;
+ $membershipLog = $membershipParams;
- $logStartDate = $formatedParams['start_date'];
+ $logStartDate = $membershipParams['start_date'];
if (!empty($dates['log_start_date'])) {
$logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
$logStartDate = CRM_Utils_Date::isoToMysql($logStartDate);
CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
//update related Memberships.
- CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams);
+ CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $membershipParams);
//update the membership type key of membership relatedObjects array
//if it has changed after membership update