X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FPayment%2FBaseIPN.php;h=f461bf693b3f130c2a03486eb61c80b4a45f999e;hb=82e7a8b8a4054c4814900ddf5e8fc56d6819c134;hp=502c9bda7d4b01b9594fc9e946d609f5c669e6cd;hpb=718e934e2c6fa496ee84f56502d73cae125b1331;p=civicrm-core.git diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index 502c9bda7d..f461bf693b 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -23,7 +23,7 @@ | GNU Affero General Public License or the licensing of CiviCRM, | | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ -*/ + */ /** * @@ -46,10 +46,11 @@ class CRM_Core_Payment_BaseIPN { protected $_isRecurring = FALSE; protected $_isFirstOrLastRecurringPayment = FALSE; + /** * Constructor */ - function __construct() { + public function __construct() { self::$_now = date('YmdHis'); } @@ -60,12 +61,13 @@ class CRM_Core_Payment_BaseIPN { * * @throws CRM_Core_Exception */ - function setInputParameters($parameters) { - if(!is_array($parameters)) { + public function setInputParameters($parameters) { + if (!is_array($parameters)) { throw new CRM_Core_Exception('Invalid input parameters'); } $this->_inputParameters = $parameters; } + /** * Validate incoming data. This function is intended to ensure that incoming data matches * It provides a form of pseudo-authentication - by checking the calling fn already knows @@ -74,20 +76,25 @@ class CRM_Core_Payment_BaseIPN { * Paypal allows you to resend Instant Payment Notifications if you, for example, moved site * and didn't update your IPN URL. * - * @param array $input interpreted values from the values returned through the IPN - * @param array $ids more interpreted values (ids) from the values returned through the IPN - * @param array $objects an empty array that will be populated with loaded object - * @param boolean $required boolean Return FALSE if the relevant objects don't exist - * @param integer $paymentProcessorID Id of the payment processor ID in use - * @return boolean + * @param array $input + * Interpreted values from the values returned through the IPN. + * @param array $ids + * More interpreted values (ids) from the values returned through the IPN. + * @param array $objects + * An empty array that will be populated with loaded object. + * @param bool $required + * Boolean Return FALSE if the relevant objects don't exist. + * @param int $paymentProcessorID + * Id of the payment processor ID in use. + * @return bool */ - function validateData(&$input, &$ids, &$objects, $required = TRUE, $paymentProcessorID = NULL) { + public function validateData(&$input, &$ids, &$objects, $required = TRUE, $paymentProcessorID = NULL) { // make sure contact exists and is valid $contact = new CRM_Contact_BAO_Contact(); $contact->id = $ids['contact']; if (!$contact->find(TRUE)) { - CRM_Core_Error::debug_log_message("Could not find contact record: {$ids['contact']} in IPN request: ".print_r($input, TRUE)); + CRM_Core_Error::debug_log_message("Could not find contact record: {$ids['contact']} in IPN request: " . print_r($input, TRUE)); echo "Failure: Could not find contact record: {$ids['contact']}
"; return FALSE; } @@ -96,7 +103,7 @@ class CRM_Core_Payment_BaseIPN { $contribution = new CRM_Contribute_BAO_Contribution(); $contribution->id = $ids['contribution']; if (!$contribution->find(TRUE)) { - CRM_Core_Error::debug_log_message("Could not find contribution record: {$contribution->id} in IPN request: ".print_r($input, TRUE)); + CRM_Core_Error::debug_log_message("Could not find contribution record: {$contribution->id} in IPN request: " . print_r($input, TRUE)); echo "Failure: Could not find contribution record for {$contribution->id}
"; return FALSE; } @@ -124,13 +131,13 @@ class CRM_Core_Payment_BaseIPN { * @param $input * @param array $ids * @param array $objects - * @param boolean $required - * @param integer $paymentProcessorID + * @param bool $required + * @param int $paymentProcessorID * @param array $error_handling * - * @return multitype:number NULL |boolean + * @return bool */ - function loadObjects(&$input, &$ids, &$objects, $required, $paymentProcessorID, $error_handling = NULL) { + public function loadObjects(&$input, &$ids, &$objects, $required, $paymentProcessorID, $error_handling = NULL) { if (empty($error_handling)) { // default options are that we log an error & echo it out // note that we should refactor this error handling into error code @ some point @@ -154,13 +161,13 @@ class CRM_Core_Payment_BaseIPN { try { $success = $contribution->loadRelatedObjects($input, $ids, $required); } - catch(Exception $e) { + catch (Exception $e) { $success = FALSE; if (!empty($error_handling['log_error'])) { CRM_Core_Error::debug_log_message($e->getMessage()); } if (!empty($error_handling['echo_error'])) { - echo ($e->getMessage()); + echo $e->getMessage(); } if (!empty($error_handling['return_error'])) { return array( @@ -178,9 +185,9 @@ class CRM_Core_Payment_BaseIPN { * @param array $objects * @param object $transaction * @param array $input - * @return boolean + * @return bool */ - function failed(&$objects, &$transaction, $input = array()) { + public function failed(&$objects, &$transaction, $input = array()) { $contribution = &$objects['contribution']; $memberships = array(); if (!empty($objects['membership'])) { @@ -197,7 +204,10 @@ class CRM_Core_Payment_BaseIPN { $participant = &$objects['participant']; //CRM-15546 - $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array('labelColumn' => 'name', 'flip' => 1)); + $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array( + 'labelColumn' => 'name', + 'flip' => 1, + )); $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date); $contribution->receipt_date = CRM_Utils_Date::isoToMysql($contribution->receipt_date); $contribution->thankyou_date = CRM_Utils_Date::isoToMysql($contribution->thankyou_date); @@ -219,7 +229,10 @@ class CRM_Core_Payment_BaseIPN { if (empty($input['skipComponentSync'])) { if (!empty($memberships)) { // if transaction is failed then set "Cancelled" as membership status - $membershipStatuses = CRM_Core_PseudoConstant::get('CRM_Member_DAO_Membership', 'status_id', array('labelColumn' => 'name', 'flip' => 1)); + $membershipStatuses = CRM_Core_PseudoConstant::get('CRM_Member_DAO_Membership', 'status_id', array( + 'labelColumn' => 'name', + 'flip' => 1, + )); foreach ($memberships as $membership) { if ($membership) { $membership->status_id = $membershipStatuses['Cancelled']; @@ -233,7 +246,10 @@ class CRM_Core_Payment_BaseIPN { } if ($participant) { - $participantStatuses = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', 'status_id', array('labelColumn' => 'name', 'flip' => 1)); + $participantStatuses = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', 'status_id', array( + 'labelColumn' => 'name', + 'flip' => 1, + )); $participant->status_id = $participantStatuses['Cancelled']; $participant->save(); } @@ -249,9 +265,9 @@ class CRM_Core_Payment_BaseIPN { * Handled pending contribution status * @param array $objects * @param object $transaction - * @return boolean + * @return bool */ - function pending(&$objects, &$transaction) { + public function pending(&$objects, &$transaction) { $transaction->commit(); CRM_Core_Error::debug_log_message("returning since contribution status is pending"); echo "Success: Returning since contribution status is pending
"; @@ -265,7 +281,7 @@ class CRM_Core_Payment_BaseIPN { * * @return bool */ - function cancelled(&$objects, &$transaction, $input = array()) { + public function cancelled(&$objects, &$transaction, $input = array()) { $contribution = &$objects['contribution']; $memberships = &$objects['membership']; if (is_numeric($memberships)) { @@ -277,7 +293,10 @@ class CRM_Core_Payment_BaseIPN { if (empty($contribution->id)) { $addLineItems = TRUE; } - $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array('labelColumn' => 'name', 'flip' => 1)); + $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array( + 'labelColumn' => 'name', + 'flip' => 1, + )); $contribution->contribution_status_id = $contributionStatuses['Cancelled']; $contribution->cancel_date = self::$_now; $contribution->cancel_reason = CRM_Utils_Array::value('reasonCode', $input); @@ -300,7 +319,10 @@ class CRM_Core_Payment_BaseIPN { if (empty($input['skipComponentSync'])) { if (!empty($memberships)) { - $membershipStatuses = CRM_Core_PseudoConstant::get('CRM_Member_DAO_Membership', 'status_id', array('labelColumn' => 'name', 'flip' => 1)); + $membershipStatuses = CRM_Core_PseudoConstant::get('CRM_Member_DAO_Membership', 'status_id', array( + 'labelColumn' => 'name', + 'flip' => 1, + )); foreach ($memberships as $membership) { if ($membership) { $membership->status_id = $membershipStatuses['Cancelled']; @@ -314,7 +336,10 @@ class CRM_Core_Payment_BaseIPN { } if ($participant) { - $participantStatuses = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', 'status_id', array('labelColumn' => 'name', 'flip' => 1)); + $participantStatuses = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', 'status_id', array( + 'labelColumn' => 'name', + 'flip' => 1, + )); $participant->status_id = $participantStatuses['Cancelled']; $participant->save(); } @@ -331,7 +356,7 @@ class CRM_Core_Payment_BaseIPN { * * @return bool */ - function unhandled(&$objects, &$transaction) { + public function unhandled(&$objects, &$transaction) { $transaction->rollback(); CRM_Core_Error::debug_log_message("returning since contribution status: is not handled"); echo "Failure: contribution status is not handled
";
@@ -345,7 +370,7 @@ class CRM_Core_Payment_BaseIPN {
* @param $transaction
* @param bool $recur
*/
- function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE) {
+ public function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE) {
$contribution = &$objects['contribution'];
$primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id;
@@ -354,9 +379,9 @@ class CRM_Core_Payment_BaseIPN {
if (is_numeric($memberships)) {
$memberships = array($objects['membership']);
}
- $participant = &$objects['participant'];
- $event = &$objects['event'];
- $changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now);
+ $participant = &$objects['participant'];
+ $event = &$objects['event'];
+ $changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now);
$recurContrib = &$objects['contributionRecur'];
$values = array();
@@ -375,7 +400,7 @@ class CRM_Core_Payment_BaseIPN {
$values['receipt_from_name'] = $domainValues[0];
$values['receipt_from_email'] = $domainValues[1];
}
- if($recurContrib && $recurContrib->id){
+ if ($recurContrib && $recurContrib->id) {
//CRM-13273 - is_email_receipt setting on recurring contribution should take precedence over contribution page setting
$values['is_email_receipt'] = $recurContrib->is_email_receipt;
}
@@ -386,7 +411,7 @@ class CRM_Core_Payment_BaseIPN {
}
if (!empty($memberships)) {
- $membershipsUpdate = array( );
+ $membershipsUpdate = array();
foreach ($memberships as $membershipTypeIdKey => $membership) {
if ($membership) {
$format = '%Y%m%d';
@@ -404,7 +429,7 @@ FROM civicrm_membership_log
WHERE membership_id=$membership->id
ORDER BY id DESC
LIMIT 1;";
- $dao = new CRM_Core_DAO;
+ $dao = new CRM_Core_DAO();
$dao->query($sql);
if ($dao->fetch()) {
if (!empty($dao->membership_type_id)) {
@@ -447,7 +472,8 @@ LIMIT 1;";
(array) $membership
);
- $formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2),
+ $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),
@@ -509,13 +535,13 @@ LIMIT 1;";
$ufJoinParams = array(
'entity_table' => 'civicrm_event',
- 'entity_id' => $ids['event'],
- 'module' => 'CiviEvent',
+ 'entity_id' => $ids['event'],
+ 'module' => 'CiviEvent',
);
list($custom_pre_id,
- $custom_post_ids
- ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
+ $custom_post_ids
+ ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
$values['custom_pre_id'] = $custom_pre_id;
$values['custom_post_id'] = $custom_post_ids;
@@ -530,7 +556,10 @@ LIMIT 1;";
$values['is_email_receipt'] = 1;
}
if (empty($input['skipComponentSync'])) {
- $participantStatuses = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', 'status_id', array('labelColumn' => 'name', 'flip' => 1));
+ $participantStatuses = CRM_Core_PseudoConstant::get('CRM_Event_DAO_Participant', 'status_id', array(
+ 'labelColumn' => 'name',
+ 'flip' => 1,
+ ));
$participant->status_id = $participantStatuses['Registered'];
}
$participant->save();
@@ -545,7 +574,10 @@ LIMIT 1;";
if (empty($contribution->id)) {
$addLineItems = TRUE;
}
- $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array('labelColumn' => 'name', 'flip' => 1));
+ $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array(
+ 'labelColumn' => 'name',
+ 'flip' => 1,
+ ));
$contribution->contribution_status_id = $contributionStatuses['Completed'];
$contribution->is_test = $input['is_test'];
$contribution->fee_amount = CRM_Utils_Array::value('fee_amount', $input, 0);
@@ -578,7 +610,7 @@ LIMIT 1;";
//add lineitems for recurring payments
if (!empty($objects['contributionRecur']) && $objects['contributionRecur']->id) {
if ($addLineItems) {
- $input ['line_item'] = $this->addRecurLineItems($objects['contributionRecur']->id, $contribution);
+ $input['line_item'] = $this->addRecurLineItems($objects['contributionRecur']->id, $contribution);
}
else {
// this is just to prevent e-notices when we call recordFinancialAccounts - per comments on that line - intention is somewhat unclear
@@ -608,10 +640,12 @@ LIMIT 1;";
// From a lot of code reading /debugging I'm still not sure the intent WRT first & subsequent payments in this code
// it would be good if someone added some comments or refactored this
if ($contribution->id) {
- $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array('labelColumn' => 'name', 'flip' => 1));
- if ((empty($input['prevContribution']) && $paymentProcessorId) || (!$input['prevContribution']->is_pay_later &&
-- $input['prevContribution']->contribution_status_id == $contributionStatuses['Pending'])) {
- $input['payment_processor'] = $paymentProcessorId;
+ $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array(
+ 'labelColumn' => 'name',
+ 'flip' => 1,
+ ));
+ if ((empty($input['prevContribution']) && $paymentProcessorId) || (!$input['prevContribution']->is_pay_later && $input['prevContribution']->contribution_status_id == $contributionStatuses['Pending'])) {
+ $input['payment_processor'] = $paymentProcessorId;
}
$input['contribution_status_id'] = $contributionStatuses['Completed'];
$input['total_amount'] = $input['amount'];
@@ -680,7 +714,7 @@ LIMIT 1;";
*
* @return bool
*/
- function getBillingID(&$ids) {
+ public function getBillingID(&$ids) {
// get the billing location type
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
// CRM-8108 remove the ts around the Billing locationtype
@@ -698,17 +732,22 @@ LIMIT 1;";
* Send receipt from contribution. Note that the compose message part has been moved to contribution
* In general LoadObjects is called first to get the objects but the composeMessageArray function now calls it
*
- * @param array $input Incoming data from Payment processor
- * @param array $ids Related object IDs
+ * @param array $input
+ * Incoming data from Payment processor.
+ * @param array $ids
+ * Related object IDs.
* @param $objects
- * @param array $values values related to objects that have already been loaded
- * @param bool $recur is it part of a recurring contribution
- * @param bool $returnMessageText Should text be returned instead of sent. This
- * is because the function is also used to generate pdfs
+ * @param array $values
+ * Values related to objects that have already been loaded.
+ * @param bool $recur
+ * Is it part of a recurring contribution.
+ * @param bool $returnMessageText
+ * Should text be returned instead of sent. This.
+ * is because the function is also used to generate pdfs
*
* @return array
*/
- function sendMail(&$input, &$ids, &$objects, &$values, $recur = FALSE, $returnMessageText = FALSE) {
+ public function sendMail(&$input, &$ids, &$objects, &$values, $recur = FALSE, $returnMessageText = FALSE) {
$contribution = &$objects['contribution'];
$input['is_recur'] = $recur;
// set receipt from e-mail and name in value
@@ -729,7 +768,7 @@ LIMIT 1;";
* @param $ids
* @param $recur
*/
- function sendRecurringStartOrEndNotification($ids, $recur) {
+ public function sendRecurringStartOrEndNotification($ids, $recur) {
if ($this->_isFirstOrLastRecurringPayment) {
$autoRenewMembership = FALSE;
if ($recur->id &&
@@ -752,18 +791,18 @@ LIMIT 1;";
* Update contribution status - this is only called from one place in the code &
* it is unclear whether it is a function on the way in or on the way out
*
- * @param unknown_type $params
- * @return void|Ambigous