Update GatewayCharge to have title, description and hold related transactions
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\Repository\GatewayChargeRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
@@ -11,7 +13,6 @@ 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\ApiResource()]
|
||||
#[ORM\Entity(repositoryClass: GatewayChargeRepository::class)]
|
||||
class GatewayCharge
|
||||
{
|
||||
@@ -20,6 +21,10 @@ class GatewayCharge
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[API\ApiProperty(readable: false, writable: false)]
|
||||
#[ORM\ManyToOne(inversedBy: 'charges')]
|
||||
private ?GatewayCheckout $checkout = null;
|
||||
|
||||
/**
|
||||
* The type represents the kind of payment for the charged money.
|
||||
*/
|
||||
@@ -55,11 +60,35 @@ class GatewayCharge
|
||||
#[ORM\Embedded(Money::class)]
|
||||
private ?Money $money = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, AccountingTransaction>
|
||||
*/
|
||||
#[API\ApiProperty(readableLink: false, writable: false)]
|
||||
#[ORM\ManyToMany(targetEntity: AccountingTransaction::class, cascade: ['persist'])]
|
||||
private Collection $transactions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->transactions = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getCheckout(): ?GatewayCheckout
|
||||
{
|
||||
return $this->checkout;
|
||||
}
|
||||
|
||||
public function setCheckout(?GatewayCheckout $checkout): static
|
||||
{
|
||||
$this->checkout = $checkout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getType(): ?GatewayChargeType
|
||||
{
|
||||
return $this->type;
|
||||
@@ -119,4 +148,28 @@ class GatewayCharge
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, AccountingTransaction>
|
||||
*/
|
||||
public function getTransactions(): Collection
|
||||
{
|
||||
return $this->transactions;
|
||||
}
|
||||
|
||||
public function addTransaction(AccountingTransaction $transaction): static
|
||||
{
|
||||
if (!$this->transactions->contains($transaction)) {
|
||||
$this->transactions->add($transaction);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeTransaction(AccountingTransaction $transaction): static
|
||||
{
|
||||
$this->transactions->removeElement($transaction);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,14 +46,6 @@ class GatewayCheckout
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Accounting $origin = null;
|
||||
|
||||
/**
|
||||
* The GatewayCharges to be charged at checkout with the Gateway.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[Assert\Count(min: 1)]
|
||||
#[ORM\ManyToMany(targetEntity: GatewayCharge::class, cascade: ['persist'])]
|
||||
private Collection $charges;
|
||||
|
||||
/**
|
||||
* The status of the checkout with the Gateway.
|
||||
*/
|
||||
@@ -63,6 +55,16 @@ class GatewayCheckout
|
||||
#[ORM\Column()]
|
||||
private ?GatewayCheckoutStatus $status = null;
|
||||
|
||||
/**
|
||||
* The GatewayCharges to be charged at checkout with the gateway.
|
||||
*
|
||||
* @var Collection<int, GatewayCharge>
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[Assert\Count(min: 1)]
|
||||
#[ORM\OneToMany(mappedBy: 'checkout', targetEntity: GatewayCharge::class, cascade: ['persist'])]
|
||||
private Collection $charges;
|
||||
|
||||
/**
|
||||
* The name of the Gateway implementation to checkout with.
|
||||
*/
|
||||
@@ -114,8 +116,8 @@ class GatewayCheckout
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->charges = new ArrayCollection();
|
||||
$this->status = GatewayCheckoutStatus::Pending;
|
||||
$this->charges = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -135,6 +137,18 @@ class GatewayCheckout
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): ?GatewayCheckoutStatus
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus(GatewayCheckoutStatus $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, GatewayCharge>
|
||||
*/
|
||||
@@ -147,6 +161,7 @@ class GatewayCheckout
|
||||
{
|
||||
if (!$this->charges->contains($charge)) {
|
||||
$this->charges->add($charge);
|
||||
$charge->setCheckout($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -154,19 +169,12 @@ class GatewayCheckout
|
||||
|
||||
public function removeCharge(GatewayCharge $charge): static
|
||||
{
|
||||
$this->charges->removeElement($charge);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): ?GatewayCheckoutStatus
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus(GatewayCheckoutStatus $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
if ($this->charges->removeElement($charge)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($charge->getCheckout() === $this) {
|
||||
$charge->setCheckout(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
|
||||
public const TRACKING_TITLE_TRANSACTION = 'v3 Invest Transaction';
|
||||
public const TRACKING_TITLE_PREAPPROVAL = 'v3 Invest Preapproval';
|
||||
|
||||
public const CHARGE_TITLE_PROJECT = 'Pago en Goteo v3 - Donación a proyecto';
|
||||
public const CHARGE_TITLE_POOL = 'Pago en Goteo v3 - Carga de monedero';
|
||||
public const CHARGE_TITLE_TIP = 'Pago en Goteo v3 - Propina a la plataforma';
|
||||
|
||||
private const PLATFORM_TIPJAR_NAME = 'platform';
|
||||
|
||||
private const MAX_INT = 2147483647;
|
||||
@@ -131,12 +135,14 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
|
||||
$charge->setMoney($this->getChargeMoney($record['amount'], $record['currency']));
|
||||
|
||||
if (empty($record['project'])) {
|
||||
$charge->setTitle(self::CHARGE_TITLE_POOL);
|
||||
$charge->setTarget($user->getAccounting());
|
||||
}
|
||||
|
||||
if (!empty($record['project'])) {
|
||||
$project = $projects[$record['project']];
|
||||
|
||||
$charge->setTitle(self::CHARGE_TITLE_PROJECT);
|
||||
$charge->setTarget($project->getAccounting());
|
||||
}
|
||||
|
||||
@@ -145,6 +151,7 @@ class CheckoutsPump extends AbstractPump implements PumpInterface
|
||||
if ($record['donate_amount'] > 0) {
|
||||
$tip = new GatewayCharge();
|
||||
$tip->setType(GatewayChargeType::Single);
|
||||
$tip->setTitle(self::CHARGE_TITLE_TIP);
|
||||
$tip->setMoney($this->getChargeMoney($record['donate_amount'], $record['currency']));
|
||||
$tip->setTarget($tipjar->getAccounting());
|
||||
|
||||
|
||||
@@ -214,8 +214,8 @@ class PaypalGateway implements GatewayInterface
|
||||
'custom_id' => $reference,
|
||||
'items' => [
|
||||
[
|
||||
'name' => $charge::MESSAGE_STATEMENT,
|
||||
'description' => $charge::MESSAGE_STATEMENT,
|
||||
'name' => $charge->getTitle(),
|
||||
'description' => $charge->getDescription(),
|
||||
'quantity' => '1',
|
||||
'unit_amount' => [
|
||||
...$money,
|
||||
|
||||
@@ -152,8 +152,8 @@ class StripeGateway implements GatewayInterface
|
||||
'currency' => $charge->getMoney()->currency,
|
||||
'unit_amount' => $charge->getMoney()->amount,
|
||||
'product_data' => [
|
||||
'name' => $charge::MESSAGE_STATEMENT,
|
||||
'statement_descriptor' => $charge::MESSAGE_STATEMENT,
|
||||
'name' => $charge->getTitle(),
|
||||
'statement_descriptor' => $charge->getDescription(),
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ class GatewayCheckoutService
|
||||
$transaction->setOrigin($checkout->getOrigin());
|
||||
$transaction->setTarget($charge->getTarget());
|
||||
|
||||
$charge->setTransaction($transaction);
|
||||
$charge->addTransaction($transaction);
|
||||
}
|
||||
|
||||
return $checkout;
|
||||
|
||||
Reference in New Issue
Block a user