Stu Mason
Stu Mason

Activity

StuMason/cleanconnect
TidyLinker.com
TypeScript
Pull Request Merged

PR #56 merged: Fix ProcessWeeklyPayouts Stripe integration with proper error handling

Summary

  • Rewrites ProcessWeeklyPayouts job to properly use the CreatePayout action instead of creating local Payout records directly
  • Adds Stripe best practices: source_transaction and transfer_group for proper transfer tracking
  • Implements robust error handling following existing patterns (RetryPaymentCapture)
  • Adds admin alerting for payout failures

Changes

ProcessWeeklyPayouts Job

  • Uses CreatePayout action for actual Stripe transfers
  • Catches only PayoutException (Stripe errors) - unexpected errors bubble up for retry
  • Adds $tries = 3, $backoff, and failed() method
  • Sends PayoutBatchFailureAlert email on partial or complete failure
  • Logs with full context from PayoutException::context()

CreatePayout Action

  • Adds source_transaction to tie transfer to original charge (avoids insufficient balance errors)
  • Adds transfer_group for tracking related transactions

New Files

  • app/Mail/Admin/PayoutBatchFailureAlert.php - Admin alert mailable
  • resources/views/mail/admin/payout-batch-failure-alert.blade.php - Email template
  • tests/Feature/Jobs/ProcessWeeklyPayoutsTest.php - 10 test cases

Test plan

  • All 10 ProcessWeeklyPayouts tests pass
  • Tests cover: happy path, skip conditions, PayoutException handling, unexpected exception bubbling, admin alerts, empty batch
  • Manual: Verify weekly schedule runs (Mondays 6am)
  • Manual: Verify admin receives email on failure
+592
additions
-31
deletions
5
files changed