PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 1.19.0
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v1.19.0
3.3.9 3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 All 67 releases
logtivity / Logs / Easy_Digital_Downloads / Logtivity_Easy_Digital_Downloads.php

Logtivity_Easy_Digital_Downloads.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 1.19.0, at Logs/Easy_Digital_Downloads/Logtivity_Easy_Digital_Downloads.php

169 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Logtivity_Easy_Digital_Downloads extends Logtivity_Abstract_Easy_Digital_Downloads
4 {
5 public function __construct()
6 {
7 add_action('edd_post_add_to_cart', [$this, 'itemAddedToCart'], 10, 3);
8 add_action('edd_post_remove_from_cart', [$this, 'itemRemovedFromCart'], 10, 2);
9 add_action('edd_customer_post_create', [$this, 'customerCreated'], 10, 2);
10 add_action('edd_update_payment_status', [$this, 'paymentStatusUpdated'], 10, 3);
11 add_action('edd_process_verified_download', [$this, 'fileDownloaded'], 10, 4);
12 add_action( 'edd_cart_discount_set', [$this, 'discountApplied'], 10, 2);
13 add_action( 'edd_cart_discount_removed', [$this, 'discountRemoved'], 10, 2);
14 }
15
16 public function itemAddedToCart($download_id, $options, $items)
17 {
18 $log = Logtivity_Logger::log()
19 ->setAction('Download Added to Cart')
20 ->setContext(logtivity_get_the_title($download_id))
21 ->setPostId($download_id);
22
23 $prices = edd_get_variable_prices($download_id);
24
25 foreach ($items as $item) {
26 if (isset($item['options']['price_id']) && isset($prices[$item['options']['price_id']])) {
27 $log->addMeta('Variable Item', $prices[$item['options']['price_id']]['name']);
28 }
29
30 if ($item['quantity']) {
31 $log->addMeta('Quantity', $item['quantity']);
32 }
33 }
34
35 $log->send();
36 }
37
38 public function itemRemovedFromCart($key, $item_id)
39 {
40 Logtivity_Logger::log()
41 ->setAction('Download Removed from Cart')
42 ->setContext(logtivity_get_the_title($item_id))
43 ->send();
44 }
45
46 public function paymentStatusUpdated($payment_id, $status, $old_status)
47 {
48 $payment = new EDD_Payment($payment_id);
49
50 if ($status == 'refunded') {
51 return $this->paymentRefunded($payment);
52 }
53
54 if ($status == 'publish') {
55 return $this->paymentCompleted($payment);
56 }
57
58 if ($status == 'edd_subscription') {
59 return;
60 }
61
62 Logtivity_Logger::log()
63 ->setAction('Payment Status Changed to ' . ucfirst($status))
64 ->setContext($this->getPaymentKey($payment))
65 ->addMeta('Payment Key', $this->getPaymentKey($payment))
66 ->addMeta('Total', $payment->total)
67 ->addMeta('Currency', $payment->currency)
68 ->addMeta('Gateway', $payment->gateway)
69 ->addMeta('Customer ID', $payment->customer_id)
70 ->send();
71 }
72
73 public function paymentCompleted($payment)
74 {
75 $key = $this->getPaymentKey($payment);
76
77 $log = Logtivity_Logger::log()
78 ->setAction('Payment Completed')
79 ->setContext($key)
80 ->addMeta('Payment Key', $key);
81
82 foreach ($payment->cart_details as $item) {
83 $log->addMeta('Cart Item', $item['name']);
84 }
85
86 if ($payment->discounts != 'none') {
87 $log->addMeta('Discount Code', $payment->discounts);
88 }
89
90 $log->addMeta('Total', $payment->total)
91 ->addMeta('Currency', $payment->currency)
92 ->addMeta('Gateway', $payment->gateway)
93 ->addMeta('Customer ID', $payment->customer_id)
94 ->send();
95 }
96
97 public function paymentRefunded($EDD_Payment)
98 {
99 Logtivity_Logger::log()
100 ->setAction('Payment Refunded')
101 ->setContext($this->getPaymentKey($EDD_Payment))
102 ->addMeta('Amount', $EDD_Payment->get_meta('_edd_payment_total'))
103 ->addMeta('Payment Key', $this->getPaymentKey($EDD_Payment))
104 ->addMeta('Customer ID', $EDD_Payment->customer_id)
105 ->send();
106 }
107
108 public function getPaymentKey($payment)
109 {
110 $meta = $payment->get_meta();
111
112 if (isset($meta['key'])) {
113 return $meta['key'];
114 }
115 }
116
117 public function customerCreated($created, $args)
118 {
119 if (!$created) {
120 return;
121 }
122
123 Logtivity_Logger::log()
124 ->setAction('Customer Created')
125 ->setContext($args['name'])
126 ->addMeta('Customer ID', $created)
127 ->send();
128 }
129
130 public function fileDownloaded($download, $email, $payment, $args)
131 {
132 $download = new EDD_Download($download);
133
134 $payment = new EDD_Payment($payment);
135
136 $log = Logtivity_Logger::log()
137 ->setAction('File Downloaded')
138 ->setContext($this->getDownloadTitle($download->get_ID(), $args['price_id'] ?? null))
139 ->setPostId($download->get_ID())
140 ->addMeta('Payment Key', $this->getPaymentKey($payment));
141
142 if (isset($args['file_key'])) {
143 $log->addMeta('File ID', $args['file_key']);
144 }
145
146 $log->addMeta('Customer ID', $payment->customer_id)
147 ->send();
148 }
149
150 public function discountApplied($code, $discounts)
151 {
152 Logtivity_Logger::log()
153 ->setAction('Discount Applied')
154 ->setContext($code)
155 ->send();
156 }
157
158 public function discountRemoved($code, $discounts)
159 {
160 Logtivity_Logger::log()
161 ->setAction('Discount Removed')
162 ->setContext($code)
163 ->send();
164 }
165 }
166
167 $Logtivity_Easy_Digital_Downloads = new Logtivity_Easy_Digital_Downloads;
168
169