Skip to content

Commit

Permalink
Fix latest_invoice retrieval (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Apr 8, 2021
1 parent 01613c3 commit d83e266
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -1062,13 +1062,15 @@ public function invoice(array $options = [])
/**
* Get the latest invoice for the subscription.
*
* @return \Laravel\Cashier\Invoice
* @return \Laravel\Cashier\Invoice|null
*/
public function latestInvoice()
{
$stripeSubscription = $this->asStripeSubscription(['latest_invoice']);

return new Invoice($this->owner, $stripeSubscription->latest_invoice);
if ($stripeSubscription->latest_invoice) {
return new Invoice($this->owner, $stripeSubscription->latest_invoice);
}
}

/**
Expand Down Expand Up @@ -1142,13 +1144,13 @@ public function hasIncompletePayment()
*/
public function latestPayment()
{
$paymentIntent = $this->asStripeSubscription(['latest_invoice.payment_intent'])
->latest_invoice
->payment_intent;
$subscription = $this->asStripeSubscription(['latest_invoice.payment_intent']);

return $paymentIntent
? new Payment($paymentIntent)
: null;
if ($invoice = $subscription->latest_invoice) {
return $invoice->payment_intent
? new Payment($invoice->payment_intent)
: null;
}
}

/**
Expand Down

0 comments on commit d83e266

Please sign in to comment.