CRM-19372 allow payment processors to define an array of accepted credit card types
[civicrm-core.git] / CRM / Core / Payment.php
index dcec384ee373da4a45695f8a40930a2ba0eef4d5..745bf1131e130f8896c66f03b2fdc8485a7a5180 100644 (file)
@@ -47,6 +47,33 @@ abstract class CRM_Core_Payment {
    */
   protected $_component;
 
+  /**
+   * Parameters to append to the notify url.
+   *
+   * The notify url is passed to the payment processor and the processor uses it for return ping backs or redirection.
+   *
+   * @var array
+   */
+  protected $notifyUrlParameters = array();
+
+  /**
+   * Get notify url parameters.
+   *
+   * @return array
+   */
+  public function getNotifyUrlParameters() {
+    return $this->notifyUrlParameters;
+  }
+
+  /**
+   * Set notify url parameters.
+   *
+   * @param array $notifyUrlParameters
+   */
+  public function setNotifyUrlParameters($notifyUrlParameters) {
+    $this->notifyUrlParameters = $notifyUrlParameters;
+  }
+
   /**
    * How are we getting billing information.
    *
@@ -83,14 +110,26 @@ abstract class CRM_Core_Payment {
   protected $_paymentProcessor;
 
   /**
-   * Base url of the calling form.
-   *
-   * This is used for processors that need to return the browser back to the CiviCRM site.
+   * Base url of the calling form (offsite processors).
    *
    * @var string
    */
   protected $baseReturnUrl;
 
+  /**
+   * Return url upon success (offsite processors).
+   *
+   * @var string
+   */
+  protected $successUrl;
+
+  /**
+   * Return url upon failure (offsite processors).
+   *
+   * @var string
+   */
+  protected $cancelUrl;
+
   /**
    * The profile configured to show on the billing form.
    *
@@ -108,15 +147,41 @@ abstract class CRM_Core_Payment {
   protected $billingProfile;
 
   /**
-   * Set Base return URL.
+   * Set base return path (offsite processors).
+   *
+   * This is only useful with an internal civicrm form.
    *
    * @param string $url
-   *   Url of site to return browser to.
+   *   Internal civicrm path.
    */
   public function setBaseReturnUrl($url) {
     $this->baseReturnUrl = $url;
   }
 
+  /**
+   * Set success return URL (offsite processors).
+   *
+   * This overrides $baseReturnUrl
+   *
+   * @param string $url
+   *   Full url of site to return browser to upon success.
+   */
+  public function setSuccessUrl($url) {
+    $this->successUrl = $url;
+  }
+
+  /**
+   * Set cancel return URL (offsite processors).
+   *
+   * This overrides $baseReturnUrl
+   *
+   * @param string $url
+   *   Full url of site to return browser to upon failure.
+   */
+  public function setCancelUrl($url) {
+    $this->cancelUrl = $url;
+  }
+
   /**
    * Set the configured payment profile.
    *
@@ -819,14 +884,18 @@ abstract class CRM_Core_Payment {
   }
 
   /**
-   * Get url to return to after cancelled or failed transaction
+   * Get url to return to after cancelled or failed transaction.
    *
-   * @param $qfKey
-   * @param $participantID
+   * @param string $qfKey
+   * @param int $participantID
    *
    * @return string cancel url
    */
   public function getCancelUrl($qfKey, $participantID) {
+    if (isset($this->cancelUrl)) {
+      return $this->cancelUrl;
+    }
+
     if ($this->_component == 'event') {
       return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
         'reset' => 1,
@@ -854,6 +923,10 @@ abstract class CRM_Core_Payment {
    * @return string
    */
   protected function getReturnSuccessUrl($qfKey) {
+    if (isset($this->successUrl)) {
+      return $this->successUrl;
+    }
+
     return CRM_Utils_System::url($this->getBaseReturnUrl(), array(
       '_qf_ThankYou_display' => 1,
       'qfKey' => $qfKey,
@@ -873,6 +946,10 @@ abstract class CRM_Core_Payment {
    *   URL for a failing transactor to be redirected to.
    */
   protected function getReturnFailUrl($key, $participantID = NULL, $eventID = NULL) {
+    if (isset($this->cancelUrl)) {
+      return $this->cancelUrl;
+    }
+
     $test = $this->_is_test ? '&action=preview' : '';
     if ($this->_component == "event") {
       return CRM_Utils_System::url('civicrm/event/register',
@@ -916,8 +993,10 @@ abstract class CRM_Core_Payment {
   protected function getNotifyUrl() {
     $url = CRM_Utils_System::url(
       'civicrm/payment/ipn/' . $this->_paymentProcessor['id'],
-      array(),
-      TRUE
+      $this->getNotifyUrlParameters(),
+      TRUE,
+      NULL,
+      FALSE
     );
     return (stristr($url, '.')) ? $url : '';
   }