Overview
Customer synchronization in Flexprice ensures that customers exist in Chargebee before invoice sync. Unlike other integrations, customers are only synced when an invoice is being synced to Chargebee, not during payment link creation or other operations.Key Concepts
- On-Demand Sync: Customers are synced only when invoice sync is triggered
- Invoice-Triggered: Sync happens automatically during invoice sync
- Entity Integration Mapping: Links Flexprice customers to Chargebee customer IDs
- Metadata Storage: Customer metadata stores cross-platform references
- Duplicate Prevention: Intelligent checks prevent duplicate customer creation
Synchronization Flow
Customer sync is invoice-triggered and happens automatically:When Customer Sync Happens
Customer sync is triggered only when:- An invoice is being synced to Chargebee
- Invoice outbound sync is enabled in the Chargebee connection
- Invoice status changes from
DRAFTtoFINALIZED
- Payment link creation
- Manual customer operations
- Other payment flows
Customer Data Model
Flexprice Customer Structure
Customer Creation in Chargebee
When creating a customer in Chargebee: Required Fields:email: Customer email addressauto_collection: Set to"on"(enables automatic payment collection)
first_name: Customer name (from Flexprice customer name)billing_address: Address information if available
line1→billing_address.line1line2→billing_address.line2city→billing_address.citystate→billing_address.statepostal_code→billing_address.zipcountry→billing_address.country
Customer Linking
Metadata Storage
Customer linking is maintained through metadata fields: In Flexprice Customer:Entity Integration Mapping
Customer links are also stored in the entity integration mapping table:- Entity Type:
customer - Entity ID: Flexprice customer ID
- Provider Type:
chargebee - Provider Entity ID: Chargebee customer ID
Duplicate Prevention
Email-Based Deduplication
The system prevents duplicate customers using email addresses:- Check Existing: Look for customers with same email in Chargebee
- Reuse Existing: If found, use existing Chargebee customer
- Link Creation: Create cross-platform links
- Audit Trail: Log all sync operations
External ID Matching
For customers with external IDs:- Priority Matching: External ID takes precedence over email
- Fallback to Email: If no external ID match, use email
- Manual Resolution: Conflicts require manual intervention
Auto Collection
Automatic Payment Collection
When creating customers in Chargebee,auto_collection is set to "on":
Benefits:
- Chargebee automatically attempts to collect payment when invoices are due
- Reduces manual payment processing
- Improves cash flow
Error Handling
Common Sync Errors
| Error | Cause | Resolution |
|---|---|---|
| ”Customer not found” | Invalid customer ID | Verify customer exists in Flexprice |
| ”Email already exists” | Duplicate email in Chargebee | System will reuse existing customer |
| ”Invalid email format” | Malformed email address | Fix email format in Flexprice |
| ”Chargebee API error” | Chargebee connection issue | Check Chargebee credentials |
Sync Failure Recovery
When customer sync fails:- Log Error: Record failure with details
- Invoice Sync Fails: Invoice sync cannot proceed without customer
- Manual Intervention: Admin can retry customer sync
- Notification: Alert on persistent failures
Testing Customer Sync
Test Environment Setup
- Test Chargebee Account: Use Chargebee test mode
- Test Customers: Create test customers in Flexprice only
- Test Invoice Sync: Trigger invoice sync to test customer sync
Testing Flow
- Create Test Customer: Add customer in Flexprice (no sync yet)
- Verify No Sync: Customer should NOT exist in Chargebee initially
- Create Invoice: Create and finalize a test invoice
- Sync Invoice: Trigger invoice sync to Chargebee
- Verify Auto-Sync: Customer should now exist in Chargebee
- Verify Reuse: Sync another invoice - should use existing customer
Next Steps
After understanding customer sync:- Create Customers: Create customers in Flexprice as normal
- Create Invoices: Create and finalize invoices
- Sync Invoices: Invoice sync will automatically handle customer sync
- Verify Sync: Check customers in Chargebee dashboard

