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

@@ -34,20 +34,34 @@ class PaymentMethods extends BaseCollection
*
* @throws Throwable
*/
public function defaultPaymentMethod(): PaymentMethod
{
if (!isset($this->defaultPaymentMethodCache)) {
$this->defaultPaymentMethodCache = (new PaymentMethod(fn() => $this->billable->anikeenId()
->request('GET', 'v1/payment-methods/default')))
public function defaultPaymentMethod(): PaymentMethod
{
if (!isset($this->defaultPaymentMethodCache)) {
$this->defaultPaymentMethodCache = (new PaymentMethod(fn() => $this->billable->anikeenId()
->request('GET', 'v1/payment-methods/default')))
->setBillable($this->billable);
}
return $this->defaultPaymentMethodCache;
}
/**
* {@inheritDoc}
*
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}
*
* @throws Throwable
*/
public function find(string $id): ?PaymentMethod
@@ -56,4 +70,4 @@ class PaymentMethods extends BaseCollection
->request('GET', sprintf('v1/payment-methods/%s', $id))))
->setBillable($this->billable);
}
}
}