<?php
namespace App\Entity;
use App\Repository\CreditTransactionRepository;
use Doctrine\ORM\Mapping as ORM;
use DateTime;
use DateTimeZone;
/**
* @ORM\Entity(repositoryClass=CreditTransactionRepository::class)
*/
class CreditTransaction
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="float")
*/
private $amount;
/**
* @ORM\Column(type="string", length=255)
*/
private $status;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $paymentIntentId;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $cardType;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $cardNumber;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=10)
*/
private $transactionType;
/**
* @ORM\Column(type="string", length=255, unique=true, nullable=true)
*/
private $transactionNumber;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="creditTransactions")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\OneToOne(targetEntity=Invoice::class, mappedBy="creditTransaction", cascade={"remove"})
*/
private $invoice;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $cardHolder;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $cardExpiration;
public function __construct()
{
$timezone = new DateTimeZone('Europe/Paris');
$this->createdAt = new DateTime('now', $timezone);
}
public function generateTransactionNumber()
{
if ($this->id) {
if ($this->transactionType === 'credit') {
$prefix = 'CB';
} else {
$prefix = 'CRD';
}
$this->transactionNumber = $prefix . str_pad((string) $this->id, 5, '0', STR_PAD_LEFT);
}
}
public function getId(): ?int
{
return $this->id;
}
public function getAmount(): ?float
{
return $this->amount;
}
public function setAmount(float $amount): self
{
$this->amount = $amount;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getPaymentIntentId(): ?string
{
return $this->paymentIntentId;
}
public function setPaymentIntentId(?string $paymentIntentId): self
{
$this->paymentIntentId = $paymentIntentId;
return $this;
}
public function getCardType(): ?string
{
return $this->cardType;
}
public function setCardType(?string $cardType): self
{
$this->cardType = $cardType;
return $this;
}
public function getCardNumber(): ?string
{
return $this->cardNumber;
}
public function setCardNumber(?string $cardNumber): self
{
$this->cardNumber = $cardNumber;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getTransactionType(): ?string
{
return $this->transactionType;
}
public function setTransactionType(string $transactionType): self
{
$this->transactionType = $transactionType;
return $this;
}
public function getTransactionNumber(): ?string
{
return $this->transactionNumber;
}
public function setTransactionNumber(?string $transactionNumber): self
{
$this->transactionNumber = $transactionNumber;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getInvoice(): ?Invoice
{
return $this->invoice;
}
public function setInvoice(?Invoice $invoice): self
{
$this->invoice = $invoice;
return $this;
}
public function getCardHolder(): ?string
{
return $this->cardHolder;
}
public function setCardHolder(?string $cardHolder): self
{
$this->cardHolder = $cardHolder;
return $this;
}
public function getCardExpiration(): ?string
{
return $this->cardExpiration;
}
public function setCardExpiration(?string $cardExpiration): self
{
$this->cardExpiration = $cardExpiration;
return $this;
}
}