I am using stripe payment gateway in my project. i am trying to display exception errors when user entered expired card number. but instead of showing me error of exception it shows me laravel error. Note: it is not working with any kind of exception not only expired card number.
I am using exception provided by Stripe.
public function recharge(Request $request)
{
$this->validate($request,[
'amount' => 'required',
]);
$amount = $request->input('amount');
\Stripe\Stripe::setApiKey('key_here');
try{
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
'amount' => $amount * 100,
'currency' => 'usd',
'description' => 'Example charge',
'source' => $token,
]);
$user = User::find(Auth::user()->id);
$user->deposit($amount);
Session::flash('success','Your Wallet is recharged!');
return back();
}
catch(\Stripe\Error\Card $e) {
// Since it's a decline, \Stripe\Error\Card will be caught
$body = $e->getJsonBody();
$err = $body['error'];
print('Status is:' . $e->getHttpStatus() . "\n");
print('Type is:' . $err['type'] . "\n");
print('Code is:' . $err['code'] . "\n");
// param is '' in this case
print('Param is:' . $err['param'] . "\n");
print('Message is:' . $err['message'] . "\n");
} catch (\Stripe\Error\InvalidRequest $e) {
return "error";
} catch (\Stripe\Error\Authentication $e) {
return "error";
} catch (\Stripe\Error\ApiConnection $e) {
// Network communication with Stripe failed
return "error";
} catch (\Stripe\Error\Base $e) {
return "error";
} catch (Exception $e) {
return "error";
}
}
I want to display error defined by me in catch block.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire