Skip to content

Commit

Permalink
register tax collection service
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Oct 10, 2024
1 parent 2e1ea7a commit c57f536
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use Bavix\Wallet\Services\PrepareService;
use Bavix\Wallet\Services\PurchaseService;
use Bavix\Wallet\Services\RegulatorService;
use Bavix\Wallet\Services\TaxCollectionService;

Check notice on line 52 in config/config.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Usage of internal entity

Class 'TaxCollectionService' is marked as @internal
use Bavix\Wallet\Services\TaxService;
use Bavix\Wallet\Services\TransactionService;
use Bavix\Wallet\Services\TransferService;
Expand Down Expand Up @@ -265,6 +266,8 @@
'purchase' => PurchaseService::class,
// Service for handling tax operations.
'tax' => TaxService::class,
// Service for handling tax collection operations.
'tax_collection' => TaxCollectionService::class,

Check notice on line 270 in config/config.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Usage of internal entity

Class 'TaxCollectionService' is marked as @internal
// Service for handling transaction operations.
'transaction' => TransactionService::class,
// Service for handling transfer operations.
Expand Down
3 changes: 3 additions & 0 deletions src/Services/TaxCollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Bavix\Wallet\Interfaces\Wallet;
use Bavix\Wallet\Internal\Service\MathServiceInterface;

/**
* @internal
*/
final readonly class TaxCollectionService implements TaxCollectionServiceInterface
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions src/Services/TaxCollectionServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Bavix\Wallet\External\Enums\TransactionType;
use Bavix\Wallet\Interfaces\Wallet;

/**
* @api
*/
interface TaxCollectionServiceInterface
{
public function calculate(TransactionType $type, Wallet $wallet, float|int|string $amount): string;
Expand Down
16 changes: 15 additions & 1 deletion src/Services/TaxService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,39 @@

namespace Bavix\Wallet\Services;

use Bavix\Wallet\External\Enums\TransactionType;
use Bavix\Wallet\Interfaces\MaximalTaxable;
use Bavix\Wallet\Interfaces\MinimalTaxable;
use Bavix\Wallet\Interfaces\Taxable;
use Bavix\Wallet\Interfaces\TaxInterface;
use Bavix\Wallet\Interfaces\Wallet;
use Bavix\Wallet\Internal\Service\MathServiceInterface;

/**
* @internal
* @deprecated use TaxCollectionServiceInterface instead.
* @see TaxCollectionServiceInterface
*/
final readonly class TaxService implements TaxServiceInterface
{
public function __construct(
private MathServiceInterface $mathService,
private CastServiceInterface $castService
private CastServiceInterface $castService,
private TaxCollectionServiceInterface $taxCollectionService
) {
}

public function getFee(Wallet $wallet, float|int|string $amount): string
{
if ($wallet instanceof TaxInterface) {
return $this->taxCollectionService->calculate(
TransactionType::Withdraw,
$wallet,

Check warning on line 34 in src/Services/TaxService.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Parameter type

Parameter '$wallet' type is not compatible with declaration
$amount,
);
}

// backward compatibility
$fee = 0;
if ($wallet instanceof Taxable) {
$fee = $this->mathService->floor(
Expand Down
5 changes: 5 additions & 0 deletions src/WalletServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
use Bavix\Wallet\Services\PurchaseServiceInterface;
use Bavix\Wallet\Services\RegulatorService;
use Bavix\Wallet\Services\RegulatorServiceInterface;
use Bavix\Wallet\Services\TaxCollectionService;
use Bavix\Wallet\Services\TaxCollectionServiceInterface;
use Bavix\Wallet\Services\TaxService;
use Bavix\Wallet\Services\TaxServiceInterface;
use Bavix\Wallet\Services\TransactionService;
Expand All @@ -121,6 +123,7 @@
use Illuminate\Database\Events\TransactionRolledBack;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
use Laravel\Cashier\Tax;

final class WalletServiceProvider extends ServiceProvider implements DeferrableProvider
{
Expand Down Expand Up @@ -285,6 +288,7 @@ private function services(array $configure, array $cache): void
$this->app->singleton(FormatterServiceInterface::class, $configure['formatter'] ?? FormatterService::class);
$this->app->singleton(PrepareServiceInterface::class, $configure['prepare'] ?? PrepareService::class);
$this->app->singleton(PurchaseServiceInterface::class, $configure['purchase'] ?? PurchaseService::class);
$this->app->singleton(TaxCollectionServiceInterface::class, $configure['tax_collection'] ?? TaxCollectionService::class);
$this->app->singleton(TaxServiceInterface::class, $configure['tax'] ?? TaxService::class);
$this->app->singleton(
TransactionServiceInterface::class,
Expand Down Expand Up @@ -479,6 +483,7 @@ private function servicesProviders(): array
FormatterServiceInterface::class,
PrepareServiceInterface::class,
PurchaseServiceInterface::class,
TaxCollectionServiceInterface::class,
TaxServiceInterface::class,
TransactionServiceInterface::class,
TransferServiceInterface::class,
Expand Down

0 comments on commit c57f536

Please sign in to comment.