src/Entity/UserSubscriptions.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use DateTimeZone;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * UserSubscriptions
  8.  *
  9.  * @ORM\Table(name="user_subscriptions")
  10.  * @ORM\Entity(repositoryClass="App\Repository\UserSubscriptionsRepository")
  11.  */
  12. class UserSubscriptions
  13. {
  14.     /**
  15.      * @var int
  16.      *
  17.      * @ORM\Column(name="id", type="integer")
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @var int
  24.      *
  25.      * @ORM\Column(name="user_id", type="integer")
  26.      */
  27.     private $userId;
  28.     /**
  29.      * @var \DateTime
  30.      *
  31.      * @ORM\Column(name="start_subscription", type="datetime", nullable=true)
  32.      */
  33.     private $startSubscription;
  34.     /**
  35.      * @var \DateTime
  36.      *
  37.      * @ORM\Column(name="end_subscription", type="datetime", nullable=true)
  38.      */
  39.     private $endSubscription;
  40.     /**
  41.      * @var \DateTime
  42.      *
  43.      * @ORM\Column(name="removed_at", type="datetime", nullable=true)
  44.      */
  45.     private $removedAt;
  46.     /**
  47.      * @var string
  48.      * Platform subscription was performed on;
  49.      *
  50.      * @ORM\Column(name="platform", type="string", nullable=false)
  51.      */
  52.     private $platform;
  53.     // Apple subscription transaction fields
  54.     /**
  55.      * @var string
  56.      *
  57.      * @ORM\Column(name="transaction_id", type="string", nullable=false, unique=true)
  58.      */
  59.     private $transactionId;
  60.     /**
  61.      * @var string
  62.      * @ORM\Column(name="original_transaction_id", type="string", nullable=true)
  63.      */
  64.     private $originalTransactionId;
  65.     /**
  66.      * @var string
  67.      * @ORM\Column(name="web_order_line_item_id", type="string", nullable=true)
  68.      */
  69.     private $webOrderLineItemId;
  70.     /**
  71.      * @var string
  72.      * @ORM\Column(name="bundle_id", type="string", nullable=true)
  73.      */
  74.     private $bundleId;
  75.     /**
  76.      * @var string
  77.      * @ORM\Column(name="product_id", type="string", nullable=true)
  78.      */
  79.     private $productId;
  80.     /**
  81.      * @var string
  82.      * @ORM\Column(name="subscription_group_identifier", type="string", nullable=true)
  83.      */
  84.     private $subscriptionGroupIdentifier;
  85.     /**
  86.      * @var \DateTime
  87.      * @ORM\Column(name="purchase_date", type="datetime", nullable=true)
  88.      */
  89.     private $purchaseDate;
  90.     /**
  91.      * @var \DateTime
  92.      * @ORM\Column(name="original_purchase_date", type="datetime", nullable=true)
  93.      */
  94.     private $originalPurchaseDate;
  95.     /**
  96.      * @var \DateTime
  97.      * @ORM\Column(name="expires_date", type="datetime", nullable=true)
  98.      */
  99.     private $expiresDate;
  100.     /**
  101.      * @var int
  102.      * @ORM\Column(name="quantity", type="integer", nullable=true)
  103.      */
  104.     private $quantity;
  105.     /**
  106.      * @var string
  107.      * @ORM\Column(name="type", type="string",  nullable=true)
  108.      */
  109.     private $type;
  110.     /**
  111.      * @var string
  112.      * @ORM\Column(name="in_app_ownership_type", type="string", nullable=true)
  113.      */
  114.     private $inAppOwnershipType;
  115.     /**
  116.      * @var \DateTime
  117.      * @ORM\Column(name="signed_date", type="datetime", nullable=true)
  118.      */
  119.     private $signedDate;
  120.     /**
  121.      * @var int
  122.      * @ORM\Column(name="offer_type", type="integer", nullable=true)
  123.      */
  124.     private $offerType;
  125.     /**
  126.      * @var string
  127.      * @ORM\Column(name="environment", type="string", nullable=true)
  128.      */
  129.     private $environment;
  130.     /**
  131.      * @var string
  132.      * @ORM\Column(name="transaction_reason", type="string", nullable=true)
  133.      */
  134.     private $transactionReason;
  135.     /**
  136.      * @var string
  137.      * @ORM\Column(name="storefront", type="string", nullable=true)
  138.      */
  139.     private $storefront;
  140.     /**
  141.      * @var int
  142.      * @ORM\Column(name="store_front_id", type="integer", nullable=true)
  143.      */
  144.     private $storefrontId;
  145.     /**
  146.      * @var float
  147.      * @ORM\Column(name="price", type="float", nullable=true)
  148.      */
  149.     private $price;
  150.     /**
  151.      * @var string
  152.      * @ORM\Column(name="currency", type="string", nullable=true)
  153.      */
  154.     private $currency;
  155.     /**
  156.      * @var string
  157.      * @ORM\Column(name="offer_discount_type", type="string", nullable=true)
  158.      */
  159.     private $offerDiscountType;
  160.     // Google subscription transaction fields
  161.     /**
  162.      * @var string
  163.      * @ORM\Column(name="subscription_state", type="string", nullable=true)
  164.      */
  165.     private $subscriptionState;
  166.     /**
  167.      * @var string
  168.      * @ORM\Column(name="acknowledgement_state", type="string", nullable=true)
  169.      */
  170.     private $acknowledgementState;
  171.     /**
  172.      * @var string
  173.      * @ORM\Column(name="latest_order_id", type="string", nullable=true)
  174.      */
  175.     private $latestOrderId;
  176.     /**
  177.      * @param string transactionId
  178.      * @param int userId
  179.      * @param string platform {apple|google}
  180.      *
  181.      * @return UserSubscriptions
  182.      */
  183.     public function __construct($transactionId$userId$platform)
  184.     {
  185.         $this->transactionId $transactionId;
  186.         $this->startSubscription = new DateTime();
  187.         $this->platform $platform;
  188.         $this->userId $userId;
  189.     }
  190.     /**
  191.      * @param transaction dictionary
  192.      */
  193.     public function updateAppleSubscription($transaction)
  194.     {
  195.         $this->originalTransactionId $transaction->originalTransactionId;
  196.         $this->webOrderLineItemId $transaction->webOrderLineItemId;
  197.         $this->bundleId $transaction->bundleId;
  198.         $this->productId $transaction->productId;
  199.         $this->subscriptionGroupIdentifier 
  200.                     $transaction->subscriptionGroupIdentifier;
  201.         $this->purchaseDate = (new DateTime(
  202.             '@'.(string)($transaction->purchaseDate/1000)
  203.         ));
  204.         $this->originalPurchaseDate = (new DateTime(
  205.             '@'.(string)($transaction->originalPurchaseDate/1000)
  206.         ));
  207.         $this->expiresDate = (new DateTime(
  208.             '@'.(string)($transaction->expiresDate/1000)
  209.         ));
  210.         $this->quantity $transaction->quantity;
  211.         $this->type $transaction->type;
  212.         $this->inAppOwnershipType $transaction->inAppOwnershipType;
  213.         $this->signedDate = (new DateTime(
  214.             '@'.(string)($transaction->signedDate/1000)
  215.         ));
  216. //        $this->offerType = $transaction->offerType;
  217.         $this->environment $transaction->environment;
  218.         $this->transactionReason $transaction->transactionReason;
  219.         $this->storefront $transaction->storefront;
  220.         $this->storefrontId $transaction->storefrontId;
  221.         $this->price $transaction->price;
  222.         $this->currency $transaction->currency;
  223. //        $this->offerDiscountType = $transaction->offerDiscountType;
  224.         $this->startSubscription $this->purchaseDate;
  225.         $this->endSubscription $this->expiresDate;
  226.     }
  227.     /**
  228.      * @param transaction dictionary
  229.      */
  230.     public function updateGoogleSubscription($transaction)
  231.     {
  232.         $this->originalTransactionId $transaction->linkedPurchaseToken;
  233.         $this->subscriptionState $transaction->subscriptionState;
  234.         $this->acknowledgementState $transaction->acknowledgementState;
  235.         $this->latestOrderId $transaction->latestOrderId;
  236.         $this->productId $transaction->lineItems[0]->productId;
  237.         $this->bundleId $transaction->bundleId;
  238.         $this->purchaseDate = new DateTime(
  239.             $transaction->startTime, new DateTimeZone('UTC')
  240.         );
  241.         $this->expiresDate = new DateTime(
  242.             $transaction->lineItems[0]->expiryTime, new DateTimeZone('UTC')
  243.         );
  244.         $this->quantity 1;
  245.         $this->storefront $transaction->regionCode;
  246.         if (isset($transaction->lineItems[0]->autoRenewingPlan) &&
  247.             $transaction->lineItems[0]->autoRenewingPlan->autoRenewEnabled === true
  248.         )
  249.             $this->type "Auto-Renewable Subscription";
  250.         $this->startSubscription $this->purchaseDate;
  251.         $this->endSubscription $this->expiresDate;
  252.     }
  253.     /**
  254.      * Get id
  255.      *
  256.      * @return int
  257.      */
  258.     public function getId()
  259.     {
  260.         return $this->id;
  261.     }
  262.     public function hasExpired()
  263.     {
  264.         return $this->expiresDate 
  265.             new DateTime('now', new DateTimeZone('UTC'));
  266.     }
  267.     /**
  268.      * Set userId
  269.      *
  270.      * @param integer $userId
  271.      *
  272.      * @return UserSubscriptions
  273.      */
  274.     public function setUserId($userId)
  275.     {
  276.         $this->userId $userId;
  277.         return $this;
  278.     }
  279.     /**
  280.      * Get userId
  281.      *
  282.      * @return int
  283.      */
  284.     public function getUserId()
  285.     {
  286.         return $this->userId;
  287.     }
  288.     /**
  289.      * Set platform
  290.      * @return UserSubscriptions
  291.      */
  292.     public function setPlatform($platform)
  293.     {
  294.         $this->platform $platform;
  295.         return $this;
  296.     }
  297.     /**
  298.      * Get platform
  299.      * @return string
  300.      */
  301.     public function getPlatform()
  302.     {
  303.         return $this->platform;
  304.     }
  305.     /**
  306.      * Set startSubscription
  307.      *
  308.      * @param \DateTime $startSubscription
  309.      *
  310.      * @return UserSubscriptions
  311.      */
  312.     public function setStartSubscription($startSubscription)
  313.     {
  314.         $this->startSubscription $startSubscription;
  315.         return $this;
  316.     }
  317.     /**
  318.      * Get startSubscription
  319.      *
  320.      * @return \DateTime
  321.      */
  322.     public function getStartSubscription()
  323.     {
  324.         return $this->startSubscription;
  325.     }
  326.     /**
  327.      * Set endSubscription
  328.      *
  329.      * @param \DateTime $endSubscription
  330.      *
  331.      * @return UserSubscriptions
  332.      */
  333.     public function setEndSubscription($endSubscription)
  334.     {
  335.         $this->endSubscription $endSubscription;
  336.         return $this;
  337.     }
  338.     /**
  339.      * Get endSubscription
  340.      *
  341.      * @return \DateTime
  342.      */
  343.     public function getEndSubscription()
  344.     {
  345.         return $this->endSubscription;
  346.     }
  347.     /**
  348.      * Set removedAt
  349.      *
  350.      * @param \DateTime $removedAt
  351.      *
  352.      * @return UserSubscriptions
  353.      */
  354.     public function setRemovedAt($removedAt)
  355.     {
  356.         $this->removedAt $removedAt;
  357.         return $this;
  358.     }
  359.     /**
  360.      * Get removedAt
  361.      *
  362.      * @return \DateTime
  363.      */
  364.     public function getRemovedAt()
  365.     {
  366.         return $this->removedAt;
  367.     }
  368.     /**
  369.      * Get the value of transactionId
  370.      */
  371.     public function getTransactionId()
  372.     {
  373.         return $this->transactionId;
  374.     }
  375.     /**
  376.      * Set the value of transactionId
  377.      */
  378.     public function setTransactionId($transactionId): self
  379.     {
  380.         $this->transactionId $transactionId;
  381.         return $this;
  382.     }
  383.     /**
  384.      * Get the value of originalTransactionId
  385.      */
  386.     public function getOriginalTransactionId()
  387.     {
  388.         return $this->originalTransactionId;
  389.     }
  390.     /**
  391.      * Set the value of originalTransactionId
  392.      */
  393.     public function setOriginalTransactionId($originalTransactionId): self
  394.     {
  395.         $this->originalTransactionId $originalTransactionId;
  396.         return $this;
  397.     }
  398. }