Answers.Body: <p>This one came up again for me so I set up some tracing. The error comes when the completetransaction api call tries to create a EntityFinancialTrxn, but there's no entity id. This is now with CiviCRM ver 5.49.5, CiviDiscount3.8.7</p>
  <p>Here's the argument to the entity create call, which gets triggered as part of the completetransaction api call.</p>
  <pre><code> [entity_table] =&gt; civicrm_financial_item
   [financial_trxn_id] =&gt; 6745
   [entity_id] =&gt; 
   [amount] =&gt; 0
   [version] =&gt; 3
  </code></pre>
  <p>I notice that in spite of the error, a valid pending contribution is created, and that it can be manually completed without error.</p>
  <p>When I look at that successful manual completion and compare, I can see that the failed completetransaction is failing at the point where it should have already created an entry in civicrm_financial_trxn - it needs to do that so that there's an id that can go in the civicrm_entity_financial_trxn as the entity id.</p>
  <p>Since these are empty/dummy 'financial transactions', I suspect some logic somewhere in the financial system that's deciding it doesn't need to add an empty financial transaction.</p>
  <p>Taking a different approach, I tried commenting out the completetransaction call in the Confirm.php page and discovered it tries twice to complete it, both times with notes about this being a bit of a kludge for membership edge cases.</p>
  <p>After commenting both out, the UX no longer reports the error, though the contribution remains incomplete in the backend.</p>
  <p>Conclusion: the completetransaction api seems to be where this needs fixing.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-14T19:28:15.073Z
Answers.LastActivityDate: 2022-12-14T21:00:16.987Z
Answers.LastEditDate: 2022-12-14T21:00:16.987Z
Answers.UserDisplayName: Alan Dixon
Body: <p>Using a fairly generic CiviCRM contribution page with membership (CiviCRM 5.19.4 + Drupal 7) and CiviDiscount (3.7).</p>
  
  <p>When a 100% discount code is used, instead of completing, the above error is returned from line 2500 of CRM/Contribute/Form/Contribution/Confirm.php, which is an api call.</p>
  
  <p>The api call is to "completetransaction", with values: </p>
  
  <pre><code>[id] =&gt; 1550
  [trxn_id] =&gt; 
  [payment_processor_id] =&gt; 3
  [is_transactional] =&gt; 
  [fee_amount] =&gt; 
  [receive_date] =&gt; 
  [card_type_id] =&gt; 
  [pan_truncation] =&gt; 
  [version] =&gt; 3
  </code></pre>
  
  <p>Since the spec for this api call doesn't include entity_id, presumably this is cascading from a separate api call with the complete transaction.</p>
  
  <p>The contribution is left as incomplete.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-12-12T06:48:29.163Z
Comments.Text: Does kind of errors are quite hard to debug. Unless you have someting as XDEBUG enabled then you can step through your code and see where exactly it is failing.
  The logs might also help but not sure if it does. And/Or it might be also caused by an extension.
Comments.UserDisplayName: Jaap Jansma - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-07T14:17:55.847Z
Comments.Text: Alan-- were you able to track this down?  We are now getting the Mandatory key(s) missing from params array: entity_id error.  It seems like it might be connected to our recent MySQL upgrade.
Comments.UserDisplayName: Larry K.
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-09-09T17:24:06.690Z
Comments.Text: TBH, I don't even remember posting this, it was so long ago. Getting the trace of the error is probably key - the error seems to be coming from somewhere further down the stack and not getting handled so it's just showing up later on where it's not very clear why. I'm not clear how a mysql upgrade would trigger something like this, but maybe.
Comments.UserDisplayName: Alan Dixon
Tags: <civicontribute><civimember><api><cividiscount>
Title: Mandatory key(s) missing from params array: entity_id
ThreadText: # Mandatory key(s) missing from params array: entity_id
  
  (Asked by: username_0 on 2019-12-11)
  
  Using a fairly generic CiviCRM contribution page with membership (CiviCRM 5.19.4 + Drupal 7) and CiviDiscount (3.7).
  When a 100% discount code is used, instead of completing, the above error is returned from line 2500 of CRM/Contribute/Form/Contribution/Confirm.php, which is an api call.
  The api call is to "completetransaction", with values: 
  [id] => 1550
  [trxn_id] => 
  [payment_processor_id] => 3
  [is_transactional] => 
  [fee_amount] => 
  [receive_date] => 
  [card_type_id] => 
  [pan_truncation] => 
  [version] => 3
  
  Since the spec for this api call doesn't include entity_id, presumably this is cascading from a separate api call with the complete transaction.
  The contribution is left as incomplete.
  
  **Tags:** civicontribute, civimember, api, cividiscount
  
  > **Comments:**
  > **username_1**: Does kind of errors are quite hard to debug. Unless you have someting as XDEBUG enabled then you can step through your code and see where exactly it is failing. The logs might also help but not sure if it does. And/Or it might be also caused by an extension.  
  > **username_2**: Alan-- were you able to track this down?  We are now getting the Mandatory key(s) missing from params array: entity_id error.  It seems like it might be connected to our recent MySQL upgrade.  
  > **username_0**: TBH, I don't even remember posting this, it was so long ago. Getting the trace of the error is probably key - the error seems to be coming from somewhere further down the stack and not getting handled so it's just showing up later on where it's not very clear why. I'm not clear how a mysql upgrade would trigger something like this, but maybe.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-12-14. Score: 2
  
  This one came up again for me so I set up some tracing. The error comes when the completetransaction api call tries to create a EntityFinancialTrxn, but there's no entity id. This is now with CiviCRM ver 5.49.5, CiviDiscount3.8.7
  Here's the argument to the entity create call, which gets triggered as part of the completetransaction api call.
   [entity_table] => civicrm_financial_item
   [financial_trxn_id] => 6745
   [entity_id] => 
   [amount] => 0
   [version] => 3
  
  I notice that in spite of the error, a valid pending contribution is created, and that it can be manually completed without error.
  When I look at that successful manual completion and compare, I can see that the failed completetransaction is failing at the point where it should have already created an entry in civicrm_financial_trxn - it needs to do that so that there's an id that can go in the civicrm_entity_financial_trxn as the entity id.
  Since these are empty/dummy 'financial transactions', I suspect some logic somewhere in the financial system that's deciding it doesn't need to add an empty financial transaction.
  Taking a different approach, I tried commenting out the completetransaction call in the Confirm.php page and discovered it tries twice to complete it, both times with notes about this being a bit of a kludge for membership edge cases.
  After commenting both out, the UX no longer reports the error, though the contribution remains incomplete in the backend.
  Conclusion: the completetransaction api seems to be where this needs fixing.
  
  
  ---
  
  