classes/XLite/Model/Order/Status/Payment.php line 38

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2001-present X-Cart Holdings LLC. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XLite\Model\Order\Status;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use XLite\API\Endpoint\OrderPaymentStatus\DTO\OrderPaymentStatusInput as Input;
  10. use XLite\API\Endpoint\OrderPaymentStatus\DTO\OrderPaymentStatusOutput as Output;
  11. /**
  12.  * Payment status
  13.  *
  14.  * @ORM\Entity
  15.  * @ORM\Table  (name="order_payment_statuses",
  16.  *      indexes={
  17.  *          @ORM\Index (name="code", columns={"code"})
  18.  *      }
  19.  * )
  20.  * @ApiPlatform\ApiResource(
  21.  *     shortName="OrderPaymentStatus",
  22.  *     input=Input::class,
  23.  *     output=Output::class,
  24.  *     itemOperations={
  25.  *          "get"={
  26.  *              "method"="GET",
  27.  *              "path"="/orders/{id}/payment_status.{_format}",
  28.  *              "identifiers"={"id"},
  29.  *              "requirements"={"id"="\d+"}
  30.  *          },
  31.  *          "put"={
  32.  *              "method"="PUT",
  33.  *              "path"="/orders/{id}/payment_status.{_format}",
  34.  *              "identifiers"={"id"},
  35.  *              "requirements"={"id"="\d+"}
  36.  *          }
  37.  *     },
  38.  *     collectionOperations={}
  39.  * )
  40.  */
  41. class Payment extends \XLite\Model\Order\Status\AStatus
  42. {
  43.     /**
  44.      * Statuses
  45.      */
  46.     public const STATUS_AUTHORIZED     'A';
  47.     public const STATUS_PART_PAID      'PP';
  48.     public const STATUS_PAID           'P';
  49.     public const STATUS_DECLINED       'D';
  50.     public const STATUS_CANCELED       'C';
  51.     public const STATUS_QUEUED         'Q';
  52.     public const STATUS_REFUNDED       'R';
  53.     /**
  54.      * @var \Doctrine\Common\Collections\Collection
  55.      *
  56.      * @ORM\OneToMany (targetEntity="XLite\Model\Order\Status\PaymentTranslation", mappedBy="owner", cascade={"all"})
  57.      */
  58.     protected $translations;
  59.     /**
  60.      * Disallowed to set manually statuses
  61.      *
  62.      * @return array
  63.      */
  64.     public static function getDisallowedToSetManuallyStatuses()
  65.     {
  66.         return [
  67.             static::STATUS_AUTHORIZED,
  68.             static::STATUS_DECLINED
  69.         ];
  70.     }
  71.     /**
  72.      * Not compatible with Shipping statuses
  73.      *
  74.      * @return array
  75.      */
  76.     public static function getNotCompatibleWithShippingStatuses()
  77.     {
  78.         return [
  79.             static::STATUS_DECLINED,
  80.             static::STATUS_CANCELED,
  81.         ];
  82.     }
  83.     /**
  84.      * Get open order statuses
  85.      *
  86.      * @return array
  87.      */
  88.     public static function getOpenStatuses()
  89.     {
  90.         return [
  91.             static::STATUS_AUTHORIZED,
  92.             static::STATUS_PART_PAID,
  93.             static::STATUS_PAID,
  94.             static::STATUS_QUEUED,
  95.         ];
  96.     }
  97.     /**
  98.      * Get paid statuses
  99.      *
  100.      * @return array
  101.      */
  102.     public static function getPaidStatuses()
  103.     {
  104.         return [
  105.             static::STATUS_AUTHORIZED,
  106.             static::STATUS_PART_PAID,
  107.             static::STATUS_PAID,
  108.         ];
  109.     }
  110.     /**
  111.      * Payment status is compatible with shipping status
  112.      *
  113.      * @return boolean
  114.      */
  115.     public function isCompatibleWithShippingStatus()
  116.     {
  117.         return !in_array(
  118.             $this->getCode(),
  119.             static::getNotCompatibleWithShippingStatuses()
  120.         );
  121.     }
  122.     /**
  123.      * Status is allowed to set manually
  124.      *
  125.      * @return boolean
  126.      */
  127.     public function isAllowedToSetManually()
  128.     {
  129.         return !in_array(
  130.             $this->getCode(),
  131.             static::getDisallowedToSetManuallyStatuses()
  132.         );
  133.     }
  134.     /**
  135.      * Get id
  136.      *
  137.      * @return integer
  138.      */
  139.     public function getId()
  140.     {
  141.         return $this->id;
  142.     }
  143.     /**
  144.      * Set code
  145.      *
  146.      * @param string $code
  147.      * @return Payment
  148.      */
  149.     public function setCode($code)
  150.     {
  151.         $this->code $code;
  152.         return $this;
  153.     }
  154.     /**
  155.      * Get code
  156.      *
  157.      * @return string|null
  158.      */
  159.     public function getCode()
  160.     {
  161.         return $this->code;
  162.     }
  163.     /**
  164.      * Set position
  165.      *
  166.      * @param integer $position
  167.      * @return Payment
  168.      */
  169.     public function setPosition($position)
  170.     {
  171.         $this->position $position;
  172.         return $this;
  173.     }
  174.     /**
  175.      * Get position
  176.      *
  177.      * @return integer
  178.      */
  179.     public function getPosition()
  180.     {
  181.         return $this->position;
  182.     }
  183.     /**
  184.      * List of change status handlers;
  185.      * top index - old status, second index - new one
  186.      * (<old_status> ----> <new_status>: $statusHandlers[$old][$new])
  187.      *
  188.      * @return array
  189.      */
  190.     public static function getStatusHandlers()
  191.     {
  192.         return [
  193.             static::STATUS_QUEUED => [
  194.                 static::STATUS_AUTHORIZED => ['authorize'],
  195.                 static::STATUS_PAID       => ['process'],
  196.                 static::STATUS_DECLINED   => ['decline''uncheckout''fail'],
  197.                 static::STATUS_CANCELED   => ['decline''uncheckout''cancel'],
  198.             ],
  199.             static::STATUS_AUTHORIZED => [
  200.                 static::STATUS_PAID       => ['process'],
  201.                 static::STATUS_DECLINED   => ['decline''uncheckout''fail'],
  202.                 static::STATUS_CANCELED   => ['decline''uncheckout''cancel'],
  203.             ],
  204.             static::STATUS_PART_PAID => [
  205.                 static::STATUS_PAID       => ['process'],
  206.                 static::STATUS_DECLINED   => ['decline''uncheckout''fail'],
  207.                 static::STATUS_CANCELED   => ['decline''uncheckout''fail'],
  208.             ],
  209.             static::STATUS_PAID => [
  210.                 static::STATUS_DECLINED   => ['decline''uncheckout''fail'],
  211.                 static::STATUS_CANCELED   => ['decline''uncheckout''cancel'],
  212.             ],
  213.             static::STATUS_DECLINED => [
  214.                 static::STATUS_AUTHORIZED => ['checkout''queue''authorize'],
  215.                 static::STATUS_PART_PAID  => ['checkout''queue'],
  216.                 static::STATUS_PAID       => ['checkout''queue''process'],
  217.                 static::STATUS_QUEUED     => ['checkout''queue'],
  218.                 static::STATUS_CANCELED   => ['cancel'],
  219.             ],
  220.             static::STATUS_CANCELED => [
  221.                 static::STATUS_AUTHORIZED => ['checkout''queue''authorize'],
  222.                 static::STATUS_PART_PAID  => ['checkout''queue'],
  223.                 static::STATUS_PAID       => ['checkout''queue''process'],
  224.                 static::STATUS_QUEUED     => ['checkout''queue'],
  225.                 static::STATUS_DECLINED   => ['fail'],
  226.             ],
  227.             static::STATUS_REFUNDED => [
  228.                 static::STATUS_PAID       => ['process'],
  229.                 static::STATUS_DECLINED   => ['fail'],
  230.                 static::STATUS_CANCELED   => ['cancel'],
  231.             ],
  232.         ];
  233.     }
  234. }