* Test IPN response updates contribution_recur & contribution for first & second contribution.
*/
public function testIPNPaymentMembershipRecurSuccess() {
- $this->setupMembershipRecurringPaymentProcessorTransaction(array('duration_unit' => 'year', 'frequency_unit' => 'year'));
+ $durationUnit = 'year';
+ $this->setupMembershipRecurringPaymentProcessorTransaction(array('duration_unit' => $durationUnit, 'frequency_unit' => $durationUnit));
$this->callAPISuccessGetSingle('membership_payment', array());
$paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurTransaction());
$paypalIPN->main();
$this->assertEquals(5, $contributionRecur['contribution_status_id']);
$paypalIPN = new CRM_Core_Payment_PaypalProIPN($this->getPaypalProRecurSubsequentTransaction());
$paypalIPN->main();
- $this->assertEquals(strtotime('+ 1 year', strtotime($membershipEndDate)), strtotime($this->callAPISuccessGetValue('membership', array('return' => 'end_date'))));
+
+ $renewedMembershipEndDate = $this->membershipRenewalDate($durationUnit, $membershipEndDate);
+ $this->assertEquals($renewedMembershipEndDate, $this->callAPISuccessGetValue('membership', array('return' => 'end_date')));
$contribution = $this->callAPISuccess('contribution', 'get', array(
'contribution_recur_id' => $this->_contributionRecurID,
'sequential' => 1,
$result = $this->callAPISuccess('MembershipStatus', 'Delete', array('id' => $membershipStatusID));
}
+ public function membershipRenewalDate($durationUnit, $membershipEndDate) {
+ // We only have an end_date if frequency units match, otherwise membership won't be autorenewed and dates won't be calculated.
+ $renewedMembershipEndDate = new DateTime($membershipEndDate);
+ switch ($durationUnit) {
+ case 'year':
+ $renewedMembershipEndDate->add(new DateInterval('P1Y'));
+ break;
+
+ case 'month':
+ // We have to add 1 day first in case it's the end of the month, then subtract afterwards
+ // eg. 2018-02-28 should renew to 2018-03-31, if we just added 1 month we'd get 2018-03-28
+ $renewedMembershipEndDate->add(new DateInterval('P1D'));
+ $renewedMembershipEndDate->add(new DateInterval('P1M'));
+ $renewedMembershipEndDate->sub(new DateInterval('P1D'));
+ break;
+ }
+ return $renewedMembershipEndDate->format('Y-m-d');
+ }
+
/**
* @param array $params
*
$renewedMembership = $this->callAPISuccessGetSingle('membership', array('id' => $membershipPayment['membership_id']));
if ($durationUnit) {
// We only have an end_date if frequency units match, otherwise membership won't be autorenewed and dates won't be calculated.
- $renewedMembershipEndDate = new DateTime($membership['end_date']);
- switch ($durationUnit) {
- case 'year':
- $renewedMembershipEndDate->add(new DateInterval('P1Y'));
- break;
-
- case 'month':
- // We have to add 1 day first in case it's the end of the month, then subtract afterwards
- // eg. 2018-02-28 should renew to 2018-03-31, if we just added 1 month we'd get 2018-03-28
- $renewedMembershipEndDate->add(new DateInterval('P1D'));
- $renewedMembershipEndDate->add(new DateInterval('P1M'));
- $renewedMembershipEndDate->sub(new DateInterval('P1D'));
- break;
- }
- $this->assertEquals($renewedMembershipEndDate->format('Y-m-d'), $renewedMembership['end_date']);
+ $renewedMembershipEndDate = $this->membershipRenewalDate($durationUnit, $membership['end_date']);
+ $this->assertEquals($renewedMembershipEndDate, $renewedMembership['end_date']);
}
$recurringContribution = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $contribution['contribution_recur_id']));
$this->assertEquals($processor['payment_instrument_id'], $recurringContribution['payment_instrument_id']);