Problem when I retrieve a non existing coupon ID
To fix it :
/**
* Retrieve a Coupon instance by its ID
*
* @throws HttpException:
* - If the couponId is invalid (the coupon does not exists...)
*
* @see https://stripe.com/docs/api#coupons
*
* @param string $couponId: The coupon ID
*
* @return Coupon
*/
public function retrieveCoupon($couponId)
{
try {
return Coupon::retrieve($couponId);
} catch(\Exception $e) {
return false;
}
}
Hey @megresec, thanks for the post :)
The reason I did not catch such exceptions inside the library is because I usually prefer to catch it inside a controller, to handle it properly.
$coupon = null;
try {
$coupon = $stripeClient->retrieveCoupon($couponId);
}
catch (Exception $exception) {}
if ($coupon) {
// ...
}
However, we could possibly add a method to the stripeClient (potentially with symfony configuration) to set an automatic catch of such exceptions.
What do you think about this?