Move Accounting and Gateway from prefixes to namespaces

This commit is contained in:
2024-11-05 14:32:59 +01:00
parent ab9b73747c
commit 3f012c9542
39 changed files with 266 additions and 243 deletions
@@ -1,14 +1,14 @@
<?php
namespace App\ApiResource;
namespace App\ApiResource\Accounting;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata as API;
use App\Entity\Accounting;
use App\Entity\Accounting as Entity;
use App\Entity\Interface\AccountingOwnerInterface;
use App\Entity\Interface\ApiResource;
use App\State\AccountingStateProcessor;
use App\State\AccountingStateProvider;
use App\State\Accounting\AccountingStateProcessor;
use App\State\Accounting\AccountingStateProvider;
/**
* Accountings represent payment services used to perform the necessary payments for Transactions between Accounts.\
@@ -27,10 +27,10 @@ use App\State\AccountingStateProvider;
processor: AccountingStateProcessor::class,
security: 'is_granted("ACCOUNTING_EDIT", object)'
)]
class AccountingApiResource
class Accounting
{
public function __construct(
private readonly Accounting $accounting,
private readonly Entity\Accounting $accounting,
private readonly AccountingOwnerInterface $owner,
) {}
@@ -1,6 +1,6 @@
<?php
namespace App\ApiResource;
namespace App\ApiResource\Gateway;
use ApiPlatform\Metadata as API;
use App\Library\Economy\Payment\GatewayInterface;
@@ -16,7 +16,7 @@ use App\State\GatewayStateProvider;
#[API\ApiResource(shortName: 'Gateway')]
#[API\GetCollection(provider: GatewayStateProvider::class)]
#[API\Get(provider: GatewayStateProvider::class)]
class GatewayApiResource
class Gateway
{
public function __construct(private readonly GatewayInterface $gateway) {}
@@ -29,7 +29,7 @@ class GatewayApiResource
/**
* The GatewayCharge types that can be processed by this Gateway.
*
* @return \App\Entity\GatewayChargeType[]
* @return \App\Entity\Gateway\ChargeType[]
*/
public function getSupported(): array
{
@@ -1,9 +1,9 @@
<?php
namespace App\Entity;
namespace App\Entity\Accounting;
use App\Entity\Interface\AccountingOwnerInterface;
use App\Repository\AccountingRepository;
use App\Repository\Accounting\AccountingRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@@ -1,9 +1,10 @@
<?php
namespace App\Entity;
namespace App\Entity\Accounting;
use ApiPlatform\Metadata as API;
use App\Repository\AccountingTransactionRepository;
use App\Entity\Money;
use App\Repository\Accounting\TransactionRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
@@ -16,8 +17,8 @@ use Symfony\Component\Validator\Constraints as Assert;
* AccountingTransactions are generated for each GatewayCharge in a GatewayCheckout once it becomes successful.
*/
#[API\Get()]
#[ORM\Entity(repositoryClass: AccountingTransactionRepository::class)]
class AccountingTransaction
#[ORM\Entity(repositoryClass: TransactionRepository::class)]
class Transaction
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -1,9 +1,12 @@
<?php
namespace App\Entity;
namespace App\Entity\Gateway;
use ApiPlatform\Metadata as API;
use App\Repository\GatewayChargeRepository;
use App\Entity\Accounting\Accounting;
use App\Entity\Accounting\Transaction;
use App\Entity\Money;
use App\Repository\Gateway\ChargeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
@@ -14,8 +17,8 @@ use Symfony\Component\Validator\Constraints as Assert;
* A GatewayCharge represents a monetary payment that can be done by an issuer at checkout with the Gateway.
*/
#[API\Get()]
#[ORM\Entity(repositoryClass: GatewayChargeRepository::class)]
class GatewayCharge
#[ORM\Entity(repositoryClass: ChargeRepository::class)]
class Charge
{
#[ORM\Id]
#[ORM\GeneratedValue]
@@ -24,14 +27,14 @@ class GatewayCharge
#[API\ApiProperty(readable: false, writable: false)]
#[ORM\ManyToOne(inversedBy: 'charges')]
private ?GatewayCheckout $checkout = null;
private ?Checkout $checkout = null;
/**
* The type represents the kind of payment for the charged money.
*/
#[Assert\NotBlank()]
#[ORM\Column()]
private ?GatewayChargeType $type = null;
private ?ChargeType $type = null;
/**
* A short, descriptive text for this charge operation.
@@ -62,10 +65,10 @@ class GatewayCharge
private ?Money $money = null;
/**
* @var Collection<int, AccountingTransaction>
* @var Collection<int, Transaction>
*/
#[API\ApiProperty(readableLink: false, writable: false)]
#[ORM\ManyToMany(targetEntity: AccountingTransaction::class, cascade: ['persist'])]
#[ORM\ManyToMany(targetEntity: Transaction::class, cascade: ['persist'])]
private Collection $transactions;
public function __construct()
@@ -78,24 +81,24 @@ class GatewayCharge
return $this->id;
}
public function getCheckout(): ?GatewayCheckout
public function getCheckout(): ?Checkout
{
return $this->checkout;
}
public function setCheckout(?GatewayCheckout $checkout): static
public function setCheckout(?Checkout $checkout): static
{
$this->checkout = $checkout;
return $this;
}
public function getType(): ?GatewayChargeType
public function getType(): ?ChargeType
{
return $this->type;
}
public function setType(GatewayChargeType $type): static
public function setType(ChargeType $type): static
{
$this->type = $type;
@@ -151,14 +154,14 @@ class GatewayCharge
}
/**
* @return Collection<int, AccountingTransaction>
* @return Collection<int, Transaction>
*/
public function getTransactions(): Collection
{
return $this->transactions;
}
public function addTransaction(AccountingTransaction $transaction): static
public function addTransaction(Transaction $transaction): static
{
if (!$this->transactions->contains($transaction)) {
$this->transactions->add($transaction);
@@ -167,7 +170,7 @@ class GatewayCharge
return $this;
}
public function removeTransaction(AccountingTransaction $transaction): static
public function removeTransaction(Transaction $transaction): static
{
$this->transactions->removeElement($transaction);
@@ -1,8 +1,8 @@
<?php
namespace App\Entity;
namespace App\Entity\Gateway;
enum GatewayChargeType: string
enum ChargeType: string
{
/**
* A one-time charge to the money payer.
@@ -1,12 +1,13 @@
<?php
namespace App\Entity;
namespace App\Entity\Gateway;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata as API;
use App\Entity\Accounting\Accounting;
use App\Entity\Trait\TimestampableCreationEntity;
use App\Entity\Trait\TimestampableUpdationEntity;
use App\Repository\GatewayCheckoutRepository;
use App\Repository\Gateway\CheckoutRepository;
use App\State\GatewayCheckoutProcessor;
use App\Validator\GatewayName;
use App\Validator\SupportedChargeTypes;
@@ -20,16 +21,16 @@ use Symfony\Component\Validator\Constraints as Assert;
* A GatewayCheckout bundles the data to perform a payment operation with a Gateway.\
* \
* Once the Gateway validates the payment as successful the GatewayCheckout will be updated
* and respective AccountingTransactions will be generated for each GatewayCharge.
* and respective AccountingTransactions will be generated for each Charge.
*/
#[Gedmo\Loggable()]
#[API\GetCollection()]
#[API\Post(processor: GatewayCheckoutProcessor::class)]
#[API\Get()]
#[API\ApiFilter(filterClass: SearchFilter::class, properties: ['origin' => 'exact', 'charges.target' => 'exact'])]
#[ORM\Entity(repositoryClass: GatewayCheckoutRepository::class)]
#[ORM\Entity(repositoryClass: CheckoutRepository::class)]
#[ORM\Index(fields: ['migratedId'])]
class GatewayCheckout
class Checkout
{
use TimestampableCreationEntity;
use TimestampableUpdationEntity;
@@ -54,18 +55,18 @@ class GatewayCheckout
#[API\ApiProperty(writable: false)]
#[API\ApiFilter(SearchFilter::class)]
#[ORM\Column()]
private ?GatewayCheckoutStatus $status = null;
private ?CheckoutStatus $status = null;
/**
* The GatewayCharges to be charged at checkout with the gateway.
*
* @var Collection<int, GatewayCharge>
* @var Collection<int, Charge>
*/
#[API\ApiProperty(readableLink: true, writableLink: true)]
#[Assert\NotBlank()]
#[Assert\Count(min: 1)]
#[SupportedChargeTypes()]
#[ORM\OneToMany(mappedBy: 'checkout', targetEntity: GatewayCharge::class, cascade: ['persist'])]
#[ORM\OneToMany(mappedBy: 'checkout', targetEntity: Charge::class, cascade: ['persist'])]
private Collection $charges;
/**
@@ -81,7 +82,7 @@ class GatewayCheckout
* A list of URLs provided by the Gateway for this checkout.\
* e.g: Fulfill payment, API resource address.
*
* @var GatewayLink[]
* @var Link[]
*/
#[API\ApiProperty(writable: false)]
#[ORM\Column]
@@ -91,7 +92,7 @@ class GatewayCheckout
* A list of tracking codes provided by the Gateway for this checkout.\
* e.g: Order ID, Payment Capture ID, Checkout Session Token.
*
* @var GatewayTracking[]
* @var Tracking[]
*/
#[API\ApiProperty(writable: false)]
#[ORM\Column]
@@ -119,7 +120,7 @@ class GatewayCheckout
public function __construct()
{
$this->status = GatewayCheckoutStatus::Pending;
$this->status = CheckoutStatus::Pending;
$this->charges = new ArrayCollection();
}
@@ -140,12 +141,12 @@ class GatewayCheckout
return $this;
}
public function getStatus(): ?GatewayCheckoutStatus
public function getStatus(): ?CheckoutStatus
{
return $this->status;
}
public function setStatus(GatewayCheckoutStatus $status): static
public function setStatus(CheckoutStatus $status): static
{
$this->status = $status;
@@ -153,14 +154,14 @@ class GatewayCheckout
}
/**
* @return Collection<int, GatewayCharge>
* @return Collection<int, Charge>
*/
public function getCharges(): Collection
{
return $this->charges;
}
public function addCharge(GatewayCharge $charge): static
public function addCharge(Charge $charge): static
{
if (!$this->charges->contains($charge)) {
$this->charges->add($charge);
@@ -170,7 +171,7 @@ class GatewayCheckout
return $this;
}
public function removeCharge(GatewayCharge $charge): static
public function removeCharge(Charge $charge): static
{
if ($this->charges->removeElement($charge)) {
// set the owning side to null (unless already changed)
@@ -195,25 +196,25 @@ class GatewayCheckout
}
/**
* @return GatewayLink[]
* @return Link[]
*/
public function getGatewayLinks(): array
{
return $this->gatewayLinks;
}
public function addGatewayLink(GatewayLink $link): static
public function addGatewayLink(Link $link): static
{
$this->gatewayLinks = [...$this->gatewayLinks, $link];
return $this;
}
public function removeGatewayLink(GatewayLink $link): static
public function removeGatewayLink(Link $link): static
{
$this->gatewayLinks = \array_filter(
$this->gatewayLinks,
function (GatewayLink $existingLink) use ($link) {
function (Link $existingLink) use ($link) {
return $existingLink->href !== $link->href;
}
);
@@ -222,25 +223,25 @@ class GatewayCheckout
}
/**
* @return GatewayTracking[]
* @return Tracking[]
*/
public function getGatewayTrackings(): array
{
return $this->gatewayTrackings;
}
public function addGatewayTracking(GatewayTracking $tracking): static
public function addGatewayTracking(Tracking $tracking): static
{
$this->gatewayTrackings = [...$this->gatewayTrackings, $tracking];
return $this;
}
public function removeGatewayTracking(GatewayTracking $tracking): static
public function removeGatewayTracking(Tracking $tracking): static
{
$this->gatewayTrackings = \array_filter(
$this->gatewayTrackings,
function (GatewayTracking $existingTracking) use ($tracking) {
function (Tracking $existingTracking) use ($tracking) {
return $existingTracking->title !== $tracking->title
&& $existingTracking->value !== $tracking->value;
}
@@ -1,8 +1,8 @@
<?php
namespace App\Entity;
namespace App\Entity\Gateway;
enum GatewayCheckoutStatus: string
enum CheckoutStatus: string
{
case Pending = 'pending';
@@ -1,8 +1,8 @@
<?php
namespace App\Entity;
namespace App\Entity\Gateway;
class GatewayLink
class Link
{
/**
* The complete target URL.
@@ -26,5 +26,5 @@ class GatewayLink
* `debug` links are for developers and platform maintainers to get useful information about the checkout.\
* `payment` links are for end-users who must visit this link to complete the checkout.
*/
public GatewayLinkType $type;
public LinkType $type;
}
@@ -1,8 +1,8 @@
<?php
namespace App\Entity;
namespace App\Entity\Gateway;
enum GatewayLinkType: string
enum LinkType: string
{
/**
* A 'debug' type link indicates a link that is helpful to developers and platform maintainers to get info about the checkout.
@@ -1,10 +1,10 @@
<?php
namespace App\Entity;
namespace App\Entity\Gateway;
use Symfony\Component\Validator\Constraints as Assert;
class GatewayTracking
class Tracking
{
/**
* A descriptive title for the tracking number.
@@ -2,7 +2,7 @@
namespace App\Entity\Interface;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
interface AccountingOwnerInterface extends ApiResource
{
+1
View File
@@ -4,6 +4,7 @@ namespace App\Entity;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata as API;
use App\Entity\Accounting\Accounting;
use App\Entity\Interface\AccountingOwnerInterface;
use App\Entity\Trait\TimestampableCreationEntity;
use App\Entity\Trait\TimestampableUpdationEntity;
+1
View File
@@ -3,6 +3,7 @@
namespace App\Entity;
use ApiPlatform\Metadata as API;
use App\Entity\Accounting\Accounting;
use App\Entity\Interface\AccountingOwnerInterface;
use App\Repository\TipjarRepository;
use Doctrine\ORM\Mapping as ORM;
+1
View File
@@ -3,6 +3,7 @@
namespace App\Entity;
use ApiPlatform\Metadata as API;
use App\Entity\Accounting\Accounting;
use App\Entity\Interface\AccountingOwnerInterface;
use App\Entity\Interface\UserOwnedInterface;
use App\Entity\Trait\TimestampableCreationEntity;
+4 -3
View File
@@ -3,6 +3,7 @@
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Entity\Accounting\Transaction;
use App\Repository\WalletStatementRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@@ -19,7 +20,7 @@ class WalletStatement
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?AccountingTransaction $transaction = null;
private ?Transaction $transaction = null;
#[ORM\Column(enumType: WalletStatementDirection::class)]
private ?WalletStatementDirection $direction = null;
@@ -55,12 +56,12 @@ class WalletStatement
return $this->id;
}
public function getTransaction(): ?AccountingTransaction
public function getTransaction(): ?Transaction
{
return $this->transaction;
}
public function setTransaction(AccountingTransaction $transaction): static
public function setTransaction(Transaction $transaction): static
{
$this->transaction = $transaction;
@@ -2,7 +2,7 @@
namespace App\EventListener;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
use App\Entity\Interface\AccountingOwnerInterface;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\EntityManagerInterface;
@@ -2,7 +2,7 @@
namespace App\EventListener;
use App\Entity\AccountingTransaction;
use App\Entity\Accounting\Transaction;
use App\Entity\User;
use App\Library\Economy\Payment\WalletGatewayService;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;
@@ -13,7 +13,7 @@ use Doctrine\ORM\Events;
#[AsEntityListener(
event: Events::postPersist,
method: 'processTransaction',
entity: AccountingTransaction::class
entity: Transaction::class
)]
final class WalletTransactionsListener
{
@@ -26,7 +26,7 @@ final class WalletTransactionsListener
* Generates a WalletStatement for User-received Transactions.
*/
public function processTransaction(
AccountingTransaction $transaction,
Transaction $transaction,
PostPersistEventArgs $event,
) {
$target = $transaction->getTarget();
+24 -24
View File
@@ -2,11 +2,11 @@
namespace App\Library\Benzina\Pump;
use App\Entity\GatewayCharge;
use App\Entity\GatewayChargeType;
use App\Entity\GatewayCheckout;
use App\Entity\GatewayCheckoutStatus;
use App\Entity\GatewayTracking;
use App\Entity\Gateway\Charge;
use App\Entity\Gateway\ChargeType;
use App\Entity\Gateway\Checkout;
use App\Entity\Gateway\CheckoutStatus;
use App\Entity\Gateway\Tracking;
use App\Entity\Money;
use App\Entity\Tipjar;
use App\Library\Benzina\Pump\Trait\ArrayPumpTrait;
@@ -20,7 +20,7 @@ use App\Library\Economy\Payment\WalletGateway;
use App\Repository\ProjectRepository;
use App\Repository\TipjarRepository;
use App\Repository\UserRepository;
use App\Service\GatewayCheckoutService;
use App\Service\Gateway\CheckoutService;
use Doctrine\ORM\EntityManagerInterface;
class CheckoutsPump extends AbstractPump implements PumpInterface
@@ -78,7 +78,7 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
private ProjectRepository $projectRepository,
private TipjarRepository $tipjarRepository,
private EntityManagerInterface $entityManager,
private GatewayCheckoutService $checkoutService,
private CheckoutService $checkoutService,
) {}
public function supports(mixed $batch): bool
@@ -92,7 +92,7 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
public function pump(mixed $batch): void
{
$batch = $this->skipPumped($batch, 'id', GatewayCheckout::class, 'migratedId');
$batch = $this->skipPumped($batch, 'id', Checkout::class, 'migratedId');
$tipjar = $this->getPlatformTipjar();
@@ -114,7 +114,7 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
$user = $users[$record['user']];
$checkout = new GatewayCheckout();
$checkout = new Checkout();
$checkout->setOrigin($user->getAccounting());
$checkout->setStatus($this->getCheckoutStatus($record));
$checkout->setGateway($this->getCheckoutGateway($record));
@@ -129,7 +129,7 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
$checkout->setDateCreated(new \DateTime($record['invested']));
$checkout->setDateUpdated(new \DateTime());
$charge = new GatewayCharge();
$charge = new Charge();
$charge->setType($this->getChargeType($record));
$charge->setMoney($this->getChargeMoney($record['amount'], $record['currency']));
@@ -148,8 +148,8 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
$checkout->addCharge($charge);
if ($record['donate_amount'] > 0) {
$tip = new GatewayCharge();
$tip->setType(GatewayChargeType::Single);
$tip = new Charge();
$tip->setType(ChargeType::Single);
$tip->setTitle(self::CHARGE_TITLE_TIP);
$tip->setMoney($this->getChargeMoney($record['donate_amount'], $record['currency']));
$tip->setTarget($tipjar->getAccounting());
@@ -157,7 +157,7 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
$checkout->addCharge($tip);
}
if ($checkout->getStatus() === GatewayCheckoutStatus::Charged) {
if ($checkout->getStatus() === CheckoutStatus::Charged) {
$checkout = $this->checkoutService->chargeCheckout($checkout);
}
@@ -219,13 +219,13 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
return $tipjar;
}
private function getChargeType(array $record): GatewayChargeType
private function getChargeType(array $record): ChargeType
{
if (\in_array($record['method'], ['stripe_subscription'])) {
return GatewayChargeType::Recurring;
return ChargeType::Recurring;
}
return GatewayChargeType::Single;
return ChargeType::Single;
}
private function getChargeMoney(int $amount, string $currency): Money
@@ -239,13 +239,13 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
return new Money($amount, $currency);
}
private function getCheckoutStatus(array $record): GatewayCheckoutStatus
private function getCheckoutStatus(array $record): CheckoutStatus
{
if ($record['status'] < 1) {
return GatewayCheckoutStatus::Pending;
return CheckoutStatus::Pending;
}
return GatewayCheckoutStatus::Charged;
return CheckoutStatus::Charged;
}
private function getCheckoutGateway(array $record): string
@@ -269,18 +269,18 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
}
/**
* @return GatewayTracking[]
* @return Tracking[]
*/
private function getCheckoutTrackings(array $record): array
{
$v3Tracking = new GatewayTracking();
$v3Tracking = new Tracking();
$v3Tracking->title = self::TRACKING_TITLE_V3;
$v3Tracking->value = $record['id'];
$trackings = [$v3Tracking];
if (!empty($record['payment'])) {
$payment = new GatewayTracking();
$payment = new Tracking();
$payment->title = self::TRACKING_TITLE_PAYMENT;
$payment->value = $record['payment'];
@@ -288,7 +288,7 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
}
if (!empty($record['transaction'])) {
$transaction = new GatewayTracking();
$transaction = new Tracking();
$transaction->title = self::TRACKING_TITLE_TRANSACTION;
$transaction->value = $record['transaction'];
@@ -296,7 +296,7 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
}
if (!empty($record['preapproval'])) {
$preapproval = new GatewayTracking();
$preapproval = new Tracking();
$preapproval->title = self::TRACKING_TITLE_PREAPPROVAL;
$preapproval->value = $record['preapproval'];
+1 -1
View File
@@ -2,7 +2,7 @@
namespace App\Library\Benzina\Pump;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
use App\Entity\Project;
use App\Entity\ProjectStatus;
use App\Entity\User;
@@ -2,19 +2,19 @@
namespace App\Library\Economy\Payment;
use App\Entity\GatewayCheckout;
use App\Entity\Gateway\Checkout;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Gateway interfaces are in charge of connecting with payment gateways to send them the data in `GatewayCheckout` instances.\
* Gateway interfaces are in charge of connecting with payment gateways to send them the data in `Checkout` instances.\
* \
* The flow is:
* 1. A client app creates a `GatewayCheckout` record
* 2. `App\State\GatewayCheckoutProcessor` calls the `sendData` method of the respective interface for the new `GatewayCheckout`
* 3. The interface connects with the gateway and sends the data for the `GatewayCheckout`
* 4. The interface updates the `GatewayCheckout` with the checkout url and reference given by the gateway for the checkout session
* 1. A client app creates a `Checkout` record
* 2. `App\State\GatewayCheckoutProcessor` calls the `sendData` method of the respective interface for the new `Checkout`
* 3. The interface connects with the gateway and sends the data for the `Checkout`
* 4. The interface updates the `Checkout` with the checkout url and reference given by the gateway for the checkout session
* 5. `App\State\GatewayCheckoutProcessor` returns the response data to the client app
* 6. The client app redirects the user to the payment with the gateway
* 7. The gateway processes the payment and redirects the user back to v4
@@ -29,18 +29,18 @@ interface GatewayInterface
public static function getName(): string;
/**
* @return \App\Entity\GatewayChargeType[] The charge types that can be processed by this Gateway
* @return \App\Entity\Gateway\ChargeType[] The charge types that can be processed by this Gateway
*/
public static function getSupportedChargeTypes(): array;
/**
* Connects with the payment gateway and creates a checkout session so the gateway can process the payment.
*
* @param GatewayCheckout $checkout The GatewayCheckout with the data for the payment to be charged
* @param Checkout $checkout The Checkout with the data for the payment to be charged
*
* @return GatewayCheckout The GatewayCheckout updated with the data given by the gateway
* @return Checkout The Checkout updated with the data given by the gateway
*/
public function process(GatewayCheckout $checkout): GatewayCheckout;
public function process(Checkout $checkout): Checkout;
/**
* When a user is redirected by the gateway we must handle the redirection
+26 -26
View File
@@ -3,15 +3,15 @@
namespace App\Library\Economy\Payment;
use ApiPlatform\Api\IriConverterInterface;
use App\Entity\GatewayCharge;
use App\Entity\GatewayChargeType;
use App\Entity\GatewayCheckout;
use App\Entity\GatewayCheckoutStatus;
use App\Entity\GatewayLink;
use App\Entity\GatewayLinkType;
use App\Entity\GatewayTracking;
use App\Repository\GatewayCheckoutRepository;
use App\Service\GatewayCheckoutService;
use App\Entity\Gateway\Charge;
use App\Entity\Gateway\ChargeType;
use App\Entity\Gateway\Checkout;
use App\Entity\Gateway\CheckoutStatus;
use App\Entity\Gateway\Link;
use App\Entity\Gateway\LinkType;
use App\Entity\Gateway\Tracking;
use App\Repository\Gateway\CheckoutRepository;
use App\Service\Gateway\CheckoutService;
use Brick\Money\Money as BrickMoney;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -48,8 +48,8 @@ class PaypalGateway implements GatewayInterface
private RouterInterface $router,
private EntityManagerInterface $entityManager,
private IriConverterInterface $iriConverter,
private GatewayCheckoutService $checkoutService,
private GatewayCheckoutRepository $checkoutRepository,
private CheckoutService $checkoutService,
private CheckoutRepository $checkoutRepository,
) {}
public static function getName(): string
@@ -60,11 +60,11 @@ class PaypalGateway implements GatewayInterface
public static function getSupportedChargeTypes(): array
{
return [
GatewayChargeType::Single,
ChargeType::Single,
];
}
public function process(GatewayCheckout $checkout): GatewayCheckout
public function process(Checkout $checkout): Checkout
{
$order = $this->paypal->postOrder([
'intent' => self::PAYPAL_ORDER_INTENT,
@@ -72,7 +72,7 @@ class PaypalGateway implements GatewayInterface
'payment_source' => $this->getPaypalPaymentSource($checkout),
]);
$tracking = new GatewayTracking();
$tracking = new Tracking();
$tracking->title = self::TRACKING_TITLE_ORDER;
$tracking->value = $order['id'];
@@ -80,10 +80,10 @@ class PaypalGateway implements GatewayInterface
foreach ($order['links'] as $linkData) {
$linkType = \in_array($linkData['rel'], ['approve', 'payer-action'])
? GatewayLinkType::Payment
: GatewayLinkType::Debug;
? LinkType::Payment
: LinkType::Debug;
$link = new GatewayLink();
$link = new Link();
$link->href = $linkData['href'];
$link->rel = $linkData['rel'];
$link->method = $linkData['method'];
@@ -97,7 +97,7 @@ class PaypalGateway implements GatewayInterface
public function handleRedirect(Request $request): RedirectResponse
{
if ($request->query->get('type') !== GatewayCheckoutService::RESPONSE_TYPE_SUCCESS) {
if ($request->query->get('type') !== CheckoutService::RESPONSE_TYPE_SUCCESS) {
throw new \Exception(sprintf('Checkout was not completed successfully.'));
}
@@ -105,10 +105,10 @@ class PaypalGateway implements GatewayInterface
$checkout = $this->checkoutRepository->find($checkoutId);
if ($checkout === null) {
throw new \Exception(sprintf("GatewayCheckout '%s' could not be found.", $checkoutId));
throw new \Exception(sprintf("Checkout '%s' could not be found.", $checkoutId));
}
if ($checkout->getStatus() === GatewayCheckoutStatus::Charged) {
if ($checkout->getStatus() === CheckoutStatus::Charged) {
return new RedirectResponse($this->iriConverter->getIriFromResource($checkout));
}
@@ -128,7 +128,7 @@ class PaypalGateway implements GatewayInterface
}
foreach ($capture['purchase_units'] as $purchaseUnit) {
$tracking = new GatewayTracking();
$tracking = new Tracking();
$tracking->title = self::TRACKING_TITLE_TRANSACTION;
$tracking->value = $purchaseUnit['payments']['captures'][0]['id'];
@@ -174,11 +174,11 @@ class PaypalGateway implements GatewayInterface
$checkout = $this->checkoutRepository->findOneByTracking(self::TRACKING_TITLE_ORDER, $orderId);
if ($checkout === null) {
throw new \Exception(sprintf("Could not find any GatewayCheckout by the GatewayTracking '%s'", $orderId), 1);
throw new \Exception(sprintf("Could not find any Checkout by the Tracking '%s'", $orderId), 1);
}
foreach ($event['resource']['purchase_units'] as $purchaseUnit) {
$tracking = new GatewayTracking();
$tracking = new Tracking();
$tracking->title = self::TRACKING_TITLE_TRANSACTION;
$tracking->value = $purchaseUnit['payments']['captures'][0]['id'];
@@ -188,7 +188,7 @@ class PaypalGateway implements GatewayInterface
$checkout = $this->checkoutService->chargeCheckout($checkout);
}
private function getPaypalMoney(GatewayCharge $charge): array
private function getPaypalMoney(Charge $charge): array
{
$brick = BrickMoney::ofMinor(
$charge->getMoney()->amount,
@@ -201,7 +201,7 @@ class PaypalGateway implements GatewayInterface
];
}
private function getPaypalPurchaseUnits(GatewayCheckout $checkout): array
private function getPaypalPurchaseUnits(Checkout $checkout): array
{
$units = [];
@@ -236,7 +236,7 @@ class PaypalGateway implements GatewayInterface
return $units;
}
private function getPaypalPaymentSource(GatewayCheckout $checkout): array
private function getPaypalPaymentSource(Checkout $checkout): array
{
return [
'paypal' => [
+38 -24
View File
@@ -3,14 +3,16 @@
namespace App\Library\Economy\Payment;
use ApiPlatform\Api\IriConverterInterface;
use App\Entity\GatewayChargeType;
use App\Entity\GatewayCheckout;
use App\Entity\GatewayCheckoutStatus;
use App\Entity\GatewayLink;
use App\Entity\GatewayLinkType;
use App\Entity\GatewayTracking;
use App\Repository\GatewayCheckoutRepository;
use App\Service\GatewayCheckoutService;
use App\Entity\Gateway\ChargeType;
use App\Entity\Gateway\Checkout;
use App\Entity\Gateway\CheckoutStatus;
use App\Entity\Gateway\Link;
use App\Entity\Gateway\LinkType;
use App\Entity\Gateway\Tracking;
use App\Entity\User;
use App\Repository\Gateway\CheckoutRepository;
use App\Repository\UserRepository;
use App\Service\Gateway\CheckoutService;
use Doctrine\ORM\EntityManagerInterface;
use Stripe\Checkout\Session as StripeSession;
use Stripe\StripeClient;
@@ -31,8 +33,9 @@ class StripeGateway implements GatewayInterface
private string $stripeApiKey,
private string $stripeWebhookSecret,
private RouterInterface $router,
private GatewayCheckoutService $checkoutService,
private GatewayCheckoutRepository $checkoutRepository,
private CheckoutService $checkoutService,
private CheckoutRepository $checkoutRepository,
private UserRepository $userRepository,
private EntityManagerInterface $entityManager,
private IriConverterInterface $iriConverter,
) {
@@ -47,15 +50,15 @@ class StripeGateway implements GatewayInterface
public static function getSupportedChargeTypes(): array
{
return [
GatewayChargeType::Single,
GatewayChargeType::Recurring,
ChargeType::Single,
ChargeType::Recurring,
];
}
public function process(GatewayCheckout $checkout): GatewayCheckout
public function process(Checkout $checkout): Checkout
{
$session = $this->stripe->checkout->sessions->create([
'customer_email' => $checkout->getOrigin()->getUser()->getEmail(),
'customer_email' => $this->getStripeCustomer($checkout),
'mode' => $this->getStripeMode($checkout),
'line_items' => $this->getStripeLineItems($checkout),
// Because Symfony's Router encodes query parameters, the value {CHECKOUT_SESSION_ID}
@@ -65,16 +68,16 @@ class StripeGateway implements GatewayInterface
'success_url' => sprintf('%s&session_id={CHECKOUT_SESSION_ID}', $this->checkoutService->generateRedirectUrl($checkout)),
]);
$link = new GatewayLink();
$link = new Link();
$link->href = $session->url;
$link->rel = 'approve';
$link->method = Request::METHOD_GET;
$link->type = GatewayLinkType::Payment;
$link->type = LinkType::Payment;
$checkout->addGatewayLink($link);
$tracking = new GatewayTracking();
$tracking = new Tracking();
$tracking->title = self::TRACKING_TITLE_CHECKOUT;
$tracking->value = $session->id;
@@ -91,14 +94,14 @@ class StripeGateway implements GatewayInterface
$checkout = $this->checkoutRepository->find($request->query->get('checkoutId'));
if ($checkout === null) {
throw new \Exception(sprintf("Stripe checkout '%s' exists but no GatewayCheckout with that reference was found.", $sessionId));
throw new \Exception(sprintf("Stripe checkout '%s' exists but no Checkout with that reference was found.", $sessionId));
}
if ($checkout->getStatus() === GatewayCheckoutStatus::Charged) {
if ($checkout->getStatus() === CheckoutStatus::Charged) {
return $checkout;
}
if ($request->query->get('type') !== GatewayCheckoutService::RESPONSE_TYPE_SUCCESS) {
if ($request->query->get('type') !== CheckoutService::RESPONSE_TYPE_SUCCESS) {
return $checkout;
}
@@ -132,10 +135,21 @@ class StripeGateway implements GatewayInterface
}
}
private function getStripeMode(GatewayCheckout $checkout): string
private function getStripeCustomer(Checkout $checkout): string
{
if ($checkout->getOrigin()->getOwnerClass() !== User::class) {
return '';
}
$user = $this->userRepository->find($checkout->getOrigin()->getOwnerId());
return $user->getEmail();
}
private function getStripeMode(Checkout $checkout): string
{
foreach ($checkout->getCharges() as $charge) {
if ($charge->getType() === GatewayChargeType::Recurring) {
if ($charge->getType() === ChargeType::Recurring) {
return StripeSession::MODE_SUBSCRIPTION;
}
}
@@ -143,7 +157,7 @@ class StripeGateway implements GatewayInterface
return StripeSession::MODE_PAYMENT;
}
private function getStripeLineItems(GatewayCheckout $checkout): array
private function getStripeLineItems(Checkout $checkout): array
{
$items = [];
@@ -157,7 +171,7 @@ class StripeGateway implements GatewayInterface
],
];
if ($charge->getType() === GatewayChargeType::Recurring) {
if ($charge->getType() === ChargeType::Recurring) {
$price['recurring'] = ['interval' => 'month'];
}
@@ -2,9 +2,9 @@
namespace App\Library\Economy\Payment;
use App\Entity\AccountingTransaction;
use App\Entity\GatewayChargeType;
use App\Entity\GatewayCheckout;
use App\Entity\Accounting\Transaction;
use App\Entity\Gateway\ChargeType;
use App\Entity\Gateway\Checkout;
use App\Entity\Money;
use App\Entity\WalletStatement;
use App\Entity\WalletStatementDirection;
@@ -23,7 +23,7 @@ class WalletGateway implements GatewayInterface
public static function getSupportedChargeTypes(): array
{
return [
GatewayChargeType::Single,
ChargeType::Single,
];
}
@@ -32,7 +32,7 @@ class WalletGateway implements GatewayInterface
private MoneyService $money,
) {}
public function process(GatewayCheckout $checkout): GatewayCheckout
public function process(Checkout $checkout): Checkout
{
$origin = $checkout->getOrigin();
$available = $this->wallet->getBalance($origin);
@@ -44,7 +44,7 @@ class WalletGateway implements GatewayInterface
$charges = $checkout->getCharges();
foreach ($charges as $charge) {
$transaction = new AccountingTransaction();
$transaction = new Transaction();
$transaction->setMoney($charge->getMoney());
$transaction->setOrigin($origin);
$transaction->setTarget($charge->getTarget());
@@ -69,7 +69,7 @@ class WalletGateway implements GatewayInterface
return new Response();
}
private function getChargeTotal(GatewayCheckout $checkout): Money
private function getChargeTotal(Checkout $checkout): Money
{
$total = new Money(0, $checkout->getOrigin()->getCurrency());
@@ -2,8 +2,8 @@
namespace App\Library\Economy\Payment;
use App\Entity\Accounting;
use App\Entity\AccountingTransaction;
use App\Entity\Accounting\Accounting;
use App\Entity\Accounting\Transaction;
use App\Entity\Money;
use App\Entity\WalletStatement;
use App\Entity\WalletStatementDirection;
@@ -52,11 +52,11 @@ class WalletGatewayService
/**
* Puts the money of a Transaction into the target wallet.
*
* @param AccountingTransaction $transaction The Transaction targetting a wallet
* @param Transaction $transaction The Transaction targetting a wallet
*
* @return WalletStatement An incoming statement for the target wallet
*/
public function save(AccountingTransaction $transaction): WalletStatement
public function save(Transaction $transaction): WalletStatement
{
$statement = new WalletStatement();
$statement->setTransaction($transaction);
@@ -72,11 +72,11 @@ class WalletGatewayService
/**
* Takes the money of a Transaction from the origin wallet.
*
* @param AccountingTransaction $transaction The Transaction originating from a wallet
* @param Transaction $transaction The Transaction originating from a wallet
*
* @return WalletStatement An outgoing statement financed by previous incoming statements
*/
public function spend(AccountingTransaction $transaction): WalletStatement
public function spend(Transaction $transaction): WalletStatement
{
$origin = $transaction->getOrigin();
@@ -1,8 +1,8 @@
<?php
namespace App\Repository;
namespace App\Repository\Accounting;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
@@ -1,28 +1,28 @@
<?php
namespace App\Repository;
namespace App\Repository\Accounting;
use App\Entity\AccountingTransaction;
use App\Entity\Accounting\Transaction;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<AccountingTransaction>
* @extends ServiceEntityRepository<Transaction>
*
* @method AccountingTransaction|null find($id, $lockMode = null, $lockVersion = null)
* @method AccountingTransaction|null findOneBy(array $criteria, array $orderBy = null)
* @method AccountingTransaction[] findAll()
* @method AccountingTransaction[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
* @method Transaction|null find($id, $lockMode = null, $lockVersion = null)
* @method Transaction|null findOneBy(array $criteria, array $orderBy = null)
* @method Transaction[] findAll()
* @method Transaction[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class AccountingTransactionRepository extends ServiceEntityRepository
class TransactionRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, AccountingTransaction::class);
parent::__construct($registry, Transaction::class);
}
// /**
// * @return AccountingTransaction[] Returns an array of AccountingTransaction objects
// * @return Transaction[] Returns an array of Transaction objects
// */
// public function findByExampleField($value): array
// {
@@ -36,7 +36,7 @@ class AccountingTransactionRepository extends ServiceEntityRepository
// ;
// }
// public function findOneBySomeField($value): ?AccountingTransaction
// public function findOneBySomeField($value): ?Transaction
// {
// return $this->createQueryBuilder('t')
// ->andWhere('t.exampleField = :val')
@@ -1,28 +1,28 @@
<?php
namespace App\Repository;
namespace App\Repository\Gateway;
use App\Entity\GatewayCharge;
use App\Entity\Gateway\Charge;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<GatewayCharge>
* @extends ServiceEntityRepository<Charge>
*
* @method GatewayCharge|null find($id, $lockMode = null, $lockVersion = null)
* @method GatewayCharge|null findOneBy(array $criteria, array $orderBy = null)
* @method GatewayCharge[] findAll()
* @method GatewayCharge[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
* @method Charge|null find($id, $lockMode = null, $lockVersion = null)
* @method Charge|null findOneBy(array $criteria, array $orderBy = null)
* @method Charge[] findAll()
* @method Charge[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class GatewayChargeRepository extends ServiceEntityRepository
class ChargeRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, GatewayCharge::class);
parent::__construct($registry, Charge::class);
}
// /**
// * @return GatewayCharge[] Returns an array of GatewayCharge objects
// * @return Charge[] Returns an array of Charge objects
// */
// public function findByExampleField($value): array
// {
@@ -36,7 +36,7 @@ class GatewayChargeRepository extends ServiceEntityRepository
// ;
// }
// public function findOneBySomeField($value): ?GatewayCharge
// public function findOneBySomeField($value): ?Charge
// {
// return $this->createQueryBuilder('g')
// ->andWhere('g.exampleField = :val')
@@ -1,29 +1,29 @@
<?php
namespace App\Repository;
namespace App\Repository\Gateway;
use App\Entity\GatewayCheckout;
use App\Entity\Gateway\Checkout;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<GatewayCheckout>
* @extends ServiceEntityRepository<Checkout>
*
* @method GatewayCheckout|null find($id, $lockMode = null, $lockVersion = null)
* @method GatewayCheckout|null findOneBy(array $criteria, array $orderBy = null)
* @method GatewayCheckout[] findAll()
* @method GatewayCheckout[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
* @method Checkout|null find($id, $lockMode = null, $lockVersion = null)
* @method Checkout|null findOneBy(array $criteria, array $orderBy = null)
* @method Checkout[] findAll()
* @method Checkout[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class GatewayCheckoutRepository extends ServiceEntityRepository
class CheckoutRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, GatewayCheckout::class);
parent::__construct($registry, Checkout::class);
}
/**
* @return GatewayCheckout|null
* @return Checkout|null
*/
public function findOneByTracking(string $title, string $value): array
{
@@ -39,7 +39,7 @@ class GatewayCheckoutRepository extends ServiceEntityRepository
}
// /**
// * @return GatewayCheckout[] Returns an array of GatewayCheckout objects
// * @return Checkout[] Returns an array of Checkout objects
// */
// public function findByExampleField($value): array
// {
@@ -53,7 +53,7 @@ class GatewayCheckoutRepository extends ServiceEntityRepository
// ;
// }
// public function findOneBySomeField($value): ?GatewayCheckout
// public function findOneBySomeField($value): ?Checkout
// {
// return $this->createQueryBuilder('g')
// ->andWhere('g.exampleField = :val')
+1 -1
View File
@@ -2,7 +2,7 @@
namespace App\Repository;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
use App\Entity\Project;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
+1 -1
View File
@@ -2,7 +2,7 @@
namespace App\Repository;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
+1 -1
View File
@@ -2,7 +2,7 @@
namespace App\Repository;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
use App\Entity\WalletStatement;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Query\Expr\Join;
+1 -1
View File
@@ -14,7 +14,7 @@ class AccountingVoter extends Voter
protected function supports(string $attribute, mixed $subject): bool
{
return in_array($attribute, [self::EDIT])
&& $subject instanceof \App\Entity\Accounting;
&& $subject instanceof \App\Entity\Accounting\Accounting;
}
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
@@ -1,15 +1,15 @@
<?php
namespace App\Service;
namespace App\Service\Gateway;
use App\Controller\GatewaysController;
use App\Entity\AccountingTransaction;
use App\Entity\GatewayCharge;
use App\Entity\GatewayCheckout;
use App\Entity\GatewayCheckoutStatus;
use App\Entity\Accounting\Transaction;
use App\Entity\Gateway\Charge;
use App\Entity\Gateway\Checkout;
use App\Entity\Gateway\CheckoutStatus;
use Symfony\Component\Routing\RouterInterface;
class GatewayCheckoutService
class CheckoutService
{
public const RESPONSE_TYPE_SUCCESS = 'success';
public const RESPONSE_TYPE_FAILURE = 'failure';
@@ -24,7 +24,7 @@ class GatewayCheckoutService
* @return string Absolute URL to the gateways redirection handler
*/
public function generateRedirectUrl(
GatewayCheckout $checkout,
Checkout $checkout,
string $type = self::RESPONSE_TYPE_SUCCESS,
array $parameters = [],
): string {
@@ -45,7 +45,7 @@ class GatewayCheckoutService
*
* @return string A tracking code suitable for external gateway data matching
*/
public function generateTracking(GatewayCheckout $checkout, GatewayCharge $charge): string
public function generateTracking(Checkout $checkout, Charge $charge): string
{
return \sprintf(
'%s-%s',
@@ -59,7 +59,7 @@ class GatewayCheckoutService
*
* @return string A tracking code suitable for external gateway data matching
*/
public function generateCheckoutTracking(GatewayCheckout $checkout): string
public function generateCheckoutTracking(Checkout $checkout): string
{
return \sprintf(
'AO%d-CO%d',
@@ -73,7 +73,7 @@ class GatewayCheckoutService
*
* @return string A tracking code suitable for external gateway data matching
*/
public function generateChargeTracking(GatewayCharge $charge): string
public function generateChargeTracking(Charge $charge): string
{
return \sprintf(
'CH%d-AT%d',
@@ -83,18 +83,18 @@ class GatewayCheckoutService
}
/**
* Updates a successful GatewayCheckout and generates the transactions for each charge.
* Updates a successful Checkout and generates the transactions for each charge.
*
* @param GatewayCheckout $checkout The GatewayCheckout to be updated
* @param Checkout $checkout The Checkout to be updated
*
* @return GatewayCheckout The updated GatewayCheckout with updated charges and generated transactions
* @return Checkout The updated Checkout with updated charges and generated transactions
*/
public function chargeCheckout(GatewayCheckout $checkout): GatewayCheckout
public function chargeCheckout(Checkout $checkout): Checkout
{
$checkout->setStatus(GatewayCheckoutStatus::Charged);
$checkout->setStatus(CheckoutStatus::Charged);
foreach ($checkout->getCharges() as $charge) {
$transaction = new AccountingTransaction();
$transaction = new Transaction();
$transaction->setMoney($charge->getMoney());
$transaction->setOrigin($checkout->getOrigin());
$transaction->setTarget($charge->getTarget());
@@ -1,11 +1,11 @@
<?php
namespace App\State;
namespace App\State\Accounting;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\ApiResource\AccountingApiResource;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
use Doctrine\ORM\EntityManagerInterface;
class AccountingStateProcessor implements ProcessorInterface
@@ -1,6 +1,6 @@
<?php
namespace App\State;
namespace App\State\Accounting;
use ApiPlatform\Doctrine\Orm\State\CollectionProvider;
use ApiPlatform\Doctrine\Orm\State\ItemProvider;
@@ -9,7 +9,7 @@ use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\Pagination\TraversablePaginator;
use ApiPlatform\State\ProviderInterface;
use App\ApiResource\AccountingApiResource;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
@@ -23,7 +23,7 @@ class SupportedChargeTypesValidator extends ConstraintValidator
return;
}
/** @var Collection<int, \App\Entity\GatewayCharge> */
/** @var Collection<int, \App\Entity\Gateway\Charge> */
$charges = $value;
$checkout = $charges->toArray()[0]->getCheckout();
@@ -1,8 +1,8 @@
<?php
namespace App\Tests\Entity;
namespace App\Tests\Entity\Accounting;
use App\Entity\Accounting;
use App\Entity\Accounting\Accounting;
use App\Entity\Tipjar;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
@@ -2,7 +2,7 @@
namespace App\Tests\Library\Economy\Payment;
use App\Entity\AccountingTransaction;
use App\Entity\Accounting\Transaction;
use App\Entity\Money;
use App\Entity\Tipjar;
use App\Entity\User;
@@ -65,7 +65,7 @@ class WalletGatewayServiceTest extends KernelTestCase
$this->assertEquals(0, $balance->amount);
$this->assertEquals($user->getCurrency(), $balance->currency);
$incoming = new AccountingTransaction();
$incoming = new Transaction();
$incoming->setMoney(new Money(100, 'EUR'));
$incoming->setOrigin($tipjar);
$incoming->setTarget($user);
@@ -101,7 +101,7 @@ class WalletGatewayServiceTest extends KernelTestCase
$tipjar = $this->getTipjar()->getAccounting();
$user = $this->getUser()->getAccounting();
$incoming = new AccountingTransaction();
$incoming = new Transaction();
$incoming->setMoney(new Money(100, 'EUR'));
$incoming->setOrigin($tipjar);
$incoming->setTarget($user);
@@ -109,7 +109,7 @@ class WalletGatewayServiceTest extends KernelTestCase
$this->entityManager->persist($incoming);
$this->entityManager->flush();
$outgoing = new AccountingTransaction();
$outgoing = new Transaction();
$outgoing->setMoney(new Money(20, 'EUR'));
$outgoing->setOrigin($user);
$outgoing->setTarget($tipjar);
@@ -139,7 +139,7 @@ class WalletGatewayServiceTest extends KernelTestCase
$this->assertCount(0, $statement->getFinancesTo());
$this->assertCount(1, $statement->getFinancedBy());
$outgoing = new AccountingTransaction();
$outgoing = new Transaction();
$outgoing->setMoney(new Money(30, 'EUR'));
$outgoing->setOrigin($user);
$outgoing->setTarget($tipjar);
@@ -182,7 +182,7 @@ class WalletGatewayServiceTest extends KernelTestCase
$tipjar = $this->getTipjar()->getAccounting();
$user = $this->getUser()->getAccounting();
$incoming = new AccountingTransaction();
$incoming = new Transaction();
$incoming->setMoney(new Money(10, 'EUR'));
$incoming->setOrigin($tipjar);
$incoming->setTarget($user);
@@ -190,7 +190,7 @@ class WalletGatewayServiceTest extends KernelTestCase
$this->entityManager->persist($incoming);
$this->entityManager->flush();
$incoming = new AccountingTransaction();
$incoming = new Transaction();
$incoming->setMoney(new Money(10, 'EUR'));
$incoming->setOrigin($tipjar);
$incoming->setTarget($user);
@@ -198,14 +198,14 @@ class WalletGatewayServiceTest extends KernelTestCase
$this->entityManager->persist($incoming);
$this->entityManager->flush();
$outgoing = new AccountingTransaction();
$outgoing = new Transaction();
$outgoing->setMoney(new Money(15, 'EUR'));
$outgoing->setOrigin($user);
$outgoing->setTarget($tipjar);
$this->walletService->spend($outgoing);
$incoming = new AccountingTransaction();
$incoming = new Transaction();
$incoming->setMoney(new Money(5, 'EUR'));
$incoming->setOrigin($tipjar);
$incoming->setTarget($user);