stripe-bundle icon indicating copy to clipboard operation
stripe-bundle copied to clipboard

Problem when I retrieve a non existing coupon ID

Open megresec opened this issue 8 years ago • 1 comments

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; } }

megresec avatar Sep 28 '17 13:09 megresec

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?

flo-sch avatar Sep 28 '17 13:09 flo-sch