I have a page where the membership payment and different contribution amounts are displayed through a price set to collect member dues for one month.
I was using civicrm 4.0.5 previously and now I am using civicrm 4.7.17
Everything worked perfectly fine on civicrm 4.0.5.
However, in civicrm 4.7.17, after the payments are made the Membership expiry dates do not advance.
So I wrote my own code to advance the membership expiry date to the last day of the next month. Here is the code:
//get the membership dates for the cid
$membership_get_params = array(
'version' => 3,
//specify the membership type id
'membership_type_id' => $membership_type_id,
'contact_id' => $objectRef->contact_id,
'filters' => array(
'is_current' => 1,
),
);
require_once 'api/api.php';
$membership_get_result = civicrm_api( 'membership','get',$membership_get_params);
$membership_get_result = $membership_get_result['values'][$membership_get_result['id']];
// Find date of next month
$end_date = $membership_get_result['end_date'];
$end_date_array = explode('-', $end_date);
$year = $end_date_array[0];
$month = $end_date_array[1];
$day = $end_date_array[2];
if (in_array($objectRef->contribution_page_id, $one_month_contribution_page_ids)) {
$next_month = $month + 1;
}
if ($next_month > 12) {
$year = $year + 1;
$next_month = $next_month - 12;// Get next month if payment for member dues goes beyond the current year
}
$date = $year . '-' . $next_month . '-1';
$next_month_end_date = new DateTime($date);
$next_month_end_date = $next_month_end_date->format( 'Y-m-t' );
$excludeIsAdmin = false;
$calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate( $membership_get_result['start_date'], $membership_get_result['end_date'], $membership_get_resul\
t['join_date'], 'today', $excludeIsAdmin );
// Save expiry date for membership for contact
$membership_create_params = array(
'id' => $membership_get_result['id'],
'contact_id' => $objectRef->contact_id,
'membership_type_id' => $membership_type_id,
'start_date' => $membership_get_result['start_date'],
'join_date' => $membership_get_result['join_date'],
'end_date' => $next_month_end_date,
'status_id' => $calcStatus['id'],
'version' => 3,
);
Logger::debug_var("membership_create_params", $membership_create_params);
require_once 'api/api.php';
$result = civicrm_api( 'membership', 'create', $membership_create_params );
Is this the optimal solution??
If not, please suggest.
Thanks in advance.