mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-15 06:36:14 +00:00
refactored code
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
53
src/Id/Concerns/ManagesBalance.php
Normal file
53
src/Id/Concerns/ManagesBalance.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Concerns;
|
||||
|
||||
use Anikeen\Id\ApiOperations\Request;
|
||||
use Anikeen\Id\Exceptions\RequestRequiresClientIdException;
|
||||
use Anikeen\Id\Result;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
|
||||
trait ManagesBalance
|
||||
{
|
||||
use Request;
|
||||
|
||||
/**
|
||||
* Get balance from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function balance(): float
|
||||
{
|
||||
return $this->getUserData()->current_balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get charges from the current user.
|
||||
*
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function charges(): float
|
||||
{
|
||||
return $this->getUserData()->current_charges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge given amount from bank to current user.
|
||||
*
|
||||
* @param float $amount Amount to charge in euros.
|
||||
* @param string $paymentMethodId Payment method ID.
|
||||
* @param array $options Additional options for the charge.
|
||||
* @throws RequestRequiresClientIdException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function charge(float $amount, string $paymentMethodId, array $options = []): Result
|
||||
{
|
||||
return $this->request('POST', 'billing/charge', [
|
||||
'amount' => $amount,
|
||||
'payment_method_id' => $paymentMethodId,
|
||||
'options' => $options,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user