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

[13.x] Add deletePaymentMethod #1298

Merged
merged 1 commit into from
Jan 7, 2022
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
17 changes: 15 additions & 2 deletions src/Concerns/ManagesPaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public function addPaymentMethod($paymentMethod)
}

/**
* Remove a payment method from the customer.
* Delete a payment method from the customer.
*
* @param \Stripe\PaymentMethod|string $paymentMethod
* @return void
*/
public function removePaymentMethod($paymentMethod)
public function deletePaymentMethod($paymentMethod)
{
$this->assertCustomerExists();

Expand All @@ -118,6 +118,19 @@ public function removePaymentMethod($paymentMethod)
}
}

/**
* Remove a payment method from the customer.
*
* @param \Stripe\PaymentMethod|string $paymentMethod
* @return void
*
* @deprecated Will be removed in a future Cashier Stripe version. Use deletePaymentMethod() instead.
*/
public function removePaymentMethod($paymentMethod)
{
return $this->deletePaymentMethod($paymentMethod);
}

/**
* Get the default payment method for the customer.
*
Expand Down
2 changes: 1 addition & 1 deletion src/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct($owner, StripePaymentMethod $paymentMethod)
*/
public function delete()
{
return $this->owner->removePaymentMethod($this->paymentMethod);
return $this->owner->deletePaymentMethod($this->paymentMethod);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/Feature/PaymentMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ public function test_we_can_add_default_sepa_payment_method()
$this->assertTrue($user->hasDefaultPaymentMethod());
}

public function test_we_can_remove_payment_methods()
public function test_we_can_delete_payment_methods()
{
$user = $this->createCustomer('we_can_remove_payment_methods');
$user = $this->createCustomer('we_can_delete_payment_methods');
$user->createAsStripeCustomer();

$paymentMethod = $user->addPaymentMethod('pm_card_visa');

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

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

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

public function test_we_can_remove_the_default_payment_method()
public function test_we_can_delete_the_default_payment_method()
{
$user = $this->createCustomer('we_can_remove_the_default_payment_method');
$user = $this->createCustomer('we_can_delete_the_default_payment_method');
$user->createAsStripeCustomer();

$paymentMethod = $user->updateDefaultPaymentMethod('pm_card_visa');
Expand All @@ -84,7 +84,7 @@ public function test_we_can_remove_the_default_payment_method()
$this->assertTrue($user->hasPaymentMethod());
$this->assertTrue($user->hasDefaultPaymentMethod());

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

$this->assertCount(0, $user->paymentMethods());
$this->assertNull($user->defaultPaymentMethod());
Expand Down