Create Balance.php

This commit is contained in:
2022-09-29 14:54:37 +02:00
committed by GitHub
parent 7dad10bd47
commit 78f570f404

View File

@@ -0,0 +1,57 @@
<?php
namespace Bitinflow\Accounts\Traits\BitinflowPaymentsWallet;
use App\Models\User;
class Balance
{
public function __construct(protected User $user)
{
//
}
/**
* Get balance from user.
*
* @return float|null
*/
public function get(): ?float
{
return $this->user->getPaymentsUser()->data->balance;
}
/**
* Deposit given amount from bank to account.
*
* @param float $amount
* @param string $description
* @return bool
*/
public function deposit(float $amount, string $decription): bool
{
$this->user->asPaymentsUser('PUT', sprintf('wallet/deposit', [
'amount' => $amount,
'decription' => $decription,
]));
}
/**
* Charge given amount from account.
*
* @param float $amount
* @param string $decription
* @return bool
*/
public function charge(float $amount, string $decription): bool
{
$order = $this->user->orders()->create([
'name' => $decription,
'description' => 'one-time payment',
'amount' => 1,
'price' => $amount,
]);
return $this->user->orders()->checkout($order->id);
}
}