-
Notifications
You must be signed in to change notification settings - Fork 0
CIVIMM-462: Copy payment_instrument_id to instalments #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
… instalment Add payment_instrument_id field to RecurringContributionDTO and copy it when creating instalment contributions. This ensures instalments inherit the payment method from the parent recurring contribution as specified in the Recurring-5 requirements.
Summary of ChangesHello @erawat, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue where instalment contributions generated by Job 1 were not inheriting the payment instrument ID from their parent recurring contributions. The changes ensure that these generated instalments now correctly carry the associated payment method information, thereby aligning with the Recurring-5 specification requirements. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly adds support for copying the payment_instrument_id from a recurring contribution to its generated instalments. The changes in the RecurringContributionDTO and InstalmentGenerationService are logical and consistent with the existing codebase. However, I've identified a potential issue in the DTO data validation that could be improved for robustness, aligning with best practices for handling critical data. Additionally, as per the repository's style guide, the changes are missing corresponding unit tests to verify the new functionality.
| 'financial_type_id', | ||
| 'campaign_id' | ||
| 'campaign_id', | ||
| 'payment_instrument_id' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding payment_instrument_id to the query is correct, this new functionality is not covered by unit tests. The repository style guide requires new features to have corresponding tests.
Please add tests to InstalmentGenerationServiceTest.php to verify that when a recurring contribution has a payment_instrument_id, the generated instalment also has it. Additionally, tests in RecurringContributionDTOTest.php should be added to ensure payment_instrument_id is correctly handled by the DTO.
References
- New features and bug fixes include unit tests. (link)
| $paymentInstrumentId = isset($record['payment_instrument_id']) && is_numeric($record['payment_instrument_id']) | ||
| ? (int) $record['payment_instrument_id'] | ||
| : NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of isset() here could allow a payment_instrument_id of 0 to be considered valid. In CiviCRM, entity IDs are typically positive integers, so 0 is not a valid ID. This could lead to incorrect data being propagated.
To ensure only valid, positive IDs are processed, it would be safer to use !empty() which correctly handles 0, null, and empty strings as invalid values. This aligns with the principle of failing fast if critical data is missing, rather than masking potential issues with invalid default values.
$paymentInstrumentId = !empty($record['payment_instrument_id']) && is_numeric($record['payment_instrument_id'])
? (int) $record['payment_instrument_id']
: NULL;References
- Avoid overly defensive variable extraction that can mask underlying data issues. It's safer to fail fast if critical data is missing, especially when default values can lead to unexpected behavior (e.g.,
strtotime('')evaluating to1970-01-01).
Overview
Ensures instalment contributions inherit the payment method (e.g., Credit Card, Direct Debit) from their parent recurring contribution when generated by Job 1.
Before
Instalment contributions created by the Generate Instalments job did not have a
payment_instrument_id, even when the parent recurring contribution had one set.After
Instalment contributions now inherit
payment_instrument_idfrom the parent recurring contribution, matching the Recurring-5 specification requirements.Technical Details
paymentInstrumentIdproperty toRecurringContributionDTOgetDueRecurringContributions()query to selectpayment_instrument_idcreateInstalment()to copypayment_instrument_idwhen presentCore overrides
None.
Comments
This completes the Job 1 (Generate Instalments) implementation per the Recurring-5 spec.