03977c6d5994c6a31962ce08873dc321f9b2f585
[GitHub/WoltLab/WCF.git] /
1 <?php
2 declare(strict_types=1);
3 namespace wcf\data\paid\subscription\transaction\log;
4 use wcf\data\object\type\ObjectTypeCache;
5 use wcf\data\paid\subscription\PaidSubscription;
6 use wcf\data\user\User;
7 use wcf\data\DatabaseObject;
8 use wcf\system\WCF;
9
10 /**
11 * Represents a paid subscription transaction log entry.
12 *
13 * @author Marcel Werk
14 * @copyright 2001-2018 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\Data\Paid\Subscription\Transaction\Log
17 *
18 * @property-read integer $logID unique id of the paid subscription transaction log entry
19 * @property-read integer|null $subscriptionUserID id of the paid subscription-user-association or `null` if no such association exists
20 * @property-read integer|null $userID id of the user who caused the paid subscription transaction log entry or `null` if the user does not exist anymore
21 * @property-read integer $subscriptionID id of the paid subscription
22 * @property-read integer $paymentMethodObjectTypeID id of the `com.woltlab.wcf.payment.method` object type
23 * @property-read integer $logTime timestamp at which the log has been created
24 * @property-read string $transactionID identifier of the paid subscription transaction
25 * @property-read string $transactionDetails serialized details of the paid subscription transaction
26 * @property-read string $logMessage log message describing the status of the paid subscription transaction
27 */
28 class PaidSubscriptionTransactionLog extends DatabaseObject {
29 /**
30 * user object
31 * @var User
32 */
33 protected $user = null;
34
35 /**
36 * paid subscription object
37 * @var PaidSubscription
38 */
39 protected $subscription = null;
40
41 /**
42 * Returns the payment method of this transaction.
43 *
44 * @return string
45 */
46 public function getPaymentMethodName() {
47 $objectType = ObjectTypeCache::getInstance()->getObjectType($this->paymentMethodObjectTypeID);
48 return $objectType->objectType;
49 }
50
51 /**
52 * Returns transaction details.
53 *
54 * @return array
55 */
56 public function getTransactionDetails() {
57 return unserialize($this->transactionDetails);
58 }
59
60 /**
61 * Returns the user of this transaction.
62 *
63 * @return User
64 */
65 public function getUser() {
66 if ($this->user === null) {
67 $this->user = new User($this->userID);
68 }
69
70 return $this->user;
71 }
72
73 /**
74 * Returns the paid subscription of this transaction.
75 *
76 * @return PaidSubscription
77 */
78 public function getSubscription() {
79 if ($this->subscription === null) {
80 $this->subscription = new PaidSubscription($this->subscriptionID);
81 }
82
83 return $this->subscription;
84 }
85
86 /**
87 * Returns the transaction log entry by transaction id or `null` if no such entry exists.
88 *
89 * @param integer $paymentMethodObjectTypeID
90 * @param string $transactionID
91 * @return PaidSubscriptionTransactionLog|null
92 */
93 public static function getLogByTransactionID($paymentMethodObjectTypeID, $transactionID) {
94 $sql = "SELECT *
95 FROM wcf".WCF_N."_paid_subscription_transaction_log
96 WHERE paymentMethodObjectTypeID = ?
97 AND transactionID = ?";
98 $statement = WCF::getDB()->prepareStatement($sql);
99 $statement->execute([$paymentMethodObjectTypeID, $transactionID]);
100 $row = $statement->fetchArray();
101 if ($row !== false) {
102 return new PaidSubscriptionTransactionLog(null, $row);
103 }
104
105 return null;
106 }
107 }