laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.38k stars 679 forks source link

Issue with `findInvoice()` returning with an undefined variable: `stripeInvoice` #815

Closed u01jmg3 closed 5 years ago

u01jmg3 commented 5 years ago

Description:

If the invoice is not retrieved from Stripe for whatever reason, the variable $stripeInvoice will not be set.

This results in return new Invoice($this, $stripeInvoice); failing.

Perhaps there should be a check in place (e.g. if (!isset($stripeInvoice)) { return null; }) to prevent an undefined variable error. Happy to put a PR together.

/**
 * Find an invoice by ID.
 *
 * @param  string  $id
 * @return \Laravel\Cashier\Invoice|null
 */
public function findInvoice($id)
{
    try {
        $stripeInvoice = StripeInvoice::retrieve(
            $id, $this->stripeOptions()
        );
    } catch (Exception $exception) {
        //
    }

    return new Invoice($this, $stripeInvoice);
}
driesvints commented 5 years ago

Thanks! I've sent in a PR here: https://github.com/laravel/cashier/pull/817