Skip to content

Flow Name: I2C Platform Event Order Payment Made

Last Updated: 2025-10-22 Source Code: I2C_Platform_Event_Order_Payment_Made.flow-meta.xml

API Name: I2C_Platform_Event_Order_Payment_Made Status: Active Type: Custom Trigger: Platform Event (Order_Payment_Made__e)

Business Purpose

This flow automatically processes payment notifications from the payment processor and updates order records, creates Order Summaries for fulfillment, and ensures proper order activation when payments are received.

Process Flow

  1. Payment Event Received: Platform event triggers with order and payment details
  2. Order Lookup: Retrieves order and account information
  3. Payment Amount Check: Determines if order is paid in full or partially paid
  4. Full Payment Path:
  5. Checks for existing Order Summary
  6. If missing Order Delivery Groups, creates Digital Delivery group
  7. Updates all Order Items with delivery group assignments
  8. Creates Order Summary for fulfillment
  9. Updates Order and Order Summary status to "Activated" and "Paid"
  10. Partial Payment Path: Updates running payment total on order
  11. UI Refresh: Triggers page refresh event for real-time updates

Key Processing Paths

Path 1: Partial Payment Processing

When payment amount is less than total order amount: 1. Updates Order payment amount with running total 2. Keeps order in current status 3. Creates page refresh event for UI update

Path 2: Full Payment Processing

When payment amount equals or exceeds total order amount: 1. Updates Order status to "Activated" and payment status to "Paid" 2. Checks for existing Order Summary 3. If Order Summary exists: Updates status to "Paid" 4. If Order Summary doesn't exist: Creates new Order Summary and related fulfillment records

Order Summary Creation Process

Prerequisites Check

  • Identifies Order Items missing Order Delivery Groups
  • Creates Order Delivery Group with Digital Delivery method if needed
  • Updates all Order Items with proper delivery group assignments

Order Summary Creation

  • Uses Salesforce Connect API createOrderSummary action
  • Associates Order Summary with the original Order
  • Sets Order Summary name to Order Number for easy identification
  • Updates Order record with Order Summary reference

Order Delivery Group Management

For orders missing delivery groups on order items: 1. Digital Delivery Method Lookup: Finds active "Digital Delivery" method 2. Order Delivery Group Creation: Creates group with Account name as delivery recipient 3. Order Item Assignment: Updates all order items with new delivery group ID 4. Type Classification: Sets Order Item type to "Order Product"

Payment Amount Calculation

  • Calculates new total paid: BLANKVALUE(Current_Payment_Amount, 0) + Added_Payment
  • Handles scenarios where no previous payments exist
  • Maintains running total across multiple payments

Data Flow

  1. Order Retrieval: Gets Order details including current payment amount and total
  2. Account Lookup: Retrieves Account information for delivery group creation
  3. Payment Evaluation: Determines if order is paid in full or partial payment
  4. Order Summary Check: Verifies if Order Summary already exists
  5. Fulfillment Setup: Creates necessary fulfillment infrastructure (delivery groups, order summary)
  6. Status Updates: Updates Order and Order Summary statuses appropriately
  7. Notification: Creates page refresh event for UI updates

Status Management

  • Order Status: Updated to "Activated" when paid in full
  • Payment Status: Set to "Paid" when total amount is reached
  • Order Summary Status: Set to "Paid" to trigger fulfillment processes

Integration Points

  • Platform Event: Order_Payment_Made__e - triggers the flow
  • Chargent Orders: Source of payment notification events
  • Order Management: Updates Order records with payment and status information
  • Order Fulfillment: Creates Order Summary records for fulfillment processing
  • Digital Delivery: Associates orders with digital delivery methods
  • Page Refresh Events: Page_Refresher__e - triggers UI updates

Error Handling

  • Graceful handling of missing delivery methods
  • Null-safe payment amount calculations
  • Proper handling of scenarios where Order Summary already exists
  • Validation of required fields before Order Summary creation

Performance Considerations

  • Efficient bulk processing of Order Items through collections
  • Single DML operations for Order Item updates
  • Strategic use of lookup queries to minimize SOQL usage
  • Platform event processing ensures asynchronous, scalable execution
📊 Click to view Process Flow Diagram
flowchart TD
    Start([Start: Order Payment Made Event]) --> GetOrder[Get Order & Account]
    GetOrder --> CalcTotal[Calculate New Total Paid]

    CalcTotal --> CheckPaid{Paid in Full?}
    CheckPaid -->|No| UpdatePartial[Update Payment Amount]
    CheckPaid -->|Yes| CheckSummary[Check for Order Summary]

    CheckSummary --> SummaryExists{Summary Exists?}
    SummaryExists -->|Yes| UpdateStatus1[Update Summary to Paid]
    SummaryExists -->|No| CheckDG[Check Order Delivery Groups]

    CheckDG --> NeedsDG{Missing Delivery Groups?}
    NeedsDG -->|Yes| CreateDG[Create Digital Delivery Group]
    NeedsDG -->|No| ActivateOrder[Update Order to Activated]

    CreateDG --> UpdateItems[Update Order Items]
    UpdateItems --> ActivateOrder

    ActivateOrder --> CreateSummary[Create Order Summary]
    CreateSummary --> LinkSummary[Link Summary to Order]
    LinkSummary --> UpdateStatus2[Update Summary to Paid]

    UpdatePartial --> Refresh1[Create Page Refresh Event]
    UpdateStatus1 --> UpdateOrder2[Update Order Status]
    UpdateOrder2 --> Refresh2[Create Page Refresh Event]
    UpdateStatus2 --> Refresh3[Create Page Refresh Event]

    Refresh1 --> End([End])
    Refresh2 --> End
    Refresh3 --> End

    style Start fill:#e1f5ff
    style CheckPaid fill:#fff4e1
    style SummaryExists fill:#fff4e1
    style NeedsDG fill:#fff4e1
    style CreateSummary fill:#ffe1e1
    style UpdateStatus1 fill:#ffe1e1
    style UpdateStatus2 fill:#ffe1e1
    style End fill:#e1f5ff

Key Business Rules

  • Payment Calculation: Running total = Current Payment Amount + Added Payment (handles null values)
  • Full Payment Threshold: Order considered paid when total payments >= order total amount
  • Order Status: Updates to "Activated" only when paid in full
  • Payment Status: Set to "Paid" on both Order and Order Summary when fully paid
  • Order Delivery Group: Required for Order Summary creation; automatically creates "Digital Delivery" group if missing
  • Order Item Classification: All items assigned type "Order Product" during delivery group setup

Dependencies

  • Platform Event: Order_Payment_Made__e (trigger)
  • Platform Event: Page_Refresher__e (for UI updates)
  • Standard Objects: Order, OrderItem, OrderSummary, OrderDeliveryGroup, OrderDeliveryMethod, Account
  • Connect API: createOrderSummary action
  • Chargent: Payment processing integration

Changes

No specific PR references found in the flow description or comments.

Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • None identified

HIGH - Address Soon After Go-Live

  • Missing Error Handling: No fault connector on Order Summary creation could cause silent failures
  • Race Conditions: Async platform event processing may cause timing issues if multiple payments arrive simultaneously

MEDIUM - Future Enhancement

  • Hardcoded Values: "Digital Delivery" method name is hardcoded; consider using metadata/custom settings
  • Partial Payment Tracking: No notification or tracking when partial payments are made
  • Performance: Multiple sequential queries could be optimized with bulkified processing

LOW - Monitor

  • Page Refresh Events: Multiple refresh events created; monitor for performance impact
  • Order Item Loop: Processes items individually; monitor for governor limit concerns with large orders

Maintenance Notes

Complexity: Medium to High - Multiple decision paths and Order Management System integration points

Review Schedule: Quarterly review recommended due to payment processing criticality

Testing Requirements: - Test partial payment scenarios - Test Order Summary creation with and without existing summaries - Test Order Delivery Group creation for missing groups - Verify page refresh functionality - Test error scenarios (missing delivery method, invalid order states)