If I call $plaid->exchangeToken($request->pubtoken); and there is an error, say a 400 error and Plaid shares back the error code (which will tell me what I need to do or tell the user), how do I handle that error, ultimately sending info back to the user, and how do I do it without writing endless logic in the controller?
@tjsherrill By using Laravel’s exception handler which is for, well, handling exceptions.
Most payment gateways give you a PHP SDK to work with. Plaid has a PHP one, albeit being third-party: https://github.com/TomorrowIdeas/plaid-sdk-php
SDKs usually throw exceptions when something happens. You can then handle those exceptions in your application’s execution handler, specifying if the exception should be converted to another exception, or what HTTP response should be displayed if that exception is encountered.
You shouldn’t be handling exceptions in your application code (controllers, console commands, queued jobs, etc) because any exceptions thrown should be handled by your application’s exception handler. Otherwise your application code will just end up stuffed full of try/catch blocks with no centralised logic for how those exceptions are dealt with.