Skip to content

Commit

Permalink
Return invoice object when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Jul 19, 2019
1 parent 5387b4b commit f901041
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function tab($description, $amount, array $options = [])
* @param int $amount
* @param array $tabOptions
* @param array $invoiceOptions
* @return \Stripe\Invoice|bool
* @return \Laravel\Cashier\Invoice|bool
*/
public function invoiceFor($description, $amount, array $tabOptions = [], array $invoiceOptions = [])
{
Expand Down Expand Up @@ -215,7 +215,7 @@ public function hasIncompletePayment()
* Invoice the billable entity outside of the regular billing cycle.
*
* @param array $options
* @return \Stripe\Invoice|bool
* @return \Laravel\Cashier\Invoice|bool
*/
public function invoice(array $options = [])
{
Expand All @@ -225,15 +225,17 @@ public function invoice(array $options = [])

try {
/** @var \Stripe\Invoice $invoice */
$invoice = StripeInvoice::create($parameters, Cashier::stripeOptions());
$stripeInvoice = StripeInvoice::create($parameters, Cashier::stripeOptions());

return $invoice->pay();
$stripeInvoice = $stripeInvoice->pay();

return new Invoice($this, $stripeInvoice);
} catch (StripeErrorInvalidRequest $e) {
return false;
} catch (StripeCardException $exception) {
$payment = new Payment(
StripePaymentIntent::retrieve(
['id' => $invoice->refresh()->payment_intent, 'expand' => ['invoice.subscription']],
['id' => $stripeInvoice->refresh()->payment_intent, 'expand' => ['invoice.subscription']],
Cashier::stripeOptions()
)
);
Expand Down
4 changes: 2 additions & 2 deletions src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,11 @@ public function resume()
* Invoice the subscription outside of the regular billing cycle.
*
* @param array $options
* @return \Stripe\Invoice|bool
* @return \Laravel\Cashier\Invoice|bool
*
* @throws \Laravel\Cashier\Exceptions\IncompletePayment
*/
protected function invoice(array $options = [])
public function invoice(array $options = [])
{
try {
return $this->user->invoice(array_merge($options, ['subscription' => $this->stripe_id]));
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/InvoicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Laravel\Cashier\Tests\Integration;

use Stripe\Invoice;
use Laravel\Cashier\Invoice;
use Laravel\Cashier\Exceptions\InvalidStripeCustomer;

class InvoicesTest extends IntegrationTestCase
Expand Down

0 comments on commit f901041

Please sign in to comment.