src/Entity/Payment.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Dictionary\BalanceType;
  4. use App\Dictionary\PaymentType;
  5. use App\Dto\Payment\WpfReconcileResponse;
  6. use App\Lib\Payment\Encashment\AuerWitteThielCsv;
  7. use App\Lib\Payment\PayMethod\AdminBonusMethod;
  8. use App\Lib\Payment\PayMethod\LiquibyteDirectdebitMethod;
  9. use App\Lib\Payment\Vendor\EmerchantpayVendor;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use JMS\Serializer\Annotation as Serializer;
  14. use JMS\Serializer\Annotation\Groups;
  15. /**
  16.  * @ORM\Table("Payment")
  17.  *
  18.  * @ORM\HasLifecycleCallbacks()
  19.  *
  20.  * @ORM\Entity(repositoryClass="App\Repository\PaymentRepository")
  21.  */
  22. class Payment
  23. {
  24.     /**
  25.      * @Groups({"adminindex"})
  26.      *
  27.      * @ORM\Id()
  28.      *
  29.      * @ORM\GeneratedValue()
  30.      *
  31.      * @ORM\Column(type="integer")
  32.      */
  33.     private $id;
  34.     /**
  35.      * @Groups({"adminindex"})
  36.      *
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private ?string $vendor null;
  40.     /**
  41.      * @Groups({"adminindex"})
  42.      *
  43.      * @ORM\Column(type="string", length=120)
  44.      */
  45.     private string $type PaymentType::BOOKING;
  46.     /**
  47.      * @Groups({"adminindex"})
  48.      *
  49.      * @ORM\Column(type="string", length=120, nullable=true)
  50.      */
  51.     private ?string $method null;
  52.     /**
  53.      * @ORM\Column(type="string", length=255)
  54.      */
  55.     private $customer_id;
  56.     /**
  57.      * @Groups({"adminindex"})
  58.      *
  59.      * @ORM\Column(type="string", length=255)
  60.      */
  61.     private ?string $booking_id null;
  62.     /**
  63.      * @Groups({"topbuyerindex", "adminindex"})
  64.      *
  65.      * @ORM\ManyToOne(targetEntity="App\Entity\Account", cascade={"persist"})
  66.      *
  67.      * @ORM\JoinColumn(name="account_id", referencedColumnName="id", onDelete="CASCADE")
  68.      */
  69.     private ?Account $account null;
  70.     /**
  71.      * @Groups({"adminindex"})
  72.      *
  73.      * @ORM\Column(type="decimal", precision=10, scale=2)
  74.      */
  75.     private float $amount 0;
  76.     /**
  77.      * @Groups({"paymenthistory", "chargebackdetail"})
  78.      *
  79.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  80.      */
  81.     private ?float $fee null;
  82.     /**
  83.      * @Groups({"paymenthistory", "chargebackdetail"})
  84.      *
  85.      * @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
  86.      */
  87.     private ?float $realamount null;
  88.     /**
  89.      * @Groups({"adminindex"})
  90.      *
  91.      * @ORM\Column(type="text", nullable=true)
  92.      */
  93.     private ?string $details null;
  94.     /**
  95.      * @Groups({"adminindex", "paymenthistory"})
  96.      *
  97.      * @ORM\Column(type="boolean")
  98.      */
  99.     private bool $on_hold false;
  100.     /**
  101.      * @Groups({"adminindex"})
  102.      *
  103.      * @ORM\ManyToOne(targetEntity="App\Entity\AdminPaymentSepaDownload", cascade={"persist"})
  104.      *
  105.      * @ORM\JoinColumn(name="admin_sepa_download_id", referencedColumnName="id", onDelete="SET NULL")
  106.      */
  107.     private ?AdminPaymentSepaDownload $sepaDownload null;
  108.     /**
  109.      * @Groups({"adminindex", "paymenthistory"})
  110.      *
  111.      * @ORM\Column(type="datetime")
  112.      */
  113.     private $created_at;
  114.     /**
  115.      * @ORM\Column(type="datetime")
  116.      */
  117.     private $updated_at;
  118.     /**
  119.      * total payments of the user for this payment.
  120.      *
  121.      * @Groups({"adminindex", "paymenthistory"})
  122.      */
  123.     private $total_payments;
  124.     /**
  125.      * @ORM\OneToMany(targetEntity="App\Entity\BalanceMember", mappedBy="payment")
  126.      *
  127.      * @Groups({"paymenthistory"})
  128.      */
  129.     private $balance_members;
  130.     /**
  131.      * @Groups({"paymenthistory"})
  132.      */
  133.     private $coins;
  134.     /**
  135.      * @ORM\OneToOne(targetEntity="App\Entity\PaymentProcess", mappedBy="payment", cascade={"persist", "remove"})
  136.      *
  137.      * @ORM\JoinColumn(name="payment_process_id", referencedColumnName="id", nullable=true)
  138.      */
  139.     private ?PaymentProcess $payment_process null;
  140.     /**
  141.      * @ORM\OneToOne(targetEntity="App\Entity\PaymentReference", cascade={"persist", "remove"})
  142.      *
  143.      * @ORM\JoinColumn(name="payment_reference_id", referencedColumnName="id", nullable=true)
  144.      */
  145.     private ?PaymentReference $payment_reference null;
  146.     /**
  147.      * @Serializer\Exclude()
  148.      */
  149.     private ?WpfReconcileResponse $reconcileResponse null;
  150.     public function __construct()
  151.     {
  152.         $this->balance_members = new ArrayCollection();
  153.         $this->created_at = new \DateTime();
  154.     }
  155.     /**
  156.      * @ORM\PrePersist()
  157.      */
  158.     public function prePersist()
  159.     {
  160.         if (!$this->getVendor() && $this->getMethod()) {
  161.             $vendor strpos($this->getMethod(), '_');
  162.             $this->setVendor(substr($this->getMethod(), 0$vendor));
  163.         }
  164.         if (!$this->getCustomerId() && $this->getAccount()) {
  165.             $this->setCustomerId((int) $this->getAccount()->getId());
  166.         }
  167.         if (!$this->getCreatedAt()) {
  168.             $this->setCreatedAt(new \DateTime());
  169.         }
  170.         if (!$this->getUpdatedAt()) {
  171.             $this->setUpdatedAt($this->getCreatedAt());
  172.         }
  173.     }
  174.     public function getId()
  175.     {
  176.         return $this->id;
  177.     }
  178.     public function getVendor(): ?string
  179.     {
  180.         return $this->vendor;
  181.     }
  182.     public function setVendor(string $vendor): self
  183.     {
  184.         $this->vendor $vendor;
  185.         return $this;
  186.     }
  187.     public function vendorEquals(string $name): bool
  188.     {
  189.         return $this->vendor === $name;
  190.     }
  191.     public function getType(): string
  192.     {
  193.         return $this->type;
  194.     }
  195.     public function setType(string $type): self
  196.     {
  197.         $this->type $type;
  198.         return $this;
  199.     }
  200.     public function isType(string $type): bool
  201.     {
  202.         return $this->getType() === $type;
  203.     }
  204.     public function isTypeBooking(): bool
  205.     {
  206.         return PaymentType::BOOKING === $this->type;
  207.     }
  208.     public function isTypeChargeback(): bool
  209.     {
  210.         return PaymentType::CHARGEBACK === $this->type;
  211.     }
  212.     public function isTypeSettlement(): bool
  213.     {
  214.         return PaymentType::SETTLEMENT === $this->type;
  215.     }
  216.     public function getMethod(): ?string
  217.     {
  218.         return $this->method;
  219.     }
  220.     public function setMethod(?string $method): self
  221.     {
  222.         $this->method $method;
  223.         return $this;
  224.     }
  225.     public function getCustomerId(): ?int
  226.     {
  227.         return $this->customer_id;
  228.     }
  229.     public function setCustomerId(int $customer_id): self
  230.     {
  231.         $this->customer_id $customer_id;
  232.         return $this;
  233.     }
  234.     public function getBookingId(): ?string
  235.     {
  236.         return $this->booking_id;
  237.     }
  238.     public function setBookingId(string $booking_id): self
  239.     {
  240.         $this->booking_id $booking_id;
  241.         return $this;
  242.     }
  243.     public function getAccount(): ?Account
  244.     {
  245.         return $this->account;
  246.     }
  247.     public function setAccount(?Account $account): self
  248.     {
  249.         $this->account $account;
  250.         if ($account && !$this->getCustomerId()) {
  251.             $this->setCustomerId($account->getId());
  252.         }
  253.         return $this;
  254.     }
  255.     public function getSepaDownload(): ?AdminPaymentSepaDownload
  256.     {
  257.         return $this->sepaDownload;
  258.     }
  259.     /**
  260.      * @return $this
  261.      */
  262.     public function setSepaDownload(?AdminPaymentSepaDownload $sepaDownload): self
  263.     {
  264.         $this->sepaDownload $sepaDownload;
  265.         return $this;
  266.     }
  267.     public function getAmount()
  268.     {
  269.         return $this->amount;
  270.     }
  271.     public function setAmount($amount): self
  272.     {
  273.         $this->amount $amount;
  274.         return $this;
  275.     }
  276.     public function getFee()
  277.     {
  278.         return $this->fee;
  279.     }
  280.     public function setFee($fee): self
  281.     {
  282.         $this->fee $fee;
  283.         return $this;
  284.     }
  285.     public function getRealamount()
  286.     {
  287.         return $this->realamount;
  288.     }
  289.     public function setRealamount($realamount): self
  290.     {
  291.         $this->realamount $realamount;
  292.         return $this;
  293.     }
  294.     public function getDetails(bool $unserialize false)
  295.     {
  296.         if ($unserialize && !empty($this->details)) {
  297.             return unserialize($this->details);
  298.         }
  299.         return $this->details;
  300.     }
  301.     public function setDetails(?string $details): self
  302.     {
  303.         $this->details $details;
  304.         return $this;
  305.     }
  306.     public function getOnHold(): ?bool
  307.     {
  308.         return $this->on_hold;
  309.     }
  310.     public function setOnHold(bool $on_hold): self
  311.     {
  312.         $this->on_hold $on_hold;
  313.         return $this;
  314.     }
  315.     public function getCreatedAt(): ?\DateTimeInterface
  316.     {
  317.         return $this->created_at;
  318.     }
  319.     public function setCreatedAt(\DateTimeInterface $created_at): self
  320.     {
  321.         $this->created_at $created_at;
  322.         return $this;
  323.     }
  324.     public function getUpdatedAt(): ?\DateTimeInterface
  325.     {
  326.         return $this->updated_at;
  327.     }
  328.     public function setUpdatedAt(\DateTimeInterface $updated_at): self
  329.     {
  330.         $this->updated_at $updated_at;
  331.         return $this;
  332.     }
  333.     public function setTotalPayments(int $totalPayments)
  334.     {
  335.         $this->total_payments $totalPayments;
  336.     }
  337.     public function setBalanceMembers(Collection $balance_members)
  338.     {
  339.         $this->balance_members $balance_members;
  340.     }
  341.     /**
  342.      * @return Collection|BalanceMember[]
  343.      */
  344.     public function getBalanceMembers(): Collection
  345.     {
  346.         return $this->balance_members;
  347.     }
  348.     public function addBalanceMember(BalanceMember $balanceMember): self
  349.     {
  350.         if (!$this->balance_members->contains($balanceMember)) {
  351.             $this->balance_members[] = $balanceMember;
  352.             $balanceMember->setPayment($this);
  353.         }
  354.         return $this;
  355.     }
  356.     public function removeBalanceMember(BalanceMember $balanceMember): self
  357.     {
  358.         if ($this->balance_members->contains($balanceMember)) {
  359.             $this->balance_members->removeElement($balanceMember);
  360.             // set the owning side to null (unless already changed)
  361.             if ($balanceMember->getPayment() === $this) {
  362.                 $balanceMember->setPayment(null);
  363.             }
  364.         }
  365.         return $this;
  366.     }
  367.     public function getCoins(): int
  368.     {
  369.         $coins 0;
  370.         foreach ($this->getBalanceMembers() as $balanceMember) {
  371.             if (BalanceType::OUTPUT === $balanceMember->getType()) {
  372.                 continue;
  373.             }
  374.             $coins += $balanceMember->getAmount();
  375.         }
  376.         return $coins;
  377.     }
  378.     public function setCoins(int $coins): self
  379.     {
  380.         $this->coins $coins;
  381.         return $this;
  382.     }
  383.     public function getPaymentProcess(): ?PaymentProcess
  384.     {
  385.         return $this->payment_process;
  386.     }
  387.     public function setPaymentProcess(PaymentProcess $payment_process): self
  388.     {
  389.         $this->payment_process $payment_process;
  390.         return $this;
  391.     }
  392.     public function appliesForIncomeCommission(): bool
  393.     {
  394.         if (!$this->isTypeBooking() || !$this->getAmount()) {
  395.             return false;
  396.         }
  397.         if ($this->getOnHold() || AdminBonusMethod::NAME === $this->getMethod()) {
  398.             return false;
  399.         }
  400.         return true;
  401.     }
  402.     public function blacklistsBankAccount(): bool
  403.     {
  404.         // not a chargeback with a negative value? nope
  405.         if (!$this->isTypeChargeback() || $this->getAmount() > 0) {
  406.             return false;
  407.         }
  408.         if (LiquibyteDirectdebitMethod::NAME === $this->getMethod()) {
  409.             return true;
  410.         }
  411.         return false;
  412.     }
  413.     public function resetsBankAccountBlacklist(): bool
  414.     {
  415.         // not a settlement with a negative value? nope
  416.         if (!$this->isTypeSettlement()) {
  417.             return false;
  418.         }
  419.         if (LiquibyteDirectdebitMethod::NAME === $this->getMethod()) {
  420.             return true;
  421.         }
  422.         return false;
  423.     }
  424.     public function hasConfirmationEmail(): bool
  425.     {
  426.         if (!$this->isTypeBooking()) {
  427.             return false;
  428.         }
  429.         if (LiquibyteDirectdebitMethod::NAME === $this->getMethod() || $this->vendorEquals(EmerchantpayVendor::EMERCHANT)) {
  430.             return true;
  431.         }
  432.         return false;
  433.     }
  434.     public function hasChargebackEmail(): bool
  435.     {
  436.         if (!$this->isTypeChargeback()) {
  437.             return false;
  438.         }
  439.         if (LiquibyteDirectdebitMethod::NAME === $this->getMethod()) {
  440.             return true;
  441.         }
  442.         return false;
  443.     }
  444.     /**
  445.      * @Serializer\VirtualProperty()
  446.      *
  447.      * @Groups({"paymenthistory", "chargebackdetail"})
  448.      */
  449.     public function getEncashmentFee(): float
  450.     {
  451.         return AuerWitteThielCsv::FEE_ENCASHMENT;
  452.     }
  453.     /**
  454.      * @Serializer\VirtualProperty()
  455.      *
  456.      * @Groups({"paymenthistory", "chargebackdetail"})
  457.      *
  458.      * @return float
  459.      */
  460.     public function getChargebackFee()
  461.     {
  462.         return AuerWitteThielCsv::FEE_CHARGEBACK;
  463.     }
  464.     public function getPaymentReference(): ?PaymentReference
  465.     {
  466.         return $this->payment_reference;
  467.     }
  468.     public function setPaymentReference(?PaymentReference $payment_reference): Payment
  469.     {
  470.         $this->payment_reference $payment_reference;
  471.         return $this;
  472.     }
  473.     public function setReconcileResponse(WpfReconcileResponse $reconcileResponse): self
  474.     {
  475.         $this->reconcileResponse $reconcileResponse;
  476.         return $this;
  477.     }
  478.     public function getReconcileResponse(): ?WpfReconcileResponse
  479.     {
  480.         return $this->reconcileResponse;
  481.     }
  482. }