Completed
Branch FET/extract-activation-detecti... (285969)
by
unknown
11:10 queued 08:02
created
core/db_classes/EE_Transaction.class.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         $txn = $has_object
54 54
             ? $has_object
55 55
             : new self($props_n_values, false, $timezone, $date_formats);
56
-        if (! $has_object) {
56
+        if ( ! $has_object) {
57 57
             $txn->set_old_txn_status($txn->status_ID());
58 58
         }
59 59
         return $txn;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
     public function lock()
94 94
     {
95 95
         // attempt to set lock, but if that fails...
96
-        if (! $this->add_extra_meta('lock', time(), true)) {
96
+        if ( ! $this->add_extra_meta('lock', time(), true)) {
97 97
             // then attempt to remove the lock in case it is expired
98 98
             if ($this->_remove_expired_lock()) {
99 99
                 // if removal was successful, then try setting lock again
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     public function is_locked()
150 150
     {
151 151
         // if TXN is not locked, then return false immediately
152
-        if (! $this->_get_lock()) {
152
+        if ( ! $this->_get_lock()) {
153 153
             return false;
154 154
         }
155 155
         // if not, then let's try and remove the lock in case it's expired...
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
                 $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : '';
648 648
                 break;
649 649
         }
650
-        return $icon . $status[ $this->status_ID() ];
650
+        return $icon.$status[$this->status_ID()];
651 651
     }
652 652
 
653 653
 
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
     public function invoice_url($type = 'html')
786 786
     {
787 787
         $REG = $this->primary_registration();
788
-        if (! $REG instanceof EE_Registration) {
788
+        if ( ! $REG instanceof EE_Registration) {
789 789
             return '';
790 790
         }
791 791
         return $REG->invoice_url($type);
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
     public function receipt_url($type = 'html')
837 837
     {
838 838
         $REG = $this->primary_registration();
839
-        if (! $REG instanceof EE_Registration) {
839
+        if ( ! $REG instanceof EE_Registration) {
840 840
             return '';
841 841
         }
842 842
         return $REG->receipt_url($type);
@@ -1025,7 +1025,7 @@  discard block
 block discarded – undo
1025 1025
     public function total_line_item($create_if_not_found = true)
1026 1026
     {
1027 1027
         $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total)));
1028
-        if (! $item && $create_if_not_found) {
1028
+        if ( ! $item && $create_if_not_found) {
1029 1029
             $item = EEH_Line_Item::create_total_line_item($this);
1030 1030
         }
1031 1031
         return $item;
@@ -1082,7 +1082,7 @@  discard block
 block discarded – undo
1082 1082
     public function billing_info()
1083 1083
     {
1084 1084
         $payment_method = $this->payment_method();
1085
-        if (! $payment_method) {
1085
+        if ( ! $payment_method) {
1086 1086
             EE_Error::add_error(
1087 1087
                 esc_html__(
1088 1088
                     'Could not find billing info for transaction because no gateway has been used for it yet',
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
             return null;
1096 1096
         }
1097 1097
         $primary_reg = $this->primary_registration();
1098
-        if (! $primary_reg) {
1098
+        if ( ! $primary_reg) {
1099 1099
             EE_Error::add_error(
1100 1100
                 esc_html__(
1101 1101
                     'Cannot get billing info for gateway %s on transaction because no primary registration exists',
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
             return null;
1109 1109
         }
1110 1110
         $attendee = $primary_reg->attendee();
1111
-        if (! $attendee) {
1111
+        if ( ! $attendee) {
1112 1112
             EE_Error::add_error(
1113 1113
                 esc_html__(
1114 1114
                     'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists',
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
     public function update_based_on_payments()
1266 1266
     {
1267 1267
         EE_Error::doing_it_wrong(
1268
-            __CLASS__ . '::' . __FUNCTION__,
1268
+            __CLASS__.'::'.__FUNCTION__,
1269 1269
             sprintf(
1270 1270
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
1271 1271
                 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'
@@ -1333,13 +1333,13 @@  discard block
 block discarded – undo
1333 1333
     private function _reg_steps_completed($reg_step_slug = '', $check_all = true)
1334 1334
     {
1335 1335
         $reg_steps = $this->reg_steps();
1336
-        if (! is_array($reg_steps) || empty($reg_steps)) {
1336
+        if ( ! is_array($reg_steps) || empty($reg_steps)) {
1337 1337
             return false;
1338 1338
         }
1339 1339
         // loop thru reg steps array)
1340 1340
         foreach ($reg_steps as $slug => $reg_step_completed) {
1341 1341
             // if NOT checking ALL steps (only checking one step)
1342
-            if (! $check_all) {
1342
+            if ( ! $check_all) {
1343 1343
                 // and this is the one
1344 1344
                 if ($slug === $reg_step_slug) {
1345 1345
                     return $reg_step_completed;
@@ -1542,30 +1542,30 @@  discard block
 block discarded – undo
1542 1542
         // get reg steps array
1543 1543
         $txn_reg_steps = $this->reg_steps();
1544 1544
         // if reg step does NOT exist
1545
-        if (! isset($txn_reg_steps[ $reg_step_slug ])) {
1545
+        if ( ! isset($txn_reg_steps[$reg_step_slug])) {
1546 1546
             return false;
1547 1547
         }
1548 1548
         // if  we're trying to complete a step that is already completed
1549
-        if ($txn_reg_steps[ $reg_step_slug ] === true) {
1549
+        if ($txn_reg_steps[$reg_step_slug] === true) {
1550 1550
             return true;
1551 1551
         }
1552 1552
         // if  we're trying to complete a step that hasn't even started
1553
-        if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) {
1553
+        if ($status === true && $txn_reg_steps[$reg_step_slug] === false) {
1554 1554
             return false;
1555 1555
         }
1556 1556
         // if current status value matches the incoming value (no change)
1557 1557
         // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890
1558
-        if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) {
1558
+        if ((int) $txn_reg_steps[$reg_step_slug] === (int) $status) {
1559 1559
             // this will happen in cases where multiple AJAX requests occur during the same step
1560 1560
             return true;
1561 1561
         }
1562 1562
         // if we're trying to set a start time, but it has already been set...
1563
-        if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) {
1563
+        if (is_numeric($status) && is_numeric($txn_reg_steps[$reg_step_slug])) {
1564 1564
             // skip the update below, but don't return FALSE so that errors won't be displayed
1565 1565
             return true;
1566 1566
         }
1567 1567
         // update completed status
1568
-        $txn_reg_steps[ $reg_step_slug ] = $status;
1568
+        $txn_reg_steps[$reg_step_slug] = $status;
1569 1569
         $this->set_reg_steps($txn_reg_steps);
1570 1570
         $this->save();
1571 1571
         return true;
@@ -1589,7 +1589,7 @@  discard block
 block discarded – undo
1589 1589
     {
1590 1590
         // get reg steps array
1591 1591
         $txn_reg_steps = $this->reg_steps();
1592
-        unset($txn_reg_steps[ $reg_step_slug ]);
1592
+        unset($txn_reg_steps[$reg_step_slug]);
1593 1593
         $this->set_reg_steps($txn_reg_steps);
1594 1594
     }
1595 1595
 
@@ -1671,12 +1671,12 @@  discard block
 block discarded – undo
1671 1671
             return;
1672 1672
         }
1673 1673
         $payments = $this->get_many_related('Payment');
1674
-        if (! empty($payments)) {
1674
+        if ( ! empty($payments)) {
1675 1675
             foreach ($payments as $payment) {
1676 1676
                 if ($payment instanceof EE_Payment) {
1677 1677
                     // kk this TXN should NOT be abandoned
1678 1678
                     $this->update_status_based_on_total_paid();
1679
-                    if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1679
+                    if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1680 1680
                         EE_Error::add_attention(
1681 1681
                             sprintf(
1682 1682
                                 esc_html__(
Please login to merge, or discard this patch.
Indentation   +1701 added lines, -1701 removed lines patch added patch discarded remove patch
@@ -13,1705 +13,1705 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Transaction extends EE_Base_Class implements EEI_Transaction
15 15
 {
16
-    /**
17
-     * The length of time in seconds that a lock is applied before being considered expired.
18
-     * It is not long because a transaction should only be locked for the duration of the request that locked it
19
-     */
20
-    const LOCK_EXPIRATION = 2;
21
-
22
-    /**
23
-     * txn status upon initial construction.
24
-     *
25
-     * @var string
26
-     */
27
-    protected $_old_txn_status;
28
-
29
-
30
-    /**
31
-     * @param array  $props_n_values          incoming values
32
-     * @param string $timezone                incoming timezone
33
-     *                                        (if not set the timezone set for the website will be used.)
34
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
35
-     *                                        date_format and the second value is the time format
36
-     * @return EE_Transaction
37
-     * @throws EE_Error
38
-     * @throws InvalidArgumentException
39
-     * @throws InvalidDataTypeException
40
-     * @throws InvalidInterfaceException
41
-     * @throws ReflectionException
42
-     */
43
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
44
-    {
45
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
46
-        $txn = $has_object
47
-            ? $has_object
48
-            : new self($props_n_values, false, $timezone, $date_formats);
49
-        if (! $has_object) {
50
-            $txn->set_old_txn_status($txn->status_ID());
51
-        }
52
-        return $txn;
53
-    }
54
-
55
-
56
-    /**
57
-     * @param array  $props_n_values  incoming values from the database
58
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
59
-     *                                the website will be used.
60
-     * @return EE_Transaction
61
-     * @throws EE_Error
62
-     * @throws InvalidArgumentException
63
-     * @throws InvalidDataTypeException
64
-     * @throws InvalidInterfaceException
65
-     * @throws ReflectionException
66
-     */
67
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
68
-    {
69
-        $txn = new self($props_n_values, true, $timezone);
70
-        $txn->set_old_txn_status($txn->status_ID());
71
-        return $txn;
72
-    }
73
-
74
-
75
-    /**
76
-     * Sets a meta field indicating that this TXN is locked and should not be updated in the db.
77
-     * If a lock has already been set, then we will attempt to remove it in case it has expired.
78
-     * If that also fails, then an exception is thrown.
79
-     *
80
-     * @throws EE_Error
81
-     * @throws InvalidArgumentException
82
-     * @throws InvalidDataTypeException
83
-     * @throws InvalidInterfaceException
84
-     * @throws ReflectionException
85
-     */
86
-    public function lock()
87
-    {
88
-        // attempt to set lock, but if that fails...
89
-        if (! $this->add_extra_meta('lock', time(), true)) {
90
-            // then attempt to remove the lock in case it is expired
91
-            if ($this->_remove_expired_lock()) {
92
-                // if removal was successful, then try setting lock again
93
-                $this->lock();
94
-            } else {
95
-                // but if the lock can not be removed, then throw an exception
96
-                throw new EE_Error(
97
-                    sprintf(
98
-                        esc_html__(
99
-                            'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.',
100
-                            'event_espresso'
101
-                        ),
102
-                        $this->ID()
103
-                    )
104
-                );
105
-            }
106
-        }
107
-    }
108
-
109
-
110
-    /**
111
-     * removes transaction lock applied in EE_Transaction::lock()
112
-     *
113
-     * @return int
114
-     * @throws EE_Error
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidInterfaceException
118
-     * @throws ReflectionException
119
-     */
120
-    public function unlock()
121
-    {
122
-        return $this->delete_extra_meta('lock');
123
-    }
124
-
125
-
126
-    /**
127
-     * Decides whether or not now is the right time to update the transaction.
128
-     * This is useful because we don't always know if it is safe to update the transaction
129
-     * and its related data. why?
130
-     * because it's possible that the transaction is being used in another
131
-     * request and could overwrite anything we save.
132
-     * So we want to only update the txn once we know that won't happen.
133
-     * We also check that the lock isn't expired, and remove it if it is
134
-     *
135
-     * @return boolean
136
-     * @throws EE_Error
137
-     * @throws InvalidArgumentException
138
-     * @throws InvalidDataTypeException
139
-     * @throws InvalidInterfaceException
140
-     * @throws ReflectionException
141
-     */
142
-    public function is_locked()
143
-    {
144
-        // if TXN is not locked, then return false immediately
145
-        if (! $this->_get_lock()) {
146
-            return false;
147
-        }
148
-        // if not, then let's try and remove the lock in case it's expired...
149
-        // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false)
150
-        // and a positive number if the lock was removed (ie: number of locks deleted),
151
-        // so we need to return the opposite
152
-        return ! $this->_remove_expired_lock() ? true : false;
153
-    }
154
-
155
-
156
-    /**
157
-     * Gets the meta field indicating that this TXN is locked
158
-     *
159
-     * @return int
160
-     * @throws EE_Error
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidInterfaceException
164
-     * @throws ReflectionException
165
-     */
166
-    protected function _get_lock()
167
-    {
168
-        return (int) $this->get_extra_meta('lock', true, 0);
169
-    }
170
-
171
-
172
-    /**
173
-     * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated
174
-     *
175
-     * @return int
176
-     * @throws EE_Error
177
-     * @throws InvalidArgumentException
178
-     * @throws InvalidDataTypeException
179
-     * @throws InvalidInterfaceException
180
-     * @throws ReflectionException
181
-     */
182
-    protected function _remove_expired_lock()
183
-    {
184
-        $locked = $this->_get_lock();
185
-        if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) {
186
-            return $this->unlock();
187
-        }
188
-        return 0;
189
-    }
190
-
191
-
192
-    /**
193
-     * Set transaction total
194
-     *
195
-     * @param float $total total value of transaction
196
-     * @throws EE_Error
197
-     * @throws InvalidArgumentException
198
-     * @throws InvalidDataTypeException
199
-     * @throws InvalidInterfaceException
200
-     * @throws ReflectionException
201
-     */
202
-    public function set_total($total = 0.00)
203
-    {
204
-        $this->set('TXN_total', (float) $total);
205
-    }
206
-
207
-
208
-    /**
209
-     * Set Total Amount Paid to Date
210
-     *
211
-     * @param float $total_paid total amount paid to date (sum of all payments)
212
-     * @throws EE_Error
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidDataTypeException
215
-     * @throws InvalidInterfaceException
216
-     * @throws ReflectionException
217
-     */
218
-    public function set_paid($total_paid = 0.00)
219
-    {
220
-        $this->set('TXN_paid', (float) $total_paid);
221
-    }
222
-
223
-
224
-    /**
225
-     * Set transaction status
226
-     *
227
-     * @param string $status        whether the transaction is open, declined, accepted,
228
-     *                              or any number of custom values that can be set
229
-     * @throws EE_Error
230
-     * @throws InvalidArgumentException
231
-     * @throws InvalidDataTypeException
232
-     * @throws InvalidInterfaceException
233
-     * @throws ReflectionException
234
-     */
235
-    public function set_status($status = '')
236
-    {
237
-        $this->set('STS_ID', $status);
238
-    }
239
-
240
-
241
-    /**
242
-     * Set hash salt
243
-     *
244
-     * @param string $hash_salt required for some payment gateways
245
-     * @throws EE_Error
246
-     * @throws InvalidArgumentException
247
-     * @throws InvalidDataTypeException
248
-     * @throws InvalidInterfaceException
249
-     * @throws ReflectionException
250
-     */
251
-    public function set_hash_salt($hash_salt = '')
252
-    {
253
-        $this->set('TXN_hash_salt', $hash_salt);
254
-    }
255
-
256
-
257
-    /**
258
-     * Sets TXN_reg_steps array
259
-     *
260
-     * @param array $txn_reg_steps
261
-     * @throws EE_Error
262
-     * @throws InvalidArgumentException
263
-     * @throws InvalidDataTypeException
264
-     * @throws InvalidInterfaceException
265
-     * @throws ReflectionException
266
-     */
267
-    public function set_reg_steps(array $txn_reg_steps)
268
-    {
269
-        $this->set('TXN_reg_steps', $txn_reg_steps);
270
-    }
271
-
272
-
273
-    /**
274
-     * Gets TXN_reg_steps
275
-     *
276
-     * @return array
277
-     * @throws EE_Error
278
-     * @throws InvalidArgumentException
279
-     * @throws InvalidDataTypeException
280
-     * @throws InvalidInterfaceException
281
-     * @throws ReflectionException
282
-     */
283
-    public function reg_steps()
284
-    {
285
-        $TXN_reg_steps = $this->get('TXN_reg_steps');
286
-        return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array();
287
-    }
288
-
289
-
290
-    /**
291
-     * @return string of transaction's total cost, with currency symbol and decimal
292
-     * @throws EE_Error
293
-     * @throws InvalidArgumentException
294
-     * @throws InvalidDataTypeException
295
-     * @throws InvalidInterfaceException
296
-     * @throws ReflectionException
297
-     */
298
-    public function pretty_total()
299
-    {
300
-        return $this->get_pretty('TXN_total');
301
-    }
302
-
303
-
304
-    /**
305
-     * Gets the amount paid in a pretty string (formatted and with currency symbol)
306
-     *
307
-     * @return string
308
-     * @throws EE_Error
309
-     * @throws InvalidArgumentException
310
-     * @throws InvalidDataTypeException
311
-     * @throws InvalidInterfaceException
312
-     * @throws ReflectionException
313
-     */
314
-    public function pretty_paid()
315
-    {
316
-        return $this->get_pretty('TXN_paid');
317
-    }
318
-
319
-
320
-    /**
321
-     * calculate the amount remaining for this transaction and return;
322
-     *
323
-     * @return float amount remaining
324
-     * @throws EE_Error
325
-     * @throws InvalidArgumentException
326
-     * @throws InvalidDataTypeException
327
-     * @throws InvalidInterfaceException
328
-     * @throws ReflectionException
329
-     */
330
-    public function remaining()
331
-    {
332
-        return $this->total() - $this->paid();
333
-    }
334
-
335
-
336
-    /**
337
-     * get Transaction Total
338
-     *
339
-     * @return float
340
-     * @throws EE_Error
341
-     * @throws InvalidArgumentException
342
-     * @throws InvalidDataTypeException
343
-     * @throws InvalidInterfaceException
344
-     * @throws ReflectionException
345
-     */
346
-    public function total()
347
-    {
348
-        return (float) $this->get('TXN_total');
349
-    }
350
-
351
-
352
-    /**
353
-     * get Total Amount Paid to Date
354
-     *
355
-     * @return float
356
-     * @throws EE_Error
357
-     * @throws InvalidArgumentException
358
-     * @throws InvalidDataTypeException
359
-     * @throws InvalidInterfaceException
360
-     * @throws ReflectionException
361
-     */
362
-    public function paid()
363
-    {
364
-        return (float) $this->get('TXN_paid');
365
-    }
366
-
367
-
368
-    /**
369
-     * @return mixed|null
370
-     * @throws EE_Error
371
-     * @throws InvalidArgumentException
372
-     * @throws InvalidDataTypeException
373
-     * @throws InvalidInterfaceException
374
-     * @throws ReflectionException
375
-     */
376
-    public function get_cart_session()
377
-    {
378
-        $session_data = (array) $this->get('TXN_session_data');
379
-        return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart
380
-            ? $session_data['cart']
381
-            : null;
382
-    }
383
-
384
-
385
-    /**
386
-     * get Transaction session data
387
-     *
388
-     * @return array|mixed
389
-     * @throws EE_Error
390
-     * @throws InvalidArgumentException
391
-     * @throws InvalidDataTypeException
392
-     * @throws InvalidInterfaceException
393
-     * @throws ReflectionException
394
-     */
395
-    public function session_data()
396
-    {
397
-        $session_data = $this->get('TXN_session_data');
398
-        if (empty($session_data)) {
399
-            $session_data = array(
400
-                'id'            => null,
401
-                'user_id'       => null,
402
-                'ip_address'    => null,
403
-                'user_agent'    => null,
404
-                'init_access'   => null,
405
-                'last_access'   => null,
406
-                'pages_visited' => array(),
407
-            );
408
-        }
409
-        return $session_data;
410
-    }
411
-
412
-
413
-    /**
414
-     * Set session data within the TXN object
415
-     *
416
-     * @param EE_Session|array $session_data
417
-     * @throws EE_Error
418
-     * @throws InvalidArgumentException
419
-     * @throws InvalidDataTypeException
420
-     * @throws InvalidInterfaceException
421
-     * @throws ReflectionException
422
-     */
423
-    public function set_txn_session_data($session_data)
424
-    {
425
-        if ($session_data instanceof EE_Session) {
426
-            $this->set('TXN_session_data', $session_data->get_session_data(null, true));
427
-        } else {
428
-            $this->set('TXN_session_data', $session_data);
429
-        }
430
-    }
431
-
432
-
433
-    /**
434
-     * get Transaction hash salt
435
-     *
436
-     * @return mixed
437
-     * @throws EE_Error
438
-     * @throws InvalidArgumentException
439
-     * @throws InvalidDataTypeException
440
-     * @throws InvalidInterfaceException
441
-     * @throws ReflectionException
442
-     */
443
-    public function hash_salt_()
444
-    {
445
-        return $this->get('TXN_hash_salt');
446
-    }
447
-
448
-
449
-    /**
450
-     * Returns the transaction datetime as either:
451
-     *            - unix timestamp format ($format = false, $gmt = true)
452
-     *            - formatted date string including the UTC (timezone) offset ($format = true ($gmt
453
-     *              has no affect with this option)), this also may include a timezone abbreviation if the
454
-     *              set timezone in this class differs from what the timezone is on the blog.
455
-     *            - formatted date string including the UTC (timezone) offset (default).
456
-     *
457
-     * @param boolean $format   - whether to return a unix timestamp (default) or formatted date string
458
-     * @param boolean $gmt      - whether to return a unix timestamp with UTC offset applied (default)
459
-     *                          or no UTC offset applied
460
-     * @return string | int
461
-     * @throws EE_Error
462
-     * @throws InvalidArgumentException
463
-     * @throws InvalidDataTypeException
464
-     * @throws InvalidInterfaceException
465
-     * @throws ReflectionException
466
-     */
467
-    public function datetime($format = false, $gmt = false)
468
-    {
469
-        if ($format) {
470
-            return $this->get_pretty('TXN_timestamp');
471
-        }
472
-        if ($gmt) {
473
-            return $this->get_raw('TXN_timestamp');
474
-        }
475
-        return $this->get('TXN_timestamp');
476
-    }
477
-
478
-
479
-    /**
480
-     * Gets registrations on this transaction
481
-     *
482
-     * @param array   $query_params array of query parameters
483
-     * @param boolean $get_cached   TRUE to retrieve cached registrations or FALSE to pull from the db
484
-     * @return EE_Base_Class[]|EE_Registration[]
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws InvalidDataTypeException
488
-     * @throws InvalidInterfaceException
489
-     * @throws ReflectionException
490
-     */
491
-    public function registrations($query_params = array(), $get_cached = false)
492
-    {
493
-        $query_params = (empty($query_params) || ! is_array($query_params))
494
-            ? array(
495
-                'order_by' => array(
496
-                    'Event.EVT_name'     => 'ASC',
497
-                    'Attendee.ATT_lname' => 'ASC',
498
-                    'Attendee.ATT_fname' => 'ASC',
499
-                ),
500
-            )
501
-            : $query_params;
502
-        $query_params = $get_cached ? array() : $query_params;
503
-        return $this->get_many_related('Registration', $query_params);
504
-    }
505
-
506
-
507
-    /**
508
-     * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event
509
-     * function for getting attendees and how many registrations they each have for an event)
510
-     *
511
-     * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT'
512
-     * @throws EE_Error
513
-     * @throws InvalidArgumentException
514
-     * @throws InvalidDataTypeException
515
-     * @throws InvalidInterfaceException
516
-     * @throws ReflectionException
517
-     */
518
-    public function attendees()
519
-    {
520
-        return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID())));
521
-    }
522
-
523
-
524
-    /**
525
-     * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default
526
-     *
527
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
528
-     * @return EE_Base_Class[]|EE_Payment[]
529
-     * @throws EE_Error
530
-     * @throws InvalidArgumentException
531
-     * @throws InvalidDataTypeException
532
-     * @throws InvalidInterfaceException
533
-     * @throws ReflectionException
534
-     */
535
-    public function payments($query_params = array())
536
-    {
537
-        return $this->get_many_related('Payment', $query_params);
538
-    }
539
-
540
-
541
-    /**
542
-     * gets only approved payments for this transaction
543
-     *
544
-     * @return EE_Base_Class[]|EE_Payment[]
545
-     * @throws EE_Error
546
-     * @throws InvalidArgumentException
547
-     * @throws ReflectionException
548
-     * @throws InvalidDataTypeException
549
-     * @throws InvalidInterfaceException
550
-     */
551
-    public function approved_payments()
552
-    {
553
-        EE_Registry::instance()->load_model('Payment');
554
-        return $this->get_many_related(
555
-            'Payment',
556
-            array(
557
-                array('STS_ID' => EEM_Payment::status_id_approved),
558
-                'order_by' => array('PAY_timestamp' => 'DESC'),
559
-            )
560
-        );
561
-    }
562
-
563
-
564
-    /**
565
-     * Gets all payments which have not been approved
566
-     *
567
-     * @return EE_Base_Class[]|EEI_Payment[]
568
-     * @throws EE_Error if a model is misconfigured somehow
569
-     * @throws InvalidArgumentException
570
-     * @throws InvalidDataTypeException
571
-     * @throws InvalidInterfaceException
572
-     * @throws ReflectionException
573
-     */
574
-    public function pending_payments()
575
-    {
576
-        return $this->get_many_related(
577
-            'Payment',
578
-            array(
579
-                array(
580
-                    'STS_ID' => EEM_Payment::status_id_pending,
581
-                ),
582
-                'order_by' => array(
583
-                    'PAY_timestamp' => 'DESC',
584
-                ),
585
-            )
586
-        );
587
-    }
588
-
589
-
590
-    /**
591
-     * echoes $this->pretty_status()
592
-     *
593
-     * @param bool $show_icons
594
-     * @throws EE_Error
595
-     * @throws InvalidArgumentException
596
-     * @throws InvalidDataTypeException
597
-     * @throws InvalidInterfaceException
598
-     * @throws ReflectionException
599
-     */
600
-    public function e_pretty_status($show_icons = false)
601
-    {
602
-        echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags());
603
-    }
604
-
605
-
606
-    /**
607
-     * returns a pretty version of the status, good for displaying to users
608
-     *
609
-     * @param bool $show_icons
610
-     * @return string
611
-     * @throws EE_Error
612
-     * @throws InvalidArgumentException
613
-     * @throws InvalidDataTypeException
614
-     * @throws InvalidInterfaceException
615
-     * @throws ReflectionException
616
-     */
617
-    public function pretty_status($show_icons = false)
618
-    {
619
-        $status = EEM_Status::instance()->localized_status(
620
-            array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
621
-            false,
622
-            'sentence'
623
-        );
624
-        $icon = '';
625
-        switch ($this->status_ID()) {
626
-            case EEM_Transaction::complete_status_code:
627
-                $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : '';
628
-                break;
629
-            case EEM_Transaction::incomplete_status_code:
630
-                $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>'
631
-                    : '';
632
-                break;
633
-            case EEM_Transaction::abandoned_status_code:
634
-                $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : '';
635
-                break;
636
-            case EEM_Transaction::failed_status_code:
637
-                $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : '';
638
-                break;
639
-            case EEM_Transaction::overpaid_status_code:
640
-                $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : '';
641
-                break;
642
-        }
643
-        return $icon . $status[ $this->status_ID() ];
644
-    }
645
-
646
-
647
-    /**
648
-     * get Transaction Status
649
-     *
650
-     * @return mixed
651
-     * @throws EE_Error
652
-     * @throws InvalidArgumentException
653
-     * @throws InvalidDataTypeException
654
-     * @throws InvalidInterfaceException
655
-     * @throws ReflectionException
656
-     */
657
-    public function status_ID()
658
-    {
659
-        return $this->get('STS_ID');
660
-    }
661
-
662
-
663
-    /**
664
-     * Returns TRUE or FALSE for whether or not this transaction cost any money
665
-     *
666
-     * @return boolean
667
-     * @throws EE_Error
668
-     * @throws InvalidArgumentException
669
-     * @throws InvalidDataTypeException
670
-     * @throws InvalidInterfaceException
671
-     * @throws ReflectionException
672
-     */
673
-    public function is_free()
674
-    {
675
-        return EEH_Money::compare_floats($this->get('TXN_total'), 0, '==');
676
-    }
677
-
678
-
679
-    /**
680
-     * Returns whether this transaction is complete
681
-     * Useful in templates and other logic for deciding if we should ask for another payment...
682
-     *
683
-     * @return boolean
684
-     * @throws EE_Error
685
-     * @throws InvalidArgumentException
686
-     * @throws InvalidDataTypeException
687
-     * @throws InvalidInterfaceException
688
-     * @throws ReflectionException
689
-     */
690
-    public function is_completed()
691
-    {
692
-        return $this->status_ID() === EEM_Transaction::complete_status_code;
693
-    }
694
-
695
-
696
-    /**
697
-     * Returns whether this transaction is incomplete
698
-     * Useful in templates and other logic for deciding if we should ask for another payment...
699
-     *
700
-     * @return boolean
701
-     * @throws EE_Error
702
-     * @throws InvalidArgumentException
703
-     * @throws InvalidDataTypeException
704
-     * @throws InvalidInterfaceException
705
-     * @throws ReflectionException
706
-     */
707
-    public function is_incomplete()
708
-    {
709
-        return $this->status_ID() === EEM_Transaction::incomplete_status_code;
710
-    }
711
-
712
-
713
-    /**
714
-     * Returns whether this transaction is overpaid
715
-     * Useful in templates and other logic for deciding if monies need to be refunded
716
-     *
717
-     * @return boolean
718
-     * @throws EE_Error
719
-     * @throws InvalidArgumentException
720
-     * @throws InvalidDataTypeException
721
-     * @throws InvalidInterfaceException
722
-     * @throws ReflectionException
723
-     */
724
-    public function is_overpaid()
725
-    {
726
-        return $this->status_ID() === EEM_Transaction::overpaid_status_code;
727
-    }
728
-
729
-
730
-    /**
731
-     * Returns whether this transaction was abandoned
732
-     * meaning that the transaction/registration process was somehow interrupted and never completed
733
-     * but that contact information exists for at least one registrant
734
-     *
735
-     * @return boolean
736
-     * @throws EE_Error
737
-     * @throws InvalidArgumentException
738
-     * @throws InvalidDataTypeException
739
-     * @throws InvalidInterfaceException
740
-     * @throws ReflectionException
741
-     */
742
-    public function is_abandoned()
743
-    {
744
-        return $this->status_ID() === EEM_Transaction::abandoned_status_code;
745
-    }
746
-
747
-
748
-    /**
749
-     * Returns whether this transaction failed
750
-     * meaning that the transaction/registration process was somehow interrupted and never completed
751
-     * and that NO contact information exists for any registrants
752
-     *
753
-     * @return boolean
754
-     * @throws EE_Error
755
-     * @throws InvalidArgumentException
756
-     * @throws InvalidDataTypeException
757
-     * @throws InvalidInterfaceException
758
-     * @throws ReflectionException
759
-     */
760
-    public function failed()
761
-    {
762
-        return $this->status_ID() === EEM_Transaction::failed_status_code;
763
-    }
764
-
765
-
766
-    /**
767
-     * This returns the url for the invoice of this transaction
768
-     *
769
-     * @param string $type 'html' or 'pdf' (default is pdf)
770
-     * @return string
771
-     * @throws EE_Error
772
-     * @throws InvalidArgumentException
773
-     * @throws InvalidDataTypeException
774
-     * @throws InvalidInterfaceException
775
-     * @throws ReflectionException
776
-     */
777
-    public function invoice_url($type = 'html')
778
-    {
779
-        $REG = $this->primary_registration();
780
-        if (! $REG instanceof EE_Registration) {
781
-            return '';
782
-        }
783
-        return $REG->invoice_url($type);
784
-    }
785
-
786
-
787
-    /**
788
-     * Gets the primary registration only
789
-     *
790
-     * @return EE_Base_Class|EE_Registration
791
-     * @throws EE_Error
792
-     * @throws InvalidArgumentException
793
-     * @throws InvalidDataTypeException
794
-     * @throws InvalidInterfaceException
795
-     * @throws ReflectionException
796
-     */
797
-    public function primary_registration()
798
-    {
799
-        $registrations = (array) $this->get_many_related(
800
-            'Registration',
801
-            array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT))
802
-        );
803
-        foreach ($registrations as $registration) {
804
-            // valid registration that is NOT cancelled or declined ?
805
-            if (
806
-                $registration instanceof EE_Registration
807
-                && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true)
808
-            ) {
809
-                return $registration;
810
-            }
811
-        }
812
-        // nothing valid found, so just return first thing from array of results
813
-        return reset($registrations);
814
-    }
815
-
816
-
817
-    /**
818
-     * Gets the URL for viewing the receipt
819
-     *
820
-     * @param string $type 'pdf' or 'html' (default is 'html')
821
-     * @return string
822
-     * @throws EE_Error
823
-     * @throws InvalidArgumentException
824
-     * @throws InvalidDataTypeException
825
-     * @throws InvalidInterfaceException
826
-     * @throws ReflectionException
827
-     */
828
-    public function receipt_url($type = 'html')
829
-    {
830
-        $REG = $this->primary_registration();
831
-        if (! $REG instanceof EE_Registration) {
832
-            return '';
833
-        }
834
-        return $REG->receipt_url($type);
835
-    }
836
-
837
-
838
-    /**
839
-     * Gets the URL of the thank you page with this registration REG_url_link added as
840
-     * a query parameter
841
-     *
842
-     * @return string
843
-     * @throws EE_Error
844
-     * @throws InvalidArgumentException
845
-     * @throws InvalidDataTypeException
846
-     * @throws InvalidInterfaceException
847
-     * @throws ReflectionException
848
-     */
849
-    public function payment_overview_url()
850
-    {
851
-        $primary_registration = $this->primary_registration();
852
-        return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false;
853
-    }
854
-
855
-
856
-    /**
857
-     * @return string
858
-     * @throws EE_Error
859
-     * @throws InvalidArgumentException
860
-     * @throws InvalidDataTypeException
861
-     * @throws InvalidInterfaceException
862
-     * @throws ReflectionException
863
-     */
864
-    public function gateway_response_on_transaction()
865
-    {
866
-        $payment = $this->get_first_related('Payment');
867
-        return $payment instanceof EE_Payment ? $payment->gateway_response() : '';
868
-    }
869
-
870
-
871
-    /**
872
-     * Get the status object of this object
873
-     *
874
-     * @return EE_Base_Class|EE_Status
875
-     * @throws EE_Error
876
-     * @throws InvalidArgumentException
877
-     * @throws InvalidDataTypeException
878
-     * @throws InvalidInterfaceException
879
-     * @throws ReflectionException
880
-     */
881
-    public function status_obj()
882
-    {
883
-        return $this->get_first_related('Status');
884
-    }
885
-
886
-
887
-    /**
888
-     * Gets all the extra meta info on this payment
889
-     *
890
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
891
-     * @return EE_Base_Class[]|EE_Extra_Meta
892
-     * @throws EE_Error
893
-     * @throws InvalidArgumentException
894
-     * @throws InvalidDataTypeException
895
-     * @throws InvalidInterfaceException
896
-     * @throws ReflectionException
897
-     */
898
-    public function extra_meta($query_params = array())
899
-    {
900
-        return $this->get_many_related('Extra_Meta', $query_params);
901
-    }
902
-
903
-
904
-    /**
905
-     * Wrapper for _add_relation_to
906
-     *
907
-     * @param EE_Registration $registration
908
-     * @return EE_Base_Class the relation was added to
909
-     * @throws EE_Error
910
-     * @throws InvalidArgumentException
911
-     * @throws InvalidDataTypeException
912
-     * @throws InvalidInterfaceException
913
-     * @throws ReflectionException
914
-     */
915
-    public function add_registration(EE_Registration $registration)
916
-    {
917
-        return $this->_add_relation_to($registration, 'Registration');
918
-    }
919
-
920
-
921
-    /**
922
-     * Removes the given registration from being related (even before saving this transaction).
923
-     * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations
924
-     *
925
-     * @param int $registration_or_id
926
-     * @return EE_Base_Class that was removed from being related
927
-     * @throws EE_Error
928
-     * @throws InvalidArgumentException
929
-     * @throws InvalidDataTypeException
930
-     * @throws InvalidInterfaceException
931
-     * @throws ReflectionException
932
-     */
933
-    public function remove_registration_with_id($registration_or_id)
934
-    {
935
-        return $this->_remove_relation_to($registration_or_id, 'Registration');
936
-    }
937
-
938
-
939
-    /**
940
-     * Gets all the line items which are for ACTUAL items
941
-     *
942
-     * @return EE_Line_Item[]
943
-     * @throws EE_Error
944
-     * @throws InvalidArgumentException
945
-     * @throws InvalidDataTypeException
946
-     * @throws InvalidInterfaceException
947
-     * @throws ReflectionException
948
-     */
949
-    public function items_purchased()
950
-    {
951
-        return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item)));
952
-    }
953
-
954
-
955
-    /**
956
-     * Wrapper for _add_relation_to
957
-     *
958
-     * @param EE_Line_Item $line_item
959
-     * @return EE_Base_Class the relation was added to
960
-     * @throws EE_Error
961
-     * @throws InvalidArgumentException
962
-     * @throws InvalidDataTypeException
963
-     * @throws InvalidInterfaceException
964
-     * @throws ReflectionException
965
-     */
966
-    public function add_line_item(EE_Line_Item $line_item)
967
-    {
968
-        return $this->_add_relation_to($line_item, 'Line_Item');
969
-    }
970
-
971
-
972
-    /**
973
-     * Gets ALL the line items related to this transaction (unstructured)
974
-     *
975
-     * @param array $query_params
976
-     * @return EE_Base_Class[]|EE_Line_Item[]
977
-     * @throws EE_Error
978
-     * @throws InvalidArgumentException
979
-     * @throws InvalidDataTypeException
980
-     * @throws InvalidInterfaceException
981
-     * @throws ReflectionException
982
-     */
983
-    public function line_items($query_params = array())
984
-    {
985
-        return $this->get_many_related('Line_Item', $query_params);
986
-    }
987
-
988
-
989
-    /**
990
-     * Gets all the line items which are taxes on the total
991
-     *
992
-     * @return EE_Line_Item[]
993
-     * @throws EE_Error
994
-     * @throws InvalidArgumentException
995
-     * @throws InvalidDataTypeException
996
-     * @throws InvalidInterfaceException
997
-     * @throws ReflectionException
998
-     */
999
-    public function tax_items()
1000
-    {
1001
-        return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax)));
1002
-    }
1003
-
1004
-
1005
-    /**
1006
-     * Gets the total line item (which is a parent of all other related line items,
1007
-     * meaning it takes them all into account on its total)
1008
-     *
1009
-     * @param bool $create_if_not_found
1010
-     * @return \EE_Line_Item
1011
-     * @throws EE_Error
1012
-     * @throws InvalidArgumentException
1013
-     * @throws InvalidDataTypeException
1014
-     * @throws InvalidInterfaceException
1015
-     * @throws ReflectionException
1016
-     */
1017
-    public function total_line_item($create_if_not_found = true)
1018
-    {
1019
-        $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total)));
1020
-        if (! $item && $create_if_not_found) {
1021
-            $item = EEH_Line_Item::create_total_line_item($this);
1022
-        }
1023
-        return $item;
1024
-    }
1025
-
1026
-
1027
-    /**
1028
-     * Returns the total amount of tax on this transaction
1029
-     * (assumes there's only one tax subtotal line item)
1030
-     *
1031
-     * @return float
1032
-     * @throws EE_Error
1033
-     * @throws InvalidArgumentException
1034
-     * @throws InvalidDataTypeException
1035
-     * @throws InvalidInterfaceException
1036
-     * @throws ReflectionException
1037
-     */
1038
-    public function tax_total()
1039
-    {
1040
-        $tax_line_item = $this->tax_total_line_item();
1041
-        if ($tax_line_item) {
1042
-            return (float) $tax_line_item->total();
1043
-        }
1044
-        return (float) 0;
1045
-    }
1046
-
1047
-
1048
-    /**
1049
-     * Gets the tax subtotal line item (assumes there's only one)
1050
-     *
1051
-     * @return EE_Line_Item
1052
-     * @throws EE_Error
1053
-     * @throws InvalidArgumentException
1054
-     * @throws InvalidDataTypeException
1055
-     * @throws InvalidInterfaceException
1056
-     * @throws ReflectionException
1057
-     */
1058
-    public function tax_total_line_item()
1059
-    {
1060
-        return EEH_Line_Item::get_taxes_subtotal($this->total_line_item());
1061
-    }
1062
-
1063
-
1064
-    /**
1065
-     * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee.
1066
-     *
1067
-     * @return EE_Form_Section_Proper
1068
-     * @throws EE_Error
1069
-     * @throws InvalidArgumentException
1070
-     * @throws InvalidDataTypeException
1071
-     * @throws InvalidInterfaceException
1072
-     * @throws ReflectionException
1073
-     */
1074
-    public function billing_info()
1075
-    {
1076
-        $payment_method = $this->payment_method();
1077
-        if (! $payment_method) {
1078
-            EE_Error::add_error(
1079
-                esc_html__(
1080
-                    'Could not find billing info for transaction because no gateway has been used for it yet',
1081
-                    'event_espresso'
1082
-                ),
1083
-                __FILE__,
1084
-                __FUNCTION__,
1085
-                __LINE__
1086
-            );
1087
-            return null;
1088
-        }
1089
-        $primary_reg = $this->primary_registration();
1090
-        if (! $primary_reg) {
1091
-            EE_Error::add_error(
1092
-                esc_html__(
1093
-                    'Cannot get billing info for gateway %s on transaction because no primary registration exists',
1094
-                    'event_espresso'
1095
-                ),
1096
-                __FILE__,
1097
-                __FUNCTION__,
1098
-                __LINE__
1099
-            );
1100
-            return null;
1101
-        }
1102
-        $attendee = $primary_reg->attendee();
1103
-        if (! $attendee) {
1104
-            EE_Error::add_error(
1105
-                esc_html__(
1106
-                    'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists',
1107
-                    'event_espresso'
1108
-                ),
1109
-                __FILE__,
1110
-                __FUNCTION__,
1111
-                __LINE__
1112
-            );
1113
-            return null;
1114
-        }
1115
-        return $attendee->billing_info_for_payment_method($payment_method);
1116
-    }
1117
-
1118
-
1119
-    /**
1120
-     * Gets PMD_ID
1121
-     *
1122
-     * @return int
1123
-     * @throws EE_Error
1124
-     * @throws InvalidArgumentException
1125
-     * @throws InvalidDataTypeException
1126
-     * @throws InvalidInterfaceException
1127
-     * @throws ReflectionException
1128
-     */
1129
-    public function payment_method_ID()
1130
-    {
1131
-        return $this->get('PMD_ID');
1132
-    }
1133
-
1134
-
1135
-    /**
1136
-     * Sets PMD_ID
1137
-     *
1138
-     * @param int $PMD_ID
1139
-     * @throws EE_Error
1140
-     * @throws InvalidArgumentException
1141
-     * @throws InvalidDataTypeException
1142
-     * @throws InvalidInterfaceException
1143
-     * @throws ReflectionException
1144
-     */
1145
-    public function set_payment_method_ID($PMD_ID)
1146
-    {
1147
-        $this->set('PMD_ID', $PMD_ID);
1148
-    }
1149
-
1150
-
1151
-    /**
1152
-     * Gets the last-used payment method on this transaction
1153
-     * (we COULD just use the last-made payment, but some payment methods, namely
1154
-     * offline ones, dont' create payments)
1155
-     *
1156
-     * @return EE_Payment_Method
1157
-     * @throws EE_Error
1158
-     * @throws InvalidArgumentException
1159
-     * @throws InvalidDataTypeException
1160
-     * @throws InvalidInterfaceException
1161
-     * @throws ReflectionException
1162
-     */
1163
-    public function payment_method()
1164
-    {
1165
-        $pm = $this->get_first_related('Payment_Method');
1166
-        if ($pm instanceof EE_Payment_Method) {
1167
-            return $pm;
1168
-        }
1169
-        $last_payment = $this->last_payment();
1170
-        if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) {
1171
-            return $last_payment->payment_method();
1172
-        }
1173
-        return null;
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * Gets the last payment made
1179
-     *
1180
-     * @return EE_Base_Class|EE_Payment
1181
-     * @throws EE_Error
1182
-     * @throws InvalidArgumentException
1183
-     * @throws InvalidDataTypeException
1184
-     * @throws InvalidInterfaceException
1185
-     * @throws ReflectionException
1186
-     */
1187
-    public function last_payment()
1188
-    {
1189
-        return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc')));
1190
-    }
1191
-
1192
-
1193
-    /**
1194
-     * Gets all the line items which are unrelated to tickets on this transaction
1195
-     *
1196
-     * @return EE_Line_Item[]
1197
-     * @throws EE_Error
1198
-     * @throws InvalidArgumentException
1199
-     * @throws InvalidDataTypeException
1200
-     * @throws InvalidInterfaceException
1201
-     * @throws ReflectionException
1202
-     */
1203
-    public function non_ticket_line_items()
1204
-    {
1205
-        return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID());
1206
-    }
1207
-
1208
-
1209
-    /**
1210
-     * possibly toggles TXN status
1211
-     *
1212
-     * @param  boolean $update whether to save the TXN
1213
-     * @return bool whether the TXN was saved
1214
-     * @throws EE_Error
1215
-     * @throws InvalidArgumentException
1216
-     * @throws InvalidDataTypeException
1217
-     * @throws InvalidInterfaceException
1218
-     * @throws ReflectionException
1219
-     * @throws RuntimeException
1220
-     */
1221
-    public function update_status_based_on_total_paid($update = true)
1222
-    {
1223
-        // set transaction status based on comparison of TXN_paid vs TXN_total
1224
-        if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) {
1225
-            $new_txn_status = EEM_Transaction::overpaid_status_code;
1226
-        } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) {
1227
-            $new_txn_status = EEM_Transaction::complete_status_code;
1228
-        } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) {
1229
-            $new_txn_status = EEM_Transaction::incomplete_status_code;
1230
-        } else {
1231
-            throw new RuntimeException(
1232
-                esc_html__('The total paid calculation for this transaction is inaccurate.', 'event_espresso')
1233
-            );
1234
-        }
1235
-        if ($new_txn_status !== $this->status_ID()) {
1236
-            $this->set_status($new_txn_status);
1237
-            if ($update) {
1238
-                return $this->save() ? true : false;
1239
-            }
1240
-        }
1241
-        return false;
1242
-    }
1243
-
1244
-
1245
-    /**
1246
-     * Updates the transaction's status and total_paid based on all the payments
1247
-     * that apply to it
1248
-     *
1249
-     * @deprecated
1250
-     * @return array|bool
1251
-     * @throws EE_Error
1252
-     * @throws InvalidArgumentException
1253
-     * @throws ReflectionException
1254
-     * @throws InvalidDataTypeException
1255
-     * @throws InvalidInterfaceException
1256
-     */
1257
-    public function update_based_on_payments()
1258
-    {
1259
-        EE_Error::doing_it_wrong(
1260
-            __CLASS__ . '::' . __FUNCTION__,
1261
-            sprintf(
1262
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
1263
-                'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'
1264
-            ),
1265
-            '4.6.0'
1266
-        );
1267
-        /** @type EE_Transaction_Processor $transaction_processor */
1268
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1269
-        return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this);
1270
-    }
1271
-
1272
-
1273
-    /**
1274
-     * @return string
1275
-     */
1276
-    public function old_txn_status()
1277
-    {
1278
-        return $this->_old_txn_status;
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     * @param string $old_txn_status
1284
-     */
1285
-    public function set_old_txn_status($old_txn_status)
1286
-    {
1287
-        // only set the first time
1288
-        if ($this->_old_txn_status === null) {
1289
-            $this->_old_txn_status = $old_txn_status;
1290
-        }
1291
-    }
1292
-
1293
-
1294
-    /**
1295
-     * reg_status_updated
1296
-     *
1297
-     * @return bool
1298
-     * @throws EE_Error
1299
-     * @throws InvalidArgumentException
1300
-     * @throws InvalidDataTypeException
1301
-     * @throws InvalidInterfaceException
1302
-     * @throws ReflectionException
1303
-     */
1304
-    public function txn_status_updated()
1305
-    {
1306
-        return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null;
1307
-    }
1308
-
1309
-
1310
-    /**
1311
-     * _reg_steps_completed
1312
-     * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed,
1313
-     * if a $reg_step_slug is provided, then this step will be skipped when testing for completion
1314
-     * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion
1315
-     *
1316
-     * @param string $reg_step_slug
1317
-     * @param bool   $check_all
1318
-     * @return bool|int
1319
-     * @throws EE_Error
1320
-     * @throws InvalidArgumentException
1321
-     * @throws InvalidDataTypeException
1322
-     * @throws InvalidInterfaceException
1323
-     * @throws ReflectionException
1324
-     */
1325
-    private function _reg_steps_completed($reg_step_slug = '', $check_all = true)
1326
-    {
1327
-        $reg_steps = $this->reg_steps();
1328
-        if (! is_array($reg_steps) || empty($reg_steps)) {
1329
-            return false;
1330
-        }
1331
-        // loop thru reg steps array)
1332
-        foreach ($reg_steps as $slug => $reg_step_completed) {
1333
-            // if NOT checking ALL steps (only checking one step)
1334
-            if (! $check_all) {
1335
-                // and this is the one
1336
-                if ($slug === $reg_step_slug) {
1337
-                    return $reg_step_completed;
1338
-                }
1339
-                // skip to next reg step in loop
1340
-                continue;
1341
-            }
1342
-            // $check_all must be true, else we would never have gotten to this point
1343
-            if ($slug === $reg_step_slug) {
1344
-                // if we reach this point, then we are testing either:
1345
-                // all_reg_steps_completed_except() or
1346
-                // all_reg_steps_completed_except_final_step(),
1347
-                // and since this is the reg step EXCEPTION being tested
1348
-                // we want to return true (yes true) if this reg step is NOT completed
1349
-                // ie: "is everything completed except the final step?"
1350
-                // "that is correct... the final step is not completed, but all others are."
1351
-                return $reg_step_completed !== true;
1352
-            }
1353
-            if ($reg_step_completed !== true) {
1354
-                // if any reg step is NOT completed, then ALL steps are not completed
1355
-                return false;
1356
-            }
1357
-        }
1358
-        return true;
1359
-    }
1360
-
1361
-
1362
-    /**
1363
-     * all_reg_steps_completed
1364
-     * returns:
1365
-     *    true if ALL reg steps have been marked as completed
1366
-     *        or false if any step is not completed
1367
-     *
1368
-     * @return bool
1369
-     * @throws EE_Error
1370
-     * @throws InvalidArgumentException
1371
-     * @throws InvalidDataTypeException
1372
-     * @throws InvalidInterfaceException
1373
-     * @throws ReflectionException
1374
-     */
1375
-    public function all_reg_steps_completed()
1376
-    {
1377
-        return $this->_reg_steps_completed();
1378
-    }
1379
-
1380
-
1381
-    /**
1382
-     * all_reg_steps_completed_except
1383
-     * returns:
1384
-     *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
1385
-     *        or false if any other step is not completed
1386
-     *        or false if ALL steps are completed including the exception you are testing !!!
1387
-     *
1388
-     * @param string $exception
1389
-     * @return bool
1390
-     * @throws EE_Error
1391
-     * @throws InvalidArgumentException
1392
-     * @throws InvalidDataTypeException
1393
-     * @throws InvalidInterfaceException
1394
-     * @throws ReflectionException
1395
-     */
1396
-    public function all_reg_steps_completed_except($exception = '')
1397
-    {
1398
-        return $this->_reg_steps_completed($exception);
1399
-    }
1400
-
1401
-
1402
-    /**
1403
-     * all_reg_steps_completed_except
1404
-     * returns:
1405
-     *        true if ALL reg steps, except the final step, have been marked as completed
1406
-     *        or false if any step is not completed
1407
-     *    or false if ALL steps are completed including the final step !!!
1408
-     *
1409
-     * @return bool
1410
-     * @throws EE_Error
1411
-     * @throws InvalidArgumentException
1412
-     * @throws InvalidDataTypeException
1413
-     * @throws InvalidInterfaceException
1414
-     * @throws ReflectionException
1415
-     */
1416
-    public function all_reg_steps_completed_except_final_step()
1417
-    {
1418
-        return $this->_reg_steps_completed('finalize_registration');
1419
-    }
1420
-
1421
-
1422
-    /**
1423
-     * reg_step_completed
1424
-     * returns:
1425
-     *    true if a specific reg step has been marked as completed
1426
-     *    a Unix timestamp if it has been initialized but not yet completed,
1427
-     *    or false if it has not yet been initialized
1428
-     *
1429
-     * @param string $reg_step_slug
1430
-     * @return bool|int
1431
-     * @throws EE_Error
1432
-     * @throws InvalidArgumentException
1433
-     * @throws InvalidDataTypeException
1434
-     * @throws InvalidInterfaceException
1435
-     * @throws ReflectionException
1436
-     */
1437
-    public function reg_step_completed($reg_step_slug)
1438
-    {
1439
-        return $this->_reg_steps_completed($reg_step_slug, false);
1440
-    }
1441
-
1442
-
1443
-    /**
1444
-     * completed_final_reg_step
1445
-     * returns:
1446
-     *    true if the finalize_registration reg step has been marked as completed
1447
-     *    a Unix timestamp if it has been initialized but not yet completed,
1448
-     *    or false if it has not yet been initialized
1449
-     *
1450
-     * @return bool|int
1451
-     * @throws EE_Error
1452
-     * @throws InvalidArgumentException
1453
-     * @throws InvalidDataTypeException
1454
-     * @throws InvalidInterfaceException
1455
-     * @throws ReflectionException
1456
-     */
1457
-    public function final_reg_step_completed()
1458
-    {
1459
-        return $this->_reg_steps_completed('finalize_registration', false);
1460
-    }
1461
-
1462
-
1463
-    /**
1464
-     * set_reg_step_initiated
1465
-     * given a valid TXN_reg_step, this sets it's value to a unix timestamp
1466
-     *
1467
-     * @param string $reg_step_slug
1468
-     * @return boolean
1469
-     * @throws EE_Error
1470
-     * @throws InvalidArgumentException
1471
-     * @throws InvalidDataTypeException
1472
-     * @throws InvalidInterfaceException
1473
-     * @throws ReflectionException
1474
-     */
1475
-    public function set_reg_step_initiated($reg_step_slug)
1476
-    {
1477
-        return $this->_set_reg_step_completed_status($reg_step_slug, time());
1478
-    }
1479
-
1480
-
1481
-    /**
1482
-     * set_reg_step_completed
1483
-     * given a valid TXN_reg_step, this sets the step as completed
1484
-     *
1485
-     * @param string $reg_step_slug
1486
-     * @return boolean
1487
-     * @throws EE_Error
1488
-     * @throws InvalidArgumentException
1489
-     * @throws InvalidDataTypeException
1490
-     * @throws InvalidInterfaceException
1491
-     * @throws ReflectionException
1492
-     */
1493
-    public function set_reg_step_completed($reg_step_slug)
1494
-    {
1495
-        return $this->_set_reg_step_completed_status($reg_step_slug, true);
1496
-    }
1497
-
1498
-
1499
-    /**
1500
-     * set_reg_step_completed
1501
-     * given a valid TXN_reg_step slug, this sets the step as NOT completed
1502
-     *
1503
-     * @param string $reg_step_slug
1504
-     * @return boolean
1505
-     * @throws EE_Error
1506
-     * @throws InvalidArgumentException
1507
-     * @throws InvalidDataTypeException
1508
-     * @throws InvalidInterfaceException
1509
-     * @throws ReflectionException
1510
-     */
1511
-    public function set_reg_step_not_completed($reg_step_slug)
1512
-    {
1513
-        return $this->_set_reg_step_completed_status($reg_step_slug, false);
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     * set_reg_step_completed
1519
-     * given a valid reg step slug, this sets the TXN_reg_step completed status which is either:
1520
-     *
1521
-     * @param  string      $reg_step_slug
1522
-     * @param  boolean|int $status
1523
-     * @return boolean
1524
-     * @throws EE_Error
1525
-     * @throws InvalidArgumentException
1526
-     * @throws InvalidDataTypeException
1527
-     * @throws InvalidInterfaceException
1528
-     * @throws ReflectionException
1529
-     */
1530
-    private function _set_reg_step_completed_status($reg_step_slug, $status)
1531
-    {
1532
-        // validate status
1533
-        $status = is_bool($status) || is_int($status) ? $status : false;
1534
-        // get reg steps array
1535
-        $txn_reg_steps = $this->reg_steps();
1536
-        // if reg step does NOT exist
1537
-        if (! isset($txn_reg_steps[ $reg_step_slug ])) {
1538
-            return false;
1539
-        }
1540
-        // if  we're trying to complete a step that is already completed
1541
-        if ($txn_reg_steps[ $reg_step_slug ] === true) {
1542
-            return true;
1543
-        }
1544
-        // if  we're trying to complete a step that hasn't even started
1545
-        if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) {
1546
-            return false;
1547
-        }
1548
-        // if current status value matches the incoming value (no change)
1549
-        // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890
1550
-        if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) {
1551
-            // this will happen in cases where multiple AJAX requests occur during the same step
1552
-            return true;
1553
-        }
1554
-        // if we're trying to set a start time, but it has already been set...
1555
-        if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) {
1556
-            // skip the update below, but don't return FALSE so that errors won't be displayed
1557
-            return true;
1558
-        }
1559
-        // update completed status
1560
-        $txn_reg_steps[ $reg_step_slug ] = $status;
1561
-        $this->set_reg_steps($txn_reg_steps);
1562
-        $this->save();
1563
-        return true;
1564
-    }
1565
-
1566
-
1567
-    /**
1568
-     * remove_reg_step
1569
-     * given a valid TXN_reg_step slug, this will remove (unset)
1570
-     * the reg step from the TXN reg step array
1571
-     *
1572
-     * @param string $reg_step_slug
1573
-     * @return void
1574
-     * @throws EE_Error
1575
-     * @throws InvalidArgumentException
1576
-     * @throws InvalidDataTypeException
1577
-     * @throws InvalidInterfaceException
1578
-     * @throws ReflectionException
1579
-     */
1580
-    public function remove_reg_step($reg_step_slug)
1581
-    {
1582
-        // get reg steps array
1583
-        $txn_reg_steps = $this->reg_steps();
1584
-        unset($txn_reg_steps[ $reg_step_slug ]);
1585
-        $this->set_reg_steps($txn_reg_steps);
1586
-    }
1587
-
1588
-
1589
-    /**
1590
-     * toggle_failed_transaction_status
1591
-     * upgrades a TXNs status from failed to abandoned,
1592
-     * meaning that contact information has been captured for at least one registrant
1593
-     *
1594
-     * @param bool $save
1595
-     * @return bool
1596
-     * @throws EE_Error
1597
-     * @throws InvalidArgumentException
1598
-     * @throws InvalidDataTypeException
1599
-     * @throws InvalidInterfaceException
1600
-     * @throws ReflectionException
1601
-     */
1602
-    public function toggle_failed_transaction_status($save = true)
1603
-    {
1604
-        // if TXN status is still set as "failed"...
1605
-        if ($this->status_ID() === EEM_Transaction::failed_status_code) {
1606
-            $this->set_status(EEM_Transaction::abandoned_status_code);
1607
-            if ($save) {
1608
-                $this->save();
1609
-            }
1610
-            return true;
1611
-        }
1612
-        return false;
1613
-    }
1614
-
1615
-
1616
-    /**
1617
-     * toggle_abandoned_transaction_status
1618
-     * upgrades a TXNs status from failed or abandoned to incomplete
1619
-     *
1620
-     * @return bool
1621
-     * @throws EE_Error
1622
-     * @throws InvalidArgumentException
1623
-     * @throws InvalidDataTypeException
1624
-     * @throws InvalidInterfaceException
1625
-     * @throws ReflectionException
1626
-     */
1627
-    public function toggle_abandoned_transaction_status()
1628
-    {
1629
-        // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"...
1630
-        $txn_status = $this->status_ID();
1631
-        if (
1632
-            $txn_status === EEM_Transaction::failed_status_code
1633
-            || $txn_status === EEM_Transaction::abandoned_status_code
1634
-        ) {
1635
-            // if a contact record for the primary registrant has been created
1636
-            if (
1637
-                $this->primary_registration() instanceof EE_Registration
1638
-                && $this->primary_registration()->attendee() instanceof EE_Attendee
1639
-            ) {
1640
-                $this->set_status(EEM_Transaction::incomplete_status_code);
1641
-            } else {
1642
-                // no contact record? yer abandoned!
1643
-                $this->set_status(EEM_Transaction::abandoned_status_code);
1644
-            }
1645
-            return true;
1646
-        }
1647
-        return false;
1648
-    }
1649
-
1650
-
1651
-    /**
1652
-     * checks if an Abandoned TXN has any related payments, and if so,
1653
-     * updates the TXN status based on the amount paid
1654
-     *
1655
-     * @throws EE_Error
1656
-     * @throws InvalidDataTypeException
1657
-     * @throws InvalidInterfaceException
1658
-     * @throws InvalidArgumentException
1659
-     * @throws RuntimeException
1660
-     * @throws ReflectionException
1661
-     */
1662
-    public function verify_abandoned_transaction_status()
1663
-    {
1664
-        if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) {
1665
-            return;
1666
-        }
1667
-        $payments = $this->get_many_related('Payment');
1668
-        if (! empty($payments)) {
1669
-            foreach ($payments as $payment) {
1670
-                if ($payment instanceof EE_Payment) {
1671
-                    // kk this TXN should NOT be abandoned
1672
-                    $this->update_status_based_on_total_paid();
1673
-                    if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1674
-                        EE_Error::add_attention(
1675
-                            sprintf(
1676
-                                esc_html__(
1677
-                                    'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.',
1678
-                                    'event_espresso'
1679
-                                ),
1680
-                                $this->ID(),
1681
-                                $this->pretty_status()
1682
-                            )
1683
-                        );
1684
-                    }
1685
-                    // get final reg step status
1686
-                    $finalized = $this->final_reg_step_completed();
1687
-                    // if the 'finalize_registration' step has been initiated (has a timestamp)
1688
-                    // but has not yet been fully completed (TRUE)
1689
-                    if (is_int($finalized) && $finalized !== false && $finalized !== true) {
1690
-                        $this->set_reg_step_completed('finalize_registration');
1691
-                        $this->save();
1692
-                    }
1693
-                }
1694
-            }
1695
-        }
1696
-    }
1697
-
1698
-
1699
-    /**
1700
-     * @since 4.10.4.p
1701
-     * @throws EE_Error
1702
-     * @throws InvalidArgumentException
1703
-     * @throws InvalidDataTypeException
1704
-     * @throws InvalidInterfaceException
1705
-     * @throws ReflectionException
1706
-     * @throws RuntimeException
1707
-     */
1708
-    public function recalculateLineItems()
1709
-    {
1710
-        $total_line_item = $this->total_line_item(false);
1711
-        if ($total_line_item instanceof EE_Line_Item) {
1712
-            EEH_Line_Item::resetIsTaxableForTickets($total_line_item);
1713
-            return EEH_Line_Item::apply_taxes($total_line_item, true);
1714
-        }
1715
-        return false;
1716
-    }
16
+	/**
17
+	 * The length of time in seconds that a lock is applied before being considered expired.
18
+	 * It is not long because a transaction should only be locked for the duration of the request that locked it
19
+	 */
20
+	const LOCK_EXPIRATION = 2;
21
+
22
+	/**
23
+	 * txn status upon initial construction.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $_old_txn_status;
28
+
29
+
30
+	/**
31
+	 * @param array  $props_n_values          incoming values
32
+	 * @param string $timezone                incoming timezone
33
+	 *                                        (if not set the timezone set for the website will be used.)
34
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
35
+	 *                                        date_format and the second value is the time format
36
+	 * @return EE_Transaction
37
+	 * @throws EE_Error
38
+	 * @throws InvalidArgumentException
39
+	 * @throws InvalidDataTypeException
40
+	 * @throws InvalidInterfaceException
41
+	 * @throws ReflectionException
42
+	 */
43
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
44
+	{
45
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
46
+		$txn = $has_object
47
+			? $has_object
48
+			: new self($props_n_values, false, $timezone, $date_formats);
49
+		if (! $has_object) {
50
+			$txn->set_old_txn_status($txn->status_ID());
51
+		}
52
+		return $txn;
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param array  $props_n_values  incoming values from the database
58
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
59
+	 *                                the website will be used.
60
+	 * @return EE_Transaction
61
+	 * @throws EE_Error
62
+	 * @throws InvalidArgumentException
63
+	 * @throws InvalidDataTypeException
64
+	 * @throws InvalidInterfaceException
65
+	 * @throws ReflectionException
66
+	 */
67
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
68
+	{
69
+		$txn = new self($props_n_values, true, $timezone);
70
+		$txn->set_old_txn_status($txn->status_ID());
71
+		return $txn;
72
+	}
73
+
74
+
75
+	/**
76
+	 * Sets a meta field indicating that this TXN is locked and should not be updated in the db.
77
+	 * If a lock has already been set, then we will attempt to remove it in case it has expired.
78
+	 * If that also fails, then an exception is thrown.
79
+	 *
80
+	 * @throws EE_Error
81
+	 * @throws InvalidArgumentException
82
+	 * @throws InvalidDataTypeException
83
+	 * @throws InvalidInterfaceException
84
+	 * @throws ReflectionException
85
+	 */
86
+	public function lock()
87
+	{
88
+		// attempt to set lock, but if that fails...
89
+		if (! $this->add_extra_meta('lock', time(), true)) {
90
+			// then attempt to remove the lock in case it is expired
91
+			if ($this->_remove_expired_lock()) {
92
+				// if removal was successful, then try setting lock again
93
+				$this->lock();
94
+			} else {
95
+				// but if the lock can not be removed, then throw an exception
96
+				throw new EE_Error(
97
+					sprintf(
98
+						esc_html__(
99
+							'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.',
100
+							'event_espresso'
101
+						),
102
+						$this->ID()
103
+					)
104
+				);
105
+			}
106
+		}
107
+	}
108
+
109
+
110
+	/**
111
+	 * removes transaction lock applied in EE_Transaction::lock()
112
+	 *
113
+	 * @return int
114
+	 * @throws EE_Error
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidInterfaceException
118
+	 * @throws ReflectionException
119
+	 */
120
+	public function unlock()
121
+	{
122
+		return $this->delete_extra_meta('lock');
123
+	}
124
+
125
+
126
+	/**
127
+	 * Decides whether or not now is the right time to update the transaction.
128
+	 * This is useful because we don't always know if it is safe to update the transaction
129
+	 * and its related data. why?
130
+	 * because it's possible that the transaction is being used in another
131
+	 * request and could overwrite anything we save.
132
+	 * So we want to only update the txn once we know that won't happen.
133
+	 * We also check that the lock isn't expired, and remove it if it is
134
+	 *
135
+	 * @return boolean
136
+	 * @throws EE_Error
137
+	 * @throws InvalidArgumentException
138
+	 * @throws InvalidDataTypeException
139
+	 * @throws InvalidInterfaceException
140
+	 * @throws ReflectionException
141
+	 */
142
+	public function is_locked()
143
+	{
144
+		// if TXN is not locked, then return false immediately
145
+		if (! $this->_get_lock()) {
146
+			return false;
147
+		}
148
+		// if not, then let's try and remove the lock in case it's expired...
149
+		// _remove_expired_lock() returns 0 when lock is valid (ie: removed = false)
150
+		// and a positive number if the lock was removed (ie: number of locks deleted),
151
+		// so we need to return the opposite
152
+		return ! $this->_remove_expired_lock() ? true : false;
153
+	}
154
+
155
+
156
+	/**
157
+	 * Gets the meta field indicating that this TXN is locked
158
+	 *
159
+	 * @return int
160
+	 * @throws EE_Error
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidInterfaceException
164
+	 * @throws ReflectionException
165
+	 */
166
+	protected function _get_lock()
167
+	{
168
+		return (int) $this->get_extra_meta('lock', true, 0);
169
+	}
170
+
171
+
172
+	/**
173
+	 * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated
174
+	 *
175
+	 * @return int
176
+	 * @throws EE_Error
177
+	 * @throws InvalidArgumentException
178
+	 * @throws InvalidDataTypeException
179
+	 * @throws InvalidInterfaceException
180
+	 * @throws ReflectionException
181
+	 */
182
+	protected function _remove_expired_lock()
183
+	{
184
+		$locked = $this->_get_lock();
185
+		if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) {
186
+			return $this->unlock();
187
+		}
188
+		return 0;
189
+	}
190
+
191
+
192
+	/**
193
+	 * Set transaction total
194
+	 *
195
+	 * @param float $total total value of transaction
196
+	 * @throws EE_Error
197
+	 * @throws InvalidArgumentException
198
+	 * @throws InvalidDataTypeException
199
+	 * @throws InvalidInterfaceException
200
+	 * @throws ReflectionException
201
+	 */
202
+	public function set_total($total = 0.00)
203
+	{
204
+		$this->set('TXN_total', (float) $total);
205
+	}
206
+
207
+
208
+	/**
209
+	 * Set Total Amount Paid to Date
210
+	 *
211
+	 * @param float $total_paid total amount paid to date (sum of all payments)
212
+	 * @throws EE_Error
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidDataTypeException
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws ReflectionException
217
+	 */
218
+	public function set_paid($total_paid = 0.00)
219
+	{
220
+		$this->set('TXN_paid', (float) $total_paid);
221
+	}
222
+
223
+
224
+	/**
225
+	 * Set transaction status
226
+	 *
227
+	 * @param string $status        whether the transaction is open, declined, accepted,
228
+	 *                              or any number of custom values that can be set
229
+	 * @throws EE_Error
230
+	 * @throws InvalidArgumentException
231
+	 * @throws InvalidDataTypeException
232
+	 * @throws InvalidInterfaceException
233
+	 * @throws ReflectionException
234
+	 */
235
+	public function set_status($status = '')
236
+	{
237
+		$this->set('STS_ID', $status);
238
+	}
239
+
240
+
241
+	/**
242
+	 * Set hash salt
243
+	 *
244
+	 * @param string $hash_salt required for some payment gateways
245
+	 * @throws EE_Error
246
+	 * @throws InvalidArgumentException
247
+	 * @throws InvalidDataTypeException
248
+	 * @throws InvalidInterfaceException
249
+	 * @throws ReflectionException
250
+	 */
251
+	public function set_hash_salt($hash_salt = '')
252
+	{
253
+		$this->set('TXN_hash_salt', $hash_salt);
254
+	}
255
+
256
+
257
+	/**
258
+	 * Sets TXN_reg_steps array
259
+	 *
260
+	 * @param array $txn_reg_steps
261
+	 * @throws EE_Error
262
+	 * @throws InvalidArgumentException
263
+	 * @throws InvalidDataTypeException
264
+	 * @throws InvalidInterfaceException
265
+	 * @throws ReflectionException
266
+	 */
267
+	public function set_reg_steps(array $txn_reg_steps)
268
+	{
269
+		$this->set('TXN_reg_steps', $txn_reg_steps);
270
+	}
271
+
272
+
273
+	/**
274
+	 * Gets TXN_reg_steps
275
+	 *
276
+	 * @return array
277
+	 * @throws EE_Error
278
+	 * @throws InvalidArgumentException
279
+	 * @throws InvalidDataTypeException
280
+	 * @throws InvalidInterfaceException
281
+	 * @throws ReflectionException
282
+	 */
283
+	public function reg_steps()
284
+	{
285
+		$TXN_reg_steps = $this->get('TXN_reg_steps');
286
+		return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array();
287
+	}
288
+
289
+
290
+	/**
291
+	 * @return string of transaction's total cost, with currency symbol and decimal
292
+	 * @throws EE_Error
293
+	 * @throws InvalidArgumentException
294
+	 * @throws InvalidDataTypeException
295
+	 * @throws InvalidInterfaceException
296
+	 * @throws ReflectionException
297
+	 */
298
+	public function pretty_total()
299
+	{
300
+		return $this->get_pretty('TXN_total');
301
+	}
302
+
303
+
304
+	/**
305
+	 * Gets the amount paid in a pretty string (formatted and with currency symbol)
306
+	 *
307
+	 * @return string
308
+	 * @throws EE_Error
309
+	 * @throws InvalidArgumentException
310
+	 * @throws InvalidDataTypeException
311
+	 * @throws InvalidInterfaceException
312
+	 * @throws ReflectionException
313
+	 */
314
+	public function pretty_paid()
315
+	{
316
+		return $this->get_pretty('TXN_paid');
317
+	}
318
+
319
+
320
+	/**
321
+	 * calculate the amount remaining for this transaction and return;
322
+	 *
323
+	 * @return float amount remaining
324
+	 * @throws EE_Error
325
+	 * @throws InvalidArgumentException
326
+	 * @throws InvalidDataTypeException
327
+	 * @throws InvalidInterfaceException
328
+	 * @throws ReflectionException
329
+	 */
330
+	public function remaining()
331
+	{
332
+		return $this->total() - $this->paid();
333
+	}
334
+
335
+
336
+	/**
337
+	 * get Transaction Total
338
+	 *
339
+	 * @return float
340
+	 * @throws EE_Error
341
+	 * @throws InvalidArgumentException
342
+	 * @throws InvalidDataTypeException
343
+	 * @throws InvalidInterfaceException
344
+	 * @throws ReflectionException
345
+	 */
346
+	public function total()
347
+	{
348
+		return (float) $this->get('TXN_total');
349
+	}
350
+
351
+
352
+	/**
353
+	 * get Total Amount Paid to Date
354
+	 *
355
+	 * @return float
356
+	 * @throws EE_Error
357
+	 * @throws InvalidArgumentException
358
+	 * @throws InvalidDataTypeException
359
+	 * @throws InvalidInterfaceException
360
+	 * @throws ReflectionException
361
+	 */
362
+	public function paid()
363
+	{
364
+		return (float) $this->get('TXN_paid');
365
+	}
366
+
367
+
368
+	/**
369
+	 * @return mixed|null
370
+	 * @throws EE_Error
371
+	 * @throws InvalidArgumentException
372
+	 * @throws InvalidDataTypeException
373
+	 * @throws InvalidInterfaceException
374
+	 * @throws ReflectionException
375
+	 */
376
+	public function get_cart_session()
377
+	{
378
+		$session_data = (array) $this->get('TXN_session_data');
379
+		return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart
380
+			? $session_data['cart']
381
+			: null;
382
+	}
383
+
384
+
385
+	/**
386
+	 * get Transaction session data
387
+	 *
388
+	 * @return array|mixed
389
+	 * @throws EE_Error
390
+	 * @throws InvalidArgumentException
391
+	 * @throws InvalidDataTypeException
392
+	 * @throws InvalidInterfaceException
393
+	 * @throws ReflectionException
394
+	 */
395
+	public function session_data()
396
+	{
397
+		$session_data = $this->get('TXN_session_data');
398
+		if (empty($session_data)) {
399
+			$session_data = array(
400
+				'id'            => null,
401
+				'user_id'       => null,
402
+				'ip_address'    => null,
403
+				'user_agent'    => null,
404
+				'init_access'   => null,
405
+				'last_access'   => null,
406
+				'pages_visited' => array(),
407
+			);
408
+		}
409
+		return $session_data;
410
+	}
411
+
412
+
413
+	/**
414
+	 * Set session data within the TXN object
415
+	 *
416
+	 * @param EE_Session|array $session_data
417
+	 * @throws EE_Error
418
+	 * @throws InvalidArgumentException
419
+	 * @throws InvalidDataTypeException
420
+	 * @throws InvalidInterfaceException
421
+	 * @throws ReflectionException
422
+	 */
423
+	public function set_txn_session_data($session_data)
424
+	{
425
+		if ($session_data instanceof EE_Session) {
426
+			$this->set('TXN_session_data', $session_data->get_session_data(null, true));
427
+		} else {
428
+			$this->set('TXN_session_data', $session_data);
429
+		}
430
+	}
431
+
432
+
433
+	/**
434
+	 * get Transaction hash salt
435
+	 *
436
+	 * @return mixed
437
+	 * @throws EE_Error
438
+	 * @throws InvalidArgumentException
439
+	 * @throws InvalidDataTypeException
440
+	 * @throws InvalidInterfaceException
441
+	 * @throws ReflectionException
442
+	 */
443
+	public function hash_salt_()
444
+	{
445
+		return $this->get('TXN_hash_salt');
446
+	}
447
+
448
+
449
+	/**
450
+	 * Returns the transaction datetime as either:
451
+	 *            - unix timestamp format ($format = false, $gmt = true)
452
+	 *            - formatted date string including the UTC (timezone) offset ($format = true ($gmt
453
+	 *              has no affect with this option)), this also may include a timezone abbreviation if the
454
+	 *              set timezone in this class differs from what the timezone is on the blog.
455
+	 *            - formatted date string including the UTC (timezone) offset (default).
456
+	 *
457
+	 * @param boolean $format   - whether to return a unix timestamp (default) or formatted date string
458
+	 * @param boolean $gmt      - whether to return a unix timestamp with UTC offset applied (default)
459
+	 *                          or no UTC offset applied
460
+	 * @return string | int
461
+	 * @throws EE_Error
462
+	 * @throws InvalidArgumentException
463
+	 * @throws InvalidDataTypeException
464
+	 * @throws InvalidInterfaceException
465
+	 * @throws ReflectionException
466
+	 */
467
+	public function datetime($format = false, $gmt = false)
468
+	{
469
+		if ($format) {
470
+			return $this->get_pretty('TXN_timestamp');
471
+		}
472
+		if ($gmt) {
473
+			return $this->get_raw('TXN_timestamp');
474
+		}
475
+		return $this->get('TXN_timestamp');
476
+	}
477
+
478
+
479
+	/**
480
+	 * Gets registrations on this transaction
481
+	 *
482
+	 * @param array   $query_params array of query parameters
483
+	 * @param boolean $get_cached   TRUE to retrieve cached registrations or FALSE to pull from the db
484
+	 * @return EE_Base_Class[]|EE_Registration[]
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws InvalidDataTypeException
488
+	 * @throws InvalidInterfaceException
489
+	 * @throws ReflectionException
490
+	 */
491
+	public function registrations($query_params = array(), $get_cached = false)
492
+	{
493
+		$query_params = (empty($query_params) || ! is_array($query_params))
494
+			? array(
495
+				'order_by' => array(
496
+					'Event.EVT_name'     => 'ASC',
497
+					'Attendee.ATT_lname' => 'ASC',
498
+					'Attendee.ATT_fname' => 'ASC',
499
+				),
500
+			)
501
+			: $query_params;
502
+		$query_params = $get_cached ? array() : $query_params;
503
+		return $this->get_many_related('Registration', $query_params);
504
+	}
505
+
506
+
507
+	/**
508
+	 * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event
509
+	 * function for getting attendees and how many registrations they each have for an event)
510
+	 *
511
+	 * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT'
512
+	 * @throws EE_Error
513
+	 * @throws InvalidArgumentException
514
+	 * @throws InvalidDataTypeException
515
+	 * @throws InvalidInterfaceException
516
+	 * @throws ReflectionException
517
+	 */
518
+	public function attendees()
519
+	{
520
+		return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID())));
521
+	}
522
+
523
+
524
+	/**
525
+	 * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default
526
+	 *
527
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
528
+	 * @return EE_Base_Class[]|EE_Payment[]
529
+	 * @throws EE_Error
530
+	 * @throws InvalidArgumentException
531
+	 * @throws InvalidDataTypeException
532
+	 * @throws InvalidInterfaceException
533
+	 * @throws ReflectionException
534
+	 */
535
+	public function payments($query_params = array())
536
+	{
537
+		return $this->get_many_related('Payment', $query_params);
538
+	}
539
+
540
+
541
+	/**
542
+	 * gets only approved payments for this transaction
543
+	 *
544
+	 * @return EE_Base_Class[]|EE_Payment[]
545
+	 * @throws EE_Error
546
+	 * @throws InvalidArgumentException
547
+	 * @throws ReflectionException
548
+	 * @throws InvalidDataTypeException
549
+	 * @throws InvalidInterfaceException
550
+	 */
551
+	public function approved_payments()
552
+	{
553
+		EE_Registry::instance()->load_model('Payment');
554
+		return $this->get_many_related(
555
+			'Payment',
556
+			array(
557
+				array('STS_ID' => EEM_Payment::status_id_approved),
558
+				'order_by' => array('PAY_timestamp' => 'DESC'),
559
+			)
560
+		);
561
+	}
562
+
563
+
564
+	/**
565
+	 * Gets all payments which have not been approved
566
+	 *
567
+	 * @return EE_Base_Class[]|EEI_Payment[]
568
+	 * @throws EE_Error if a model is misconfigured somehow
569
+	 * @throws InvalidArgumentException
570
+	 * @throws InvalidDataTypeException
571
+	 * @throws InvalidInterfaceException
572
+	 * @throws ReflectionException
573
+	 */
574
+	public function pending_payments()
575
+	{
576
+		return $this->get_many_related(
577
+			'Payment',
578
+			array(
579
+				array(
580
+					'STS_ID' => EEM_Payment::status_id_pending,
581
+				),
582
+				'order_by' => array(
583
+					'PAY_timestamp' => 'DESC',
584
+				),
585
+			)
586
+		);
587
+	}
588
+
589
+
590
+	/**
591
+	 * echoes $this->pretty_status()
592
+	 *
593
+	 * @param bool $show_icons
594
+	 * @throws EE_Error
595
+	 * @throws InvalidArgumentException
596
+	 * @throws InvalidDataTypeException
597
+	 * @throws InvalidInterfaceException
598
+	 * @throws ReflectionException
599
+	 */
600
+	public function e_pretty_status($show_icons = false)
601
+	{
602
+		echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags());
603
+	}
604
+
605
+
606
+	/**
607
+	 * returns a pretty version of the status, good for displaying to users
608
+	 *
609
+	 * @param bool $show_icons
610
+	 * @return string
611
+	 * @throws EE_Error
612
+	 * @throws InvalidArgumentException
613
+	 * @throws InvalidDataTypeException
614
+	 * @throws InvalidInterfaceException
615
+	 * @throws ReflectionException
616
+	 */
617
+	public function pretty_status($show_icons = false)
618
+	{
619
+		$status = EEM_Status::instance()->localized_status(
620
+			array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
621
+			false,
622
+			'sentence'
623
+		);
624
+		$icon = '';
625
+		switch ($this->status_ID()) {
626
+			case EEM_Transaction::complete_status_code:
627
+				$icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : '';
628
+				break;
629
+			case EEM_Transaction::incomplete_status_code:
630
+				$icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>'
631
+					: '';
632
+				break;
633
+			case EEM_Transaction::abandoned_status_code:
634
+				$icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : '';
635
+				break;
636
+			case EEM_Transaction::failed_status_code:
637
+				$icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : '';
638
+				break;
639
+			case EEM_Transaction::overpaid_status_code:
640
+				$icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : '';
641
+				break;
642
+		}
643
+		return $icon . $status[ $this->status_ID() ];
644
+	}
645
+
646
+
647
+	/**
648
+	 * get Transaction Status
649
+	 *
650
+	 * @return mixed
651
+	 * @throws EE_Error
652
+	 * @throws InvalidArgumentException
653
+	 * @throws InvalidDataTypeException
654
+	 * @throws InvalidInterfaceException
655
+	 * @throws ReflectionException
656
+	 */
657
+	public function status_ID()
658
+	{
659
+		return $this->get('STS_ID');
660
+	}
661
+
662
+
663
+	/**
664
+	 * Returns TRUE or FALSE for whether or not this transaction cost any money
665
+	 *
666
+	 * @return boolean
667
+	 * @throws EE_Error
668
+	 * @throws InvalidArgumentException
669
+	 * @throws InvalidDataTypeException
670
+	 * @throws InvalidInterfaceException
671
+	 * @throws ReflectionException
672
+	 */
673
+	public function is_free()
674
+	{
675
+		return EEH_Money::compare_floats($this->get('TXN_total'), 0, '==');
676
+	}
677
+
678
+
679
+	/**
680
+	 * Returns whether this transaction is complete
681
+	 * Useful in templates and other logic for deciding if we should ask for another payment...
682
+	 *
683
+	 * @return boolean
684
+	 * @throws EE_Error
685
+	 * @throws InvalidArgumentException
686
+	 * @throws InvalidDataTypeException
687
+	 * @throws InvalidInterfaceException
688
+	 * @throws ReflectionException
689
+	 */
690
+	public function is_completed()
691
+	{
692
+		return $this->status_ID() === EEM_Transaction::complete_status_code;
693
+	}
694
+
695
+
696
+	/**
697
+	 * Returns whether this transaction is incomplete
698
+	 * Useful in templates and other logic for deciding if we should ask for another payment...
699
+	 *
700
+	 * @return boolean
701
+	 * @throws EE_Error
702
+	 * @throws InvalidArgumentException
703
+	 * @throws InvalidDataTypeException
704
+	 * @throws InvalidInterfaceException
705
+	 * @throws ReflectionException
706
+	 */
707
+	public function is_incomplete()
708
+	{
709
+		return $this->status_ID() === EEM_Transaction::incomplete_status_code;
710
+	}
711
+
712
+
713
+	/**
714
+	 * Returns whether this transaction is overpaid
715
+	 * Useful in templates and other logic for deciding if monies need to be refunded
716
+	 *
717
+	 * @return boolean
718
+	 * @throws EE_Error
719
+	 * @throws InvalidArgumentException
720
+	 * @throws InvalidDataTypeException
721
+	 * @throws InvalidInterfaceException
722
+	 * @throws ReflectionException
723
+	 */
724
+	public function is_overpaid()
725
+	{
726
+		return $this->status_ID() === EEM_Transaction::overpaid_status_code;
727
+	}
728
+
729
+
730
+	/**
731
+	 * Returns whether this transaction was abandoned
732
+	 * meaning that the transaction/registration process was somehow interrupted and never completed
733
+	 * but that contact information exists for at least one registrant
734
+	 *
735
+	 * @return boolean
736
+	 * @throws EE_Error
737
+	 * @throws InvalidArgumentException
738
+	 * @throws InvalidDataTypeException
739
+	 * @throws InvalidInterfaceException
740
+	 * @throws ReflectionException
741
+	 */
742
+	public function is_abandoned()
743
+	{
744
+		return $this->status_ID() === EEM_Transaction::abandoned_status_code;
745
+	}
746
+
747
+
748
+	/**
749
+	 * Returns whether this transaction failed
750
+	 * meaning that the transaction/registration process was somehow interrupted and never completed
751
+	 * and that NO contact information exists for any registrants
752
+	 *
753
+	 * @return boolean
754
+	 * @throws EE_Error
755
+	 * @throws InvalidArgumentException
756
+	 * @throws InvalidDataTypeException
757
+	 * @throws InvalidInterfaceException
758
+	 * @throws ReflectionException
759
+	 */
760
+	public function failed()
761
+	{
762
+		return $this->status_ID() === EEM_Transaction::failed_status_code;
763
+	}
764
+
765
+
766
+	/**
767
+	 * This returns the url for the invoice of this transaction
768
+	 *
769
+	 * @param string $type 'html' or 'pdf' (default is pdf)
770
+	 * @return string
771
+	 * @throws EE_Error
772
+	 * @throws InvalidArgumentException
773
+	 * @throws InvalidDataTypeException
774
+	 * @throws InvalidInterfaceException
775
+	 * @throws ReflectionException
776
+	 */
777
+	public function invoice_url($type = 'html')
778
+	{
779
+		$REG = $this->primary_registration();
780
+		if (! $REG instanceof EE_Registration) {
781
+			return '';
782
+		}
783
+		return $REG->invoice_url($type);
784
+	}
785
+
786
+
787
+	/**
788
+	 * Gets the primary registration only
789
+	 *
790
+	 * @return EE_Base_Class|EE_Registration
791
+	 * @throws EE_Error
792
+	 * @throws InvalidArgumentException
793
+	 * @throws InvalidDataTypeException
794
+	 * @throws InvalidInterfaceException
795
+	 * @throws ReflectionException
796
+	 */
797
+	public function primary_registration()
798
+	{
799
+		$registrations = (array) $this->get_many_related(
800
+			'Registration',
801
+			array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT))
802
+		);
803
+		foreach ($registrations as $registration) {
804
+			// valid registration that is NOT cancelled or declined ?
805
+			if (
806
+				$registration instanceof EE_Registration
807
+				&& ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true)
808
+			) {
809
+				return $registration;
810
+			}
811
+		}
812
+		// nothing valid found, so just return first thing from array of results
813
+		return reset($registrations);
814
+	}
815
+
816
+
817
+	/**
818
+	 * Gets the URL for viewing the receipt
819
+	 *
820
+	 * @param string $type 'pdf' or 'html' (default is 'html')
821
+	 * @return string
822
+	 * @throws EE_Error
823
+	 * @throws InvalidArgumentException
824
+	 * @throws InvalidDataTypeException
825
+	 * @throws InvalidInterfaceException
826
+	 * @throws ReflectionException
827
+	 */
828
+	public function receipt_url($type = 'html')
829
+	{
830
+		$REG = $this->primary_registration();
831
+		if (! $REG instanceof EE_Registration) {
832
+			return '';
833
+		}
834
+		return $REG->receipt_url($type);
835
+	}
836
+
837
+
838
+	/**
839
+	 * Gets the URL of the thank you page with this registration REG_url_link added as
840
+	 * a query parameter
841
+	 *
842
+	 * @return string
843
+	 * @throws EE_Error
844
+	 * @throws InvalidArgumentException
845
+	 * @throws InvalidDataTypeException
846
+	 * @throws InvalidInterfaceException
847
+	 * @throws ReflectionException
848
+	 */
849
+	public function payment_overview_url()
850
+	{
851
+		$primary_registration = $this->primary_registration();
852
+		return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false;
853
+	}
854
+
855
+
856
+	/**
857
+	 * @return string
858
+	 * @throws EE_Error
859
+	 * @throws InvalidArgumentException
860
+	 * @throws InvalidDataTypeException
861
+	 * @throws InvalidInterfaceException
862
+	 * @throws ReflectionException
863
+	 */
864
+	public function gateway_response_on_transaction()
865
+	{
866
+		$payment = $this->get_first_related('Payment');
867
+		return $payment instanceof EE_Payment ? $payment->gateway_response() : '';
868
+	}
869
+
870
+
871
+	/**
872
+	 * Get the status object of this object
873
+	 *
874
+	 * @return EE_Base_Class|EE_Status
875
+	 * @throws EE_Error
876
+	 * @throws InvalidArgumentException
877
+	 * @throws InvalidDataTypeException
878
+	 * @throws InvalidInterfaceException
879
+	 * @throws ReflectionException
880
+	 */
881
+	public function status_obj()
882
+	{
883
+		return $this->get_first_related('Status');
884
+	}
885
+
886
+
887
+	/**
888
+	 * Gets all the extra meta info on this payment
889
+	 *
890
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
891
+	 * @return EE_Base_Class[]|EE_Extra_Meta
892
+	 * @throws EE_Error
893
+	 * @throws InvalidArgumentException
894
+	 * @throws InvalidDataTypeException
895
+	 * @throws InvalidInterfaceException
896
+	 * @throws ReflectionException
897
+	 */
898
+	public function extra_meta($query_params = array())
899
+	{
900
+		return $this->get_many_related('Extra_Meta', $query_params);
901
+	}
902
+
903
+
904
+	/**
905
+	 * Wrapper for _add_relation_to
906
+	 *
907
+	 * @param EE_Registration $registration
908
+	 * @return EE_Base_Class the relation was added to
909
+	 * @throws EE_Error
910
+	 * @throws InvalidArgumentException
911
+	 * @throws InvalidDataTypeException
912
+	 * @throws InvalidInterfaceException
913
+	 * @throws ReflectionException
914
+	 */
915
+	public function add_registration(EE_Registration $registration)
916
+	{
917
+		return $this->_add_relation_to($registration, 'Registration');
918
+	}
919
+
920
+
921
+	/**
922
+	 * Removes the given registration from being related (even before saving this transaction).
923
+	 * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations
924
+	 *
925
+	 * @param int $registration_or_id
926
+	 * @return EE_Base_Class that was removed from being related
927
+	 * @throws EE_Error
928
+	 * @throws InvalidArgumentException
929
+	 * @throws InvalidDataTypeException
930
+	 * @throws InvalidInterfaceException
931
+	 * @throws ReflectionException
932
+	 */
933
+	public function remove_registration_with_id($registration_or_id)
934
+	{
935
+		return $this->_remove_relation_to($registration_or_id, 'Registration');
936
+	}
937
+
938
+
939
+	/**
940
+	 * Gets all the line items which are for ACTUAL items
941
+	 *
942
+	 * @return EE_Line_Item[]
943
+	 * @throws EE_Error
944
+	 * @throws InvalidArgumentException
945
+	 * @throws InvalidDataTypeException
946
+	 * @throws InvalidInterfaceException
947
+	 * @throws ReflectionException
948
+	 */
949
+	public function items_purchased()
950
+	{
951
+		return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item)));
952
+	}
953
+
954
+
955
+	/**
956
+	 * Wrapper for _add_relation_to
957
+	 *
958
+	 * @param EE_Line_Item $line_item
959
+	 * @return EE_Base_Class the relation was added to
960
+	 * @throws EE_Error
961
+	 * @throws InvalidArgumentException
962
+	 * @throws InvalidDataTypeException
963
+	 * @throws InvalidInterfaceException
964
+	 * @throws ReflectionException
965
+	 */
966
+	public function add_line_item(EE_Line_Item $line_item)
967
+	{
968
+		return $this->_add_relation_to($line_item, 'Line_Item');
969
+	}
970
+
971
+
972
+	/**
973
+	 * Gets ALL the line items related to this transaction (unstructured)
974
+	 *
975
+	 * @param array $query_params
976
+	 * @return EE_Base_Class[]|EE_Line_Item[]
977
+	 * @throws EE_Error
978
+	 * @throws InvalidArgumentException
979
+	 * @throws InvalidDataTypeException
980
+	 * @throws InvalidInterfaceException
981
+	 * @throws ReflectionException
982
+	 */
983
+	public function line_items($query_params = array())
984
+	{
985
+		return $this->get_many_related('Line_Item', $query_params);
986
+	}
987
+
988
+
989
+	/**
990
+	 * Gets all the line items which are taxes on the total
991
+	 *
992
+	 * @return EE_Line_Item[]
993
+	 * @throws EE_Error
994
+	 * @throws InvalidArgumentException
995
+	 * @throws InvalidDataTypeException
996
+	 * @throws InvalidInterfaceException
997
+	 * @throws ReflectionException
998
+	 */
999
+	public function tax_items()
1000
+	{
1001
+		return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax)));
1002
+	}
1003
+
1004
+
1005
+	/**
1006
+	 * Gets the total line item (which is a parent of all other related line items,
1007
+	 * meaning it takes them all into account on its total)
1008
+	 *
1009
+	 * @param bool $create_if_not_found
1010
+	 * @return \EE_Line_Item
1011
+	 * @throws EE_Error
1012
+	 * @throws InvalidArgumentException
1013
+	 * @throws InvalidDataTypeException
1014
+	 * @throws InvalidInterfaceException
1015
+	 * @throws ReflectionException
1016
+	 */
1017
+	public function total_line_item($create_if_not_found = true)
1018
+	{
1019
+		$item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total)));
1020
+		if (! $item && $create_if_not_found) {
1021
+			$item = EEH_Line_Item::create_total_line_item($this);
1022
+		}
1023
+		return $item;
1024
+	}
1025
+
1026
+
1027
+	/**
1028
+	 * Returns the total amount of tax on this transaction
1029
+	 * (assumes there's only one tax subtotal line item)
1030
+	 *
1031
+	 * @return float
1032
+	 * @throws EE_Error
1033
+	 * @throws InvalidArgumentException
1034
+	 * @throws InvalidDataTypeException
1035
+	 * @throws InvalidInterfaceException
1036
+	 * @throws ReflectionException
1037
+	 */
1038
+	public function tax_total()
1039
+	{
1040
+		$tax_line_item = $this->tax_total_line_item();
1041
+		if ($tax_line_item) {
1042
+			return (float) $tax_line_item->total();
1043
+		}
1044
+		return (float) 0;
1045
+	}
1046
+
1047
+
1048
+	/**
1049
+	 * Gets the tax subtotal line item (assumes there's only one)
1050
+	 *
1051
+	 * @return EE_Line_Item
1052
+	 * @throws EE_Error
1053
+	 * @throws InvalidArgumentException
1054
+	 * @throws InvalidDataTypeException
1055
+	 * @throws InvalidInterfaceException
1056
+	 * @throws ReflectionException
1057
+	 */
1058
+	public function tax_total_line_item()
1059
+	{
1060
+		return EEH_Line_Item::get_taxes_subtotal($this->total_line_item());
1061
+	}
1062
+
1063
+
1064
+	/**
1065
+	 * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee.
1066
+	 *
1067
+	 * @return EE_Form_Section_Proper
1068
+	 * @throws EE_Error
1069
+	 * @throws InvalidArgumentException
1070
+	 * @throws InvalidDataTypeException
1071
+	 * @throws InvalidInterfaceException
1072
+	 * @throws ReflectionException
1073
+	 */
1074
+	public function billing_info()
1075
+	{
1076
+		$payment_method = $this->payment_method();
1077
+		if (! $payment_method) {
1078
+			EE_Error::add_error(
1079
+				esc_html__(
1080
+					'Could not find billing info for transaction because no gateway has been used for it yet',
1081
+					'event_espresso'
1082
+				),
1083
+				__FILE__,
1084
+				__FUNCTION__,
1085
+				__LINE__
1086
+			);
1087
+			return null;
1088
+		}
1089
+		$primary_reg = $this->primary_registration();
1090
+		if (! $primary_reg) {
1091
+			EE_Error::add_error(
1092
+				esc_html__(
1093
+					'Cannot get billing info for gateway %s on transaction because no primary registration exists',
1094
+					'event_espresso'
1095
+				),
1096
+				__FILE__,
1097
+				__FUNCTION__,
1098
+				__LINE__
1099
+			);
1100
+			return null;
1101
+		}
1102
+		$attendee = $primary_reg->attendee();
1103
+		if (! $attendee) {
1104
+			EE_Error::add_error(
1105
+				esc_html__(
1106
+					'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists',
1107
+					'event_espresso'
1108
+				),
1109
+				__FILE__,
1110
+				__FUNCTION__,
1111
+				__LINE__
1112
+			);
1113
+			return null;
1114
+		}
1115
+		return $attendee->billing_info_for_payment_method($payment_method);
1116
+	}
1117
+
1118
+
1119
+	/**
1120
+	 * Gets PMD_ID
1121
+	 *
1122
+	 * @return int
1123
+	 * @throws EE_Error
1124
+	 * @throws InvalidArgumentException
1125
+	 * @throws InvalidDataTypeException
1126
+	 * @throws InvalidInterfaceException
1127
+	 * @throws ReflectionException
1128
+	 */
1129
+	public function payment_method_ID()
1130
+	{
1131
+		return $this->get('PMD_ID');
1132
+	}
1133
+
1134
+
1135
+	/**
1136
+	 * Sets PMD_ID
1137
+	 *
1138
+	 * @param int $PMD_ID
1139
+	 * @throws EE_Error
1140
+	 * @throws InvalidArgumentException
1141
+	 * @throws InvalidDataTypeException
1142
+	 * @throws InvalidInterfaceException
1143
+	 * @throws ReflectionException
1144
+	 */
1145
+	public function set_payment_method_ID($PMD_ID)
1146
+	{
1147
+		$this->set('PMD_ID', $PMD_ID);
1148
+	}
1149
+
1150
+
1151
+	/**
1152
+	 * Gets the last-used payment method on this transaction
1153
+	 * (we COULD just use the last-made payment, but some payment methods, namely
1154
+	 * offline ones, dont' create payments)
1155
+	 *
1156
+	 * @return EE_Payment_Method
1157
+	 * @throws EE_Error
1158
+	 * @throws InvalidArgumentException
1159
+	 * @throws InvalidDataTypeException
1160
+	 * @throws InvalidInterfaceException
1161
+	 * @throws ReflectionException
1162
+	 */
1163
+	public function payment_method()
1164
+	{
1165
+		$pm = $this->get_first_related('Payment_Method');
1166
+		if ($pm instanceof EE_Payment_Method) {
1167
+			return $pm;
1168
+		}
1169
+		$last_payment = $this->last_payment();
1170
+		if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) {
1171
+			return $last_payment->payment_method();
1172
+		}
1173
+		return null;
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * Gets the last payment made
1179
+	 *
1180
+	 * @return EE_Base_Class|EE_Payment
1181
+	 * @throws EE_Error
1182
+	 * @throws InvalidArgumentException
1183
+	 * @throws InvalidDataTypeException
1184
+	 * @throws InvalidInterfaceException
1185
+	 * @throws ReflectionException
1186
+	 */
1187
+	public function last_payment()
1188
+	{
1189
+		return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc')));
1190
+	}
1191
+
1192
+
1193
+	/**
1194
+	 * Gets all the line items which are unrelated to tickets on this transaction
1195
+	 *
1196
+	 * @return EE_Line_Item[]
1197
+	 * @throws EE_Error
1198
+	 * @throws InvalidArgumentException
1199
+	 * @throws InvalidDataTypeException
1200
+	 * @throws InvalidInterfaceException
1201
+	 * @throws ReflectionException
1202
+	 */
1203
+	public function non_ticket_line_items()
1204
+	{
1205
+		return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID());
1206
+	}
1207
+
1208
+
1209
+	/**
1210
+	 * possibly toggles TXN status
1211
+	 *
1212
+	 * @param  boolean $update whether to save the TXN
1213
+	 * @return bool whether the TXN was saved
1214
+	 * @throws EE_Error
1215
+	 * @throws InvalidArgumentException
1216
+	 * @throws InvalidDataTypeException
1217
+	 * @throws InvalidInterfaceException
1218
+	 * @throws ReflectionException
1219
+	 * @throws RuntimeException
1220
+	 */
1221
+	public function update_status_based_on_total_paid($update = true)
1222
+	{
1223
+		// set transaction status based on comparison of TXN_paid vs TXN_total
1224
+		if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) {
1225
+			$new_txn_status = EEM_Transaction::overpaid_status_code;
1226
+		} elseif (EEH_Money::compare_floats($this->paid(), $this->total())) {
1227
+			$new_txn_status = EEM_Transaction::complete_status_code;
1228
+		} elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) {
1229
+			$new_txn_status = EEM_Transaction::incomplete_status_code;
1230
+		} else {
1231
+			throw new RuntimeException(
1232
+				esc_html__('The total paid calculation for this transaction is inaccurate.', 'event_espresso')
1233
+			);
1234
+		}
1235
+		if ($new_txn_status !== $this->status_ID()) {
1236
+			$this->set_status($new_txn_status);
1237
+			if ($update) {
1238
+				return $this->save() ? true : false;
1239
+			}
1240
+		}
1241
+		return false;
1242
+	}
1243
+
1244
+
1245
+	/**
1246
+	 * Updates the transaction's status and total_paid based on all the payments
1247
+	 * that apply to it
1248
+	 *
1249
+	 * @deprecated
1250
+	 * @return array|bool
1251
+	 * @throws EE_Error
1252
+	 * @throws InvalidArgumentException
1253
+	 * @throws ReflectionException
1254
+	 * @throws InvalidDataTypeException
1255
+	 * @throws InvalidInterfaceException
1256
+	 */
1257
+	public function update_based_on_payments()
1258
+	{
1259
+		EE_Error::doing_it_wrong(
1260
+			__CLASS__ . '::' . __FUNCTION__,
1261
+			sprintf(
1262
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
1263
+				'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'
1264
+			),
1265
+			'4.6.0'
1266
+		);
1267
+		/** @type EE_Transaction_Processor $transaction_processor */
1268
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1269
+		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this);
1270
+	}
1271
+
1272
+
1273
+	/**
1274
+	 * @return string
1275
+	 */
1276
+	public function old_txn_status()
1277
+	{
1278
+		return $this->_old_txn_status;
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 * @param string $old_txn_status
1284
+	 */
1285
+	public function set_old_txn_status($old_txn_status)
1286
+	{
1287
+		// only set the first time
1288
+		if ($this->_old_txn_status === null) {
1289
+			$this->_old_txn_status = $old_txn_status;
1290
+		}
1291
+	}
1292
+
1293
+
1294
+	/**
1295
+	 * reg_status_updated
1296
+	 *
1297
+	 * @return bool
1298
+	 * @throws EE_Error
1299
+	 * @throws InvalidArgumentException
1300
+	 * @throws InvalidDataTypeException
1301
+	 * @throws InvalidInterfaceException
1302
+	 * @throws ReflectionException
1303
+	 */
1304
+	public function txn_status_updated()
1305
+	{
1306
+		return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null;
1307
+	}
1308
+
1309
+
1310
+	/**
1311
+	 * _reg_steps_completed
1312
+	 * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed,
1313
+	 * if a $reg_step_slug is provided, then this step will be skipped when testing for completion
1314
+	 * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion
1315
+	 *
1316
+	 * @param string $reg_step_slug
1317
+	 * @param bool   $check_all
1318
+	 * @return bool|int
1319
+	 * @throws EE_Error
1320
+	 * @throws InvalidArgumentException
1321
+	 * @throws InvalidDataTypeException
1322
+	 * @throws InvalidInterfaceException
1323
+	 * @throws ReflectionException
1324
+	 */
1325
+	private function _reg_steps_completed($reg_step_slug = '', $check_all = true)
1326
+	{
1327
+		$reg_steps = $this->reg_steps();
1328
+		if (! is_array($reg_steps) || empty($reg_steps)) {
1329
+			return false;
1330
+		}
1331
+		// loop thru reg steps array)
1332
+		foreach ($reg_steps as $slug => $reg_step_completed) {
1333
+			// if NOT checking ALL steps (only checking one step)
1334
+			if (! $check_all) {
1335
+				// and this is the one
1336
+				if ($slug === $reg_step_slug) {
1337
+					return $reg_step_completed;
1338
+				}
1339
+				// skip to next reg step in loop
1340
+				continue;
1341
+			}
1342
+			// $check_all must be true, else we would never have gotten to this point
1343
+			if ($slug === $reg_step_slug) {
1344
+				// if we reach this point, then we are testing either:
1345
+				// all_reg_steps_completed_except() or
1346
+				// all_reg_steps_completed_except_final_step(),
1347
+				// and since this is the reg step EXCEPTION being tested
1348
+				// we want to return true (yes true) if this reg step is NOT completed
1349
+				// ie: "is everything completed except the final step?"
1350
+				// "that is correct... the final step is not completed, but all others are."
1351
+				return $reg_step_completed !== true;
1352
+			}
1353
+			if ($reg_step_completed !== true) {
1354
+				// if any reg step is NOT completed, then ALL steps are not completed
1355
+				return false;
1356
+			}
1357
+		}
1358
+		return true;
1359
+	}
1360
+
1361
+
1362
+	/**
1363
+	 * all_reg_steps_completed
1364
+	 * returns:
1365
+	 *    true if ALL reg steps have been marked as completed
1366
+	 *        or false if any step is not completed
1367
+	 *
1368
+	 * @return bool
1369
+	 * @throws EE_Error
1370
+	 * @throws InvalidArgumentException
1371
+	 * @throws InvalidDataTypeException
1372
+	 * @throws InvalidInterfaceException
1373
+	 * @throws ReflectionException
1374
+	 */
1375
+	public function all_reg_steps_completed()
1376
+	{
1377
+		return $this->_reg_steps_completed();
1378
+	}
1379
+
1380
+
1381
+	/**
1382
+	 * all_reg_steps_completed_except
1383
+	 * returns:
1384
+	 *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
1385
+	 *        or false if any other step is not completed
1386
+	 *        or false if ALL steps are completed including the exception you are testing !!!
1387
+	 *
1388
+	 * @param string $exception
1389
+	 * @return bool
1390
+	 * @throws EE_Error
1391
+	 * @throws InvalidArgumentException
1392
+	 * @throws InvalidDataTypeException
1393
+	 * @throws InvalidInterfaceException
1394
+	 * @throws ReflectionException
1395
+	 */
1396
+	public function all_reg_steps_completed_except($exception = '')
1397
+	{
1398
+		return $this->_reg_steps_completed($exception);
1399
+	}
1400
+
1401
+
1402
+	/**
1403
+	 * all_reg_steps_completed_except
1404
+	 * returns:
1405
+	 *        true if ALL reg steps, except the final step, have been marked as completed
1406
+	 *        or false if any step is not completed
1407
+	 *    or false if ALL steps are completed including the final step !!!
1408
+	 *
1409
+	 * @return bool
1410
+	 * @throws EE_Error
1411
+	 * @throws InvalidArgumentException
1412
+	 * @throws InvalidDataTypeException
1413
+	 * @throws InvalidInterfaceException
1414
+	 * @throws ReflectionException
1415
+	 */
1416
+	public function all_reg_steps_completed_except_final_step()
1417
+	{
1418
+		return $this->_reg_steps_completed('finalize_registration');
1419
+	}
1420
+
1421
+
1422
+	/**
1423
+	 * reg_step_completed
1424
+	 * returns:
1425
+	 *    true if a specific reg step has been marked as completed
1426
+	 *    a Unix timestamp if it has been initialized but not yet completed,
1427
+	 *    or false if it has not yet been initialized
1428
+	 *
1429
+	 * @param string $reg_step_slug
1430
+	 * @return bool|int
1431
+	 * @throws EE_Error
1432
+	 * @throws InvalidArgumentException
1433
+	 * @throws InvalidDataTypeException
1434
+	 * @throws InvalidInterfaceException
1435
+	 * @throws ReflectionException
1436
+	 */
1437
+	public function reg_step_completed($reg_step_slug)
1438
+	{
1439
+		return $this->_reg_steps_completed($reg_step_slug, false);
1440
+	}
1441
+
1442
+
1443
+	/**
1444
+	 * completed_final_reg_step
1445
+	 * returns:
1446
+	 *    true if the finalize_registration reg step has been marked as completed
1447
+	 *    a Unix timestamp if it has been initialized but not yet completed,
1448
+	 *    or false if it has not yet been initialized
1449
+	 *
1450
+	 * @return bool|int
1451
+	 * @throws EE_Error
1452
+	 * @throws InvalidArgumentException
1453
+	 * @throws InvalidDataTypeException
1454
+	 * @throws InvalidInterfaceException
1455
+	 * @throws ReflectionException
1456
+	 */
1457
+	public function final_reg_step_completed()
1458
+	{
1459
+		return $this->_reg_steps_completed('finalize_registration', false);
1460
+	}
1461
+
1462
+
1463
+	/**
1464
+	 * set_reg_step_initiated
1465
+	 * given a valid TXN_reg_step, this sets it's value to a unix timestamp
1466
+	 *
1467
+	 * @param string $reg_step_slug
1468
+	 * @return boolean
1469
+	 * @throws EE_Error
1470
+	 * @throws InvalidArgumentException
1471
+	 * @throws InvalidDataTypeException
1472
+	 * @throws InvalidInterfaceException
1473
+	 * @throws ReflectionException
1474
+	 */
1475
+	public function set_reg_step_initiated($reg_step_slug)
1476
+	{
1477
+		return $this->_set_reg_step_completed_status($reg_step_slug, time());
1478
+	}
1479
+
1480
+
1481
+	/**
1482
+	 * set_reg_step_completed
1483
+	 * given a valid TXN_reg_step, this sets the step as completed
1484
+	 *
1485
+	 * @param string $reg_step_slug
1486
+	 * @return boolean
1487
+	 * @throws EE_Error
1488
+	 * @throws InvalidArgumentException
1489
+	 * @throws InvalidDataTypeException
1490
+	 * @throws InvalidInterfaceException
1491
+	 * @throws ReflectionException
1492
+	 */
1493
+	public function set_reg_step_completed($reg_step_slug)
1494
+	{
1495
+		return $this->_set_reg_step_completed_status($reg_step_slug, true);
1496
+	}
1497
+
1498
+
1499
+	/**
1500
+	 * set_reg_step_completed
1501
+	 * given a valid TXN_reg_step slug, this sets the step as NOT completed
1502
+	 *
1503
+	 * @param string $reg_step_slug
1504
+	 * @return boolean
1505
+	 * @throws EE_Error
1506
+	 * @throws InvalidArgumentException
1507
+	 * @throws InvalidDataTypeException
1508
+	 * @throws InvalidInterfaceException
1509
+	 * @throws ReflectionException
1510
+	 */
1511
+	public function set_reg_step_not_completed($reg_step_slug)
1512
+	{
1513
+		return $this->_set_reg_step_completed_status($reg_step_slug, false);
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 * set_reg_step_completed
1519
+	 * given a valid reg step slug, this sets the TXN_reg_step completed status which is either:
1520
+	 *
1521
+	 * @param  string      $reg_step_slug
1522
+	 * @param  boolean|int $status
1523
+	 * @return boolean
1524
+	 * @throws EE_Error
1525
+	 * @throws InvalidArgumentException
1526
+	 * @throws InvalidDataTypeException
1527
+	 * @throws InvalidInterfaceException
1528
+	 * @throws ReflectionException
1529
+	 */
1530
+	private function _set_reg_step_completed_status($reg_step_slug, $status)
1531
+	{
1532
+		// validate status
1533
+		$status = is_bool($status) || is_int($status) ? $status : false;
1534
+		// get reg steps array
1535
+		$txn_reg_steps = $this->reg_steps();
1536
+		// if reg step does NOT exist
1537
+		if (! isset($txn_reg_steps[ $reg_step_slug ])) {
1538
+			return false;
1539
+		}
1540
+		// if  we're trying to complete a step that is already completed
1541
+		if ($txn_reg_steps[ $reg_step_slug ] === true) {
1542
+			return true;
1543
+		}
1544
+		// if  we're trying to complete a step that hasn't even started
1545
+		if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) {
1546
+			return false;
1547
+		}
1548
+		// if current status value matches the incoming value (no change)
1549
+		// type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890
1550
+		if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) {
1551
+			// this will happen in cases where multiple AJAX requests occur during the same step
1552
+			return true;
1553
+		}
1554
+		// if we're trying to set a start time, but it has already been set...
1555
+		if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) {
1556
+			// skip the update below, but don't return FALSE so that errors won't be displayed
1557
+			return true;
1558
+		}
1559
+		// update completed status
1560
+		$txn_reg_steps[ $reg_step_slug ] = $status;
1561
+		$this->set_reg_steps($txn_reg_steps);
1562
+		$this->save();
1563
+		return true;
1564
+	}
1565
+
1566
+
1567
+	/**
1568
+	 * remove_reg_step
1569
+	 * given a valid TXN_reg_step slug, this will remove (unset)
1570
+	 * the reg step from the TXN reg step array
1571
+	 *
1572
+	 * @param string $reg_step_slug
1573
+	 * @return void
1574
+	 * @throws EE_Error
1575
+	 * @throws InvalidArgumentException
1576
+	 * @throws InvalidDataTypeException
1577
+	 * @throws InvalidInterfaceException
1578
+	 * @throws ReflectionException
1579
+	 */
1580
+	public function remove_reg_step($reg_step_slug)
1581
+	{
1582
+		// get reg steps array
1583
+		$txn_reg_steps = $this->reg_steps();
1584
+		unset($txn_reg_steps[ $reg_step_slug ]);
1585
+		$this->set_reg_steps($txn_reg_steps);
1586
+	}
1587
+
1588
+
1589
+	/**
1590
+	 * toggle_failed_transaction_status
1591
+	 * upgrades a TXNs status from failed to abandoned,
1592
+	 * meaning that contact information has been captured for at least one registrant
1593
+	 *
1594
+	 * @param bool $save
1595
+	 * @return bool
1596
+	 * @throws EE_Error
1597
+	 * @throws InvalidArgumentException
1598
+	 * @throws InvalidDataTypeException
1599
+	 * @throws InvalidInterfaceException
1600
+	 * @throws ReflectionException
1601
+	 */
1602
+	public function toggle_failed_transaction_status($save = true)
1603
+	{
1604
+		// if TXN status is still set as "failed"...
1605
+		if ($this->status_ID() === EEM_Transaction::failed_status_code) {
1606
+			$this->set_status(EEM_Transaction::abandoned_status_code);
1607
+			if ($save) {
1608
+				$this->save();
1609
+			}
1610
+			return true;
1611
+		}
1612
+		return false;
1613
+	}
1614
+
1615
+
1616
+	/**
1617
+	 * toggle_abandoned_transaction_status
1618
+	 * upgrades a TXNs status from failed or abandoned to incomplete
1619
+	 *
1620
+	 * @return bool
1621
+	 * @throws EE_Error
1622
+	 * @throws InvalidArgumentException
1623
+	 * @throws InvalidDataTypeException
1624
+	 * @throws InvalidInterfaceException
1625
+	 * @throws ReflectionException
1626
+	 */
1627
+	public function toggle_abandoned_transaction_status()
1628
+	{
1629
+		// if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"...
1630
+		$txn_status = $this->status_ID();
1631
+		if (
1632
+			$txn_status === EEM_Transaction::failed_status_code
1633
+			|| $txn_status === EEM_Transaction::abandoned_status_code
1634
+		) {
1635
+			// if a contact record for the primary registrant has been created
1636
+			if (
1637
+				$this->primary_registration() instanceof EE_Registration
1638
+				&& $this->primary_registration()->attendee() instanceof EE_Attendee
1639
+			) {
1640
+				$this->set_status(EEM_Transaction::incomplete_status_code);
1641
+			} else {
1642
+				// no contact record? yer abandoned!
1643
+				$this->set_status(EEM_Transaction::abandoned_status_code);
1644
+			}
1645
+			return true;
1646
+		}
1647
+		return false;
1648
+	}
1649
+
1650
+
1651
+	/**
1652
+	 * checks if an Abandoned TXN has any related payments, and if so,
1653
+	 * updates the TXN status based on the amount paid
1654
+	 *
1655
+	 * @throws EE_Error
1656
+	 * @throws InvalidDataTypeException
1657
+	 * @throws InvalidInterfaceException
1658
+	 * @throws InvalidArgumentException
1659
+	 * @throws RuntimeException
1660
+	 * @throws ReflectionException
1661
+	 */
1662
+	public function verify_abandoned_transaction_status()
1663
+	{
1664
+		if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) {
1665
+			return;
1666
+		}
1667
+		$payments = $this->get_many_related('Payment');
1668
+		if (! empty($payments)) {
1669
+			foreach ($payments as $payment) {
1670
+				if ($payment instanceof EE_Payment) {
1671
+					// kk this TXN should NOT be abandoned
1672
+					$this->update_status_based_on_total_paid();
1673
+					if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1674
+						EE_Error::add_attention(
1675
+							sprintf(
1676
+								esc_html__(
1677
+									'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.',
1678
+									'event_espresso'
1679
+								),
1680
+								$this->ID(),
1681
+								$this->pretty_status()
1682
+							)
1683
+						);
1684
+					}
1685
+					// get final reg step status
1686
+					$finalized = $this->final_reg_step_completed();
1687
+					// if the 'finalize_registration' step has been initiated (has a timestamp)
1688
+					// but has not yet been fully completed (TRUE)
1689
+					if (is_int($finalized) && $finalized !== false && $finalized !== true) {
1690
+						$this->set_reg_step_completed('finalize_registration');
1691
+						$this->save();
1692
+					}
1693
+				}
1694
+			}
1695
+		}
1696
+	}
1697
+
1698
+
1699
+	/**
1700
+	 * @since 4.10.4.p
1701
+	 * @throws EE_Error
1702
+	 * @throws InvalidArgumentException
1703
+	 * @throws InvalidDataTypeException
1704
+	 * @throws InvalidInterfaceException
1705
+	 * @throws ReflectionException
1706
+	 * @throws RuntimeException
1707
+	 */
1708
+	public function recalculateLineItems()
1709
+	{
1710
+		$total_line_item = $this->total_line_item(false);
1711
+		if ($total_line_item instanceof EE_Line_Item) {
1712
+			EEH_Line_Item::resetIsTaxableForTickets($total_line_item);
1713
+			return EEH_Line_Item::apply_taxes($total_line_item, true);
1714
+		}
1715
+		return false;
1716
+	}
1717 1717
 }
Please login to merge, or discard this patch.
admin_pages/events/Event_Categories_Admin_List_Table.class.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
     public function column_id($item)
83 83
     {
84 84
         $content = $item->get('term_id');
85
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->get_first_related('Term')->get(
85
+        $content .= '  <span class="show-on-mobile-view-only">'.$item->get_first_related('Term')->get(
86 86
             'name'
87
-        ) . '</span>';
87
+        ).'</span>';
88 88
         return $content;
89 89
     }
90 90
 
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
         $delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL);
106 106
 
107 107
         $actions = array(
108
-            'edit' => '<a href="' . $edit_link . '" aria-label="' . esc_attr__(
108
+            'edit' => '<a href="'.$edit_link.'" aria-label="'.esc_attr__(
109 109
                 'Edit Category',
110 110
                 'event_espresso'
111
-            ) . '">' . esc_html__('Edit', 'event_espresso') . '</a>',
111
+            ).'">'.esc_html__('Edit', 'event_espresso').'</a>',
112 112
         );
113 113
 
114
-        $actions['delete'] = '<a href="' . $delete_link . '" aria-label="' . esc_attr__(
114
+        $actions['delete'] = '<a href="'.$delete_link.'" aria-label="'.esc_attr__(
115 115
             'Delete Category',
116 116
             'event_espresso'
117
-        ) . '">' . esc_html__('Delete', 'event_espresso') . '</a>';
117
+        ).'">'.esc_html__('Delete', 'event_espresso').'</a>';
118 118
 
119 119
         $actions['view'] = sprintf(
120 120
             '<a href="%s" aria-label="%s">%s</a>',
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
             esc_html__('View', 'event_espresso')
130 130
         );
131 131
 
132
-        $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->get_first_related('Term')->get(
132
+        $content = '<strong><a class="row-title" href="'.$edit_link.'">'.$item->get_first_related('Term')->get(
133 133
             'name'
134
-        ) . '</a></strong>';
134
+        ).'</a></strong>';
135 135
         $content .= $this->row_actions($actions);
136 136
         return $content;
137 137
     }
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 
140 140
     public function column_shortcode($item)
141 141
     {
142
-        $content = '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']';
142
+        $content = '[ESPRESSO_EVENTS category_slug='.$item->get_first_related('Term')->get('slug').']';
143 143
         return $content;
144 144
     }
145 145
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
             'EVT_CAT' => $item->get_first_related('Term')->ID(),
152 152
         );
153 153
         $e_link = EE_Admin_Page::add_query_args_and_nonce($e_args, EVENTS_ADMIN_URL);
154
-        $content = '<a href="' . $e_link . '">' . $item->get('term_count') . '</a>';
154
+        $content = '<a href="'.$e_link.'">'.$item->get('term_count').'</a>';
155 155
         return $content;
156 156
     }
157 157
 }
Please login to merge, or discard this patch.
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -15,142 +15,142 @@
 block discarded – undo
15 15
  */
16 16
 class Event_Categories_Admin_List_Table extends EE_Admin_List_Table
17 17
 {
18
-    public function __construct($admin_page)
19
-    {
20
-        parent::__construct($admin_page);
21
-    }
22
-
23
-
24
-    protected function _setup_data()
25
-    {
26
-        $this->_data = $this->_admin_page->get_categories($this->_per_page, $this->_current_page);
27
-        $this->_all_data_count = EEM_Term_Taxonomy::instance()->count(
28
-            array(array('taxonomy' => 'espresso_event_categories'))
29
-        );
30
-    }
31
-
32
-
33
-    protected function _set_properties()
34
-    {
35
-        $this->_wp_list_args = array(
36
-            'singular' => esc_html__('event category', 'event_espresso'),
37
-            'plural'   => esc_html__('event categories', 'event_espresso'),
38
-            'ajax'     => true, // for now,
39
-            'screen'   => $this->_admin_page->get_current_screen()->id,
40
-        );
41
-
42
-        $this->_columns = array(
43
-            'cb'        => '<input type="checkbox" />',
44
-            'id'        => esc_html__('ID', 'event_espresso'),
45
-            'name'      => esc_html__('Name', 'event_espresso'),
46
-            'shortcode' => esc_html__('Shortcode', 'event_espresso'),
47
-            'count'     => esc_html__('Events', 'event_espresso'),
48
-        );
49
-
50
-        $this->_sortable_columns = array(
51
-            'id'    => array('Term.term_id' => true),
52
-            'name'  => array('Term.slug' => false),
53
-            'count' => array('term_count' => false),
54
-        );
55
-
56
-        $this->_primary_column = 'id';
57
-
58
-        $this->_hidden_columns = array();
59
-    }
60
-
61
-
62
-    // not needed
63
-    protected function _get_table_filters()
64
-    {
65
-        return array();
66
-    }
67
-
68
-
69
-    protected function _add_view_counts()
70
-    {
71
-        $this->_views['all']['count'] = $this->_all_data_count;
72
-    }
73
-
74
-
75
-    public function column_cb($item)
76
-    {
77
-        return sprintf('<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id'));
78
-    }
79
-
80
-
81
-    public function column_id($item)
82
-    {
83
-        $content = $item->get('term_id');
84
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->get_first_related('Term')->get(
85
-            'name'
86
-        ) . '</span>';
87
-        return $content;
88
-    }
89
-
90
-
91
-    public function column_name($item)
92
-    {
93
-        $edit_query_args = array(
94
-            'action'     => 'edit_category',
95
-            'EVT_CAT_ID' => $item->get('term_id'),
96
-        );
97
-
98
-        $delete_query_args = array(
99
-            'action'     => 'delete_category',
100
-            'EVT_CAT_ID' => $item->get('term_id'),
101
-        );
102
-
103
-        $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
104
-        $delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL);
105
-
106
-        $actions = array(
107
-            'edit' => '<a href="' . $edit_link . '" aria-label="' . esc_attr__(
108
-                'Edit Category',
109
-                'event_espresso'
110
-            ) . '">' . esc_html__('Edit', 'event_espresso') . '</a>',
111
-        );
112
-
113
-        $actions['delete'] = '<a href="' . $delete_link . '" aria-label="' . esc_attr__(
114
-            'Delete Category',
115
-            'event_espresso'
116
-        ) . '">' . esc_html__('Delete', 'event_espresso') . '</a>';
117
-
118
-        $actions['view'] = sprintf(
119
-            '<a href="%s" aria-label="%s">%s</a>',
120
-            get_term_link($item->get('term_id')),
121
-            esc_attr(
122
-                sprintf(
123
-                    /* translators: %s: event category name */
124
-                    esc_html__('View &#8220;%s&#8221; archive', 'event_espresso'),
125
-                    $item->get_first_related('Term')->get('name')
126
-                )
127
-            ),
128
-            esc_html__('View', 'event_espresso')
129
-        );
130
-
131
-        $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->get_first_related('Term')->get(
132
-            'name'
133
-        ) . '</a></strong>';
134
-        $content .= $this->row_actions($actions);
135
-        return $content;
136
-    }
137
-
138
-
139
-    public function column_shortcode($item)
140
-    {
141
-        $content = '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']';
142
-        return $content;
143
-    }
144
-
145
-
146
-    public function column_count($item)
147
-    {
148
-        $e_args = array(
149
-            'action'  => 'default',
150
-            'EVT_CAT' => $item->get_first_related('Term')->ID(),
151
-        );
152
-        $e_link = EE_Admin_Page::add_query_args_and_nonce($e_args, EVENTS_ADMIN_URL);
153
-        $content = '<a href="' . $e_link . '">' . $item->get('term_count') . '</a>';
154
-        return $content;
155
-    }
18
+	public function __construct($admin_page)
19
+	{
20
+		parent::__construct($admin_page);
21
+	}
22
+
23
+
24
+	protected function _setup_data()
25
+	{
26
+		$this->_data = $this->_admin_page->get_categories($this->_per_page, $this->_current_page);
27
+		$this->_all_data_count = EEM_Term_Taxonomy::instance()->count(
28
+			array(array('taxonomy' => 'espresso_event_categories'))
29
+		);
30
+	}
31
+
32
+
33
+	protected function _set_properties()
34
+	{
35
+		$this->_wp_list_args = array(
36
+			'singular' => esc_html__('event category', 'event_espresso'),
37
+			'plural'   => esc_html__('event categories', 'event_espresso'),
38
+			'ajax'     => true, // for now,
39
+			'screen'   => $this->_admin_page->get_current_screen()->id,
40
+		);
41
+
42
+		$this->_columns = array(
43
+			'cb'        => '<input type="checkbox" />',
44
+			'id'        => esc_html__('ID', 'event_espresso'),
45
+			'name'      => esc_html__('Name', 'event_espresso'),
46
+			'shortcode' => esc_html__('Shortcode', 'event_espresso'),
47
+			'count'     => esc_html__('Events', 'event_espresso'),
48
+		);
49
+
50
+		$this->_sortable_columns = array(
51
+			'id'    => array('Term.term_id' => true),
52
+			'name'  => array('Term.slug' => false),
53
+			'count' => array('term_count' => false),
54
+		);
55
+
56
+		$this->_primary_column = 'id';
57
+
58
+		$this->_hidden_columns = array();
59
+	}
60
+
61
+
62
+	// not needed
63
+	protected function _get_table_filters()
64
+	{
65
+		return array();
66
+	}
67
+
68
+
69
+	protected function _add_view_counts()
70
+	{
71
+		$this->_views['all']['count'] = $this->_all_data_count;
72
+	}
73
+
74
+
75
+	public function column_cb($item)
76
+	{
77
+		return sprintf('<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id'));
78
+	}
79
+
80
+
81
+	public function column_id($item)
82
+	{
83
+		$content = $item->get('term_id');
84
+		$content .= '  <span class="show-on-mobile-view-only">' . $item->get_first_related('Term')->get(
85
+			'name'
86
+		) . '</span>';
87
+		return $content;
88
+	}
89
+
90
+
91
+	public function column_name($item)
92
+	{
93
+		$edit_query_args = array(
94
+			'action'     => 'edit_category',
95
+			'EVT_CAT_ID' => $item->get('term_id'),
96
+		);
97
+
98
+		$delete_query_args = array(
99
+			'action'     => 'delete_category',
100
+			'EVT_CAT_ID' => $item->get('term_id'),
101
+		);
102
+
103
+		$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
104
+		$delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL);
105
+
106
+		$actions = array(
107
+			'edit' => '<a href="' . $edit_link . '" aria-label="' . esc_attr__(
108
+				'Edit Category',
109
+				'event_espresso'
110
+			) . '">' . esc_html__('Edit', 'event_espresso') . '</a>',
111
+		);
112
+
113
+		$actions['delete'] = '<a href="' . $delete_link . '" aria-label="' . esc_attr__(
114
+			'Delete Category',
115
+			'event_espresso'
116
+		) . '">' . esc_html__('Delete', 'event_espresso') . '</a>';
117
+
118
+		$actions['view'] = sprintf(
119
+			'<a href="%s" aria-label="%s">%s</a>',
120
+			get_term_link($item->get('term_id')),
121
+			esc_attr(
122
+				sprintf(
123
+					/* translators: %s: event category name */
124
+					esc_html__('View &#8220;%s&#8221; archive', 'event_espresso'),
125
+					$item->get_first_related('Term')->get('name')
126
+				)
127
+			),
128
+			esc_html__('View', 'event_espresso')
129
+		);
130
+
131
+		$content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->get_first_related('Term')->get(
132
+			'name'
133
+		) . '</a></strong>';
134
+		$content .= $this->row_actions($actions);
135
+		return $content;
136
+	}
137
+
138
+
139
+	public function column_shortcode($item)
140
+	{
141
+		$content = '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']';
142
+		return $content;
143
+	}
144
+
145
+
146
+	public function column_count($item)
147
+	{
148
+		$e_args = array(
149
+			'action'  => 'default',
150
+			'EVT_CAT' => $item->get_first_related('Term')->ID(),
151
+		);
152
+		$e_link = EE_Admin_Page::add_query_args_and_nonce($e_args, EVENTS_ADMIN_URL);
153
+		$content = '<a href="' . $e_link . '">' . $item->get('term_count') . '</a>';
154
+		return $content;
155
+	}
156 156
 }
Please login to merge, or discard this patch.
support/templates/support_admin_details_additional_information.template.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <div class="padding">
2 2
     <p><?php
3
-        printf(
4
-            esc_html__('Check out the %1$sroadmap for Event Espresso%2$s.', 'event_espresso'),
5
-            '<a href="https://trello.com/b/zg9DCIpe/event-espresso-public-roadmap" target="_blank" rel="noopener noreferrer">',
6
-            '</a>'
7
-        ); ?></p>
3
+		printf(
4
+			esc_html__('Check out the %1$sroadmap for Event Espresso%2$s.', 'event_espresso'),
5
+			'<a href="https://trello.com/b/zg9DCIpe/event-espresso-public-roadmap" target="_blank" rel="noopener noreferrer">',
6
+			'</a>'
7
+		); ?></p>
8 8
 </div>
9 9
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/support/templates/developers_admin_details.template.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -1,93 +1,93 @@
 block discarded – undo
1 1
 <div class="padding">
2 2
     <?php esc_html_e(
3
-        'If you want to integrate with Event Espresso or participate in building code, then you are in the right place. The following resources can help you get started.',
4
-        'event_espresso'
5
-    ); ?>
3
+		'If you want to integrate with Event Espresso or participate in building code, then you are in the right place. The following resources can help you get started.',
4
+		'event_espresso'
5
+	); ?>
6 6
     <h2><?php esc_html_e('Developer Resources', 'event_espresso'); ?></h2>
7 7
     <ul>
8 8
         <li>
9 9
             <?php printf(
10
-                esc_html__('%1$sEvent Espresso 4 Developer Documentation%2$s', 'event_espresso'),
11
-                '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs#getting-started-with-the-ee-developer-docs" target="_blank" rel="noopener noreferrer">',
12
-                '</a>'
13
-            ); ?></li>
10
+				esc_html__('%1$sEvent Espresso 4 Developer Documentation%2$s', 'event_espresso'),
11
+				'<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs#getting-started-with-the-ee-developer-docs" target="_blank" rel="noopener noreferrer">',
12
+				'</a>'
13
+			); ?></li>
14 14
         <li>
15 15
             <?php printf(
16
-                esc_html__('%1$sEvent Espresso 4 Developer News%2$s', 'event_espresso'),
17
-                '<a href="http://developer.eventespresso.com/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
18
-                '</a>'
19
-            ); ?></li>
16
+				esc_html__('%1$sEvent Espresso 4 Developer News%2$s', 'event_espresso'),
17
+				'<a href="http://developer.eventespresso.com/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
18
+				'</a>'
19
+			); ?></li>
20 20
         <li>
21 21
             <?php printf(
22
-                esc_html__('%1$sApply%2$s to be listed as an %3$sEvent Espresso Professional%2$s', 'event_espresso'),
23
-                '<a href="https://eventespresso.com/developers/event-espresso-pros-application/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
24
-                '</a>',
25
-                '<a href="https://eventespresso.com/developers/event-espresso-pros/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">'
26
-            ); ?></li>
22
+				esc_html__('%1$sApply%2$s to be listed as an %3$sEvent Espresso Professional%2$s', 'event_espresso'),
23
+				'<a href="https://eventespresso.com/developers/event-espresso-pros-application/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
24
+				'</a>',
25
+				'<a href="https://eventespresso.com/developers/event-espresso-pros/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">'
26
+			); ?></li>
27 27
     </ul>
28 28
 
29 29
     <h2><?php esc_html_e('Event Espresso 4 Articles for Developers', 'event_espresso'); ?></h2>
30 30
     <ul>
31 31
         <li>
32 32
             <?php printf(
33
-                esc_html__('%1$sCustom Post Types Usage%2$s', 'event_espresso'),
34
-                '<a href="https://eventespresso.com/2014/02/epsresso-brewery-custom-post-types-event-espresso/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
35
-                '</a>'
36
-            ); ?></li>
33
+				esc_html__('%1$sCustom Post Types Usage%2$s', 'event_espresso'),
34
+				'<a href="https://eventespresso.com/2014/02/epsresso-brewery-custom-post-types-event-espresso/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
35
+				'</a>'
36
+			); ?></li>
37 37
         <li>
38 38
             <?php printf(
39
-                esc_html__('%1$sTheme Development%2$s', 'event_espresso'),
40
-                '<a href="https://eventespresso.com/2014/02/developers-corner-theming-event-espresso-4/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
41
-                '</a>'
42
-            ); ?></li>
39
+				esc_html__('%1$sTheme Development%2$s', 'event_espresso'),
40
+				'<a href="https://eventespresso.com/2014/02/developers-corner-theming-event-espresso-4/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
41
+				'</a>'
42
+			); ?></li>
43 43
         <li>
44 44
             <?php printf(
45
-                esc_html__('%1$sCapability System%2$s', 'event_espresso'),
46
-                '<a href="http://developer.eventespresso.com/docs/ee-capability-system-overview/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
47
-                '</a>'
48
-            ); ?></li>
45
+				esc_html__('%1$sCapability System%2$s', 'event_espresso'),
46
+				'<a href="http://developer.eventespresso.com/docs/ee-capability-system-overview/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
47
+				'</a>'
48
+			); ?></li>
49 49
         <li>
50 50
             <?php printf(
51
-                esc_html__('%1$sPayment Method Development%2$s', 'event_espresso'),
52
-                '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/L--Payment-Methods-and-Gateways/creating-a-payment-method.md" target="_blank" rel="noopener noreferrer">',
53
-                '</a>'
54
-            ); ?></li>
51
+				esc_html__('%1$sPayment Method Development%2$s', 'event_espresso'),
52
+				'<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/L--Payment-Methods-and-Gateways/creating-a-payment-method.md" target="_blank" rel="noopener noreferrer">',
53
+				'</a>'
54
+			); ?></li>
55 55
         <li>
56 56
             <?php printf(
57
-                esc_html__('%1$sMessages System in Event Espresso 4%2$s', 'event_espresso'),
58
-                '<a href="https://eventespresso.com/2014/03/messages-systemyour-tool-getting-word/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
59
-                '</a>'
60
-            ); ?></li>
57
+				esc_html__('%1$sMessages System in Event Espresso 4%2$s', 'event_espresso'),
58
+				'<a href="https://eventespresso.com/2014/03/messages-systemyour-tool-getting-word/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
59
+				'</a>'
60
+			); ?></li>
61 61
         <li>
62 62
             <?php printf(
63
-                esc_html__(
64
-                    '%1$sDatabase Model System%2$s (used for interfacing with EE4 data via WordPress plugins and server side querying)',
65
-                    'event_espresso'
66
-                ),
67
-                '<a href="http://developer.eventespresso.com/docs/using-ee4-model-objects/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
68
-                '</a>'
69
-            ); ?></li>
63
+				esc_html__(
64
+					'%1$sDatabase Model System%2$s (used for interfacing with EE4 data via WordPress plugins and server side querying)',
65
+					'event_espresso'
66
+				),
67
+				'<a href="http://developer.eventespresso.com/docs/using-ee4-model-objects/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">',
68
+				'</a>'
69
+			); ?></li>
70 70
     </ul>
71 71
 
72 72
     <h2><?php esc_html_e('REST API Resources', 'event_espresso'); ?></h2>
73 73
     <ul>
74 74
         <li>
75 75
             <?php printf(
76
-                esc_html__('%1$sREST API: Introduction%2$s', 'event_espresso'),
77
-                '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/C--REST-API/ee4-rest-api-introduction.md" target="_blank" rel="noopener noreferrer">',
78
-                '</a>'
79
-            ); ?></li>
76
+				esc_html__('%1$sREST API: Introduction%2$s', 'event_espresso'),
77
+				'<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/C--REST-API/ee4-rest-api-introduction.md" target="_blank" rel="noopener noreferrer">',
78
+				'</a>'
79
+			); ?></li>
80 80
         <li>
81 81
             <?php printf(
82
-                esc_html__('%1$sREST API: Reading Data%2$s', 'event_espresso'),
83
-                '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/C--REST-API/ee4-rest-api-reading-data.md" target="_blank" rel="noopener noreferrer">',
84
-                '</a>'
85
-            ); ?></li>
82
+				esc_html__('%1$sREST API: Reading Data%2$s', 'event_espresso'),
83
+				'<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/C--REST-API/ee4-rest-api-reading-data.md" target="_blank" rel="noopener noreferrer">',
84
+				'</a>'
85
+			); ?></li>
86 86
         <li>
87 87
             <?php printf(
88
-                esc_html__('%1$sBuilding an EE4 Add-on Using the REST API%2$s', 'event_espresso'),
89
-                '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/T--Tutorials/building-an-ee4-addon-that-uses-angular-js-and-the-ee4-json-rest-api.md" target="_blank" rel="noopener noreferrer">',
90
-                '</a>'
91
-            ); ?></li>
88
+				esc_html__('%1$sBuilding an EE4 Add-on Using the REST API%2$s', 'event_espresso'),
89
+				'<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/T--Tutorials/building-an-ee4-addon-that-uses-angular-js-and-the-ee4-json-rest-api.md" target="_blank" rel="noopener noreferrer">',
90
+				'</a>'
91
+			); ?></li>
92 92
     </ul>
93 93
 </div>
94 94
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/request/files/FileSubmission.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public function getType()
95 95
     {
96
-        if (!$this->type) {
96
+        if ( ! $this->type) {
97 97
             $this->type = $this->determineType();
98 98
         }
99 99
         return $this->type;
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      */
106 106
     protected function determineType()
107 107
     {
108
-        if (!$this->getTmpFile()) {
108
+        if ( ! $this->getTmpFile()) {
109 109
             return '';
110 110
         }
111 111
         $finfo = new finfo(FILEINFO_MIME_TYPE);
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     public function getExtension()
121 121
     {
122
-        if (!$this->extension) {
122
+        if ( ! $this->extension) {
123 123
             $this->extension = $this->determineExtension();
124 124
         }
125 125
         return $this->extension;
Please login to merge, or discard this patch.
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -19,164 +19,164 @@
 block discarded – undo
19 19
  */
20 20
 class FileSubmission implements FileSubmissionInterface
21 21
 {
22
-    /**
23
-     * @var string original name on the client machine
24
-     */
25
-    protected $name;
26
-
27
-    /**
28
-     * @var string mime type
29
-     */
30
-    protected $type;
31
-
32
-    /**
33
-     * @var string file extension
34
-     */
35
-    protected $extension;
36
-
37
-    /**
38
-     * @var int in bytes
39
-     */
40
-    protected $size;
41
-
42
-    /**
43
-     * @var string local filepath to the temporary file
44
-     */
45
-    protected $tmp_file;
46
-
47
-    /**
48
-     * @var int one of UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE or other values
49
-     * although those aren't expected.
50
-     */
51
-    protected $error_code;
52
-
53
-    /**
54
-     * FileSubmission constructor.
55
-     * @param $name
56
-     * @param $tmp_file
57
-     * @param $size
58
-     * @param null $error_code
59
-     * @throws InvalidArgumentException
60
-     */
61
-    public function __construct($name, $tmp_file, $size, $error_code = null)
62
-    {
63
-        $this->name = basename($name);
64
-        $scheme = parse_url($tmp_file, PHP_URL_SCHEME);
65
-        if (in_array($scheme, ['http', 'https'])) {
66
-            // Wait a minute- just local filepaths please, no URL schemes allowed!
67
-            throw new InvalidArgumentException(
68
-                sprintf(
69
-                    // @codingStandardsIgnoreStart
70
-                    esc_html__('The scheme ("%1$s") on the temporary file ("%2$s") indicates is located elsewhere, that’s not ok!', 'event_espresso'),
71
-                    // @codingStandardsIgnoreEnd
72
-                    $scheme,
73
-                    $tmp_file
74
-                )
75
-            );
76
-        }
77
-        $this->tmp_file = (string) $tmp_file;
78
-        $this->size = (int) $size;
79
-        $this->error_code = (int) $error_code;
80
-    }
81
-
82
-    /**
83
-     * @return string
84
-     */
85
-    public function getName()
86
-    {
87
-        return $this->name;
88
-    }
89
-
90
-    /**
91
-     * Gets the file's mime type
92
-     * @return string
93
-     */
94
-    public function getType()
95
-    {
96
-        if (!$this->type) {
97
-            $this->type = $this->determineType();
98
-        }
99
-        return $this->type;
100
-    }
101
-
102
-    /**
103
-     * @since 4.9.80.p
104
-     * @return string
105
-     */
106
-    protected function determineType()
107
-    {
108
-        if (!$this->getTmpFile()) {
109
-            return '';
110
-        }
111
-        $finfo = new finfo(FILEINFO_MIME_TYPE);
112
-        return $finfo->file($this->getTmpFile());
113
-    }
114
-
115
-    /**
116
-     * Gets the file's extension.
117
-     * @since 4.9.80.p
118
-     * @return string
119
-     */
120
-    public function getExtension()
121
-    {
122
-        if (!$this->extension) {
123
-            $this->extension = $this->determineExtension();
124
-        }
125
-        return $this->extension;
126
-    }
127
-
128
-    /**
129
-     * Determine's the file's extension given the temporary file.
130
-     * @since 4.9.80.p
131
-     * @return string
132
-     */
133
-    protected function determineExtension()
134
-    {
135
-        $position_of_period = strrpos($this->getName(), '.');
136
-        if ($position_of_period === false) {
137
-            return '';
138
-        }
139
-        return mb_substr(
140
-            $this->getName(),
141
-            $position_of_period + 1
142
-        );
143
-    }
144
-
145
-    /**
146
-     * Gets the size of the file
147
-     * @return int
148
-     */
149
-    public function getSize()
150
-    {
151
-        return $this->size;
152
-    }
153
-
154
-    /**
155
-     * Gets the path to the temporary file which was uploaded.
156
-     * @return string
157
-     */
158
-    public function getTmpFile()
159
-    {
160
-        return $this->tmp_file;
161
-    }
162
-
163
-    /**
164
-     * @since 4.9.80.p
165
-     * @return string
166
-     */
167
-    public function __toString()
168
-    {
169
-        return $this->getName();
170
-    }
171
-
172
-    /**
173
-     * Gets the error code PHP reported for the file upload.
174
-     * @return string
175
-     */
176
-    public function getErrorCode()
177
-    {
178
-        return $this->error_code;
179
-    }
22
+	/**
23
+	 * @var string original name on the client machine
24
+	 */
25
+	protected $name;
26
+
27
+	/**
28
+	 * @var string mime type
29
+	 */
30
+	protected $type;
31
+
32
+	/**
33
+	 * @var string file extension
34
+	 */
35
+	protected $extension;
36
+
37
+	/**
38
+	 * @var int in bytes
39
+	 */
40
+	protected $size;
41
+
42
+	/**
43
+	 * @var string local filepath to the temporary file
44
+	 */
45
+	protected $tmp_file;
46
+
47
+	/**
48
+	 * @var int one of UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE or other values
49
+	 * although those aren't expected.
50
+	 */
51
+	protected $error_code;
52
+
53
+	/**
54
+	 * FileSubmission constructor.
55
+	 * @param $name
56
+	 * @param $tmp_file
57
+	 * @param $size
58
+	 * @param null $error_code
59
+	 * @throws InvalidArgumentException
60
+	 */
61
+	public function __construct($name, $tmp_file, $size, $error_code = null)
62
+	{
63
+		$this->name = basename($name);
64
+		$scheme = parse_url($tmp_file, PHP_URL_SCHEME);
65
+		if (in_array($scheme, ['http', 'https'])) {
66
+			// Wait a minute- just local filepaths please, no URL schemes allowed!
67
+			throw new InvalidArgumentException(
68
+				sprintf(
69
+					// @codingStandardsIgnoreStart
70
+					esc_html__('The scheme ("%1$s") on the temporary file ("%2$s") indicates is located elsewhere, that’s not ok!', 'event_espresso'),
71
+					// @codingStandardsIgnoreEnd
72
+					$scheme,
73
+					$tmp_file
74
+				)
75
+			);
76
+		}
77
+		$this->tmp_file = (string) $tmp_file;
78
+		$this->size = (int) $size;
79
+		$this->error_code = (int) $error_code;
80
+	}
81
+
82
+	/**
83
+	 * @return string
84
+	 */
85
+	public function getName()
86
+	{
87
+		return $this->name;
88
+	}
89
+
90
+	/**
91
+	 * Gets the file's mime type
92
+	 * @return string
93
+	 */
94
+	public function getType()
95
+	{
96
+		if (!$this->type) {
97
+			$this->type = $this->determineType();
98
+		}
99
+		return $this->type;
100
+	}
101
+
102
+	/**
103
+	 * @since 4.9.80.p
104
+	 * @return string
105
+	 */
106
+	protected function determineType()
107
+	{
108
+		if (!$this->getTmpFile()) {
109
+			return '';
110
+		}
111
+		$finfo = new finfo(FILEINFO_MIME_TYPE);
112
+		return $finfo->file($this->getTmpFile());
113
+	}
114
+
115
+	/**
116
+	 * Gets the file's extension.
117
+	 * @since 4.9.80.p
118
+	 * @return string
119
+	 */
120
+	public function getExtension()
121
+	{
122
+		if (!$this->extension) {
123
+			$this->extension = $this->determineExtension();
124
+		}
125
+		return $this->extension;
126
+	}
127
+
128
+	/**
129
+	 * Determine's the file's extension given the temporary file.
130
+	 * @since 4.9.80.p
131
+	 * @return string
132
+	 */
133
+	protected function determineExtension()
134
+	{
135
+		$position_of_period = strrpos($this->getName(), '.');
136
+		if ($position_of_period === false) {
137
+			return '';
138
+		}
139
+		return mb_substr(
140
+			$this->getName(),
141
+			$position_of_period + 1
142
+		);
143
+	}
144
+
145
+	/**
146
+	 * Gets the size of the file
147
+	 * @return int
148
+	 */
149
+	public function getSize()
150
+	{
151
+		return $this->size;
152
+	}
153
+
154
+	/**
155
+	 * Gets the path to the temporary file which was uploaded.
156
+	 * @return string
157
+	 */
158
+	public function getTmpFile()
159
+	{
160
+		return $this->tmp_file;
161
+	}
162
+
163
+	/**
164
+	 * @since 4.9.80.p
165
+	 * @return string
166
+	 */
167
+	public function __toString()
168
+	{
169
+		return $this->getName();
170
+	}
171
+
172
+	/**
173
+	 * Gets the error code PHP reported for the file upload.
174
+	 * @return string
175
+	 */
176
+	public function getErrorCode()
177
+	{
178
+		return $this->error_code;
179
+	}
180 180
 }
181 181
 // End of file FileSubmission.php
182 182
 // Location: EventEspresso\core\services\request\files/FileSubmission.php
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Select2_Display_Strategy.strategy.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
         // is carelessly registering an older version of Select2 on admin pages that don't even belong to them
43 43
         wp_deregister_script('select2');
44 44
         wp_deregister_style('select2');
45
-        wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true);
46
-        wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all');
47
-        wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true);
48
-        wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all');
45
+        wp_register_script('select2', EE_GLOBAL_ASSETS_URL.'scripts/select2.min.js', array(), '4.0.2', true);
46
+        wp_register_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all');
47
+        wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL.'scripts/form_section_select2_init.js', array('select2'), '1.0.0', true);
48
+        wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all');
49 49
     }
50 50
 
51 51
     /**
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
     public function get_other_js_data($other_js_data = array())
75 75
     {
76 76
         $other_js_data = parent::get_other_js_data($other_js_data);
77
-        if (! isset($other_js_data['select2s'])) {
77
+        if ( ! isset($other_js_data['select2s'])) {
78 78
             $other_js_data['select2s'] = array();
79 79
         }
80
-        $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args();
80
+        $other_js_data['select2s'][$this->_input->html_id()] = $this->get_js_args();
81 81
         return $other_js_data;
82 82
     }
83 83
 
Please login to merge, or discard this patch.
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -15,80 +15,80 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Select2_Display_Strategy extends EE_Select_Display_Strategy
17 17
 {
18
-    /**
19
-     * Arguments that will be passed into the select2 javascript constructor
20
-     * @var array
21
-     */
22
-    protected $_select2_js_args = array();
18
+	/**
19
+	 * Arguments that will be passed into the select2 javascript constructor
20
+	 * @var array
21
+	 */
22
+	protected $_select2_js_args = array();
23 23
 
24
-    /**
25
-     *
26
-     * @param array $select2_js_args pass in the EXACT array of JS arguments you want
27
-     * to pass into the select2 js/html input. See https://select2.github.io
28
-     */
29
-    public function __construct($select2_js_args = array())
30
-    {
31
-        $this->_select2_js_args = $select2_js_args;
32
-        parent::__construct();
33
-    }
24
+	/**
25
+	 *
26
+	 * @param array $select2_js_args pass in the EXACT array of JS arguments you want
27
+	 * to pass into the select2 js/html input. See https://select2.github.io
28
+	 */
29
+	public function __construct($select2_js_args = array())
30
+	{
31
+		$this->_select2_js_args = $select2_js_args;
32
+		parent::__construct();
33
+	}
34 34
 
35
-    /**
36
-     * enqueues the select2 initializing js (which depends on the select2 js) and
37
-     * the select2 css
38
-     */
39
-    public function enqueue_js()
40
-    {
41
-        // need to first deregister the select2 script in case some other plugin **cough cough Toolset Types cough**
42
-        // is carelessly registering an older version of Select2 on admin pages that don't even belong to them
43
-        wp_deregister_script('select2');
44
-        wp_deregister_style('select2');
45
-        wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true);
46
-        wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all');
47
-        wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true);
48
-        wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all');
49
-    }
35
+	/**
36
+	 * enqueues the select2 initializing js (which depends on the select2 js) and
37
+	 * the select2 css
38
+	 */
39
+	public function enqueue_js()
40
+	{
41
+		// need to first deregister the select2 script in case some other plugin **cough cough Toolset Types cough**
42
+		// is carelessly registering an older version of Select2 on admin pages that don't even belong to them
43
+		wp_deregister_script('select2');
44
+		wp_deregister_style('select2');
45
+		wp_register_script('select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true);
46
+		wp_register_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all');
47
+		wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true);
48
+		wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all');
49
+	}
50 50
 
51
-    /**
52
-     * Gets the javascript args which will be localized and passed into the select2 js/html input
53
-     * @return array
54
-     */
55
-    public function get_js_args()
56
-    {
57
-        return $this->_select2_js_args;
58
-    }
51
+	/**
52
+	 * Gets the javascript args which will be localized and passed into the select2 js/html input
53
+	 * @return array
54
+	 */
55
+	public function get_js_args()
56
+	{
57
+		return $this->_select2_js_args;
58
+	}
59 59
 
60
-    /**
61
-     * Sets the exact js args which will be passed into the select2 js/html input
62
-     * @param array $js_args
63
-     */
64
-    public function set_js_args($js_args)
65
-    {
66
-        $this->_select2_js_args = $js_args;
67
-    }
60
+	/**
61
+	 * Sets the exact js args which will be passed into the select2 js/html input
62
+	 * @param array $js_args
63
+	 */
64
+	public function set_js_args($js_args)
65
+	{
66
+		$this->_select2_js_args = $js_args;
67
+	}
68 68
 
69
-    /**
70
-     * Adds select2 data for localization
71
-     * @param array $other_js_data
72
-     * @return array
73
-     */
74
-    public function get_other_js_data($other_js_data = array())
75
-    {
76
-        $other_js_data = parent::get_other_js_data($other_js_data);
77
-        if (! isset($other_js_data['select2s'])) {
78
-            $other_js_data['select2s'] = array();
79
-        }
80
-        $other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args();
81
-        return $other_js_data;
82
-    }
69
+	/**
70
+	 * Adds select2 data for localization
71
+	 * @param array $other_js_data
72
+	 * @return array
73
+	 */
74
+	public function get_other_js_data($other_js_data = array())
75
+	{
76
+		$other_js_data = parent::get_other_js_data($other_js_data);
77
+		if (! isset($other_js_data['select2s'])) {
78
+			$other_js_data['select2s'] = array();
79
+		}
80
+		$other_js_data['select2s'][ $this->_input->html_id() ] = $this->get_js_args();
81
+		return $other_js_data;
82
+	}
83 83
 
84
-    /**
85
-     * Overrides standard attributes array to add the CSS class "ee-select2"
86
-     * @return array
87
-     */
88
-    protected function _standard_attributes_array()
89
-    {
90
-        $standard_attributes = parent::_standard_attributes_array();
91
-        $standard_attributes['class'] .= ' ee-select2';
92
-        return $standard_attributes;
93
-    }
84
+	/**
85
+	 * Overrides standard attributes array to add the CSS class "ee-select2"
86
+	 * @return array
87
+	 */
88
+	protected function _standard_attributes_array()
89
+	{
90
+		$standard_attributes = parent::_standard_attributes_array();
91
+		$standard_attributes['class'] .= ' ee-select2';
92
+		return $standard_attributes;
93
+	}
94 94
 }
Please login to merge, or discard this patch.
strategies/display/EE_File_Input_Display_Strategy.strategy.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,11 +10,11 @@
 block discarded – undo
10 10
  */
11 11
 class EE_File_Input_Display_Strategy extends EE_Text_Input_Display_Strategy
12 12
 {
13
-    /**
14
-     * Override's parent to just set the type. May someday support other arguments.
15
-     */
16
-    public function __construct()
17
-    {
18
-        parent::__construct('file');
19
-    }
13
+	/**
14
+	 * Override's parent to just set the type. May someday support other arguments.
15
+	 */
16
+	public function __construct()
17
+	{
18
+		parent::__construct('file');
19
+	}
20 20
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_File_Input.input.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
                     esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'),
56 56
                     implode(', ', $this->allowed_file_extensions)
57 57
                 ),
58
-                '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~'
58
+                '~.*\.('.implode('|', $this->allowed_file_extensions).')$~'
59 59
             )
60 60
         );
61 61
         parent::__construct($options);
Please login to merge, or discard this patch.
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -19,86 +19,86 @@
 block discarded – undo
19 19
  */
20 20
 class EE_File_Input extends EE_Form_Input_Base
21 21
 {
22
-    /**
23
-     * @var array
24
-     */
25
-    protected $allowed_file_extensions;
22
+	/**
23
+	 * @var array
24
+	 */
25
+	protected $allowed_file_extensions;
26 26
 
27
-    /**
28
-     * @var array
29
-     */
30
-    protected $allowed_mime_types;
27
+	/**
28
+	 * @var array
29
+	 */
30
+	protected $allowed_mime_types;
31 31
 
32
-    /**
33
-     * @param array $options
34
-     * @throws InvalidArgumentException
35
-     */
36
-    public function __construct($options = array())
37
-    {
38
-        if (isset($options['allowed_file_extensions'])) {
39
-            $this->allowed_file_extensions = (array) $options['allowed_file_extensions'];
40
-        } else {
41
-            $this->allowed_file_extensions = ['csv'];
42
-        }
43
-        if (isset($options['allowed_mime_types'])) {
44
-            $this->allowed_mime_types = (array) $options['allowed_file_extensions'];
45
-        } else {
46
-            $this->allowed_mime_types = ['text/csv'];
47
-        }
32
+	/**
33
+	 * @param array $options
34
+	 * @throws InvalidArgumentException
35
+	 */
36
+	public function __construct($options = array())
37
+	{
38
+		if (isset($options['allowed_file_extensions'])) {
39
+			$this->allowed_file_extensions = (array) $options['allowed_file_extensions'];
40
+		} else {
41
+			$this->allowed_file_extensions = ['csv'];
42
+		}
43
+		if (isset($options['allowed_mime_types'])) {
44
+			$this->allowed_mime_types = (array) $options['allowed_file_extensions'];
45
+		} else {
46
+			$this->allowed_mime_types = ['text/csv'];
47
+		}
48 48
 
49
-        $this->_set_display_strategy(new EE_File_Input_Display_Strategy());
50
-        $this->_set_normalization_strategy(new EE_File_Normalization());
51
-        $this->add_validation_strategy(
52
-            new EE_Text_Validation_Strategy(
53
-                sprintf(
54
-                    // translators: %1$s is a list of allowed file extensions.
55
-                    esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'),
56
-                    implode(', ', $this->allowed_file_extensions)
57
-                ),
58
-                '~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~'
59
-            )
60
-        );
61
-        parent::__construct($options);
49
+		$this->_set_display_strategy(new EE_File_Input_Display_Strategy());
50
+		$this->_set_normalization_strategy(new EE_File_Normalization());
51
+		$this->add_validation_strategy(
52
+			new EE_Text_Validation_Strategy(
53
+				sprintf(
54
+					// translators: %1$s is a list of allowed file extensions.
55
+					esc_html__('Please provide a file of the requested filetype: %1$s', 'event_espresso'),
56
+					implode(', ', $this->allowed_file_extensions)
57
+				),
58
+				'~.*\.(' . implode('|', $this->allowed_file_extensions) . ')$~'
59
+			)
60
+		);
61
+		parent::__construct($options);
62 62
 
63 63
 //        It would be great to add this HTML attribute, but jQuery validate chokes on it.
64
-        $this->set_other_html_attributes(
65
-            $this->other_html_attributes()
66
-            . ' extension="'
67
-            . implode(
68
-                ',',
69
-                $this->allowed_file_extensions
70
-            )
71
-            . '"'
72
-        );
73
-    }
64
+		$this->set_other_html_attributes(
65
+			$this->other_html_attributes()
66
+			. ' extension="'
67
+			. implode(
68
+				',',
69
+				$this->allowed_file_extensions
70
+			)
71
+			. '"'
72
+		);
73
+	}
74 74
 
75
-    /**
76
-     * $_FILES has a really weird structure. So we let `FilesDataHandler` take care of finding the file info for
77
-     * this input.
78
-     * @since 4.9.80.p
79
-     * @param array $req_data
80
-     * @return FileSubmissionInterface
81
-     * @throws InvalidArgumentException
82
-     * @throws InvalidDataTypeException
83
-     * @throws InvalidInterfaceException
84
-     */
85
-    public function find_form_data_for_this_section($req_data)
86
-    {
87
-        // ignore $req_data. Files are in the files data handler.
88
-        $fileDataHandler = LoaderFactory::getLoader()->getShared(
89
-            'EventEspresso\core\services\request\files\FilesDataHandler'
90
-        );
91
-        return $fileDataHandler->getFileObject($this->html_name());
92
-    }
75
+	/**
76
+	 * $_FILES has a really weird structure. So we let `FilesDataHandler` take care of finding the file info for
77
+	 * this input.
78
+	 * @since 4.9.80.p
79
+	 * @param array $req_data
80
+	 * @return FileSubmissionInterface
81
+	 * @throws InvalidArgumentException
82
+	 * @throws InvalidDataTypeException
83
+	 * @throws InvalidInterfaceException
84
+	 */
85
+	public function find_form_data_for_this_section($req_data)
86
+	{
87
+		// ignore $req_data. Files are in the files data handler.
88
+		$fileDataHandler = LoaderFactory::getLoader()->getShared(
89
+			'EventEspresso\core\services\request\files\FilesDataHandler'
90
+		);
91
+		return $fileDataHandler->getFileObject($this->html_name());
92
+	}
93 93
 
94
-    /**
95
-     * Don't transform the file submission object into a string, thanks.
96
-     *
97
-     * @param string $value
98
-     * @return null|string
99
-     */
100
-    protected function _sanitize($value)
101
-    {
102
-        return $value;
103
-    }
94
+	/**
95
+	 * Don't transform the file submission object into a string, thanks.
96
+	 *
97
+	 * @param string $value
98
+	 * @return null|string
99
+	 */
100
+	protected function _sanitize($value)
101
+	{
102
+		return $value;
103
+	}
104 104
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Script_Stage_Table.core.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
     {
71 71
         global $wpdb;
72 72
         $start_at_record = $this->count_records_migrated();
73
-        $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
73
+        $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} ".$wpdb->prepare(
74 74
             "LIMIT %d, %d",
75 75
             $start_at_record,
76 76
             $limit
Please login to merge, or discard this patch.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -15,89 +15,89 @@
 block discarded – undo
15 15
  */
16 16
 abstract class EE_Data_Migration_Script_Stage_Table extends EE_Data_Migration_Script_Stage
17 17
 {
18
-    protected $_old_table;
18
+	protected $_old_table;
19 19
 
20
-    /**
21
-     * @var string The columns to select. May be overridden for children.
22
-     */
23
-    protected $select_expression = '*';
20
+	/**
21
+	 * @var string The columns to select. May be overridden for children.
22
+	 */
23
+	protected $select_expression = '*';
24 24
 
25
-    /**
26
-     * Set in the constructor to add this sql to both the counting query in
27
-     * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and
28
-     * EE_Data_Migration_Script_Stage_Table::_get_rows().
29
-     * Eg "where column_name like '%some_value%'"
30
-     *
31
-     * @var string
32
-     */
33
-    protected $_extra_where_sql;
25
+	/**
26
+	 * Set in the constructor to add this sql to both the counting query in
27
+	 * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and
28
+	 * EE_Data_Migration_Script_Stage_Table::_get_rows().
29
+	 * Eg "where column_name like '%some_value%'"
30
+	 *
31
+	 * @var string
32
+	 */
33
+	protected $_extra_where_sql;
34 34
 
35 35
 
36
-    /**
37
-     * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property
38
-     * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that
39
-     * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the
40
-     * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees
41
-     * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at
42
-     * very least we MUST report/return 50 items migrated)
43
-     *
44
-     * @param int $num_items
45
-     * @return int number of items ACTUALLY migrated
46
-     */
47
-    public function _migration_step($num_items = 50)
48
-    {
49
-        $rows = $this->_get_rows($num_items);
50
-        $items_actually_migrated = 0;
51
-        foreach ($rows as $old_row) {
52
-            $this->_migrate_old_row($old_row);
53
-            $items_actually_migrated++;
54
-        }
55
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
56
-            $this->set_completed();
57
-        }
58
-        return $items_actually_migrated;
59
-    }
36
+	/**
37
+	 * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property
38
+	 * accordingly. Note: it should not alter the count of items migrated. That is done in the public function that
39
+	 * calls this. IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the
40
+	 * last migration step, otherwise it should always return $num_items_to_migrate. (Eg, if we're migrating attendees
41
+	 * rows from the database, and $num_items_to_migrate is set to 50, then we SHOULD actually migrate 50 rows,but at
42
+	 * very least we MUST report/return 50 items migrated)
43
+	 *
44
+	 * @param int $num_items
45
+	 * @return int number of items ACTUALLY migrated
46
+	 */
47
+	public function _migration_step($num_items = 50)
48
+	{
49
+		$rows = $this->_get_rows($num_items);
50
+		$items_actually_migrated = 0;
51
+		foreach ($rows as $old_row) {
52
+			$this->_migrate_old_row($old_row);
53
+			$items_actually_migrated++;
54
+		}
55
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
56
+			$this->set_completed();
57
+		}
58
+		return $items_actually_migrated;
59
+	}
60 60
 
61
-    /**
62
-     * Gets the rows for each migration stage from the old table
63
-     *
64
-     * @global wpdb $wpdb
65
-     * @param int   $limit
66
-     * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
67
-     */
68
-    protected function _get_rows($limit)
69
-    {
70
-        global $wpdb;
71
-        $start_at_record = $this->count_records_migrated();
72
-        $query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
73
-            "LIMIT %d, %d",
74
-            $start_at_record,
75
-            $limit
76
-        );
77
-        return $wpdb->get_results($query, ARRAY_A);
78
-    }
61
+	/**
62
+	 * Gets the rows for each migration stage from the old table
63
+	 *
64
+	 * @global wpdb $wpdb
65
+	 * @param int   $limit
66
+	 * @return array of arrays like $wpdb->get_results($sql, ARRAY_A)
67
+	 */
68
+	protected function _get_rows($limit)
69
+	{
70
+		global $wpdb;
71
+		$start_at_record = $this->count_records_migrated();
72
+		$query = "SELECT {$this->select_expression} FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare(
73
+			"LIMIT %d, %d",
74
+			$start_at_record,
75
+			$limit
76
+		);
77
+		return $wpdb->get_results($query, ARRAY_A);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * Counts the records to migrate; the public version may cache it
83
-     *
84
-     * @return int
85
-     */
86
-    public function _count_records_to_migrate()
87
-    {
88
-        global $wpdb;
89
-        $query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}";
90
-        $count = $wpdb->get_var($query);
91
-        return $count;
92
-    }
81
+	/**
82
+	 * Counts the records to migrate; the public version may cache it
83
+	 *
84
+	 * @return int
85
+	 */
86
+	public function _count_records_to_migrate()
87
+	{
88
+		global $wpdb;
89
+		$query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}";
90
+		$count = $wpdb->get_var($query);
91
+		return $count;
92
+	}
93 93
 
94
-    /**
95
-     * takes care of migrating this particular row from the OLD table to whatever its
96
-     * representation is in the new database. If there are errors, use $this->add_error to log them. If there is a
97
-     * fatal error which prevents all future migrations, throw an exception describing it
98
-     *
99
-     * @param array $old_row an associative array where keys are column names and values are their values.
100
-     * @return null
101
-     */
102
-    abstract protected function _migrate_old_row($old_row);
94
+	/**
95
+	 * takes care of migrating this particular row from the OLD table to whatever its
96
+	 * representation is in the new database. If there are errors, use $this->add_error to log them. If there is a
97
+	 * fatal error which prevents all future migrations, throw an exception describing it
98
+	 *
99
+	 * @param array $old_row an associative array where keys are column names and values are their values.
100
+	 * @return null
101
+	 */
102
+	abstract protected function _migrate_old_row($old_row);
103 103
 }
Please login to merge, or discard this patch.