-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #682 from laravel/fix-invoice-non-customers
[10.0] Throw exception when no stripe id is found
- Loading branch information
Showing
3 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Laravel\Cashier\Exceptions; | ||
|
||
use Exception; | ||
|
||
class InvalidStripeCustomer extends Exception | ||
{ | ||
/** | ||
* Create a new CustomerFailure instance. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Model $owner | ||
* @return self | ||
*/ | ||
public static function nonCustomer($owner) | ||
{ | ||
return new static(class_basename($owner).' is not a Stripe customer. See the createAsStripeCustomer method.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Laravel\Cashier\Tests\Integration; | ||
|
||
use Stripe\Invoice; | ||
use Laravel\Cashier\Exceptions\InvalidStripeCustomer; | ||
|
||
class InvoicesTest extends IntegrationTestCase | ||
{ | ||
public function test_require_stripe_customer_for_invoicing() | ||
{ | ||
$user = $this->createCustomer('require_stripe_customer_for_invoicing'); | ||
|
||
$this->expectException(InvalidStripeCustomer::class); | ||
|
||
$user->invoice(); | ||
} | ||
|
||
public function test_invoicing_fails_with_nothing_to_invoice() | ||
{ | ||
$user = $this->createCustomer('invoicing_fails_with_nothing_to_invoice'); | ||
$user->createAsStripeCustomer(); | ||
$user->updateCard('tok_visa'); | ||
|
||
$response = $user->invoice(); | ||
|
||
$this->assertFalse($response); | ||
} | ||
|
||
public function test_customer_can_be_invoiced() | ||
{ | ||
$user = $this->createCustomer('customer_can_be_invoiced'); | ||
$user->createAsStripeCustomer(); | ||
$user->updateCard('tok_visa'); | ||
|
||
$response = $user->invoiceFor('Laracon', 49900); | ||
|
||
$this->assertInstanceOf(Invoice::class, $response); | ||
$this->assertEquals(49900, $response->total); | ||
} | ||
} |