Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Loosen exception throwing #882

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function charge($amount, $paymentMethod, array $options = [])
$options['amount'] = $amount;
$options['payment_method'] = $paymentMethod;

if ($this->stripe_id) {
if ($this->hasStripeId()) {
$options['customer'] = $this->stripe_id;
}

Expand Down Expand Up @@ -264,7 +264,9 @@ public function invoice(array $options = [])
*/
public function upcomingInvoice()
{
$this->assertCustomerExists();
if (! $this->hasStripeId()) {
return;
}

try {
$stripeInvoice = StripeInvoice::upcoming(['customer' => $this->stripe_id], $this->stripeOptions());
Expand Down Expand Up @@ -338,7 +340,9 @@ public function downloadInvoice($id, array $data)
*/
public function invoices($includePending = false, $parameters = [])
{
$this->assertCustomerExists();
if (! $this->hasStripeId()) {
return collect();
}

$invoices = [];

Expand Down Expand Up @@ -415,7 +419,9 @@ public function hasPaymentMethod()
*/
public function paymentMethods($parameters = [])
{
$this->assertCustomerExists();
if (! $this->hasStripeId()) {
return collect();
}

$parameters = array_merge(['limit' => 24], $parameters);

Expand Down Expand Up @@ -733,7 +739,7 @@ public function hasStripeId()
*/
protected function assertCustomerExists()
{
if (! $this->stripe_id) {
if (! $this->hasStripeId()) {
throw InvalidStripeCustomer::nonCustomer($this);
}
}
Expand All @@ -746,7 +752,7 @@ protected function assertCustomerExists()
*/
public function createAsStripeCustomer(array $options = [])
{
if ($this->stripe_id) {
if ($this->hasStripeId()) {
throw InvalidStripeCustomer::exists($this);
}

Expand Down Expand Up @@ -789,7 +795,7 @@ public function updateStripeCustomer(array $options = [])
*/
public function createOrGetStripeCustomer(array $options = [])
{
if ($this->stripe_id) {
if ($this->hasStripeId()) {
return $this->asStripeCustomer();
}

Expand Down