Body: <p>I have an odd issue. If the total for the Drupal Commerce transaction is zero, without using a discount code, the transaction is stored properly in CiviCRM. However, if the total comes to zero by using a discount code, the transaction goes through, but does not get recorded in CiviCRM. I am using the Commerce CiviCRM module.</p>
  
  <p>Thanks for any help you may provide.</p>
  
  <p>Here is the backtrace that shows in the CiviCRM log:</p>
  
  <pre><code>[info] $contribution = #0 /home/pppnet/www/www/sites/all/modules/civicrm/api/api.php(51): CRM_Core_Error::backtrace("contribution", TRUE)
  #1 /home/pppnet/www/www/sites/all/modules/commerce_civicrm/commerce_civicrm.module(786): civicrm_api3("Contribution", "create", (Array:16))
  #2 /home/pppnet/www/www/sites/all/modules/commerce_civicrm/commerce_civicrm.module(202): _commerce_civicrm_add_contribution("21056", Object(stdClass), Object(stdClass))
  #3 [internal function](): commerce_civicrm_commerce_payment_transaction_insert(Object(stdClass))
  #4 /home/pppnet/www/www/includes/module.inc(957): call_user_func_array("commerce_civicrm_commerce_payment_transaction_insert", (Array:1))
  #5 /home/pppnet/www/www/sites/all/modules/commerce/includes/commerce.controller.inc(98): module_invoke_all("commerce_payment_transaction_insert", Object(stdClass))
  #6 /home/pppnet/www/www/sites/all/modules/commerce/includes/commerce.controller.inc(244): DrupalCommerceEntityController-&gt;invoke("insert", Object(stdClass))
  #7 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/includes/commerce_payment_transaction.controller.inc(118): DrupalCommerceEntityController-&gt;save(Object(stdClass), Object(DatabaseTransaction))
  #8 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/commerce_payment.module(854): CommercePaymentTransactionEntityController-&gt;save(Object(stdClass))
  #9 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/modules/commerce_payment_example.module(100): commerce_payment_transaction_save(Object(stdClass))
  #10 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/modules/commerce_payment_example.module(71): commerce_payment_example_transaction((Array:16), Object(stdClass), (Array:2))
  #11 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/includes/commerce_payment.checkout_pane.inc(261): commerce_payment_example_submit_form_submit((Array:16), (Array:14), (Array:1), Object(stdClass), (Array:2))
  #12 /home/pppnet/www/www/sites/all/modules/commerce/modules/checkout/includes/commerce_checkout.pages.inc(320): commerce_payment_pane_checkout_form_submit((Array:31), (Array:26), (Array:16), Object(stdClass))
  #13 /home/pppnet/www/www/includes/form.inc(1520): commerce_checkout_form_validate((Array:31), (Array:26))
  #14 /home/pppnet/www/www/includes/form.inc(1460): form_execute_handlers("validate", (Array:31), (Array:26))
  #15 /home/pppnet/www/www/includes/form.inc(1190): _form_validate((Array:31), (Array:26), "commerce_checkout_form_review")
  #16 /home/pppnet/www/www/includes/form.inc(890): drupal_validate_form("commerce_checkout_form_review", (Array:31), (Array:26))
  #17 /home/pppnet/www/www/includes/form.inc(386): drupal_process_form("commerce_checkout_form_review", (Array:31), (Array:26))
  #18 /home/pppnet/www/www/includes/form.inc(131): drupal_build_form("commerce_checkout_form_review", (Array:26))
  #19 /home/pppnet/www/www/sites/all/modules/commerce/modules/checkout/includes/commerce_checkout.pages.inc(56): drupal_get_form("commerce_checkout_form_review", Object(stdClass), (Array:11))
  #20 [internal function](): commerce_checkout_router(Object(stdClass), (Array:11))
  #21 /home/pppnet/www/www/includes/menu.inc(527): call_user_func_array("commerce_checkout_router", (Array:2))
  #22 /home/pppnet/www/www/index.php(21): menu_execute_active_handler()
  #23 {main}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-26T18:38:37.917Z
Comments.Text: Hi Marianella, Can you check your Drupal error log and see if there is anything useful reported. Ditto for the CiviCRM log - this extension makes the latter possible via the ui - https://civicrm.org/extensions/civicrm-log-viewer
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-26T21:13:20.713Z
Comments.Text: In the CiviCRM log, I am finding something like this (these are the first few lines). Not sure if this is helpful. [info] $contribution = #0 /home/pppnet/www/www/sites/all/modules/civicrm/api/api.php(26): CRM_Core_Error::backtrace("contribution", TRUE)
  #1 /home/pppnet/www/www/sites/all/modules/civicrm/api/api.php(53): civicrm_api("Contribution", "getfields", (Array:2))
Comments.UserDisplayName: user2174
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-26T21:37:09.497Z
Comments.Text: i am kind of surprised to hear anything works with a $0 contribution - there aren't many folk using the Commerce integration. We did a bunch of work on it years ago but have hardly touched in the past several years as we moved towards using Rules directly rather than this module
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-26T21:39:01.207Z
Comments.Text: by which i mean https://github.com/eileenmcnaughton/commerce_civicrm_rules
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-26T23:13:24.117Z
Comments.Text: @user2174 The backtrace you posted a few lines about in the comments is likely to provide clues!  Could you please edit your original question to include the full backtrace?
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-27T11:51:47.917Z
Comments.Text: I updated the original question to include the full backtrace. Thanks!
Comments.UserDisplayName: user2174
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-27T11:58:15.067Z
Comments.Text: This implementation uses rules also, but to add the order as a contribution to CiviCRM, it is using the module. I would not mind using an alternative if it will work. The $0 transactions come from discounted products for certain campaigns.
Comments.UserDisplayName: user2174
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-27T18:36:15.067Z
Comments.Text: If you don't have much luck with suggestions on here - you could try on chat.civicrm.org in either the Drupal channel or the dev-financial one.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-10T20:26:10.817Z
Comments.Text: I now have a staging version with this rules module, as it was suggested. I added the action Create a contribution by contribution Line item, but I am unsure of which values I need to add for the following: Data selector for civiCRM Contact, Order, Line Item. Financial Type ID, offset value, Registering for Event ID value, Registering for Membership Type ID value, etc.
Comments.UserDisplayName: user2174
Tags: <drupal><commerce>
Title: Zero dollar total from Drupal commerce (by using discount code) is not writing back to CiviCRM
ThreadText: # Zero dollar total from Drupal commerce (by using discount code) is not writing back to CiviCRM
  
  (Asked by: username_0 on 2018-11-26)
  
  I have an odd issue. If the total for the Drupal Commerce transaction is zero, without using a discount code, the transaction is stored properly in CiviCRM. However, if the total comes to zero by using a discount code, the transaction goes through, but does not get recorded in CiviCRM. I am using the Commerce CiviCRM module.
  Thanks for any help you may provide.
  Here is the backtrace that shows in the CiviCRM log:
  [info] $contribution = #0 /home/pppnet/www/www/sites/all/modules/civicrm/api/api.php(51): CRM_Core_Error::backtrace("contribution", TRUE)
  #1 /home/pppnet/www/www/sites/all/modules/commerce_civicrm/commerce_civicrm.module(786): civicrm_api3("Contribution", "create", (Array:16))
  #2 /home/pppnet/www/www/sites/all/modules/commerce_civicrm/commerce_civicrm.module(202): _commerce_civicrm_add_contribution("21056", Object(stdClass), Object(stdClass))
  #3 [internal function](): commerce_civicrm_commerce_payment_transaction_insert(Object(stdClass))
  #4 /home/pppnet/www/www/includes/module.inc(957): call_user_func_array("commerce_civicrm_commerce_payment_transaction_insert", (Array:1))
  #5 /home/pppnet/www/www/sites/all/modules/commerce/includes/commerce.controller.inc(98): module_invoke_all("commerce_payment_transaction_insert", Object(stdClass))
  #6 /home/pppnet/www/www/sites/all/modules/commerce/includes/commerce.controller.inc(244): DrupalCommerceEntityController->invoke("insert", Object(stdClass))
  #7 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/includes/commerce_payment_transaction.controller.inc(118): DrupalCommerceEntityController->save(Object(stdClass), Object(DatabaseTransaction))
  #8 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/commerce_payment.module(854): CommercePaymentTransactionEntityController->save(Object(stdClass))
  #9 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/modules/commerce_payment_example.module(100): commerce_payment_transaction_save(Object(stdClass))
  #10 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/modules/commerce_payment_example.module(71): commerce_payment_example_transaction((Array:16), Object(stdClass), (Array:2))
  #11 /home/pppnet/www/www/sites/all/modules/commerce/modules/payment/includes/commerce_payment.checkout_pane.inc(261): commerce_payment_example_submit_form_submit((Array:16), (Array:14), (Array:1), Object(stdClass), (Array:2))
  #12 /home/pppnet/www/www/sites/all/modules/commerce/modules/checkout/includes/commerce_checkout.pages.inc(320): commerce_payment_pane_checkout_form_submit((Array:31), (Array:26), (Array:16), Object(stdClass))
  #13 /home/pppnet/www/www/includes/form.inc(1520): commerce_checkout_form_validate((Array:31), (Array:26))
  #14 /home/pppnet/www/www/includes/form.inc(1460): form_execute_handlers("validate", (Array:31), (Array:26))
  #15 /home/pppnet/www/www/includes/form.inc(1190): _form_validate((Array:31), (Array:26), "commerce_checkout_form_review")
  #16 /home/pppnet/www/www/includes/form.inc(890): drupal_validate_form("commerce_checkout_form_review", (Array:31), (Array:26))
  #17 /home/pppnet/www/www/includes/form.inc(386): drupal_process_form("commerce_checkout_form_review", (Array:31), (Array:26))
  #18 /home/pppnet/www/www/includes/form.inc(131): drupal_build_form("commerce_checkout_form_review", (Array:26))
  #19 /home/pppnet/www/www/sites/all/modules/commerce/modules/checkout/includes/commerce_checkout.pages.inc(56): drupal_get_form("commerce_checkout_form_review", Object(stdClass), (Array:11))
  #20 [internal function](): commerce_checkout_router(Object(stdClass), (Array:11))
  #21 /home/pppnet/www/www/includes/menu.inc(527): call_user_func_array("commerce_checkout_router", (Array:2))
  #22 /home/pppnet/www/www/index.php(21): menu_execute_active_handler()
  #23 {main}
  
  **Tags:** drupal, commerce
  
  > **Comments:**
  > **username_1**: Hi Marianella, Can you check your Drupal error log and see if there is anything useful reported. Ditto for the CiviCRM log - this extension makes the latter possible via the ui - https://civicrm.org/extensions/civicrm-log-viewer  
  > **username_0**: In the CiviCRM log, I am finding something like this (these are the first few lines). Not sure if this is helpful. [info] $contribution = #0 /home/pppnet/www/www/sites/all/modules/civicrm/api/api.php(26): CRM_Core_Error::backtrace("contribution", TRUE) #1 /home/pppnet/www/www/sites/all/modules/civicrm/api/api.php(53): civicrm_api("Contribution", "getfields", (Array:2))  
  > **username_1**: i am kind of surprised to hear anything works with a $0 contribution - there aren't many folk using the Commerce integration. We did a bunch of work on it years ago but have hardly touched in the past several years as we moved towards using Rules directly rather than this module  
  > **username_1**: by which i mean https://github.com/eileenmcnaughton/commerce_civicrm_rules  
  > **username_2**: @username_0 The backtrace you posted a few lines about in the comments is likely to provide clues!  Could you please edit your original question to include the full backtrace?  
  > **username_0**: I updated the original question to include the full backtrace. Thanks!  
  > **username_0**: This implementation uses rules also, but to add the order as a contribution to CiviCRM, it is using the module. I would not mind using an alternative if it will work. The $0 transactions come from discounted products for certain campaigns.  
  > **username_1**: If you don't have much luck with suggestions on here - you could try on chat.civicrm.org in either the Drupal channel or the dev-financial one.  
  > **username_0**: I now have a staging version with this rules module, as it was suggested. I added the action Create a contribution by contribution Line item, but I am unsure of which values I need to add for the following: Data selector for civiCRM Contact, Order, Line Item. Financial Type ID, offset value, Registering for Event ID value, Registering for Membership Type ID value, etc.  
  
  ---
  
  ## 0 answers
  
  