Completed
Branch FET/extra-logging-when-trashin... (44a8f3)
by
unknown
16:47 queued 14:37
created
core/db_models/fields/EE_Password_Field.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -12,45 +12,45 @@
 block discarded – undo
12 12
  */
13 13
 class EE_Password_Field extends EE_Text_Field_Base
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $protected_fields;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $protected_fields;
19 19
 
20
-    /**
21
-     * EE_Password_Field constructor.
22
-     * @param $table_column
23
-     * @param $nicename
24
-     * @param $nullable
25
-     * @param null $default_value
26
-     * @param array $protected_fields
27
-     */
28
-    public function __construct($table_column, $nicename, $nullable, $default_value = null, $protected_fields = array())
29
-    {
30
-        $this->protected_fields = $protected_fields;
31
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
32
-    }
20
+	/**
21
+	 * EE_Password_Field constructor.
22
+	 * @param $table_column
23
+	 * @param $nicename
24
+	 * @param $nullable
25
+	 * @param null $default_value
26
+	 * @param array $protected_fields
27
+	 */
28
+	public function __construct($table_column, $nicename, $nullable, $default_value = null, $protected_fields = array())
29
+	{
30
+		$this->protected_fields = $protected_fields;
31
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
32
+	}
33 33
 
34
-    /**
35
-     * Returns the names of the fields on this model that this password field should protect
36
-     * @since 4.9.74.p
37
-     * @return array
38
-     */
39
-    public function protectedFields()
40
-    {
41
-        return $this->protected_fields;
42
-    }
34
+	/**
35
+	 * Returns the names of the fields on this model that this password field should protect
36
+	 * @since 4.9.74.p
37
+	 * @return array
38
+	 */
39
+	public function protectedFields()
40
+	{
41
+		return $this->protected_fields;
42
+	}
43 43
 
44
-    /**
45
-     * Returns whether or not the specified field is protected by this model
46
-     * @since 4.9.74.p
47
-     * @param $field_name
48
-     * @return bool
49
-     */
50
-    public function fieldIsProtected($field_name)
51
-    {
52
-        return in_array($field_name, $this->protectedFields(), true);
53
-    }
44
+	/**
45
+	 * Returns whether or not the specified field is protected by this model
46
+	 * @since 4.9.74.p
47
+	 * @param $field_name
48
+	 * @return bool
49
+	 */
50
+	public function fieldIsProtected($field_name)
51
+	{
52
+		return in_array($field_name, $this->protectedFields(), true);
53
+	}
54 54
 }
55 55
 // End of file EE_Password_Field.php
56 56
 // Location: ${NAMESPACE}/EE_Password_Field.php
Please login to merge, or discard this patch.
core/domain/services/admin/ajax/EventEditorHeartbeat.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
          * check whether count of tickets is approaching the potential
58 58
          * limits for the server.
59 59
          */
60
-        if (! empty($data['input_count'])) {
60
+        if ( ! empty($data['input_count'])) {
61 61
             $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
62 62
                 $data['input_count']
63 63
             );
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -15,52 +15,52 @@
 block discarded – undo
15 15
  */
16 16
 class EventEditorHeartbeat
17 17
 {
18
-    /**
19
-     * @var Domain $domain
20
-     */
21
-    protected $domain;
18
+	/**
19
+	 * @var Domain $domain
20
+	 */
21
+	protected $domain;
22 22
 
23
-    /**
24
-     * @var EE_Environment_Config $environment
25
-     */
26
-    protected $environment;
23
+	/**
24
+	 * @var EE_Environment_Config $environment
25
+	 */
26
+	protected $environment;
27 27
 
28 28
 
29
-    /**
30
-     * EventEditorHeartbeat constructor.
31
-     *
32
-     * @param Domain                $domain
33
-     * @param EE_Environment_Config $environment
34
-     */
35
-    public function __construct(Domain $domain, EE_Environment_Config $environment)
36
-    {
37
-        $this->domain = $domain;
38
-        $this->environment = $environment;
39
-        if ($this->domain->isCaffeinated()) {
40
-            add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2);
41
-        }
42
-    }
29
+	/**
30
+	 * EventEditorHeartbeat constructor.
31
+	 *
32
+	 * @param Domain                $domain
33
+	 * @param EE_Environment_Config $environment
34
+	 */
35
+	public function __construct(Domain $domain, EE_Environment_Config $environment)
36
+	{
37
+		$this->domain = $domain;
38
+		$this->environment = $environment;
39
+		if ($this->domain->isCaffeinated()) {
40
+			add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2);
41
+		}
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
47
-     * accordingly.
48
-     *
49
-     * @param array $response The existing heartbeat response array.
50
-     * @param array $data     The incoming data package.
51
-     * @return array  possibly appended response.
52
-     */
53
-    public function heartbeatResponse($response, $data)
54
-    {
55
-        /**
56
-         * check whether count of tickets is approaching the potential
57
-         * limits for the server.
58
-         */
59
-        if (! empty($data['input_count'])) {
60
-            $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
61
-                $data['input_count']
62
-            );
63
-        }
64
-        return $response;
65
-    }
45
+	/**
46
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
47
+	 * accordingly.
48
+	 *
49
+	 * @param array $response The existing heartbeat response array.
50
+	 * @param array $data     The incoming data package.
51
+	 * @return array  possibly appended response.
52
+	 */
53
+	public function heartbeatResponse($response, $data)
54
+	{
55
+		/**
56
+		 * check whether count of tickets is approaching the potential
57
+		 * limits for the server.
58
+		 */
59
+		if (! empty($data['input_count'])) {
60
+			$response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
61
+				$data['input_count']
62
+			);
63
+		}
64
+		return $response;
65
+	}
66 66
 }
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/forms/SettingsForm.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -19,53 +19,53 @@
 block discarded – undo
19 19
  */
20 20
 class SettingsForm extends PayPalSettingsForm
21 21
 {
22
-    /**
23
-     * SettingsForm constructor.
24
-     *
25
-     * @param array $options_array
26
-     * @param string $help_tab_link
27
-     * @throws InvalidDataTypeException
28
-     * @throws InvalidInterfaceException
29
-     * @throws InvalidArgumentException
30
-     */
31
-    public function __construct(array $options_array = array(), $help_tab_link = '')
32
-    {
33
-        $options_array = array_replace_recursive(
34
-            array(
35
-                'extra_meta_inputs' => array(
36
-                    'request_shipping_addr' => new EE_Yes_No_Input(
37
-                        array(
38
-                            'html_label_text' => sprintf(
39
-                                esc_html__('Request Shipping Address %s', 'event_espresso'),
40
-                                $help_tab_link
41
-                            ),
42
-                            'html_help_text'  => esc_html__(
43
-                            // @codingStandardsIgnoreStart
44
-                                'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
45
-                                // @codingStandardsIgnoreEnd
46
-                                'event_espresso'
47
-                            ),
48
-                            'required'        => true,
49
-                            'default'         => false,
50
-                        )
51
-                    ),
52
-                    'image_url' => new EE_Admin_File_Uploader_Input(
53
-                        array(
54
-                            'html_label_text' => sprintf(
55
-                                esc_html__('Image URL %s', 'event_espresso'),
56
-                                $help_tab_link
57
-                            ),
58
-                            'html_help_text'  => esc_html__(
59
-                                'Used for your business/personal logo on the PayPal page',
60
-                                'event_espresso'
61
-                            ),
62
-                            'required'        => false,
63
-                        )
64
-                    ),
65
-                )
66
-            ),
67
-            $options_array
68
-        );
69
-        parent::__construct($options_array, $help_tab_link);
70
-    }
22
+	/**
23
+	 * SettingsForm constructor.
24
+	 *
25
+	 * @param array $options_array
26
+	 * @param string $help_tab_link
27
+	 * @throws InvalidDataTypeException
28
+	 * @throws InvalidInterfaceException
29
+	 * @throws InvalidArgumentException
30
+	 */
31
+	public function __construct(array $options_array = array(), $help_tab_link = '')
32
+	{
33
+		$options_array = array_replace_recursive(
34
+			array(
35
+				'extra_meta_inputs' => array(
36
+					'request_shipping_addr' => new EE_Yes_No_Input(
37
+						array(
38
+							'html_label_text' => sprintf(
39
+								esc_html__('Request Shipping Address %s', 'event_espresso'),
40
+								$help_tab_link
41
+							),
42
+							'html_help_text'  => esc_html__(
43
+							// @codingStandardsIgnoreStart
44
+								'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.',
45
+								// @codingStandardsIgnoreEnd
46
+								'event_espresso'
47
+							),
48
+							'required'        => true,
49
+							'default'         => false,
50
+						)
51
+					),
52
+					'image_url' => new EE_Admin_File_Uploader_Input(
53
+						array(
54
+							'html_label_text' => sprintf(
55
+								esc_html__('Image URL %s', 'event_espresso'),
56
+								$help_tab_link
57
+							),
58
+							'html_help_text'  => esc_html__(
59
+								'Used for your business/personal logo on the PayPal page',
60
+								'event_espresso'
61
+							),
62
+							'required'        => false,
63
+						)
64
+					),
65
+				)
66
+			),
67
+			$options_array
68
+		);
69
+		parent::__construct($options_array, $help_tab_link);
70
+	}
71 71
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Question_Group.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@
 block discarded – undo
32 32
         );
33 33
         // this model is generally available for reading
34 34
         $path_to_event = 'Event';
35
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
35
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
36
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
37
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
38
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
39 39
         parent::__construct($timezone);
40 40
     }
41 41
 
Please login to merge, or discard this patch.
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -8,72 +8,72 @@
 block discarded – undo
8 8
  */
9 9
 class EEM_Event_Question_Group extends EEM_Base
10 10
 {
11
-    /**
12
-     * Name of the field indicating an event should use the question group for the primary attendee
13
-     */
14
-    const PRIMARY = 'EQG_primary';
11
+	/**
12
+	 * Name of the field indicating an event should use the question group for the primary attendee
13
+	 */
14
+	const PRIMARY = 'EQG_primary';
15 15
 
16
-    /**
17
-     * Name of hte field indicating an event should use the question group for additional attendees
18
-     */
19
-    const ADDITIONAL = 'EQG_additional';
16
+	/**
17
+	 * Name of hte field indicating an event should use the question group for additional attendees
18
+	 */
19
+	const ADDITIONAL = 'EQG_additional';
20 20
 
21
-    // private instance of the Event_Question_Group object
22
-    protected static $_instance = null;
21
+	// private instance of the Event_Question_Group object
22
+	protected static $_instance = null;
23 23
 
24
-    protected function __construct($timezone = null)
25
-    {
26
-        $this->singular_item = esc_html__('Event to Question Group Link', 'event_espresso');
27
-        $this->plural_item = esc_html__('Event to Question Group Links', 'event_espresso');
28
-        $this->_tables = array(
29
-            'Event_Question_Group' => new EE_Primary_Table('esp_event_question_group', 'EQG_ID')
30
-        );
31
-        $this->_fields = array(
32
-            'Event_Question_Group' => array(
33
-                'EQG_ID' => new EE_Primary_Key_Int_Field('EQG_ID', esc_html__('Event to Question Group Link ID', 'event_espresso')),
34
-                'EVT_ID' => new EE_Foreign_Key_Int_Field('EVT_ID', esc_html__('Event ID', 'event_espresso'), false, 0, 'Event'),
35
-                'QSG_ID' => new EE_Foreign_Key_Int_Field('QSG_ID', esc_html__('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'),
36
-                'EQG_primary' => new EE_Boolean_Field('EQG_primary', esc_html__('Flag indicating question is only for primary attendees', 'event_espresso'), false, false),
37
-                'EQG_additional' => new EE_Boolean_Field('EQG_additional', esc_html__('Flag indicating question is only for additional attendees', 'event_espresso'), false, false)
38
-            )
39
-        );
40
-        $this->_model_relations = array(
41
-            'Event' => new EE_Belongs_To_Relation(),
42
-            'Question_Group' => new EE_Belongs_To_Relation()
43
-        );
44
-        // this model is generally available for reading
45
-        $path_to_event = 'Event';
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
50
-        parent::__construct($timezone);
51
-    }
24
+	protected function __construct($timezone = null)
25
+	{
26
+		$this->singular_item = esc_html__('Event to Question Group Link', 'event_espresso');
27
+		$this->plural_item = esc_html__('Event to Question Group Links', 'event_espresso');
28
+		$this->_tables = array(
29
+			'Event_Question_Group' => new EE_Primary_Table('esp_event_question_group', 'EQG_ID')
30
+		);
31
+		$this->_fields = array(
32
+			'Event_Question_Group' => array(
33
+				'EQG_ID' => new EE_Primary_Key_Int_Field('EQG_ID', esc_html__('Event to Question Group Link ID', 'event_espresso')),
34
+				'EVT_ID' => new EE_Foreign_Key_Int_Field('EVT_ID', esc_html__('Event ID', 'event_espresso'), false, 0, 'Event'),
35
+				'QSG_ID' => new EE_Foreign_Key_Int_Field('QSG_ID', esc_html__('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'),
36
+				'EQG_primary' => new EE_Boolean_Field('EQG_primary', esc_html__('Flag indicating question is only for primary attendees', 'event_espresso'), false, false),
37
+				'EQG_additional' => new EE_Boolean_Field('EQG_additional', esc_html__('Flag indicating question is only for additional attendees', 'event_espresso'), false, false)
38
+			)
39
+		);
40
+		$this->_model_relations = array(
41
+			'Event' => new EE_Belongs_To_Relation(),
42
+			'Question_Group' => new EE_Belongs_To_Relation()
43
+		);
44
+		// this model is generally available for reading
45
+		$path_to_event = 'Event';
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event);
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
49
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
50
+		parent::__construct($timezone);
51
+	}
52 52
 
53
-    /**
54
-     * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether
55
-     * this is concerning primary attendees or additional attendees.
56
-     * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns
57
-     * EQG_additional.
58
-     * @since 4.10.0.p
59
-     * @param string|boolean|int $context
60
-     * @return string
61
-     */
62
-    public function fieldNameForContext($context)
63
-    {
64
-        // Basically do a strict switch statement.
65
-        switch (true) {
66
-            case $context === 'additional':
67
-            case $context === false:
68
-            case $context === 0:
69
-                $field_name = EEM_Event_Question_Group::ADDITIONAL;
70
-                break;
71
-            case $context === 'primary':
72
-            case $context === true:
73
-            case $context === 1:
74
-            default:
75
-                $field_name = EEM_Event_Question_Group::PRIMARY;
76
-        }
77
-        return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context);
78
-    }
53
+	/**
54
+	 * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether
55
+	 * this is concerning primary attendees or additional attendees.
56
+	 * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns
57
+	 * EQG_additional.
58
+	 * @since 4.10.0.p
59
+	 * @param string|boolean|int $context
60
+	 * @return string
61
+	 */
62
+	public function fieldNameForContext($context)
63
+	{
64
+		// Basically do a strict switch statement.
65
+		switch (true) {
66
+			case $context === 'additional':
67
+			case $context === false:
68
+			case $context === 0:
69
+				$field_name = EEM_Event_Question_Group::ADDITIONAL;
70
+				break;
71
+			case $context === 'primary':
72
+			case $context === true:
73
+			case $context === 1:
74
+			default:
75
+				$field_name = EEM_Event_Question_Group::PRIMARY;
76
+		}
77
+		return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context);
78
+	}
79 79
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Line_Item.model.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
         );
325 325
         $query = $wpdb->prepare(
326 326
             'DELETE li
327
-				FROM ' . $this->table() . ' li
328
-				LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID
327
+				FROM ' . $this->table().' li
328
+				LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID
329 329
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
330 330
             // use GMT time because that's what TXN_timestamps are in
331 331
             date('Y-m-d H:i:s', time() - $time_to_leave_alone)
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
      */
599 599
     public function getTicketLineItemsForExpiredCarts($timestamp = 0)
600 600
     {
601
-        if (! absint($timestamp)) {
601
+        if ( ! absint($timestamp)) {
602 602
             /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
603 603
             $session_lifespan = LoaderFactory::getLoader()->getShared(
604 604
                 'EventEspresso\core\domain\values\session\SessionLifespan'
Please login to merge, or discard this patch.
Indentation   +595 added lines, -595 removed lines patch added patch discarded remove patch
@@ -27,602 +27,602 @@
 block discarded – undo
27 27
  */
28 28
 class EEM_Line_Item extends EEM_Base
29 29
 {
30
-    /**
31
-     * Tax sub-total is just the total of all the taxes, which should be children
32
-     * of this line item. There should only ever be one tax sub-total, and it should
33
-     * be a direct child of. Its quantity and LIN_unit_price = 1.
34
-     */
35
-    const type_tax_sub_total = 'tax-sub-total';
36
-
37
-    /**
38
-     * Tax line items indicate a tax applied to all the taxable line items.
39
-     * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
40
-     * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
41
-     */
42
-    const type_tax = 'tax';
43
-
44
-    /**
45
-     * Indicating individual items purchased, or discounts or surcharges.
46
-     * The sum of all the regular line items  plus the tax items should equal the grand total.
47
-     * Possible children are sub-line-items and cancellations.
48
-     * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
49
-     * LIN_totals. Its LIN_percent = 0.
50
-     * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
51
-     * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
52
-     */
53
-    const type_line_item = 'line-item';
54
-
55
-    /**
56
-     * Line item indicating all the factors that make a single line item.
57
-     * Sub-line items should have NO children line items.
58
-     * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
59
-     * contribution towards the price of ONE of their parent items, and its LIN_total should be
60
-     *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
61
-     * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
62
-     * = LIN_percent / 100 * sum of lower-priority sibling line items..
63
-     */
64
-    const type_sub_line_item = 'sub-item';
65
-
66
-    /**
67
-     * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
68
-     * Direct children should be event subtotals.
69
-     * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
70
-     */
71
-    const type_sub_total = 'sub-total';
72
-
73
-    /**
74
-     * Line item for the grand total of an order.
75
-     * Its direct children should be tax subtotals and (pre-tax) subtotals,
76
-     * and possibly a regular line item indicating a transaction-wide discount/surcharge.
77
-     * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount.
78
-     */
79
-    const type_total = 'total';
80
-
81
-    /**
82
-     * When a line item is cancelled, a sub-line-item of type 'cancellation'
83
-     * should be created, indicating the quantity that were cancelled
84
-     * (because a line item could have a quantity of 1, and its cancellation item
85
-     * could be for 3, indicating that originally 4 were purchased, but 3 have been
86
-     * cancelled, and only one remains).
87
-     * When items are refunded, a cancellation line item should be made, which points
88
-     * to teh payment model object which actually refunded the payment.
89
-     * Cancellations should NOT have any children line items; the should NOT affect
90
-     * any calculations, and are only meant as a record that cancellations have occurred.
91
-     * Their LIN_percent should be 0.
92
-     */
93
-    const type_cancellation = 'cancellation';
94
-
95
-    // various line item object types
96
-    const OBJ_TYPE_EVENT = 'Event';
97
-
98
-    const OBJ_TYPE_PRICE = 'Price';
99
-
100
-    const OBJ_TYPE_PROMOTION = 'Promotion';
101
-
102
-    const OBJ_TYPE_TICKET = 'Ticket';
103
-
104
-    const OBJ_TYPE_TRANSACTION = 'Transaction';
105
-
106
-    /**
107
-     * @var EEM_Line_Item $_instance
108
-     */
109
-    protected static $_instance;
110
-
111
-
112
-    /**
113
-     * private constructor to prevent direct creation
114
-     *
115
-     * @Constructor
116
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
117
-     *                         (and any incoming timezone data that gets saved).
118
-     *                         Note this just sends the timezone info to the date time model field objects.
119
-     *                         Default is NULL
120
-     *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
121
-     * @throws EE_Error
122
-     * @throws InvalidArgumentException
123
-     */
124
-    protected function __construct($timezone)
125
-    {
126
-        $this->singular_item = esc_html__('Line Item', 'event_espresso');
127
-        $this->plural_item = esc_html__('Line Items', 'event_espresso');
128
-
129
-        $this->_tables = array(
130
-            'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'),
131
-        );
132
-        $line_items_can_be_for = apply_filters(
133
-            'FHEE__EEM_Line_Item__line_items_can_be_for',
134
-            array('Ticket', 'Price', 'Event')
135
-        );
136
-        $this->_fields = array(
137
-            'Line_Item' => array(
138
-                'LIN_ID'         => new EE_Primary_Key_Int_Field(
139
-                    'LIN_ID',
140
-                    esc_html__('ID', 'event_espresso')
141
-                ),
142
-                'LIN_code'       => new EE_Slug_Field(
143
-                    'LIN_code',
144
-                    esc_html__('Code for index into Cart', 'event_espresso'),
145
-                    true
146
-                ),
147
-                'TXN_ID'         => new EE_Foreign_Key_Int_Field(
148
-                    'TXN_ID',
149
-                    esc_html__('Transaction ID', 'event_espresso'),
150
-                    true,
151
-                    null,
152
-                    'Transaction'
153
-                ),
154
-                'LIN_name'       => new EE_Full_HTML_Field(
155
-                    'LIN_name',
156
-                    esc_html__('Line Item Name', 'event_espresso'),
157
-                    false,
158
-                    ''
159
-                ),
160
-                'LIN_desc'       => new EE_Full_HTML_Field(
161
-                    'LIN_desc',
162
-                    esc_html__('Line Item Description', 'event_espresso'),
163
-                    true
164
-                ),
165
-                'LIN_unit_price' => new EE_Money_Field(
166
-                    'LIN_unit_price',
167
-                    esc_html__('Unit Price', 'event_espresso'),
168
-                    false,
169
-                    0
170
-                ),
171
-                'LIN_percent'    => new EE_Float_Field(
172
-                    'LIN_percent',
173
-                    esc_html__('Percent', 'event_espresso'),
174
-                    false,
175
-                    0
176
-                ),
177
-                'LIN_is_taxable' => new EE_Boolean_Field(
178
-                    'LIN_is_taxable',
179
-                    esc_html__('Taxable', 'event_espresso'),
180
-                    false,
181
-                    false
182
-                ),
183
-                'LIN_order'      => new EE_Integer_Field(
184
-                    'LIN_order',
185
-                    esc_html__('Order of Application towards total of parent', 'event_espresso'),
186
-                    false,
187
-                    1
188
-                ),
189
-                'LIN_total'      => new EE_Money_Field(
190
-                    'LIN_total',
191
-                    esc_html__('Total (unit price x quantity)', 'event_espresso'),
192
-                    false,
193
-                    0
194
-                ),
195
-                'LIN_quantity'   => new EE_Integer_Field(
196
-                    'LIN_quantity',
197
-                    esc_html__('Quantity', 'event_espresso'),
198
-                    true,
199
-                    1
200
-                ),
201
-                'LIN_parent'     => new EE_Integer_Field(
202
-                    'LIN_parent',
203
-                    esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'),
204
-                    true,
205
-                    null
206
-                ),
207
-                'LIN_type'       => new EE_Enum_Text_Field(
208
-                    'LIN_type',
209
-                    esc_html__('Type', 'event_espresso'),
210
-                    false,
211
-                    'line-item',
212
-                    array(
213
-                        self::type_line_item     => esc_html__('Line Item', 'event_espresso'),
214
-                        self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'),
215
-                        self::type_sub_total     => esc_html__('Subtotal', 'event_espresso'),
216
-                        self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'),
217
-                        self::type_tax           => esc_html__('Tax', 'event_espresso'),
218
-                        self::type_total         => esc_html__('Total', 'event_espresso'),
219
-                        self::type_cancellation  => esc_html__('Cancellation', 'event_espresso'),
220
-                    )
221
-                ),
222
-                'OBJ_ID'         => new EE_Foreign_Key_Int_Field(
223
-                    'OBJ_ID',
224
-                    esc_html__('ID of Item purchased.', 'event_espresso'),
225
-                    true,
226
-                    null,
227
-                    $line_items_can_be_for
228
-                ),
229
-                'OBJ_type'       => new EE_Any_Foreign_Model_Name_Field(
230
-                    'OBJ_type',
231
-                    esc_html__('Model Name this Line Item is for', 'event_espresso'),
232
-                    true,
233
-                    null,
234
-                    $line_items_can_be_for
235
-                ),
236
-                'LIN_timestamp'  => new EE_Datetime_Field(
237
-                    'LIN_timestamp',
238
-                    esc_html__('When the line item was created', 'event_espresso'),
239
-                    false,
240
-                    EE_Datetime_Field::now,
241
-                    $timezone
242
-                ),
243
-            ),
244
-        );
245
-        $this->_model_relations = array(
246
-            'Transaction' => new EE_Belongs_To_Relation(),
247
-            'Ticket'      => new EE_Belongs_To_Any_Relation(),
248
-            'Price'       => new EE_Belongs_To_Any_Relation(),
249
-            'Event'       => new EE_Belongs_To_Any_Relation(),
250
-        );
251
-        $this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
252
-        $this->_caps_slug = 'transactions';
253
-        parent::__construct($timezone);
254
-    }
255
-
256
-
257
-    /**
258
-     * Gets all the line items for this transaction of the given type
259
-     *
260
-     * @param string             $line_item_type like one of EEM_Line_Item::type_*
261
-     * @param EE_Transaction|int $transaction
262
-     * @return EE_Base_Class[]|EE_Line_Item[]
263
-     * @throws EE_Error
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     */
268
-    public function get_all_of_type_for_transaction($line_item_type, $transaction)
269
-    {
270
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
271
-        return $this->get_all(array(
272
-            array(
273
-                'LIN_type' => $line_item_type,
274
-                'TXN_ID'   => $transaction,
275
-            ),
276
-        ));
277
-    }
278
-
279
-
280
-    /**
281
-     * Gets all line items unrelated to tickets that are normal line items
282
-     * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
283
-     *
284
-     * @param EE_Transaction|int $transaction
285
-     * @return EE_Base_Class[]|EE_Line_Item[]
286
-     * @throws EE_Error
287
-     * @throws InvalidArgumentException
288
-     * @throws InvalidDataTypeException
289
-     * @throws InvalidInterfaceException
290
-     */
291
-    public function get_all_non_ticket_line_items_for_transaction($transaction)
292
-    {
293
-        $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
294
-        return $this->get_all(array(
295
-            array(
296
-                'LIN_type' => self::type_line_item,
297
-                'TXN_ID'   => $transaction,
298
-                'OR'       => array(
299
-                    'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET),
300
-                    'OBJ_type*null'      => array('IS_NULL'),
301
-                ),
302
-            ),
303
-        ));
304
-    }
305
-
306
-
307
-    /**
308
-     * Deletes line items with no transaction who have passed the transaction cutoff time.
309
-     * This needs to be very efficient
310
-     * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when
311
-     * deleting and joining tables like this.
312
-     *
313
-     * @return int count of how many deleted
314
-     * @throws EE_Error
315
-     * @throws InvalidArgumentException
316
-     * @throws InvalidDataTypeException
317
-     * @throws InvalidInterfaceException
318
-     */
319
-    public function delete_line_items_with_no_transaction()
320
-    {
321
-        /** @type WPDB $wpdb */
322
-        global $wpdb;
323
-        $time_to_leave_alone = apply_filters(
324
-            'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
325
-            WEEK_IN_SECONDS
326
-        );
327
-        $query = $wpdb->prepare(
328
-            'DELETE li
30
+	/**
31
+	 * Tax sub-total is just the total of all the taxes, which should be children
32
+	 * of this line item. There should only ever be one tax sub-total, and it should
33
+	 * be a direct child of. Its quantity and LIN_unit_price = 1.
34
+	 */
35
+	const type_tax_sub_total = 'tax-sub-total';
36
+
37
+	/**
38
+	 * Tax line items indicate a tax applied to all the taxable line items.
39
+	 * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal
40
+	 * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1.
41
+	 */
42
+	const type_tax = 'tax';
43
+
44
+	/**
45
+	 * Indicating individual items purchased, or discounts or surcharges.
46
+	 * The sum of all the regular line items  plus the tax items should equal the grand total.
47
+	 * Possible children are sub-line-items and cancellations.
48
+	 * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children
49
+	 * LIN_totals. Its LIN_percent = 0.
50
+	 * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1).
51
+	 * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1.
52
+	 */
53
+	const type_line_item = 'line-item';
54
+
55
+	/**
56
+	 * Line item indicating all the factors that make a single line item.
57
+	 * Sub-line items should have NO children line items.
58
+	 * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's
59
+	 * contribution towards the price of ONE of their parent items, and its LIN_total should be
60
+	 *  = LIN_quantity * LIN_unit_price. Its LIN_percent = 0.
61
+	 * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should
62
+	 * = LIN_percent / 100 * sum of lower-priority sibling line items..
63
+	 */
64
+	const type_sub_line_item = 'sub-item';
65
+
66
+	/**
67
+	 * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal).
68
+	 * Direct children should be event subtotals.
69
+	 * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals.
70
+	 */
71
+	const type_sub_total = 'sub-total';
72
+
73
+	/**
74
+	 * Line item for the grand total of an order.
75
+	 * Its direct children should be tax subtotals and (pre-tax) subtotals,
76
+	 * and possibly a regular line item indicating a transaction-wide discount/surcharge.
77
+	 * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount.
78
+	 */
79
+	const type_total = 'total';
80
+
81
+	/**
82
+	 * When a line item is cancelled, a sub-line-item of type 'cancellation'
83
+	 * should be created, indicating the quantity that were cancelled
84
+	 * (because a line item could have a quantity of 1, and its cancellation item
85
+	 * could be for 3, indicating that originally 4 were purchased, but 3 have been
86
+	 * cancelled, and only one remains).
87
+	 * When items are refunded, a cancellation line item should be made, which points
88
+	 * to teh payment model object which actually refunded the payment.
89
+	 * Cancellations should NOT have any children line items; the should NOT affect
90
+	 * any calculations, and are only meant as a record that cancellations have occurred.
91
+	 * Their LIN_percent should be 0.
92
+	 */
93
+	const type_cancellation = 'cancellation';
94
+
95
+	// various line item object types
96
+	const OBJ_TYPE_EVENT = 'Event';
97
+
98
+	const OBJ_TYPE_PRICE = 'Price';
99
+
100
+	const OBJ_TYPE_PROMOTION = 'Promotion';
101
+
102
+	const OBJ_TYPE_TICKET = 'Ticket';
103
+
104
+	const OBJ_TYPE_TRANSACTION = 'Transaction';
105
+
106
+	/**
107
+	 * @var EEM_Line_Item $_instance
108
+	 */
109
+	protected static $_instance;
110
+
111
+
112
+	/**
113
+	 * private constructor to prevent direct creation
114
+	 *
115
+	 * @Constructor
116
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
117
+	 *                         (and any incoming timezone data that gets saved).
118
+	 *                         Note this just sends the timezone info to the date time model field objects.
119
+	 *                         Default is NULL
120
+	 *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
121
+	 * @throws EE_Error
122
+	 * @throws InvalidArgumentException
123
+	 */
124
+	protected function __construct($timezone)
125
+	{
126
+		$this->singular_item = esc_html__('Line Item', 'event_espresso');
127
+		$this->plural_item = esc_html__('Line Items', 'event_espresso');
128
+
129
+		$this->_tables = array(
130
+			'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'),
131
+		);
132
+		$line_items_can_be_for = apply_filters(
133
+			'FHEE__EEM_Line_Item__line_items_can_be_for',
134
+			array('Ticket', 'Price', 'Event')
135
+		);
136
+		$this->_fields = array(
137
+			'Line_Item' => array(
138
+				'LIN_ID'         => new EE_Primary_Key_Int_Field(
139
+					'LIN_ID',
140
+					esc_html__('ID', 'event_espresso')
141
+				),
142
+				'LIN_code'       => new EE_Slug_Field(
143
+					'LIN_code',
144
+					esc_html__('Code for index into Cart', 'event_espresso'),
145
+					true
146
+				),
147
+				'TXN_ID'         => new EE_Foreign_Key_Int_Field(
148
+					'TXN_ID',
149
+					esc_html__('Transaction ID', 'event_espresso'),
150
+					true,
151
+					null,
152
+					'Transaction'
153
+				),
154
+				'LIN_name'       => new EE_Full_HTML_Field(
155
+					'LIN_name',
156
+					esc_html__('Line Item Name', 'event_espresso'),
157
+					false,
158
+					''
159
+				),
160
+				'LIN_desc'       => new EE_Full_HTML_Field(
161
+					'LIN_desc',
162
+					esc_html__('Line Item Description', 'event_espresso'),
163
+					true
164
+				),
165
+				'LIN_unit_price' => new EE_Money_Field(
166
+					'LIN_unit_price',
167
+					esc_html__('Unit Price', 'event_espresso'),
168
+					false,
169
+					0
170
+				),
171
+				'LIN_percent'    => new EE_Float_Field(
172
+					'LIN_percent',
173
+					esc_html__('Percent', 'event_espresso'),
174
+					false,
175
+					0
176
+				),
177
+				'LIN_is_taxable' => new EE_Boolean_Field(
178
+					'LIN_is_taxable',
179
+					esc_html__('Taxable', 'event_espresso'),
180
+					false,
181
+					false
182
+				),
183
+				'LIN_order'      => new EE_Integer_Field(
184
+					'LIN_order',
185
+					esc_html__('Order of Application towards total of parent', 'event_espresso'),
186
+					false,
187
+					1
188
+				),
189
+				'LIN_total'      => new EE_Money_Field(
190
+					'LIN_total',
191
+					esc_html__('Total (unit price x quantity)', 'event_espresso'),
192
+					false,
193
+					0
194
+				),
195
+				'LIN_quantity'   => new EE_Integer_Field(
196
+					'LIN_quantity',
197
+					esc_html__('Quantity', 'event_espresso'),
198
+					true,
199
+					1
200
+				),
201
+				'LIN_parent'     => new EE_Integer_Field(
202
+					'LIN_parent',
203
+					esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'),
204
+					true,
205
+					null
206
+				),
207
+				'LIN_type'       => new EE_Enum_Text_Field(
208
+					'LIN_type',
209
+					esc_html__('Type', 'event_espresso'),
210
+					false,
211
+					'line-item',
212
+					array(
213
+						self::type_line_item     => esc_html__('Line Item', 'event_espresso'),
214
+						self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'),
215
+						self::type_sub_total     => esc_html__('Subtotal', 'event_espresso'),
216
+						self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'),
217
+						self::type_tax           => esc_html__('Tax', 'event_espresso'),
218
+						self::type_total         => esc_html__('Total', 'event_espresso'),
219
+						self::type_cancellation  => esc_html__('Cancellation', 'event_espresso'),
220
+					)
221
+				),
222
+				'OBJ_ID'         => new EE_Foreign_Key_Int_Field(
223
+					'OBJ_ID',
224
+					esc_html__('ID of Item purchased.', 'event_espresso'),
225
+					true,
226
+					null,
227
+					$line_items_can_be_for
228
+				),
229
+				'OBJ_type'       => new EE_Any_Foreign_Model_Name_Field(
230
+					'OBJ_type',
231
+					esc_html__('Model Name this Line Item is for', 'event_espresso'),
232
+					true,
233
+					null,
234
+					$line_items_can_be_for
235
+				),
236
+				'LIN_timestamp'  => new EE_Datetime_Field(
237
+					'LIN_timestamp',
238
+					esc_html__('When the line item was created', 'event_espresso'),
239
+					false,
240
+					EE_Datetime_Field::now,
241
+					$timezone
242
+				),
243
+			),
244
+		);
245
+		$this->_model_relations = array(
246
+			'Transaction' => new EE_Belongs_To_Relation(),
247
+			'Ticket'      => new EE_Belongs_To_Any_Relation(),
248
+			'Price'       => new EE_Belongs_To_Any_Relation(),
249
+			'Event'       => new EE_Belongs_To_Any_Relation(),
250
+		);
251
+		$this->_model_chain_to_wp_user = 'Transaction.Registration.Event';
252
+		$this->_caps_slug = 'transactions';
253
+		parent::__construct($timezone);
254
+	}
255
+
256
+
257
+	/**
258
+	 * Gets all the line items for this transaction of the given type
259
+	 *
260
+	 * @param string             $line_item_type like one of EEM_Line_Item::type_*
261
+	 * @param EE_Transaction|int $transaction
262
+	 * @return EE_Base_Class[]|EE_Line_Item[]
263
+	 * @throws EE_Error
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 */
268
+	public function get_all_of_type_for_transaction($line_item_type, $transaction)
269
+	{
270
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
271
+		return $this->get_all(array(
272
+			array(
273
+				'LIN_type' => $line_item_type,
274
+				'TXN_ID'   => $transaction,
275
+			),
276
+		));
277
+	}
278
+
279
+
280
+	/**
281
+	 * Gets all line items unrelated to tickets that are normal line items
282
+	 * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category)
283
+	 *
284
+	 * @param EE_Transaction|int $transaction
285
+	 * @return EE_Base_Class[]|EE_Line_Item[]
286
+	 * @throws EE_Error
287
+	 * @throws InvalidArgumentException
288
+	 * @throws InvalidDataTypeException
289
+	 * @throws InvalidInterfaceException
290
+	 */
291
+	public function get_all_non_ticket_line_items_for_transaction($transaction)
292
+	{
293
+		$transaction = EEM_Transaction::instance()->ensure_is_ID($transaction);
294
+		return $this->get_all(array(
295
+			array(
296
+				'LIN_type' => self::type_line_item,
297
+				'TXN_ID'   => $transaction,
298
+				'OR'       => array(
299
+					'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET),
300
+					'OBJ_type*null'      => array('IS_NULL'),
301
+				),
302
+			),
303
+		));
304
+	}
305
+
306
+
307
+	/**
308
+	 * Deletes line items with no transaction who have passed the transaction cutoff time.
309
+	 * This needs to be very efficient
310
+	 * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when
311
+	 * deleting and joining tables like this.
312
+	 *
313
+	 * @return int count of how many deleted
314
+	 * @throws EE_Error
315
+	 * @throws InvalidArgumentException
316
+	 * @throws InvalidDataTypeException
317
+	 * @throws InvalidInterfaceException
318
+	 */
319
+	public function delete_line_items_with_no_transaction()
320
+	{
321
+		/** @type WPDB $wpdb */
322
+		global $wpdb;
323
+		$time_to_leave_alone = apply_filters(
324
+			'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone',
325
+			WEEK_IN_SECONDS
326
+		);
327
+		$query = $wpdb->prepare(
328
+			'DELETE li
329 329
 				FROM ' . $this->table() . ' li
330 330
 				LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID
331 331
 				WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s',
332
-            // use GMT time because that's what TXN_timestamps are in
333
-            date('Y-m-d H:i:s', time() - $time_to_leave_alone)
334
-        );
335
-        return $wpdb->query($query);
336
-    }
337
-
338
-
339
-    /**
340
-     * get_line_item_for_transaction_object
341
-     * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
342
-     *
343
-     * @param int           $TXN_ID
344
-     * @param EE_Base_Class $object
345
-     * @return EE_Base_Class[]|EE_Line_Item[]
346
-     * @throws EE_Error
347
-     * @throws InvalidArgumentException
348
-     * @throws InvalidDataTypeException
349
-     * @throws InvalidInterfaceException
350
-     * @throws ReflectionException
351
-     */
352
-    public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
353
-    {
354
-        return $this->get_all(array(
355
-            array(
356
-                'TXN_ID'   => $TXN_ID,
357
-                'OBJ_type' => str_replace('EE_', '', get_class($object)),
358
-                'OBJ_ID'   => $object->ID(),
359
-            ),
360
-        ));
361
-    }
362
-
363
-
364
-    /**
365
-     * get_object_line_items_for_transaction
366
-     * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
367
-     *
368
-     * @param int    $TXN_ID
369
-     * @param string $OBJ_type
370
-     * @param array  $OBJ_IDs
371
-     * @return EE_Base_Class[]|EE_Line_Item[]
372
-     * @throws EE_Error
373
-     */
374
-    public function get_object_line_items_for_transaction(
375
-        $TXN_ID,
376
-        $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT,
377
-        $OBJ_IDs = array()
378
-    ) {
379
-        $query_params = array(
380
-            'OBJ_type' => $OBJ_type,
381
-            // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
382
-            'OBJ_ID'   => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs,
383
-        );
384
-        if ($TXN_ID) {
385
-            $query_params['TXN_ID'] = $TXN_ID;
386
-        }
387
-        return $this->get_all(array($query_params));
388
-    }
389
-
390
-
391
-    /**
392
-     * get_all_ticket_line_items_for_transaction
393
-     *
394
-     * @param EE_Transaction $transaction
395
-     * @return EE_Base_Class[]|EE_Line_Item[]
396
-     * @throws EE_Error
397
-     * @throws InvalidArgumentException
398
-     * @throws InvalidDataTypeException
399
-     * @throws InvalidInterfaceException
400
-     * @throws ReflectionException
401
-     */
402
-    public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
403
-    {
404
-        return $this->get_all(array(
405
-            array(
406
-                'TXN_ID'   => $transaction->ID(),
407
-                'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
408
-            ),
409
-        ));
410
-    }
411
-
412
-
413
-    /**
414
-     * get_ticket_line_item_for_transaction
415
-     *
416
-     * @param int $TXN_ID
417
-     * @param int $TKT_ID
418
-     * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
419
-     * @throws EE_Error
420
-     * @throws InvalidArgumentException
421
-     * @throws InvalidDataTypeException
422
-     * @throws InvalidInterfaceException
423
-     */
424
-    public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
425
-    {
426
-        return $this->get_one(array(
427
-            array(
428
-                'TXN_ID'   => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
429
-                'OBJ_ID'   => $TKT_ID,
430
-                'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
431
-            ),
432
-        ));
433
-    }
434
-
435
-
436
-    /**
437
-     * get_existing_promotion_line_item
438
-     * searches the cart for existing line items for the specified promotion
439
-     *
440
-     * @since 1.0.0
441
-     * @param EE_Line_Item $parent_line_item
442
-     * @param EE_Promotion $promotion
443
-     * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
444
-     * @throws EE_Error
445
-     * @throws InvalidArgumentException
446
-     * @throws InvalidDataTypeException
447
-     * @throws InvalidInterfaceException
448
-     * @throws ReflectionException
449
-     */
450
-    public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
451
-    {
452
-        return $this->get_one(array(
453
-            array(
454
-                'TXN_ID'     => $parent_line_item->TXN_ID(),
455
-                'LIN_parent' => $parent_line_item->ID(),
456
-                'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
457
-                'OBJ_ID'     => $promotion->ID(),
458
-            ),
459
-        ));
460
-    }
461
-
462
-
463
-    /**
464
-     * get_all_promotion_line_items
465
-     * searches the cart for any and all existing promotion line items
466
-     *
467
-     * @since   1.0.0
468
-     * @param EE_Line_Item $parent_line_item
469
-     * @return EE_Base_Class[]|EE_Line_Item[]
470
-     * @throws EE_Error
471
-     * @throws InvalidArgumentException
472
-     * @throws InvalidDataTypeException
473
-     * @throws InvalidInterfaceException
474
-     * @throws ReflectionException
475
-     */
476
-    public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
477
-    {
478
-        return $this->get_all(array(
479
-            array(
480
-                'TXN_ID'     => $parent_line_item->TXN_ID(),
481
-                'LIN_parent' => $parent_line_item->ID(),
482
-                'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
483
-            ),
484
-        ));
485
-    }
486
-
487
-
488
-    /**
489
-     * Gets the registration's corresponding line item.
490
-     * Note: basically does NOT support having multiple line items for a single ticket,
491
-     * which would happen if some of the registrations had a price modifier while others didn't.
492
-     * In order to support that, we'd probably need a LIN_ID on registrations or something.
493
-     *
494
-     * @param EE_Registration $registration
495
-     * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL
496
-     * @throws EE_Error
497
-     */
498
-    public function get_line_item_for_registration(EE_Registration $registration)
499
-    {
500
-        return $this->get_one($this->line_item_for_registration_query_params($registration));
501
-    }
502
-
503
-
504
-    /**
505
-     * Gets the query params used to retrieve a specific line item for the given registration
506
-     *
507
-     * @param EE_Registration $registration
508
-     * @param array           $original_query_params any extra query params you'd like to be merged with
509
-     * @return array @see
510
-     *      https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
511
-     * @throws EE_Error
512
-     */
513
-    public function line_item_for_registration_query_params(
514
-        EE_Registration $registration,
515
-        $original_query_params = array()
516
-    ) {
517
-        return array_replace_recursive($original_query_params, array(
518
-            array(
519
-                'OBJ_ID'   => $registration->ticket_ID(),
520
-                'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
521
-                'TXN_ID'   => $registration->transaction_ID(),
522
-            ),
523
-        ));
524
-    }
525
-
526
-
527
-    /**
528
-     * @return EE_Base_Class[]|EE_Line_Item[]
529
-     * @throws InvalidInterfaceException
530
-     * @throws InvalidDataTypeException
531
-     * @throws EE_Error
532
-     * @throws InvalidArgumentException
533
-     */
534
-    public function get_total_line_items_with_no_transaction()
535
-    {
536
-        return $this->get_total_line_items_for_carts();
537
-    }
538
-
539
-
540
-    /**
541
-     * @return EE_Base_Class[]|EE_Line_Item[]
542
-     * @throws InvalidInterfaceException
543
-     * @throws InvalidDataTypeException
544
-     * @throws EE_Error
545
-     * @throws InvalidArgumentException
546
-     */
547
-    public function get_total_line_items_for_active_carts()
548
-    {
549
-        return $this->get_total_line_items_for_carts(false);
550
-    }
551
-
552
-
553
-    /**
554
-     * @return EE_Base_Class[]|EE_Line_Item[]
555
-     * @throws InvalidInterfaceException
556
-     * @throws InvalidDataTypeException
557
-     * @throws EE_Error
558
-     * @throws InvalidArgumentException
559
-     */
560
-    public function get_total_line_items_for_expired_carts()
561
-    {
562
-        return $this->get_total_line_items_for_carts(true);
563
-    }
564
-
565
-
566
-    /**
567
-     * Returns an array of grand total line items where the TXN_ID is 0.
568
-     * If $expired is set to true, then only line items for expired sessions will be returned.
569
-     * If $expired is set to false, then only line items for active sessions will be returned.
570
-     *
571
-     * @param null $expired
572
-     * @return EE_Base_Class[]|EE_Line_Item[]
573
-     * @throws EE_Error
574
-     * @throws InvalidArgumentException
575
-     * @throws InvalidDataTypeException
576
-     * @throws InvalidInterfaceException
577
-     */
578
-    private function get_total_line_items_for_carts($expired = null)
579
-    {
580
-        $where_params = array(
581
-            'TXN_ID'   => 0,
582
-            'LIN_type' => 'total',
583
-        );
584
-        if ($expired !== null) {
585
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
586
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
587
-                'EventEspresso\core\domain\values\session\SessionLifespan'
588
-            );
589
-            $where_params['LIN_timestamp'] = array(
590
-                $expired ? '<=' : '>',
591
-                $session_lifespan->expiration(),
592
-            );
593
-        }
594
-        return $this->get_all(array($where_params));
595
-    }
596
-
597
-
598
-    /**
599
-     * Returns an array of ticket total line items where the TXN_ID is 0
600
-     * AND the timestamp is older than the session lifespan.
601
-     *
602
-     * @param int $timestamp
603
-     * @return EE_Base_Class[]|EE_Line_Item[]
604
-     * @throws EE_Error
605
-     * @throws InvalidArgumentException
606
-     * @throws InvalidDataTypeException
607
-     * @throws InvalidInterfaceException
608
-     */
609
-    public function getTicketLineItemsForExpiredCarts($timestamp = 0)
610
-    {
611
-        if (! absint($timestamp)) {
612
-            /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
613
-            $session_lifespan = LoaderFactory::getLoader()->getShared(
614
-                'EventEspresso\core\domain\values\session\SessionLifespan'
615
-            );
616
-            $timestamp = $session_lifespan->expiration();
617
-        }
618
-        return $this->get_all(
619
-            array(
620
-                array(
621
-                    'TXN_ID'        => 0,
622
-                    'OBJ_type'      => EEM_Line_Item::OBJ_TYPE_TICKET,
623
-                    'LIN_timestamp' => array('<=', $timestamp),
624
-                ),
625
-            )
626
-        );
627
-    }
332
+			// use GMT time because that's what TXN_timestamps are in
333
+			date('Y-m-d H:i:s', time() - $time_to_leave_alone)
334
+		);
335
+		return $wpdb->query($query);
336
+	}
337
+
338
+
339
+	/**
340
+	 * get_line_item_for_transaction_object
341
+	 * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket
342
+	 *
343
+	 * @param int           $TXN_ID
344
+	 * @param EE_Base_Class $object
345
+	 * @return EE_Base_Class[]|EE_Line_Item[]
346
+	 * @throws EE_Error
347
+	 * @throws InvalidArgumentException
348
+	 * @throws InvalidDataTypeException
349
+	 * @throws InvalidInterfaceException
350
+	 * @throws ReflectionException
351
+	 */
352
+	public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object)
353
+	{
354
+		return $this->get_all(array(
355
+			array(
356
+				'TXN_ID'   => $TXN_ID,
357
+				'OBJ_type' => str_replace('EE_', '', get_class($object)),
358
+				'OBJ_ID'   => $object->ID(),
359
+			),
360
+		));
361
+	}
362
+
363
+
364
+	/**
365
+	 * get_object_line_items_for_transaction
366
+	 * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs
367
+	 *
368
+	 * @param int    $TXN_ID
369
+	 * @param string $OBJ_type
370
+	 * @param array  $OBJ_IDs
371
+	 * @return EE_Base_Class[]|EE_Line_Item[]
372
+	 * @throws EE_Error
373
+	 */
374
+	public function get_object_line_items_for_transaction(
375
+		$TXN_ID,
376
+		$OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT,
377
+		$OBJ_IDs = array()
378
+	) {
379
+		$query_params = array(
380
+			'OBJ_type' => $OBJ_type,
381
+			// if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query
382
+			'OBJ_ID'   => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs,
383
+		);
384
+		if ($TXN_ID) {
385
+			$query_params['TXN_ID'] = $TXN_ID;
386
+		}
387
+		return $this->get_all(array($query_params));
388
+	}
389
+
390
+
391
+	/**
392
+	 * get_all_ticket_line_items_for_transaction
393
+	 *
394
+	 * @param EE_Transaction $transaction
395
+	 * @return EE_Base_Class[]|EE_Line_Item[]
396
+	 * @throws EE_Error
397
+	 * @throws InvalidArgumentException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws InvalidInterfaceException
400
+	 * @throws ReflectionException
401
+	 */
402
+	public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction)
403
+	{
404
+		return $this->get_all(array(
405
+			array(
406
+				'TXN_ID'   => $transaction->ID(),
407
+				'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
408
+			),
409
+		));
410
+	}
411
+
412
+
413
+	/**
414
+	 * get_ticket_line_item_for_transaction
415
+	 *
416
+	 * @param int $TXN_ID
417
+	 * @param int $TKT_ID
418
+	 * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
419
+	 * @throws EE_Error
420
+	 * @throws InvalidArgumentException
421
+	 * @throws InvalidDataTypeException
422
+	 * @throws InvalidInterfaceException
423
+	 */
424
+	public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID)
425
+	{
426
+		return $this->get_one(array(
427
+			array(
428
+				'TXN_ID'   => EEM_Transaction::instance()->ensure_is_ID($TXN_ID),
429
+				'OBJ_ID'   => $TKT_ID,
430
+				'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
431
+			),
432
+		));
433
+	}
434
+
435
+
436
+	/**
437
+	 * get_existing_promotion_line_item
438
+	 * searches the cart for existing line items for the specified promotion
439
+	 *
440
+	 * @since 1.0.0
441
+	 * @param EE_Line_Item $parent_line_item
442
+	 * @param EE_Promotion $promotion
443
+	 * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL
444
+	 * @throws EE_Error
445
+	 * @throws InvalidArgumentException
446
+	 * @throws InvalidDataTypeException
447
+	 * @throws InvalidInterfaceException
448
+	 * @throws ReflectionException
449
+	 */
450
+	public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion)
451
+	{
452
+		return $this->get_one(array(
453
+			array(
454
+				'TXN_ID'     => $parent_line_item->TXN_ID(),
455
+				'LIN_parent' => $parent_line_item->ID(),
456
+				'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
457
+				'OBJ_ID'     => $promotion->ID(),
458
+			),
459
+		));
460
+	}
461
+
462
+
463
+	/**
464
+	 * get_all_promotion_line_items
465
+	 * searches the cart for any and all existing promotion line items
466
+	 *
467
+	 * @since   1.0.0
468
+	 * @param EE_Line_Item $parent_line_item
469
+	 * @return EE_Base_Class[]|EE_Line_Item[]
470
+	 * @throws EE_Error
471
+	 * @throws InvalidArgumentException
472
+	 * @throws InvalidDataTypeException
473
+	 * @throws InvalidInterfaceException
474
+	 * @throws ReflectionException
475
+	 */
476
+	public function get_all_promotion_line_items(EE_Line_Item $parent_line_item)
477
+	{
478
+		return $this->get_all(array(
479
+			array(
480
+				'TXN_ID'     => $parent_line_item->TXN_ID(),
481
+				'LIN_parent' => $parent_line_item->ID(),
482
+				'OBJ_type'   => EEM_Line_Item::OBJ_TYPE_PROMOTION,
483
+			),
484
+		));
485
+	}
486
+
487
+
488
+	/**
489
+	 * Gets the registration's corresponding line item.
490
+	 * Note: basically does NOT support having multiple line items for a single ticket,
491
+	 * which would happen if some of the registrations had a price modifier while others didn't.
492
+	 * In order to support that, we'd probably need a LIN_ID on registrations or something.
493
+	 *
494
+	 * @param EE_Registration $registration
495
+	 * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL
496
+	 * @throws EE_Error
497
+	 */
498
+	public function get_line_item_for_registration(EE_Registration $registration)
499
+	{
500
+		return $this->get_one($this->line_item_for_registration_query_params($registration));
501
+	}
502
+
503
+
504
+	/**
505
+	 * Gets the query params used to retrieve a specific line item for the given registration
506
+	 *
507
+	 * @param EE_Registration $registration
508
+	 * @param array           $original_query_params any extra query params you'd like to be merged with
509
+	 * @return array @see
510
+	 *      https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
511
+	 * @throws EE_Error
512
+	 */
513
+	public function line_item_for_registration_query_params(
514
+		EE_Registration $registration,
515
+		$original_query_params = array()
516
+	) {
517
+		return array_replace_recursive($original_query_params, array(
518
+			array(
519
+				'OBJ_ID'   => $registration->ticket_ID(),
520
+				'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET,
521
+				'TXN_ID'   => $registration->transaction_ID(),
522
+			),
523
+		));
524
+	}
525
+
526
+
527
+	/**
528
+	 * @return EE_Base_Class[]|EE_Line_Item[]
529
+	 * @throws InvalidInterfaceException
530
+	 * @throws InvalidDataTypeException
531
+	 * @throws EE_Error
532
+	 * @throws InvalidArgumentException
533
+	 */
534
+	public function get_total_line_items_with_no_transaction()
535
+	{
536
+		return $this->get_total_line_items_for_carts();
537
+	}
538
+
539
+
540
+	/**
541
+	 * @return EE_Base_Class[]|EE_Line_Item[]
542
+	 * @throws InvalidInterfaceException
543
+	 * @throws InvalidDataTypeException
544
+	 * @throws EE_Error
545
+	 * @throws InvalidArgumentException
546
+	 */
547
+	public function get_total_line_items_for_active_carts()
548
+	{
549
+		return $this->get_total_line_items_for_carts(false);
550
+	}
551
+
552
+
553
+	/**
554
+	 * @return EE_Base_Class[]|EE_Line_Item[]
555
+	 * @throws InvalidInterfaceException
556
+	 * @throws InvalidDataTypeException
557
+	 * @throws EE_Error
558
+	 * @throws InvalidArgumentException
559
+	 */
560
+	public function get_total_line_items_for_expired_carts()
561
+	{
562
+		return $this->get_total_line_items_for_carts(true);
563
+	}
564
+
565
+
566
+	/**
567
+	 * Returns an array of grand total line items where the TXN_ID is 0.
568
+	 * If $expired is set to true, then only line items for expired sessions will be returned.
569
+	 * If $expired is set to false, then only line items for active sessions will be returned.
570
+	 *
571
+	 * @param null $expired
572
+	 * @return EE_Base_Class[]|EE_Line_Item[]
573
+	 * @throws EE_Error
574
+	 * @throws InvalidArgumentException
575
+	 * @throws InvalidDataTypeException
576
+	 * @throws InvalidInterfaceException
577
+	 */
578
+	private function get_total_line_items_for_carts($expired = null)
579
+	{
580
+		$where_params = array(
581
+			'TXN_ID'   => 0,
582
+			'LIN_type' => 'total',
583
+		);
584
+		if ($expired !== null) {
585
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
586
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
587
+				'EventEspresso\core\domain\values\session\SessionLifespan'
588
+			);
589
+			$where_params['LIN_timestamp'] = array(
590
+				$expired ? '<=' : '>',
591
+				$session_lifespan->expiration(),
592
+			);
593
+		}
594
+		return $this->get_all(array($where_params));
595
+	}
596
+
597
+
598
+	/**
599
+	 * Returns an array of ticket total line items where the TXN_ID is 0
600
+	 * AND the timestamp is older than the session lifespan.
601
+	 *
602
+	 * @param int $timestamp
603
+	 * @return EE_Base_Class[]|EE_Line_Item[]
604
+	 * @throws EE_Error
605
+	 * @throws InvalidArgumentException
606
+	 * @throws InvalidDataTypeException
607
+	 * @throws InvalidInterfaceException
608
+	 */
609
+	public function getTicketLineItemsForExpiredCarts($timestamp = 0)
610
+	{
611
+		if (! absint($timestamp)) {
612
+			/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
613
+			$session_lifespan = LoaderFactory::getLoader()->getShared(
614
+				'EventEspresso\core\domain\values\session\SessionLifespan'
615
+			);
616
+			$timestamp = $session_lifespan->expiration();
617
+		}
618
+		return $this->get_all(
619
+			array(
620
+				array(
621
+					'TXN_ID'        => 0,
622
+					'OBJ_type'      => EEM_Line_Item::OBJ_TYPE_TICKET,
623
+					'LIN_timestamp' => array('<=', $timestamp),
624
+				),
625
+			)
626
+		);
627
+	}
628 628
 }
Please login to merge, or discard this patch.
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   +1730 added lines, -1730 removed lines patch added patch discarded remove patch
@@ -13,1734 +13,1734 @@
 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
-     * extra meta key for tracking when transactions are deleted and by who
24
-     *
25
-     * @type string
26
-     */
27
-    const EXTRA_META_KEY_TXN_DELETED = 'transaction-deleted';
28
-
29
-    /**
30
-     * txn status upon initial construction.
31
-     *
32
-     * @var string
33
-     */
34
-    protected $_old_txn_status;
35
-
36
-
37
-    /**
38
-     * @param array  $props_n_values          incoming values
39
-     * @param string $timezone                incoming timezone
40
-     *                                        (if not set the timezone set for the website will be used.)
41
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
42
-     *                                        date_format and the second value is the time format
43
-     * @return EE_Transaction
44
-     * @throws EE_Error
45
-     * @throws InvalidArgumentException
46
-     * @throws InvalidDataTypeException
47
-     * @throws InvalidInterfaceException
48
-     * @throws ReflectionException
49
-     */
50
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
51
-    {
52
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
53
-        $txn = $has_object
54
-            ? $has_object
55
-            : new self($props_n_values, false, $timezone, $date_formats);
56
-        if (! $has_object) {
57
-            $txn->set_old_txn_status($txn->status_ID());
58
-        }
59
-        return $txn;
60
-    }
61
-
62
-
63
-    /**
64
-     * @param array  $props_n_values  incoming values from the database
65
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
66
-     *                                the website will be used.
67
-     * @return EE_Transaction
68
-     * @throws EE_Error
69
-     * @throws InvalidArgumentException
70
-     * @throws InvalidDataTypeException
71
-     * @throws InvalidInterfaceException
72
-     * @throws ReflectionException
73
-     */
74
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
75
-    {
76
-        $txn = new self($props_n_values, true, $timezone);
77
-        $txn->set_old_txn_status($txn->status_ID());
78
-        return $txn;
79
-    }
80
-
81
-
82
-    /**
83
-     * Sets a meta field indicating that this TXN is locked and should not be updated in the db.
84
-     * If a lock has already been set, then we will attempt to remove it in case it has expired.
85
-     * If that also fails, then an exception is thrown.
86
-     *
87
-     * @throws EE_Error
88
-     * @throws InvalidArgumentException
89
-     * @throws InvalidDataTypeException
90
-     * @throws InvalidInterfaceException
91
-     * @throws ReflectionException
92
-     */
93
-    public function lock()
94
-    {
95
-        // attempt to set lock, but if that fails...
96
-        if (! $this->add_extra_meta('lock', time(), true)) {
97
-            // then attempt to remove the lock in case it is expired
98
-            if ($this->_remove_expired_lock()) {
99
-                // if removal was successful, then try setting lock again
100
-                $this->lock();
101
-            } else {
102
-                // but if the lock can not be removed, then throw an exception
103
-                throw new EE_Error(
104
-                    sprintf(
105
-                        esc_html__(
106
-                            '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.',
107
-                            'event_espresso'
108
-                        ),
109
-                        $this->ID()
110
-                    )
111
-                );
112
-            }
113
-        }
114
-    }
115
-
116
-
117
-    /**
118
-     * removes transaction lock applied in EE_Transaction::lock()
119
-     *
120
-     * @return int
121
-     * @throws EE_Error
122
-     * @throws InvalidArgumentException
123
-     * @throws InvalidDataTypeException
124
-     * @throws InvalidInterfaceException
125
-     * @throws ReflectionException
126
-     */
127
-    public function unlock()
128
-    {
129
-        return $this->delete_extra_meta('lock');
130
-    }
131
-
132
-
133
-    /**
134
-     * Decides whether or not now is the right time to update the transaction.
135
-     * This is useful because we don't always know if it is safe to update the transaction
136
-     * and its related data. why?
137
-     * because it's possible that the transaction is being used in another
138
-     * request and could overwrite anything we save.
139
-     * So we want to only update the txn once we know that won't happen.
140
-     * We also check that the lock isn't expired, and remove it if it is
141
-     *
142
-     * @return boolean
143
-     * @throws EE_Error
144
-     * @throws InvalidArgumentException
145
-     * @throws InvalidDataTypeException
146
-     * @throws InvalidInterfaceException
147
-     * @throws ReflectionException
148
-     */
149
-    public function is_locked()
150
-    {
151
-        // if TXN is not locked, then return false immediately
152
-        if (! $this->_get_lock()) {
153
-            return false;
154
-        }
155
-        // if not, then let's try and remove the lock in case it's expired...
156
-        // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false)
157
-        // and a positive number if the lock was removed (ie: number of locks deleted),
158
-        // so we need to return the opposite
159
-        return ! $this->_remove_expired_lock() ? true : false;
160
-    }
161
-
162
-
163
-    /**
164
-     * Gets the meta field indicating that this TXN is locked
165
-     *
166
-     * @return int
167
-     * @throws EE_Error
168
-     * @throws InvalidArgumentException
169
-     * @throws InvalidDataTypeException
170
-     * @throws InvalidInterfaceException
171
-     * @throws ReflectionException
172
-     */
173
-    protected function _get_lock()
174
-    {
175
-        return (int) $this->get_extra_meta('lock', true, 0);
176
-    }
177
-
178
-
179
-    /**
180
-     * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated
181
-     *
182
-     * @return int
183
-     * @throws EE_Error
184
-     * @throws InvalidArgumentException
185
-     * @throws InvalidDataTypeException
186
-     * @throws InvalidInterfaceException
187
-     * @throws ReflectionException
188
-     */
189
-    protected function _remove_expired_lock()
190
-    {
191
-        $locked = $this->_get_lock();
192
-        if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) {
193
-            return $this->unlock();
194
-        }
195
-        return 0;
196
-    }
197
-
198
-
199
-    /**
200
-     * Set transaction total
201
-     *
202
-     * @param float $total total value of transaction
203
-     * @throws EE_Error
204
-     * @throws InvalidArgumentException
205
-     * @throws InvalidDataTypeException
206
-     * @throws InvalidInterfaceException
207
-     * @throws ReflectionException
208
-     */
209
-    public function set_total($total = 0.00)
210
-    {
211
-        $this->set('TXN_total', (float) $total);
212
-    }
213
-
214
-
215
-    /**
216
-     * Set Total Amount Paid to Date
217
-     *
218
-     * @param float $total_paid total amount paid to date (sum of all payments)
219
-     * @throws EE_Error
220
-     * @throws InvalidArgumentException
221
-     * @throws InvalidDataTypeException
222
-     * @throws InvalidInterfaceException
223
-     * @throws ReflectionException
224
-     */
225
-    public function set_paid($total_paid = 0.00)
226
-    {
227
-        $this->set('TXN_paid', (float) $total_paid);
228
-    }
229
-
230
-
231
-    /**
232
-     * Set transaction status
233
-     *
234
-     * @param string $status        whether the transaction is open, declined, accepted,
235
-     *                              or any number of custom values that can be set
236
-     * @throws EE_Error
237
-     * @throws InvalidArgumentException
238
-     * @throws InvalidDataTypeException
239
-     * @throws InvalidInterfaceException
240
-     * @throws ReflectionException
241
-     */
242
-    public function set_status($status = '')
243
-    {
244
-        $this->set('STS_ID', $status);
245
-    }
246
-
247
-
248
-    /**
249
-     * Set hash salt
250
-     *
251
-     * @param string $hash_salt required for some payment gateways
252
-     * @throws EE_Error
253
-     * @throws InvalidArgumentException
254
-     * @throws InvalidDataTypeException
255
-     * @throws InvalidInterfaceException
256
-     * @throws ReflectionException
257
-     */
258
-    public function set_hash_salt($hash_salt = '')
259
-    {
260
-        $this->set('TXN_hash_salt', $hash_salt);
261
-    }
262
-
263
-
264
-    /**
265
-     * Sets TXN_reg_steps array
266
-     *
267
-     * @param array $txn_reg_steps
268
-     * @throws EE_Error
269
-     * @throws InvalidArgumentException
270
-     * @throws InvalidDataTypeException
271
-     * @throws InvalidInterfaceException
272
-     * @throws ReflectionException
273
-     */
274
-    public function set_reg_steps(array $txn_reg_steps)
275
-    {
276
-        $this->set('TXN_reg_steps', $txn_reg_steps);
277
-    }
278
-
279
-
280
-    /**
281
-     * Gets TXN_reg_steps
282
-     *
283
-     * @return array
284
-     * @throws EE_Error
285
-     * @throws InvalidArgumentException
286
-     * @throws InvalidDataTypeException
287
-     * @throws InvalidInterfaceException
288
-     * @throws ReflectionException
289
-     */
290
-    public function reg_steps()
291
-    {
292
-        $TXN_reg_steps = $this->get('TXN_reg_steps');
293
-        return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array();
294
-    }
295
-
296
-
297
-    /**
298
-     * @return string of transaction's total cost, with currency symbol and decimal
299
-     * @throws EE_Error
300
-     * @throws InvalidArgumentException
301
-     * @throws InvalidDataTypeException
302
-     * @throws InvalidInterfaceException
303
-     * @throws ReflectionException
304
-     */
305
-    public function pretty_total()
306
-    {
307
-        return $this->get_pretty('TXN_total');
308
-    }
309
-
310
-
311
-    /**
312
-     * Gets the amount paid in a pretty string (formatted and with currency symbol)
313
-     *
314
-     * @return string
315
-     * @throws EE_Error
316
-     * @throws InvalidArgumentException
317
-     * @throws InvalidDataTypeException
318
-     * @throws InvalidInterfaceException
319
-     * @throws ReflectionException
320
-     */
321
-    public function pretty_paid()
322
-    {
323
-        return $this->get_pretty('TXN_paid');
324
-    }
325
-
326
-
327
-    /**
328
-     * calculate the amount remaining for this transaction and return;
329
-     *
330
-     * @return float amount remaining
331
-     * @throws EE_Error
332
-     * @throws InvalidArgumentException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     * @throws ReflectionException
336
-     */
337
-    public function remaining()
338
-    {
339
-        return $this->total() - $this->paid();
340
-    }
341
-
342
-
343
-    /**
344
-     * get Transaction Total
345
-     *
346
-     * @return float
347
-     * @throws EE_Error
348
-     * @throws InvalidArgumentException
349
-     * @throws InvalidDataTypeException
350
-     * @throws InvalidInterfaceException
351
-     * @throws ReflectionException
352
-     */
353
-    public function total()
354
-    {
355
-        return (float) $this->get('TXN_total');
356
-    }
357
-
358
-
359
-    /**
360
-     * get Total Amount Paid to Date
361
-     *
362
-     * @return float
363
-     * @throws EE_Error
364
-     * @throws InvalidArgumentException
365
-     * @throws InvalidDataTypeException
366
-     * @throws InvalidInterfaceException
367
-     * @throws ReflectionException
368
-     */
369
-    public function paid()
370
-    {
371
-        return (float) $this->get('TXN_paid');
372
-    }
373
-
374
-
375
-    /**
376
-     * @return mixed|null
377
-     * @throws EE_Error
378
-     * @throws InvalidArgumentException
379
-     * @throws InvalidDataTypeException
380
-     * @throws InvalidInterfaceException
381
-     * @throws ReflectionException
382
-     */
383
-    public function get_cart_session()
384
-    {
385
-        $session_data = (array) $this->get('TXN_session_data');
386
-        return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart
387
-            ? $session_data['cart']
388
-            : null;
389
-    }
390
-
391
-
392
-    /**
393
-     * get Transaction session data
394
-     *
395
-     * @return array|mixed
396
-     * @throws EE_Error
397
-     * @throws InvalidArgumentException
398
-     * @throws InvalidDataTypeException
399
-     * @throws InvalidInterfaceException
400
-     * @throws ReflectionException
401
-     */
402
-    public function session_data()
403
-    {
404
-        $session_data = $this->get('TXN_session_data');
405
-        if (empty($session_data)) {
406
-            $session_data = array(
407
-                'id'            => null,
408
-                'user_id'       => null,
409
-                'ip_address'    => null,
410
-                'user_agent'    => null,
411
-                'init_access'   => null,
412
-                'last_access'   => null,
413
-                'pages_visited' => array(),
414
-            );
415
-        }
416
-        return $session_data;
417
-    }
418
-
419
-
420
-    /**
421
-     * Set session data within the TXN object
422
-     *
423
-     * @param EE_Session|array $session_data
424
-     * @throws EE_Error
425
-     * @throws InvalidArgumentException
426
-     * @throws InvalidDataTypeException
427
-     * @throws InvalidInterfaceException
428
-     * @throws ReflectionException
429
-     */
430
-    public function set_txn_session_data($session_data)
431
-    {
432
-        if ($session_data instanceof EE_Session) {
433
-            $this->set('TXN_session_data', $session_data->get_session_data(null, true));
434
-        } else {
435
-            $this->set('TXN_session_data', $session_data);
436
-        }
437
-    }
438
-
439
-
440
-    /**
441
-     * get Transaction hash salt
442
-     *
443
-     * @return mixed
444
-     * @throws EE_Error
445
-     * @throws InvalidArgumentException
446
-     * @throws InvalidDataTypeException
447
-     * @throws InvalidInterfaceException
448
-     * @throws ReflectionException
449
-     */
450
-    public function hash_salt_()
451
-    {
452
-        return $this->get('TXN_hash_salt');
453
-    }
454
-
455
-
456
-    /**
457
-     * Returns the transaction datetime as either:
458
-     *            - unix timestamp format ($format = false, $gmt = true)
459
-     *            - formatted date string including the UTC (timezone) offset ($format = true ($gmt
460
-     *              has no affect with this option)), this also may include a timezone abbreviation if the
461
-     *              set timezone in this class differs from what the timezone is on the blog.
462
-     *            - formatted date string including the UTC (timezone) offset (default).
463
-     *
464
-     * @param boolean $format   - whether to return a unix timestamp (default) or formatted date string
465
-     * @param boolean $gmt      - whether to return a unix timestamp with UTC offset applied (default)
466
-     *                          or no UTC offset applied
467
-     * @return string | int
468
-     * @throws EE_Error
469
-     * @throws InvalidArgumentException
470
-     * @throws InvalidDataTypeException
471
-     * @throws InvalidInterfaceException
472
-     * @throws ReflectionException
473
-     */
474
-    public function datetime($format = false, $gmt = false)
475
-    {
476
-        if ($format) {
477
-            return $this->get_pretty('TXN_timestamp');
478
-        }
479
-        if ($gmt) {
480
-            return $this->get_raw('TXN_timestamp');
481
-        }
482
-        return $this->get('TXN_timestamp');
483
-    }
484
-
485
-
486
-    /**
487
-     * Gets registrations on this transaction
488
-     *
489
-     * @param array   $query_params array of query parameters
490
-     * @param boolean $get_cached   TRUE to retrieve cached registrations or FALSE to pull from the db
491
-     * @return EE_Base_Class[]|EE_Registration[]
492
-     * @throws EE_Error
493
-     * @throws InvalidArgumentException
494
-     * @throws InvalidDataTypeException
495
-     * @throws InvalidInterfaceException
496
-     * @throws ReflectionException
497
-     */
498
-    public function registrations($query_params = array(), $get_cached = false)
499
-    {
500
-        $query_params = (empty($query_params) || ! is_array($query_params))
501
-            ? array(
502
-                'order_by' => array(
503
-                    'Event.EVT_name'     => 'ASC',
504
-                    'Attendee.ATT_lname' => 'ASC',
505
-                    'Attendee.ATT_fname' => 'ASC',
506
-                ),
507
-            )
508
-            : $query_params;
509
-        $query_params = $get_cached ? array() : $query_params;
510
-        return $this->get_many_related('Registration', $query_params);
511
-    }
512
-
513
-
514
-    /**
515
-     * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event
516
-     * function for getting attendees and how many registrations they each have for an event)
517
-     *
518
-     * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT'
519
-     * @throws EE_Error
520
-     * @throws InvalidArgumentException
521
-     * @throws InvalidDataTypeException
522
-     * @throws InvalidInterfaceException
523
-     * @throws ReflectionException
524
-     */
525
-    public function attendees()
526
-    {
527
-        return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID())));
528
-    }
529
-
530
-
531
-    /**
532
-     * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default
533
-     *
534
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
535
-     * @return EE_Base_Class[]|EE_Payment[]
536
-     * @throws EE_Error
537
-     * @throws InvalidArgumentException
538
-     * @throws InvalidDataTypeException
539
-     * @throws InvalidInterfaceException
540
-     * @throws ReflectionException
541
-     */
542
-    public function payments($query_params = array())
543
-    {
544
-        return $this->get_many_related('Payment', $query_params);
545
-    }
546
-
547
-
548
-    /**
549
-     * gets only approved payments for this transaction
550
-     *
551
-     * @return EE_Base_Class[]|EE_Payment[]
552
-     * @throws EE_Error
553
-     * @throws InvalidArgumentException
554
-     * @throws ReflectionException
555
-     * @throws InvalidDataTypeException
556
-     * @throws InvalidInterfaceException
557
-     */
558
-    public function approved_payments()
559
-    {
560
-        EE_Registry::instance()->load_model('Payment');
561
-        return $this->get_many_related(
562
-            'Payment',
563
-            array(
564
-                array('STS_ID' => EEM_Payment::status_id_approved),
565
-                'order_by' => array('PAY_timestamp' => 'DESC'),
566
-            )
567
-        );
568
-    }
569
-
570
-
571
-    /**
572
-     * Gets all payments which have not been approved
573
-     *
574
-     * @return EE_Base_Class[]|EEI_Payment[]
575
-     * @throws EE_Error if a model is misconfigured somehow
576
-     * @throws InvalidArgumentException
577
-     * @throws InvalidDataTypeException
578
-     * @throws InvalidInterfaceException
579
-     * @throws ReflectionException
580
-     */
581
-    public function pending_payments()
582
-    {
583
-        return $this->get_many_related(
584
-            'Payment',
585
-            array(
586
-                array(
587
-                    'STS_ID' => EEM_Payment::status_id_pending,
588
-                ),
589
-                'order_by' => array(
590
-                    'PAY_timestamp' => 'DESC',
591
-                ),
592
-            )
593
-        );
594
-    }
595
-
596
-
597
-    /**
598
-     * echoes $this->pretty_status()
599
-     *
600
-     * @param bool $show_icons
601
-     * @throws EE_Error
602
-     * @throws InvalidArgumentException
603
-     * @throws InvalidDataTypeException
604
-     * @throws InvalidInterfaceException
605
-     * @throws ReflectionException
606
-     */
607
-    public function e_pretty_status($show_icons = false)
608
-    {
609
-        echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags());
610
-    }
611
-
612
-
613
-    /**
614
-     * returns a pretty version of the status, good for displaying to users
615
-     *
616
-     * @param bool $show_icons
617
-     * @return string
618
-     * @throws EE_Error
619
-     * @throws InvalidArgumentException
620
-     * @throws InvalidDataTypeException
621
-     * @throws InvalidInterfaceException
622
-     * @throws ReflectionException
623
-     */
624
-    public function pretty_status($show_icons = false)
625
-    {
626
-        $status = EEM_Status::instance()->localized_status(
627
-            array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
628
-            false,
629
-            'sentence'
630
-        );
631
-        $icon = '';
632
-        switch ($this->status_ID()) {
633
-            case EEM_Transaction::complete_status_code:
634
-                $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : '';
635
-                break;
636
-            case EEM_Transaction::incomplete_status_code:
637
-                $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>'
638
-                    : '';
639
-                break;
640
-            case EEM_Transaction::abandoned_status_code:
641
-                $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : '';
642
-                break;
643
-            case EEM_Transaction::failed_status_code:
644
-                $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : '';
645
-                break;
646
-            case EEM_Transaction::overpaid_status_code:
647
-                $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : '';
648
-                break;
649
-        }
650
-        return $icon . $status[ $this->status_ID() ];
651
-    }
652
-
653
-
654
-    /**
655
-     * get Transaction Status
656
-     *
657
-     * @return mixed
658
-     * @throws EE_Error
659
-     * @throws InvalidArgumentException
660
-     * @throws InvalidDataTypeException
661
-     * @throws InvalidInterfaceException
662
-     * @throws ReflectionException
663
-     */
664
-    public function status_ID()
665
-    {
666
-        return $this->get('STS_ID');
667
-    }
668
-
669
-
670
-    /**
671
-     * Returns TRUE or FALSE for whether or not this transaction cost any money
672
-     *
673
-     * @return boolean
674
-     * @throws EE_Error
675
-     * @throws InvalidArgumentException
676
-     * @throws InvalidDataTypeException
677
-     * @throws InvalidInterfaceException
678
-     * @throws ReflectionException
679
-     */
680
-    public function is_free()
681
-    {
682
-        return EEH_Money::compare_floats($this->get('TXN_total'), 0, '==');
683
-    }
684
-
685
-
686
-    /**
687
-     * Returns whether this transaction is complete
688
-     * Useful in templates and other logic for deciding if we should ask for another payment...
689
-     *
690
-     * @return boolean
691
-     * @throws EE_Error
692
-     * @throws InvalidArgumentException
693
-     * @throws InvalidDataTypeException
694
-     * @throws InvalidInterfaceException
695
-     * @throws ReflectionException
696
-     */
697
-    public function is_completed()
698
-    {
699
-        return $this->status_ID() === EEM_Transaction::complete_status_code;
700
-    }
701
-
702
-
703
-    /**
704
-     * Returns whether this transaction is incomplete
705
-     * Useful in templates and other logic for deciding if we should ask for another payment...
706
-     *
707
-     * @return boolean
708
-     * @throws EE_Error
709
-     * @throws InvalidArgumentException
710
-     * @throws InvalidDataTypeException
711
-     * @throws InvalidInterfaceException
712
-     * @throws ReflectionException
713
-     */
714
-    public function is_incomplete()
715
-    {
716
-        return $this->status_ID() === EEM_Transaction::incomplete_status_code;
717
-    }
718
-
719
-
720
-    /**
721
-     * Returns whether this transaction is overpaid
722
-     * Useful in templates and other logic for deciding if monies need to be refunded
723
-     *
724
-     * @return boolean
725
-     * @throws EE_Error
726
-     * @throws InvalidArgumentException
727
-     * @throws InvalidDataTypeException
728
-     * @throws InvalidInterfaceException
729
-     * @throws ReflectionException
730
-     */
731
-    public function is_overpaid()
732
-    {
733
-        return $this->status_ID() === EEM_Transaction::overpaid_status_code;
734
-    }
735
-
736
-
737
-    /**
738
-     * Returns whether this transaction was abandoned
739
-     * meaning that the transaction/registration process was somehow interrupted and never completed
740
-     * but that contact information exists for at least one registrant
741
-     *
742
-     * @return boolean
743
-     * @throws EE_Error
744
-     * @throws InvalidArgumentException
745
-     * @throws InvalidDataTypeException
746
-     * @throws InvalidInterfaceException
747
-     * @throws ReflectionException
748
-     */
749
-    public function is_abandoned()
750
-    {
751
-        return $this->status_ID() === EEM_Transaction::abandoned_status_code;
752
-    }
753
-
754
-
755
-    /**
756
-     * Returns whether this transaction failed
757
-     * meaning that the transaction/registration process was somehow interrupted and never completed
758
-     * and that NO contact information exists for any registrants
759
-     *
760
-     * @return boolean
761
-     * @throws EE_Error
762
-     * @throws InvalidArgumentException
763
-     * @throws InvalidDataTypeException
764
-     * @throws InvalidInterfaceException
765
-     * @throws ReflectionException
766
-     */
767
-    public function failed()
768
-    {
769
-        return $this->status_ID() === EEM_Transaction::failed_status_code;
770
-    }
771
-
772
-
773
-    /**
774
-     * This returns the url for the invoice of this transaction
775
-     *
776
-     * @param string $type 'html' or 'pdf' (default is pdf)
777
-     * @return string
778
-     * @throws DomainException
779
-     * @throws EE_Error
780
-     * @throws InvalidArgumentException
781
-     * @throws InvalidDataTypeException
782
-     * @throws InvalidInterfaceException
783
-     * @throws ReflectionException
784
-     */
785
-    public function invoice_url($type = 'html')
786
-    {
787
-        $REG = $this->primary_registration();
788
-        if (! $REG instanceof EE_Registration) {
789
-            return '';
790
-        }
791
-        return $REG->invoice_url($type);
792
-    }
793
-
794
-
795
-    /**
796
-     * Gets the primary registration only
797
-     *
798
-     * @return EE_Base_Class|EE_Registration
799
-     * @throws EE_Error
800
-     * @throws InvalidArgumentException
801
-     * @throws InvalidDataTypeException
802
-     * @throws InvalidInterfaceException
803
-     * @throws ReflectionException
804
-     */
805
-    public function primary_registration()
806
-    {
807
-        $registrations = (array) $this->get_many_related(
808
-            'Registration',
809
-            array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT))
810
-        );
811
-        foreach ($registrations as $registration) {
812
-            // valid registration that is NOT cancelled or declined ?
813
-            if (
814
-                $registration instanceof EE_Registration
815
-                && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true)
816
-            ) {
817
-                return $registration;
818
-            }
819
-        }
820
-        // nothing valid found, so just return first thing from array of results
821
-        return reset($registrations);
822
-    }
823
-
824
-
825
-    /**
826
-     * Gets the URL for viewing the receipt
827
-     *
828
-     * @param string $type 'pdf' or 'html' (default is 'html')
829
-     * @return string
830
-     * @throws DomainException
831
-     * @throws EE_Error
832
-     * @throws InvalidArgumentException
833
-     * @throws InvalidDataTypeException
834
-     * @throws InvalidInterfaceException
835
-     * @throws ReflectionException
836
-     */
837
-    public function receipt_url($type = 'html')
838
-    {
839
-        $REG = $this->primary_registration();
840
-        if (! $REG instanceof EE_Registration) {
841
-            return '';
842
-        }
843
-        return $REG->receipt_url($type);
844
-    }
845
-
846
-
847
-    /**
848
-     * Gets the URL of the thank you page with this registration REG_url_link added as
849
-     * a query parameter
850
-     *
851
-     * @return string
852
-     * @throws EE_Error
853
-     * @throws InvalidArgumentException
854
-     * @throws InvalidDataTypeException
855
-     * @throws InvalidInterfaceException
856
-     * @throws ReflectionException
857
-     */
858
-    public function payment_overview_url()
859
-    {
860
-        $primary_registration = $this->primary_registration();
861
-        return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false;
862
-    }
863
-
864
-
865
-    /**
866
-     * @return string
867
-     * @throws EE_Error
868
-     * @throws InvalidArgumentException
869
-     * @throws InvalidDataTypeException
870
-     * @throws InvalidInterfaceException
871
-     * @throws ReflectionException
872
-     */
873
-    public function gateway_response_on_transaction()
874
-    {
875
-        $payment = $this->get_first_related('Payment');
876
-        return $payment instanceof EE_Payment ? $payment->gateway_response() : '';
877
-    }
878
-
879
-
880
-    /**
881
-     * Get the status object of this object
882
-     *
883
-     * @return EE_Base_Class|EE_Status
884
-     * @throws EE_Error
885
-     * @throws InvalidArgumentException
886
-     * @throws InvalidDataTypeException
887
-     * @throws InvalidInterfaceException
888
-     * @throws ReflectionException
889
-     */
890
-    public function status_obj()
891
-    {
892
-        return $this->get_first_related('Status');
893
-    }
894
-
895
-
896
-    /**
897
-     * Gets all the extra meta info on this payment
898
-     *
899
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
900
-     * @return EE_Base_Class[]|EE_Extra_Meta
901
-     * @throws EE_Error
902
-     * @throws InvalidArgumentException
903
-     * @throws InvalidDataTypeException
904
-     * @throws InvalidInterfaceException
905
-     * @throws ReflectionException
906
-     */
907
-    public function extra_meta($query_params = array())
908
-    {
909
-        return $this->get_many_related('Extra_Meta', $query_params);
910
-    }
911
-
912
-
913
-    /**
914
-     * Wrapper for _add_relation_to
915
-     *
916
-     * @param EE_Registration $registration
917
-     * @return EE_Base_Class the relation was added to
918
-     * @throws EE_Error
919
-     * @throws InvalidArgumentException
920
-     * @throws InvalidDataTypeException
921
-     * @throws InvalidInterfaceException
922
-     * @throws ReflectionException
923
-     */
924
-    public function add_registration(EE_Registration $registration)
925
-    {
926
-        return $this->_add_relation_to($registration, 'Registration');
927
-    }
928
-
929
-
930
-    /**
931
-     * Removes the given registration from being related (even before saving this transaction).
932
-     * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations
933
-     *
934
-     * @param int $registration_or_id
935
-     * @return EE_Base_Class that was removed from being related
936
-     * @throws EE_Error
937
-     * @throws InvalidArgumentException
938
-     * @throws InvalidDataTypeException
939
-     * @throws InvalidInterfaceException
940
-     * @throws ReflectionException
941
-     */
942
-    public function remove_registration_with_id($registration_or_id)
943
-    {
944
-        return $this->_remove_relation_to($registration_or_id, 'Registration');
945
-    }
946
-
947
-
948
-    /**
949
-     * Gets all the line items which are for ACTUAL items
950
-     *
951
-     * @return EE_Line_Item[]
952
-     * @throws EE_Error
953
-     * @throws InvalidArgumentException
954
-     * @throws InvalidDataTypeException
955
-     * @throws InvalidInterfaceException
956
-     * @throws ReflectionException
957
-     */
958
-    public function items_purchased()
959
-    {
960
-        return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item)));
961
-    }
962
-
963
-
964
-    /**
965
-     * Wrapper for _add_relation_to
966
-     *
967
-     * @param EE_Line_Item $line_item
968
-     * @return EE_Base_Class the relation was added to
969
-     * @throws EE_Error
970
-     * @throws InvalidArgumentException
971
-     * @throws InvalidDataTypeException
972
-     * @throws InvalidInterfaceException
973
-     * @throws ReflectionException
974
-     */
975
-    public function add_line_item(EE_Line_Item $line_item)
976
-    {
977
-        return $this->_add_relation_to($line_item, 'Line_Item');
978
-    }
979
-
980
-
981
-    /**
982
-     * Gets ALL the line items related to this transaction (unstructured)
983
-     *
984
-     * @param array $query_params
985
-     * @return EE_Base_Class[]|EE_Line_Item[]
986
-     * @throws EE_Error
987
-     * @throws InvalidArgumentException
988
-     * @throws InvalidDataTypeException
989
-     * @throws InvalidInterfaceException
990
-     * @throws ReflectionException
991
-     */
992
-    public function line_items($query_params = array())
993
-    {
994
-        return $this->get_many_related('Line_Item', $query_params);
995
-    }
996
-
997
-
998
-    /**
999
-     * Gets all the line items which are taxes on the total
1000
-     *
1001
-     * @return EE_Line_Item[]
1002
-     * @throws EE_Error
1003
-     * @throws InvalidArgumentException
1004
-     * @throws InvalidDataTypeException
1005
-     * @throws InvalidInterfaceException
1006
-     * @throws ReflectionException
1007
-     */
1008
-    public function tax_items()
1009
-    {
1010
-        return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax)));
1011
-    }
1012
-
1013
-
1014
-    /**
1015
-     * Gets the total line item (which is a parent of all other related line items,
1016
-     * meaning it takes them all into account on its total)
1017
-     *
1018
-     * @param bool $create_if_not_found
1019
-     * @return \EE_Line_Item
1020
-     * @throws EE_Error
1021
-     * @throws InvalidArgumentException
1022
-     * @throws InvalidDataTypeException
1023
-     * @throws InvalidInterfaceException
1024
-     * @throws ReflectionException
1025
-     */
1026
-    public function total_line_item($create_if_not_found = true)
1027
-    {
1028
-        $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total)));
1029
-        if (! $item && $create_if_not_found) {
1030
-            $item = EEH_Line_Item::create_total_line_item($this);
1031
-        }
1032
-        return $item;
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * Returns the total amount of tax on this transaction
1038
-     * (assumes there's only one tax subtotal line item)
1039
-     *
1040
-     * @return float
1041
-     * @throws EE_Error
1042
-     * @throws InvalidArgumentException
1043
-     * @throws InvalidDataTypeException
1044
-     * @throws InvalidInterfaceException
1045
-     * @throws ReflectionException
1046
-     */
1047
-    public function tax_total()
1048
-    {
1049
-        $tax_line_item = $this->tax_total_line_item();
1050
-        if ($tax_line_item) {
1051
-            return (float) $tax_line_item->total();
1052
-        }
1053
-        return (float) 0;
1054
-    }
1055
-
1056
-
1057
-    /**
1058
-     * Gets the tax subtotal line item (assumes there's only one)
1059
-     *
1060
-     * @return EE_Line_Item
1061
-     * @throws EE_Error
1062
-     * @throws InvalidArgumentException
1063
-     * @throws InvalidDataTypeException
1064
-     * @throws InvalidInterfaceException
1065
-     * @throws ReflectionException
1066
-     */
1067
-    public function tax_total_line_item()
1068
-    {
1069
-        return EEH_Line_Item::get_taxes_subtotal($this->total_line_item());
1070
-    }
1071
-
1072
-
1073
-    /**
1074
-     * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee.
1075
-     *
1076
-     * @return EE_Form_Section_Proper
1077
-     * @throws EE_Error
1078
-     * @throws InvalidArgumentException
1079
-     * @throws InvalidDataTypeException
1080
-     * @throws InvalidInterfaceException
1081
-     * @throws ReflectionException
1082
-     */
1083
-    public function billing_info()
1084
-    {
1085
-        $payment_method = $this->payment_method();
1086
-        if (! $payment_method) {
1087
-            EE_Error::add_error(
1088
-                esc_html__(
1089
-                    'Could not find billing info for transaction because no gateway has been used for it yet',
1090
-                    'event_espresso'
1091
-                ),
1092
-                __FILE__,
1093
-                __FUNCTION__,
1094
-                __LINE__
1095
-            );
1096
-            return null;
1097
-        }
1098
-        $primary_reg = $this->primary_registration();
1099
-        if (! $primary_reg) {
1100
-            EE_Error::add_error(
1101
-                esc_html__(
1102
-                    'Cannot get billing info for gateway %s on transaction because no primary registration exists',
1103
-                    'event_espresso'
1104
-                ),
1105
-                __FILE__,
1106
-                __FUNCTION__,
1107
-                __LINE__
1108
-            );
1109
-            return null;
1110
-        }
1111
-        $attendee = $primary_reg->attendee();
1112
-        if (! $attendee) {
1113
-            EE_Error::add_error(
1114
-                esc_html__(
1115
-                    'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists',
1116
-                    'event_espresso'
1117
-                ),
1118
-                __FILE__,
1119
-                __FUNCTION__,
1120
-                __LINE__
1121
-            );
1122
-            return null;
1123
-        }
1124
-        return $attendee->billing_info_for_payment_method($payment_method);
1125
-    }
1126
-
1127
-
1128
-    /**
1129
-     * Gets PMD_ID
1130
-     *
1131
-     * @return int
1132
-     * @throws EE_Error
1133
-     * @throws InvalidArgumentException
1134
-     * @throws InvalidDataTypeException
1135
-     * @throws InvalidInterfaceException
1136
-     * @throws ReflectionException
1137
-     */
1138
-    public function payment_method_ID()
1139
-    {
1140
-        return $this->get('PMD_ID');
1141
-    }
1142
-
1143
-
1144
-    /**
1145
-     * Sets PMD_ID
1146
-     *
1147
-     * @param int $PMD_ID
1148
-     * @throws EE_Error
1149
-     * @throws InvalidArgumentException
1150
-     * @throws InvalidDataTypeException
1151
-     * @throws InvalidInterfaceException
1152
-     * @throws ReflectionException
1153
-     */
1154
-    public function set_payment_method_ID($PMD_ID)
1155
-    {
1156
-        $this->set('PMD_ID', $PMD_ID);
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * Gets the last-used payment method on this transaction
1162
-     * (we COULD just use the last-made payment, but some payment methods, namely
1163
-     * offline ones, dont' create payments)
1164
-     *
1165
-     * @return EE_Payment_Method
1166
-     * @throws EE_Error
1167
-     * @throws InvalidArgumentException
1168
-     * @throws InvalidDataTypeException
1169
-     * @throws InvalidInterfaceException
1170
-     * @throws ReflectionException
1171
-     */
1172
-    public function payment_method()
1173
-    {
1174
-        $pm = $this->get_first_related('Payment_Method');
1175
-        if ($pm instanceof EE_Payment_Method) {
1176
-            return $pm;
1177
-        }
1178
-        $last_payment = $this->last_payment();
1179
-        if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) {
1180
-            return $last_payment->payment_method();
1181
-        }
1182
-        return null;
1183
-    }
1184
-
1185
-
1186
-    /**
1187
-     * Gets the last payment made
1188
-     *
1189
-     * @return EE_Base_Class|EE_Payment
1190
-     * @throws EE_Error
1191
-     * @throws InvalidArgumentException
1192
-     * @throws InvalidDataTypeException
1193
-     * @throws InvalidInterfaceException
1194
-     * @throws ReflectionException
1195
-     */
1196
-    public function last_payment()
1197
-    {
1198
-        return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc')));
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * Gets all the line items which are unrelated to tickets on this transaction
1204
-     *
1205
-     * @return EE_Line_Item[]
1206
-     * @throws EE_Error
1207
-     * @throws InvalidArgumentException
1208
-     * @throws InvalidDataTypeException
1209
-     * @throws InvalidInterfaceException
1210
-     * @throws ReflectionException
1211
-     */
1212
-    public function non_ticket_line_items()
1213
-    {
1214
-        return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID());
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * possibly toggles TXN status
1220
-     *
1221
-     * @param  boolean $update whether to save the TXN
1222
-     * @return bool whether the TXN was saved
1223
-     * @throws EE_Error
1224
-     * @throws InvalidArgumentException
1225
-     * @throws InvalidDataTypeException
1226
-     * @throws InvalidInterfaceException
1227
-     * @throws ReflectionException
1228
-     * @throws RuntimeException
1229
-     */
1230
-    public function update_status_based_on_total_paid($update = true)
1231
-    {
1232
-        // set transaction status based on comparison of TXN_paid vs TXN_total
1233
-        if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) {
1234
-            $new_txn_status = EEM_Transaction::overpaid_status_code;
1235
-        } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) {
1236
-            $new_txn_status = EEM_Transaction::complete_status_code;
1237
-        } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) {
1238
-            $new_txn_status = EEM_Transaction::incomplete_status_code;
1239
-        } else {
1240
-            throw new RuntimeException(
1241
-                esc_html__('The total paid calculation for this transaction is inaccurate.', 'event_espresso')
1242
-            );
1243
-        }
1244
-        if ($new_txn_status !== $this->status_ID()) {
1245
-            $this->set_status($new_txn_status);
1246
-            if ($update) {
1247
-                return $this->save() ? true : false;
1248
-            }
1249
-        }
1250
-        return false;
1251
-    }
1252
-
1253
-
1254
-    /**
1255
-     * Updates the transaction's status and total_paid based on all the payments
1256
-     * that apply to it
1257
-     *
1258
-     * @deprecated
1259
-     * @return array|bool
1260
-     * @throws EE_Error
1261
-     * @throws InvalidArgumentException
1262
-     * @throws ReflectionException
1263
-     * @throws InvalidDataTypeException
1264
-     * @throws InvalidInterfaceException
1265
-     */
1266
-    public function update_based_on_payments()
1267
-    {
1268
-        EE_Error::doing_it_wrong(
1269
-            __CLASS__ . '::' . __FUNCTION__,
1270
-            sprintf(
1271
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
1272
-                'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'
1273
-            ),
1274
-            '4.6.0'
1275
-        );
1276
-        /** @type EE_Transaction_Processor $transaction_processor */
1277
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1278
-        return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this);
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     * @return string
1284
-     */
1285
-    public function old_txn_status()
1286
-    {
1287
-        return $this->_old_txn_status;
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * @param string $old_txn_status
1293
-     */
1294
-    public function set_old_txn_status($old_txn_status)
1295
-    {
1296
-        // only set the first time
1297
-        if ($this->_old_txn_status === null) {
1298
-            $this->_old_txn_status = $old_txn_status;
1299
-        }
1300
-    }
1301
-
1302
-
1303
-    /**
1304
-     * reg_status_updated
1305
-     *
1306
-     * @return bool
1307
-     * @throws EE_Error
1308
-     * @throws InvalidArgumentException
1309
-     * @throws InvalidDataTypeException
1310
-     * @throws InvalidInterfaceException
1311
-     * @throws ReflectionException
1312
-     */
1313
-    public function txn_status_updated()
1314
-    {
1315
-        return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null;
1316
-    }
1317
-
1318
-
1319
-    /**
1320
-     * _reg_steps_completed
1321
-     * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed,
1322
-     * if a $reg_step_slug is provided, then this step will be skipped when testing for completion
1323
-     * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion
1324
-     *
1325
-     * @param string $reg_step_slug
1326
-     * @param bool   $check_all
1327
-     * @return bool|int
1328
-     * @throws EE_Error
1329
-     * @throws InvalidArgumentException
1330
-     * @throws InvalidDataTypeException
1331
-     * @throws InvalidInterfaceException
1332
-     * @throws ReflectionException
1333
-     */
1334
-    private function _reg_steps_completed($reg_step_slug = '', $check_all = true)
1335
-    {
1336
-        $reg_steps = $this->reg_steps();
1337
-        if (! is_array($reg_steps) || empty($reg_steps)) {
1338
-            return false;
1339
-        }
1340
-        // loop thru reg steps array)
1341
-        foreach ($reg_steps as $slug => $reg_step_completed) {
1342
-            // if NOT checking ALL steps (only checking one step)
1343
-            if (! $check_all) {
1344
-                // and this is the one
1345
-                if ($slug === $reg_step_slug) {
1346
-                    return $reg_step_completed;
1347
-                }
1348
-                // skip to next reg step in loop
1349
-                continue;
1350
-            }
1351
-            // $check_all must be true, else we would never have gotten to this point
1352
-            if ($slug === $reg_step_slug) {
1353
-                // if we reach this point, then we are testing either:
1354
-                // all_reg_steps_completed_except() or
1355
-                // all_reg_steps_completed_except_final_step(),
1356
-                // and since this is the reg step EXCEPTION being tested
1357
-                // we want to return true (yes true) if this reg step is NOT completed
1358
-                // ie: "is everything completed except the final step?"
1359
-                // "that is correct... the final step is not completed, but all others are."
1360
-                return $reg_step_completed !== true;
1361
-            }
1362
-            if ($reg_step_completed !== true) {
1363
-                // if any reg step is NOT completed, then ALL steps are not completed
1364
-                return false;
1365
-            }
1366
-        }
1367
-        return true;
1368
-    }
1369
-
1370
-
1371
-    /**
1372
-     * all_reg_steps_completed
1373
-     * returns:
1374
-     *    true if ALL reg steps have been marked as completed
1375
-     *        or false if any step is not completed
1376
-     *
1377
-     * @return bool
1378
-     * @throws EE_Error
1379
-     * @throws InvalidArgumentException
1380
-     * @throws InvalidDataTypeException
1381
-     * @throws InvalidInterfaceException
1382
-     * @throws ReflectionException
1383
-     */
1384
-    public function all_reg_steps_completed()
1385
-    {
1386
-        return $this->_reg_steps_completed();
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     * all_reg_steps_completed_except
1392
-     * returns:
1393
-     *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
1394
-     *        or false if any other step is not completed
1395
-     *        or false if ALL steps are completed including the exception you are testing !!!
1396
-     *
1397
-     * @param string $exception
1398
-     * @return bool
1399
-     * @throws EE_Error
1400
-     * @throws InvalidArgumentException
1401
-     * @throws InvalidDataTypeException
1402
-     * @throws InvalidInterfaceException
1403
-     * @throws ReflectionException
1404
-     */
1405
-    public function all_reg_steps_completed_except($exception = '')
1406
-    {
1407
-        return $this->_reg_steps_completed($exception);
1408
-    }
1409
-
1410
-
1411
-    /**
1412
-     * all_reg_steps_completed_except
1413
-     * returns:
1414
-     *        true if ALL reg steps, except the final step, have been marked as completed
1415
-     *        or false if any step is not completed
1416
-     *    or false if ALL steps are completed including the final step !!!
1417
-     *
1418
-     * @return bool
1419
-     * @throws EE_Error
1420
-     * @throws InvalidArgumentException
1421
-     * @throws InvalidDataTypeException
1422
-     * @throws InvalidInterfaceException
1423
-     * @throws ReflectionException
1424
-     */
1425
-    public function all_reg_steps_completed_except_final_step()
1426
-    {
1427
-        return $this->_reg_steps_completed('finalize_registration');
1428
-    }
1429
-
1430
-
1431
-    /**
1432
-     * reg_step_completed
1433
-     * returns:
1434
-     *    true if a specific reg step has been marked as completed
1435
-     *    a Unix timestamp if it has been initialized but not yet completed,
1436
-     *    or false if it has not yet been initialized
1437
-     *
1438
-     * @param string $reg_step_slug
1439
-     * @return bool|int
1440
-     * @throws EE_Error
1441
-     * @throws InvalidArgumentException
1442
-     * @throws InvalidDataTypeException
1443
-     * @throws InvalidInterfaceException
1444
-     * @throws ReflectionException
1445
-     */
1446
-    public function reg_step_completed($reg_step_slug)
1447
-    {
1448
-        return $this->_reg_steps_completed($reg_step_slug, false);
1449
-    }
1450
-
1451
-
1452
-    /**
1453
-     * completed_final_reg_step
1454
-     * returns:
1455
-     *    true if the finalize_registration reg step has been marked as completed
1456
-     *    a Unix timestamp if it has been initialized but not yet completed,
1457
-     *    or false if it has not yet been initialized
1458
-     *
1459
-     * @return bool|int
1460
-     * @throws EE_Error
1461
-     * @throws InvalidArgumentException
1462
-     * @throws InvalidDataTypeException
1463
-     * @throws InvalidInterfaceException
1464
-     * @throws ReflectionException
1465
-     */
1466
-    public function final_reg_step_completed()
1467
-    {
1468
-        return $this->_reg_steps_completed('finalize_registration', false);
1469
-    }
1470
-
1471
-
1472
-    /**
1473
-     * set_reg_step_initiated
1474
-     * given a valid TXN_reg_step, this sets it's value to a unix timestamp
1475
-     *
1476
-     * @param string $reg_step_slug
1477
-     * @return boolean
1478
-     * @throws EE_Error
1479
-     * @throws InvalidArgumentException
1480
-     * @throws InvalidDataTypeException
1481
-     * @throws InvalidInterfaceException
1482
-     * @throws ReflectionException
1483
-     */
1484
-    public function set_reg_step_initiated($reg_step_slug)
1485
-    {
1486
-        return $this->_set_reg_step_completed_status($reg_step_slug, time());
1487
-    }
1488
-
1489
-
1490
-    /**
1491
-     * set_reg_step_completed
1492
-     * given a valid TXN_reg_step, this sets the step as completed
1493
-     *
1494
-     * @param string $reg_step_slug
1495
-     * @return boolean
1496
-     * @throws EE_Error
1497
-     * @throws InvalidArgumentException
1498
-     * @throws InvalidDataTypeException
1499
-     * @throws InvalidInterfaceException
1500
-     * @throws ReflectionException
1501
-     */
1502
-    public function set_reg_step_completed($reg_step_slug)
1503
-    {
1504
-        return $this->_set_reg_step_completed_status($reg_step_slug, true);
1505
-    }
1506
-
1507
-
1508
-    /**
1509
-     * set_reg_step_completed
1510
-     * given a valid TXN_reg_step slug, this sets the step as NOT completed
1511
-     *
1512
-     * @param string $reg_step_slug
1513
-     * @return boolean
1514
-     * @throws EE_Error
1515
-     * @throws InvalidArgumentException
1516
-     * @throws InvalidDataTypeException
1517
-     * @throws InvalidInterfaceException
1518
-     * @throws ReflectionException
1519
-     */
1520
-    public function set_reg_step_not_completed($reg_step_slug)
1521
-    {
1522
-        return $this->_set_reg_step_completed_status($reg_step_slug, false);
1523
-    }
1524
-
1525
-
1526
-    /**
1527
-     * set_reg_step_completed
1528
-     * given a valid reg step slug, this sets the TXN_reg_step completed status which is either:
1529
-     *
1530
-     * @param  string      $reg_step_slug
1531
-     * @param  boolean|int $status
1532
-     * @return boolean
1533
-     * @throws EE_Error
1534
-     * @throws InvalidArgumentException
1535
-     * @throws InvalidDataTypeException
1536
-     * @throws InvalidInterfaceException
1537
-     * @throws ReflectionException
1538
-     */
1539
-    private function _set_reg_step_completed_status($reg_step_slug, $status)
1540
-    {
1541
-        // validate status
1542
-        $status = is_bool($status) || is_int($status) ? $status : false;
1543
-        // get reg steps array
1544
-        $txn_reg_steps = $this->reg_steps();
1545
-        // if reg step does NOT exist
1546
-        if (! isset($txn_reg_steps[ $reg_step_slug ])) {
1547
-            return false;
1548
-        }
1549
-        // if  we're trying to complete a step that is already completed
1550
-        if ($txn_reg_steps[ $reg_step_slug ] === true) {
1551
-            return true;
1552
-        }
1553
-        // if  we're trying to complete a step that hasn't even started
1554
-        if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) {
1555
-            return false;
1556
-        }
1557
-        // if current status value matches the incoming value (no change)
1558
-        // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890
1559
-        if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) {
1560
-            // this will happen in cases where multiple AJAX requests occur during the same step
1561
-            return true;
1562
-        }
1563
-        // if we're trying to set a start time, but it has already been set...
1564
-        if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) {
1565
-            // skip the update below, but don't return FALSE so that errors won't be displayed
1566
-            return true;
1567
-        }
1568
-        // update completed status
1569
-        $txn_reg_steps[ $reg_step_slug ] = $status;
1570
-        $this->set_reg_steps($txn_reg_steps);
1571
-        $this->save();
1572
-        return true;
1573
-    }
1574
-
1575
-
1576
-    /**
1577
-     * remove_reg_step
1578
-     * given a valid TXN_reg_step slug, this will remove (unset)
1579
-     * the reg step from the TXN reg step array
1580
-     *
1581
-     * @param string $reg_step_slug
1582
-     * @return void
1583
-     * @throws EE_Error
1584
-     * @throws InvalidArgumentException
1585
-     * @throws InvalidDataTypeException
1586
-     * @throws InvalidInterfaceException
1587
-     * @throws ReflectionException
1588
-     */
1589
-    public function remove_reg_step($reg_step_slug)
1590
-    {
1591
-        // get reg steps array
1592
-        $txn_reg_steps = $this->reg_steps();
1593
-        unset($txn_reg_steps[ $reg_step_slug ]);
1594
-        $this->set_reg_steps($txn_reg_steps);
1595
-    }
1596
-
1597
-
1598
-    /**
1599
-     * toggle_failed_transaction_status
1600
-     * upgrades a TXNs status from failed to abandoned,
1601
-     * meaning that contact information has been captured for at least one registrant
1602
-     *
1603
-     * @param bool $save
1604
-     * @return bool
1605
-     * @throws EE_Error
1606
-     * @throws InvalidArgumentException
1607
-     * @throws InvalidDataTypeException
1608
-     * @throws InvalidInterfaceException
1609
-     * @throws ReflectionException
1610
-     */
1611
-    public function toggle_failed_transaction_status($save = true)
1612
-    {
1613
-        // if TXN status is still set as "failed"...
1614
-        if ($this->status_ID() === EEM_Transaction::failed_status_code) {
1615
-            $this->set_status(EEM_Transaction::abandoned_status_code);
1616
-            if ($save) {
1617
-                $this->save();
1618
-            }
1619
-            return true;
1620
-        }
1621
-        return false;
1622
-    }
1623
-
1624
-
1625
-    /**
1626
-     * toggle_abandoned_transaction_status
1627
-     * upgrades a TXNs status from failed or abandoned to incomplete
1628
-     *
1629
-     * @return bool
1630
-     * @throws EE_Error
1631
-     * @throws InvalidArgumentException
1632
-     * @throws InvalidDataTypeException
1633
-     * @throws InvalidInterfaceException
1634
-     * @throws ReflectionException
1635
-     */
1636
-    public function toggle_abandoned_transaction_status()
1637
-    {
1638
-        // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"...
1639
-        $txn_status = $this->status_ID();
1640
-        if (
1641
-            $txn_status === EEM_Transaction::failed_status_code
1642
-            || $txn_status === EEM_Transaction::abandoned_status_code
1643
-        ) {
1644
-            // if a contact record for the primary registrant has been created
1645
-            if (
1646
-                $this->primary_registration() instanceof EE_Registration
1647
-                && $this->primary_registration()->attendee() instanceof EE_Attendee
1648
-            ) {
1649
-                $this->set_status(EEM_Transaction::incomplete_status_code);
1650
-            } else {
1651
-                // no contact record? yer abandoned!
1652
-                $this->set_status(EEM_Transaction::abandoned_status_code);
1653
-            }
1654
-            return true;
1655
-        }
1656
-        return false;
1657
-    }
1658
-
1659
-
1660
-    /**
1661
-     * checks if an Abandoned TXN has any related payments, and if so,
1662
-     * updates the TXN status based on the amount paid
1663
-     *
1664
-     * @throws EE_Error
1665
-     * @throws InvalidArgumentException
1666
-     * @throws InvalidDataTypeException
1667
-     * @throws InvalidInterfaceException
1668
-     * @throws ReflectionException
1669
-     * @throws RuntimeException
1670
-     * @throws ReflectionException
1671
-     */
1672
-    public function verify_abandoned_transaction_status()
1673
-    {
1674
-        if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) {
1675
-            return;
1676
-        }
1677
-        $payments = $this->get_many_related('Payment');
1678
-        if (! empty($payments)) {
1679
-            foreach ($payments as $payment) {
1680
-                if ($payment instanceof EE_Payment) {
1681
-                    // kk this TXN should NOT be abandoned
1682
-                    $this->update_status_based_on_total_paid();
1683
-                    if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1684
-                        EE_Error::add_attention(
1685
-                            sprintf(
1686
-                                esc_html__(
1687
-                                    '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.',
1688
-                                    'event_espresso'
1689
-                                ),
1690
-                                $this->ID(),
1691
-                                $this->pretty_status()
1692
-                            )
1693
-                        );
1694
-                    }
1695
-                    // get final reg step status
1696
-                    $finalized = $this->final_reg_step_completed();
1697
-                    // if the 'finalize_registration' step has been initiated (has a timestamp)
1698
-                    // but has not yet been fully completed (TRUE)
1699
-                    if (is_int($finalized) && $finalized !== false && $finalized !== true) {
1700
-                        $this->set_reg_step_completed('finalize_registration');
1701
-                        $this->save();
1702
-                    }
1703
-                }
1704
-            }
1705
-        }
1706
-    }
1707
-
1708
-
1709
-    /**
1710
-     * @since 4.10.4.p
1711
-     * @throws EE_Error
1712
-     * @throws InvalidArgumentException
1713
-     * @throws InvalidDataTypeException
1714
-     * @throws InvalidInterfaceException
1715
-     * @throws ReflectionException
1716
-     * @throws RuntimeException
1717
-     */
1718
-    public function recalculateLineItems()
1719
-    {
1720
-        $total_line_item = $this->total_line_item(false);
1721
-        if ($total_line_item instanceof EE_Line_Item) {
1722
-            EEH_Line_Item::resetIsTaxableForTickets($total_line_item);
1723
-            return EEH_Line_Item::apply_taxes($total_line_item, true);
1724
-        }
1725
-        return false;
1726
-	}
1727
-
1728
-
1729
-    /**
1730
-     * @param string $source function name that called this method
1731
-     * @return boolean | int
1732
-     */
1733
-    public function delete($source = 'unknown')
1734
-    {
1735
-        $current_user = wp_get_current_user();
1736
-        $this->add_extra_meta(
1737
-            EE_Transaction::EXTRA_META_KEY_TXN_DELETED,
1738
-            array(
1739
-                'deleted-by' => $current_user->ID ? $current_user->display_name : 'unauthed user',
1740
-                'timestamp'  => time(),
1741
-                'source'     => $source,
1742
-            )
1743
-        );
1744
-        return parent::delete();
1745
-    }
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
+	 * extra meta key for tracking when transactions are deleted and by who
24
+	 *
25
+	 * @type string
26
+	 */
27
+	const EXTRA_META_KEY_TXN_DELETED = 'transaction-deleted';
28
+
29
+	/**
30
+	 * txn status upon initial construction.
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $_old_txn_status;
35
+
36
+
37
+	/**
38
+	 * @param array  $props_n_values          incoming values
39
+	 * @param string $timezone                incoming timezone
40
+	 *                                        (if not set the timezone set for the website will be used.)
41
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
42
+	 *                                        date_format and the second value is the time format
43
+	 * @return EE_Transaction
44
+	 * @throws EE_Error
45
+	 * @throws InvalidArgumentException
46
+	 * @throws InvalidDataTypeException
47
+	 * @throws InvalidInterfaceException
48
+	 * @throws ReflectionException
49
+	 */
50
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
51
+	{
52
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
53
+		$txn = $has_object
54
+			? $has_object
55
+			: new self($props_n_values, false, $timezone, $date_formats);
56
+		if (! $has_object) {
57
+			$txn->set_old_txn_status($txn->status_ID());
58
+		}
59
+		return $txn;
60
+	}
61
+
62
+
63
+	/**
64
+	 * @param array  $props_n_values  incoming values from the database
65
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
66
+	 *                                the website will be used.
67
+	 * @return EE_Transaction
68
+	 * @throws EE_Error
69
+	 * @throws InvalidArgumentException
70
+	 * @throws InvalidDataTypeException
71
+	 * @throws InvalidInterfaceException
72
+	 * @throws ReflectionException
73
+	 */
74
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
75
+	{
76
+		$txn = new self($props_n_values, true, $timezone);
77
+		$txn->set_old_txn_status($txn->status_ID());
78
+		return $txn;
79
+	}
80
+
81
+
82
+	/**
83
+	 * Sets a meta field indicating that this TXN is locked and should not be updated in the db.
84
+	 * If a lock has already been set, then we will attempt to remove it in case it has expired.
85
+	 * If that also fails, then an exception is thrown.
86
+	 *
87
+	 * @throws EE_Error
88
+	 * @throws InvalidArgumentException
89
+	 * @throws InvalidDataTypeException
90
+	 * @throws InvalidInterfaceException
91
+	 * @throws ReflectionException
92
+	 */
93
+	public function lock()
94
+	{
95
+		// attempt to set lock, but if that fails...
96
+		if (! $this->add_extra_meta('lock', time(), true)) {
97
+			// then attempt to remove the lock in case it is expired
98
+			if ($this->_remove_expired_lock()) {
99
+				// if removal was successful, then try setting lock again
100
+				$this->lock();
101
+			} else {
102
+				// but if the lock can not be removed, then throw an exception
103
+				throw new EE_Error(
104
+					sprintf(
105
+						esc_html__(
106
+							'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.',
107
+							'event_espresso'
108
+						),
109
+						$this->ID()
110
+					)
111
+				);
112
+			}
113
+		}
114
+	}
115
+
116
+
117
+	/**
118
+	 * removes transaction lock applied in EE_Transaction::lock()
119
+	 *
120
+	 * @return int
121
+	 * @throws EE_Error
122
+	 * @throws InvalidArgumentException
123
+	 * @throws InvalidDataTypeException
124
+	 * @throws InvalidInterfaceException
125
+	 * @throws ReflectionException
126
+	 */
127
+	public function unlock()
128
+	{
129
+		return $this->delete_extra_meta('lock');
130
+	}
131
+
132
+
133
+	/**
134
+	 * Decides whether or not now is the right time to update the transaction.
135
+	 * This is useful because we don't always know if it is safe to update the transaction
136
+	 * and its related data. why?
137
+	 * because it's possible that the transaction is being used in another
138
+	 * request and could overwrite anything we save.
139
+	 * So we want to only update the txn once we know that won't happen.
140
+	 * We also check that the lock isn't expired, and remove it if it is
141
+	 *
142
+	 * @return boolean
143
+	 * @throws EE_Error
144
+	 * @throws InvalidArgumentException
145
+	 * @throws InvalidDataTypeException
146
+	 * @throws InvalidInterfaceException
147
+	 * @throws ReflectionException
148
+	 */
149
+	public function is_locked()
150
+	{
151
+		// if TXN is not locked, then return false immediately
152
+		if (! $this->_get_lock()) {
153
+			return false;
154
+		}
155
+		// if not, then let's try and remove the lock in case it's expired...
156
+		// _remove_expired_lock() returns 0 when lock is valid (ie: removed = false)
157
+		// and a positive number if the lock was removed (ie: number of locks deleted),
158
+		// so we need to return the opposite
159
+		return ! $this->_remove_expired_lock() ? true : false;
160
+	}
161
+
162
+
163
+	/**
164
+	 * Gets the meta field indicating that this TXN is locked
165
+	 *
166
+	 * @return int
167
+	 * @throws EE_Error
168
+	 * @throws InvalidArgumentException
169
+	 * @throws InvalidDataTypeException
170
+	 * @throws InvalidInterfaceException
171
+	 * @throws ReflectionException
172
+	 */
173
+	protected function _get_lock()
174
+	{
175
+		return (int) $this->get_extra_meta('lock', true, 0);
176
+	}
177
+
178
+
179
+	/**
180
+	 * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated
181
+	 *
182
+	 * @return int
183
+	 * @throws EE_Error
184
+	 * @throws InvalidArgumentException
185
+	 * @throws InvalidDataTypeException
186
+	 * @throws InvalidInterfaceException
187
+	 * @throws ReflectionException
188
+	 */
189
+	protected function _remove_expired_lock()
190
+	{
191
+		$locked = $this->_get_lock();
192
+		if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) {
193
+			return $this->unlock();
194
+		}
195
+		return 0;
196
+	}
197
+
198
+
199
+	/**
200
+	 * Set transaction total
201
+	 *
202
+	 * @param float $total total value of transaction
203
+	 * @throws EE_Error
204
+	 * @throws InvalidArgumentException
205
+	 * @throws InvalidDataTypeException
206
+	 * @throws InvalidInterfaceException
207
+	 * @throws ReflectionException
208
+	 */
209
+	public function set_total($total = 0.00)
210
+	{
211
+		$this->set('TXN_total', (float) $total);
212
+	}
213
+
214
+
215
+	/**
216
+	 * Set Total Amount Paid to Date
217
+	 *
218
+	 * @param float $total_paid total amount paid to date (sum of all payments)
219
+	 * @throws EE_Error
220
+	 * @throws InvalidArgumentException
221
+	 * @throws InvalidDataTypeException
222
+	 * @throws InvalidInterfaceException
223
+	 * @throws ReflectionException
224
+	 */
225
+	public function set_paid($total_paid = 0.00)
226
+	{
227
+		$this->set('TXN_paid', (float) $total_paid);
228
+	}
229
+
230
+
231
+	/**
232
+	 * Set transaction status
233
+	 *
234
+	 * @param string $status        whether the transaction is open, declined, accepted,
235
+	 *                              or any number of custom values that can be set
236
+	 * @throws EE_Error
237
+	 * @throws InvalidArgumentException
238
+	 * @throws InvalidDataTypeException
239
+	 * @throws InvalidInterfaceException
240
+	 * @throws ReflectionException
241
+	 */
242
+	public function set_status($status = '')
243
+	{
244
+		$this->set('STS_ID', $status);
245
+	}
246
+
247
+
248
+	/**
249
+	 * Set hash salt
250
+	 *
251
+	 * @param string $hash_salt required for some payment gateways
252
+	 * @throws EE_Error
253
+	 * @throws InvalidArgumentException
254
+	 * @throws InvalidDataTypeException
255
+	 * @throws InvalidInterfaceException
256
+	 * @throws ReflectionException
257
+	 */
258
+	public function set_hash_salt($hash_salt = '')
259
+	{
260
+		$this->set('TXN_hash_salt', $hash_salt);
261
+	}
262
+
263
+
264
+	/**
265
+	 * Sets TXN_reg_steps array
266
+	 *
267
+	 * @param array $txn_reg_steps
268
+	 * @throws EE_Error
269
+	 * @throws InvalidArgumentException
270
+	 * @throws InvalidDataTypeException
271
+	 * @throws InvalidInterfaceException
272
+	 * @throws ReflectionException
273
+	 */
274
+	public function set_reg_steps(array $txn_reg_steps)
275
+	{
276
+		$this->set('TXN_reg_steps', $txn_reg_steps);
277
+	}
278
+
279
+
280
+	/**
281
+	 * Gets TXN_reg_steps
282
+	 *
283
+	 * @return array
284
+	 * @throws EE_Error
285
+	 * @throws InvalidArgumentException
286
+	 * @throws InvalidDataTypeException
287
+	 * @throws InvalidInterfaceException
288
+	 * @throws ReflectionException
289
+	 */
290
+	public function reg_steps()
291
+	{
292
+		$TXN_reg_steps = $this->get('TXN_reg_steps');
293
+		return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array();
294
+	}
295
+
296
+
297
+	/**
298
+	 * @return string of transaction's total cost, with currency symbol and decimal
299
+	 * @throws EE_Error
300
+	 * @throws InvalidArgumentException
301
+	 * @throws InvalidDataTypeException
302
+	 * @throws InvalidInterfaceException
303
+	 * @throws ReflectionException
304
+	 */
305
+	public function pretty_total()
306
+	{
307
+		return $this->get_pretty('TXN_total');
308
+	}
309
+
310
+
311
+	/**
312
+	 * Gets the amount paid in a pretty string (formatted and with currency symbol)
313
+	 *
314
+	 * @return string
315
+	 * @throws EE_Error
316
+	 * @throws InvalidArgumentException
317
+	 * @throws InvalidDataTypeException
318
+	 * @throws InvalidInterfaceException
319
+	 * @throws ReflectionException
320
+	 */
321
+	public function pretty_paid()
322
+	{
323
+		return $this->get_pretty('TXN_paid');
324
+	}
325
+
326
+
327
+	/**
328
+	 * calculate the amount remaining for this transaction and return;
329
+	 *
330
+	 * @return float amount remaining
331
+	 * @throws EE_Error
332
+	 * @throws InvalidArgumentException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 * @throws ReflectionException
336
+	 */
337
+	public function remaining()
338
+	{
339
+		return $this->total() - $this->paid();
340
+	}
341
+
342
+
343
+	/**
344
+	 * get Transaction Total
345
+	 *
346
+	 * @return float
347
+	 * @throws EE_Error
348
+	 * @throws InvalidArgumentException
349
+	 * @throws InvalidDataTypeException
350
+	 * @throws InvalidInterfaceException
351
+	 * @throws ReflectionException
352
+	 */
353
+	public function total()
354
+	{
355
+		return (float) $this->get('TXN_total');
356
+	}
357
+
358
+
359
+	/**
360
+	 * get Total Amount Paid to Date
361
+	 *
362
+	 * @return float
363
+	 * @throws EE_Error
364
+	 * @throws InvalidArgumentException
365
+	 * @throws InvalidDataTypeException
366
+	 * @throws InvalidInterfaceException
367
+	 * @throws ReflectionException
368
+	 */
369
+	public function paid()
370
+	{
371
+		return (float) $this->get('TXN_paid');
372
+	}
373
+
374
+
375
+	/**
376
+	 * @return mixed|null
377
+	 * @throws EE_Error
378
+	 * @throws InvalidArgumentException
379
+	 * @throws InvalidDataTypeException
380
+	 * @throws InvalidInterfaceException
381
+	 * @throws ReflectionException
382
+	 */
383
+	public function get_cart_session()
384
+	{
385
+		$session_data = (array) $this->get('TXN_session_data');
386
+		return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart
387
+			? $session_data['cart']
388
+			: null;
389
+	}
390
+
391
+
392
+	/**
393
+	 * get Transaction session data
394
+	 *
395
+	 * @return array|mixed
396
+	 * @throws EE_Error
397
+	 * @throws InvalidArgumentException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws InvalidInterfaceException
400
+	 * @throws ReflectionException
401
+	 */
402
+	public function session_data()
403
+	{
404
+		$session_data = $this->get('TXN_session_data');
405
+		if (empty($session_data)) {
406
+			$session_data = array(
407
+				'id'            => null,
408
+				'user_id'       => null,
409
+				'ip_address'    => null,
410
+				'user_agent'    => null,
411
+				'init_access'   => null,
412
+				'last_access'   => null,
413
+				'pages_visited' => array(),
414
+			);
415
+		}
416
+		return $session_data;
417
+	}
418
+
419
+
420
+	/**
421
+	 * Set session data within the TXN object
422
+	 *
423
+	 * @param EE_Session|array $session_data
424
+	 * @throws EE_Error
425
+	 * @throws InvalidArgumentException
426
+	 * @throws InvalidDataTypeException
427
+	 * @throws InvalidInterfaceException
428
+	 * @throws ReflectionException
429
+	 */
430
+	public function set_txn_session_data($session_data)
431
+	{
432
+		if ($session_data instanceof EE_Session) {
433
+			$this->set('TXN_session_data', $session_data->get_session_data(null, true));
434
+		} else {
435
+			$this->set('TXN_session_data', $session_data);
436
+		}
437
+	}
438
+
439
+
440
+	/**
441
+	 * get Transaction hash salt
442
+	 *
443
+	 * @return mixed
444
+	 * @throws EE_Error
445
+	 * @throws InvalidArgumentException
446
+	 * @throws InvalidDataTypeException
447
+	 * @throws InvalidInterfaceException
448
+	 * @throws ReflectionException
449
+	 */
450
+	public function hash_salt_()
451
+	{
452
+		return $this->get('TXN_hash_salt');
453
+	}
454
+
455
+
456
+	/**
457
+	 * Returns the transaction datetime as either:
458
+	 *            - unix timestamp format ($format = false, $gmt = true)
459
+	 *            - formatted date string including the UTC (timezone) offset ($format = true ($gmt
460
+	 *              has no affect with this option)), this also may include a timezone abbreviation if the
461
+	 *              set timezone in this class differs from what the timezone is on the blog.
462
+	 *            - formatted date string including the UTC (timezone) offset (default).
463
+	 *
464
+	 * @param boolean $format   - whether to return a unix timestamp (default) or formatted date string
465
+	 * @param boolean $gmt      - whether to return a unix timestamp with UTC offset applied (default)
466
+	 *                          or no UTC offset applied
467
+	 * @return string | int
468
+	 * @throws EE_Error
469
+	 * @throws InvalidArgumentException
470
+	 * @throws InvalidDataTypeException
471
+	 * @throws InvalidInterfaceException
472
+	 * @throws ReflectionException
473
+	 */
474
+	public function datetime($format = false, $gmt = false)
475
+	{
476
+		if ($format) {
477
+			return $this->get_pretty('TXN_timestamp');
478
+		}
479
+		if ($gmt) {
480
+			return $this->get_raw('TXN_timestamp');
481
+		}
482
+		return $this->get('TXN_timestamp');
483
+	}
484
+
485
+
486
+	/**
487
+	 * Gets registrations on this transaction
488
+	 *
489
+	 * @param array   $query_params array of query parameters
490
+	 * @param boolean $get_cached   TRUE to retrieve cached registrations or FALSE to pull from the db
491
+	 * @return EE_Base_Class[]|EE_Registration[]
492
+	 * @throws EE_Error
493
+	 * @throws InvalidArgumentException
494
+	 * @throws InvalidDataTypeException
495
+	 * @throws InvalidInterfaceException
496
+	 * @throws ReflectionException
497
+	 */
498
+	public function registrations($query_params = array(), $get_cached = false)
499
+	{
500
+		$query_params = (empty($query_params) || ! is_array($query_params))
501
+			? array(
502
+				'order_by' => array(
503
+					'Event.EVT_name'     => 'ASC',
504
+					'Attendee.ATT_lname' => 'ASC',
505
+					'Attendee.ATT_fname' => 'ASC',
506
+				),
507
+			)
508
+			: $query_params;
509
+		$query_params = $get_cached ? array() : $query_params;
510
+		return $this->get_many_related('Registration', $query_params);
511
+	}
512
+
513
+
514
+	/**
515
+	 * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event
516
+	 * function for getting attendees and how many registrations they each have for an event)
517
+	 *
518
+	 * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT'
519
+	 * @throws EE_Error
520
+	 * @throws InvalidArgumentException
521
+	 * @throws InvalidDataTypeException
522
+	 * @throws InvalidInterfaceException
523
+	 * @throws ReflectionException
524
+	 */
525
+	public function attendees()
526
+	{
527
+		return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID())));
528
+	}
529
+
530
+
531
+	/**
532
+	 * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default
533
+	 *
534
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
535
+	 * @return EE_Base_Class[]|EE_Payment[]
536
+	 * @throws EE_Error
537
+	 * @throws InvalidArgumentException
538
+	 * @throws InvalidDataTypeException
539
+	 * @throws InvalidInterfaceException
540
+	 * @throws ReflectionException
541
+	 */
542
+	public function payments($query_params = array())
543
+	{
544
+		return $this->get_many_related('Payment', $query_params);
545
+	}
546
+
547
+
548
+	/**
549
+	 * gets only approved payments for this transaction
550
+	 *
551
+	 * @return EE_Base_Class[]|EE_Payment[]
552
+	 * @throws EE_Error
553
+	 * @throws InvalidArgumentException
554
+	 * @throws ReflectionException
555
+	 * @throws InvalidDataTypeException
556
+	 * @throws InvalidInterfaceException
557
+	 */
558
+	public function approved_payments()
559
+	{
560
+		EE_Registry::instance()->load_model('Payment');
561
+		return $this->get_many_related(
562
+			'Payment',
563
+			array(
564
+				array('STS_ID' => EEM_Payment::status_id_approved),
565
+				'order_by' => array('PAY_timestamp' => 'DESC'),
566
+			)
567
+		);
568
+	}
569
+
570
+
571
+	/**
572
+	 * Gets all payments which have not been approved
573
+	 *
574
+	 * @return EE_Base_Class[]|EEI_Payment[]
575
+	 * @throws EE_Error if a model is misconfigured somehow
576
+	 * @throws InvalidArgumentException
577
+	 * @throws InvalidDataTypeException
578
+	 * @throws InvalidInterfaceException
579
+	 * @throws ReflectionException
580
+	 */
581
+	public function pending_payments()
582
+	{
583
+		return $this->get_many_related(
584
+			'Payment',
585
+			array(
586
+				array(
587
+					'STS_ID' => EEM_Payment::status_id_pending,
588
+				),
589
+				'order_by' => array(
590
+					'PAY_timestamp' => 'DESC',
591
+				),
592
+			)
593
+		);
594
+	}
595
+
596
+
597
+	/**
598
+	 * echoes $this->pretty_status()
599
+	 *
600
+	 * @param bool $show_icons
601
+	 * @throws EE_Error
602
+	 * @throws InvalidArgumentException
603
+	 * @throws InvalidDataTypeException
604
+	 * @throws InvalidInterfaceException
605
+	 * @throws ReflectionException
606
+	 */
607
+	public function e_pretty_status($show_icons = false)
608
+	{
609
+		echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags());
610
+	}
611
+
612
+
613
+	/**
614
+	 * returns a pretty version of the status, good for displaying to users
615
+	 *
616
+	 * @param bool $show_icons
617
+	 * @return string
618
+	 * @throws EE_Error
619
+	 * @throws InvalidArgumentException
620
+	 * @throws InvalidDataTypeException
621
+	 * @throws InvalidInterfaceException
622
+	 * @throws ReflectionException
623
+	 */
624
+	public function pretty_status($show_icons = false)
625
+	{
626
+		$status = EEM_Status::instance()->localized_status(
627
+			array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
628
+			false,
629
+			'sentence'
630
+		);
631
+		$icon = '';
632
+		switch ($this->status_ID()) {
633
+			case EEM_Transaction::complete_status_code:
634
+				$icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : '';
635
+				break;
636
+			case EEM_Transaction::incomplete_status_code:
637
+				$icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>'
638
+					: '';
639
+				break;
640
+			case EEM_Transaction::abandoned_status_code:
641
+				$icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : '';
642
+				break;
643
+			case EEM_Transaction::failed_status_code:
644
+				$icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : '';
645
+				break;
646
+			case EEM_Transaction::overpaid_status_code:
647
+				$icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : '';
648
+				break;
649
+		}
650
+		return $icon . $status[ $this->status_ID() ];
651
+	}
652
+
653
+
654
+	/**
655
+	 * get Transaction Status
656
+	 *
657
+	 * @return mixed
658
+	 * @throws EE_Error
659
+	 * @throws InvalidArgumentException
660
+	 * @throws InvalidDataTypeException
661
+	 * @throws InvalidInterfaceException
662
+	 * @throws ReflectionException
663
+	 */
664
+	public function status_ID()
665
+	{
666
+		return $this->get('STS_ID');
667
+	}
668
+
669
+
670
+	/**
671
+	 * Returns TRUE or FALSE for whether or not this transaction cost any money
672
+	 *
673
+	 * @return boolean
674
+	 * @throws EE_Error
675
+	 * @throws InvalidArgumentException
676
+	 * @throws InvalidDataTypeException
677
+	 * @throws InvalidInterfaceException
678
+	 * @throws ReflectionException
679
+	 */
680
+	public function is_free()
681
+	{
682
+		return EEH_Money::compare_floats($this->get('TXN_total'), 0, '==');
683
+	}
684
+
685
+
686
+	/**
687
+	 * Returns whether this transaction is complete
688
+	 * Useful in templates and other logic for deciding if we should ask for another payment...
689
+	 *
690
+	 * @return boolean
691
+	 * @throws EE_Error
692
+	 * @throws InvalidArgumentException
693
+	 * @throws InvalidDataTypeException
694
+	 * @throws InvalidInterfaceException
695
+	 * @throws ReflectionException
696
+	 */
697
+	public function is_completed()
698
+	{
699
+		return $this->status_ID() === EEM_Transaction::complete_status_code;
700
+	}
701
+
702
+
703
+	/**
704
+	 * Returns whether this transaction is incomplete
705
+	 * Useful in templates and other logic for deciding if we should ask for another payment...
706
+	 *
707
+	 * @return boolean
708
+	 * @throws EE_Error
709
+	 * @throws InvalidArgumentException
710
+	 * @throws InvalidDataTypeException
711
+	 * @throws InvalidInterfaceException
712
+	 * @throws ReflectionException
713
+	 */
714
+	public function is_incomplete()
715
+	{
716
+		return $this->status_ID() === EEM_Transaction::incomplete_status_code;
717
+	}
718
+
719
+
720
+	/**
721
+	 * Returns whether this transaction is overpaid
722
+	 * Useful in templates and other logic for deciding if monies need to be refunded
723
+	 *
724
+	 * @return boolean
725
+	 * @throws EE_Error
726
+	 * @throws InvalidArgumentException
727
+	 * @throws InvalidDataTypeException
728
+	 * @throws InvalidInterfaceException
729
+	 * @throws ReflectionException
730
+	 */
731
+	public function is_overpaid()
732
+	{
733
+		return $this->status_ID() === EEM_Transaction::overpaid_status_code;
734
+	}
735
+
736
+
737
+	/**
738
+	 * Returns whether this transaction was abandoned
739
+	 * meaning that the transaction/registration process was somehow interrupted and never completed
740
+	 * but that contact information exists for at least one registrant
741
+	 *
742
+	 * @return boolean
743
+	 * @throws EE_Error
744
+	 * @throws InvalidArgumentException
745
+	 * @throws InvalidDataTypeException
746
+	 * @throws InvalidInterfaceException
747
+	 * @throws ReflectionException
748
+	 */
749
+	public function is_abandoned()
750
+	{
751
+		return $this->status_ID() === EEM_Transaction::abandoned_status_code;
752
+	}
753
+
754
+
755
+	/**
756
+	 * Returns whether this transaction failed
757
+	 * meaning that the transaction/registration process was somehow interrupted and never completed
758
+	 * and that NO contact information exists for any registrants
759
+	 *
760
+	 * @return boolean
761
+	 * @throws EE_Error
762
+	 * @throws InvalidArgumentException
763
+	 * @throws InvalidDataTypeException
764
+	 * @throws InvalidInterfaceException
765
+	 * @throws ReflectionException
766
+	 */
767
+	public function failed()
768
+	{
769
+		return $this->status_ID() === EEM_Transaction::failed_status_code;
770
+	}
771
+
772
+
773
+	/**
774
+	 * This returns the url for the invoice of this transaction
775
+	 *
776
+	 * @param string $type 'html' or 'pdf' (default is pdf)
777
+	 * @return string
778
+	 * @throws DomainException
779
+	 * @throws EE_Error
780
+	 * @throws InvalidArgumentException
781
+	 * @throws InvalidDataTypeException
782
+	 * @throws InvalidInterfaceException
783
+	 * @throws ReflectionException
784
+	 */
785
+	public function invoice_url($type = 'html')
786
+	{
787
+		$REG = $this->primary_registration();
788
+		if (! $REG instanceof EE_Registration) {
789
+			return '';
790
+		}
791
+		return $REG->invoice_url($type);
792
+	}
793
+
794
+
795
+	/**
796
+	 * Gets the primary registration only
797
+	 *
798
+	 * @return EE_Base_Class|EE_Registration
799
+	 * @throws EE_Error
800
+	 * @throws InvalidArgumentException
801
+	 * @throws InvalidDataTypeException
802
+	 * @throws InvalidInterfaceException
803
+	 * @throws ReflectionException
804
+	 */
805
+	public function primary_registration()
806
+	{
807
+		$registrations = (array) $this->get_many_related(
808
+			'Registration',
809
+			array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT))
810
+		);
811
+		foreach ($registrations as $registration) {
812
+			// valid registration that is NOT cancelled or declined ?
813
+			if (
814
+				$registration instanceof EE_Registration
815
+				&& ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true)
816
+			) {
817
+				return $registration;
818
+			}
819
+		}
820
+		// nothing valid found, so just return first thing from array of results
821
+		return reset($registrations);
822
+	}
823
+
824
+
825
+	/**
826
+	 * Gets the URL for viewing the receipt
827
+	 *
828
+	 * @param string $type 'pdf' or 'html' (default is 'html')
829
+	 * @return string
830
+	 * @throws DomainException
831
+	 * @throws EE_Error
832
+	 * @throws InvalidArgumentException
833
+	 * @throws InvalidDataTypeException
834
+	 * @throws InvalidInterfaceException
835
+	 * @throws ReflectionException
836
+	 */
837
+	public function receipt_url($type = 'html')
838
+	{
839
+		$REG = $this->primary_registration();
840
+		if (! $REG instanceof EE_Registration) {
841
+			return '';
842
+		}
843
+		return $REG->receipt_url($type);
844
+	}
845
+
846
+
847
+	/**
848
+	 * Gets the URL of the thank you page with this registration REG_url_link added as
849
+	 * a query parameter
850
+	 *
851
+	 * @return string
852
+	 * @throws EE_Error
853
+	 * @throws InvalidArgumentException
854
+	 * @throws InvalidDataTypeException
855
+	 * @throws InvalidInterfaceException
856
+	 * @throws ReflectionException
857
+	 */
858
+	public function payment_overview_url()
859
+	{
860
+		$primary_registration = $this->primary_registration();
861
+		return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false;
862
+	}
863
+
864
+
865
+	/**
866
+	 * @return string
867
+	 * @throws EE_Error
868
+	 * @throws InvalidArgumentException
869
+	 * @throws InvalidDataTypeException
870
+	 * @throws InvalidInterfaceException
871
+	 * @throws ReflectionException
872
+	 */
873
+	public function gateway_response_on_transaction()
874
+	{
875
+		$payment = $this->get_first_related('Payment');
876
+		return $payment instanceof EE_Payment ? $payment->gateway_response() : '';
877
+	}
878
+
879
+
880
+	/**
881
+	 * Get the status object of this object
882
+	 *
883
+	 * @return EE_Base_Class|EE_Status
884
+	 * @throws EE_Error
885
+	 * @throws InvalidArgumentException
886
+	 * @throws InvalidDataTypeException
887
+	 * @throws InvalidInterfaceException
888
+	 * @throws ReflectionException
889
+	 */
890
+	public function status_obj()
891
+	{
892
+		return $this->get_first_related('Status');
893
+	}
894
+
895
+
896
+	/**
897
+	 * Gets all the extra meta info on this payment
898
+	 *
899
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
900
+	 * @return EE_Base_Class[]|EE_Extra_Meta
901
+	 * @throws EE_Error
902
+	 * @throws InvalidArgumentException
903
+	 * @throws InvalidDataTypeException
904
+	 * @throws InvalidInterfaceException
905
+	 * @throws ReflectionException
906
+	 */
907
+	public function extra_meta($query_params = array())
908
+	{
909
+		return $this->get_many_related('Extra_Meta', $query_params);
910
+	}
911
+
912
+
913
+	/**
914
+	 * Wrapper for _add_relation_to
915
+	 *
916
+	 * @param EE_Registration $registration
917
+	 * @return EE_Base_Class the relation was added to
918
+	 * @throws EE_Error
919
+	 * @throws InvalidArgumentException
920
+	 * @throws InvalidDataTypeException
921
+	 * @throws InvalidInterfaceException
922
+	 * @throws ReflectionException
923
+	 */
924
+	public function add_registration(EE_Registration $registration)
925
+	{
926
+		return $this->_add_relation_to($registration, 'Registration');
927
+	}
928
+
929
+
930
+	/**
931
+	 * Removes the given registration from being related (even before saving this transaction).
932
+	 * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations
933
+	 *
934
+	 * @param int $registration_or_id
935
+	 * @return EE_Base_Class that was removed from being related
936
+	 * @throws EE_Error
937
+	 * @throws InvalidArgumentException
938
+	 * @throws InvalidDataTypeException
939
+	 * @throws InvalidInterfaceException
940
+	 * @throws ReflectionException
941
+	 */
942
+	public function remove_registration_with_id($registration_or_id)
943
+	{
944
+		return $this->_remove_relation_to($registration_or_id, 'Registration');
945
+	}
946
+
947
+
948
+	/**
949
+	 * Gets all the line items which are for ACTUAL items
950
+	 *
951
+	 * @return EE_Line_Item[]
952
+	 * @throws EE_Error
953
+	 * @throws InvalidArgumentException
954
+	 * @throws InvalidDataTypeException
955
+	 * @throws InvalidInterfaceException
956
+	 * @throws ReflectionException
957
+	 */
958
+	public function items_purchased()
959
+	{
960
+		return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item)));
961
+	}
962
+
963
+
964
+	/**
965
+	 * Wrapper for _add_relation_to
966
+	 *
967
+	 * @param EE_Line_Item $line_item
968
+	 * @return EE_Base_Class the relation was added to
969
+	 * @throws EE_Error
970
+	 * @throws InvalidArgumentException
971
+	 * @throws InvalidDataTypeException
972
+	 * @throws InvalidInterfaceException
973
+	 * @throws ReflectionException
974
+	 */
975
+	public function add_line_item(EE_Line_Item $line_item)
976
+	{
977
+		return $this->_add_relation_to($line_item, 'Line_Item');
978
+	}
979
+
980
+
981
+	/**
982
+	 * Gets ALL the line items related to this transaction (unstructured)
983
+	 *
984
+	 * @param array $query_params
985
+	 * @return EE_Base_Class[]|EE_Line_Item[]
986
+	 * @throws EE_Error
987
+	 * @throws InvalidArgumentException
988
+	 * @throws InvalidDataTypeException
989
+	 * @throws InvalidInterfaceException
990
+	 * @throws ReflectionException
991
+	 */
992
+	public function line_items($query_params = array())
993
+	{
994
+		return $this->get_many_related('Line_Item', $query_params);
995
+	}
996
+
997
+
998
+	/**
999
+	 * Gets all the line items which are taxes on the total
1000
+	 *
1001
+	 * @return EE_Line_Item[]
1002
+	 * @throws EE_Error
1003
+	 * @throws InvalidArgumentException
1004
+	 * @throws InvalidDataTypeException
1005
+	 * @throws InvalidInterfaceException
1006
+	 * @throws ReflectionException
1007
+	 */
1008
+	public function tax_items()
1009
+	{
1010
+		return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax)));
1011
+	}
1012
+
1013
+
1014
+	/**
1015
+	 * Gets the total line item (which is a parent of all other related line items,
1016
+	 * meaning it takes them all into account on its total)
1017
+	 *
1018
+	 * @param bool $create_if_not_found
1019
+	 * @return \EE_Line_Item
1020
+	 * @throws EE_Error
1021
+	 * @throws InvalidArgumentException
1022
+	 * @throws InvalidDataTypeException
1023
+	 * @throws InvalidInterfaceException
1024
+	 * @throws ReflectionException
1025
+	 */
1026
+	public function total_line_item($create_if_not_found = true)
1027
+	{
1028
+		$item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total)));
1029
+		if (! $item && $create_if_not_found) {
1030
+			$item = EEH_Line_Item::create_total_line_item($this);
1031
+		}
1032
+		return $item;
1033
+	}
1034
+
1035
+
1036
+	/**
1037
+	 * Returns the total amount of tax on this transaction
1038
+	 * (assumes there's only one tax subtotal line item)
1039
+	 *
1040
+	 * @return float
1041
+	 * @throws EE_Error
1042
+	 * @throws InvalidArgumentException
1043
+	 * @throws InvalidDataTypeException
1044
+	 * @throws InvalidInterfaceException
1045
+	 * @throws ReflectionException
1046
+	 */
1047
+	public function tax_total()
1048
+	{
1049
+		$tax_line_item = $this->tax_total_line_item();
1050
+		if ($tax_line_item) {
1051
+			return (float) $tax_line_item->total();
1052
+		}
1053
+		return (float) 0;
1054
+	}
1055
+
1056
+
1057
+	/**
1058
+	 * Gets the tax subtotal line item (assumes there's only one)
1059
+	 *
1060
+	 * @return EE_Line_Item
1061
+	 * @throws EE_Error
1062
+	 * @throws InvalidArgumentException
1063
+	 * @throws InvalidDataTypeException
1064
+	 * @throws InvalidInterfaceException
1065
+	 * @throws ReflectionException
1066
+	 */
1067
+	public function tax_total_line_item()
1068
+	{
1069
+		return EEH_Line_Item::get_taxes_subtotal($this->total_line_item());
1070
+	}
1071
+
1072
+
1073
+	/**
1074
+	 * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee.
1075
+	 *
1076
+	 * @return EE_Form_Section_Proper
1077
+	 * @throws EE_Error
1078
+	 * @throws InvalidArgumentException
1079
+	 * @throws InvalidDataTypeException
1080
+	 * @throws InvalidInterfaceException
1081
+	 * @throws ReflectionException
1082
+	 */
1083
+	public function billing_info()
1084
+	{
1085
+		$payment_method = $this->payment_method();
1086
+		if (! $payment_method) {
1087
+			EE_Error::add_error(
1088
+				esc_html__(
1089
+					'Could not find billing info for transaction because no gateway has been used for it yet',
1090
+					'event_espresso'
1091
+				),
1092
+				__FILE__,
1093
+				__FUNCTION__,
1094
+				__LINE__
1095
+			);
1096
+			return null;
1097
+		}
1098
+		$primary_reg = $this->primary_registration();
1099
+		if (! $primary_reg) {
1100
+			EE_Error::add_error(
1101
+				esc_html__(
1102
+					'Cannot get billing info for gateway %s on transaction because no primary registration exists',
1103
+					'event_espresso'
1104
+				),
1105
+				__FILE__,
1106
+				__FUNCTION__,
1107
+				__LINE__
1108
+			);
1109
+			return null;
1110
+		}
1111
+		$attendee = $primary_reg->attendee();
1112
+		if (! $attendee) {
1113
+			EE_Error::add_error(
1114
+				esc_html__(
1115
+					'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists',
1116
+					'event_espresso'
1117
+				),
1118
+				__FILE__,
1119
+				__FUNCTION__,
1120
+				__LINE__
1121
+			);
1122
+			return null;
1123
+		}
1124
+		return $attendee->billing_info_for_payment_method($payment_method);
1125
+	}
1126
+
1127
+
1128
+	/**
1129
+	 * Gets PMD_ID
1130
+	 *
1131
+	 * @return int
1132
+	 * @throws EE_Error
1133
+	 * @throws InvalidArgumentException
1134
+	 * @throws InvalidDataTypeException
1135
+	 * @throws InvalidInterfaceException
1136
+	 * @throws ReflectionException
1137
+	 */
1138
+	public function payment_method_ID()
1139
+	{
1140
+		return $this->get('PMD_ID');
1141
+	}
1142
+
1143
+
1144
+	/**
1145
+	 * Sets PMD_ID
1146
+	 *
1147
+	 * @param int $PMD_ID
1148
+	 * @throws EE_Error
1149
+	 * @throws InvalidArgumentException
1150
+	 * @throws InvalidDataTypeException
1151
+	 * @throws InvalidInterfaceException
1152
+	 * @throws ReflectionException
1153
+	 */
1154
+	public function set_payment_method_ID($PMD_ID)
1155
+	{
1156
+		$this->set('PMD_ID', $PMD_ID);
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * Gets the last-used payment method on this transaction
1162
+	 * (we COULD just use the last-made payment, but some payment methods, namely
1163
+	 * offline ones, dont' create payments)
1164
+	 *
1165
+	 * @return EE_Payment_Method
1166
+	 * @throws EE_Error
1167
+	 * @throws InvalidArgumentException
1168
+	 * @throws InvalidDataTypeException
1169
+	 * @throws InvalidInterfaceException
1170
+	 * @throws ReflectionException
1171
+	 */
1172
+	public function payment_method()
1173
+	{
1174
+		$pm = $this->get_first_related('Payment_Method');
1175
+		if ($pm instanceof EE_Payment_Method) {
1176
+			return $pm;
1177
+		}
1178
+		$last_payment = $this->last_payment();
1179
+		if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) {
1180
+			return $last_payment->payment_method();
1181
+		}
1182
+		return null;
1183
+	}
1184
+
1185
+
1186
+	/**
1187
+	 * Gets the last payment made
1188
+	 *
1189
+	 * @return EE_Base_Class|EE_Payment
1190
+	 * @throws EE_Error
1191
+	 * @throws InvalidArgumentException
1192
+	 * @throws InvalidDataTypeException
1193
+	 * @throws InvalidInterfaceException
1194
+	 * @throws ReflectionException
1195
+	 */
1196
+	public function last_payment()
1197
+	{
1198
+		return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc')));
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * Gets all the line items which are unrelated to tickets on this transaction
1204
+	 *
1205
+	 * @return EE_Line_Item[]
1206
+	 * @throws EE_Error
1207
+	 * @throws InvalidArgumentException
1208
+	 * @throws InvalidDataTypeException
1209
+	 * @throws InvalidInterfaceException
1210
+	 * @throws ReflectionException
1211
+	 */
1212
+	public function non_ticket_line_items()
1213
+	{
1214
+		return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID());
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * possibly toggles TXN status
1220
+	 *
1221
+	 * @param  boolean $update whether to save the TXN
1222
+	 * @return bool whether the TXN was saved
1223
+	 * @throws EE_Error
1224
+	 * @throws InvalidArgumentException
1225
+	 * @throws InvalidDataTypeException
1226
+	 * @throws InvalidInterfaceException
1227
+	 * @throws ReflectionException
1228
+	 * @throws RuntimeException
1229
+	 */
1230
+	public function update_status_based_on_total_paid($update = true)
1231
+	{
1232
+		// set transaction status based on comparison of TXN_paid vs TXN_total
1233
+		if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) {
1234
+			$new_txn_status = EEM_Transaction::overpaid_status_code;
1235
+		} elseif (EEH_Money::compare_floats($this->paid(), $this->total())) {
1236
+			$new_txn_status = EEM_Transaction::complete_status_code;
1237
+		} elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) {
1238
+			$new_txn_status = EEM_Transaction::incomplete_status_code;
1239
+		} else {
1240
+			throw new RuntimeException(
1241
+				esc_html__('The total paid calculation for this transaction is inaccurate.', 'event_espresso')
1242
+			);
1243
+		}
1244
+		if ($new_txn_status !== $this->status_ID()) {
1245
+			$this->set_status($new_txn_status);
1246
+			if ($update) {
1247
+				return $this->save() ? true : false;
1248
+			}
1249
+		}
1250
+		return false;
1251
+	}
1252
+
1253
+
1254
+	/**
1255
+	 * Updates the transaction's status and total_paid based on all the payments
1256
+	 * that apply to it
1257
+	 *
1258
+	 * @deprecated
1259
+	 * @return array|bool
1260
+	 * @throws EE_Error
1261
+	 * @throws InvalidArgumentException
1262
+	 * @throws ReflectionException
1263
+	 * @throws InvalidDataTypeException
1264
+	 * @throws InvalidInterfaceException
1265
+	 */
1266
+	public function update_based_on_payments()
1267
+	{
1268
+		EE_Error::doing_it_wrong(
1269
+			__CLASS__ . '::' . __FUNCTION__,
1270
+			sprintf(
1271
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
1272
+				'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'
1273
+			),
1274
+			'4.6.0'
1275
+		);
1276
+		/** @type EE_Transaction_Processor $transaction_processor */
1277
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1278
+		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this);
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 * @return string
1284
+	 */
1285
+	public function old_txn_status()
1286
+	{
1287
+		return $this->_old_txn_status;
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * @param string $old_txn_status
1293
+	 */
1294
+	public function set_old_txn_status($old_txn_status)
1295
+	{
1296
+		// only set the first time
1297
+		if ($this->_old_txn_status === null) {
1298
+			$this->_old_txn_status = $old_txn_status;
1299
+		}
1300
+	}
1301
+
1302
+
1303
+	/**
1304
+	 * reg_status_updated
1305
+	 *
1306
+	 * @return bool
1307
+	 * @throws EE_Error
1308
+	 * @throws InvalidArgumentException
1309
+	 * @throws InvalidDataTypeException
1310
+	 * @throws InvalidInterfaceException
1311
+	 * @throws ReflectionException
1312
+	 */
1313
+	public function txn_status_updated()
1314
+	{
1315
+		return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null;
1316
+	}
1317
+
1318
+
1319
+	/**
1320
+	 * _reg_steps_completed
1321
+	 * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed,
1322
+	 * if a $reg_step_slug is provided, then this step will be skipped when testing for completion
1323
+	 * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion
1324
+	 *
1325
+	 * @param string $reg_step_slug
1326
+	 * @param bool   $check_all
1327
+	 * @return bool|int
1328
+	 * @throws EE_Error
1329
+	 * @throws InvalidArgumentException
1330
+	 * @throws InvalidDataTypeException
1331
+	 * @throws InvalidInterfaceException
1332
+	 * @throws ReflectionException
1333
+	 */
1334
+	private function _reg_steps_completed($reg_step_slug = '', $check_all = true)
1335
+	{
1336
+		$reg_steps = $this->reg_steps();
1337
+		if (! is_array($reg_steps) || empty($reg_steps)) {
1338
+			return false;
1339
+		}
1340
+		// loop thru reg steps array)
1341
+		foreach ($reg_steps as $slug => $reg_step_completed) {
1342
+			// if NOT checking ALL steps (only checking one step)
1343
+			if (! $check_all) {
1344
+				// and this is the one
1345
+				if ($slug === $reg_step_slug) {
1346
+					return $reg_step_completed;
1347
+				}
1348
+				// skip to next reg step in loop
1349
+				continue;
1350
+			}
1351
+			// $check_all must be true, else we would never have gotten to this point
1352
+			if ($slug === $reg_step_slug) {
1353
+				// if we reach this point, then we are testing either:
1354
+				// all_reg_steps_completed_except() or
1355
+				// all_reg_steps_completed_except_final_step(),
1356
+				// and since this is the reg step EXCEPTION being tested
1357
+				// we want to return true (yes true) if this reg step is NOT completed
1358
+				// ie: "is everything completed except the final step?"
1359
+				// "that is correct... the final step is not completed, but all others are."
1360
+				return $reg_step_completed !== true;
1361
+			}
1362
+			if ($reg_step_completed !== true) {
1363
+				// if any reg step is NOT completed, then ALL steps are not completed
1364
+				return false;
1365
+			}
1366
+		}
1367
+		return true;
1368
+	}
1369
+
1370
+
1371
+	/**
1372
+	 * all_reg_steps_completed
1373
+	 * returns:
1374
+	 *    true if ALL reg steps have been marked as completed
1375
+	 *        or false if any step is not completed
1376
+	 *
1377
+	 * @return bool
1378
+	 * @throws EE_Error
1379
+	 * @throws InvalidArgumentException
1380
+	 * @throws InvalidDataTypeException
1381
+	 * @throws InvalidInterfaceException
1382
+	 * @throws ReflectionException
1383
+	 */
1384
+	public function all_reg_steps_completed()
1385
+	{
1386
+		return $this->_reg_steps_completed();
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 * all_reg_steps_completed_except
1392
+	 * returns:
1393
+	 *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
1394
+	 *        or false if any other step is not completed
1395
+	 *        or false if ALL steps are completed including the exception you are testing !!!
1396
+	 *
1397
+	 * @param string $exception
1398
+	 * @return bool
1399
+	 * @throws EE_Error
1400
+	 * @throws InvalidArgumentException
1401
+	 * @throws InvalidDataTypeException
1402
+	 * @throws InvalidInterfaceException
1403
+	 * @throws ReflectionException
1404
+	 */
1405
+	public function all_reg_steps_completed_except($exception = '')
1406
+	{
1407
+		return $this->_reg_steps_completed($exception);
1408
+	}
1409
+
1410
+
1411
+	/**
1412
+	 * all_reg_steps_completed_except
1413
+	 * returns:
1414
+	 *        true if ALL reg steps, except the final step, have been marked as completed
1415
+	 *        or false if any step is not completed
1416
+	 *    or false if ALL steps are completed including the final step !!!
1417
+	 *
1418
+	 * @return bool
1419
+	 * @throws EE_Error
1420
+	 * @throws InvalidArgumentException
1421
+	 * @throws InvalidDataTypeException
1422
+	 * @throws InvalidInterfaceException
1423
+	 * @throws ReflectionException
1424
+	 */
1425
+	public function all_reg_steps_completed_except_final_step()
1426
+	{
1427
+		return $this->_reg_steps_completed('finalize_registration');
1428
+	}
1429
+
1430
+
1431
+	/**
1432
+	 * reg_step_completed
1433
+	 * returns:
1434
+	 *    true if a specific reg step has been marked as completed
1435
+	 *    a Unix timestamp if it has been initialized but not yet completed,
1436
+	 *    or false if it has not yet been initialized
1437
+	 *
1438
+	 * @param string $reg_step_slug
1439
+	 * @return bool|int
1440
+	 * @throws EE_Error
1441
+	 * @throws InvalidArgumentException
1442
+	 * @throws InvalidDataTypeException
1443
+	 * @throws InvalidInterfaceException
1444
+	 * @throws ReflectionException
1445
+	 */
1446
+	public function reg_step_completed($reg_step_slug)
1447
+	{
1448
+		return $this->_reg_steps_completed($reg_step_slug, false);
1449
+	}
1450
+
1451
+
1452
+	/**
1453
+	 * completed_final_reg_step
1454
+	 * returns:
1455
+	 *    true if the finalize_registration reg step has been marked as completed
1456
+	 *    a Unix timestamp if it has been initialized but not yet completed,
1457
+	 *    or false if it has not yet been initialized
1458
+	 *
1459
+	 * @return bool|int
1460
+	 * @throws EE_Error
1461
+	 * @throws InvalidArgumentException
1462
+	 * @throws InvalidDataTypeException
1463
+	 * @throws InvalidInterfaceException
1464
+	 * @throws ReflectionException
1465
+	 */
1466
+	public function final_reg_step_completed()
1467
+	{
1468
+		return $this->_reg_steps_completed('finalize_registration', false);
1469
+	}
1470
+
1471
+
1472
+	/**
1473
+	 * set_reg_step_initiated
1474
+	 * given a valid TXN_reg_step, this sets it's value to a unix timestamp
1475
+	 *
1476
+	 * @param string $reg_step_slug
1477
+	 * @return boolean
1478
+	 * @throws EE_Error
1479
+	 * @throws InvalidArgumentException
1480
+	 * @throws InvalidDataTypeException
1481
+	 * @throws InvalidInterfaceException
1482
+	 * @throws ReflectionException
1483
+	 */
1484
+	public function set_reg_step_initiated($reg_step_slug)
1485
+	{
1486
+		return $this->_set_reg_step_completed_status($reg_step_slug, time());
1487
+	}
1488
+
1489
+
1490
+	/**
1491
+	 * set_reg_step_completed
1492
+	 * given a valid TXN_reg_step, this sets the step as completed
1493
+	 *
1494
+	 * @param string $reg_step_slug
1495
+	 * @return boolean
1496
+	 * @throws EE_Error
1497
+	 * @throws InvalidArgumentException
1498
+	 * @throws InvalidDataTypeException
1499
+	 * @throws InvalidInterfaceException
1500
+	 * @throws ReflectionException
1501
+	 */
1502
+	public function set_reg_step_completed($reg_step_slug)
1503
+	{
1504
+		return $this->_set_reg_step_completed_status($reg_step_slug, true);
1505
+	}
1506
+
1507
+
1508
+	/**
1509
+	 * set_reg_step_completed
1510
+	 * given a valid TXN_reg_step slug, this sets the step as NOT completed
1511
+	 *
1512
+	 * @param string $reg_step_slug
1513
+	 * @return boolean
1514
+	 * @throws EE_Error
1515
+	 * @throws InvalidArgumentException
1516
+	 * @throws InvalidDataTypeException
1517
+	 * @throws InvalidInterfaceException
1518
+	 * @throws ReflectionException
1519
+	 */
1520
+	public function set_reg_step_not_completed($reg_step_slug)
1521
+	{
1522
+		return $this->_set_reg_step_completed_status($reg_step_slug, false);
1523
+	}
1524
+
1525
+
1526
+	/**
1527
+	 * set_reg_step_completed
1528
+	 * given a valid reg step slug, this sets the TXN_reg_step completed status which is either:
1529
+	 *
1530
+	 * @param  string      $reg_step_slug
1531
+	 * @param  boolean|int $status
1532
+	 * @return boolean
1533
+	 * @throws EE_Error
1534
+	 * @throws InvalidArgumentException
1535
+	 * @throws InvalidDataTypeException
1536
+	 * @throws InvalidInterfaceException
1537
+	 * @throws ReflectionException
1538
+	 */
1539
+	private function _set_reg_step_completed_status($reg_step_slug, $status)
1540
+	{
1541
+		// validate status
1542
+		$status = is_bool($status) || is_int($status) ? $status : false;
1543
+		// get reg steps array
1544
+		$txn_reg_steps = $this->reg_steps();
1545
+		// if reg step does NOT exist
1546
+		if (! isset($txn_reg_steps[ $reg_step_slug ])) {
1547
+			return false;
1548
+		}
1549
+		// if  we're trying to complete a step that is already completed
1550
+		if ($txn_reg_steps[ $reg_step_slug ] === true) {
1551
+			return true;
1552
+		}
1553
+		// if  we're trying to complete a step that hasn't even started
1554
+		if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) {
1555
+			return false;
1556
+		}
1557
+		// if current status value matches the incoming value (no change)
1558
+		// type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890
1559
+		if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) {
1560
+			// this will happen in cases where multiple AJAX requests occur during the same step
1561
+			return true;
1562
+		}
1563
+		// if we're trying to set a start time, but it has already been set...
1564
+		if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) {
1565
+			// skip the update below, but don't return FALSE so that errors won't be displayed
1566
+			return true;
1567
+		}
1568
+		// update completed status
1569
+		$txn_reg_steps[ $reg_step_slug ] = $status;
1570
+		$this->set_reg_steps($txn_reg_steps);
1571
+		$this->save();
1572
+		return true;
1573
+	}
1574
+
1575
+
1576
+	/**
1577
+	 * remove_reg_step
1578
+	 * given a valid TXN_reg_step slug, this will remove (unset)
1579
+	 * the reg step from the TXN reg step array
1580
+	 *
1581
+	 * @param string $reg_step_slug
1582
+	 * @return void
1583
+	 * @throws EE_Error
1584
+	 * @throws InvalidArgumentException
1585
+	 * @throws InvalidDataTypeException
1586
+	 * @throws InvalidInterfaceException
1587
+	 * @throws ReflectionException
1588
+	 */
1589
+	public function remove_reg_step($reg_step_slug)
1590
+	{
1591
+		// get reg steps array
1592
+		$txn_reg_steps = $this->reg_steps();
1593
+		unset($txn_reg_steps[ $reg_step_slug ]);
1594
+		$this->set_reg_steps($txn_reg_steps);
1595
+	}
1596
+
1597
+
1598
+	/**
1599
+	 * toggle_failed_transaction_status
1600
+	 * upgrades a TXNs status from failed to abandoned,
1601
+	 * meaning that contact information has been captured for at least one registrant
1602
+	 *
1603
+	 * @param bool $save
1604
+	 * @return bool
1605
+	 * @throws EE_Error
1606
+	 * @throws InvalidArgumentException
1607
+	 * @throws InvalidDataTypeException
1608
+	 * @throws InvalidInterfaceException
1609
+	 * @throws ReflectionException
1610
+	 */
1611
+	public function toggle_failed_transaction_status($save = true)
1612
+	{
1613
+		// if TXN status is still set as "failed"...
1614
+		if ($this->status_ID() === EEM_Transaction::failed_status_code) {
1615
+			$this->set_status(EEM_Transaction::abandoned_status_code);
1616
+			if ($save) {
1617
+				$this->save();
1618
+			}
1619
+			return true;
1620
+		}
1621
+		return false;
1622
+	}
1623
+
1624
+
1625
+	/**
1626
+	 * toggle_abandoned_transaction_status
1627
+	 * upgrades a TXNs status from failed or abandoned to incomplete
1628
+	 *
1629
+	 * @return bool
1630
+	 * @throws EE_Error
1631
+	 * @throws InvalidArgumentException
1632
+	 * @throws InvalidDataTypeException
1633
+	 * @throws InvalidInterfaceException
1634
+	 * @throws ReflectionException
1635
+	 */
1636
+	public function toggle_abandoned_transaction_status()
1637
+	{
1638
+		// if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"...
1639
+		$txn_status = $this->status_ID();
1640
+		if (
1641
+			$txn_status === EEM_Transaction::failed_status_code
1642
+			|| $txn_status === EEM_Transaction::abandoned_status_code
1643
+		) {
1644
+			// if a contact record for the primary registrant has been created
1645
+			if (
1646
+				$this->primary_registration() instanceof EE_Registration
1647
+				&& $this->primary_registration()->attendee() instanceof EE_Attendee
1648
+			) {
1649
+				$this->set_status(EEM_Transaction::incomplete_status_code);
1650
+			} else {
1651
+				// no contact record? yer abandoned!
1652
+				$this->set_status(EEM_Transaction::abandoned_status_code);
1653
+			}
1654
+			return true;
1655
+		}
1656
+		return false;
1657
+	}
1658
+
1659
+
1660
+	/**
1661
+	 * checks if an Abandoned TXN has any related payments, and if so,
1662
+	 * updates the TXN status based on the amount paid
1663
+	 *
1664
+	 * @throws EE_Error
1665
+	 * @throws InvalidArgumentException
1666
+	 * @throws InvalidDataTypeException
1667
+	 * @throws InvalidInterfaceException
1668
+	 * @throws ReflectionException
1669
+	 * @throws RuntimeException
1670
+	 * @throws ReflectionException
1671
+	 */
1672
+	public function verify_abandoned_transaction_status()
1673
+	{
1674
+		if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) {
1675
+			return;
1676
+		}
1677
+		$payments = $this->get_many_related('Payment');
1678
+		if (! empty($payments)) {
1679
+			foreach ($payments as $payment) {
1680
+				if ($payment instanceof EE_Payment) {
1681
+					// kk this TXN should NOT be abandoned
1682
+					$this->update_status_based_on_total_paid();
1683
+					if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
1684
+						EE_Error::add_attention(
1685
+							sprintf(
1686
+								esc_html__(
1687
+									'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.',
1688
+									'event_espresso'
1689
+								),
1690
+								$this->ID(),
1691
+								$this->pretty_status()
1692
+							)
1693
+						);
1694
+					}
1695
+					// get final reg step status
1696
+					$finalized = $this->final_reg_step_completed();
1697
+					// if the 'finalize_registration' step has been initiated (has a timestamp)
1698
+					// but has not yet been fully completed (TRUE)
1699
+					if (is_int($finalized) && $finalized !== false && $finalized !== true) {
1700
+						$this->set_reg_step_completed('finalize_registration');
1701
+						$this->save();
1702
+					}
1703
+				}
1704
+			}
1705
+		}
1706
+	}
1707
+
1708
+
1709
+	/**
1710
+	 * @since 4.10.4.p
1711
+	 * @throws EE_Error
1712
+	 * @throws InvalidArgumentException
1713
+	 * @throws InvalidDataTypeException
1714
+	 * @throws InvalidInterfaceException
1715
+	 * @throws ReflectionException
1716
+	 * @throws RuntimeException
1717
+	 */
1718
+	public function recalculateLineItems()
1719
+	{
1720
+		$total_line_item = $this->total_line_item(false);
1721
+		if ($total_line_item instanceof EE_Line_Item) {
1722
+			EEH_Line_Item::resetIsTaxableForTickets($total_line_item);
1723
+			return EEH_Line_Item::apply_taxes($total_line_item, true);
1724
+		}
1725
+		return false;
1726
+	}
1727
+
1728
+
1729
+	/**
1730
+	 * @param string $source function name that called this method
1731
+	 * @return boolean | int
1732
+	 */
1733
+	public function delete($source = 'unknown')
1734
+	{
1735
+		$current_user = wp_get_current_user();
1736
+		$this->add_extra_meta(
1737
+			EE_Transaction::EXTRA_META_KEY_TXN_DELETED,
1738
+			array(
1739
+				'deleted-by' => $current_user->ID ? $current_user->display_name : 'unauthed user',
1740
+				'timestamp'  => time(),
1741
+				'source'     => $source,
1742
+			)
1743
+		);
1744
+		return parent::delete();
1745
+	}
1746 1746
 }
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.