Answers.Body: <p>Ken West,</p>
  
  <p>I guess your cron job 'Clean-up Temporary Data and Files' must be running when your site is busy. The session key is not an usual error. CiviCRM stores sessions variables into its database int the form of cache. When 'Clean-up Temporary Data and Files' schedule job is executed or CiviCRM cache is cleared manually the cache table is truncated. So when the user leaves CiviCRM and goes to Paypal standard for making payment and come backs to CiviCRM once payment is done and between these process CiviCRM cache is cleared than CiviCRM won't get the session key of the user from the cache table and you will end up the error message of session key invalid on screen.</p>
  
  <p>Try if you can replicate using below step
  1. Open 2 browsers(normal user and admin).
  2. 1st browser - Do a donation, Click on confirm.
  3. Once the user is on paypal screen(don't proceed with payment), from browser 2 clear civicrm cache.
  4. From browser 1 proceed with payment in paypal</p>
  
  <p>Solution:
  Try running the 'Clean-up Temporary Data and Files' schedule job once is a day when your site is not busy.</p>
  
  <p>Cheers</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-27T10:00:34.490Z
Answers.Text: Thanks for the suggestion, @Pradeep. The clean-up job is currently configured to run once per day so that's probably not the cause. But I will check the logs.
Answers.UserDisplayName: Ken West
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-27T10:10:18.037Z
Answers.Text: I tried the steps you suggested @pradeep-nayak but got a different message "Your browser session has expired and we are unable to complete your form submission".
Answers.UserDisplayName: Ken West
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-27T10:11:39.340Z
Answers.Text: I tried the steps @Pradeep suggested but rather than clearing the cache I ran the clean-up job. The donation worked as expected.
Answers.UserDisplayName: Ken West
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-27T05:11:50.330Z
Answers.LastActivityDate: 2019-05-27T05:11:50.330Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>Occasionally users at our site are getting &quot;Could not find a valid session key&quot; messages when making payments through PayPal Standard. The payment succeeds but this message unsettles users.</p>
  <p>The sequence of requests for a contribution is ...</p>
  <ol>
  <li>POST /civicrm/contribute/transact (submit payment details)</li>
  <li>GET /civicrm/contribute/transact?_qf_Confirm_display=true&amp;qfKey=XXXXX</li>
  <li>POST /civicrm/contribute/transact (confirm payment details)</li>
  <li>POST /civicrm/payment/ipn/NNN (PayPal IPN callback)</li>
  <li>POST /civicrm/contribute/transact?_qf_ThankYou_display=1&amp;qfKey=XXXXX</li>
  </ol>
  <p>On the occasions when this fails the 5th step says &quot;Could not find a valid session key&quot;. I'm unable to reproduce this on the PayPal Sandbox.</p>
  <p>I'm running CiviCRM 5.10.4 (with security patches) on Drupal 7.67.</p>
  <p>See <a href="https://civicrm.stackexchange.com/questions/39156/payments-fail-with-paypal-standard-and-could-not-find-a-valid-session-key">this question for an update and a solution</a>.</p>
  
Tags: <paypal>
Title: PayPal Standard - users getting "Could not find a valid session key"
ThreadText: # PayPal Standard - users getting "Could not find a valid session key"
  
  (Asked by: username_0 on 2019-05-27)
  
  Occasionally users at our site are getting "Could not find a valid session key" messages when making payments through PayPal Standard. The payment succeeds but this message unsettles users.
  
  The sequence of requests for a contribution is ...
  
  1. POST /civicrm/contribute/transact (submit payment details)
  2. GET /civicrm/contribute/transact?\_qf\_Confirm\_display=true&qfKey=XXXXX
  3. POST /civicrm/contribute/transact (confirm payment details)
  4. POST /civicrm/payment/ipn/NNN (PayPal IPN callback)
  5. POST /civicrm/contribute/transact?\_qf\_ThankYou\_display=1&qfKey=XXXXX
  
  On the occasions when this fails the 5th step says "Could not find a valid session key". I'm unable to reproduce this on the PayPal Sandbox.
  
  I'm running CiviCRM 5.10.4 (with security patches) on Drupal 7.67.
  
  See [this question for an update and a solution](https://civicrm.stackexchange.com/questions/39156/payments-fail-with-paypal-standard-and-could-not-find-a-valid-session-key).
  
  **Tags:** paypal
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-27. Score: 4
  
  username_0,
  
  I guess your cron job 'Clean-up Temporary Data and Files' must be running when your site is busy. The session key is not an usual error. CiviCRM stores sessions variables into its database int the form of cache. When 'Clean-up Temporary Data and Files' schedule job is executed or CiviCRM cache is cleared manually the cache table is truncated. So when the user leaves CiviCRM and goes to Paypal standard for making payment and come backs to CiviCRM once payment is done and between these process CiviCRM cache is cleared than CiviCRM won't get the session key of the user from the cache table and you will end up the error message of session key invalid on screen.
  
  Try if you can replicate using below step
  1. Open 2 browsers(normal user and admin).
  2. 1st browser - Do a donation, Click on confirm.
  3. Once the user is on paypal screen(don't proceed with payment), from browser 2 clear civicrm cache.
  4. From browser 1 proceed with payment in paypal
  
  Solution:
  Try running the 'Clean-up Temporary Data and Files' schedule job once is a day when your site is not busy.
  
  Cheers
  
  username_1
  
  > **Comments:**
  > **username_0**: Thanks for the suggestion, @username_1. The clean-up job is currently configured to run once per day so that's probably not the cause. But I will check the logs.  
  > **username_0**: I tried the steps you suggested @username_1 but got a different message "Your browser session has expired and we are unable to complete your form submission".  
  > **username_0**: I tried the steps @username_1 suggested but rather than clearing the cache I ran the clean-up job. The donation worked as expected.  
  
  ---
  
  