Completed
Branch BUG/update-unit-tests (7b5400)
by
unknown
07:51 queued 05:38
created
core/db_models/fields/EE_Foreign_Key_Int_Field.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -3,36 +3,36 @@
 block discarded – undo
3 3
 class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base
4 4
 {
5 5
 
6
-    /**
7
-     * @param string  $table_column  name fo column for field
8
-     * @param string  $nicename      should eb internationalized with esc_html__('blah','event_espresso')
9
-     * @param boolean $nullable
10
-     * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
11
-     *                               dbe a string
12
-     * @param string|string[]  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
13
-     *                               "EEM_"
14
-     */
15
-    public function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
16
-    {
17
-        parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name);
18
-        $this->setSchemaType('integer');
19
-    }
6
+	/**
7
+	 * @param string  $table_column  name fo column for field
8
+	 * @param string  $nicename      should eb internationalized with esc_html__('blah','event_espresso')
9
+	 * @param boolean $nullable
10
+	 * @param mixed   $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul
11
+	 *                               dbe a string
12
+	 * @param string|string[]  $model_name    eg 'Event','Answer','Term', etc. Basically its the model class's name without the
13
+	 *                               "EEM_"
14
+	 */
15
+	public function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
16
+	{
17
+		parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name);
18
+		$this->setSchemaType('integer');
19
+	}
20 20
 
21 21
 
22
-    /**
23
-     * @param int|EE_Base_Class $value_inputted_for_field_on_model_object
24
-     * @return int
25
-     */
26
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
27
-    {
28
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
29
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
30
-        }
31
-        return absint($value_inputted_for_field_on_model_object);
32
-    }
22
+	/**
23
+	 * @param int|EE_Base_Class $value_inputted_for_field_on_model_object
24
+	 * @return int
25
+	 */
26
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
27
+	{
28
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
29
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
30
+		}
31
+		return absint($value_inputted_for_field_on_model_object);
32
+	}
33 33
 
34
-    public function prepare_for_set_from_db($value_found_in_db_for_model_object)
35
-    {
36
-        return intval($value_found_in_db_for_model_object);
37
-    }
34
+	public function prepare_for_set_from_db($value_found_in_db_for_model_object)
35
+	{
36
+		return intval($value_found_in_db_for_model_object);
37
+	}
38 38
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Boolean_Field.php 1 patch
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -2,66 +2,66 @@
 block discarded – undo
2 2
 
3 3
 class EE_Boolean_Field extends EE_Integer_Field
4 4
 {
5
-    /**
6
-     * @param string $table_column
7
-     * @param string $nicename
8
-     * @param bool   $nullable
9
-     * @param null   $default_value
10
-     */
11
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
12
-    {
13
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
14
-        $this->setSchemaType('boolean');
15
-    }
5
+	/**
6
+	 * @param string $table_column
7
+	 * @param string $nicename
8
+	 * @param bool   $nullable
9
+	 * @param null   $default_value
10
+	 */
11
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
12
+	{
13
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
14
+		$this->setSchemaType('boolean');
15
+	}
16 16
 
17
-    /**
18
-     * Double-checks the value being returned is an boolean.
19
-     * @since 4.9.74.p
20
-     * @param mixed $value_of_field_on_model_object
21
-     * @return boolean
22
-     */
23
-    public function prepare_for_get($value_of_field_on_model_object)
24
-    {
25
-        return (bool) parent::prepare_for_get($value_of_field_on_model_object);
26
-    }
17
+	/**
18
+	 * Double-checks the value being returned is an boolean.
19
+	 * @since 4.9.74.p
20
+	 * @param mixed $value_of_field_on_model_object
21
+	 * @return boolean
22
+	 */
23
+	public function prepare_for_get($value_of_field_on_model_object)
24
+	{
25
+		return (bool) parent::prepare_for_get($value_of_field_on_model_object);
26
+	}
27 27
 
28
-    /**
29
-     * @since 4.9.74.p
30
-     * @param $value_inputted_for_field_on_model_object
31
-     * @return boolean
32
-     */
33
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
34
-    {
35
-        if ($value_inputted_for_field_on_model_object) {
36
-            return true;
37
-        } else {
38
-            return false;
39
-        }
40
-    }
28
+	/**
29
+	 * @since 4.9.74.p
30
+	 * @param $value_inputted_for_field_on_model_object
31
+	 * @return boolean
32
+	 */
33
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
34
+	{
35
+		if ($value_inputted_for_field_on_model_object) {
36
+			return true;
37
+		} else {
38
+			return false;
39
+		}
40
+	}
41 41
 
42
-    /**
43
-     * Make sure we're returning booleans
44
-     *
45
-     * @param string $value_inputted_for_field_on_model_object
46
-     * @return boolean
47
-     */
48
-    public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
49
-    {
50
-        return intval($value_inputted_for_field_on_model_object) ? true : false;
51
-    }
42
+	/**
43
+	 * Make sure we're returning booleans
44
+	 *
45
+	 * @param string $value_inputted_for_field_on_model_object
46
+	 * @return boolean
47
+	 */
48
+	public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
49
+	{
50
+		return intval($value_inputted_for_field_on_model_object) ? true : false;
51
+	}
52 52
 
53
-    /**
54
-     * Gets a nice Yes/No value for this field
55
-     *
56
-     * @param boolean $value_on_field_to_be_outputted
57
-     * @return string Yes or No
58
-     */
59
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
60
-    {
61
-        return apply_filters(
62
-            'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return',
63
-            $value_on_field_to_be_outputted ? esc_html__('Yes', 'event_espresso') : esc_html__('No', 'event_espresso'),
64
-            $value_on_field_to_be_outputted
65
-        );
66
-    }
53
+	/**
54
+	 * Gets a nice Yes/No value for this field
55
+	 *
56
+	 * @param boolean $value_on_field_to_be_outputted
57
+	 * @return string Yes or No
58
+	 */
59
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
60
+	{
61
+		return apply_filters(
62
+			'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return',
63
+			$value_on_field_to_be_outputted ? esc_html__('Yes', 'event_espresso') : esc_html__('No', 'event_espresso'),
64
+			$value_on_field_to_be_outputted
65
+		);
66
+	}
67 67
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_User_Field.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -13,39 +13,39 @@
 block discarded – undo
13 13
  */
14 14
 class EE_WP_User_Field extends EE_Foreign_Key_Int_Field
15 15
 {
16
-    /**
17
-     * No need to provide a default or the model pointed to- the default is
18
-     * always get_current_user_id() and the model pointed to is always WP_User
19
-     *
20
-     * @param string  $table_column name fo column for field
21
-     * @param string  $nicename     should eb internationalized with esc_html__('blah','event_espresso')
22
-     * @param boolean $nullable
23
-     */
24
-    public function __construct($table_column, $nicename, $nullable)
25
-    {
26
-        parent::__construct($table_column, $nicename, $nullable, null, 'WP_User');
27
-    }
16
+	/**
17
+	 * No need to provide a default or the model pointed to- the default is
18
+	 * always get_current_user_id() and the model pointed to is always WP_User
19
+	 *
20
+	 * @param string  $table_column name fo column for field
21
+	 * @param string  $nicename     should eb internationalized with esc_html__('blah','event_espresso')
22
+	 * @param boolean $nullable
23
+	 */
24
+	public function __construct($table_column, $nicename, $nullable)
25
+	{
26
+		parent::__construct($table_column, $nicename, $nullable, null, 'WP_User');
27
+	}
28 28
 
29
-    /**
30
-     * Gets the default which is always the current user. This can't be set when initially
31
-     * constructing the model field because that's done before $current_user is set
32
-     *
33
-     * @return mixed
34
-     */
35
-    public function get_default_value()
36
-    {
37
-        if (did_action('init')) {
38
-            return get_current_user_id();
39
-        } else {
40
-            EE_Error::doing_it_wrong(
41
-                'EE_WP_User_Field::get_default_value',
42
-                esc_html__(
43
-                    'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.',
44
-                    'event_espresso'
45
-                ),
46
-                '4.6.20'
47
-            );
48
-            return 1;
49
-        }
50
-    }
29
+	/**
30
+	 * Gets the default which is always the current user. This can't be set when initially
31
+	 * constructing the model field because that's done before $current_user is set
32
+	 *
33
+	 * @return mixed
34
+	 */
35
+	public function get_default_value()
36
+	{
37
+		if (did_action('init')) {
38
+			return get_current_user_id();
39
+		} else {
40
+			EE_Error::doing_it_wrong(
41
+				'EE_WP_User_Field::get_default_value',
42
+				esc_html__(
43
+					'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.',
44
+					'event_espresso'
45
+				),
46
+				'4.6.20'
47
+			);
48
+			return 1;
49
+		}
50
+	}
51 51
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Payment.model.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
127 127
     {
128 128
         // all payments for a TXN ordered chronologically
129
-        $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
129
+        $query_params = array(array('TXN_ID' => $TXN_ID), 'order_by' => array('PAY_timestamp' => 'ASC'));
130 130
         // if provided with a status, search specifically for that status. Otherwise get them all
131 131
         if ($status_of_payment) {
132 132
             $query_params[0]['STS_ID'] = $status_of_payment;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     {
169 169
         $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
170 170
         // if $start_date or $end date, verify $format is included.
171
-        if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) {
171
+        if (( ! empty($start_date) || ! empty($end_date)) && empty($format)) {
172 172
             throw new EE_Error(esc_html__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query', 'event_espresso'));
173 173
         }
174 174
         $now = new DateTime('now');
@@ -178,12 +178,12 @@  discard block
 block discarded – undo
178 178
         // setup start date
179 179
         $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
180 180
         EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
181
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
181
+        $start_date = $start_date->format('Y-m-d').' 00:00:00';
182 182
         $start_date = strtotime($start_date);
183 183
         // setup end date
184 184
         $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
185 185
         EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
186
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
186
+        $end_date = $end_date->format('Y-m-d').' 23:59:59';
187 187
         $end_date = strtotime($end_date);
188 188
 
189 189
         // make sure our start date is the lowest value and vice versa
@@ -191,10 +191,10 @@  discard block
 block discarded – undo
191 191
         $end = max($start_date, $end_date);
192 192
 
193 193
         // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
194
-        $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
195
-        $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
194
+        $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start).' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
195
+        $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end).' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
196 196
 
197
-        return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date))));
197
+        return $this->get_all(array(array('PAY_timestamp' => array('>=', $start_date), 'PAY_timestamp*' => array('<=', $end_date))));
198 198
     }
199 199
 
200 200
     /**
Please login to merge, or discard this patch.
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -11,232 +11,232 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Payment extends EEM_Base implements EEMI_Payment
13 13
 {
14
-    // private instance of the Payment object
15
-    protected static $_instance = null;
14
+	// private instance of the Payment object
15
+	protected static $_instance = null;
16 16
 
17 17
 
18 18
 
19 19
 /**
20
-     * Status id in esp_status table that represents an approved payment
21
-     */
22
-    const status_id_approved = 'PAP';
23
-
24
-
25
-    /**
26
-     * Status id in esp_status table that represents a pending payment
27
-     */
28
-    const status_id_pending = 'PPN';
29
-
30
-
31
-    /**
32
-     * Status id in esp_status table that represents a cancelled payment (eg, the
33
-     * user went to PayPal, but on the paypal site decided to cancel the payment)
34
-     */
35
-    const status_id_cancelled = 'PCN';
36
-
37
-
38
-
39
-    /**
40
-     * Status id in esp_status table that represents a payment that was declined by
41
-     * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
42
-     */
43
-    const status_id_declined = 'PDC';
44
-
45
-
46
-
47
-    /**
48
-     * Status id in esp_status table that represents a payment that failed for technical reasons.
49
-     * (Eg, there was some error in communicating with the payment gateway.)
50
-     */
51
-    const status_id_failed = 'PFL';
52
-
53
-    /**
54
-     *      private constructor to prevent direct creation
55
-     *      @Constructor
56
-     *      @access protected
57
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
58
-     *      @return EEM_Payment
59
-     */
60
-    protected function __construct($timezone)
61
-    {
62
-
63
-        $this->singular_item = esc_html__('Payment', 'event_espresso');
64
-        $this->plural_item = esc_html__('Payments', 'event_espresso');
65
-
66
-        $this->_tables = array(
67
-            'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID')
68
-        );
69
-        $this->_fields = array(
70
-            'Payment' => array(
71
-                'PAY_ID' => new EE_Primary_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso')),
72
-                'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso'), false, 0, 'Transaction'),
73
-                'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'),
74
-                'PAY_timestamp' => new EE_Datetime_Field('PAY_timestamp', esc_html__('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
75
-                'PAY_source' => new EE_All_Caps_Text_Field('PAY_source', esc_html__('User-friendly description of payment', 'event_espresso'), false, 'CART'),
76
-                'PAY_amount' => new EE_Money_Field('PAY_amount', esc_html__('Amount Payment should be for', 'event_espresso'), false, 0),
77
-                'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'),
78
-                'PAY_gateway_response' => new EE_Plain_Text_Field('PAY_gateway_response', esc_html__('Response from Gateway about the payment', 'event_espresso'), false, ''),
79
-                'PAY_txn_id_chq_nmbr' => new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''),
80
-                'PAY_po_number' => new EE_Plain_Text_Field('PAY_po_number', esc_html__('Purchase or Sales Number', 'event_espresso'), true, ''),
81
-                'PAY_extra_accntng' => new EE_Simple_HTML_Field('PAY_extra_accntng', esc_html__('Extra Account Info', 'event_espresso'), true, ''),
82
-                'PAY_details' => new EE_Serialized_Text_Field('PAY_details', esc_html__('Full Gateway response about payment', 'event_espresso'), true, ''),
83
-                'PAY_redirect_url' => new EE_Plain_Text_Field('PAY_redirect_url', esc_html__("Redirect URL", 'event_espresso'), true),
84
-                'PAY_redirect_args' => new EE_Serialized_Text_Field('PAY_redirect_args', esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'), true)
85
-            )
86
-        );
87
-        $this->_model_relations = array(
88
-            'Transaction' => new EE_Belongs_To_Relation(),
89
-            'Status' => new EE_Belongs_To_Relation(),
90
-            'Payment_Method' => new EE_Belongs_To_Relation(),
91
-            'Registration_Payment' => new EE_Has_Many_Relation(),
92
-            'Registration' => new EE_HABTM_Relation('Registration_Payment'),
93
-        );
94
-        $this->_model_chain_to_wp_user = 'Payment_Method';
95
-        $this->_caps_slug = 'transactions';
96
-        parent::__construct($timezone);
97
-    }
98
-
99
-
100
-
101
-
102
-    /**
103
-     * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
104
-     * to the payment. This is handy for verifying an IPN hasn't already been processed.
105
-     * @param string $PAY_txn_id_chq_nmbr
106
-     * @return EE_Payment
107
-     */
108
-    public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
109
-    {
110
-        return $this->get_one(array(array('PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr)));
111
-    }
112
-
113
-
114
-
115
-
116
-    /**
117
-    *       retrieve  all payments from db for a particular transaction, optionally with
118
-     *      a particular status
119
-    *
120
-    *       @access     public
121
-    *       @param      $TXN_ID
122
-     *      @param  string  $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status
123
-    *       @return     EE_Payment[]
124
-    */
125
-    public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
126
-    {
127
-        // all payments for a TXN ordered chronologically
128
-        $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
129
-        // if provided with a status, search specifically for that status. Otherwise get them all
130
-        if ($status_of_payment) {
131
-            $query_params[0]['STS_ID'] = $status_of_payment;
132
-        }
133
-        // retrieve payments
134
-        return $this->get_all($query_params);
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     * Only gets payments which have been approved
141
-     * @param int $TXN_ID
142
-     * @return EE_Payment[]
143
-     */
144
-    public function get_approved_payments_for_transaction($TXN_ID = 0)
145
-    {
146
-        return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
147
-    }
148
-
149
-
150
-
151
-
152
-
153
-    /**
154
-     * retrieve  all payments from db between two dates,
155
-     *
156
-     * @param string $start_date incoming start date. If empty the beginning of today is used.
157
-     * @param string $end_date   incoming end date. If empty the end of today is used.
158
-     * @param string $format    If you include $start_date or $end_date then you must include the format string
159
-     *                              for the format your date is in.
160
-     * @param string $timezone   If your range is in a different timezone then the current setting on this
161
-     *                                  WordPress install, then include it here.
162
-     * @throws EE_Error
163
-     *
164
-     * @return EE_Payment[]
165
-     */
166
-    public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
167
-    {
168
-        $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
169
-        // if $start_date or $end date, verify $format is included.
170
-        if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) {
171
-            throw new EE_Error(esc_html__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query', 'event_espresso'));
172
-        }
173
-        $now = new DateTime('now');
174
-        // setup timezone objects once
175
-        $modelDateTimeZone = new DateTimeZone($this->_timezone);
176
-        $passedDateTimeZone = new DateTimeZone($timezone);
177
-        // setup start date
178
-        $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
179
-        EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
180
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
181
-        $start_date = strtotime($start_date);
182
-        // setup end date
183
-        $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
184
-        EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
185
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
186
-        $end_date = strtotime($end_date);
187
-
188
-        // make sure our start date is the lowest value and vice versa
189
-        $start = min($start_date, $end_date);
190
-        $end = max($start_date, $end_date);
191
-
192
-        // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
193
-        $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
194
-        $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
195
-
196
-        return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date))));
197
-    }
198
-
199
-    /**
200
-     * methods for EEMI_Payment
201
-     */
202
-    /**
203
-     * returns a string for the approved status
204
-     * @return  string
205
-     */
206
-    public function approved_status()
207
-    {
208
-        return self::status_id_approved;
209
-    }
210
-    /**
211
-     * returns a string for the pending status
212
-     * @return  string
213
-     */
214
-    public function pending_status()
215
-    {
216
-        return self::status_id_pending;
217
-    }
218
-    /**
219
-     * returns a string for the cancelled status
220
-     * @return  string
221
-     */
222
-    public function cancelled_status()
223
-    {
224
-        return self::status_id_cancelled;
225
-    }
226
-    /**
227
-     * returns a string for the failed status
228
-     * @return  string
229
-     */
230
-    public function failed_status()
231
-    {
232
-        return self::status_id_failed;
233
-    }
234
-    /**
235
-     * returns a string for the declined status
236
-     * @return  string
237
-     */
238
-    public function declined_status()
239
-    {
240
-        return self::status_id_declined;
241
-    }
20
+ * Status id in esp_status table that represents an approved payment
21
+ */
22
+	const status_id_approved = 'PAP';
23
+
24
+
25
+	/**
26
+	 * Status id in esp_status table that represents a pending payment
27
+	 */
28
+	const status_id_pending = 'PPN';
29
+
30
+
31
+	/**
32
+	 * Status id in esp_status table that represents a cancelled payment (eg, the
33
+	 * user went to PayPal, but on the paypal site decided to cancel the payment)
34
+	 */
35
+	const status_id_cancelled = 'PCN';
36
+
37
+
38
+
39
+	/**
40
+	 * Status id in esp_status table that represents a payment that was declined by
41
+	 * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
42
+	 */
43
+	const status_id_declined = 'PDC';
44
+
45
+
46
+
47
+	/**
48
+	 * Status id in esp_status table that represents a payment that failed for technical reasons.
49
+	 * (Eg, there was some error in communicating with the payment gateway.)
50
+	 */
51
+	const status_id_failed = 'PFL';
52
+
53
+	/**
54
+	 *      private constructor to prevent direct creation
55
+	 *      @Constructor
56
+	 *      @access protected
57
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
58
+	 *      @return EEM_Payment
59
+	 */
60
+	protected function __construct($timezone)
61
+	{
62
+
63
+		$this->singular_item = esc_html__('Payment', 'event_espresso');
64
+		$this->plural_item = esc_html__('Payments', 'event_espresso');
65
+
66
+		$this->_tables = array(
67
+			'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID')
68
+		);
69
+		$this->_fields = array(
70
+			'Payment' => array(
71
+				'PAY_ID' => new EE_Primary_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso')),
72
+				'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso'), false, 0, 'Transaction'),
73
+				'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'),
74
+				'PAY_timestamp' => new EE_Datetime_Field('PAY_timestamp', esc_html__('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
75
+				'PAY_source' => new EE_All_Caps_Text_Field('PAY_source', esc_html__('User-friendly description of payment', 'event_espresso'), false, 'CART'),
76
+				'PAY_amount' => new EE_Money_Field('PAY_amount', esc_html__('Amount Payment should be for', 'event_espresso'), false, 0),
77
+				'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'),
78
+				'PAY_gateway_response' => new EE_Plain_Text_Field('PAY_gateway_response', esc_html__('Response from Gateway about the payment', 'event_espresso'), false, ''),
79
+				'PAY_txn_id_chq_nmbr' => new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''),
80
+				'PAY_po_number' => new EE_Plain_Text_Field('PAY_po_number', esc_html__('Purchase or Sales Number', 'event_espresso'), true, ''),
81
+				'PAY_extra_accntng' => new EE_Simple_HTML_Field('PAY_extra_accntng', esc_html__('Extra Account Info', 'event_espresso'), true, ''),
82
+				'PAY_details' => new EE_Serialized_Text_Field('PAY_details', esc_html__('Full Gateway response about payment', 'event_espresso'), true, ''),
83
+				'PAY_redirect_url' => new EE_Plain_Text_Field('PAY_redirect_url', esc_html__("Redirect URL", 'event_espresso'), true),
84
+				'PAY_redirect_args' => new EE_Serialized_Text_Field('PAY_redirect_args', esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'), true)
85
+			)
86
+		);
87
+		$this->_model_relations = array(
88
+			'Transaction' => new EE_Belongs_To_Relation(),
89
+			'Status' => new EE_Belongs_To_Relation(),
90
+			'Payment_Method' => new EE_Belongs_To_Relation(),
91
+			'Registration_Payment' => new EE_Has_Many_Relation(),
92
+			'Registration' => new EE_HABTM_Relation('Registration_Payment'),
93
+		);
94
+		$this->_model_chain_to_wp_user = 'Payment_Method';
95
+		$this->_caps_slug = 'transactions';
96
+		parent::__construct($timezone);
97
+	}
98
+
99
+
100
+
101
+
102
+	/**
103
+	 * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
104
+	 * to the payment. This is handy for verifying an IPN hasn't already been processed.
105
+	 * @param string $PAY_txn_id_chq_nmbr
106
+	 * @return EE_Payment
107
+	 */
108
+	public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
109
+	{
110
+		return $this->get_one(array(array('PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr)));
111
+	}
112
+
113
+
114
+
115
+
116
+	/**
117
+	 *       retrieve  all payments from db for a particular transaction, optionally with
118
+	 *      a particular status
119
+	 *
120
+	 *       @access     public
121
+	 *       @param      $TXN_ID
122
+	 *      @param  string  $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status
123
+	 *       @return     EE_Payment[]
124
+	 */
125
+	public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
126
+	{
127
+		// all payments for a TXN ordered chronologically
128
+		$query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
129
+		// if provided with a status, search specifically for that status. Otherwise get them all
130
+		if ($status_of_payment) {
131
+			$query_params[0]['STS_ID'] = $status_of_payment;
132
+		}
133
+		// retrieve payments
134
+		return $this->get_all($query_params);
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 * Only gets payments which have been approved
141
+	 * @param int $TXN_ID
142
+	 * @return EE_Payment[]
143
+	 */
144
+	public function get_approved_payments_for_transaction($TXN_ID = 0)
145
+	{
146
+		return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
147
+	}
148
+
149
+
150
+
151
+
152
+
153
+	/**
154
+	 * retrieve  all payments from db between two dates,
155
+	 *
156
+	 * @param string $start_date incoming start date. If empty the beginning of today is used.
157
+	 * @param string $end_date   incoming end date. If empty the end of today is used.
158
+	 * @param string $format    If you include $start_date or $end_date then you must include the format string
159
+	 *                              for the format your date is in.
160
+	 * @param string $timezone   If your range is in a different timezone then the current setting on this
161
+	 *                                  WordPress install, then include it here.
162
+	 * @throws EE_Error
163
+	 *
164
+	 * @return EE_Payment[]
165
+	 */
166
+	public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
167
+	{
168
+		$timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
169
+		// if $start_date or $end date, verify $format is included.
170
+		if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) {
171
+			throw new EE_Error(esc_html__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query', 'event_espresso'));
172
+		}
173
+		$now = new DateTime('now');
174
+		// setup timezone objects once
175
+		$modelDateTimeZone = new DateTimeZone($this->_timezone);
176
+		$passedDateTimeZone = new DateTimeZone($timezone);
177
+		// setup start date
178
+		$start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
179
+		EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
180
+		$start_date = $start_date->format('Y-m-d') . ' 00:00:00';
181
+		$start_date = strtotime($start_date);
182
+		// setup end date
183
+		$end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
184
+		EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
185
+		$end_date = $end_date->format('Y-m-d') . ' 23:59:59';
186
+		$end_date = strtotime($end_date);
187
+
188
+		// make sure our start date is the lowest value and vice versa
189
+		$start = min($start_date, $end_date);
190
+		$end = max($start_date, $end_date);
191
+
192
+		// yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
193
+		$start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
194
+		$end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
195
+
196
+		return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date))));
197
+	}
198
+
199
+	/**
200
+	 * methods for EEMI_Payment
201
+	 */
202
+	/**
203
+	 * returns a string for the approved status
204
+	 * @return  string
205
+	 */
206
+	public function approved_status()
207
+	{
208
+		return self::status_id_approved;
209
+	}
210
+	/**
211
+	 * returns a string for the pending status
212
+	 * @return  string
213
+	 */
214
+	public function pending_status()
215
+	{
216
+		return self::status_id_pending;
217
+	}
218
+	/**
219
+	 * returns a string for the cancelled status
220
+	 * @return  string
221
+	 */
222
+	public function cancelled_status()
223
+	{
224
+		return self::status_id_cancelled;
225
+	}
226
+	/**
227
+	 * returns a string for the failed status
228
+	 * @return  string
229
+	 */
230
+	public function failed_status()
231
+	{
232
+		return self::status_id_failed;
233
+	}
234
+	/**
235
+	 * returns a string for the declined status
236
+	 * @return  string
237
+	 */
238
+	public function declined_status()
239
+	{
240
+		return self::status_id_declined;
241
+	}
242 242
 }
Please login to merge, or discard this patch.
core/business/EE_Transaction_Processor.class.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public static function instance($registration_query_params = array())
54 54
     {
55 55
         // check if class object is instantiated
56
-        if (! self::$_instance instanceof EE_Transaction_Processor) {
56
+        if ( ! self::$_instance instanceof EE_Transaction_Processor) {
57 57
             self::$_instance = new self($registration_query_params);
58 58
         }
59 59
         return self::$_instance;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         // these reg statuses should not be considered in any calculations involving monies owing
312 312
         $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
313 313
             : EEM_Registration::closed_reg_statuses();
314
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
314
+        if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
315 315
             return false;
316 316
         }
317 317
         try {
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
     public function get_transaction_for_registration(EE_Registration $registration)
366 366
     {
367 367
         $transaction = $registration->transaction();
368
-        if (! $transaction instanceof EE_Transaction) {
368
+        if ( ! $transaction instanceof EE_Transaction) {
369 369
             throw new EE_Error(
370 370
                 sprintf(
371 371
                     esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             $transaction->ID(),
396 396
             $registration->ticket_ID()
397 397
         );
398
-        if (! $ticket_line_item instanceof EE_Line_Item) {
398
+        if ( ! $ticket_line_item instanceof EE_Line_Item) {
399 399
             throw new EE_Error(
400 400
                 sprintf(
401 401
                     esc_html__(
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
         /** @type EE_Registration_Processor $registration_processor */
480 480
         $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
481 481
         // check that method exists
482
-        if (! method_exists($registration_processor, $method_name)) {
482
+        if ( ! method_exists($registration_processor, $method_name)) {
483 483
             throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso'));
484 484
         }
485 485
         // make sure some query params are set for retrieving registrations
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
                         $transaction,
538 538
                         EEM_Payment_Method::scope_cart
539 539
                     );
540
-                    if (! empty($available_payment_methods)) {
540
+                    if ( ! empty($available_payment_methods)) {
541 541
                         $PMD_ID = 0;
542 542
                         foreach ($available_payment_methods as $available_payment_method) {
543 543
                             if (
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
                                 break;
549 549
                             }
550 550
                         }
551
-                        if (! $PMD_ID) {
551
+                        if ( ! $PMD_ID) {
552 552
                             $first_payment_method = reset($available_payment_methods);
553 553
                             if ($first_payment_method instanceof EE_Payment_Method) {
554 554
                                 $PMD_ID = $first_payment_method->ID();
Please login to merge, or discard this patch.
Indentation   +948 added lines, -948 removed lines patch added patch discarded remove patch
@@ -16,952 +16,952 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Transaction_Processor extends EE_Processor_Base
18 18
 {
19
-    /**
20
-     * @var EE_Registration_Processor $_instance
21
-     * @access    private
22
-     */
23
-    private static $_instance;
24
-
25
-    /**
26
-     * array of query WHERE params to use when retrieving cached registrations from a transaction
27
-     *
28
-     * @var array $registration_query_params
29
-     * @access private
30
-     */
31
-    private $_registration_query_params = array();
32
-
33
-    /**
34
-     * @deprecated
35
-     * @var string
36
-     */
37
-    protected $_old_txn_status;
38
-
39
-    /**
40
-     * @deprecated
41
-     * @var string
42
-     */
43
-    protected $_new_txn_status;
44
-
45
-
46
-    /**
47
-     * @singleton method used to instantiate class object
48
-     * @access    public
49
-     * @param array $registration_query_params
50
-     * @return EE_Transaction_Processor instance
51
-     */
52
-    public static function instance($registration_query_params = array())
53
-    {
54
-        // check if class object is instantiated
55
-        if (! self::$_instance instanceof EE_Transaction_Processor) {
56
-            self::$_instance = new self($registration_query_params);
57
-        }
58
-        return self::$_instance;
59
-    }
60
-
61
-
62
-    /**
63
-     * @param array $registration_query_params
64
-     */
65
-    private function __construct($registration_query_params = array())
66
-    {
67
-        // make sure some query params are set for retrieving registrations
68
-        $this->_set_registration_query_params($registration_query_params);
69
-    }
70
-
71
-
72
-    /**
73
-     * @access private
74
-     * @param array $registration_query_params
75
-     */
76
-    private function _set_registration_query_params($registration_query_params)
77
-    {
78
-        $this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params
79
-            : array('order_by' => array('REG_count' => 'ASC'));
80
-    }
81
-
82
-
83
-    /**
84
-     * manually_update_registration_statuses
85
-     *
86
-     * @access public
87
-     * @param EE_Transaction $transaction
88
-     * @param string         $new_reg_status
89
-     * @param array          $registration_query_params array of query WHERE params to use
90
-     *                                                  when retrieving cached registrations from a transaction
91
-     * @return    boolean
92
-     * @throws \EE_Error
93
-     */
94
-    public function manually_update_registration_statuses(
95
-        EE_Transaction $transaction,
96
-        $new_reg_status = '',
97
-        $registration_query_params = array()
98
-    ) {
99
-        $status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
100
-            'manually_update_registration_status',
101
-            $transaction,
102
-            $registration_query_params,
103
-            $new_reg_status
104
-        );
105
-        // send messages
106
-        /** @type EE_Registration_Processor $registration_processor */
107
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
108
-        $registration_processor->trigger_registration_update_notifications(
109
-            $transaction->primary_registration(),
110
-            array('manually_updated' => true)
111
-        );
112
-        do_action(
113
-            'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
114
-            $transaction,
115
-            $status_updates
116
-        );
117
-        return $status_updates;
118
-    }
119
-
120
-
121
-    /**
122
-     * toggle_registration_statuses_for_default_approved_events
123
-     *
124
-     * @access public
125
-     * @param EE_Transaction $transaction
126
-     * @param array          $registration_query_params array of query WHERE params to use
127
-     *                                                  when retrieving cached registrations from a transaction
128
-     * @return    boolean
129
-     * @throws \EE_Error
130
-     */
131
-    public function toggle_registration_statuses_for_default_approved_events(
132
-        EE_Transaction $transaction,
133
-        $registration_query_params = array()
134
-    ) {
135
-        $status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
136
-            'toggle_registration_status_for_default_approved_events',
137
-            $transaction,
138
-            $registration_query_params
139
-        );
140
-        do_action(
141
-            'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
142
-            $transaction,
143
-            $status_updates
144
-        );
145
-        return $status_updates;
146
-    }
147
-
148
-
149
-    /**
150
-     * toggle_registration_statuses_if_no_monies_owing
151
-     *
152
-     * @access public
153
-     * @param EE_Transaction $transaction
154
-     * @param array          $registration_query_params array of query WHERE params to use
155
-     *                                                  when retrieving cached registrations from a transaction
156
-     * @return    boolean
157
-     * @throws \EE_Error
158
-     */
159
-    public function toggle_registration_statuses_if_no_monies_owing(
160
-        EE_Transaction $transaction,
161
-        $registration_query_params = array()
162
-    ) {
163
-        $status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
164
-            'toggle_registration_status_if_no_monies_owing',
165
-            $transaction,
166
-            $registration_query_params
167
-        );
168
-        do_action(
169
-            'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing',
170
-            $transaction,
171
-            $status_updates
172
-        );
173
-        return $status_updates;
174
-    }
175
-
176
-
177
-    /**
178
-     * update_transaction_and_registrations_after_checkout_or_payment
179
-     * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
180
-     *
181
-     * @param EE_Transaction     $transaction
182
-     * @param \EE_Payment | NULL $payment
183
-     * @param array              $registration_query_params    array of query WHERE params to use
184
-     *                                                         when retrieving cached registrations from a transaction
185
-     * @param bool               $trigger_notifications        whether or not to call
186
-     *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
187
-     * @return array
188
-     * @throws \EE_Error
189
-     */
190
-    public function update_transaction_and_registrations_after_checkout_or_payment(
191
-        EE_Transaction $transaction,
192
-        $payment = null,
193
-        $registration_query_params = array(),
194
-        $trigger_notifications = true
195
-    ) {
196
-        // make sure some query params are set for retrieving registrations
197
-        $this->_set_registration_query_params($registration_query_params);
198
-        // get final reg step status
199
-        $finalized = $transaction->final_reg_step_completed();
200
-        // if the 'finalize_registration' step has been initiated (has a timestamp)
201
-        // but has not yet been fully completed (TRUE)
202
-        if (is_int($finalized) && $finalized !== false && $finalized !== true) {
203
-            $transaction->set_reg_step_completed('finalize_registration');
204
-            $finalized = true;
205
-        }
206
-        $transaction->save();
207
-        // array of details to aid in decision making by systems
208
-        $update_params = array(
209
-            'old_txn_status'  => $transaction->old_txn_status(),
210
-            'new_txn_status'  => $transaction->status_ID(),
211
-            'finalized'       => $finalized,
212
-            'revisit'         => $this->_revisit,
213
-            'payment_updates' => $payment instanceof EE_Payment ? true : false,
214
-            'last_payment'    => $payment,
215
-        );
216
-        // now update the registrations and add the results to our $update_params
217
-        $update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor(
218
-            'update_registration_after_checkout_or_payment',
219
-            $transaction,
220
-            $this->_registration_query_params,
221
-            $update_params
222
-        );
223
-        if ($trigger_notifications) {
224
-            // send messages
225
-            /** @type EE_Registration_Processor $registration_processor */
226
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
227
-            $registration_processor->trigger_registration_update_notifications(
228
-                $transaction->primary_registration(),
229
-                $update_params
230
-            );
231
-        }
232
-        do_action(
233
-            'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
234
-            $transaction,
235
-            $update_params
236
-        );
237
-        return $update_params;
238
-    }
239
-
240
-
241
-    /**
242
-     * update_transaction_after_registration_reopened
243
-     * readjusts TXN and Line Item totals after a registration is changed from
244
-     * cancelled or declined to another reg status such as pending payment or approved
245
-     *
246
-     * @param \EE_Registration $registration
247
-     * @param array            $closed_reg_statuses
248
-     * @param bool             $update_txn
249
-     * @return bool
250
-     * @throws \EE_Error
251
-     */
252
-    public function update_transaction_after_reinstating_canceled_registration(
253
-        EE_Registration $registration,
254
-        $closed_reg_statuses = array(),
255
-        $update_txn = true
256
-    ) {
257
-        // these reg statuses should not be considered in any calculations involving monies owing
258
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
259
-            : EEM_Registration::closed_reg_statuses();
260
-        if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
261
-            return false;
262
-        }
263
-        try {
264
-            $transaction = $this->get_transaction_for_registration($registration);
265
-            $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
266
-                $transaction,
267
-                $registration
268
-            );
269
-            // un-cancel the ticket
270
-            $success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item);
271
-        } catch (EE_Error $e) {
272
-            EE_Error::add_error(
273
-                sprintf(
274
-                    esc_html__(
275
-                        'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s',
276
-                        'event_espresso'
277
-                    ),
278
-                    $registration->ID(),
279
-                    '<br />',
280
-                    $e->getMessage()
281
-                ),
282
-                __FILE__,
283
-                __FUNCTION__,
284
-                __LINE__
285
-            );
286
-            return false;
287
-        }
288
-        if ($update_txn) {
289
-            return $transaction->save() ? $success : false;
290
-        }
291
-        return $success;
292
-    }
293
-
294
-
295
-    /**
296
-     * update_transaction_after_canceled_or_declined_registration
297
-     * readjusts TXN and Line Item totals after a registration is cancelled or declined
298
-     *
299
-     * @param \EE_Registration $registration
300
-     * @param array            $closed_reg_statuses
301
-     * @param bool             $update_txn
302
-     * @return bool
303
-     * @throws \EE_Error
304
-     */
305
-    public function update_transaction_after_canceled_or_declined_registration(
306
-        EE_Registration $registration,
307
-        $closed_reg_statuses = array(),
308
-        $update_txn = true
309
-    ) {
310
-        // these reg statuses should not be considered in any calculations involving monies owing
311
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
312
-            : EEM_Registration::closed_reg_statuses();
313
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
314
-            return false;
315
-        }
316
-        try {
317
-            $transaction = $this->get_transaction_for_registration($registration);
318
-            if (
319
-                apply_filters(
320
-                    'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item',
321
-                    true,
322
-                    $registration,
323
-                    $transaction
324
-                )
325
-            ) {
326
-                $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
327
-                    $transaction,
328
-                    $registration
329
-                );
330
-                EEH_Line_Item::cancel_ticket_line_item($ticket_line_item);
331
-            }
332
-        } catch (EE_Error $e) {
333
-            EE_Error::add_error(
334
-                sprintf(
335
-                    esc_html__(
336
-                        'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s',
337
-                        'event_espresso'
338
-                    ),
339
-                    $registration->ID(),
340
-                    '<br />',
341
-                    $e->getMessage()
342
-                ),
343
-                __FILE__,
344
-                __FUNCTION__,
345
-                __LINE__
346
-            );
347
-            return false;
348
-        }
349
-        if ($update_txn) {
350
-            return $transaction->save() ? true : false;
351
-        }
352
-        return true;
353
-    }
354
-
355
-
356
-    /**
357
-     * get_transaction_for_registration
358
-     *
359
-     * @access    public
360
-     * @param    EE_Registration $registration
361
-     * @return    EE_Transaction
362
-     * @throws    EE_Error
363
-     */
364
-    public function get_transaction_for_registration(EE_Registration $registration)
365
-    {
366
-        $transaction = $registration->transaction();
367
-        if (! $transaction instanceof EE_Transaction) {
368
-            throw new EE_Error(
369
-                sprintf(
370
-                    esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
371
-                    $registration->ID()
372
-                )
373
-            );
374
-        }
375
-        return $transaction;
376
-    }
377
-
378
-
379
-    /**
380
-     * get_ticket_line_item_for_transaction_registration
381
-     *
382
-     * @access    public
383
-     * @param    EE_Transaction  $transaction
384
-     * @param    EE_Registration $registration
385
-     * @return    EE_Line_Item
386
-     * @throws    EE_Error
387
-     */
388
-    public function get_ticket_line_item_for_transaction_registration(
389
-        EE_Transaction $transaction,
390
-        EE_Registration $registration
391
-    ) {
392
-        EE_Registry::instance()->load_helper('Line_Item');
393
-        $ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction(
394
-            $transaction->ID(),
395
-            $registration->ticket_ID()
396
-        );
397
-        if (! $ticket_line_item instanceof EE_Line_Item) {
398
-            throw new EE_Error(
399
-                sprintf(
400
-                    esc_html__(
401
-                        'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
402
-                        'event_espresso'
403
-                    ),
404
-                    $transaction->ID(),
405
-                    $registration->ticket_ID()
406
-                )
407
-            );
408
-        }
409
-        return $ticket_line_item;
410
-    }
411
-
412
-
413
-    /**
414
-     * cancel_transaction_if_all_registrations_canceled
415
-     * cycles thru related registrations and checks their statuses
416
-     * if ALL registrations are Cancelled or Declined, then this sets the TXN status to
417
-     *
418
-     * @access    public
419
-     * @param    EE_Transaction $transaction
420
-     * @param    string         $new_TXN_status
421
-     * @param    array          $registration_query_params - array of query WHERE params to use when
422
-     *                                                     retrieving cached registrations from a transaction
423
-     * @param    array          $closed_reg_statuses
424
-     * @param    bool           $update_txn
425
-     * @return    bool            true if TXN status was updated, false if not
426
-     */
427
-    public function toggle_transaction_status_if_all_registrations_canceled_or_declined(
428
-        EE_Transaction $transaction,
429
-        $new_TXN_status = '',
430
-        $registration_query_params = array(),
431
-        $closed_reg_statuses = array(),
432
-        $update_txn = true
433
-    ) {
434
-        // make sure some query params are set for retrieving registrations
435
-        $this->_set_registration_query_params($registration_query_params);
436
-        // these reg statuses should not be considered in any calculations involving monies owing
437
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
438
-            : EEM_Registration::closed_reg_statuses();
439
-        // loop through cached registrations
440
-        foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
441
-            if (
442
-                $registration instanceof EE_Registration
443
-                && ! in_array($registration->status_ID(), $closed_reg_statuses)
444
-            ) {
445
-                return false;
446
-            }
447
-        }
448
-        if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) {
449
-            $transaction->set_status($new_TXN_status);
450
-        }
451
-        if ($update_txn) {
452
-            return $transaction->save() ? true : false;
453
-        }
454
-        return true;
455
-    }
456
-
457
-
458
-    /**
459
-     * _call_method_on_registrations_via_Registration_Processor
460
-     * cycles thru related registrations and calls the requested method on each
461
-     *
462
-     * @access private
463
-     * @param string         $method_name
464
-     * @param EE_Transaction $transaction
465
-     * @param array          $registration_query_params array of query WHERE params to use
466
-     *                                                  when retrieving cached registrations from a transaction
467
-     * @param string         $additional_param
468
-     * @throws \EE_Error
469
-     * @return boolean
470
-     */
471
-    private function _call_method_on_registrations_via_Registration_Processor(
472
-        $method_name,
473
-        EE_Transaction $transaction,
474
-        $registration_query_params = array(),
475
-        $additional_param = null
476
-    ) {
477
-        $response = false;
478
-        /** @type EE_Registration_Processor $registration_processor */
479
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
480
-        // check that method exists
481
-        if (! method_exists($registration_processor, $method_name)) {
482
-            throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso'));
483
-        }
484
-        // make sure some query params are set for retrieving registrations
485
-        $this->_set_registration_query_params($registration_query_params);
486
-        // loop through cached registrations
487
-        foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
488
-            if ($registration instanceof EE_Registration) {
489
-                if ($additional_param) {
490
-                    $response = $registration_processor->{$method_name}($registration, $additional_param)
491
-                        ? true
492
-                        : $response;
493
-                } else {
494
-                    $response = $registration_processor->{$method_name}($registration)
495
-                        ? true
496
-                        : $response;
497
-                }
498
-            }
499
-        }
500
-        return $response;
501
-    }
502
-
503
-
504
-    /**
505
-     * set_transaction_payment_method_based_on_registration_statuses
506
-     * sets or unsets the PMD_ID field on the TXN based on the related REG statuses
507
-     * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null,
508
-     * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either:
509
-     *        the first "default" Payment Method
510
-     *        the first active Payment Method
511
-     *    whichever is found first.
512
-     *
513
-     * @param  EE_Registration $edited_registration
514
-     * @return void
515
-     * @throws \EE_Error
516
-     */
517
-    public function set_transaction_payment_method_based_on_registration_statuses(
518
-        EE_Registration $edited_registration
519
-    ) {
520
-        if ($edited_registration instanceof EE_Registration) {
521
-            $transaction = $edited_registration->transaction();
522
-            if ($transaction instanceof EE_Transaction) {
523
-                $all_not_approved = true;
524
-                foreach ($transaction->registrations() as $registration) {
525
-                    if ($registration instanceof EE_Registration) {
526
-                        // if any REG != "Not Approved" then toggle to false
527
-                        $all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
528
-                    }
529
-                }
530
-                // if ALL Registrations are "Not Approved"
531
-                if ($all_not_approved) {
532
-                    $transaction->set_payment_method_ID(null);
533
-                    $transaction->save();
534
-                } else {
535
-                    $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
536
-                        $transaction,
537
-                        EEM_Payment_Method::scope_cart
538
-                    );
539
-                    if (! empty($available_payment_methods)) {
540
-                        $PMD_ID = 0;
541
-                        foreach ($available_payment_methods as $available_payment_method) {
542
-                            if (
543
-                                $available_payment_method instanceof EE_Payment_Method
544
-                                && $available_payment_method->open_by_default()
545
-                            ) {
546
-                                $PMD_ID = $available_payment_method->ID();
547
-                                break;
548
-                            }
549
-                        }
550
-                        if (! $PMD_ID) {
551
-                            $first_payment_method = reset($available_payment_methods);
552
-                            if ($first_payment_method instanceof EE_Payment_Method) {
553
-                                $PMD_ID = $first_payment_method->ID();
554
-                            } else {
555
-                                EE_Error::add_error(
556
-                                    esc_html__(
557
-                                        'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.',
558
-                                        'event_espresso'
559
-                                    ),
560
-                                    __FILE__,
561
-                                    __LINE__,
562
-                                    __FUNCTION__
563
-                                );
564
-                            }
565
-                        }
566
-                        $transaction->set_payment_method_ID($PMD_ID);
567
-                        $transaction->save();
568
-                    } else {
569
-                        EE_Error::add_error(
570
-                            esc_html__(
571
-                                'Please activate at least one Payment Method in order for things to operate correctly.',
572
-                                'event_espresso'
573
-                            ),
574
-                            __FILE__,
575
-                            __LINE__,
576
-                            __FUNCTION__
577
-                        );
578
-                    }
579
-                }
580
-            }
581
-        }
582
-    }
583
-
584
-
585
-
586
-    /********************************** DEPRECATED METHODS **********************************/
587
-
588
-
589
-    /**
590
-     * @deprecated 4.9.12
591
-     * @return string
592
-     */
593
-    public function old_txn_status()
594
-    {
595
-        EE_Error::doing_it_wrong(
596
-            __METHOD__,
597
-            esc_html__(
598
-                'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
599
-                'event_espresso'
600
-            ),
601
-            '4.9.12'
602
-        );
603
-        return $this->_old_txn_status;
604
-    }
605
-
606
-
607
-    /**
608
-     * @deprecated 4.9.12
609
-     * @param string $old_txn_status
610
-     */
611
-    public function set_old_txn_status($old_txn_status)
612
-    {
613
-        EE_Error::doing_it_wrong(
614
-            __METHOD__,
615
-            esc_html__(
616
-                'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
617
-                'event_espresso'
618
-            ),
619
-            '4.9.12'
620
-        );
621
-        // only set the first time
622
-        if ($this->_old_txn_status === null) {
623
-            $this->_old_txn_status = $old_txn_status;
624
-        }
625
-    }
626
-
627
-
628
-    /**
629
-     * @deprecated 4.9.12
630
-     * @return string
631
-     */
632
-    public function new_txn_status()
633
-    {
634
-        EE_Error::doing_it_wrong(
635
-            __METHOD__,
636
-            esc_html__(
637
-                'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
638
-                'event_espresso'
639
-            ),
640
-            '4.9.12'
641
-        );
642
-        return $this->_new_txn_status;
643
-    }
644
-
645
-
646
-    /**
647
-     * @deprecated 4.9.12
648
-     * @param string $new_txn_status
649
-     */
650
-    public function set_new_txn_status($new_txn_status)
651
-    {
652
-        EE_Error::doing_it_wrong(
653
-            __METHOD__,
654
-            esc_html__(
655
-                'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
656
-                'event_espresso'
657
-            ),
658
-            '4.9.12'
659
-        );
660
-        $this->_new_txn_status = $new_txn_status;
661
-    }
662
-
663
-
664
-    /**
665
-     * reg_status_updated
666
-     *
667
-     * @deprecated 4.9.12
668
-     * @return bool
669
-     */
670
-    public function txn_status_updated()
671
-    {
672
-        EE_Error::doing_it_wrong(
673
-            __METHOD__,
674
-            esc_html__(
675
-                'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
676
-                'event_espresso'
677
-            ),
678
-            '4.9.12'
679
-        );
680
-        return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
681
-    }
682
-
683
-
684
-    /**
685
-     * all_reg_steps_completed
686
-     * returns:
687
-     *    true if ALL reg steps have been marked as completed
688
-     *        or false if any step is not completed
689
-     *
690
-     * @deprecated 4.9.12
691
-     * @param EE_Transaction $transaction
692
-     * @return boolean
693
-     */
694
-    public function all_reg_steps_completed(EE_Transaction $transaction)
695
-    {
696
-        EE_Error::doing_it_wrong(
697
-            __METHOD__,
698
-            esc_html__(
699
-                'This logic has been moved into \EE_Transaction::all_reg_steps_completed(), please use that method instead.',
700
-                'event_espresso'
701
-            ),
702
-            '4.9.12',
703
-            '5.0.0'
704
-        );
705
-        return $transaction->all_reg_steps_completed();
706
-    }
707
-
708
-
709
-    /**
710
-     * all_reg_steps_completed_except
711
-     * returns:
712
-     *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
713
-     *        or false if any other step is not completed
714
-     *        or false if ALL steps are completed including the exception you are testing !!!
715
-     *
716
-     * @deprecated 4.9.12
717
-     * @param EE_Transaction $transaction
718
-     * @param string         $exception
719
-     * @return boolean
720
-     */
721
-    public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '')
722
-    {
723
-        EE_Error::doing_it_wrong(
724
-            __METHOD__,
725
-            esc_html__(
726
-                'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except(), please use that method instead.',
727
-                'event_espresso'
728
-            ),
729
-            '4.9.12',
730
-            '5.0.0'
731
-        );
732
-        return $transaction->all_reg_steps_completed_except($exception);
733
-    }
734
-
735
-
736
-    /**
737
-     * all_reg_steps_completed_except
738
-     * returns:
739
-     *        true if ALL reg steps, except the final step, have been marked as completed
740
-     *        or false if any step is not completed
741
-     *    or false if ALL steps are completed including the final step !!!
742
-     *
743
-     * @deprecated 4.9.12
744
-     * @param EE_Transaction $transaction
745
-     * @return boolean
746
-     */
747
-    public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction)
748
-    {
749
-        EE_Error::doing_it_wrong(
750
-            __METHOD__,
751
-            esc_html__(
752
-                'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except_final_step(), please use that method instead.',
753
-                'event_espresso'
754
-            ),
755
-            '4.9.12',
756
-            '5.0.0'
757
-        );
758
-        return $transaction->all_reg_steps_completed_except_final_step();
759
-    }
760
-
761
-
762
-    /**
763
-     * reg_step_completed
764
-     * returns:
765
-     *    true if a specific reg step has been marked as completed
766
-     *    a Unix timestamp if it has been initialized but not yet completed,
767
-     *    or false if it has not yet been initialized
768
-     *
769
-     * @deprecated 4.9.12
770
-     * @param EE_Transaction $transaction
771
-     * @param string         $reg_step_slug
772
-     * @return boolean | int
773
-     */
774
-    public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
775
-    {
776
-        EE_Error::doing_it_wrong(
777
-            __METHOD__,
778
-            esc_html__(
779
-                'This logic has been moved into \EE_Transaction::reg_step_completed(), please use that method instead.',
780
-                'event_espresso'
781
-            ),
782
-            '4.9.12',
783
-            '5.0.0'
784
-        );
785
-        return $transaction->reg_step_completed($reg_step_slug);
786
-    }
787
-
788
-
789
-    /**
790
-     * completed_final_reg_step
791
-     * returns:
792
-     *    true if the finalize_registration reg step has been marked as completed
793
-     *    a Unix timestamp if it has been initialized but not yet completed,
794
-     *    or false if it has not yet been initialized
795
-     *
796
-     * @deprecated 4.9.12
797
-     * @param EE_Transaction $transaction
798
-     * @return boolean | int
799
-     */
800
-    public function final_reg_step_completed(EE_Transaction $transaction)
801
-    {
802
-        EE_Error::doing_it_wrong(
803
-            __METHOD__,
804
-            esc_html__(
805
-                'This logic has been moved into \EE_Transaction::final_reg_step_completed(), please use that method instead.',
806
-                'event_espresso'
807
-            ),
808
-            '4.9.12',
809
-            '5.0.0'
810
-        );
811
-        return $transaction->final_reg_step_completed();
812
-    }
813
-
814
-
815
-    /**
816
-     * set_reg_step_initiated
817
-     * given a valid TXN_reg_step, this sets it's value to a unix timestamp
818
-     *
819
-     * @deprecated 4.9.12
820
-     * @access     public
821
-     * @param \EE_Transaction $transaction
822
-     * @param string          $reg_step_slug
823
-     * @return boolean
824
-     * @throws \EE_Error
825
-     */
826
-    public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug)
827
-    {
828
-        EE_Error::doing_it_wrong(
829
-            __METHOD__,
830
-            esc_html__(
831
-                'This logic has been moved into \EE_Transaction::set_reg_step_initiated(), please use that method instead.',
832
-                'event_espresso'
833
-            ),
834
-            '4.9.12',
835
-            '5.0.0'
836
-        );
837
-        return $transaction->set_reg_step_initiated($reg_step_slug);
838
-    }
839
-
840
-
841
-    /**
842
-     * set_reg_step_completed
843
-     * given a valid TXN_reg_step, this sets the step as completed
844
-     *
845
-     * @deprecated 4.9.12
846
-     * @access     public
847
-     * @param \EE_Transaction $transaction
848
-     * @param string          $reg_step_slug
849
-     * @return boolean
850
-     * @throws \EE_Error
851
-     */
852
-    public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
853
-    {
854
-        EE_Error::doing_it_wrong(
855
-            __METHOD__,
856
-            esc_html__(
857
-                'This logic has been moved into \EE_Transaction::set_reg_step_completed(), please use that method instead.',
858
-                'event_espresso'
859
-            ),
860
-            '4.9.12',
861
-            '5.0.0'
862
-        );
863
-        return $transaction->set_reg_step_completed($reg_step_slug);
864
-    }
865
-
866
-
867
-    /**
868
-     * set_reg_step_completed
869
-     * given a valid TXN_reg_step slug, this sets the step as NOT completed
870
-     *
871
-     * @deprecated 4.9.12
872
-     * @access     public
873
-     * @param \EE_Transaction $transaction
874
-     * @param string          $reg_step_slug
875
-     * @return boolean
876
-     * @throws \EE_Error
877
-     */
878
-    public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug)
879
-    {
880
-        EE_Error::doing_it_wrong(
881
-            __METHOD__,
882
-            esc_html__(
883
-                'This logic has been moved into \EE_Transaction::set_reg_step_not_completed(), please use that method instead.',
884
-                'event_espresso'
885
-            ),
886
-            '4.9.12',
887
-            '5.0.0'
888
-        );
889
-        return $transaction->set_reg_step_not_completed($reg_step_slug);
890
-    }
891
-
892
-
893
-    /**
894
-     * remove_reg_step
895
-     * given a valid TXN_reg_step slug, this will remove (unset)
896
-     * the reg step from the TXN reg step array
897
-     *
898
-     * @deprecated 4.9.12
899
-     * @access     public
900
-     * @param \EE_Transaction $transaction
901
-     * @param string          $reg_step_slug
902
-     * @return void
903
-     */
904
-    public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug)
905
-    {
906
-        EE_Error::doing_it_wrong(
907
-            __METHOD__,
908
-            esc_html__(
909
-                'This logic has been moved into \EE_Transaction::remove_reg_step(), please use that method instead.',
910
-                'event_espresso'
911
-            ),
912
-            '4.9.12',
913
-            '5.0.0'
914
-        );
915
-        $transaction->remove_reg_step($reg_step_slug);
916
-    }
917
-
918
-
919
-    /**
920
-     *    toggle_failed_transaction_status
921
-     * upgrades a TXNs status from failed to abandoned,
922
-     * meaning that contact information has been captured for at least one registrant
923
-     *
924
-     * @deprecated 4.9.12
925
-     * @access     public
926
-     * @param EE_Transaction $transaction
927
-     * @return    boolean
928
-     * @throws \EE_Error
929
-     */
930
-    public function toggle_failed_transaction_status(EE_Transaction $transaction)
931
-    {
932
-        EE_Error::doing_it_wrong(
933
-            __METHOD__,
934
-            esc_html__(
935
-                'This logic has been moved into \EE_Transaction::toggle_failed_transaction_status(), please use that method instead.',
936
-                'event_espresso'
937
-            ),
938
-            '4.9.12',
939
-            '5.0.0'
940
-        );
941
-        return $transaction->toggle_failed_transaction_status();
942
-    }
943
-
944
-
945
-    /**
946
-     * toggle_abandoned_transaction_status
947
-     * upgrades a TXNs status from failed or abandoned to incomplete
948
-     *
949
-     * @deprecated 4.9.12
950
-     * @access     public
951
-     * @param  EE_Transaction $transaction
952
-     * @return boolean
953
-     */
954
-    public function toggle_abandoned_transaction_status(EE_Transaction $transaction)
955
-    {
956
-        EE_Error::doing_it_wrong(
957
-            __METHOD__,
958
-            esc_html__(
959
-                'This logic has been moved into \EE_Transaction::toggle_abandoned_transaction_status(), please use that method instead.',
960
-                'event_espresso'
961
-            ),
962
-            '4.9.12',
963
-            '5.0.0'
964
-        );
965
-        return $transaction->toggle_abandoned_transaction_status();
966
-    }
19
+	/**
20
+	 * @var EE_Registration_Processor $_instance
21
+	 * @access    private
22
+	 */
23
+	private static $_instance;
24
+
25
+	/**
26
+	 * array of query WHERE params to use when retrieving cached registrations from a transaction
27
+	 *
28
+	 * @var array $registration_query_params
29
+	 * @access private
30
+	 */
31
+	private $_registration_query_params = array();
32
+
33
+	/**
34
+	 * @deprecated
35
+	 * @var string
36
+	 */
37
+	protected $_old_txn_status;
38
+
39
+	/**
40
+	 * @deprecated
41
+	 * @var string
42
+	 */
43
+	protected $_new_txn_status;
44
+
45
+
46
+	/**
47
+	 * @singleton method used to instantiate class object
48
+	 * @access    public
49
+	 * @param array $registration_query_params
50
+	 * @return EE_Transaction_Processor instance
51
+	 */
52
+	public static function instance($registration_query_params = array())
53
+	{
54
+		// check if class object is instantiated
55
+		if (! self::$_instance instanceof EE_Transaction_Processor) {
56
+			self::$_instance = new self($registration_query_params);
57
+		}
58
+		return self::$_instance;
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param array $registration_query_params
64
+	 */
65
+	private function __construct($registration_query_params = array())
66
+	{
67
+		// make sure some query params are set for retrieving registrations
68
+		$this->_set_registration_query_params($registration_query_params);
69
+	}
70
+
71
+
72
+	/**
73
+	 * @access private
74
+	 * @param array $registration_query_params
75
+	 */
76
+	private function _set_registration_query_params($registration_query_params)
77
+	{
78
+		$this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params
79
+			: array('order_by' => array('REG_count' => 'ASC'));
80
+	}
81
+
82
+
83
+	/**
84
+	 * manually_update_registration_statuses
85
+	 *
86
+	 * @access public
87
+	 * @param EE_Transaction $transaction
88
+	 * @param string         $new_reg_status
89
+	 * @param array          $registration_query_params array of query WHERE params to use
90
+	 *                                                  when retrieving cached registrations from a transaction
91
+	 * @return    boolean
92
+	 * @throws \EE_Error
93
+	 */
94
+	public function manually_update_registration_statuses(
95
+		EE_Transaction $transaction,
96
+		$new_reg_status = '',
97
+		$registration_query_params = array()
98
+	) {
99
+		$status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
100
+			'manually_update_registration_status',
101
+			$transaction,
102
+			$registration_query_params,
103
+			$new_reg_status
104
+		);
105
+		// send messages
106
+		/** @type EE_Registration_Processor $registration_processor */
107
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
108
+		$registration_processor->trigger_registration_update_notifications(
109
+			$transaction->primary_registration(),
110
+			array('manually_updated' => true)
111
+		);
112
+		do_action(
113
+			'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
114
+			$transaction,
115
+			$status_updates
116
+		);
117
+		return $status_updates;
118
+	}
119
+
120
+
121
+	/**
122
+	 * toggle_registration_statuses_for_default_approved_events
123
+	 *
124
+	 * @access public
125
+	 * @param EE_Transaction $transaction
126
+	 * @param array          $registration_query_params array of query WHERE params to use
127
+	 *                                                  when retrieving cached registrations from a transaction
128
+	 * @return    boolean
129
+	 * @throws \EE_Error
130
+	 */
131
+	public function toggle_registration_statuses_for_default_approved_events(
132
+		EE_Transaction $transaction,
133
+		$registration_query_params = array()
134
+	) {
135
+		$status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
136
+			'toggle_registration_status_for_default_approved_events',
137
+			$transaction,
138
+			$registration_query_params
139
+		);
140
+		do_action(
141
+			'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
142
+			$transaction,
143
+			$status_updates
144
+		);
145
+		return $status_updates;
146
+	}
147
+
148
+
149
+	/**
150
+	 * toggle_registration_statuses_if_no_monies_owing
151
+	 *
152
+	 * @access public
153
+	 * @param EE_Transaction $transaction
154
+	 * @param array          $registration_query_params array of query WHERE params to use
155
+	 *                                                  when retrieving cached registrations from a transaction
156
+	 * @return    boolean
157
+	 * @throws \EE_Error
158
+	 */
159
+	public function toggle_registration_statuses_if_no_monies_owing(
160
+		EE_Transaction $transaction,
161
+		$registration_query_params = array()
162
+	) {
163
+		$status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
164
+			'toggle_registration_status_if_no_monies_owing',
165
+			$transaction,
166
+			$registration_query_params
167
+		);
168
+		do_action(
169
+			'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing',
170
+			$transaction,
171
+			$status_updates
172
+		);
173
+		return $status_updates;
174
+	}
175
+
176
+
177
+	/**
178
+	 * update_transaction_and_registrations_after_checkout_or_payment
179
+	 * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
180
+	 *
181
+	 * @param EE_Transaction     $transaction
182
+	 * @param \EE_Payment | NULL $payment
183
+	 * @param array              $registration_query_params    array of query WHERE params to use
184
+	 *                                                         when retrieving cached registrations from a transaction
185
+	 * @param bool               $trigger_notifications        whether or not to call
186
+	 *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
187
+	 * @return array
188
+	 * @throws \EE_Error
189
+	 */
190
+	public function update_transaction_and_registrations_after_checkout_or_payment(
191
+		EE_Transaction $transaction,
192
+		$payment = null,
193
+		$registration_query_params = array(),
194
+		$trigger_notifications = true
195
+	) {
196
+		// make sure some query params are set for retrieving registrations
197
+		$this->_set_registration_query_params($registration_query_params);
198
+		// get final reg step status
199
+		$finalized = $transaction->final_reg_step_completed();
200
+		// if the 'finalize_registration' step has been initiated (has a timestamp)
201
+		// but has not yet been fully completed (TRUE)
202
+		if (is_int($finalized) && $finalized !== false && $finalized !== true) {
203
+			$transaction->set_reg_step_completed('finalize_registration');
204
+			$finalized = true;
205
+		}
206
+		$transaction->save();
207
+		// array of details to aid in decision making by systems
208
+		$update_params = array(
209
+			'old_txn_status'  => $transaction->old_txn_status(),
210
+			'new_txn_status'  => $transaction->status_ID(),
211
+			'finalized'       => $finalized,
212
+			'revisit'         => $this->_revisit,
213
+			'payment_updates' => $payment instanceof EE_Payment ? true : false,
214
+			'last_payment'    => $payment,
215
+		);
216
+		// now update the registrations and add the results to our $update_params
217
+		$update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor(
218
+			'update_registration_after_checkout_or_payment',
219
+			$transaction,
220
+			$this->_registration_query_params,
221
+			$update_params
222
+		);
223
+		if ($trigger_notifications) {
224
+			// send messages
225
+			/** @type EE_Registration_Processor $registration_processor */
226
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
227
+			$registration_processor->trigger_registration_update_notifications(
228
+				$transaction->primary_registration(),
229
+				$update_params
230
+			);
231
+		}
232
+		do_action(
233
+			'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
234
+			$transaction,
235
+			$update_params
236
+		);
237
+		return $update_params;
238
+	}
239
+
240
+
241
+	/**
242
+	 * update_transaction_after_registration_reopened
243
+	 * readjusts TXN and Line Item totals after a registration is changed from
244
+	 * cancelled or declined to another reg status such as pending payment or approved
245
+	 *
246
+	 * @param \EE_Registration $registration
247
+	 * @param array            $closed_reg_statuses
248
+	 * @param bool             $update_txn
249
+	 * @return bool
250
+	 * @throws \EE_Error
251
+	 */
252
+	public function update_transaction_after_reinstating_canceled_registration(
253
+		EE_Registration $registration,
254
+		$closed_reg_statuses = array(),
255
+		$update_txn = true
256
+	) {
257
+		// these reg statuses should not be considered in any calculations involving monies owing
258
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
259
+			: EEM_Registration::closed_reg_statuses();
260
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
261
+			return false;
262
+		}
263
+		try {
264
+			$transaction = $this->get_transaction_for_registration($registration);
265
+			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
266
+				$transaction,
267
+				$registration
268
+			);
269
+			// un-cancel the ticket
270
+			$success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item);
271
+		} catch (EE_Error $e) {
272
+			EE_Error::add_error(
273
+				sprintf(
274
+					esc_html__(
275
+						'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s',
276
+						'event_espresso'
277
+					),
278
+					$registration->ID(),
279
+					'<br />',
280
+					$e->getMessage()
281
+				),
282
+				__FILE__,
283
+				__FUNCTION__,
284
+				__LINE__
285
+			);
286
+			return false;
287
+		}
288
+		if ($update_txn) {
289
+			return $transaction->save() ? $success : false;
290
+		}
291
+		return $success;
292
+	}
293
+
294
+
295
+	/**
296
+	 * update_transaction_after_canceled_or_declined_registration
297
+	 * readjusts TXN and Line Item totals after a registration is cancelled or declined
298
+	 *
299
+	 * @param \EE_Registration $registration
300
+	 * @param array            $closed_reg_statuses
301
+	 * @param bool             $update_txn
302
+	 * @return bool
303
+	 * @throws \EE_Error
304
+	 */
305
+	public function update_transaction_after_canceled_or_declined_registration(
306
+		EE_Registration $registration,
307
+		$closed_reg_statuses = array(),
308
+		$update_txn = true
309
+	) {
310
+		// these reg statuses should not be considered in any calculations involving monies owing
311
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
312
+			: EEM_Registration::closed_reg_statuses();
313
+		if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
314
+			return false;
315
+		}
316
+		try {
317
+			$transaction = $this->get_transaction_for_registration($registration);
318
+			if (
319
+				apply_filters(
320
+					'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item',
321
+					true,
322
+					$registration,
323
+					$transaction
324
+				)
325
+			) {
326
+				$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
327
+					$transaction,
328
+					$registration
329
+				);
330
+				EEH_Line_Item::cancel_ticket_line_item($ticket_line_item);
331
+			}
332
+		} catch (EE_Error $e) {
333
+			EE_Error::add_error(
334
+				sprintf(
335
+					esc_html__(
336
+						'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s',
337
+						'event_espresso'
338
+					),
339
+					$registration->ID(),
340
+					'<br />',
341
+					$e->getMessage()
342
+				),
343
+				__FILE__,
344
+				__FUNCTION__,
345
+				__LINE__
346
+			);
347
+			return false;
348
+		}
349
+		if ($update_txn) {
350
+			return $transaction->save() ? true : false;
351
+		}
352
+		return true;
353
+	}
354
+
355
+
356
+	/**
357
+	 * get_transaction_for_registration
358
+	 *
359
+	 * @access    public
360
+	 * @param    EE_Registration $registration
361
+	 * @return    EE_Transaction
362
+	 * @throws    EE_Error
363
+	 */
364
+	public function get_transaction_for_registration(EE_Registration $registration)
365
+	{
366
+		$transaction = $registration->transaction();
367
+		if (! $transaction instanceof EE_Transaction) {
368
+			throw new EE_Error(
369
+				sprintf(
370
+					esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
371
+					$registration->ID()
372
+				)
373
+			);
374
+		}
375
+		return $transaction;
376
+	}
377
+
378
+
379
+	/**
380
+	 * get_ticket_line_item_for_transaction_registration
381
+	 *
382
+	 * @access    public
383
+	 * @param    EE_Transaction  $transaction
384
+	 * @param    EE_Registration $registration
385
+	 * @return    EE_Line_Item
386
+	 * @throws    EE_Error
387
+	 */
388
+	public function get_ticket_line_item_for_transaction_registration(
389
+		EE_Transaction $transaction,
390
+		EE_Registration $registration
391
+	) {
392
+		EE_Registry::instance()->load_helper('Line_Item');
393
+		$ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction(
394
+			$transaction->ID(),
395
+			$registration->ticket_ID()
396
+		);
397
+		if (! $ticket_line_item instanceof EE_Line_Item) {
398
+			throw new EE_Error(
399
+				sprintf(
400
+					esc_html__(
401
+						'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
402
+						'event_espresso'
403
+					),
404
+					$transaction->ID(),
405
+					$registration->ticket_ID()
406
+				)
407
+			);
408
+		}
409
+		return $ticket_line_item;
410
+	}
411
+
412
+
413
+	/**
414
+	 * cancel_transaction_if_all_registrations_canceled
415
+	 * cycles thru related registrations and checks their statuses
416
+	 * if ALL registrations are Cancelled or Declined, then this sets the TXN status to
417
+	 *
418
+	 * @access    public
419
+	 * @param    EE_Transaction $transaction
420
+	 * @param    string         $new_TXN_status
421
+	 * @param    array          $registration_query_params - array of query WHERE params to use when
422
+	 *                                                     retrieving cached registrations from a transaction
423
+	 * @param    array          $closed_reg_statuses
424
+	 * @param    bool           $update_txn
425
+	 * @return    bool            true if TXN status was updated, false if not
426
+	 */
427
+	public function toggle_transaction_status_if_all_registrations_canceled_or_declined(
428
+		EE_Transaction $transaction,
429
+		$new_TXN_status = '',
430
+		$registration_query_params = array(),
431
+		$closed_reg_statuses = array(),
432
+		$update_txn = true
433
+	) {
434
+		// make sure some query params are set for retrieving registrations
435
+		$this->_set_registration_query_params($registration_query_params);
436
+		// these reg statuses should not be considered in any calculations involving monies owing
437
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
438
+			: EEM_Registration::closed_reg_statuses();
439
+		// loop through cached registrations
440
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
441
+			if (
442
+				$registration instanceof EE_Registration
443
+				&& ! in_array($registration->status_ID(), $closed_reg_statuses)
444
+			) {
445
+				return false;
446
+			}
447
+		}
448
+		if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) {
449
+			$transaction->set_status($new_TXN_status);
450
+		}
451
+		if ($update_txn) {
452
+			return $transaction->save() ? true : false;
453
+		}
454
+		return true;
455
+	}
456
+
457
+
458
+	/**
459
+	 * _call_method_on_registrations_via_Registration_Processor
460
+	 * cycles thru related registrations and calls the requested method on each
461
+	 *
462
+	 * @access private
463
+	 * @param string         $method_name
464
+	 * @param EE_Transaction $transaction
465
+	 * @param array          $registration_query_params array of query WHERE params to use
466
+	 *                                                  when retrieving cached registrations from a transaction
467
+	 * @param string         $additional_param
468
+	 * @throws \EE_Error
469
+	 * @return boolean
470
+	 */
471
+	private function _call_method_on_registrations_via_Registration_Processor(
472
+		$method_name,
473
+		EE_Transaction $transaction,
474
+		$registration_query_params = array(),
475
+		$additional_param = null
476
+	) {
477
+		$response = false;
478
+		/** @type EE_Registration_Processor $registration_processor */
479
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
480
+		// check that method exists
481
+		if (! method_exists($registration_processor, $method_name)) {
482
+			throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso'));
483
+		}
484
+		// make sure some query params are set for retrieving registrations
485
+		$this->_set_registration_query_params($registration_query_params);
486
+		// loop through cached registrations
487
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
488
+			if ($registration instanceof EE_Registration) {
489
+				if ($additional_param) {
490
+					$response = $registration_processor->{$method_name}($registration, $additional_param)
491
+						? true
492
+						: $response;
493
+				} else {
494
+					$response = $registration_processor->{$method_name}($registration)
495
+						? true
496
+						: $response;
497
+				}
498
+			}
499
+		}
500
+		return $response;
501
+	}
502
+
503
+
504
+	/**
505
+	 * set_transaction_payment_method_based_on_registration_statuses
506
+	 * sets or unsets the PMD_ID field on the TXN based on the related REG statuses
507
+	 * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null,
508
+	 * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either:
509
+	 *        the first "default" Payment Method
510
+	 *        the first active Payment Method
511
+	 *    whichever is found first.
512
+	 *
513
+	 * @param  EE_Registration $edited_registration
514
+	 * @return void
515
+	 * @throws \EE_Error
516
+	 */
517
+	public function set_transaction_payment_method_based_on_registration_statuses(
518
+		EE_Registration $edited_registration
519
+	) {
520
+		if ($edited_registration instanceof EE_Registration) {
521
+			$transaction = $edited_registration->transaction();
522
+			if ($transaction instanceof EE_Transaction) {
523
+				$all_not_approved = true;
524
+				foreach ($transaction->registrations() as $registration) {
525
+					if ($registration instanceof EE_Registration) {
526
+						// if any REG != "Not Approved" then toggle to false
527
+						$all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
528
+					}
529
+				}
530
+				// if ALL Registrations are "Not Approved"
531
+				if ($all_not_approved) {
532
+					$transaction->set_payment_method_ID(null);
533
+					$transaction->save();
534
+				} else {
535
+					$available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
536
+						$transaction,
537
+						EEM_Payment_Method::scope_cart
538
+					);
539
+					if (! empty($available_payment_methods)) {
540
+						$PMD_ID = 0;
541
+						foreach ($available_payment_methods as $available_payment_method) {
542
+							if (
543
+								$available_payment_method instanceof EE_Payment_Method
544
+								&& $available_payment_method->open_by_default()
545
+							) {
546
+								$PMD_ID = $available_payment_method->ID();
547
+								break;
548
+							}
549
+						}
550
+						if (! $PMD_ID) {
551
+							$first_payment_method = reset($available_payment_methods);
552
+							if ($first_payment_method instanceof EE_Payment_Method) {
553
+								$PMD_ID = $first_payment_method->ID();
554
+							} else {
555
+								EE_Error::add_error(
556
+									esc_html__(
557
+										'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.',
558
+										'event_espresso'
559
+									),
560
+									__FILE__,
561
+									__LINE__,
562
+									__FUNCTION__
563
+								);
564
+							}
565
+						}
566
+						$transaction->set_payment_method_ID($PMD_ID);
567
+						$transaction->save();
568
+					} else {
569
+						EE_Error::add_error(
570
+							esc_html__(
571
+								'Please activate at least one Payment Method in order for things to operate correctly.',
572
+								'event_espresso'
573
+							),
574
+							__FILE__,
575
+							__LINE__,
576
+							__FUNCTION__
577
+						);
578
+					}
579
+				}
580
+			}
581
+		}
582
+	}
583
+
584
+
585
+
586
+	/********************************** DEPRECATED METHODS **********************************/
587
+
588
+
589
+	/**
590
+	 * @deprecated 4.9.12
591
+	 * @return string
592
+	 */
593
+	public function old_txn_status()
594
+	{
595
+		EE_Error::doing_it_wrong(
596
+			__METHOD__,
597
+			esc_html__(
598
+				'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
599
+				'event_espresso'
600
+			),
601
+			'4.9.12'
602
+		);
603
+		return $this->_old_txn_status;
604
+	}
605
+
606
+
607
+	/**
608
+	 * @deprecated 4.9.12
609
+	 * @param string $old_txn_status
610
+	 */
611
+	public function set_old_txn_status($old_txn_status)
612
+	{
613
+		EE_Error::doing_it_wrong(
614
+			__METHOD__,
615
+			esc_html__(
616
+				'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
617
+				'event_espresso'
618
+			),
619
+			'4.9.12'
620
+		);
621
+		// only set the first time
622
+		if ($this->_old_txn_status === null) {
623
+			$this->_old_txn_status = $old_txn_status;
624
+		}
625
+	}
626
+
627
+
628
+	/**
629
+	 * @deprecated 4.9.12
630
+	 * @return string
631
+	 */
632
+	public function new_txn_status()
633
+	{
634
+		EE_Error::doing_it_wrong(
635
+			__METHOD__,
636
+			esc_html__(
637
+				'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
638
+				'event_espresso'
639
+			),
640
+			'4.9.12'
641
+		);
642
+		return $this->_new_txn_status;
643
+	}
644
+
645
+
646
+	/**
647
+	 * @deprecated 4.9.12
648
+	 * @param string $new_txn_status
649
+	 */
650
+	public function set_new_txn_status($new_txn_status)
651
+	{
652
+		EE_Error::doing_it_wrong(
653
+			__METHOD__,
654
+			esc_html__(
655
+				'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
656
+				'event_espresso'
657
+			),
658
+			'4.9.12'
659
+		);
660
+		$this->_new_txn_status = $new_txn_status;
661
+	}
662
+
663
+
664
+	/**
665
+	 * reg_status_updated
666
+	 *
667
+	 * @deprecated 4.9.12
668
+	 * @return bool
669
+	 */
670
+	public function txn_status_updated()
671
+	{
672
+		EE_Error::doing_it_wrong(
673
+			__METHOD__,
674
+			esc_html__(
675
+				'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
676
+				'event_espresso'
677
+			),
678
+			'4.9.12'
679
+		);
680
+		return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
681
+	}
682
+
683
+
684
+	/**
685
+	 * all_reg_steps_completed
686
+	 * returns:
687
+	 *    true if ALL reg steps have been marked as completed
688
+	 *        or false if any step is not completed
689
+	 *
690
+	 * @deprecated 4.9.12
691
+	 * @param EE_Transaction $transaction
692
+	 * @return boolean
693
+	 */
694
+	public function all_reg_steps_completed(EE_Transaction $transaction)
695
+	{
696
+		EE_Error::doing_it_wrong(
697
+			__METHOD__,
698
+			esc_html__(
699
+				'This logic has been moved into \EE_Transaction::all_reg_steps_completed(), please use that method instead.',
700
+				'event_espresso'
701
+			),
702
+			'4.9.12',
703
+			'5.0.0'
704
+		);
705
+		return $transaction->all_reg_steps_completed();
706
+	}
707
+
708
+
709
+	/**
710
+	 * all_reg_steps_completed_except
711
+	 * returns:
712
+	 *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
713
+	 *        or false if any other step is not completed
714
+	 *        or false if ALL steps are completed including the exception you are testing !!!
715
+	 *
716
+	 * @deprecated 4.9.12
717
+	 * @param EE_Transaction $transaction
718
+	 * @param string         $exception
719
+	 * @return boolean
720
+	 */
721
+	public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '')
722
+	{
723
+		EE_Error::doing_it_wrong(
724
+			__METHOD__,
725
+			esc_html__(
726
+				'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except(), please use that method instead.',
727
+				'event_espresso'
728
+			),
729
+			'4.9.12',
730
+			'5.0.0'
731
+		);
732
+		return $transaction->all_reg_steps_completed_except($exception);
733
+	}
734
+
735
+
736
+	/**
737
+	 * all_reg_steps_completed_except
738
+	 * returns:
739
+	 *        true if ALL reg steps, except the final step, have been marked as completed
740
+	 *        or false if any step is not completed
741
+	 *    or false if ALL steps are completed including the final step !!!
742
+	 *
743
+	 * @deprecated 4.9.12
744
+	 * @param EE_Transaction $transaction
745
+	 * @return boolean
746
+	 */
747
+	public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction)
748
+	{
749
+		EE_Error::doing_it_wrong(
750
+			__METHOD__,
751
+			esc_html__(
752
+				'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except_final_step(), please use that method instead.',
753
+				'event_espresso'
754
+			),
755
+			'4.9.12',
756
+			'5.0.0'
757
+		);
758
+		return $transaction->all_reg_steps_completed_except_final_step();
759
+	}
760
+
761
+
762
+	/**
763
+	 * reg_step_completed
764
+	 * returns:
765
+	 *    true if a specific reg step has been marked as completed
766
+	 *    a Unix timestamp if it has been initialized but not yet completed,
767
+	 *    or false if it has not yet been initialized
768
+	 *
769
+	 * @deprecated 4.9.12
770
+	 * @param EE_Transaction $transaction
771
+	 * @param string         $reg_step_slug
772
+	 * @return boolean | int
773
+	 */
774
+	public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
775
+	{
776
+		EE_Error::doing_it_wrong(
777
+			__METHOD__,
778
+			esc_html__(
779
+				'This logic has been moved into \EE_Transaction::reg_step_completed(), please use that method instead.',
780
+				'event_espresso'
781
+			),
782
+			'4.9.12',
783
+			'5.0.0'
784
+		);
785
+		return $transaction->reg_step_completed($reg_step_slug);
786
+	}
787
+
788
+
789
+	/**
790
+	 * completed_final_reg_step
791
+	 * returns:
792
+	 *    true if the finalize_registration reg step has been marked as completed
793
+	 *    a Unix timestamp if it has been initialized but not yet completed,
794
+	 *    or false if it has not yet been initialized
795
+	 *
796
+	 * @deprecated 4.9.12
797
+	 * @param EE_Transaction $transaction
798
+	 * @return boolean | int
799
+	 */
800
+	public function final_reg_step_completed(EE_Transaction $transaction)
801
+	{
802
+		EE_Error::doing_it_wrong(
803
+			__METHOD__,
804
+			esc_html__(
805
+				'This logic has been moved into \EE_Transaction::final_reg_step_completed(), please use that method instead.',
806
+				'event_espresso'
807
+			),
808
+			'4.9.12',
809
+			'5.0.0'
810
+		);
811
+		return $transaction->final_reg_step_completed();
812
+	}
813
+
814
+
815
+	/**
816
+	 * set_reg_step_initiated
817
+	 * given a valid TXN_reg_step, this sets it's value to a unix timestamp
818
+	 *
819
+	 * @deprecated 4.9.12
820
+	 * @access     public
821
+	 * @param \EE_Transaction $transaction
822
+	 * @param string          $reg_step_slug
823
+	 * @return boolean
824
+	 * @throws \EE_Error
825
+	 */
826
+	public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug)
827
+	{
828
+		EE_Error::doing_it_wrong(
829
+			__METHOD__,
830
+			esc_html__(
831
+				'This logic has been moved into \EE_Transaction::set_reg_step_initiated(), please use that method instead.',
832
+				'event_espresso'
833
+			),
834
+			'4.9.12',
835
+			'5.0.0'
836
+		);
837
+		return $transaction->set_reg_step_initiated($reg_step_slug);
838
+	}
839
+
840
+
841
+	/**
842
+	 * set_reg_step_completed
843
+	 * given a valid TXN_reg_step, this sets the step as completed
844
+	 *
845
+	 * @deprecated 4.9.12
846
+	 * @access     public
847
+	 * @param \EE_Transaction $transaction
848
+	 * @param string          $reg_step_slug
849
+	 * @return boolean
850
+	 * @throws \EE_Error
851
+	 */
852
+	public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
853
+	{
854
+		EE_Error::doing_it_wrong(
855
+			__METHOD__,
856
+			esc_html__(
857
+				'This logic has been moved into \EE_Transaction::set_reg_step_completed(), please use that method instead.',
858
+				'event_espresso'
859
+			),
860
+			'4.9.12',
861
+			'5.0.0'
862
+		);
863
+		return $transaction->set_reg_step_completed($reg_step_slug);
864
+	}
865
+
866
+
867
+	/**
868
+	 * set_reg_step_completed
869
+	 * given a valid TXN_reg_step slug, this sets the step as NOT completed
870
+	 *
871
+	 * @deprecated 4.9.12
872
+	 * @access     public
873
+	 * @param \EE_Transaction $transaction
874
+	 * @param string          $reg_step_slug
875
+	 * @return boolean
876
+	 * @throws \EE_Error
877
+	 */
878
+	public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug)
879
+	{
880
+		EE_Error::doing_it_wrong(
881
+			__METHOD__,
882
+			esc_html__(
883
+				'This logic has been moved into \EE_Transaction::set_reg_step_not_completed(), please use that method instead.',
884
+				'event_espresso'
885
+			),
886
+			'4.9.12',
887
+			'5.0.0'
888
+		);
889
+		return $transaction->set_reg_step_not_completed($reg_step_slug);
890
+	}
891
+
892
+
893
+	/**
894
+	 * remove_reg_step
895
+	 * given a valid TXN_reg_step slug, this will remove (unset)
896
+	 * the reg step from the TXN reg step array
897
+	 *
898
+	 * @deprecated 4.9.12
899
+	 * @access     public
900
+	 * @param \EE_Transaction $transaction
901
+	 * @param string          $reg_step_slug
902
+	 * @return void
903
+	 */
904
+	public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug)
905
+	{
906
+		EE_Error::doing_it_wrong(
907
+			__METHOD__,
908
+			esc_html__(
909
+				'This logic has been moved into \EE_Transaction::remove_reg_step(), please use that method instead.',
910
+				'event_espresso'
911
+			),
912
+			'4.9.12',
913
+			'5.0.0'
914
+		);
915
+		$transaction->remove_reg_step($reg_step_slug);
916
+	}
917
+
918
+
919
+	/**
920
+	 *    toggle_failed_transaction_status
921
+	 * upgrades a TXNs status from failed to abandoned,
922
+	 * meaning that contact information has been captured for at least one registrant
923
+	 *
924
+	 * @deprecated 4.9.12
925
+	 * @access     public
926
+	 * @param EE_Transaction $transaction
927
+	 * @return    boolean
928
+	 * @throws \EE_Error
929
+	 */
930
+	public function toggle_failed_transaction_status(EE_Transaction $transaction)
931
+	{
932
+		EE_Error::doing_it_wrong(
933
+			__METHOD__,
934
+			esc_html__(
935
+				'This logic has been moved into \EE_Transaction::toggle_failed_transaction_status(), please use that method instead.',
936
+				'event_espresso'
937
+			),
938
+			'4.9.12',
939
+			'5.0.0'
940
+		);
941
+		return $transaction->toggle_failed_transaction_status();
942
+	}
943
+
944
+
945
+	/**
946
+	 * toggle_abandoned_transaction_status
947
+	 * upgrades a TXNs status from failed or abandoned to incomplete
948
+	 *
949
+	 * @deprecated 4.9.12
950
+	 * @access     public
951
+	 * @param  EE_Transaction $transaction
952
+	 * @return boolean
953
+	 */
954
+	public function toggle_abandoned_transaction_status(EE_Transaction $transaction)
955
+	{
956
+		EE_Error::doing_it_wrong(
957
+			__METHOD__,
958
+			esc_html__(
959
+				'This logic has been moved into \EE_Transaction::toggle_abandoned_transaction_status(), please use that method instead.',
960
+				'event_espresso'
961
+			),
962
+			'4.9.12',
963
+			'5.0.0'
964
+		);
965
+		return $transaction->toggle_abandoned_transaction_status();
966
+	}
967 967
 }
Please login to merge, or discard this patch.
core/business/EE_Transaction_Payments.class.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public static function instance()
43 43
     {
44 44
         // check if class object is instantiated
45
-        if (! self::$_instance instanceof EE_Transaction_Payments) {
45
+        if ( ! self::$_instance instanceof EE_Transaction_Payments) {
46 46
             self::$_instance = new self();
47 47
         }
48 48
         return self::$_instance;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true)
62 62
     {
63 63
         $total_line_item = $transaction->total_line_item();
64
-        if (! $total_line_item instanceof EE_Line_Item) {
64
+        if ( ! $total_line_item instanceof EE_Line_Item) {
65 65
             EE_Error::add_error(
66 66
                 sprintf(
67 67
                     esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'),
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true)
101 101
     {
102 102
         // verify transaction
103
-        if (! $transaction instanceof EE_Transaction) {
103
+        if ( ! $transaction instanceof EE_Transaction) {
104 104
             EE_Error::add_error(
105 105
                 esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
106 106
                 __FILE__,
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
116 116
             $transaction->set_paid($total_paid);
117 117
             // maybe update status, and make sure to save transaction if not done already
118
-            if (! $transaction->update_status_based_on_total_paid($update_txn)) {
118
+            if ( ! $transaction->update_status_based_on_total_paid($update_txn)) {
119 119
                 if ($update_txn) {
120 120
                     return $transaction->save() ? true : false;
121 121
                 }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         $payment_status = EEM_Payment::status_id_approved
145 145
     ) {
146 146
         // verify transaction
147
-        if (! $transaction instanceof EE_Transaction) {
147
+        if ( ! $transaction instanceof EE_Transaction) {
148 148
             EE_Error::add_error(
149 149
                 esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
150 150
                 __FILE__,
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     public function delete_payment_and_update_transaction(EE_Payment $payment)
178 178
     {
179 179
         // verify payment
180
-        if (! $payment instanceof EE_Payment) {
180
+        if ( ! $payment instanceof EE_Payment) {
181 181
             EE_Error::add_error(
182 182
                 esc_html__('A valid Payment object was not received.', 'event_espresso'),
183 183
                 __FILE__,
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
             );
187 187
             return false;
188 188
         }
189
-        if (! $this->delete_registration_payments_and_update_registrations($payment)) {
189
+        if ( ! $this->delete_registration_payments_and_update_registrations($payment)) {
190 190
             return false;
191 191
         }
192
-        if (! $payment->delete()) {
192
+        if ( ! $payment->delete()) {
193 193
             EE_Error::add_error(
194 194
                 esc_html__('The payment could not be deleted.', 'event_espresso'),
195 195
                 __FILE__,
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
         // if this fails, that just means that the transaction didn't get its status changed and/or updated.
215 215
         // however the payment was still deleted.
216
-        if (! $this->calculate_total_payments_and_update_status($transaction)) {
216
+        if ( ! $this->calculate_total_payments_and_update_status($transaction)) {
217 217
             EE_Error::add_attention(
218 218
                 esc_html__(
219 219
                     'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..',
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params
256 256
             : array(array('PAY_ID' => $payment->ID()));
257 257
         $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
258
-        if (! empty($registration_payments)) {
258
+        if ( ! empty($registration_payments)) {
259 259
             foreach ($registration_payments as $registration_payment) {
260 260
                 if ($registration_payment instanceof EE_Registration_Payment) {
261 261
                     $amount_paid = $registration_payment->amount();
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
322 322
     {
323 323
         EE_Error::doing_it_wrong(
324
-            __CLASS__ . '::' . __FUNCTION__,
324
+            __CLASS__.'::'.__FUNCTION__,
325 325
             sprintf(
326 326
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
327 327
                 'EE_Transaction::update_status_based_on_total_paid()'
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
             '5.0.0'
331 331
         );
332 332
         // verify transaction
333
-        if (! $transaction instanceof EE_Transaction) {
333
+        if ( ! $transaction instanceof EE_Transaction) {
334 334
             EE_Error::add_error(
335 335
                 esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
336 336
                 __FILE__,
Please login to merge, or discard this patch.
Indentation   +420 added lines, -420 removed lines patch added patch discarded remove patch
@@ -14,424 +14,424 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Transaction_Payments
16 16
 {
17
-    /**
18
-     * @var EE_Transaction_Payments $_instance
19
-     * @access    private
20
-     */
21
-    private static $_instance;
22
-
23
-    /**
24
-     * @deprecated
25
-     * @var string
26
-     */
27
-    protected $_old_txn_status;
28
-
29
-    /**
30
-     * @deprecated
31
-     * @var string
32
-     */
33
-    protected $_new_txn_status;
34
-
35
-
36
-    /**
37
-     * @singleton method used to instantiate class object
38
-     * @access    public
39
-     * @return EE_Transaction_Payments instance
40
-     */
41
-    public static function instance()
42
-    {
43
-        // check if class object is instantiated
44
-        if (! self::$_instance instanceof EE_Transaction_Payments) {
45
-            self::$_instance = new self();
46
-        }
47
-        return self::$_instance;
48
-    }
49
-
50
-
51
-    /**
52
-     * recalculate_transaction_total
53
-     *
54
-     * @access private
55
-     * @param EE_Transaction $transaction
56
-     * @param bool           $update_txn
57
-     * @return bool true if TXN total was updated, false if not
58
-     * @throws \EE_Error
59
-     */
60
-    public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true)
61
-    {
62
-        $total_line_item = $transaction->total_line_item();
63
-        if (! $total_line_item instanceof EE_Line_Item) {
64
-            EE_Error::add_error(
65
-                sprintf(
66
-                    esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'),
67
-                    $transaction->ID()
68
-                ),
69
-                __FILE__,
70
-                __FUNCTION__,
71
-                __LINE__
72
-            );
73
-            return false;
74
-        }
75
-        $new_total = $total_line_item->recalculate_total_including_taxes();
76
-        $transaction->set_total($new_total);
77
-        if ($update_txn) {
78
-            return $transaction->save() ? true : false;
79
-        }
80
-        return false;
81
-    }
82
-
83
-
84
-    /**
85
-     * Updates the provided EE_Transaction with all the applicable payments
86
-     * returns a boolean for whether the TXN was saved to the db
87
-     * (meaning a status change occurred)
88
-     * or not saved (which could **still** mean that
89
-     * the TXN status changed, but just was not yet saved).
90
-     * So if passing a value of false for the $update_txn param,
91
-     * then client code needs to take responsibility for saving the TXN
92
-     * regardless of what happens within EE_Transaction_Payments;
93
-     *
94
-     * @param            EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID
95
-     * @param    boolean $update_txn whether to save the TXN
96
-     * @return    boolean        whether the TXN was saved
97
-     * @throws \EE_Error
98
-     */
99
-    public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true)
100
-    {
101
-        // verify transaction
102
-        if (! $transaction instanceof EE_Transaction) {
103
-            EE_Error::add_error(
104
-                esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
105
-                __FILE__,
106
-                __FUNCTION__,
107
-                __LINE__
108
-            );
109
-            return false;
110
-        }
111
-        // calculate total paid
112
-        $total_paid = $this->recalculate_total_payments_for_transaction($transaction);
113
-        // if total paid has changed
114
-        if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
115
-            $transaction->set_paid($total_paid);
116
-            // maybe update status, and make sure to save transaction if not done already
117
-            if (! $transaction->update_status_based_on_total_paid($update_txn)) {
118
-                if ($update_txn) {
119
-                    return $transaction->save() ? true : false;
120
-                }
121
-            } else {
122
-                // the status got updated and was saved by
123
-                // update_transaction_status_based_on_total_paid()
124
-                return true;
125
-            }
126
-        }
127
-        return false;
128
-    }
129
-
130
-
131
-    /**
132
-     * recalculate_total_payments_for_transaction
133
-     *
134
-     * @access public
135
-     * @param EE_Transaction $transaction
136
-     * @param string         $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved).
137
-     *                                       By default, searches for approved payments
138
-     * @return float|false   float on success, false on fail
139
-     * @throws \EE_Error
140
-     */
141
-    public function recalculate_total_payments_for_transaction(
142
-        EE_Transaction $transaction,
143
-        $payment_status = EEM_Payment::status_id_approved
144
-    ) {
145
-        // verify transaction
146
-        if (! $transaction instanceof EE_Transaction) {
147
-            EE_Error::add_error(
148
-                esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
149
-                __FILE__,
150
-                __FUNCTION__,
151
-                __LINE__
152
-            );
153
-            return false;
154
-        }
155
-        // ensure Payment model is loaded
156
-        EE_Registry::instance()->load_model('Payment');
157
-        // calls EEM_Base::sum()
158
-        return EEM_Payment::instance()->sum(
159
-            // query params
160
-            array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)),
161
-            // field to sum
162
-            'PAY_amount'
163
-        );
164
-    }
165
-
166
-
167
-    /**
168
-     * delete_payment_and_update_transaction
169
-     * Before deleting the selected payment, we fetch it's transaction,
170
-     * then delete the payment, and update the transactions' amount paid.
171
-     *
172
-     * @param EE_Payment $payment
173
-     * @return boolean
174
-     * @throws \EE_Error
175
-     */
176
-    public function delete_payment_and_update_transaction(EE_Payment $payment)
177
-    {
178
-        // verify payment
179
-        if (! $payment instanceof EE_Payment) {
180
-            EE_Error::add_error(
181
-                esc_html__('A valid Payment object was not received.', 'event_espresso'),
182
-                __FILE__,
183
-                __FUNCTION__,
184
-                __LINE__
185
-            );
186
-            return false;
187
-        }
188
-        if (! $this->delete_registration_payments_and_update_registrations($payment)) {
189
-            return false;
190
-        }
191
-        if (! $payment->delete()) {
192
-            EE_Error::add_error(
193
-                esc_html__('The payment could not be deleted.', 'event_espresso'),
194
-                __FILE__,
195
-                __FUNCTION__,
196
-                __LINE__
197
-            );
198
-            return false;
199
-        }
200
-
201
-        $transaction = $payment->transaction();
202
-        $TXN_status = $transaction->status_ID();
203
-        if (
204
-            $TXN_status === EEM_Transaction::abandoned_status_code
205
-            || $TXN_status === EEM_Transaction::failed_status_code
206
-            || $payment->amount() === 0
207
-        ) {
208
-            EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso'));
209
-            return true;
210
-        }
211
-
212
-
213
-        // if this fails, that just means that the transaction didn't get its status changed and/or updated.
214
-        // however the payment was still deleted.
215
-        if (! $this->calculate_total_payments_and_update_status($transaction)) {
216
-            EE_Error::add_attention(
217
-                esc_html__(
218
-                    'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..',
219
-                    'event_espresso'
220
-                ),
221
-                __FILE__,
222
-                __FUNCTION__,
223
-                __LINE__
224
-            );
225
-            return true;
226
-        }
227
-
228
-        EE_Error::add_success(
229
-            esc_html__(
230
-                'The Payment was successfully deleted, and the Transaction has been updated accordingly.',
231
-                'event_espresso'
232
-            )
233
-        );
234
-        return true;
235
-    }
236
-
237
-
238
-    /**
239
-     * delete_registration_payments_and_update_registrations
240
-     *
241
-     * removes all registration payment records associated with a payment
242
-     * and subtracts their amounts from the corresponding registrations REG_paid field
243
-     *
244
-     * @param EE_Payment $payment
245
-     * @param array      $reg_payment_query_params
246
-     * @return bool
247
-     * @throws \EE_Error
248
-     */
249
-    public function delete_registration_payments_and_update_registrations(
250
-        EE_Payment $payment,
251
-        $reg_payment_query_params = array()
252
-    ) {
253
-        $save_payment = false;
254
-        $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params
255
-            : array(array('PAY_ID' => $payment->ID()));
256
-        $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
257
-        if (! empty($registration_payments)) {
258
-            foreach ($registration_payments as $registration_payment) {
259
-                if ($registration_payment instanceof EE_Registration_Payment) {
260
-                    $amount_paid = $registration_payment->amount();
261
-                    $registration = $registration_payment->registration();
262
-                    if ($registration instanceof EE_Registration) {
263
-                        $registration->set_paid($registration->paid() - $amount_paid);
264
-                        if ($registration->save() !== false) {
265
-                            $registration_payment->delete_permanently();
266
-                            $save_payment = true;
267
-                        }
268
-                    } else {
269
-                        EE_Error::add_error(
270
-                            sprintf(
271
-                                esc_html__(
272
-                                    'An invalid Registration object was associated with Registration Payment ID# %1$d.',
273
-                                    'event_espresso'
274
-                                ),
275
-                                $registration_payment->ID()
276
-                            ),
277
-                            __FILE__,
278
-                            __FUNCTION__,
279
-                            __LINE__
280
-                        );
281
-                        return false;
282
-                    }
283
-                } else {
284
-                    EE_Error::add_error(
285
-                        sprintf(
286
-                            esc_html__(
287
-                                'An invalid Registration Payment object was associated with payment ID# %1$d.',
288
-                                'event_espresso'
289
-                            ),
290
-                            $payment->ID()
291
-                        ),
292
-                        __FILE__,
293
-                        __FUNCTION__,
294
-                        __LINE__
295
-                    );
296
-                    return false;
297
-                }
298
-            }
299
-        }
300
-        if ($save_payment) {
301
-            $payment->save();
302
-        }
303
-        return true;
304
-    }
305
-
306
-
307
-
308
-    /********************************** DEPRECATED METHODS **********************************/
309
-
310
-
311
-    /**
312
-     * possibly toggles TXN status
313
-     *
314
-     * @deprecated 4.9.1
315
-     * @param EE_Transaction $transaction
316
-     * @param    boolean     $update_txn whether to save the TXN
317
-     * @return    boolean        whether the TXN was saved
318
-     * @throws \EE_Error
319
-     */
320
-    public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
321
-    {
322
-        EE_Error::doing_it_wrong(
323
-            __CLASS__ . '::' . __FUNCTION__,
324
-            sprintf(
325
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
326
-                'EE_Transaction::update_status_based_on_total_paid()'
327
-            ),
328
-            '4.9.1',
329
-            '5.0.0'
330
-        );
331
-        // verify transaction
332
-        if (! $transaction instanceof EE_Transaction) {
333
-            EE_Error::add_error(
334
-                esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
335
-                __FILE__,
336
-                __FUNCTION__,
337
-                __LINE__
338
-            );
339
-            return false;
340
-        }
341
-        // set transaction status based on comparison of TXN_paid vs TXN_total
342
-        return $transaction->update_status_based_on_total_paid($update_txn);
343
-    }
344
-
345
-
346
-    /**
347
-     * @deprecated 4.9.12
348
-     * @return string
349
-     */
350
-    public function old_txn_status()
351
-    {
352
-        EE_Error::doing_it_wrong(
353
-            __METHOD__,
354
-            esc_html__(
355
-                'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
356
-                'event_espresso'
357
-            ),
358
-            '4.9.12'
359
-        );
360
-        return $this->_old_txn_status;
361
-    }
362
-
363
-
364
-    /**
365
-     * @deprecated 4.9.12
366
-     * @param string $old_txn_status
367
-     */
368
-    public function set_old_txn_status($old_txn_status)
369
-    {
370
-        EE_Error::doing_it_wrong(
371
-            __METHOD__,
372
-            esc_html__(
373
-                'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
374
-                'event_espresso'
375
-            ),
376
-            '4.9.12'
377
-        );
378
-        // only set the first time
379
-        if ($this->_old_txn_status === null) {
380
-            $this->_old_txn_status = $old_txn_status;
381
-        }
382
-    }
383
-
384
-
385
-    /**
386
-     * @deprecated 4.9.12
387
-     * @return string
388
-     */
389
-    public function new_txn_status()
390
-    {
391
-        EE_Error::doing_it_wrong(
392
-            __METHOD__,
393
-            esc_html__(
394
-                'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
395
-                'event_espresso'
396
-            ),
397
-            '4.9.12'
398
-        );
399
-        return $this->_new_txn_status;
400
-    }
401
-
402
-
403
-    /**
404
-     * @deprecated 4.9.12
405
-     * @param string $new_txn_status
406
-     */
407
-    public function set_new_txn_status($new_txn_status)
408
-    {
409
-        EE_Error::doing_it_wrong(
410
-            __METHOD__,
411
-            esc_html__(
412
-                'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
413
-                'event_espresso'
414
-            ),
415
-            '4.9.12'
416
-        );
417
-        $this->_new_txn_status = $new_txn_status;
418
-    }
419
-
420
-
421
-    /**
422
-     * @deprecated 4.9.12
423
-     * @return bool
424
-     */
425
-    public function txn_status_updated()
426
-    {
427
-        EE_Error::doing_it_wrong(
428
-            __METHOD__,
429
-            esc_html__(
430
-                'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
431
-                'event_espresso'
432
-            ),
433
-            '4.9.12'
434
-        );
435
-        return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
436
-    }
17
+	/**
18
+	 * @var EE_Transaction_Payments $_instance
19
+	 * @access    private
20
+	 */
21
+	private static $_instance;
22
+
23
+	/**
24
+	 * @deprecated
25
+	 * @var string
26
+	 */
27
+	protected $_old_txn_status;
28
+
29
+	/**
30
+	 * @deprecated
31
+	 * @var string
32
+	 */
33
+	protected $_new_txn_status;
34
+
35
+
36
+	/**
37
+	 * @singleton method used to instantiate class object
38
+	 * @access    public
39
+	 * @return EE_Transaction_Payments instance
40
+	 */
41
+	public static function instance()
42
+	{
43
+		// check if class object is instantiated
44
+		if (! self::$_instance instanceof EE_Transaction_Payments) {
45
+			self::$_instance = new self();
46
+		}
47
+		return self::$_instance;
48
+	}
49
+
50
+
51
+	/**
52
+	 * recalculate_transaction_total
53
+	 *
54
+	 * @access private
55
+	 * @param EE_Transaction $transaction
56
+	 * @param bool           $update_txn
57
+	 * @return bool true if TXN total was updated, false if not
58
+	 * @throws \EE_Error
59
+	 */
60
+	public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true)
61
+	{
62
+		$total_line_item = $transaction->total_line_item();
63
+		if (! $total_line_item instanceof EE_Line_Item) {
64
+			EE_Error::add_error(
65
+				sprintf(
66
+					esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'),
67
+					$transaction->ID()
68
+				),
69
+				__FILE__,
70
+				__FUNCTION__,
71
+				__LINE__
72
+			);
73
+			return false;
74
+		}
75
+		$new_total = $total_line_item->recalculate_total_including_taxes();
76
+		$transaction->set_total($new_total);
77
+		if ($update_txn) {
78
+			return $transaction->save() ? true : false;
79
+		}
80
+		return false;
81
+	}
82
+
83
+
84
+	/**
85
+	 * Updates the provided EE_Transaction with all the applicable payments
86
+	 * returns a boolean for whether the TXN was saved to the db
87
+	 * (meaning a status change occurred)
88
+	 * or not saved (which could **still** mean that
89
+	 * the TXN status changed, but just was not yet saved).
90
+	 * So if passing a value of false for the $update_txn param,
91
+	 * then client code needs to take responsibility for saving the TXN
92
+	 * regardless of what happens within EE_Transaction_Payments;
93
+	 *
94
+	 * @param            EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID
95
+	 * @param    boolean $update_txn whether to save the TXN
96
+	 * @return    boolean        whether the TXN was saved
97
+	 * @throws \EE_Error
98
+	 */
99
+	public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true)
100
+	{
101
+		// verify transaction
102
+		if (! $transaction instanceof EE_Transaction) {
103
+			EE_Error::add_error(
104
+				esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
105
+				__FILE__,
106
+				__FUNCTION__,
107
+				__LINE__
108
+			);
109
+			return false;
110
+		}
111
+		// calculate total paid
112
+		$total_paid = $this->recalculate_total_payments_for_transaction($transaction);
113
+		// if total paid has changed
114
+		if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
115
+			$transaction->set_paid($total_paid);
116
+			// maybe update status, and make sure to save transaction if not done already
117
+			if (! $transaction->update_status_based_on_total_paid($update_txn)) {
118
+				if ($update_txn) {
119
+					return $transaction->save() ? true : false;
120
+				}
121
+			} else {
122
+				// the status got updated and was saved by
123
+				// update_transaction_status_based_on_total_paid()
124
+				return true;
125
+			}
126
+		}
127
+		return false;
128
+	}
129
+
130
+
131
+	/**
132
+	 * recalculate_total_payments_for_transaction
133
+	 *
134
+	 * @access public
135
+	 * @param EE_Transaction $transaction
136
+	 * @param string         $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved).
137
+	 *                                       By default, searches for approved payments
138
+	 * @return float|false   float on success, false on fail
139
+	 * @throws \EE_Error
140
+	 */
141
+	public function recalculate_total_payments_for_transaction(
142
+		EE_Transaction $transaction,
143
+		$payment_status = EEM_Payment::status_id_approved
144
+	) {
145
+		// verify transaction
146
+		if (! $transaction instanceof EE_Transaction) {
147
+			EE_Error::add_error(
148
+				esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
149
+				__FILE__,
150
+				__FUNCTION__,
151
+				__LINE__
152
+			);
153
+			return false;
154
+		}
155
+		// ensure Payment model is loaded
156
+		EE_Registry::instance()->load_model('Payment');
157
+		// calls EEM_Base::sum()
158
+		return EEM_Payment::instance()->sum(
159
+			// query params
160
+			array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)),
161
+			// field to sum
162
+			'PAY_amount'
163
+		);
164
+	}
165
+
166
+
167
+	/**
168
+	 * delete_payment_and_update_transaction
169
+	 * Before deleting the selected payment, we fetch it's transaction,
170
+	 * then delete the payment, and update the transactions' amount paid.
171
+	 *
172
+	 * @param EE_Payment $payment
173
+	 * @return boolean
174
+	 * @throws \EE_Error
175
+	 */
176
+	public function delete_payment_and_update_transaction(EE_Payment $payment)
177
+	{
178
+		// verify payment
179
+		if (! $payment instanceof EE_Payment) {
180
+			EE_Error::add_error(
181
+				esc_html__('A valid Payment object was not received.', 'event_espresso'),
182
+				__FILE__,
183
+				__FUNCTION__,
184
+				__LINE__
185
+			);
186
+			return false;
187
+		}
188
+		if (! $this->delete_registration_payments_and_update_registrations($payment)) {
189
+			return false;
190
+		}
191
+		if (! $payment->delete()) {
192
+			EE_Error::add_error(
193
+				esc_html__('The payment could not be deleted.', 'event_espresso'),
194
+				__FILE__,
195
+				__FUNCTION__,
196
+				__LINE__
197
+			);
198
+			return false;
199
+		}
200
+
201
+		$transaction = $payment->transaction();
202
+		$TXN_status = $transaction->status_ID();
203
+		if (
204
+			$TXN_status === EEM_Transaction::abandoned_status_code
205
+			|| $TXN_status === EEM_Transaction::failed_status_code
206
+			|| $payment->amount() === 0
207
+		) {
208
+			EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso'));
209
+			return true;
210
+		}
211
+
212
+
213
+		// if this fails, that just means that the transaction didn't get its status changed and/or updated.
214
+		// however the payment was still deleted.
215
+		if (! $this->calculate_total_payments_and_update_status($transaction)) {
216
+			EE_Error::add_attention(
217
+				esc_html__(
218
+					'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..',
219
+					'event_espresso'
220
+				),
221
+				__FILE__,
222
+				__FUNCTION__,
223
+				__LINE__
224
+			);
225
+			return true;
226
+		}
227
+
228
+		EE_Error::add_success(
229
+			esc_html__(
230
+				'The Payment was successfully deleted, and the Transaction has been updated accordingly.',
231
+				'event_espresso'
232
+			)
233
+		);
234
+		return true;
235
+	}
236
+
237
+
238
+	/**
239
+	 * delete_registration_payments_and_update_registrations
240
+	 *
241
+	 * removes all registration payment records associated with a payment
242
+	 * and subtracts their amounts from the corresponding registrations REG_paid field
243
+	 *
244
+	 * @param EE_Payment $payment
245
+	 * @param array      $reg_payment_query_params
246
+	 * @return bool
247
+	 * @throws \EE_Error
248
+	 */
249
+	public function delete_registration_payments_and_update_registrations(
250
+		EE_Payment $payment,
251
+		$reg_payment_query_params = array()
252
+	) {
253
+		$save_payment = false;
254
+		$reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params
255
+			: array(array('PAY_ID' => $payment->ID()));
256
+		$registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
257
+		if (! empty($registration_payments)) {
258
+			foreach ($registration_payments as $registration_payment) {
259
+				if ($registration_payment instanceof EE_Registration_Payment) {
260
+					$amount_paid = $registration_payment->amount();
261
+					$registration = $registration_payment->registration();
262
+					if ($registration instanceof EE_Registration) {
263
+						$registration->set_paid($registration->paid() - $amount_paid);
264
+						if ($registration->save() !== false) {
265
+							$registration_payment->delete_permanently();
266
+							$save_payment = true;
267
+						}
268
+					} else {
269
+						EE_Error::add_error(
270
+							sprintf(
271
+								esc_html__(
272
+									'An invalid Registration object was associated with Registration Payment ID# %1$d.',
273
+									'event_espresso'
274
+								),
275
+								$registration_payment->ID()
276
+							),
277
+							__FILE__,
278
+							__FUNCTION__,
279
+							__LINE__
280
+						);
281
+						return false;
282
+					}
283
+				} else {
284
+					EE_Error::add_error(
285
+						sprintf(
286
+							esc_html__(
287
+								'An invalid Registration Payment object was associated with payment ID# %1$d.',
288
+								'event_espresso'
289
+							),
290
+							$payment->ID()
291
+						),
292
+						__FILE__,
293
+						__FUNCTION__,
294
+						__LINE__
295
+					);
296
+					return false;
297
+				}
298
+			}
299
+		}
300
+		if ($save_payment) {
301
+			$payment->save();
302
+		}
303
+		return true;
304
+	}
305
+
306
+
307
+
308
+	/********************************** DEPRECATED METHODS **********************************/
309
+
310
+
311
+	/**
312
+	 * possibly toggles TXN status
313
+	 *
314
+	 * @deprecated 4.9.1
315
+	 * @param EE_Transaction $transaction
316
+	 * @param    boolean     $update_txn whether to save the TXN
317
+	 * @return    boolean        whether the TXN was saved
318
+	 * @throws \EE_Error
319
+	 */
320
+	public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
321
+	{
322
+		EE_Error::doing_it_wrong(
323
+			__CLASS__ . '::' . __FUNCTION__,
324
+			sprintf(
325
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
326
+				'EE_Transaction::update_status_based_on_total_paid()'
327
+			),
328
+			'4.9.1',
329
+			'5.0.0'
330
+		);
331
+		// verify transaction
332
+		if (! $transaction instanceof EE_Transaction) {
333
+			EE_Error::add_error(
334
+				esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
335
+				__FILE__,
336
+				__FUNCTION__,
337
+				__LINE__
338
+			);
339
+			return false;
340
+		}
341
+		// set transaction status based on comparison of TXN_paid vs TXN_total
342
+		return $transaction->update_status_based_on_total_paid($update_txn);
343
+	}
344
+
345
+
346
+	/**
347
+	 * @deprecated 4.9.12
348
+	 * @return string
349
+	 */
350
+	public function old_txn_status()
351
+	{
352
+		EE_Error::doing_it_wrong(
353
+			__METHOD__,
354
+			esc_html__(
355
+				'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
356
+				'event_espresso'
357
+			),
358
+			'4.9.12'
359
+		);
360
+		return $this->_old_txn_status;
361
+	}
362
+
363
+
364
+	/**
365
+	 * @deprecated 4.9.12
366
+	 * @param string $old_txn_status
367
+	 */
368
+	public function set_old_txn_status($old_txn_status)
369
+	{
370
+		EE_Error::doing_it_wrong(
371
+			__METHOD__,
372
+			esc_html__(
373
+				'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
374
+				'event_espresso'
375
+			),
376
+			'4.9.12'
377
+		);
378
+		// only set the first time
379
+		if ($this->_old_txn_status === null) {
380
+			$this->_old_txn_status = $old_txn_status;
381
+		}
382
+	}
383
+
384
+
385
+	/**
386
+	 * @deprecated 4.9.12
387
+	 * @return string
388
+	 */
389
+	public function new_txn_status()
390
+	{
391
+		EE_Error::doing_it_wrong(
392
+			__METHOD__,
393
+			esc_html__(
394
+				'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
395
+				'event_espresso'
396
+			),
397
+			'4.9.12'
398
+		);
399
+		return $this->_new_txn_status;
400
+	}
401
+
402
+
403
+	/**
404
+	 * @deprecated 4.9.12
405
+	 * @param string $new_txn_status
406
+	 */
407
+	public function set_new_txn_status($new_txn_status)
408
+	{
409
+		EE_Error::doing_it_wrong(
410
+			__METHOD__,
411
+			esc_html__(
412
+				'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
413
+				'event_espresso'
414
+			),
415
+			'4.9.12'
416
+		);
417
+		$this->_new_txn_status = $new_txn_status;
418
+	}
419
+
420
+
421
+	/**
422
+	 * @deprecated 4.9.12
423
+	 * @return bool
424
+	 */
425
+	public function txn_status_updated()
426
+	{
427
+		EE_Error::doing_it_wrong(
428
+			__METHOD__,
429
+			esc_html__(
430
+				'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
431
+				'event_espresso'
432
+			),
433
+			'4.9.12'
434
+		);
435
+		return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
436
+	}
437 437
 }
Please login to merge, or discard this patch.
core/domain/entities/DbSafeDateTime.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             DbSafeDateTime::db_safe_timestamp_format,
74 74
             $this->_datetime_string
75 75
         );
76
-        if (! $date instanceof DateTime) {
76
+        if ( ! $date instanceof DateTime) {
77 77
             try {
78 78
                 // we want a stack trace to determine where the malformed date came from, so...
79 79
                 throw new DomainException('');
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             DbSafeDateTime::db_safe_timestamp_format,
116 116
             $this->_datetime_string
117 117
         );
118
-        if (! $date instanceof DateTime) {
118
+        if ( ! $date instanceof DateTime) {
119 119
             $this->writeToErrorLog(
120 120
                 sprintf(
121 121
                     esc_html__(
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      */
195 195
     private function writeToErrorLog($message)
196 196
     {
197
-        if (! empty($this->_error_log_dir)) {
197
+        if ( ! empty($this->_error_log_dir)) {
198 198
             /** @noinspection ForgottenDebugOutputInspection */
199 199
             error_log($message, 3, $this->_error_log_dir);
200 200
         } else {
Please login to merge, or discard this patch.
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -17,188 +17,188 @@
 block discarded – undo
17 17
  */
18 18
 class DbSafeDateTime extends DateTime
19 19
 {
20
-    // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
21
-    /**
22
-     * @type string db_safe_timestamp_format
23
-     */
24
-    const db_safe_timestamp_format = 'Y-m-d H:i:s O e';
25
-    // phpcs:enable
26
-
27
-    // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
28
-    /**
29
-     * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier
30
-     *
31
-     * @type string $_datetime_string
32
-     */
33
-    protected $_datetime_string = '';
34
-
35
-    /**
36
-     * where to write the error log to
37
-     *
38
-     * @type string $_error_log_dir
39
-     */
40
-    protected $_error_log_dir = '';
41
-    // phpcs:enable
42
-
43
-
44
-    /**
45
-     * @param string $error_log_dir
46
-     */
47
-    public function setErrorLogDir($error_log_dir)
48
-    {
49
-        // if the folder path is writable, then except the path + filename, else keep empty
50
-        $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
51
-            ? $error_log_dir
52
-            : '';
53
-    }
54
-
55
-
56
-    /**
57
-     * @return string
58
-     */
59
-    public function __toString()
60
-    {
61
-        return $this->format(DbSafeDateTime::db_safe_timestamp_format);
62
-    }
63
-
64
-
65
-    /**
66
-     * @return array
67
-     */
68
-    public function __sleep()
69
-    {
70
-        $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format);
71
-        $date = DateTime::createFromFormat(
72
-            DbSafeDateTime::db_safe_timestamp_format,
73
-            $this->_datetime_string
74
-        );
75
-        if (! $date instanceof DateTime) {
76
-            try {
77
-                // we want a stack trace to determine where the malformed date came from, so...
78
-                throw new DomainException('');
79
-            } catch (DomainException $e) {
80
-                $stack_trace = $e->getTraceAsString();
81
-            }
82
-            $this->writeToErrorLog(
83
-                sprintf(
84
-                    esc_html__(
85
-                        'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s',
86
-                        'event_espresso'
87
-                    ),
88
-                    $this->_datetime_string,
89
-                    '<br />',
90
-                    print_r(DateTime::getLastErrors(), true),
91
-                    PHP_VERSION,
92
-                    $stack_trace
93
-                )
94
-            );
95
-        }
96
-        return array('_datetime_string');
97
-    }
98
-
99
-
100
-    /**
101
-     * if an empty or null value got saved to the db for a datetime,
102
-     * then some servers and/or PHP itself will incorrectly convert that date string
103
-     * resulting in "-0001-11-30" for the year-month-day.
104
-     * see the Notes section
105
-     *
106
-     * @link http://php.net/manual/en/datetime.formats.date.php
107
-     * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created,
108
-     * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
109
-     * so we're no better off, but at least things won't go fatal on us.
110
-     */
111
-    public function __wakeup()
112
-    {
113
-        $date = self::createFromFormat(
114
-            DbSafeDateTime::db_safe_timestamp_format,
115
-            $this->_datetime_string
116
-        );
117
-        if (! $date instanceof DateTime) {
118
-            $this->writeToErrorLog(
119
-                sprintf(
120
-                    esc_html__(
121
-                        'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s',
122
-                        'event_espresso'
123
-                    ),
124
-                    $this->_datetime_string,
125
-                    '<br />',
126
-                    print_r(DateTime::getLastErrors(), true),
127
-                    PHP_VERSION
128
-                )
129
-            );
130
-        } else {
131
-            $this->__construct(
132
-                $date->format(\EE_Datetime_Field::mysql_timestamp_format),
133
-                new DateTimeZone($date->format('e'))
134
-            );
135
-        }
136
-    }
137
-
138
-
139
-    /**
140
-     * Normalizes incoming date string so that it is a bit more stable for use.
141
-     * @param string $date_string
142
-     * @return string
143
-     */
144
-    public static function normalizeInvalidDate($date_string)
145
-    {
146
-        return str_replace(
147
-            array('-0001-11-29', '-0001-11-30', '0000-00-00'),
148
-            '0000-01-03',
149
-            $date_string
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     * Creates a DbSafeDateTime from ye old DateTime
156
-     *
157
-     * @param DateTime $datetime
158
-     * @return \EventEspresso\core\domain\entities\DbSafeDateTime
159
-     */
160
-    public static function createFromDateTime(DateTime $datetime)
161
-    {
162
-        return new DbSafeDateTime(
163
-            $datetime->format(\EE_Datetime_Field::mysql_timestamp_format),
164
-            new DateTimeZone($datetime->format('e'))
165
-        );
166
-    }
167
-
168
-
169
-    /**
170
-     * Parse a string into a new DateTime object according to the specified format
171
-     *
172
-     * @param string       $format   Format accepted by date().
173
-     * @param string       $time     String representing the time.
174
-     * @param DateTimeZone $timezone A DateTimeZone object representing the desired time zone.
175
-     * @return DbSafeDateTime|boolean
176
-     * @link https://php.net/manual/en/datetime.createfromformat.php
177
-     */
178
-    public static function createFromFormat($format, $time, $timezone = null)
179
-    {
180
-        $time = self::normalizeInvalidDate($time);
181
-        // Various php versions handle the third argument differently.  This conditional accounts for that.
182
-        $DateTime = $timezone === null
183
-            ? parent::createFromFormat($format, $time)
184
-            : parent::createFromFormat($format, $time, $timezone);
185
-        return $DateTime instanceof DateTime
186
-            ? self::createFromDateTime($DateTime)
187
-            : $DateTime;
188
-    }
189
-
190
-
191
-    /**
192
-     * @param string $message
193
-     */
194
-    private function writeToErrorLog($message)
195
-    {
196
-        if (! empty($this->_error_log_dir)) {
197
-            /** @noinspection ForgottenDebugOutputInspection */
198
-            error_log($message, 3, $this->_error_log_dir);
199
-        } else {
200
-            /** @noinspection ForgottenDebugOutputInspection */
201
-            error_log($message);
202
-        }
203
-    }
20
+	// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
21
+	/**
22
+	 * @type string db_safe_timestamp_format
23
+	 */
24
+	const db_safe_timestamp_format = 'Y-m-d H:i:s O e';
25
+	// phpcs:enable
26
+
27
+	// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
28
+	/**
29
+	 * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier
30
+	 *
31
+	 * @type string $_datetime_string
32
+	 */
33
+	protected $_datetime_string = '';
34
+
35
+	/**
36
+	 * where to write the error log to
37
+	 *
38
+	 * @type string $_error_log_dir
39
+	 */
40
+	protected $_error_log_dir = '';
41
+	// phpcs:enable
42
+
43
+
44
+	/**
45
+	 * @param string $error_log_dir
46
+	 */
47
+	public function setErrorLogDir($error_log_dir)
48
+	{
49
+		// if the folder path is writable, then except the path + filename, else keep empty
50
+		$this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
51
+			? $error_log_dir
52
+			: '';
53
+	}
54
+
55
+
56
+	/**
57
+	 * @return string
58
+	 */
59
+	public function __toString()
60
+	{
61
+		return $this->format(DbSafeDateTime::db_safe_timestamp_format);
62
+	}
63
+
64
+
65
+	/**
66
+	 * @return array
67
+	 */
68
+	public function __sleep()
69
+	{
70
+		$this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format);
71
+		$date = DateTime::createFromFormat(
72
+			DbSafeDateTime::db_safe_timestamp_format,
73
+			$this->_datetime_string
74
+		);
75
+		if (! $date instanceof DateTime) {
76
+			try {
77
+				// we want a stack trace to determine where the malformed date came from, so...
78
+				throw new DomainException('');
79
+			} catch (DomainException $e) {
80
+				$stack_trace = $e->getTraceAsString();
81
+			}
82
+			$this->writeToErrorLog(
83
+				sprintf(
84
+					esc_html__(
85
+						'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s',
86
+						'event_espresso'
87
+					),
88
+					$this->_datetime_string,
89
+					'<br />',
90
+					print_r(DateTime::getLastErrors(), true),
91
+					PHP_VERSION,
92
+					$stack_trace
93
+				)
94
+			);
95
+		}
96
+		return array('_datetime_string');
97
+	}
98
+
99
+
100
+	/**
101
+	 * if an empty or null value got saved to the db for a datetime,
102
+	 * then some servers and/or PHP itself will incorrectly convert that date string
103
+	 * resulting in "-0001-11-30" for the year-month-day.
104
+	 * see the Notes section
105
+	 *
106
+	 * @link http://php.net/manual/en/datetime.formats.date.php
107
+	 * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created,
108
+	 * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
109
+	 * so we're no better off, but at least things won't go fatal on us.
110
+	 */
111
+	public function __wakeup()
112
+	{
113
+		$date = self::createFromFormat(
114
+			DbSafeDateTime::db_safe_timestamp_format,
115
+			$this->_datetime_string
116
+		);
117
+		if (! $date instanceof DateTime) {
118
+			$this->writeToErrorLog(
119
+				sprintf(
120
+					esc_html__(
121
+						'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s',
122
+						'event_espresso'
123
+					),
124
+					$this->_datetime_string,
125
+					'<br />',
126
+					print_r(DateTime::getLastErrors(), true),
127
+					PHP_VERSION
128
+				)
129
+			);
130
+		} else {
131
+			$this->__construct(
132
+				$date->format(\EE_Datetime_Field::mysql_timestamp_format),
133
+				new DateTimeZone($date->format('e'))
134
+			);
135
+		}
136
+	}
137
+
138
+
139
+	/**
140
+	 * Normalizes incoming date string so that it is a bit more stable for use.
141
+	 * @param string $date_string
142
+	 * @return string
143
+	 */
144
+	public static function normalizeInvalidDate($date_string)
145
+	{
146
+		return str_replace(
147
+			array('-0001-11-29', '-0001-11-30', '0000-00-00'),
148
+			'0000-01-03',
149
+			$date_string
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 * Creates a DbSafeDateTime from ye old DateTime
156
+	 *
157
+	 * @param DateTime $datetime
158
+	 * @return \EventEspresso\core\domain\entities\DbSafeDateTime
159
+	 */
160
+	public static function createFromDateTime(DateTime $datetime)
161
+	{
162
+		return new DbSafeDateTime(
163
+			$datetime->format(\EE_Datetime_Field::mysql_timestamp_format),
164
+			new DateTimeZone($datetime->format('e'))
165
+		);
166
+	}
167
+
168
+
169
+	/**
170
+	 * Parse a string into a new DateTime object according to the specified format
171
+	 *
172
+	 * @param string       $format   Format accepted by date().
173
+	 * @param string       $time     String representing the time.
174
+	 * @param DateTimeZone $timezone A DateTimeZone object representing the desired time zone.
175
+	 * @return DbSafeDateTime|boolean
176
+	 * @link https://php.net/manual/en/datetime.createfromformat.php
177
+	 */
178
+	public static function createFromFormat($format, $time, $timezone = null)
179
+	{
180
+		$time = self::normalizeInvalidDate($time);
181
+		// Various php versions handle the third argument differently.  This conditional accounts for that.
182
+		$DateTime = $timezone === null
183
+			? parent::createFromFormat($format, $time)
184
+			: parent::createFromFormat($format, $time, $timezone);
185
+		return $DateTime instanceof DateTime
186
+			? self::createFromDateTime($DateTime)
187
+			: $DateTime;
188
+	}
189
+
190
+
191
+	/**
192
+	 * @param string $message
193
+	 */
194
+	private function writeToErrorLog($message)
195
+	{
196
+		if (! empty($this->_error_log_dir)) {
197
+			/** @noinspection ForgottenDebugOutputInspection */
198
+			error_log($message, 3, $this->_error_log_dir);
199
+		} else {
200
+			/** @noinspection ForgottenDebugOutputInspection */
201
+			error_log($message);
202
+		}
203
+	}
204 204
 }
Please login to merge, or discard this patch.
services/admin/registrations/list_table/page_header/TicketFilterHeader.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
         if ($TKT_ID) {
60 60
             $ticket = $this->ticket_model->get_one_by_ID($TKT_ID);
61 61
             if ($ticket instanceof EE_Ticket) {
62
-                $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> ';
62
+                $ticket_details = '<span class="ee-ticket-name">'.$ticket->name().'</span> ';
63 63
                 $ticket_details .= ! $ticket->is_free()
64
-                    ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>'
64
+                    ? '<span class="ee-ticket-price">'.$ticket->pretty_price().'</span>'
65 65
                     : '<span class="reg-overview-free-event-spn">'
66 66
                       . esc_html__('free', 'event_espresso')
67 67
                       . '</span>';
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
                 $text .= '&nbsp; &nbsp; ';
79 79
                 $text .= '<span class="drk-grey-text" style="font-size:.9em;">';
80 80
                 $text .= '<span class="dashicons dashicons-tickets-alt"></span>';
81
-                $text .= $ticket_details . '</span></h3>';
81
+                $text .= $ticket_details.'</span></h3>';
82 82
             }
83 83
         }
84 84
         return $text;
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -22,64 +22,64 @@
 block discarded – undo
22 22
  */
23 23
 class TicketFilterHeader extends AdminPageHeaderDecorator
24 24
 {
25
-    /**
26
-     * @var EEM_Ticket $ticket_model
27
-     */
28
-    private $ticket_model;
25
+	/**
26
+	 * @var EEM_Ticket $ticket_model
27
+	 */
28
+	private $ticket_model;
29 29
 
30 30
 
31
-    /**
32
-     * TicketFilterHeader constructor.
33
-     *
34
-     * @param RequestInterface $request
35
-     * @param EEM_Ticket       $ticket_model
36
-     */
37
-    public function __construct(RequestInterface $request, EEM_Ticket $ticket_model)
38
-    {
39
-        parent::__construct($request);
40
-        $this->ticket_model = $ticket_model;
41
-    }
31
+	/**
32
+	 * TicketFilterHeader constructor.
33
+	 *
34
+	 * @param RequestInterface $request
35
+	 * @param EEM_Ticket       $ticket_model
36
+	 */
37
+	public function __construct(RequestInterface $request, EEM_Ticket $ticket_model)
38
+	{
39
+		parent::__construct($request);
40
+		$this->ticket_model = $ticket_model;
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * @param string $text
46
-     * @return string
47
-     * @throws EE_Error
48
-     * @throws InvalidDataTypeException
49
-     * @throws InvalidInterfaceException
50
-     * @throws InvalidArgumentException
51
-     * @throws ReflectionException
52
-     * @since 4.10.2.p
53
-     */
54
-    public function getHeaderText($text = '')
55
-    {
56
-        $TKT_ID = $this->request->getRequestParam('TKT_ID');
57
-        $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int');
58
-        if ($TKT_ID) {
59
-            $ticket = $this->ticket_model->get_one_by_ID($TKT_ID);
60
-            if ($ticket instanceof EE_Ticket) {
61
-                $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> ';
62
-                $ticket_details .= ! $ticket->is_free()
63
-                    ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>'
64
-                    : '<span class="reg-overview-free-event-spn">'
65
-                      . esc_html__('free', 'event_espresso')
66
-                      . '</span>';
67
-                // remove the closing h3 heading tag if it exists
68
-                $text = str_replace(
69
-                    '</h3>',
70
-                    '',
71
-                    $text
72
-                );
73
-                if (empty($text)) {
74
-                    $text = '<h3 style="line-height:1.5em;">';
75
-                    $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso');
76
-                }
77
-                $text .= '&nbsp; &nbsp; ';
78
-                $text .= '<span class="drk-grey-text" style="font-size:.9em;">';
79
-                $text .= '<span class="dashicons dashicons-tickets-alt"></span>';
80
-                $text .= $ticket_details . '</span></h3>';
81
-            }
82
-        }
83
-        return $text;
84
-    }
44
+	/**
45
+	 * @param string $text
46
+	 * @return string
47
+	 * @throws EE_Error
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws InvalidInterfaceException
50
+	 * @throws InvalidArgumentException
51
+	 * @throws ReflectionException
52
+	 * @since 4.10.2.p
53
+	 */
54
+	public function getHeaderText($text = '')
55
+	{
56
+		$TKT_ID = $this->request->getRequestParam('TKT_ID');
57
+		$TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int');
58
+		if ($TKT_ID) {
59
+			$ticket = $this->ticket_model->get_one_by_ID($TKT_ID);
60
+			if ($ticket instanceof EE_Ticket) {
61
+				$ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> ';
62
+				$ticket_details .= ! $ticket->is_free()
63
+					? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>'
64
+					: '<span class="reg-overview-free-event-spn">'
65
+					  . esc_html__('free', 'event_espresso')
66
+					  . '</span>';
67
+				// remove the closing h3 heading tag if it exists
68
+				$text = str_replace(
69
+					'</h3>',
70
+					'',
71
+					$text
72
+				);
73
+				if (empty($text)) {
74
+					$text = '<h3 style="line-height:1.5em;">';
75
+					$text .= esc_html__('Viewing registrations for ticket:', 'event_espresso');
76
+				}
77
+				$text .= '&nbsp; &nbsp; ';
78
+				$text .= '<span class="drk-grey-text" style="font-size:.9em;">';
79
+				$text .= '<span class="dashicons dashicons-tickets-alt"></span>';
80
+				$text .= $ticket_details . '</span></h3>';
81
+			}
82
+		}
83
+		return $text;
84
+	}
85 85
 }
Please login to merge, or discard this patch.
core/domain/services/admin/ajax/ThankYouPageIpnMonitor.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -67,12 +67,12 @@  discard block
 block discarded – undo
67 67
     public function heartbeatResponse($response = array(), $data = array())
68 68
     {
69 69
         // does this heartbeat contain our data ?
70
-        if (! isset($data[ $this->heartbeat ])) {
70
+        if ( ! isset($data[$this->heartbeat])) {
71 71
             return $response;
72 72
         }
73 73
         // check for reg_url_link in the incoming heartbeat data
74
-        if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) {
75
-            $response[ $this->heartbeat ] = array(
74
+        if ( ! isset($data[$this->heartbeat]['e_reg_url_link'])) {
75
+            $response[$this->heartbeat] = array(
76 76
                 'errors' => ! empty($notices['errors'])
77 77
                     ? $notices['errors']
78 78
                     : esc_html__(
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
         // kk heartbeat has our data
86 86
         $response = $this->initializeThankYouPageAndTransaction($response, $data);
87 87
         // if something went wrong...
88
-        if (isset($response[ $this->heartbeat ]['errors'])) {
88
+        if (isset($response[$this->heartbeat]['errors'])) {
89 89
             return $response;
90 90
         }
91 91
         // grab transient of Transaction's status
92
-        $txn_status = isset($data[ $this->heartbeat ]['txn_status'])
93
-            ? $data[ $this->heartbeat ]['txn_status']
92
+        $txn_status = isset($data[$this->heartbeat]['txn_status'])
93
+            ? $data[$this->heartbeat]['txn_status']
94 94
             : null;
95 95
         $response = $this->getTransactionDetails($txn_status, $response, $data);
96 96
         // no payment data yet?
97
-        if (isset($response[ $this->heartbeat ]['still_waiting'])) {
97
+        if (isset($response[$this->heartbeat]['still_waiting'])) {
98 98
             return $response;
99 99
         }
100 100
         // TXN is happening so let's get the payments now
101 101
         // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
102
-        $since = isset($data[ $this->heartbeat ]['get_payments_since'])
103
-            ? $data[ $this->heartbeat ]['get_payments_since']
102
+        $since = isset($data[$this->heartbeat]['get_payments_since'])
103
+            ? $data[$this->heartbeat]['get_payments_since']
104 104
             : 0;
105 105
         return $this->paymentDetails($response, $since);
106 106
     }
@@ -117,18 +117,18 @@  discard block
 block discarded – undo
117 117
      */
118 118
     private function initializeThankYouPageAndTransaction($response, $data)
119 119
     {
120
-        require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
120
+        require_once EE_MODULES.'thank_you_page/EED_Thank_You_Page.module.php';
121 121
         // set_definitions, instantiate the thank you page class, and get the ball rolling
122 122
         EED_Thank_You_Page::set_definitions();
123 123
         $this->thank_you_page = EED_Thank_You_Page::instance();
124
-        $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']);
124
+        $this->thank_you_page->set_reg_url_link($data[$this->heartbeat]['e_reg_url_link']);
125 125
         $this->thank_you_page->init();
126 126
         // get TXN
127 127
         $transaction = $this->thank_you_page->get_txn();
128 128
         // no TXN? then get out
129
-        if (! $transaction instanceof EE_Transaction) {
129
+        if ( ! $transaction instanceof EE_Transaction) {
130 130
             $notices = EE_Error::get_notices();
131
-            $response[ $this->heartbeat ] = array(
131
+            $response[$this->heartbeat] = array(
132 132
                 'errors' => ! empty($notices['errors'])
133 133
                     ? $notices['errors']
134 134
                     : sprintf(
@@ -173,12 +173,12 @@  discard block
 block discarded – undo
173 173
                 case EEM_Transaction::failed_status_code:
174 174
                 default:
175 175
                     // keep on waiting...
176
-                    return $this->updateServerWaitTime($data[ $this->heartbeat ]);
176
+                    return $this->updateServerWaitTime($data[$this->heartbeat]);
177 177
             }
178 178
             // or is the TXN still failed (never been updated) ???
179 179
         } elseif ($this->transaction->failed()) {
180 180
             // keep on waiting...
181
-            return $this->updateServerWaitTime($data[ $this->heartbeat ]);
181
+            return $this->updateServerWaitTime($data[$this->heartbeat]);
182 182
         }
183 183
         return $response;
184 184
     }
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
      */
197 197
     private function setTransactionDetails($response, $status_only = false)
198 198
     {
199
-        if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) {
200
-            $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details();
199
+        if ( ! $status_only && ! isset($response[$this->heartbeat]['transaction_details'])) {
200
+            $response[$this->heartbeat]['transaction_details'] = $this->thank_you_page->get_transaction_details();
201 201
         }
202
-        if (! isset($response[ $this->heartbeat ]['txn_status'])) {
203
-            $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID();
202
+        if ( ! isset($response[$this->heartbeat]['txn_status'])) {
203
+            $response[$this->heartbeat]['txn_status'] = $this->transaction->status_ID();
204 204
         }
205 205
         return $response;
206 206
     }
@@ -221,19 +221,19 @@  discard block
 block discarded – undo
221 221
         // then check for payments
222 222
         $payments = $this->thank_you_page->get_txn_payments($since);
223 223
         // has a payment been processed ?
224
-        if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
224
+        if ( ! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
225 225
             if ($since) {
226
-                $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments);
226
+                $response[$this->heartbeat]['new_payments'] = $this->thank_you_page->get_new_payments($payments);
227 227
                 $response = $this->setTransactionDetails($response);
228 228
             } else {
229
-                $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details(
229
+                $response[$this->heartbeat]['payment_details'] = $this->thank_you_page->get_payment_details(
230 230
                     $payments
231 231
                 );
232 232
             }
233 233
             // reset time to check for payments
234
-            $response[ $this->heartbeat ]['get_payments_since'] = time();
234
+            $response[$this->heartbeat]['get_payments_since'] = time();
235 235
         } else {
236
-            $response[ $this->heartbeat ]['get_payments_since'] = $since;
236
+            $response[$this->heartbeat]['get_payments_since'] = $since;
237 237
         }
238 238
         return $response;
239 239
     }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
      */
252 252
     private function updateServerWaitTime($thank_you_page_data)
253 253
     {
254
-        $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access'])
254
+        $response[$this->heartbeat]['still_waiting'] = isset($thank_you_page_data['initial_access'])
255 255
             ? time() - $thank_you_page_data['initial_access']
256 256
             : 0;
257 257
         $response = $this->setTransactionDetails($response, true);
Please login to merge, or discard this patch.
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -21,239 +21,239 @@
 block discarded – undo
21 21
  */
22 22
 class ThankYouPageIpnMonitor
23 23
 {
24
-    /**
25
-     * @var string $heartbeat
26
-     */
27
-    private $heartbeat;
24
+	/**
25
+	 * @var string $heartbeat
26
+	 */
27
+	private $heartbeat;
28 28
 
29
-    /**
30
-     * @var EED_Thank_You_Page $thank_you_page
31
-     */
32
-    private $thank_you_page;
29
+	/**
30
+	 * @var EED_Thank_You_Page $thank_you_page
31
+	 */
32
+	private $thank_you_page;
33 33
 
34
-    /**
35
-     * @var EE_Transaction $transaction
36
-     */
37
-    private $transaction;
34
+	/**
35
+	 * @var EE_Transaction $transaction
36
+	 */
37
+	private $transaction;
38 38
 
39 39
 
40
-    /**
41
-     * EventEditorHeartbeat constructor.
42
-     */
43
-    public function __construct()
44
-    {
45
-        $this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE;
46
-        add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3);
47
-        add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3);
48
-    }
40
+	/**
41
+	 * EventEditorHeartbeat constructor.
42
+	 */
43
+	public function __construct()
44
+	{
45
+		$this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE;
46
+		add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3);
47
+		add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3);
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * thank_you_page_IPN_monitor
53
-     * this basically just pulls the TXN based on the reg_url_link sent from the server,
54
-     * then checks that the TXN status is not failed, and that no other errors have been generated.
55
-     * it also calculates the IPN wait time since the Thank You page was first loaded
56
-     *
57
-     * @param array $response
58
-     * @param array $data
59
-     * @return array
60
-     * @throws EE_Error
61
-     * @throws InvalidArgumentException
62
-     * @throws InvalidDataTypeException
63
-     * @throws InvalidInterfaceException
64
-     * @throws ReflectionException
65
-     */
66
-    public function heartbeatResponse($response = array(), $data = array())
67
-    {
68
-        // does this heartbeat contain our data ?
69
-        if (! isset($data[ $this->heartbeat ])) {
70
-            return $response;
71
-        }
72
-        // check for reg_url_link in the incoming heartbeat data
73
-        if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) {
74
-            $response[ $this->heartbeat ] = array(
75
-                'errors' => ! empty($notices['errors'])
76
-                    ? $notices['errors']
77
-                    : esc_html__(
78
-                        'No transaction information could be retrieved because the registration URL link is missing or invalid.',
79
-                        'event_espresso'
80
-                    ),
81
-            );
82
-            return $response;
83
-        }
84
-        // kk heartbeat has our data
85
-        $response = $this->initializeThankYouPageAndTransaction($response, $data);
86
-        // if something went wrong...
87
-        if (isset($response[ $this->heartbeat ]['errors'])) {
88
-            return $response;
89
-        }
90
-        // grab transient of Transaction's status
91
-        $txn_status = isset($data[ $this->heartbeat ]['txn_status'])
92
-            ? $data[ $this->heartbeat ]['txn_status']
93
-            : null;
94
-        $response = $this->getTransactionDetails($txn_status, $response, $data);
95
-        // no payment data yet?
96
-        if (isset($response[ $this->heartbeat ]['still_waiting'])) {
97
-            return $response;
98
-        }
99
-        // TXN is happening so let's get the payments now
100
-        // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
101
-        $since = isset($data[ $this->heartbeat ]['get_payments_since'])
102
-            ? $data[ $this->heartbeat ]['get_payments_since']
103
-            : 0;
104
-        return $this->paymentDetails($response, $since);
105
-    }
51
+	/**
52
+	 * thank_you_page_IPN_monitor
53
+	 * this basically just pulls the TXN based on the reg_url_link sent from the server,
54
+	 * then checks that the TXN status is not failed, and that no other errors have been generated.
55
+	 * it also calculates the IPN wait time since the Thank You page was first loaded
56
+	 *
57
+	 * @param array $response
58
+	 * @param array $data
59
+	 * @return array
60
+	 * @throws EE_Error
61
+	 * @throws InvalidArgumentException
62
+	 * @throws InvalidDataTypeException
63
+	 * @throws InvalidInterfaceException
64
+	 * @throws ReflectionException
65
+	 */
66
+	public function heartbeatResponse($response = array(), $data = array())
67
+	{
68
+		// does this heartbeat contain our data ?
69
+		if (! isset($data[ $this->heartbeat ])) {
70
+			return $response;
71
+		}
72
+		// check for reg_url_link in the incoming heartbeat data
73
+		if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) {
74
+			$response[ $this->heartbeat ] = array(
75
+				'errors' => ! empty($notices['errors'])
76
+					? $notices['errors']
77
+					: esc_html__(
78
+						'No transaction information could be retrieved because the registration URL link is missing or invalid.',
79
+						'event_espresso'
80
+					),
81
+			);
82
+			return $response;
83
+		}
84
+		// kk heartbeat has our data
85
+		$response = $this->initializeThankYouPageAndTransaction($response, $data);
86
+		// if something went wrong...
87
+		if (isset($response[ $this->heartbeat ]['errors'])) {
88
+			return $response;
89
+		}
90
+		// grab transient of Transaction's status
91
+		$txn_status = isset($data[ $this->heartbeat ]['txn_status'])
92
+			? $data[ $this->heartbeat ]['txn_status']
93
+			: null;
94
+		$response = $this->getTransactionDetails($txn_status, $response, $data);
95
+		// no payment data yet?
96
+		if (isset($response[ $this->heartbeat ]['still_waiting'])) {
97
+			return $response;
98
+		}
99
+		// TXN is happening so let's get the payments now
100
+		// if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
101
+		$since = isset($data[ $this->heartbeat ]['get_payments_since'])
102
+			? $data[ $this->heartbeat ]['get_payments_since']
103
+			: 0;
104
+		return $this->paymentDetails($response, $since);
105
+	}
106 106
 
107 107
 
108
-    /**
109
-     * @param array $response
110
-     * @param array $data
111
-     * @return array
112
-     * @throws EE_Error
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidInterfaceException
116
-     */
117
-    private function initializeThankYouPageAndTransaction($response, $data)
118
-    {
119
-        require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
120
-        // set_definitions, instantiate the thank you page class, and get the ball rolling
121
-        EED_Thank_You_Page::set_definitions();
122
-        $this->thank_you_page = EED_Thank_You_Page::instance();
123
-        $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']);
124
-        $this->thank_you_page->init();
125
-        // get TXN
126
-        $transaction = $this->thank_you_page->get_txn();
127
-        // no TXN? then get out
128
-        if (! $transaction instanceof EE_Transaction) {
129
-            $notices = EE_Error::get_notices();
130
-            $response[ $this->heartbeat ] = array(
131
-                'errors' => ! empty($notices['errors'])
132
-                    ? $notices['errors']
133
-                    : sprintf(
134
-                        esc_html__(
135
-                            'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
136
-                            'event_espresso'
137
-                        ),
138
-                        __LINE__
139
-                    ),
140
-            );
141
-            return $response;
142
-        }
143
-        $this->transaction = $transaction;
144
-        return $response;
145
-    }
108
+	/**
109
+	 * @param array $response
110
+	 * @param array $data
111
+	 * @return array
112
+	 * @throws EE_Error
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidInterfaceException
116
+	 */
117
+	private function initializeThankYouPageAndTransaction($response, $data)
118
+	{
119
+		require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
120
+		// set_definitions, instantiate the thank you page class, and get the ball rolling
121
+		EED_Thank_You_Page::set_definitions();
122
+		$this->thank_you_page = EED_Thank_You_Page::instance();
123
+		$this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']);
124
+		$this->thank_you_page->init();
125
+		// get TXN
126
+		$transaction = $this->thank_you_page->get_txn();
127
+		// no TXN? then get out
128
+		if (! $transaction instanceof EE_Transaction) {
129
+			$notices = EE_Error::get_notices();
130
+			$response[ $this->heartbeat ] = array(
131
+				'errors' => ! empty($notices['errors'])
132
+					? $notices['errors']
133
+					: sprintf(
134
+						esc_html__(
135
+							'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
136
+							'event_espresso'
137
+						),
138
+						__LINE__
139
+					),
140
+			);
141
+			return $response;
142
+		}
143
+		$this->transaction = $transaction;
144
+		return $response;
145
+	}
146 146
 
147 147
 
148
-    /**
149
-     * @param string $txn_status
150
-     * @param array  $response
151
-     * @param array  $data
152
-     * @return array
153
-     * @throws EE_Error
154
-     * @throws InvalidArgumentException
155
-     * @throws InvalidDataTypeException
156
-     * @throws InvalidInterfaceException
157
-     * @throws ReflectionException
158
-     */
159
-    private function getTransactionDetails($txn_status, $response, $data)
160
-    {
161
-        // has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
162
-        if ($txn_status !== $this->transaction->status_ID()) {
163
-            // switch between two possible basic outcomes
164
-            switch ($this->transaction->status_ID()) {
165
-                // TXN has been updated in some way
166
-                case EEM_Transaction::overpaid_status_code:
167
-                case EEM_Transaction::complete_status_code:
168
-                case EEM_Transaction::incomplete_status_code:
169
-                    // send updated TXN results back to client,
170
-                    return $this->setTransactionDetails($response);
171
-                // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
172
-                case EEM_Transaction::failed_status_code:
173
-                default:
174
-                    // keep on waiting...
175
-                    return $this->updateServerWaitTime($data[ $this->heartbeat ]);
176
-            }
177
-            // or is the TXN still failed (never been updated) ???
178
-        } elseif ($this->transaction->failed()) {
179
-            // keep on waiting...
180
-            return $this->updateServerWaitTime($data[ $this->heartbeat ]);
181
-        }
182
-        return $response;
183
-    }
148
+	/**
149
+	 * @param string $txn_status
150
+	 * @param array  $response
151
+	 * @param array  $data
152
+	 * @return array
153
+	 * @throws EE_Error
154
+	 * @throws InvalidArgumentException
155
+	 * @throws InvalidDataTypeException
156
+	 * @throws InvalidInterfaceException
157
+	 * @throws ReflectionException
158
+	 */
159
+	private function getTransactionDetails($txn_status, $response, $data)
160
+	{
161
+		// has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
162
+		if ($txn_status !== $this->transaction->status_ID()) {
163
+			// switch between two possible basic outcomes
164
+			switch ($this->transaction->status_ID()) {
165
+				// TXN has been updated in some way
166
+				case EEM_Transaction::overpaid_status_code:
167
+				case EEM_Transaction::complete_status_code:
168
+				case EEM_Transaction::incomplete_status_code:
169
+					// send updated TXN results back to client,
170
+					return $this->setTransactionDetails($response);
171
+				// or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
172
+				case EEM_Transaction::failed_status_code:
173
+				default:
174
+					// keep on waiting...
175
+					return $this->updateServerWaitTime($data[ $this->heartbeat ]);
176
+			}
177
+			// or is the TXN still failed (never been updated) ???
178
+		} elseif ($this->transaction->failed()) {
179
+			// keep on waiting...
180
+			return $this->updateServerWaitTime($data[ $this->heartbeat ]);
181
+		}
182
+		return $response;
183
+	}
184 184
 
185 185
 
186
-    /**
187
-     * @param array $response
188
-     * @param boolean $status_only
189
-     * @return array
190
-     * @throws EE_Error
191
-     * @throws InvalidArgumentException
192
-     * @throws InvalidDataTypeException
193
-     * @throws InvalidInterfaceException
194
-     * @throws ReflectionException
195
-     */
196
-    private function setTransactionDetails($response, $status_only = false)
197
-    {
198
-        if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) {
199
-            $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details();
200
-        }
201
-        if (! isset($response[ $this->heartbeat ]['txn_status'])) {
202
-            $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID();
203
-        }
204
-        return $response;
205
-    }
186
+	/**
187
+	 * @param array $response
188
+	 * @param boolean $status_only
189
+	 * @return array
190
+	 * @throws EE_Error
191
+	 * @throws InvalidArgumentException
192
+	 * @throws InvalidDataTypeException
193
+	 * @throws InvalidInterfaceException
194
+	 * @throws ReflectionException
195
+	 */
196
+	private function setTransactionDetails($response, $status_only = false)
197
+	{
198
+		if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) {
199
+			$response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details();
200
+		}
201
+		if (! isset($response[ $this->heartbeat ]['txn_status'])) {
202
+			$response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID();
203
+		}
204
+		return $response;
205
+	}
206 206
 
207 207
 
208
-    /**
209
-     * @param array $response
210
-     * @param int $since
211
-     * @return array
212
-     * @throws EE_Error
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidDataTypeException
215
-     * @throws InvalidInterfaceException
216
-     * @throws ReflectionException
217
-     */
218
-    private function paymentDetails($response, $since)
219
-    {
220
-        // then check for payments
221
-        $payments = $this->thank_you_page->get_txn_payments($since);
222
-        // has a payment been processed ?
223
-        if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
224
-            if ($since) {
225
-                $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments);
226
-                $response = $this->setTransactionDetails($response);
227
-            } else {
228
-                $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details(
229
-                    $payments
230
-                );
231
-            }
232
-            // reset time to check for payments
233
-            $response[ $this->heartbeat ]['get_payments_since'] = time();
234
-        } else {
235
-            $response[ $this->heartbeat ]['get_payments_since'] = $since;
236
-        }
237
-        return $response;
238
-    }
208
+	/**
209
+	 * @param array $response
210
+	 * @param int $since
211
+	 * @return array
212
+	 * @throws EE_Error
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidDataTypeException
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws ReflectionException
217
+	 */
218
+	private function paymentDetails($response, $since)
219
+	{
220
+		// then check for payments
221
+		$payments = $this->thank_you_page->get_txn_payments($since);
222
+		// has a payment been processed ?
223
+		if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
224
+			if ($since) {
225
+				$response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments);
226
+				$response = $this->setTransactionDetails($response);
227
+			} else {
228
+				$response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details(
229
+					$payments
230
+				);
231
+			}
232
+			// reset time to check for payments
233
+			$response[ $this->heartbeat ]['get_payments_since'] = time();
234
+		} else {
235
+			$response[ $this->heartbeat ]['get_payments_since'] = $since;
236
+		}
237
+		return $response;
238
+	}
239 239
 
240 240
 
241
-    /**
242
-     * @param array $thank_you_page_data    thank you page portion of the incoming JSON array
243
-     *                                      from the WP heartbeat data
244
-     * @return array
245
-     * @throws EE_Error
246
-     * @throws InvalidArgumentException
247
-     * @throws InvalidDataTypeException
248
-     * @throws InvalidInterfaceException
249
-     * @throws ReflectionException
250
-     */
251
-    private function updateServerWaitTime($thank_you_page_data)
252
-    {
253
-        $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access'])
254
-            ? time() - $thank_you_page_data['initial_access']
255
-            : 0;
256
-        $response = $this->setTransactionDetails($response, true);
257
-        return $response;
258
-    }
241
+	/**
242
+	 * @param array $thank_you_page_data    thank you page portion of the incoming JSON array
243
+	 *                                      from the WP heartbeat data
244
+	 * @return array
245
+	 * @throws EE_Error
246
+	 * @throws InvalidArgumentException
247
+	 * @throws InvalidDataTypeException
248
+	 * @throws InvalidInterfaceException
249
+	 * @throws ReflectionException
250
+	 */
251
+	private function updateServerWaitTime($thank_you_page_data)
252
+	{
253
+		$response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access'])
254
+			? time() - $thank_you_page_data['initial_access']
255
+			: 0;
256
+		$response = $this->setTransactionDetails($response, true);
257
+		return $response;
258
+	}
259 259
 }
Please login to merge, or discard this patch.