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] Add new has payment method #838

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,25 @@ public function createSetupIntent(array $options = [])
}

/**
* Determines if the customer currently has a payment method.
* Determines if the customer currently has a default payment method.
*
* @return bool
*/
public function hasPaymentMethod()
public function hasDefaultPaymentMethod()
{
return (bool) $this->card_brand;
}

/**
* Determines if the customer currently has at least one payment method.
*
* @return bool
*/
public function hasPaymentMethod()
{
return $this->paymentMethods()->isNotEmpty();
}

/**
* Get a collection of the entity's payment methods.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/PaymentMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function test_we_can_add_payment_methods()
$this->assertInstanceOf(PaymentMethod::class, $paymentMethod);
$this->assertEquals('visa', $paymentMethod->card->brand);
$this->assertEquals('4242', $paymentMethod->card->last4);
$this->assertTrue($user->hasPaymentMethod());
$this->assertFalse($user->hasDefaultPaymentMethod());
}

public function test_we_can_remove_payment_methods()
Expand All @@ -38,10 +40,12 @@ public function test_we_can_remove_payment_methods()
$paymentMethod = $user->addPaymentMethod('pm_card_visa');

$this->assertCount(1, $user->paymentMethods());
$this->assertTrue($user->hasPaymentMethod());

$user->removePaymentMethod($paymentMethod->asStripePaymentMethod());

$this->assertCount(0, $user->paymentMethods());
$this->assertFalse($user->hasPaymentMethod());
}

public function test_we_can_remove_the_default_payment_method()
Expand All @@ -52,13 +56,17 @@ public function test_we_can_remove_the_default_payment_method()
$paymentMethod = $user->updateDefaultPaymentMethod('pm_card_visa');

$this->assertCount(1, $user->paymentMethods());
$this->assertTrue($user->hasPaymentMethod());
$this->assertTrue($user->hasDefaultPaymentMethod());

$user->removePaymentMethod($paymentMethod->asStripePaymentMethod());

$this->assertCount(0, $user->paymentMethods());
$this->assertNull($user->defaultPaymentMethod());
$this->assertNull($user->card_brand);
$this->assertNull($user->card_last_four);
$this->assertFalse($user->hasPaymentMethod());
$this->assertFalse($user->hasDefaultPaymentMethod());
}

public function test_we_can_set_a_default_payment_method()
Expand All @@ -71,6 +79,7 @@ public function test_we_can_set_a_default_payment_method()
$this->assertInstanceOf(PaymentMethod::class, $paymentMethod);
$this->assertEquals('visa', $paymentMethod->card->brand);
$this->assertEquals('4242', $paymentMethod->card->last4);
$this->assertTrue($user->hasDefaultPaymentMethod());

$paymentMethod = $user->defaultPaymentMethod();

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function test_we_can_determine_if_it_has_a_payment_method()
$user = new User;
$user->card_brand = 'visa';

$this->assertTrue($user->hasPaymentMethod());
$this->assertTrue($user->hasDefaultPaymentMethod());

$user = new User;

$this->assertFalse($user->hasPaymentMethod());
$this->assertFalse($user->hasDefaultPaymentMethod());
}

public function test_default_payment_method_returns_null_when_the_user_is_not_a_customer_yet()
Expand Down