Answers.Body: <p>Not an answer to the specific issue as such, but perhaps handy for future folks looking to debug issues in this area - you can dump the gateway request data with something like this in your business logic plugin:</p>
  
  <p>(see hook docs here: <a href="https://craftcommerce.com/docs/hooks-reference#commerce_modifygatewayrequestdata" rel="nofollow noreferrer">https://craftcommerce.com/docs/hooks-reference#commerce_modifygatewayrequestdata</a>)</p>
  
  <pre><code>    public function commerce_modifyGatewayRequestData($data,$type,$transaction)
  {
  
          BusinessLogicPlugin::log("commerce_modifyGatewayRequestData"); 
          BusinessLogicPlugin::log("data");
          BusinessLogicPlugin::log($data);
          BusinessLogicPlugin::log("type");
          BusinessLogicPlugin::log($type);
          BusinessLogicPlugin::log("transaction");
          BusinessLogicPlugin::log($transaction);
   }
  </code></pre>
  
  <p>(assuming you have a <code>log</code> function in there that accepts strings and if not a string does a <code>var_dump</code>)</p>
  
  <p>That at least gives you a full look at the data you're sending.</p>
  
  <p>You can also modify the <code>$data</code> in there, and <code>return $data</code> at the end if you need to massage any of the data before submissin.  E.g. with <code>eWay</code> you should truncate some fields if they are too long or you will get errors...</p>
  
  <p>E.g.</p>
  
  <pre><code>        if(isset($data['Customer']['Street1']))
          $data['Customer']['Street1'] = substr($data['Customer']['Street1'], 0, 49);
  
          ...etc
  
          return $data;
  </code></pre>
  
  <p>Similarly, after a transaction, you can log the response etc using this event: <a href="https://craftcommerce.com/docs/events-reference#commerce_transactions.onsavetransaction" rel="nofollow noreferrer">https://craftcommerce.com/docs/events-reference#commerce_transactions.onsavetransaction</a></p>
  
  <p>(See what you can log at <a href="https://craftcommerce.com/docs/transaction-model" rel="nofollow noreferrer">https://craftcommerce.com/docs/transaction-model</a>)</p>
  
  <pre><code>craft()-&gt;on('commerce_transactions.onSaveTransaction', function ($event){
  
      $transaction = $event-&gt;params['transaction'];
      BusinessLogicPlugin::log($transaction-&gt;response);
  
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-19T07:32:14.003Z
Answers.Text: Thanks Jeremy. This is great! 
  My issues have been resolved. I am adding my findings in an answer.
Answers.UserDisplayName: Marcus Scheller
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-19T00:11:40.880Z
Answers.LastActivityDate: 2017-05-19T00:11:40.880Z
Answers.UserDisplayName: Jeremy Daalder
Answers.Body: <p>The <em>Complete Function</em> of the SaferPay gateway had the wrong arguments which I didn’t catch first thus creating a malformed request, I guess. Fixing that solved the problem. </p>
  
  <p>As for the second issue (<code>Missing DATA attribute</code>): turned out that I didn’t have CSRF protection enabled which I was sure that I had. But this Craft installation is from around 2014 and I only picked up working on it again this month. So I missed that also. Enabling it (<a href="https://craftcommerce.com/docs/payment-gateways#csrf-protection-issues" rel="nofollow noreferrer">as suggested in the docs</a>) resolved that too so everything is working as expected now.</p>
  
  <p>I have no idea about the inner workings of this so if anyone could enlighten me on that I would be very grateful. My knowledge of PHP is pretty much non existing and I am merely glueing stuff together and see what works.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-19T07:32:39.873Z
Answers.LastActivityDate: 2017-05-19T07:45:50.760Z
Answers.LastEditDate: 2017-05-19T07:45:50.760Z
Answers.UserDisplayName: Marcus Scheller
Body: <p>I am having trouble getting a payment completed (SaferPay, offsite gateway). After coming back from the payment provider I get redirected to the unchanged payment page again with the following error message: <em>Payment Error: ,</em> the error code (?) is 0.</p>
  
  <p>I have found this in the logs:</p>
  
  <pre><code>$_GET=array (
  'commerceTransactionId' =&gt; '87'
  'commerceTransactionHash' =&gt; 'f4dcff157345d68b54934791fe7b0522'
  )
  $_POST=array (
  'DATA' =&gt; '&lt;IDP MSGTYPE="PayConfirm" TOKEN="(unused)" VTVERIFY="(obsolete)" KEYID="1-0" ID="Oh7p4zbhSnWOUAzjGE5bAS4rSnAb" ACCOUNTID="401860-17795278" PROVIDERID="1395" PROVIDERNAME="PayPal Saferpay Test" PAYMENTMETHOD="16" ORDERID="2435" AMOUNT="3071" CURRENCY="EUR" IP="84.141.245.197" IPCOUNTRY="DE" /&gt;'
  'SIGNATURE' =&gt; '3eec17d64cd2f4e9e57402e3efb1d91d79af35cf462f1f971ad2aa79ceda5e6814d7fb4d82cf2bfe044c791cbc38ea3007598d4d0ac6ba16db08e1abb2dc0b61'
  )
  $_SESSION=array (
  '1c4d338641dbdf309e6ed655daae834eYii.CWebUser.flash.error' =&gt; 'Payment Error: '
  '1c4d338641dbdf309e6ed655daae834eYii.CWebUser.flashcounters' =&gt;
  array (
  'error' =&gt; 0
  )
  )
  </code></pre>
  
  <p>The <strong>QUERY_STRING</strong> cuts after the transaction hash:   </p>
  
  <pre><code>'commerceTransactionId=87&amp;commerceTransactionHash=f4dcff157345d68b54934791fe7b0522'
  </code></pre>
  
  <p>Strangeley enough it is working locally, where the log says the following:</p>
  
  <pre><code>$_GET=array (
  'commerceTransactionId' =&gt; '56'
  'commerceTransactionHash' =&gt; '2db11e4c56020b3adad7565478f2bc56'
  'DATA' =&gt; '&lt;IDP MSGTYPE="PayConfirm" TOKEN="(unused)" VTVERIFY="(obsolete)" KEYID="1-0" ID="GCzE6MbphEYrSAUYhlA9bnvY6Y7b" ACCOUNTID="401860-17795278" PROVIDERID="1395" PROVIDERNAME="PayPal Saferpay Test" PAYMENTMETHOD="16" ORDERID="2435" AMOUNT="20430" CURRENCY="EUR" IP="84.141.245.197" IPCOUNTRY="DE" /&gt;'
  'SIGNATURE' =&gt; '0378583461a09e40efe22a39cc5c7ca4c3bbe4e7f89c041154b00bcd1b65604309d219bad395ee2fefabc8726e9afd2364b769baa08ac927317698a9ab795e8b'
  )
  </code></pre>
  
  <p>Remotely it lives on a sub domain. What could be the problem?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-18T13:10:34.917Z
Comments.Text: Which gateway driver are you using?
Comments.UserDisplayName: Luke Holder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-18T13:13:11.043Z
Comments.Text: SaferPay by Six Payment Solutions. I had to make a plugin. I have just resolved the problem: a function collected the wrong data. Apparently the universe decided asking for help a required step to solving stuff on your own.
Comments.UserDisplayName: Marcus Scheller
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-18T13:14:32.280Z
Comments.Text: But a different problem arised: Now I have a Error Message: `DATA Atribute missing` although it is clearly there. If I catch the URL and use that a second time it works. What could that be?
Comments.UserDisplayName: Marcus Scheller
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-18T13:18:07.430Z
Comments.Text: Again, works locally.
Comments.UserDisplayName: Marcus Scheller
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-18T21:34:47.000Z
Comments.Text: Can you add an answer for the solution that worked for this question?  If you have a new question, you can post it separately.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-19T07:37:04.713Z
Comments.Text: Brad, just did.
Comments.UserDisplayName: Marcus Scheller
Tags: <plugin-craftcommerce>
Title: Commerce: Payment does not get completed
ThreadText: # Commerce: Payment does not get completed
  
  (Asked by: username_0 on 2017-05-18)
  
  I am having trouble getting a payment completed (SaferPay, offsite gateway). After coming back from the payment provider I get redirected to the unchanged payment page again with the following error message: *Payment Error: ,* the error code (?) is 0.
  
  I have found this in the logs:
  
  ```
  $_GET=array (
  'commerceTransactionId' => '87'
  'commerceTransactionHash' => 'f4dcff157345d68b54934791fe7b0522'
  )
  $_POST=array (
  'DATA' => '<IDP MSGTYPE="PayConfirm" TOKEN="(unused)" VTVERIFY="(obsolete)" KEYID="1-0" ID="Oh7p4zbhSnWOUAzjGE5bAS4rSnAb" ACCOUNTID="401860-17795278" PROVIDERID="1395" PROVIDERNAME="PayPal Saferpay Test" PAYMENTMETHOD="16" ORDERID="2435" AMOUNT="3071" CURRENCY="EUR" IP="84.141.245.197" IPCOUNTRY="DE" />'
  'SIGNATURE' => '3eec17d64cd2f4e9e57402e3efb1d91d79af35cf462f1f971ad2aa79ceda5e6814d7fb4d82cf2bfe044c791cbc38ea3007598d4d0ac6ba16db08e1abb2dc0b61'
  )
  $_SESSION=array (
  '1c4d338641dbdf309e6ed655daae834eYii.CWebUser.flash.error' => 'Payment Error: '
  '1c4d338641dbdf309e6ed655daae834eYii.CWebUser.flashcounters' =>
  array (
  'error' => 0
  )
  )
  
  ```
  
  The **QUERY\_STRING** cuts after the transaction hash:
  
  ```
  'commerceTransactionId=87&commerceTransactionHash=f4dcff157345d68b54934791fe7b0522'
  
  ```
  
  Strangeley enough it is working locally, where the log says the following:
  
  ```
  $_GET=array (
  'commerceTransactionId' => '56'
  'commerceTransactionHash' => '2db11e4c56020b3adad7565478f2bc56'
  'DATA' => '<IDP MSGTYPE="PayConfirm" TOKEN="(unused)" VTVERIFY="(obsolete)" KEYID="1-0" ID="GCzE6MbphEYrSAUYhlA9bnvY6Y7b" ACCOUNTID="401860-17795278" PROVIDERID="1395" PROVIDERNAME="PayPal Saferpay Test" PAYMENTMETHOD="16" ORDERID="2435" AMOUNT="20430" CURRENCY="EUR" IP="84.141.245.197" IPCOUNTRY="DE" />'
  'SIGNATURE' => '0378583461a09e40efe22a39cc5c7ca4c3bbe4e7f89c041154b00bcd1b65604309d219bad395ee2fefabc8726e9afd2364b769baa08ac927317698a9ab795e8b'
  )
  
  ```
  
  Remotely it lives on a sub domain. What could be the problem?
  
  **Tags:** plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: Which gateway driver are you using?  
  > **username_0**: SaferPay by Six Payment Solutions. I had to make a plugin. I have just resolved the problem: a function collected the wrong data. Apparently the universe decided asking for help a required step to solving stuff on your own.  
  > **username_0**: But a different problem arised: Now I have a Error Message: `DATA Atribute missing` although it is clearly there. If I catch the URL and use that a second time it works. What could that be?  
  > **username_0**: Again, works locally.  
  > **username_2**: Can you add an answer for the solution that worked for this question?  If you have a new question, you can post it separately.  
  > **username_0**: username_2, just did.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2017-05-19. Score: 2
  
  Not an answer to the specific issue as such, but perhaps handy for future folks looking to debug issues in this area - you can dump the gateway request data with something like this in your business logic plugin:
  
  (see hook docs here: <https://craftcommerce.com/docs/hooks-reference#commerce_modifygatewayrequestdata>)
  
  ```
      public function commerce_modifyGatewayRequestData($data,$type,$transaction)
  {
  
          BusinessLogicPlugin::log("commerce_modifyGatewayRequestData"); 
          BusinessLogicPlugin::log("data");
          BusinessLogicPlugin::log($data);
          BusinessLogicPlugin::log("type");
          BusinessLogicPlugin::log($type);
          BusinessLogicPlugin::log("transaction");
          BusinessLogicPlugin::log($transaction);
   }
  
  ```
  
  (assuming you have a `log` function in there that accepts strings and if not a string does a `var_dump`)
  
  That at least gives you a full look at the data you're sending.
  
  You can also modify the `$data` in there, and `return $data` at the end if you need to massage any of the data before submissin. E.g. with `eWay` you should truncate some fields if they are too long or you will get errors...
  
  E.g.
  
  ```
          if(isset($data['Customer']['Street1']))
          $data['Customer']['Street1'] = substr($data['Customer']['Street1'], 0, 49);
  
          ...etc
  
          return $data;
  
  ```
  
  Similarly, after a transaction, you can log the response etc using this event: <https://craftcommerce.com/docs/events-reference#commerce_transactions.onsavetransaction>
  
  (See what you can log at <https://craftcommerce.com/docs/transaction-model>)
  
  ```
  craft()->on('commerce_transactions.onSaveTransaction', function ($event){
  
      $transaction = $event->params['transaction'];
      BusinessLogicPlugin::log($transaction->response);
  
  });
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_3. This is great!  My issues have been resolved. I am adding my findings in an answer.  
  
  ---
  
  ### Answer by username_0 on 2017-05-19. Score: 1
  
  The *Complete Function* of the SaferPay gateway had the wrong arguments which I didn’t catch first thus creating a malformed request, I guess. Fixing that solved the problem.
  
  As for the second issue (`Missing DATA attribute`): turned out that I didn’t have CSRF protection enabled which I was sure that I had. But this Craft installation is from around 2014 and I only picked up working on it again this month. So I missed that also. Enabling it ([as suggested in the docs](https://craftcommerce.com/docs/payment-gateways#csrf-protection-issues)) resolved that too so everything is working as expected now.
  
  I have no idea about the inner workings of this so if anyone could enlighten me on that I would be very grateful. My knowledge of PHP is pretty much non existing and I am merely glueing stuff together and see what works.
  
  
  ---
  
  