add set default payment method

Signed-off-by: Maurice Preuß <envoyr@froxlor.org>
This commit is contained in:
Maurice Preuß
2026-05-17 16:46:06 +02:00
parent 4555efa80c
commit a7ec7aa908
2 changed files with 48 additions and 21 deletions

View File

@@ -60,6 +60,19 @@ trait ManagesPaymentMethods
return $this->paymentMethods()->hasDefaultPaymentMethod(); return $this->paymentMethods()->hasDefaultPaymentMethod();
} }
/**
* Set the default payment method for the current user.
*
* @throws Throwable
* @see \Anikeen\Id\Resources\PaymentMethods::setDefault()
*/
public function setDefaultPaymentMethod(string $id): PaymentMethod
{
unset($this->paymentMethodsCache);
return $this->paymentMethods()->setDefault($id);
}
/** /**
* Get billing portal URL for the current user. * Get billing portal URL for the current user.
* *

View File

@@ -45,6 +45,20 @@ class PaymentMethods extends BaseCollection
return $this->defaultPaymentMethodCache; return $this->defaultPaymentMethodCache;
} }
/**
* Set the default payment method for the current user.
*
* @throws Throwable
*/
public function setDefault(string $id): PaymentMethod
{
unset($this->defaultPaymentMethodCache);
return (new PaymentMethod(fn() => $this->billable->anikeenId()
->request('PUT', sprintf('v1/payment-methods/%s/default', $id))))
->setBillable($this->billable);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
* *