Answers.Body: <p>I think session issues sounds more like a D8/CiviCRM configuration issue rather than a D8WFC module issue.</p>
  
  <p>I just confirmed that D8WFC can do live payments (authenticated and anonymous) with iATS Payments. I'm sorry we don't use any Omnipay processors with any of our clients so I can't try to confirm your scenario. Perhaps check on Mattermost -> chat.civicrm.org Drupal channel to see if you can find others who can reproduce this. Some folks in that channel are system administrators themselves and may be able to help. </p>
  
  <p>Here's an example of a live-payment -> with a Confirmation that all lands in the database using D8 CiviCRM Entity:</p>
  
  <p><a href="https://i.sstatic.net/gfWyw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/gfWyw.png" alt="enter image description here"></a>
  <a href="https://i.sstatic.net/qw6Xm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qw6Xm.png" alt="enter image description here"></a>
  <a href="https://i.sstatic.net/f8R4l.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/f8R4l.png" alt="enter image description here"></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-01T17:21:37.047Z
Answers.Text: Thanks for this Karen! I think the problem only comes about with offsite payments...
  I did figure out a fix but I'm sure it's not the best approach. Perhaps it'll at least give some insight into the problem. Will post it now...
Answers.UserDisplayName: Aiden
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-30T14:56:24.987Z
Answers.LastActivityDate: 2020-04-30T14:56:24.987Z
Answers.UserDisplayName: KarinG - Semper IT
Answers.Body: <p>I narrowed the issue down to what goes on in initialize() in civicrm-core/CRM/Core/Session.php.
  When calling the contribution page directly resetScope() is called, which calls initialize() without any argument. When going through webform only createScope() gets called with $isRead set to TRUE every time. This means initialize() is only ever run with $isRead TRUE which means this code never runs:</p>
  
  <pre><code>if (!isset($this-&gt;_session[$this-&gt;_key]) ||
    !is_array($this-&gt;_session[$this-&gt;_key])
  ) {
    $this-&gt;_session[$this-&gt;_key] = [];
  }
  </code></pre>
  
  <p>And that seems to make all the difference.</p>
  
  <p>As a quick fix I've added</p>
  
  <pre><code>\CRM_Core_Session::singleton()-&gt;initialize();
  </code></pre>
  
  <p>to alterElements() after the other initialize() in webform_civicrm/src/Plugin/WebformHandler/CivicrmWebformHandler.php. This works but if anyone knows the "right" approach here please let me know.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-02T05:17:42.163Z
Answers.Text: Hey Aiden -> open an issue on drupal.org project webform_civicrm and share the exact code change.
Answers.UserDisplayName: KarinG - Semper IT
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-01T17:44:39.883Z
Answers.LastActivityDate: 2020-05-01T17:44:39.883Z
Answers.UserDisplayName: Aiden
Body: <p>I'm not sure this is the best place for this but really needing some assistance with this.</p>
  
  <p>Using Drupal 8.8.5 and CiviCRM 5.24.3 along with webform 5.9 and the latest version of webform_civicrm.</p>
  
  <p>This is only a problem when not logged in. If an anonymous user makes payment through a webform (linked to a contribution page that uses an omnipay payment processor), when the user is redirected back to the website it lands on the IPN url with a white screen. It should redirect to the confirmation page but at this point the session variables no longer exist. (Including the url needed and anything I store in $_SESSION)</p>
  
  <p>When making a payment directly through the CiviCRM contribution page there is no problem. And interestingly, if the contribution page is merely visited in the browser first, the webform will then also work correctly and will keep working correctly. Clear the cache in the browser and the webform will again have a problem.</p>
  
  <p>I'm really in the dark with this kind of thing, anyone have any ideas?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-29T19:17:00.797Z
Comments.Text: have you mentioned the payment processor? i see you say "an omnipay pp" but i don't see you specify it
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-04-29T19:28:18.203Z
Comments.Text: It's Eileen's Omnipay Multiprocessor with a custom plugin... I don't think there's anything in there that could be the problem though... and it's totally fine in D7, this is the only obscure issue in D8.
Comments.UserDisplayName: Aiden
Tags: <civicontribute><webform-civicrm><drupal-8><omnipay>
Title: Session variables destroyed while making contribution through webform in Drupal 8
ThreadText: # Session variables destroyed while making contribution through webform in Drupal 8
  
  (Asked by: username_0 on 2020-04-29)
  
  I'm not sure this is the best place for this but really needing some assistance with this.
  
  Using Drupal 8.8.5 and CiviCRM 5.24.3 along with webform 5.9 and the latest version of webform\_civicrm.
  
  This is only a problem when not logged in. If an anonymous user makes payment through a webform (linked to a contribution page that uses an omnipay payment processor), when the user is redirected back to the website it lands on the IPN url with a white screen. It should redirect to the confirmation page but at this point the session variables no longer exist. (Including the url needed and anything I store in $\_SESSION)
  
  When making a payment directly through the CiviCRM contribution page there is no problem. And interestingly, if the contribution page is merely visited in the browser first, the webform will then also work correctly and will keep working correctly. Clear the cache in the browser and the webform will again have a problem.
  
  I'm really in the dark with this kind of thing, anyone have any ideas?
  
  **Tags:** civicontribute, webform-civicrm, drupal-8, omnipay
  
  > **Comments:**
  > **username_1**: have you mentioned the payment processor? i see you say "an omnipay pp" but i don't see you specify it  
  > **username_0**: It's Eileen's Omnipay Multiprocessor with a custom plugin... I don't think there's anything in there that could be the problem though... and it's totally fine in D7, this is the only obscure issue in D8.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-04-30. Score: 2
  
  I think session issues sounds more like a D8/CiviCRM configuration issue rather than a D8WFC module issue.
  
  I just confirmed that D8WFC can do live payments (authenticated and anonymous) with iATS Payments. I'm sorry we don't use any Omnipay processors with any of our clients so I can't try to confirm your scenario. Perhaps check on Mattermost -> chat.civicrm.org Drupal channel to see if you can find others who can reproduce this. Some folks in that channel are system administrators themselves and may be able to help.
  
  Here's an example of a live-payment -> with a Confirmation that all lands in the database using D8 CiviCRM Entity:
  
  [![enter image description here](https://i.sstatic.net/gfWyw.png)](https://i.sstatic.net/gfWyw.png)
  [![enter image description here](https://i.sstatic.net/qw6Xm.png)](https://i.sstatic.net/qw6Xm.png)
  [![enter image description here](https://i.sstatic.net/f8R4l.png)](https://i.sstatic.net/f8R4l.png)
  
  > **Comments:**
  > **username_0**: Thanks for this Karen! I think the problem only comes about with offsite payments... I did figure out a fix but I'm sure it's not the best approach. Perhaps it'll at least give some insight into the problem. Will post it now...  
  
  ---
  
  ### Answer by username_0 on 2020-05-01. Score: 1
  
  I narrowed the issue down to what goes on in initialize() in civicrm-core/CRM/Core/Session.php.
  When calling the contribution page directly resetScope() is called, which calls initialize() without any argument. When going through webform only createScope() gets called with $isRead set to TRUE every time. This means initialize() is only ever run with $isRead TRUE which means this code never runs:
  
  ```
  if (!isset($this->_session[$this->_key]) ||
    !is_array($this->_session[$this->_key])
  ) {
    $this->_session[$this->_key] = [];
  }
  
  ```
  
  And that seems to make all the difference.
  
  As a quick fix I've added
  
  ```
  \CRM_Core_Session::singleton()->initialize();
  
  ```
  
  to alterElements() after the other initialize() in webform\_civicrm/src/Plugin/WebformHandler/CivicrmWebformHandler.php. This works but if anyone knows the "right" approach here please let me know.
  
  > **Comments:**
  > **username_2**: Hey username_0 -> open an issue on drupal.org project webform_civicrm and share the exact code change.  
  
  ---
  
  