Invoice Automation
Automatically create and send invoices when CRM deals close
Invoice Automation Tutorial
Learn how to automatically create invoices in Stripe when Salesforce opportunities close, eliminating manual data entry and accelerating your revenue cycle.
The Problem
When a sales deal closes, finance teams typically:
- Wait for sales to notify them (often via email or spreadsheet)
- Manually look up the customer in Stripe
- Create an invoice with the correct line items
- Send the invoice to the customer
- Update the CRM opportunity with invoice details
This manual process causes:
- Delayed invoicing - Hours or days between deal close and invoice sent
- Data entry errors - Wrong amounts, typos in customer details
- Missing invoices - Deals that slip through the cracks
- No audit trail - Hard to track what was invoiced and when
The Solution
Build a workflow that automatically:
- Triggers instantly when a Salesforce opportunity closes as "Won"
- Finds or creates the customer in Stripe
- Creates an invoice with line items from the opportunity
- Sends the invoice immediately
- Updates the Salesforce opportunity with the invoice URL
- Notifies the sales and finance teams
What You'll Build
Prerequisites
Required Connections
| Provider | Connection Type | Purpose |
|---|---|---|
| Salesforce | OAuth via Nango | Receive webhooks, update opportunities |
| Stripe | OAuth via Nango | Create customers, invoices |
| Slack | OAuth via Nango | Team notifications |
Salesforce Setup
-
Enable Change Data Capture (CDC) for the Opportunity object:
- Setup → Integrations → Change Data Capture
- Select "Opportunity" and move to Selected Entities
- Save
-
Custom Fields (optional but recommended):
Invoice_URL__c(URL) - To store the Stripe invoice linkInvoice_Status__c(Picklist) - Draft, Sent, Paid, Overdue
Stripe Setup
Ensure your Stripe account has:
- Products/prices configured for your offerings
- Tax settings configured (if applicable)
- Invoice customization (logo, footer, etc.)
Step-by-Step Implementation
Step 1: Create the Workflow
Start with the basic workflow structure:
Why this filter?
- We only want opportunities that just closed as "Won"
- The CDC event fires on any update, so we filter for the specific state
IsClosedandIsWonensure we don't process losses
Step 2: Get Account Details
Retrieve the associated account to get the billing email:
Output includes:
Name- Company nameBillingStreet,BillingCity,BillingState,BillingPostalCode,BillingCountry- Custom fields like
Billing_Email__c
Step 3: Find or Create Stripe Customer
Check if the customer exists in Stripe, create if not:
Then conditionally create:
Step 4: Resolve Customer ID
Use a transform to get the customer ID regardless of which path was taken:
Step 5: Create the Invoice
Create the invoice with line items from the opportunity:
Step 6: Add Line Items
Add line items based on opportunity products or the total amount:
Note: Stripe amounts are in cents, so we multiply by 100.
Step 7: Finalize and Send Invoice
Finalize the draft invoice and send it:
Step 8: Update Salesforce Opportunity
Update the opportunity with the invoice URL:
Step 9: Notify Team in Slack
Send a notification to your finance channel:
Complete Workflow
Here's the complete workflow JSON:
Testing
1. Create Test Workflow
2. Activate Workflow
3. Test with Simulated Webhook
4. Verify Results
Check each system:
| System | What to Verify |
|---|---|
| Stripe Dashboard | New customer created, invoice sent |
| Salesforce | Opportunity updated with Invoice_URL__c |
| Slack | Notification in #finance-notifications |
| Workflow Runs | Run completed successfully |
5. End-to-End Test
For a real test:
- Create a test opportunity in Salesforce
- Move it through stages to "Closed Won"
- Watch the workflow execute in real-time
- Verify all systems updated correctly
Error Handling
Handle Missing Customer Email
Handle Stripe API Errors
Notify on Failure
Variations and Extensions
Multi-Currency Support
Add currency detection based on account country:
Approval for Large Deals
Add an approval step for deals over $100k:
Multiple Line Items from Opportunity Products
If your opportunities have product line items:
Add Tax Calculation
Integrate tax calculation for compliant invoicing:
HubSpot Variant
Use HubSpot instead of Salesforce:
Common Issues
| Issue | Cause | Solution |
|---|---|---|
| Invoice not created | Missing customer in Stripe | Ensure find-or-create logic works |
| Wrong amount | Currency conversion | Verify amount is in cents for Stripe |
| Duplicate invoices | Webhook retries | Add idempotency key using opportunity ID |
| Missing email | No billing email on account | Add validation step, notify if missing |