CRM-13743 use paypal receive date on ipn
authorEileen <eileen@fuzion.co.nz>
Mon, 11 Nov 2013 22:37:39 +0000 (11:37 +1300)
committerEileen <eileen@fuzion.co.nz>
Mon, 11 Nov 2013 23:31:12 +0000 (12:31 +1300)
----------------------------------------
* CRM-13743: receive_date on paypal contribution should be taken from IPN
  http://issues.civicrm.org/jira/browse/CRM-13743

----------------------------------------
* CRM-13743: receive_date on paypal contribution should be taken from IPN
  http://issues.civicrm.org/jira/browse/CRM-13743

CRM/Core/Payment/PayPalProIPN.php
tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php

index a11d39d971b377586bc01f16f4e33fc465341ff2..86cee3efef38939dcbc906481787a0986217b63f 100644 (file)
@@ -274,16 +274,16 @@ class CRM_Core_Payment_PayPalProIPN extends CRM_Core_Payment_BaseIPN {
       $contribution->financial_type_id  = $objects['contributionType']->id;
       $contribution->contribution_page_id = $ids['contributionPage'];
       $contribution->contribution_recur_id = $ids['contributionRecur'];
-      $contribution->receive_date = $now;
       $contribution->currency = $objects['contribution']->currency;
       $contribution->payment_instrument_id = $objects['contribution']->payment_instrument_id;
       $contribution->amount_level = $objects['contribution']->amount_level;
       $contribution->honor_contact_id = $objects['contribution']->honor_contact_id;
       $contribution->honor_type_id = $objects['contribution']->honor_type_id;
       $contribution->campaign_id = $objects['contribution']->campaign_id;
-
       $objects['contribution'] = &$contribution;
     }
+    // CRM-13737 - am not aware of any reason why payment_date would not be set - this if is a belt & braces
+    $objects['contribution']->receive_date = !empty($input['payment_date']) ? date('YmdHis', strtotime($input['payment_date'])): $now;
 
     $this->single($input, $ids, $objects,
       TRUE, $first
@@ -462,6 +462,7 @@ INNER JOIN civicrm_membership_payment mp ON m.id = mp.membership_id AND mp.contr
     $input['fee_amount'] = self::retrieve('mc_fee', 'Money', 'POST', FALSE);
     $input['net_amount'] = self::retrieve('settle_amount', 'Money', 'POST', FALSE);
     $input['trxn_id']    = self::retrieve('txn_id', 'String', 'POST', FALSE);
+    $input['payment_date'] = self::retrieve('payment_date', 'String', 'POST', FALSE);
   }
 
   /**
index 2441ca9eb8c2983258f1536ab670f23f5399cf57..cf22aa8d5437f6e34dbd04a7843cda6bece44489 100644 (file)
@@ -99,6 +99,33 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase {
     $this->assertEquals('secondone', $contribution['values'][1]['trxn_id']);
   }
 
+  /**
+   * CRM-13743 test IPN edge case where the first transaction fails and the second succeeds
+   * We are checking that the created contribution has the same date as IPN says it should
+   * Note that only one contribution will be created (no evidence of the failed contribution is left)
+   * It seems likely that may change in future & this test will start failing (I point this out in the hope it
+   * will help future debuggers)
+   */
+  function testIPNPaymentCRM13743() {
+    $this->setupPaymentProcessorTransaction();
+    $firstPaymentParams = $this->getPaypalProRecurTransaction();
+    $firstPaymentParams['txn_type'] = 'recurring_payment_failed';
+    $paypalIPN = new CRM_Core_Payment_PayPalProIPN($firstPaymentParams);
+    $paypalIPN->main();
+
+    $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID));
+    $this->assertEquals(2, $contribution['contribution_status_id']);
+    $this->assertEquals('', $contribution['trxn_id']);
+    $contributionRecur = $this->callAPISuccess('contribution_recur', 'getsingle', array('id' => $this->_contributionRecurID));
+    $this->assertEquals(2, $contributionRecur['contribution_status_id']);
+    $paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurSubsequentTransaction());
+    $paypalIPN->main();
+    $contribution = $this->callAPISuccess('contribution', 'get', array('contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1));
+    $this->assertEquals(1, $contribution['count']);
+    $this->assertEquals('secondone', $contribution['values'][0]['trxn_id']);
+    $this->assertEquals(strtotime('03:59:05 Jul 14, 2013 PDT'), strtotime($contribution['values'][0]['receive_date']));
+  }
+
   /**
    * check a payment express IPN call does not throw any errors
    * At this stage nothing it supposed to happen so it's a pretty blunt test