Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem when I retrieve a non existing coupon ID #3

Open
megresec opened this issue Sep 28, 2017 · 1 comment
Open

Problem when I retrieve a non existing coupon ID #3

megresec opened this issue Sep 28, 2017 · 1 comment

Comments

@megresec
Copy link

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

@flo-sch
Copy link
Owner

flo-sch commented Sep 28, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants