1.9 KiB
1.9 KiB
Payout Retry Processor Lambda
Retries failed Stripe payouts daily. Triggered by EventBridge Scheduler at 7 AM EST.
Setup
-
Install shared dependencies:
cd lambdas/shared npm install -
Install Lambda dependencies:
cd lambdas/payoutRetryProcessor npm install
Local Testing
Run the Lambda locally using your dev environment:
cd lambdas/payoutRetryProcessor
node test-local.js
This will:
- Query your local database for failed payouts
- Attempt Stripe transfers (use test mode!)
- Send email notifications if
EMAIL_ENABLED=true
Creating Test Data
To test the retry logic, create a rental with failed payout status:
UPDATE "Rentals"
SET "payoutStatus" = 'failed'
WHERE id = '<rental-id>'
AND status = 'completed'
AND "paymentStatus" = 'paid';
Verifying Results
After running the test:
- Check console output for success/failure counts
- Query the database:
SELECT id, "payoutStatus", "stripeTransferId", "payoutProcessedAt" FROM "Rentals" WHERE id = '<rental-id>'; - Check Stripe Dashboard for new transfers
- Check email inbox if emails are enabled
AWS Deployment
When deploying to AWS:
- Create Lambda function with Node.js 20.x runtime
- Set timeout to 60 seconds (batch processing)
- Set memory to 256 MB
- Configure EventBridge Scheduler with cron:
cron(0 12 * * ? *)(7 AM EST = 12:00 UTC) - Add environment variables listed above
- Configure DLQ for failed invocations
Architecture
EventBridge Scheduler (7 AM EST daily)
|
v
Lambda Function
|
+-- Query failed payouts from database
|
+-- For each failed payout:
| +-- Reset status to "pending"
| +-- Create Stripe transfer
| +-- Update rental record
| +-- Send email notification
|
v
Return summary (success/failure counts)