Answers.Body: <p>I used the <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterPaymentProcessorParams" rel="nofollow noreferrer">alterPaymentProcessorParams</a> Hook to override the parameters 'return' and 'cancel_return'. </p>
  
  <p>The code looks like this:</p>
  
  <pre><code>function civicrm_alterPaymentProcessorParams($paymentObj,  &amp;$rawParams,  &amp;$cookedParams) 
  {  
      if ($paymentObj-&gt;_processorName == "PayPal Standard") 
      {    
          if (!empty($rawParams['successUrl'])) {
              $cookedParams['return'] = $rawParams['successUrl'];
          }
          if (!empty($rawParams['cancelUrl'])) {
              $cookedParams['cancel_return'] = $rawParams['cancelUrl']; 
          }
      }  
  }
  </code></pre>
  
  <p>$rawParams is the parameters that you passed to the payment processor in CiviCRM and cookedParams is what is passed from CiviCRM on to the Payment Site.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-28T22:20:28.860Z
Answers.LastActivityDate: 2017-11-29T02:33:22.947Z
Answers.LastEditDate: 2017-11-29T02:33:22.947Z
Answers.UserDisplayName: Ash Lock
Body: <p>I'm using the api to process contributions from some custom pages I have created, specifically the call to civicrm_api3('Contribution', 'transact', $params).</p>
  
  <p>When I use PayPal Standard as my payment gateway how do I get the Cancel URL and Success URL to point back to the pages I have created? I can't see a way to override the default urls.</p>
  
  <p>The Success url is <a href="http://example.com/administrator/?option=com_civicrm&amp;task=civicrm/contribute/transact&amp;_qf_ThankYou_display=1&amp;qfKey=" rel="nofollow noreferrer">http://example.com/administrator/?option=com_civicrm&amp;task=civicrm/contribute/transact&amp;_qf_ThankYou_display=1&amp;qfKey=</a> However I would like to redirect to <a href="http://example.com/index.php?option=com_xxx&amp;task=payments.success" rel="nofollow noreferrer">http://example.com/index.php?option=com_xxx&amp;task=payments.success</a></p>
  
  <p>The Cancel url is <a href="http://example.com/administrator/?option=com_civicrm&amp;task=civicrm/contribute/transact&amp;_qf_Main_display=1&amp;cancel=1&amp;qfKey=" rel="nofollow noreferrer">http://example.com/administrator/?option=com_civicrm&amp;task=civicrm/contribute/transact&amp;_qf_Main_display=1&amp;cancel=1&amp;qfKey=</a> However I would like to redirect to <a href="http://example.com/index.php?option=com_xxx&amp;task=payments.cancel" rel="nofollow noreferrer">http://example.com/index.php?option=com_xxx&amp;task=payments.cancel</a></p>
  
  <p>Do I need to create my own Payment Gateway that inherits from the PayPal Payement Gateway?
  Or can I redirect the CiviCRM Tranact pages to point to the pages I need?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-09T20:46:27.847Z
Comments.Text: This question can be improved by adding details like the wrong return URLs you're currently seeing. (You can replace your site domain with `example.org` for anonymity.)
Comments.UserDisplayName: Chris Burgess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-09T20:48:22.597Z
Comments.Text: I'd also recommend running a transaction and observing the URLs your browser moves through as it completes the transaction (via browser devel tools). You may see something like `paypal.com/asdf` => `example.org/civicrm/ipn/1` => `example.org/civicrm/contribute/thanks` => `example.org/`, and those steps are all potentially significant.
Comments.UserDisplayName: Chris Burgess
Tags: <api><contributions><paypal>
Title: Wrong return URLs in PayPal Standard
ThreadText: # Wrong return URLs in PayPal Standard
  
  (Asked by: username_0 on 2017-11-09)
  
  I'm using the api to process contributions from some custom pages I have created, specifically the call to civicrm\_api3('Contribution', 'transact', $params).
  
  When I use PayPal Standard as my payment gateway how do I get the Cancel URL and Success URL to point back to the pages I have created? I can't see a way to override the default urls.
  
  The Success url is <http://example.com/administrator/?option=com_civicrm&task=civicrm/contribute/transact&_qf_ThankYou_display=1&qfKey=> However I would like to redirect to <http://example.com/index.php?option=com_xxx&task=payments.success>
  
  The Cancel url is <http://example.com/administrator/?option=com_civicrm&task=civicrm/contribute/transact&_qf_Main_display=1&cancel=1&qfKey=> However I would like to redirect to <http://example.com/index.php?option=com_xxx&task=payments.cancel>
  
  Do I need to create my own Payment Gateway that inherits from the PayPal Payement Gateway?
  Or can I redirect the CiviCRM Tranact pages to point to the pages I need?
  
  **Tags:** api, contributions, paypal
  
  > **Comments:**
  > **username_1**: This question can be improved by adding details like the wrong return URLs you're currently seeing. (You can replace your site domain with `example.org` for anonymity.)  
  > **username_1**: I'd also recommend running a transaction and observing the URLs your browser moves through as it completes the transaction (via browser devel tools). You may see something like `paypal.com/asdf` => `example.org/civicrm/ipn/1` => `example.org/civicrm/contribute/thanks` => `example.org/`, and those steps are all potentially significant.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-11-28. Score: 3 | Accepted answer
  
  I used the [alterPaymentProcessorParams](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterPaymentProcessorParams) Hook to override the parameters 'return' and 'cancel\_return'.
  
  The code looks like this:
  
  ```
  function civicrm_alterPaymentProcessorParams($paymentObj,  &$rawParams,  &$cookedParams) 
  {  
      if ($paymentObj->_processorName == "PayPal Standard") 
      {    
          if (!empty($rawParams['successUrl'])) {
              $cookedParams['return'] = $rawParams['successUrl'];
          }
          if (!empty($rawParams['cancelUrl'])) {
              $cookedParams['cancel_return'] = $rawParams['cancelUrl']; 
          }
      }  
  }
  
  ```
  
  $rawParams is the parameters that you passed to the payment processor in CiviCRM and cookedParams is what is passed from CiviCRM on to the Payment Site.
  
  
  ---
  
  