Issue#3108529 : Fix Pay later option for CiviCRM versions >= 5.21.0 #289
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before
The contribution will not be created when using the pay later payment method on CiviCRM versions >= 5.21.0 .
The issue is reported here : https://www.drupal.org/project/webform_civicrm/issues/3108529
After
Using the pay later option is working fine and the contribution is created normally.
Technical Notes
The issue was interoducded 3 months ago after this PR get merged to CiviCRM core :
civicrm/civicrm-core#15697
one of the changes in the above PR updates CRM_Core_Payment::getPaymentInstrumentID() method to return 0 instead of null when no payment method is found for the specified payment processor, but CiviCRM API treat 0 values differently from null values , it will ignore null values where it will try to set values that equal 0 into the database (which is normal given that 0 represents a value where null represents the absence of any value), and given that there is a foreign key constraint on the payment method/instrument field on the contribution table, CiviCRM will fail to create the contribution.
I solved the issue here by skipping the code that tries to get payment method Id if the payment processor Id is not set (and hence that the pay later option Id = 0 so it will always will skip this part) .