mirror of
https://github.com/anikeen-com/id.git
synced 2026-05-29 16:41:32 +00:00
add set default payment method
Signed-off-by: Maurice Preuß <envoyr@froxlor.org>
This commit is contained in:
@@ -55,14 +55,27 @@ trait ManagesPaymentMethods
|
|||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
* @see \Anikeen\Id\Resources\PaymentMethods::hasDefaultPaymentMethod()
|
* @see \Anikeen\Id\Resources\PaymentMethods::hasDefaultPaymentMethod()
|
||||||
*/
|
*/
|
||||||
public function hasDefaultPaymentMethod(): bool
|
public function hasDefaultPaymentMethod(): bool
|
||||||
{
|
{
|
||||||
return $this->paymentMethods()->hasDefaultPaymentMethod();
|
return $this->paymentMethods()->hasDefaultPaymentMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get billing portal URL for the current user.
|
* 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.
|
||||||
|
*
|
||||||
* @param string|null $returnUrl The URL to redirect to after the user has finished in the billing portal.
|
* @param string|null $returnUrl The URL to redirect to after the user has finished in the billing portal.
|
||||||
* @param array $options Additional options for the billing portal.
|
* @param array $options Additional options for the billing portal.
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
|
|||||||
@@ -34,20 +34,34 @@ class PaymentMethods extends BaseCollection
|
|||||||
*
|
*
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function defaultPaymentMethod(): PaymentMethod
|
public function defaultPaymentMethod(): PaymentMethod
|
||||||
{
|
{
|
||||||
if (!isset($this->defaultPaymentMethodCache)) {
|
if (!isset($this->defaultPaymentMethodCache)) {
|
||||||
$this->defaultPaymentMethodCache = (new PaymentMethod(fn() => $this->billable->anikeenId()
|
$this->defaultPaymentMethodCache = (new PaymentMethod(fn() => $this->billable->anikeenId()
|
||||||
->request('GET', 'v1/payment-methods/default')))
|
->request('GET', 'v1/payment-methods/default')))
|
||||||
->setBillable($this->billable);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->defaultPaymentMethodCache;
|
return $this->defaultPaymentMethodCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* 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
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function find(string $id): ?PaymentMethod
|
public function find(string $id): ?PaymentMethod
|
||||||
@@ -56,4 +70,4 @@ class PaymentMethods extends BaseCollection
|
|||||||
->request('GET', sprintf('v1/payment-methods/%s', $id))))
|
->request('GET', sprintf('v1/payment-methods/%s', $id))))
|
||||||
->setBillable($this->billable);
|
->setBillable($this->billable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user