Create Wallets.php

This commit is contained in:
2022-09-29 14:41:26 +02:00
committed by GitHub
parent 4fdbe165bc
commit 91bdad593f

View File

@@ -0,0 +1,49 @@
<?php
namespace Bitinflow\Accounts\Traits\BitinflowPaymentsWallet;
use App\Models\User;
class Wallets
{
public function __construct(protected User $user)
{
//
}
/**
* Get all wallets that belongs to the user.
*
* @return array|null
*/
public function get(): ?array
{
return $this->user->getPaymentsUser()->data->wallets;
}
/**
* Check if user has an active wallet.
*
* @return bool
* @throws GuzzleException
*/
public function has(): ?bool
{
return $this->user->getPaymentsUser()->data->has_wallet;
}
/**
* Set default wallet to given wallet token.
*
* @param string $token default payment method token
* @return bool
*/
public function setDefault(string $token): bool
{
$this->user->asPaymentsUser('PUT', sprintf('wallets/default', [
'token' => $token
]));
return true;
}
}