Skip to content

Autogenerate Invoice Id#612

Merged
pokhiii merged 8 commits intodevelopfrom
generate-Invoice-ID
Dec 13, 2024
Merged

Autogenerate Invoice Id#612
pokhiii merged 8 commits intodevelopfrom
generate-Invoice-ID

Conversation

@tarunnjoshi
Copy link
Copy Markdown
Member

@tarunnjoshi tarunnjoshi commented Dec 12, 2024

Autogenerate Invoice ID when we are adding contribution from backend

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced event handling for contributions with a new event handler for generating invoice IDs.
    • Added a method to generate unique invoice IDs for contributions automatically upon creation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes introduce a new method, generateInvoiceIdForContribution, in the CollectionCampService class, which is triggered after a database write on Contribution entities. This method checks specific conditions and generates a unique invoice ID if necessary. Additionally, the getSubscribedEvents method has been updated to include this new event handler for the &hook_civicrm_post event, enhancing the class's event handling capabilities related to contributions.

Changes

File Path Change Summary
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php - Added method generateInvoiceIdForContribution to generate a unique invoice ID after contribution edits.
- Updated getSubscribedEvents to include the new event handler.

Possibly related PRs

Suggested reviewers

  • pokhiii

Poem

In the code where contributions play,
A new method logs the way,
With hooks and events, it takes its stand,
Generating IDs, just as planned.
So here's to changes, bright and new,
In the world of code, we bid adieu! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (2)

1451-1451: Remove debug logging statement.

The error_log statement should be removed as it appears to be temporary debugging code.

-      error_log("contributionId: " . print_r($contributionId, TRUE));

1456-1456: Fix incorrect error message.

The error message references the wrong method name.

-      \Civi::log()->error("Exception occurred in updateCampaignForCollectionSourceContribution.", [
+      \Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cacda09 and b51604a.

📒 Files selected for processing (1)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (2 hunks)

Comment on lines +1440 to +1462
public static function generateInvoiceIdForContribution(string $op, string $objectName, int $objectId, &$objectRef) {
if ($objectName !== 'Contribution' || !$objectRef->id || $op !== 'edit') {
return;
}

try {
$contributionId = $objectRef->id;
if (!$contributionId) {
return;
}

error_log("contributionId: " . print_r($contributionId, TRUE));

}

catch (\Exception $e) {
\Civi::log()->error("Exception occurred in updateCampaignForCollectionSourceContribution.", [
'Message' => $e->getMessage(),
'Stack Trace' => $e->getTraceAsString(),
]);
}

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Implement invoice generation logic.

The method is currently incomplete. It only checks for conditions and logs the contributionId without implementing the actual invoice generation logic. Based on the PR title "Generate Invoice Id", this is the core functionality that needs to be implemented.

Consider:

  1. Generating a unique invoice ID
  2. Updating the contribution record with the generated invoice ID
  3. Adding appropriate validation and error handling
  4. Adding logging for successful invoice generation

Would you like me to help design and implement the invoice generation logic?

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b51604a and 39742b7.

📒 Files selected for processing (1)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (2 hunks)
🔇 Additional comments (1)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1)

56-56: LGTM: Event handler registration is correct.

The new event handler is properly registered for the post-write hook.

Comment on lines +1428 to +1471
/**
* This hook is called after a db write on entities.
*
* @param string $op
* The type of operation being performed.
* @param string $objectName
* The name of the object.
* @param int $objectId
* The unique identifier for the object.
* @param object $objectRef
* The reference to the object.
*/
public static function generateInvoiceIdForContribution(string $op, string $objectName, int $objectId, &$objectRef) {
if ($objectName !== 'Contribution' || !$objectRef->id) {
return;
}

try {
$contributionId = $objectRef->id;
if (!$contributionId) {
return;
}

error_log("contributionId: " . print_r($contributionId, TRUE));

if (!empty($objectRef->invoice_id)) {
return;
}

$results = Contribution::update(TRUE)
->addValue('invoice_id', 'tarun')
->addWhere('id', '=', $contributionId)
->execute();

}

catch (\Exception $e) {
\Civi::log()->error("Exception occurred in updateCampaignForCollectionSourceContribution.", [
'Message' => $e->getMessage(),
'Stack Trace' => $e->getTraceAsString(),
]);
}

}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Potential issue

Critical: Invoice ID implementation deviates from CiviCRM core patterns and best practices

The current implementation has several issues when compared to CiviCRM core's invoice ID handling:

  1. Hardcoding 'tarun' as invoice_id violates CiviCRM's established pattern where invoice IDs are generated using md5(uniqid(rand(), TRUE)) as seen in Contribution/Transact.php
  2. Debug logging via error_log should be removed as CiviCRM provides proper logging via \Civi::log()
  3. The error message references wrong method name "updateCampaignForCollectionSourceContribution" instead of "generateInvoiceIdForContribution"
 public static function generateInvoiceIdForContribution(string $op, string $objectName, int $objectId, &$objectRef) {
   if ($objectName !== 'Contribution' || !$objectRef->id) {
     return;
   }

   try {
     $contributionId = $objectRef->id;
     if (!$contributionId) {
       return;
     }

-    error_log("contributionId: " . print_r($contributionId, TRUE));
-
     if (!empty($objectRef->invoice_id)) {
       return;
     }

     $results = Contribution::update(TRUE)
-      ->addValue('invoice_id', 'tarun')
+      ->addValue('invoice_id', md5(uniqid(rand(), TRUE)))
       ->addWhere('id', '=', $contributionId)
       ->execute();
   }
   catch (\Exception $e) {
-    \Civi::log()->error("Exception occurred in updateCampaignForCollectionSourceContribution.", [
+    \Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
       'Message' => $e->getMessage(),
       'Stack Trace' => $e->getTraceAsString(),
     ]);
   }
 }
🔗 Analysis chain

Critical: Invoice ID generation implementation needs significant improvements.

The current implementation has several issues that need to be addressed:

  1. The invoice ID is hardcoded as 'tarun' instead of generating a proper unique identifier
  2. Using error_log for debugging (line 1451) should be removed in production code
  3. The error message in the catch block refers to the wrong method name
  4. Missing proper invoice ID format/pattern
  5. No validation for duplicate invoice IDs

Consider implementing the following improvements:

 public static function generateInvoiceIdForContribution(string $op, string $objectName, int $objectId, &$objectRef) {
   if ($objectName !== 'Contribution' || !$objectRef->id) {
     return;
   }

   try {
     $contributionId = $objectRef->id;
     if (!$contributionId) {
       return;
     }

-    error_log("contributionId: " . print_r($contributionId, TRUE));
-
     if (!empty($objectRef->invoice_id)) {
       return;
     }

+    // Generate unique invoice ID with proper format
+    $prefix = 'INV';
+    $timestamp = date('YmdHis');
+    $random = substr(md5(uniqid()), 0, 6);
+    $invoiceId = "{$prefix}-{$timestamp}-{$random}";
+
+    // Verify uniqueness
+    $existing = Contribution::get(FALSE)
+      ->addSelect('id')
+      ->addWhere('invoice_id', '=', $invoiceId)
+      ->execute()
+      ->count();
+
+    if ($existing > 0) {
+      throw new \Exception("Generated invoice ID already exists: {$invoiceId}");
+    }

     $results = Contribution::update(TRUE)
-      ->addValue('invoice_id', 'tarun')
+      ->addValue('invoice_id', $invoiceId)
       ->addWhere('id', '=', $contributionId)
       ->execute();

   }
   catch (\Exception $e) {
     \Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
       'Message' => $e->getMessage(),
       'Stack Trace' => $e->getTraceAsString(),
     ]);
   }
 }

Let's verify the uniqueness of invoice IDs:


The previous command had encoding issues. Let's try these alternative approaches to understand the invoice ID generation patterns in the codebase.


The search results show there's existing invoice ID generation logic in the CiviCRM core. Let's examine it to ensure we're following established patterns and not reinventing the wheel.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for duplicate invoice IDs in contributions
ast-grep --pattern $'Contribution::get(FALSE)
  ->addSelect("invoice_id")
  ->addWhere("invoice_id", "IS NOT NULL")
  ->execute()'

Length of output: 9403


Script:

#!/bin/bash
# Let's try a different approach to find invoice ID related code
rg -l "invoice_id" --type php

# Then check for any existing invoice ID generation patterns
rg "invoice.*id.*generate" --type php -i

# Look for contribution related files
fd "contribution" -e php

Length of output: 13144


Script:

#!/bin/bash
# Let's check the existing invoice ID generation logic in Contribution.php
rg -A 10 "invoice_id.*generate" wp-content/plugins/civicrm/civicrm/CRM/Contribute/BAO/Contribution.php

# Also check for any existing invoice ID format patterns
rg "invoice.*format" --type php -i

# Look at the actual implementation in api/v3/Contribution/Transact.php since it was mentioned
rg -A 10 "invoice_id" wp-content/plugins/civicrm/civicrm/api/v3/Contribution/Transact.php

Length of output: 2228

@tarunnjoshi tarunnjoshi changed the title Generate Invoice Id Autogenerate Invoice Id Dec 12, 2024
}
catch (\Exception $e) {
\Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
'Message' => $e->getMessage(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Message' => $e->getMessage(),
'message' => $e->getMessage(),

catch (\Exception $e) {
\Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
'Message' => $e->getMessage(),
'Stack Trace' => $e->getTraceAsString(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'Stack Trace' => $e->getTraceAsString(),
'trace' => $e->getTraceAsString(),

$timestamp = time();
// Generate a unique ID based on the current time in microseconds.
$uniqueId = uniqid();
$invoiceId = base64_encode($timestamp . '-' . $uniqueId);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing this?

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1)

Line range hint 1-1474: Consider splitting the class into focused service classes

The CollectionCampService class has grown to handle multiple distinct responsibilities:

  • Collection camp management
  • Email notifications
  • Form handling
  • Contribution management

This violates the Single Responsibility Principle and makes the code harder to maintain.

Consider splitting into these service classes:

  • CollectionCampService: Core camp management
  • CampNotificationService: Email handling
  • CampFormService: Form operations
  • ContributionService: Contribution and invoice operations

This would improve:

  • Code organization
  • Testability
  • Maintainability
  • Reusability
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39742b7 and 272fff9.

📒 Files selected for processing (1)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (2 hunks)
🔇 Additional comments (1)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1)

56-56: LGTM: Event handler registration is correct.

The new event handler is properly registered in the getSubscribedEvents method.

Comment on lines +1440 to +1474
public static function generateInvoiceIdForContribution(string $op, string $objectName, int $objectId, &$objectRef) {
if ($objectName !== 'Contribution' || !$objectRef->id) {
return;
}

try {
$contributionId = $objectRef->id;
if (!$contributionId) {
return;
}

if (!empty($objectRef->invoice_id)) {
return;
}

// Generate a unique invoice ID.
// Current timestamp.
$timestamp = time();
// Generate a unique ID based on the current time in microseconds.
$uniqueId = uniqid();
$invoiceId = hash('sha256', $timestamp . $uniqueId);

Contribution::update(TRUE)
->addValue('invoice_id', $invoiceId)
->addWhere('id', '=', $contributionId)
->execute();

}
catch (\Exception $e) {
\Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
'Message' => $e->getMessage(),
'Stack Trace' => $e->getTraceAsString(),
]);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Potential issue

Invoice ID implementation needs alignment with CiviCRM patterns

The current implementation should be updated to match CiviCRM's established patterns:

  1. Use md5(uniqid(rand(), TRUE)) for invoice ID generation, as consistently shown in CiviCRM core files
  2. While we couldn't find explicit duplicate checks in core, adding one would improve reliability
  3. Add success logging for better traceability
  4. Re-throw exceptions to maintain proper error handling chain
-    $timestamp = time();
-    $uniqueId = uniqid();
-    $invoiceId = hash('sha256', $timestamp . $uniqueId);
+    // Use CiviCRM's standard invoice ID generation
+    $invoiceId = md5(uniqid(rand(), TRUE));
+
+    // Add duplicate check for extra safety
+    $existing = Contribution::get(FALSE)
+      ->addSelect('id')
+      ->addWhere('invoice_id', '=', $invoiceId)
+      ->execute()
+      ->count();
+
+    if ($existing > 0) {
+      throw new \Exception("Generated invoice ID already exists: {$invoiceId}");
+    }

     Contribution::update(TRUE)
       ->addValue('invoice_id', $invoiceId)
       ->addWhere('id', '=', $contributionId)
       ->execute();

+    \Civi::log()->info("Successfully generated invoice ID for contribution: {$contributionId}");
🔗 Analysis chain

Critical: Invoice ID implementation deviates from CiviCRM patterns

The current implementation has several issues:

  1. The invoice ID generation doesn't follow CiviCRM's established pattern
  2. No validation for duplicate invoice IDs
  3. Missing logging for successful generation
  4. Error logging structure needs improvement

Consider this implementation:

 public static function generateInvoiceIdForContribution(string $op, string $objectName, int $objectId, &$objectRef) {
   if ($objectName !== 'Contribution' || !$objectRef->id) {
     return;
   }

   try {
     $contributionId = $objectRef->id;
     if (!$contributionId) {
       return;
     }

     if (!empty($objectRef->invoice_id)) {
       return;
     }

-    // Generate a unique invoice ID.
-    // Current timestamp.
-    $timestamp = time();
-    // Generate a unique ID based on the current time in microseconds.
-    $uniqueId = uniqid();
-    $invoiceId = hash('sha256', $timestamp . $uniqueId);
+    // Generate invoice ID using CiviCRM's pattern
+    $invoiceId = md5(uniqid(rand(), TRUE));
+
+    // Verify uniqueness
+    $existing = Contribution::get(FALSE)
+      ->addSelect('id')
+      ->addWhere('invoice_id', '=', $invoiceId)
+      ->execute()
+      ->count();
+
+    if ($existing > 0) {
+      throw new \Exception("Generated invoice ID already exists: {$invoiceId}");
+    }

     Contribution::update(TRUE)
       ->addValue('invoice_id', $invoiceId)
       ->addWhere('id', '=', $contributionId)
       ->execute();

+    \Civi::log()->info("Successfully generated invoice ID for contribution: {$contributionId}");
   }
   catch (\Exception $e) {
     \Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
       'Message' => $e->getMessage(),
       'Stack Trace' => $e->getTraceAsString(),
     ]);
+    throw $e;  // Re-throw to allow proper error handling upstream
   }
 }

Let's verify the CiviCRM invoice ID pattern:


Invoice ID generation pattern matches CiviCRM core implementation

The review comment's suggestion is correct. The search results confirm that CiviCRM consistently uses md5(uniqid(rand(), TRUE)) for invoice ID generation across multiple core components:

  • CRM/Core/Payment/PayPalProIPN.php
  • bin/ContributionProcessor.php
  • api/v3/Contribution/Transact.php

Let's verify if there are any existing duplicate invoice ID checks:


Let's try a different search pattern to find duplicate invoice ID validation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing invoice ID generation patterns
rg -A 5 "invoice_id.*=.*md5" --type php

Length of output: 2130


Script:

#!/bin/bash
# Search for duplicate invoice ID validation patterns
rg -B 2 -A 5 "invoice_id.*=.*" --type php | rg -B 2 -A 5 "count|exist"

Length of output: 72


Script:

#!/bin/bash
# Search for invoice ID uniqueness checks in a broader context
rg -B 5 -A 5 "addWhere.*invoice_id.*=" --type php

Length of output: 51

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1)

1440-1474: Add success logging for better traceability.

Consider adding a success log message after successful invoice ID generation for better traceability.

       ->addWhere('id', '=', $contributionId)
       ->execute();

+      \Civi::log()->info("Successfully generated invoice ID for contribution: {$contributionId}");
     }
     catch (\Exception $e) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 272fff9 and 137bdee.

📒 Files selected for processing (1)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (2 hunks)
🔇 Additional comments (2)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (2)

56-56: LGTM: Hook registration is properly configured.

The new hook for invoice ID generation is correctly registered in the post-write event handlers.


1455-1461: ⚠️ Potential issue

Critical: Invoice ID generation needs alignment with CiviCRM patterns.

The current implementation should be updated to match CiviCRM's established patterns:

  1. Use md5(uniqid(rand(), TRUE)) for invoice ID generation
  2. Add duplicate check for reliability
-      // Generate a unique invoice ID.
-      // Current timestamp.
-      $timestamp = time();
-      // Generate a unique ID based on the current time in microseconds.
-      $uniqueId = uniqid();
-      $invoiceId = hash('sha256', $timestamp . $uniqueId);
+      // Generate invoice ID using CiviCRM's pattern
+      $invoiceId = md5(uniqid(rand(), TRUE));
+
+      // Verify uniqueness
+      $existing = Contribution::get(FALSE)
+        ->addSelect('id')
+        ->addWhere('invoice_id', '=', $invoiceId)
+        ->execute()
+        ->count();
+
+      if ($existing > 0) {
+        throw new \Exception("Generated invoice ID already exists: {$invoiceId}");
+      }

Likely invalid or redundant comment.

Comment on lines +1468 to +1473
catch (\Exception $e) {
\Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve error handling and logging consistency.

  1. Re-throw the exception to maintain proper error handling chain
  2. Use consistent log message keys (Message/Stack Trace) as seen in other methods
     catch (\Exception $e) {
       \Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
-        'message' => $e->getMessage(),
-        'trace' => $e->getTraceAsString(),
+        'Message' => $e->getMessage(),
+        'Stack Trace' => $e->getTraceAsString(),
       ]);
+      throw $e;  // Re-throw to allow proper error handling upstream
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
catch (\Exception $e) {
\Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);
}
catch (\Exception $e) {
\Civi::log()->error("Exception occurred in generateInvoiceIdForContribution.", [
'Message' => $e->getMessage(),
'Stack Trace' => $e->getTraceAsString(),
]);
throw $e; // Re-throw to allow proper error handling upstream
}

@pokhiii pokhiii merged commit a354f42 into develop Dec 13, 2024
@pokhiii pokhiii deleted the generate-Invoice-ID branch December 13, 2024 04:58
@coderabbitai coderabbitai bot mentioned this pull request Feb 6, 2025
@coderabbitai coderabbitai bot mentioned this pull request Mar 4, 2025
This was referenced May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants