Skip to content

Flow Name: [I2C] Chargent Order Payment Received

Last Updated: 2025-09-01 Source Code: I2C_Chargent_Order_Payment_Received.flow-meta.xml

API Name: I2C_Chargent_Order_Payment_Received Status: Active Type: Custom Trigger: ChargentOrder update (after save) when Process_Auto_Renewed__c = true

Business Purpose

Handles complex auto-renewal processing when ChargentOrders receive recurring payments, including creating new standard orders, managing PAC contribution frequency changes, cloning order items with updated pricing, and maintaining order adjustments.

Process Flow

  1. Initial Processing: Turns off triggering field to prevent recursion
  2. Payment Type Detection: Determines if this is a consecutive recurring payment (count ≥ 2 or specific transaction pattern)
  3. PAC Product Setup: Retrieves and maps PAC contribution products based on SKU codes (P-PAC-998, P-PAC-997, P-PAC-032)
  4. Frequency Matching: Sets correct PAC product ID based on ChargentOrder payment frequency (Monthly/Quarterly/Annual)
  5. Order Creation: Creates new standard Order if recurring line items exist, otherwise stops recurring payments
  6. Product Price Retrieval: Gets current pricing for all products using Apex action
  7. Order Item Processing: Loops through existing order items, clears recurring order relationships, clones items to new order with updated prices
  8. PAC Frequency Handling: Special logic to update PAC contribution product IDs when frequency changed
  9. Order Adjustment Cloning: Copies promotions/discounts from old order items to new order items
  10. Platform Event Creation: Triggers downstream order processing
  11. Recurring Charge Recalculation: Recalculates charges using Apex action
📊 Click to view Process Flow Diagram
flowchart TD
    Start([Start: ChargentOrder update (after save) when Process_Auto_Renewed__c = true]) --> Check{Entry Criteria<br/>Met?}

    Check -->|No| End([End])
    Check -->|Yes| Process[Execute Business Logic]

    Process --> Update[Update Records]
    Update --> End

    style Start fill:#e1f5ff
    style Check fill:#fff4e1
    style Process fill:#e1ffe1
    style Update fill:#ffe1e1
    style End fill:#e1f5ff

Key Business Rules

  • Only processes when Process_Auto_Renewed__c is true and must have changed
  • Handles PAC contribution frequency changes by swapping product IDs
  • Stops recurring payments if no line items exist
  • Preserves order adjustments (promotions/discounts) on renewal
  • Uses async after commit for performance
  • Complex product mapping based on hardcoded SKU codes

Dependencies

  • ChargentOrders__ChargentOrder__c with multiple fields including payment frequency and transaction counts
  • Standard Order object and OrderItem relationships
  • PAC Contribution products with specific SKU codes (P-PAC-998, P-PAC-997, P-PAC-032)
  • Apex classes: I2C_RecalculateRecurringCharge, I2C_GetProductPrices, PriceResultWrapper
  • Platform Event: Order_Payment_Made__e
  • OrderItemAdjustmentLineItem for discount handling

Changes

No specific PR references noted in flow description.

⚠️ Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • Hardcoded PAC product SKU codes could break if products change
  • Complex nested loops with no error handling could cause partial failures
  • No rollback mechanism for failed order creation
  • Hardcoded delivery method name "Digital Delivery" could fail if method changes

HIGH - Address Soon After Go-Live

  • Extremely complex flow with high risk of data inconsistency
  • No comprehensive error handling throughout the process
  • Performance concerns with multiple Apex calls and complex loops
  • Missing validation that all required related records exist

MEDIUM - Future Enhancement

  • Refactor into smaller, focused flows for better maintainability
  • Externalize hardcoded values to custom settings
  • Add comprehensive audit logging for renewal processing
  • Implement proper error handling and rollback mechanisms

LOW - Monitor

  • Monitor for platform event delivery failures
  • Track renewal processing performance and success rates
  • Validate pricing accuracy after renewals

Maintenance Notes

EXTREMELY HIGH COMPLEXITY FLOW - This is one of the most complex flows in the system with critical business impact. Requires deep technical understanding for maintenance. Recommend thorough testing for any changes and consider breaking into smaller, focused flows. High risk for production issues.