Skip to content

Commit

Permalink
Fix broken unit_amount in tab
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Jun 4, 2021
1 parent beea7ed commit 9246063
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Concerns/ManagesInvoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function tab($description, $amount, array $options = [])
], $options);

if (array_key_exists('quantity', $options)) {
$options['unit_amount'] = $amount;
$options['unit_amount'] = $options['unit_amount'] ?? $amount;
} else {
$options['amount'] = $amount;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Feature/InvoicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Laravel\Cashier\Exceptions\InvalidCustomer;
use Laravel\Cashier\Exceptions\InvalidInvoice;
use Laravel\Cashier\Invoice;
use Stripe\InvoiceItem as StripeInvoiceItem;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;

class InvoicesTest extends FeatureTestCase
Expand Down Expand Up @@ -95,5 +96,14 @@ public function test_customer_can_be_invoiced_with_quantity()

$this->assertInstanceOf(Invoice::class, $response);
$this->assertEquals(5000, $response->total);

$response = $user->tab('Laracon', null, [
'unit_amount' => 1000,
'quantity' => 2,
]);

$this->assertInstanceOf(StripeInvoiceItem::class, $response);
$this->assertEquals(1000, $response->unit_amount);
$this->assertEquals(2, $response->quantity);
}
}

0 comments on commit 9246063

Please sign in to comment.