Reputation: 551
I'm testing making payments using the Stripe api in the Symfony framework.
Currently when I make a legitimate call payment is made and Stripe returns a status 200
.
The problems start when I use one of the test cards (or just a made up one) to force Stripe to return an error, card has expired for example, and an exception is thrown (Stripe_CardError
). The response code from the api is 402
but even when I put a catch block in for that exception Symfony throws a 500 internal server error
.
Here's part of the code:
require_once('../vendor/stripe/stripe-php/lib/Stripe/Stripe.php');
try{
\Stripe::setApiKey($this->container->getParameter('stripe_api_key'));
$charge = \Stripe_Charge::create(array(
"amount" => 1599,
"currency" => "usd",
"description" => "This is a test payment from post data",
"card" => array(
"number" => $data['cardNumber'],
"exp_month" => $data['expMonth'],
"exp_year" => $data['expYear']
)));
} catch(Stripe_CardError $e) {
Do error checking stuff here...
}catch (Exception $e) {
print_r($e->getMessage());
} catch (ErrorException $e) {
print_r($e->getMessage());
}
Like I say, this code works fine until an exception is thrown but when one is I seem unable to catch it and act upon it.
In the Symfony debug screen shows the correct error message is returned from the api but it does not have the correct code (should be 402
):
Your card was declined.
500 Internal Server Error - Stripe_CardError
I feel this is a Symfony config issue but numerous searches have not provided me with any solutions. Any ideas?
P.s. I am also using the FOSUserBundle.
Upvotes: 3
Views: 1356
Reputation: 551
It's What Pazi said. The Stripe error class wasn't registered in the current namespace and so needed the slash in front of it like when the create method was called. I can't believe I missed it but that's what you get for cut and paste! Thanks Pazi.
Upvotes: 2