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

[15.x] Fetch all payment methods #1617

Merged
merged 1 commit into from
Dec 13, 2023
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
18 changes: 9 additions & 9 deletions src/Concerns/ManagesPaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ public function hasDefaultPaymentMethod()
}

/**
* Determines if the customer currently has at least one payment method of the given type.
* Determines if the customer currently has at least one payment method of an optional type.
*
* @param string $type
* @param string|null $type
* @return bool
*/
public function hasPaymentMethod($type = 'card')
public function hasPaymentMethod($type = null)
{
return $this->paymentMethods($type)->isNotEmpty();
}

/**
* Get a collection of the customer's payment methods of the given type.
* Get a collection of the customer's payment methods of an optional type.
*
* @param string $type
* @param string|null $type
* @param array $parameters
* @return \Illuminate\Support\Collection|\Laravel\Cashier\PaymentMethod[]
*/
public function paymentMethods($type = 'card', $parameters = [])
public function paymentMethods($type = null, $parameters = [])
{
if (! $this->hasStripeId()) {
return new Collection();
Expand All @@ -77,7 +77,7 @@ public function paymentMethods($type = 'card', $parameters = [])

// "type" is temporarily required by Stripe...
$paymentMethods = static::stripe()->paymentMethods->all(
['customer' => $this->stripe_id, 'type' => $type] + $parameters
array_filter(['customer' => $this->stripe_id, 'type' => $type]) + $parameters
);

return Collection::make($paymentMethods->data)->map(function ($paymentMethod) {
Expand Down Expand Up @@ -266,10 +266,10 @@ protected function fillSourceDetails($source)
/**
* Deletes the customer's payment methods of the given type.
*
* @param string $type
* @param string|null $type
* @return void
*/
public function deletePaymentMethods($type = 'card')
public function deletePaymentMethods($type = null)
{
$this->paymentMethods($type)->each(function (PaymentMethod $paymentMethod) {
$paymentMethod->delete();
Expand Down