Sometimes IRBM returns 5xx errors or transient failures. Instead of forcing users to retry manually, we can automatically retry failed submissions using Laravel’s queue and job retry mechanism.
✅ Create a job class:
php artisan make:job SubmitInvoiceToIRB
Inside SubmitInvoiceToIRB
:
public $tries = 3;
public $backoff = [60, 300, 600]; // retry in 1 min, 5 min, 10 min
public function handle()
{
if ($invoice->irb_uuid) {
return; // already submitted
}
try {
$response = $this->irbService->submitInvoice($invoice);
$invoice->update([
'irb_uuid' => $response['uuid'],
'irb_status' => $response['invoiceStatus'],
'irb_submitted_at' => now(),
]);
} catch (\Throwable $e) {
\Log::error("IRB submit failed", ['id' => $invoice->id, 'error' => $e->getMessage()]);
throw $e; // triggers retry
}
}
✅ Dispatch with:
SubmitInvoiceToIRB::dispatch($invoice);
💡 Benefits:
- Retry logic is automatic
- Backoff helps avoid spamming IRBM
- Cleaner UX for the user
Coming up in Day 5:
We’ll fetch and update the IRBM invoice status using the UUID we stored earlier.