How can I catch exception and redirect to my on message in Cartalyst/Stripe Laravel. I have Tried to add catch block in below mentioned code I want to catch errors in catch block
<?php
namespace App\Http\Controllers;
use Cartalyst\Stripe\Laravel\Facades\Stripe;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
class BuyNowController extends Controller
{
public function buyNow(Request $request)
{
try {
$charge = Stripe::charges()->create([
'amount' => $request->total,
'currency' => 'CAD',
'source' => $request->stripeToken,
'description' => 'Description goes here',
'receipt_email' => $request->email,
'metadata' => [
'country'=>$request->country,
'address'=>$request->address,
'postal code'=>$request->postalcode,
'data1' => 'metadata 1',
'data2' => 'metadata 2',
'data3' => 'metadata 3',
],
]);
}
catch (CardErrorException $e) {
// save info to database for failed
return back()->withErrors('Error! ' . $e->getMessage());
}
}
}