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