From 03cfff4c78a1cc37ec690b919ea5f92b5cee1991 Mon Sep 17 00:00:00 2001 From: Ken West Date: Sun, 8 Jun 2014 00:36:13 +1000 Subject: [PATCH] CRM-14815 subscriptionURL() doesn't add checksum when called from CLI --- CRM/Core/Payment.php | 91 +++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 91d0919ab6..8bd762806d 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -350,59 +350,72 @@ abstract class CRM_Core_Payment { * @return string */ function subscriptionURL($entityID = NULL, $entity = NULL, $action = 'cancel') { - if ($action == 'cancel') { - $url = 'civicrm/contribute/unsubscribe'; - } - elseif ($action == 'billing') { - //in notify mode don't return the update billing url - if ($this->_paymentProcessor['billing_mode'] == self::BILLING_MODE_NOTIFY) { - return NULL; - } - $url = 'civicrm/contribute/updatebilling'; - } - elseif ($action == 'update') { - $url = 'civicrm/contribute/updaterecur'; - } - $session = CRM_Core_Session::singleton(); - $userId = $session->get('userID'); - $checksumValue = ""; - - if ($entityID && $entity == 'membership') { - if (!$userId) { - $contactID = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $entityID, "contact_id"); - $checksumValue = CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf'); - $checksumValue = "&cs={$checksumValue}"; - } - return CRM_Utils_System::url($url, "reset=1&mid={$entityID}{$checksumValue}", TRUE, NULL, FALSE, TRUE); - } + // Set URL + switch ($action) { + case 'cancel' : + $url = 'civicrm/contribute/unsubscribe'; + break; + + case 'billing' : + //in notify mode don't return the update billing url + if ($this->_paymentProcessor['billing_mode'] == self::BILLING_MODE_NOTIFY) { + return NULL; + } + $url = 'civicrm/contribute/updatebilling'; + break; - if ($entityID && $entity == 'contribution') { - if (!$userId) { - $contactID = CRM_Core_DAO::getFieldValue("CRM_Contribute_DAO_Contribution", $entityID, "contact_id"); - $checksumValue = CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf'); - $checksumValue = "&cs={$checksumValue}"; - } - return CRM_Utils_System::url($url, "reset=1&coid={$entityID}{$checksumValue}", TRUE, NULL, FALSE, TRUE); + case 'update' : + $url = 'civicrm/contribute/updaterecur'; + break; } - if ($entityID && $entity == 'recur') { - if (!$userId) { - $sql = " + $session = CRM_Core_Session::singleton(); + $userId = $session->get('userID'); + $contactID = 0; + $checksumValue = ''; + $entityArg = ''; + + // Find related Contact + if ($entityID) { + switch ($entity) { + case 'membership' : + $contactID = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $entityID, "contact_id"); + $entityArg = 'mid'; + break; + + case 'contribution' : + $contactID = CRM_Core_DAO::getFieldValue("CRM_Contribute_DAO_Contribution", $entityID, "contact_id"); + $entityArg = 'coid'; + break; + + case 'recur' : + $sql = " SELECT con.contact_id FROM civicrm_contribution_recur rec INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) WHERE rec.id = %1 GROUP BY rec.id"; - $contactID = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($entityID, 'Integer'))); - $checksumValue = CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf'); - $checksumValue = "&cs={$checksumValue}"; + $contactID = CRM_Core_DAO::singleValueQuery($sql, array(1 => array($entityID, 'Integer'))); + $entityArg = 'crid'; + break; } - return CRM_Utils_System::url($url, "reset=1&crid={$entityID}{$checksumValue}", TRUE, NULL, FALSE, TRUE); } + // Add entity arguments + if ($entityArg != '') { + // Add checksum argument + if ($contactID != 0 && $userId != $contactID) { + $checksumValue = '&cs=' . CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf'); + } + return CRM_Utils_System::url($url, "reset=1&{$entityArg}={$entityID}{$checksumValue}", TRUE, NULL, FALSE, TRUE); + } + + // Else login URL if ($this->isSupported('accountLoginURL')) { return $this->accountLoginURL(); } + + // Else default return $this->_paymentProcessor['url_recur']; } } -- 2.25.1