Completed
Branch BUG/fix-ee-rest-debug-headers (1355bc)
by
unknown
03:29 queued 18s
created
core/db_models/EEM_Payment.model.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
127 127
     {
128 128
         // all payments for a TXN ordered chronologically
129
-        $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
129
+        $query_params = array(array('TXN_ID' => $TXN_ID), 'order_by' => array('PAY_timestamp' => 'ASC'));
130 130
         // if provided with a status, search specifically for that status. Otherwise get them all
131 131
         if ($status_of_payment) {
132 132
             $query_params[0]['STS_ID'] = $status_of_payment;
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
     {
169 169
         $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
170 170
         // if $start_date or $end date, verify $format is included.
171
-        if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) {
171
+        if (( ! empty($start_date) || ! empty($end_date)) && empty($format)) {
172 172
             throw new EE_Error(esc_html__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query', 'event_espresso'));
173 173
         }
174 174
         $now = new DateTime('now');
@@ -178,12 +178,12 @@  discard block
 block discarded – undo
178 178
         // setup start date
179 179
         $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
180 180
         EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
181
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
181
+        $start_date = $start_date->format('Y-m-d').' 00:00:00';
182 182
         $start_date = strtotime($start_date);
183 183
         // setup end date
184 184
         $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
185 185
         EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
186
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
186
+        $end_date = $end_date->format('Y-m-d').' 23:59:59';
187 187
         $end_date = strtotime($end_date);
188 188
 
189 189
         // make sure our start date is the lowest value and vice versa
@@ -191,10 +191,10 @@  discard block
 block discarded – undo
191 191
         $end = max($start_date, $end_date);
192 192
 
193 193
         // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
194
-        $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
195
-        $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
194
+        $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start).' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
195
+        $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end).' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
196 196
 
197
-        return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date))));
197
+        return $this->get_all(array(array('PAY_timestamp' => array('>=', $start_date), 'PAY_timestamp*' => array('<=', $end_date))));
198 198
     }
199 199
 
200 200
     /**
Please login to merge, or discard this patch.
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -11,232 +11,232 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Payment extends EEM_Base implements EEMI_Payment
13 13
 {
14
-    // private instance of the Payment object
15
-    protected static $_instance = null;
14
+	// private instance of the Payment object
15
+	protected static $_instance = null;
16 16
 
17 17
 
18 18
 
19 19
 /**
20
-     * Status id in esp_status table that represents an approved payment
21
-     */
22
-    const status_id_approved = 'PAP';
23
-
24
-
25
-    /**
26
-     * Status id in esp_status table that represents a pending payment
27
-     */
28
-    const status_id_pending = 'PPN';
29
-
30
-
31
-    /**
32
-     * Status id in esp_status table that represents a cancelled payment (eg, the
33
-     * user went to PayPal, but on the paypal site decided to cancel the payment)
34
-     */
35
-    const status_id_cancelled = 'PCN';
36
-
37
-
38
-
39
-    /**
40
-     * Status id in esp_status table that represents a payment that was declined by
41
-     * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
42
-     */
43
-    const status_id_declined = 'PDC';
44
-
45
-
46
-
47
-    /**
48
-     * Status id in esp_status table that represents a payment that failed for technical reasons.
49
-     * (Eg, there was some error in communicating with the payment gateway.)
50
-     */
51
-    const status_id_failed = 'PFL';
52
-
53
-    /**
54
-     *      private constructor to prevent direct creation
55
-     *      @Constructor
56
-     *      @access protected
57
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
58
-     *      @return EEM_Payment
59
-     */
60
-    protected function __construct($timezone)
61
-    {
62
-
63
-        $this->singular_item = esc_html__('Payment', 'event_espresso');
64
-        $this->plural_item = esc_html__('Payments', 'event_espresso');
65
-
66
-        $this->_tables = array(
67
-            'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID')
68
-        );
69
-        $this->_fields = array(
70
-            'Payment' => array(
71
-                'PAY_ID' => new EE_Primary_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso')),
72
-                'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso'), false, 0, 'Transaction'),
73
-                'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'),
74
-                'PAY_timestamp' => new EE_Datetime_Field('PAY_timestamp', esc_html__('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
75
-                'PAY_source' => new EE_All_Caps_Text_Field('PAY_source', esc_html__('User-friendly description of payment', 'event_espresso'), false, 'CART'),
76
-                'PAY_amount' => new EE_Money_Field('PAY_amount', esc_html__('Amount Payment should be for', 'event_espresso'), false, 0),
77
-                'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'),
78
-                'PAY_gateway_response' => new EE_Plain_Text_Field('PAY_gateway_response', esc_html__('Response from Gateway about the payment', 'event_espresso'), false, ''),
79
-                'PAY_txn_id_chq_nmbr' => new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''),
80
-                'PAY_po_number' => new EE_Plain_Text_Field('PAY_po_number', esc_html__('Purchase or Sales Number', 'event_espresso'), true, ''),
81
-                'PAY_extra_accntng' => new EE_Simple_HTML_Field('PAY_extra_accntng', esc_html__('Extra Account Info', 'event_espresso'), true, ''),
82
-                'PAY_details' => new EE_Serialized_Text_Field('PAY_details', esc_html__('Full Gateway response about payment', 'event_espresso'), true, ''),
83
-                'PAY_redirect_url' => new EE_Plain_Text_Field('PAY_redirect_url', esc_html__("Redirect URL", 'event_espresso'), true),
84
-                'PAY_redirect_args' => new EE_Serialized_Text_Field('PAY_redirect_args', esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'), true)
85
-            )
86
-        );
87
-        $this->_model_relations = array(
88
-            'Transaction' => new EE_Belongs_To_Relation(),
89
-            'Status' => new EE_Belongs_To_Relation(),
90
-            'Payment_Method' => new EE_Belongs_To_Relation(),
91
-            'Registration_Payment' => new EE_Has_Many_Relation(),
92
-            'Registration' => new EE_HABTM_Relation('Registration_Payment'),
93
-        );
94
-        $this->_model_chain_to_wp_user = 'Payment_Method';
95
-        $this->_caps_slug = 'transactions';
96
-        parent::__construct($timezone);
97
-    }
98
-
99
-
100
-
101
-
102
-    /**
103
-     * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
104
-     * to the payment. This is handy for verifying an IPN hasn't already been processed.
105
-     * @param string $PAY_txn_id_chq_nmbr
106
-     * @return EE_Payment
107
-     */
108
-    public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
109
-    {
110
-        return $this->get_one(array(array('PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr)));
111
-    }
112
-
113
-
114
-
115
-
116
-    /**
117
-    *       retrieve  all payments from db for a particular transaction, optionally with
118
-     *      a particular status
119
-    *
120
-    *       @access     public
121
-    *       @param      $TXN_ID
122
-     *      @param  string  $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status
123
-    *       @return     EE_Payment[]
124
-    */
125
-    public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
126
-    {
127
-        // all payments for a TXN ordered chronologically
128
-        $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
129
-        // if provided with a status, search specifically for that status. Otherwise get them all
130
-        if ($status_of_payment) {
131
-            $query_params[0]['STS_ID'] = $status_of_payment;
132
-        }
133
-        // retrieve payments
134
-        return $this->get_all($query_params);
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     * Only gets payments which have been approved
141
-     * @param int $TXN_ID
142
-     * @return EE_Payment[]
143
-     */
144
-    public function get_approved_payments_for_transaction($TXN_ID = 0)
145
-    {
146
-        return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
147
-    }
148
-
149
-
150
-
151
-
152
-
153
-    /**
154
-     * retrieve  all payments from db between two dates,
155
-     *
156
-     * @param string $start_date incoming start date. If empty the beginning of today is used.
157
-     * @param string $end_date   incoming end date. If empty the end of today is used.
158
-     * @param string $format    If you include $start_date or $end_date then you must include the format string
159
-     *                              for the format your date is in.
160
-     * @param string $timezone   If your range is in a different timezone then the current setting on this
161
-     *                                  WordPress install, then include it here.
162
-     * @throws EE_Error
163
-     *
164
-     * @return EE_Payment[]
165
-     */
166
-    public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
167
-    {
168
-        $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
169
-        // if $start_date or $end date, verify $format is included.
170
-        if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) {
171
-            throw new EE_Error(esc_html__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query', 'event_espresso'));
172
-        }
173
-        $now = new DateTime('now');
174
-        // setup timezone objects once
175
-        $modelDateTimeZone = new DateTimeZone($this->_timezone);
176
-        $passedDateTimeZone = new DateTimeZone($timezone);
177
-        // setup start date
178
-        $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
179
-        EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
180
-        $start_date = $start_date->format('Y-m-d') . ' 00:00:00';
181
-        $start_date = strtotime($start_date);
182
-        // setup end date
183
-        $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
184
-        EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
185
-        $end_date = $end_date->format('Y-m-d') . ' 23:59:59';
186
-        $end_date = strtotime($end_date);
187
-
188
-        // make sure our start date is the lowest value and vice versa
189
-        $start = min($start_date, $end_date);
190
-        $end = max($start_date, $end_date);
191
-
192
-        // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
193
-        $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
194
-        $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
195
-
196
-        return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date))));
197
-    }
198
-
199
-    /**
200
-     * methods for EEMI_Payment
201
-     */
202
-    /**
203
-     * returns a string for the approved status
204
-     * @return  string
205
-     */
206
-    public function approved_status()
207
-    {
208
-        return self::status_id_approved;
209
-    }
210
-    /**
211
-     * returns a string for the pending status
212
-     * @return  string
213
-     */
214
-    public function pending_status()
215
-    {
216
-        return self::status_id_pending;
217
-    }
218
-    /**
219
-     * returns a string for the cancelled status
220
-     * @return  string
221
-     */
222
-    public function cancelled_status()
223
-    {
224
-        return self::status_id_cancelled;
225
-    }
226
-    /**
227
-     * returns a string for the failed status
228
-     * @return  string
229
-     */
230
-    public function failed_status()
231
-    {
232
-        return self::status_id_failed;
233
-    }
234
-    /**
235
-     * returns a string for the declined status
236
-     * @return  string
237
-     */
238
-    public function declined_status()
239
-    {
240
-        return self::status_id_declined;
241
-    }
20
+ * Status id in esp_status table that represents an approved payment
21
+ */
22
+	const status_id_approved = 'PAP';
23
+
24
+
25
+	/**
26
+	 * Status id in esp_status table that represents a pending payment
27
+	 */
28
+	const status_id_pending = 'PPN';
29
+
30
+
31
+	/**
32
+	 * Status id in esp_status table that represents a cancelled payment (eg, the
33
+	 * user went to PayPal, but on the paypal site decided to cancel the payment)
34
+	 */
35
+	const status_id_cancelled = 'PCN';
36
+
37
+
38
+
39
+	/**
40
+	 * Status id in esp_status table that represents a payment that was declined by
41
+	 * the gateway. (eg, the user's card had no funds, or it was a fraudulent card)
42
+	 */
43
+	const status_id_declined = 'PDC';
44
+
45
+
46
+
47
+	/**
48
+	 * Status id in esp_status table that represents a payment that failed for technical reasons.
49
+	 * (Eg, there was some error in communicating with the payment gateway.)
50
+	 */
51
+	const status_id_failed = 'PFL';
52
+
53
+	/**
54
+	 *      private constructor to prevent direct creation
55
+	 *      @Constructor
56
+	 *      @access protected
57
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
58
+	 *      @return EEM_Payment
59
+	 */
60
+	protected function __construct($timezone)
61
+	{
62
+
63
+		$this->singular_item = esc_html__('Payment', 'event_espresso');
64
+		$this->plural_item = esc_html__('Payments', 'event_espresso');
65
+
66
+		$this->_tables = array(
67
+			'Payment' => new EE_Primary_Table('esp_payment', 'PAY_ID')
68
+		);
69
+		$this->_fields = array(
70
+			'Payment' => array(
71
+				'PAY_ID' => new EE_Primary_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso')),
72
+				'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso'), false, 0, 'Transaction'),
73
+				'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'),
74
+				'PAY_timestamp' => new EE_Datetime_Field('PAY_timestamp', esc_html__('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone),
75
+				'PAY_source' => new EE_All_Caps_Text_Field('PAY_source', esc_html__('User-friendly description of payment', 'event_espresso'), false, 'CART'),
76
+				'PAY_amount' => new EE_Money_Field('PAY_amount', esc_html__('Amount Payment should be for', 'event_espresso'), false, 0),
77
+				'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', esc_html__("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'),
78
+				'PAY_gateway_response' => new EE_Plain_Text_Field('PAY_gateway_response', esc_html__('Response from Gateway about the payment', 'event_espresso'), false, ''),
79
+				'PAY_txn_id_chq_nmbr' => new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', esc_html__('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''),
80
+				'PAY_po_number' => new EE_Plain_Text_Field('PAY_po_number', esc_html__('Purchase or Sales Number', 'event_espresso'), true, ''),
81
+				'PAY_extra_accntng' => new EE_Simple_HTML_Field('PAY_extra_accntng', esc_html__('Extra Account Info', 'event_espresso'), true, ''),
82
+				'PAY_details' => new EE_Serialized_Text_Field('PAY_details', esc_html__('Full Gateway response about payment', 'event_espresso'), true, ''),
83
+				'PAY_redirect_url' => new EE_Plain_Text_Field('PAY_redirect_url', esc_html__("Redirect URL", 'event_espresso'), true),
84
+				'PAY_redirect_args' => new EE_Serialized_Text_Field('PAY_redirect_args', esc_html__("Key-Value POST vars to send along with redirect", 'event_espresso'), true)
85
+			)
86
+		);
87
+		$this->_model_relations = array(
88
+			'Transaction' => new EE_Belongs_To_Relation(),
89
+			'Status' => new EE_Belongs_To_Relation(),
90
+			'Payment_Method' => new EE_Belongs_To_Relation(),
91
+			'Registration_Payment' => new EE_Has_Many_Relation(),
92
+			'Registration' => new EE_HABTM_Relation('Registration_Payment'),
93
+		);
94
+		$this->_model_chain_to_wp_user = 'Payment_Method';
95
+		$this->_caps_slug = 'transactions';
96
+		parent::__construct($timezone);
97
+	}
98
+
99
+
100
+
101
+
102
+	/**
103
+	 * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned
104
+	 * to the payment. This is handy for verifying an IPN hasn't already been processed.
105
+	 * @param string $PAY_txn_id_chq_nmbr
106
+	 * @return EE_Payment
107
+	 */
108
+	public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr)
109
+	{
110
+		return $this->get_one(array(array('PAY_txn_id_chq_nmbr' => $PAY_txn_id_chq_nmbr)));
111
+	}
112
+
113
+
114
+
115
+
116
+	/**
117
+	 *       retrieve  all payments from db for a particular transaction, optionally with
118
+	 *      a particular status
119
+	 *
120
+	 *       @access     public
121
+	 *       @param      $TXN_ID
122
+	 *      @param  string  $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status
123
+	 *       @return     EE_Payment[]
124
+	 */
125
+	public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null)
126
+	{
127
+		// all payments for a TXN ordered chronologically
128
+		$query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' ));
129
+		// if provided with a status, search specifically for that status. Otherwise get them all
130
+		if ($status_of_payment) {
131
+			$query_params[0]['STS_ID'] = $status_of_payment;
132
+		}
133
+		// retrieve payments
134
+		return $this->get_all($query_params);
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 * Only gets payments which have been approved
141
+	 * @param int $TXN_ID
142
+	 * @return EE_Payment[]
143
+	 */
144
+	public function get_approved_payments_for_transaction($TXN_ID = 0)
145
+	{
146
+		return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved);
147
+	}
148
+
149
+
150
+
151
+
152
+
153
+	/**
154
+	 * retrieve  all payments from db between two dates,
155
+	 *
156
+	 * @param string $start_date incoming start date. If empty the beginning of today is used.
157
+	 * @param string $end_date   incoming end date. If empty the end of today is used.
158
+	 * @param string $format    If you include $start_date or $end_date then you must include the format string
159
+	 *                              for the format your date is in.
160
+	 * @param string $timezone   If your range is in a different timezone then the current setting on this
161
+	 *                                  WordPress install, then include it here.
162
+	 * @throws EE_Error
163
+	 *
164
+	 * @return EE_Payment[]
165
+	 */
166
+	public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '')
167
+	{
168
+		$timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
169
+		// if $start_date or $end date, verify $format is included.
170
+		if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) {
171
+			throw new EE_Error(esc_html__('You included a start date and/or a end date for this method but did not include a format string.  The format string is needed for setting up the query', 'event_espresso'));
172
+		}
173
+		$now = new DateTime('now');
174
+		// setup timezone objects once
175
+		$modelDateTimeZone = new DateTimeZone($this->_timezone);
176
+		$passedDateTimeZone = new DateTimeZone($timezone);
177
+		// setup start date
178
+		$start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now;
179
+		EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone);
180
+		$start_date = $start_date->format('Y-m-d') . ' 00:00:00';
181
+		$start_date = strtotime($start_date);
182
+		// setup end date
183
+		$end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now;
184
+		EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone);
185
+		$end_date = $end_date->format('Y-m-d') . ' 23:59:59';
186
+		$end_date = strtotime($end_date);
187
+
188
+		// make sure our start date is the lowest value and vice versa
189
+		$start = min($start_date, $end_date);
190
+		$end = max($start_date, $end_date);
191
+
192
+		// yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model.
193
+		$start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone());
194
+		$end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone());
195
+
196
+		return $this->get_all(array(array('PAY_timestamp' => array('>=',$start_date),'PAY_timestamp*' => array('<=',$end_date))));
197
+	}
198
+
199
+	/**
200
+	 * methods for EEMI_Payment
201
+	 */
202
+	/**
203
+	 * returns a string for the approved status
204
+	 * @return  string
205
+	 */
206
+	public function approved_status()
207
+	{
208
+		return self::status_id_approved;
209
+	}
210
+	/**
211
+	 * returns a string for the pending status
212
+	 * @return  string
213
+	 */
214
+	public function pending_status()
215
+	{
216
+		return self::status_id_pending;
217
+	}
218
+	/**
219
+	 * returns a string for the cancelled status
220
+	 * @return  string
221
+	 */
222
+	public function cancelled_status()
223
+	{
224
+		return self::status_id_cancelled;
225
+	}
226
+	/**
227
+	 * returns a string for the failed status
228
+	 * @return  string
229
+	 */
230
+	public function failed_status()
231
+	{
232
+		return self::status_id_failed;
233
+	}
234
+	/**
235
+	 * returns a string for the declined status
236
+	 * @return  string
237
+	 */
238
+	public function declined_status()
239
+	{
240
+		return self::status_id_declined;
241
+	}
242 242
 }
Please login to merge, or discard this patch.
core/business/EE_Transaction_Processor.class.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public static function instance($registration_query_params = array())
54 54
     {
55 55
         // check if class object is instantiated
56
-        if (! self::$_instance instanceof EE_Transaction_Processor) {
56
+        if ( ! self::$_instance instanceof EE_Transaction_Processor) {
57 57
             self::$_instance = new self($registration_query_params);
58 58
         }
59 59
         return self::$_instance;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         // these reg statuses should not be considered in any calculations involving monies owing
312 312
         $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
313 313
             : EEM_Registration::closed_reg_statuses();
314
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
314
+        if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
315 315
             return false;
316 316
         }
317 317
         try {
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
     public function get_transaction_for_registration(EE_Registration $registration)
366 366
     {
367 367
         $transaction = $registration->transaction();
368
-        if (! $transaction instanceof EE_Transaction) {
368
+        if ( ! $transaction instanceof EE_Transaction) {
369 369
             throw new EE_Error(
370 370
                 sprintf(
371 371
                     esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             $transaction->ID(),
396 396
             $registration->ticket_ID()
397 397
         );
398
-        if (! $ticket_line_item instanceof EE_Line_Item) {
398
+        if ( ! $ticket_line_item instanceof EE_Line_Item) {
399 399
             throw new EE_Error(
400 400
                 sprintf(
401 401
                     esc_html__(
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
         /** @type EE_Registration_Processor $registration_processor */
480 480
         $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
481 481
         // check that method exists
482
-        if (! method_exists($registration_processor, $method_name)) {
482
+        if ( ! method_exists($registration_processor, $method_name)) {
483 483
             throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso'));
484 484
         }
485 485
         // make sure some query params are set for retrieving registrations
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
                         $transaction,
538 538
                         EEM_Payment_Method::scope_cart
539 539
                     );
540
-                    if (! empty($available_payment_methods)) {
540
+                    if ( ! empty($available_payment_methods)) {
541 541
                         $PMD_ID = 0;
542 542
                         foreach ($available_payment_methods as $available_payment_method) {
543 543
                             if (
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
                                 break;
549 549
                             }
550 550
                         }
551
-                        if (! $PMD_ID) {
551
+                        if ( ! $PMD_ID) {
552 552
                             $first_payment_method = reset($available_payment_methods);
553 553
                             if ($first_payment_method instanceof EE_Payment_Method) {
554 554
                                 $PMD_ID = $first_payment_method->ID();
Please login to merge, or discard this patch.
Indentation   +948 added lines, -948 removed lines patch added patch discarded remove patch
@@ -16,952 +16,952 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Transaction_Processor extends EE_Processor_Base
18 18
 {
19
-    /**
20
-     * @var EE_Registration_Processor $_instance
21
-     * @access    private
22
-     */
23
-    private static $_instance;
24
-
25
-    /**
26
-     * array of query WHERE params to use when retrieving cached registrations from a transaction
27
-     *
28
-     * @var array $registration_query_params
29
-     * @access private
30
-     */
31
-    private $_registration_query_params = array();
32
-
33
-    /**
34
-     * @deprecated
35
-     * @var string
36
-     */
37
-    protected $_old_txn_status;
38
-
39
-    /**
40
-     * @deprecated
41
-     * @var string
42
-     */
43
-    protected $_new_txn_status;
44
-
45
-
46
-    /**
47
-     * @singleton method used to instantiate class object
48
-     * @access    public
49
-     * @param array $registration_query_params
50
-     * @return EE_Transaction_Processor instance
51
-     */
52
-    public static function instance($registration_query_params = array())
53
-    {
54
-        // check if class object is instantiated
55
-        if (! self::$_instance instanceof EE_Transaction_Processor) {
56
-            self::$_instance = new self($registration_query_params);
57
-        }
58
-        return self::$_instance;
59
-    }
60
-
61
-
62
-    /**
63
-     * @param array $registration_query_params
64
-     */
65
-    private function __construct($registration_query_params = array())
66
-    {
67
-        // make sure some query params are set for retrieving registrations
68
-        $this->_set_registration_query_params($registration_query_params);
69
-    }
70
-
71
-
72
-    /**
73
-     * @access private
74
-     * @param array $registration_query_params
75
-     */
76
-    private function _set_registration_query_params($registration_query_params)
77
-    {
78
-        $this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params
79
-            : array('order_by' => array('REG_count' => 'ASC'));
80
-    }
81
-
82
-
83
-    /**
84
-     * manually_update_registration_statuses
85
-     *
86
-     * @access public
87
-     * @param EE_Transaction $transaction
88
-     * @param string         $new_reg_status
89
-     * @param array          $registration_query_params array of query WHERE params to use
90
-     *                                                  when retrieving cached registrations from a transaction
91
-     * @return    boolean
92
-     * @throws \EE_Error
93
-     */
94
-    public function manually_update_registration_statuses(
95
-        EE_Transaction $transaction,
96
-        $new_reg_status = '',
97
-        $registration_query_params = array()
98
-    ) {
99
-        $status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
100
-            'manually_update_registration_status',
101
-            $transaction,
102
-            $registration_query_params,
103
-            $new_reg_status
104
-        );
105
-        // send messages
106
-        /** @type EE_Registration_Processor $registration_processor */
107
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
108
-        $registration_processor->trigger_registration_update_notifications(
109
-            $transaction->primary_registration(),
110
-            array('manually_updated' => true)
111
-        );
112
-        do_action(
113
-            'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
114
-            $transaction,
115
-            $status_updates
116
-        );
117
-        return $status_updates;
118
-    }
119
-
120
-
121
-    /**
122
-     * toggle_registration_statuses_for_default_approved_events
123
-     *
124
-     * @access public
125
-     * @param EE_Transaction $transaction
126
-     * @param array          $registration_query_params array of query WHERE params to use
127
-     *                                                  when retrieving cached registrations from a transaction
128
-     * @return    boolean
129
-     * @throws \EE_Error
130
-     */
131
-    public function toggle_registration_statuses_for_default_approved_events(
132
-        EE_Transaction $transaction,
133
-        $registration_query_params = array()
134
-    ) {
135
-        $status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
136
-            'toggle_registration_status_for_default_approved_events',
137
-            $transaction,
138
-            $registration_query_params
139
-        );
140
-        do_action(
141
-            'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
142
-            $transaction,
143
-            $status_updates
144
-        );
145
-        return $status_updates;
146
-    }
147
-
148
-
149
-    /**
150
-     * toggle_registration_statuses_if_no_monies_owing
151
-     *
152
-     * @access public
153
-     * @param EE_Transaction $transaction
154
-     * @param array          $registration_query_params array of query WHERE params to use
155
-     *                                                  when retrieving cached registrations from a transaction
156
-     * @return    boolean
157
-     * @throws \EE_Error
158
-     */
159
-    public function toggle_registration_statuses_if_no_monies_owing(
160
-        EE_Transaction $transaction,
161
-        $registration_query_params = array()
162
-    ) {
163
-        $status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
164
-            'toggle_registration_status_if_no_monies_owing',
165
-            $transaction,
166
-            $registration_query_params
167
-        );
168
-        do_action(
169
-            'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing',
170
-            $transaction,
171
-            $status_updates
172
-        );
173
-        return $status_updates;
174
-    }
175
-
176
-
177
-    /**
178
-     * update_transaction_and_registrations_after_checkout_or_payment
179
-     * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
180
-     *
181
-     * @param EE_Transaction     $transaction
182
-     * @param \EE_Payment | NULL $payment
183
-     * @param array              $registration_query_params    array of query WHERE params to use
184
-     *                                                         when retrieving cached registrations from a transaction
185
-     * @param bool               $trigger_notifications        whether or not to call
186
-     *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
187
-     * @return array
188
-     * @throws \EE_Error
189
-     */
190
-    public function update_transaction_and_registrations_after_checkout_or_payment(
191
-        EE_Transaction $transaction,
192
-        $payment = null,
193
-        $registration_query_params = array(),
194
-        $trigger_notifications = true
195
-    ) {
196
-        // make sure some query params are set for retrieving registrations
197
-        $this->_set_registration_query_params($registration_query_params);
198
-        // get final reg step status
199
-        $finalized = $transaction->final_reg_step_completed();
200
-        // if the 'finalize_registration' step has been initiated (has a timestamp)
201
-        // but has not yet been fully completed (TRUE)
202
-        if (is_int($finalized) && $finalized !== false && $finalized !== true) {
203
-            $transaction->set_reg_step_completed('finalize_registration');
204
-            $finalized = true;
205
-        }
206
-        $transaction->save();
207
-        // array of details to aid in decision making by systems
208
-        $update_params = array(
209
-            'old_txn_status'  => $transaction->old_txn_status(),
210
-            'new_txn_status'  => $transaction->status_ID(),
211
-            'finalized'       => $finalized,
212
-            'revisit'         => $this->_revisit,
213
-            'payment_updates' => $payment instanceof EE_Payment ? true : false,
214
-            'last_payment'    => $payment,
215
-        );
216
-        // now update the registrations and add the results to our $update_params
217
-        $update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor(
218
-            'update_registration_after_checkout_or_payment',
219
-            $transaction,
220
-            $this->_registration_query_params,
221
-            $update_params
222
-        );
223
-        if ($trigger_notifications) {
224
-            // send messages
225
-            /** @type EE_Registration_Processor $registration_processor */
226
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
227
-            $registration_processor->trigger_registration_update_notifications(
228
-                $transaction->primary_registration(),
229
-                $update_params
230
-            );
231
-        }
232
-        do_action(
233
-            'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
234
-            $transaction,
235
-            $update_params
236
-        );
237
-        return $update_params;
238
-    }
239
-
240
-
241
-    /**
242
-     * update_transaction_after_registration_reopened
243
-     * readjusts TXN and Line Item totals after a registration is changed from
244
-     * cancelled or declined to another reg status such as pending payment or approved
245
-     *
246
-     * @param \EE_Registration $registration
247
-     * @param array            $closed_reg_statuses
248
-     * @param bool             $update_txn
249
-     * @return bool
250
-     * @throws \EE_Error
251
-     */
252
-    public function update_transaction_after_reinstating_canceled_registration(
253
-        EE_Registration $registration,
254
-        $closed_reg_statuses = array(),
255
-        $update_txn = true
256
-    ) {
257
-        // these reg statuses should not be considered in any calculations involving monies owing
258
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
259
-            : EEM_Registration::closed_reg_statuses();
260
-        if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
261
-            return false;
262
-        }
263
-        try {
264
-            $transaction = $this->get_transaction_for_registration($registration);
265
-            $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
266
-                $transaction,
267
-                $registration
268
-            );
269
-            // un-cancel the ticket
270
-            $success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item);
271
-        } catch (EE_Error $e) {
272
-            EE_Error::add_error(
273
-                sprintf(
274
-                    esc_html__(
275
-                        'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s',
276
-                        'event_espresso'
277
-                    ),
278
-                    $registration->ID(),
279
-                    '<br />',
280
-                    $e->getMessage()
281
-                ),
282
-                __FILE__,
283
-                __FUNCTION__,
284
-                __LINE__
285
-            );
286
-            return false;
287
-        }
288
-        if ($update_txn) {
289
-            return $transaction->save() ? $success : false;
290
-        }
291
-        return $success;
292
-    }
293
-
294
-
295
-    /**
296
-     * update_transaction_after_canceled_or_declined_registration
297
-     * readjusts TXN and Line Item totals after a registration is cancelled or declined
298
-     *
299
-     * @param \EE_Registration $registration
300
-     * @param array            $closed_reg_statuses
301
-     * @param bool             $update_txn
302
-     * @return bool
303
-     * @throws \EE_Error
304
-     */
305
-    public function update_transaction_after_canceled_or_declined_registration(
306
-        EE_Registration $registration,
307
-        $closed_reg_statuses = array(),
308
-        $update_txn = true
309
-    ) {
310
-        // these reg statuses should not be considered in any calculations involving monies owing
311
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
312
-            : EEM_Registration::closed_reg_statuses();
313
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
314
-            return false;
315
-        }
316
-        try {
317
-            $transaction = $this->get_transaction_for_registration($registration);
318
-            if (
319
-                apply_filters(
320
-                    'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item',
321
-                    true,
322
-                    $registration,
323
-                    $transaction
324
-                )
325
-            ) {
326
-                $ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
327
-                    $transaction,
328
-                    $registration
329
-                );
330
-                EEH_Line_Item::cancel_ticket_line_item($ticket_line_item);
331
-            }
332
-        } catch (EE_Error $e) {
333
-            EE_Error::add_error(
334
-                sprintf(
335
-                    esc_html__(
336
-                        'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s',
337
-                        'event_espresso'
338
-                    ),
339
-                    $registration->ID(),
340
-                    '<br />',
341
-                    $e->getMessage()
342
-                ),
343
-                __FILE__,
344
-                __FUNCTION__,
345
-                __LINE__
346
-            );
347
-            return false;
348
-        }
349
-        if ($update_txn) {
350
-            return $transaction->save() ? true : false;
351
-        }
352
-        return true;
353
-    }
354
-
355
-
356
-    /**
357
-     * get_transaction_for_registration
358
-     *
359
-     * @access    public
360
-     * @param    EE_Registration $registration
361
-     * @return    EE_Transaction
362
-     * @throws    EE_Error
363
-     */
364
-    public function get_transaction_for_registration(EE_Registration $registration)
365
-    {
366
-        $transaction = $registration->transaction();
367
-        if (! $transaction instanceof EE_Transaction) {
368
-            throw new EE_Error(
369
-                sprintf(
370
-                    esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
371
-                    $registration->ID()
372
-                )
373
-            );
374
-        }
375
-        return $transaction;
376
-    }
377
-
378
-
379
-    /**
380
-     * get_ticket_line_item_for_transaction_registration
381
-     *
382
-     * @access    public
383
-     * @param    EE_Transaction  $transaction
384
-     * @param    EE_Registration $registration
385
-     * @return    EE_Line_Item
386
-     * @throws    EE_Error
387
-     */
388
-    public function get_ticket_line_item_for_transaction_registration(
389
-        EE_Transaction $transaction,
390
-        EE_Registration $registration
391
-    ) {
392
-        EE_Registry::instance()->load_helper('Line_Item');
393
-        $ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction(
394
-            $transaction->ID(),
395
-            $registration->ticket_ID()
396
-        );
397
-        if (! $ticket_line_item instanceof EE_Line_Item) {
398
-            throw new EE_Error(
399
-                sprintf(
400
-                    esc_html__(
401
-                        'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
402
-                        'event_espresso'
403
-                    ),
404
-                    $transaction->ID(),
405
-                    $registration->ticket_ID()
406
-                )
407
-            );
408
-        }
409
-        return $ticket_line_item;
410
-    }
411
-
412
-
413
-    /**
414
-     * cancel_transaction_if_all_registrations_canceled
415
-     * cycles thru related registrations and checks their statuses
416
-     * if ALL registrations are Cancelled or Declined, then this sets the TXN status to
417
-     *
418
-     * @access    public
419
-     * @param    EE_Transaction $transaction
420
-     * @param    string         $new_TXN_status
421
-     * @param    array          $registration_query_params - array of query WHERE params to use when
422
-     *                                                     retrieving cached registrations from a transaction
423
-     * @param    array          $closed_reg_statuses
424
-     * @param    bool           $update_txn
425
-     * @return    bool            true if TXN status was updated, false if not
426
-     */
427
-    public function toggle_transaction_status_if_all_registrations_canceled_or_declined(
428
-        EE_Transaction $transaction,
429
-        $new_TXN_status = '',
430
-        $registration_query_params = array(),
431
-        $closed_reg_statuses = array(),
432
-        $update_txn = true
433
-    ) {
434
-        // make sure some query params are set for retrieving registrations
435
-        $this->_set_registration_query_params($registration_query_params);
436
-        // these reg statuses should not be considered in any calculations involving monies owing
437
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
438
-            : EEM_Registration::closed_reg_statuses();
439
-        // loop through cached registrations
440
-        foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
441
-            if (
442
-                $registration instanceof EE_Registration
443
-                && ! in_array($registration->status_ID(), $closed_reg_statuses)
444
-            ) {
445
-                return false;
446
-            }
447
-        }
448
-        if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) {
449
-            $transaction->set_status($new_TXN_status);
450
-        }
451
-        if ($update_txn) {
452
-            return $transaction->save() ? true : false;
453
-        }
454
-        return true;
455
-    }
456
-
457
-
458
-    /**
459
-     * _call_method_on_registrations_via_Registration_Processor
460
-     * cycles thru related registrations and calls the requested method on each
461
-     *
462
-     * @access private
463
-     * @param string         $method_name
464
-     * @param EE_Transaction $transaction
465
-     * @param array          $registration_query_params array of query WHERE params to use
466
-     *                                                  when retrieving cached registrations from a transaction
467
-     * @param string         $additional_param
468
-     * @throws \EE_Error
469
-     * @return boolean
470
-     */
471
-    private function _call_method_on_registrations_via_Registration_Processor(
472
-        $method_name,
473
-        EE_Transaction $transaction,
474
-        $registration_query_params = array(),
475
-        $additional_param = null
476
-    ) {
477
-        $response = false;
478
-        /** @type EE_Registration_Processor $registration_processor */
479
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
480
-        // check that method exists
481
-        if (! method_exists($registration_processor, $method_name)) {
482
-            throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso'));
483
-        }
484
-        // make sure some query params are set for retrieving registrations
485
-        $this->_set_registration_query_params($registration_query_params);
486
-        // loop through cached registrations
487
-        foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
488
-            if ($registration instanceof EE_Registration) {
489
-                if ($additional_param) {
490
-                    $response = $registration_processor->{$method_name}($registration, $additional_param)
491
-                        ? true
492
-                        : $response;
493
-                } else {
494
-                    $response = $registration_processor->{$method_name}($registration)
495
-                        ? true
496
-                        : $response;
497
-                }
498
-            }
499
-        }
500
-        return $response;
501
-    }
502
-
503
-
504
-    /**
505
-     * set_transaction_payment_method_based_on_registration_statuses
506
-     * sets or unsets the PMD_ID field on the TXN based on the related REG statuses
507
-     * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null,
508
-     * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either:
509
-     *        the first "default" Payment Method
510
-     *        the first active Payment Method
511
-     *    whichever is found first.
512
-     *
513
-     * @param  EE_Registration $edited_registration
514
-     * @return void
515
-     * @throws \EE_Error
516
-     */
517
-    public function set_transaction_payment_method_based_on_registration_statuses(
518
-        EE_Registration $edited_registration
519
-    ) {
520
-        if ($edited_registration instanceof EE_Registration) {
521
-            $transaction = $edited_registration->transaction();
522
-            if ($transaction instanceof EE_Transaction) {
523
-                $all_not_approved = true;
524
-                foreach ($transaction->registrations() as $registration) {
525
-                    if ($registration instanceof EE_Registration) {
526
-                        // if any REG != "Not Approved" then toggle to false
527
-                        $all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
528
-                    }
529
-                }
530
-                // if ALL Registrations are "Not Approved"
531
-                if ($all_not_approved) {
532
-                    $transaction->set_payment_method_ID(null);
533
-                    $transaction->save();
534
-                } else {
535
-                    $available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
536
-                        $transaction,
537
-                        EEM_Payment_Method::scope_cart
538
-                    );
539
-                    if (! empty($available_payment_methods)) {
540
-                        $PMD_ID = 0;
541
-                        foreach ($available_payment_methods as $available_payment_method) {
542
-                            if (
543
-                                $available_payment_method instanceof EE_Payment_Method
544
-                                && $available_payment_method->open_by_default()
545
-                            ) {
546
-                                $PMD_ID = $available_payment_method->ID();
547
-                                break;
548
-                            }
549
-                        }
550
-                        if (! $PMD_ID) {
551
-                            $first_payment_method = reset($available_payment_methods);
552
-                            if ($first_payment_method instanceof EE_Payment_Method) {
553
-                                $PMD_ID = $first_payment_method->ID();
554
-                            } else {
555
-                                EE_Error::add_error(
556
-                                    esc_html__(
557
-                                        'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.',
558
-                                        'event_espresso'
559
-                                    ),
560
-                                    __FILE__,
561
-                                    __LINE__,
562
-                                    __FUNCTION__
563
-                                );
564
-                            }
565
-                        }
566
-                        $transaction->set_payment_method_ID($PMD_ID);
567
-                        $transaction->save();
568
-                    } else {
569
-                        EE_Error::add_error(
570
-                            esc_html__(
571
-                                'Please activate at least one Payment Method in order for things to operate correctly.',
572
-                                'event_espresso'
573
-                            ),
574
-                            __FILE__,
575
-                            __LINE__,
576
-                            __FUNCTION__
577
-                        );
578
-                    }
579
-                }
580
-            }
581
-        }
582
-    }
583
-
584
-
585
-
586
-    /********************************** DEPRECATED METHODS **********************************/
587
-
588
-
589
-    /**
590
-     * @deprecated 4.9.12
591
-     * @return string
592
-     */
593
-    public function old_txn_status()
594
-    {
595
-        EE_Error::doing_it_wrong(
596
-            __METHOD__,
597
-            esc_html__(
598
-                'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
599
-                'event_espresso'
600
-            ),
601
-            '4.9.12'
602
-        );
603
-        return $this->_old_txn_status;
604
-    }
605
-
606
-
607
-    /**
608
-     * @deprecated 4.9.12
609
-     * @param string $old_txn_status
610
-     */
611
-    public function set_old_txn_status($old_txn_status)
612
-    {
613
-        EE_Error::doing_it_wrong(
614
-            __METHOD__,
615
-            esc_html__(
616
-                'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
617
-                'event_espresso'
618
-            ),
619
-            '4.9.12'
620
-        );
621
-        // only set the first time
622
-        if ($this->_old_txn_status === null) {
623
-            $this->_old_txn_status = $old_txn_status;
624
-        }
625
-    }
626
-
627
-
628
-    /**
629
-     * @deprecated 4.9.12
630
-     * @return string
631
-     */
632
-    public function new_txn_status()
633
-    {
634
-        EE_Error::doing_it_wrong(
635
-            __METHOD__,
636
-            esc_html__(
637
-                'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
638
-                'event_espresso'
639
-            ),
640
-            '4.9.12'
641
-        );
642
-        return $this->_new_txn_status;
643
-    }
644
-
645
-
646
-    /**
647
-     * @deprecated 4.9.12
648
-     * @param string $new_txn_status
649
-     */
650
-    public function set_new_txn_status($new_txn_status)
651
-    {
652
-        EE_Error::doing_it_wrong(
653
-            __METHOD__,
654
-            esc_html__(
655
-                'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
656
-                'event_espresso'
657
-            ),
658
-            '4.9.12'
659
-        );
660
-        $this->_new_txn_status = $new_txn_status;
661
-    }
662
-
663
-
664
-    /**
665
-     * reg_status_updated
666
-     *
667
-     * @deprecated 4.9.12
668
-     * @return bool
669
-     */
670
-    public function txn_status_updated()
671
-    {
672
-        EE_Error::doing_it_wrong(
673
-            __METHOD__,
674
-            esc_html__(
675
-                'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
676
-                'event_espresso'
677
-            ),
678
-            '4.9.12'
679
-        );
680
-        return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
681
-    }
682
-
683
-
684
-    /**
685
-     * all_reg_steps_completed
686
-     * returns:
687
-     *    true if ALL reg steps have been marked as completed
688
-     *        or false if any step is not completed
689
-     *
690
-     * @deprecated 4.9.12
691
-     * @param EE_Transaction $transaction
692
-     * @return boolean
693
-     */
694
-    public function all_reg_steps_completed(EE_Transaction $transaction)
695
-    {
696
-        EE_Error::doing_it_wrong(
697
-            __METHOD__,
698
-            esc_html__(
699
-                'This logic has been moved into \EE_Transaction::all_reg_steps_completed(), please use that method instead.',
700
-                'event_espresso'
701
-            ),
702
-            '4.9.12',
703
-            '5.0.0'
704
-        );
705
-        return $transaction->all_reg_steps_completed();
706
-    }
707
-
708
-
709
-    /**
710
-     * all_reg_steps_completed_except
711
-     * returns:
712
-     *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
713
-     *        or false if any other step is not completed
714
-     *        or false if ALL steps are completed including the exception you are testing !!!
715
-     *
716
-     * @deprecated 4.9.12
717
-     * @param EE_Transaction $transaction
718
-     * @param string         $exception
719
-     * @return boolean
720
-     */
721
-    public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '')
722
-    {
723
-        EE_Error::doing_it_wrong(
724
-            __METHOD__,
725
-            esc_html__(
726
-                'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except(), please use that method instead.',
727
-                'event_espresso'
728
-            ),
729
-            '4.9.12',
730
-            '5.0.0'
731
-        );
732
-        return $transaction->all_reg_steps_completed_except($exception);
733
-    }
734
-
735
-
736
-    /**
737
-     * all_reg_steps_completed_except
738
-     * returns:
739
-     *        true if ALL reg steps, except the final step, have been marked as completed
740
-     *        or false if any step is not completed
741
-     *    or false if ALL steps are completed including the final step !!!
742
-     *
743
-     * @deprecated 4.9.12
744
-     * @param EE_Transaction $transaction
745
-     * @return boolean
746
-     */
747
-    public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction)
748
-    {
749
-        EE_Error::doing_it_wrong(
750
-            __METHOD__,
751
-            esc_html__(
752
-                'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except_final_step(), please use that method instead.',
753
-                'event_espresso'
754
-            ),
755
-            '4.9.12',
756
-            '5.0.0'
757
-        );
758
-        return $transaction->all_reg_steps_completed_except_final_step();
759
-    }
760
-
761
-
762
-    /**
763
-     * reg_step_completed
764
-     * returns:
765
-     *    true if a specific reg step has been marked as completed
766
-     *    a Unix timestamp if it has been initialized but not yet completed,
767
-     *    or false if it has not yet been initialized
768
-     *
769
-     * @deprecated 4.9.12
770
-     * @param EE_Transaction $transaction
771
-     * @param string         $reg_step_slug
772
-     * @return boolean | int
773
-     */
774
-    public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
775
-    {
776
-        EE_Error::doing_it_wrong(
777
-            __METHOD__,
778
-            esc_html__(
779
-                'This logic has been moved into \EE_Transaction::reg_step_completed(), please use that method instead.',
780
-                'event_espresso'
781
-            ),
782
-            '4.9.12',
783
-            '5.0.0'
784
-        );
785
-        return $transaction->reg_step_completed($reg_step_slug);
786
-    }
787
-
788
-
789
-    /**
790
-     * completed_final_reg_step
791
-     * returns:
792
-     *    true if the finalize_registration reg step has been marked as completed
793
-     *    a Unix timestamp if it has been initialized but not yet completed,
794
-     *    or false if it has not yet been initialized
795
-     *
796
-     * @deprecated 4.9.12
797
-     * @param EE_Transaction $transaction
798
-     * @return boolean | int
799
-     */
800
-    public function final_reg_step_completed(EE_Transaction $transaction)
801
-    {
802
-        EE_Error::doing_it_wrong(
803
-            __METHOD__,
804
-            esc_html__(
805
-                'This logic has been moved into \EE_Transaction::final_reg_step_completed(), please use that method instead.',
806
-                'event_espresso'
807
-            ),
808
-            '4.9.12',
809
-            '5.0.0'
810
-        );
811
-        return $transaction->final_reg_step_completed();
812
-    }
813
-
814
-
815
-    /**
816
-     * set_reg_step_initiated
817
-     * given a valid TXN_reg_step, this sets it's value to a unix timestamp
818
-     *
819
-     * @deprecated 4.9.12
820
-     * @access     public
821
-     * @param \EE_Transaction $transaction
822
-     * @param string          $reg_step_slug
823
-     * @return boolean
824
-     * @throws \EE_Error
825
-     */
826
-    public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug)
827
-    {
828
-        EE_Error::doing_it_wrong(
829
-            __METHOD__,
830
-            esc_html__(
831
-                'This logic has been moved into \EE_Transaction::set_reg_step_initiated(), please use that method instead.',
832
-                'event_espresso'
833
-            ),
834
-            '4.9.12',
835
-            '5.0.0'
836
-        );
837
-        return $transaction->set_reg_step_initiated($reg_step_slug);
838
-    }
839
-
840
-
841
-    /**
842
-     * set_reg_step_completed
843
-     * given a valid TXN_reg_step, this sets the step as completed
844
-     *
845
-     * @deprecated 4.9.12
846
-     * @access     public
847
-     * @param \EE_Transaction $transaction
848
-     * @param string          $reg_step_slug
849
-     * @return boolean
850
-     * @throws \EE_Error
851
-     */
852
-    public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
853
-    {
854
-        EE_Error::doing_it_wrong(
855
-            __METHOD__,
856
-            esc_html__(
857
-                'This logic has been moved into \EE_Transaction::set_reg_step_completed(), please use that method instead.',
858
-                'event_espresso'
859
-            ),
860
-            '4.9.12',
861
-            '5.0.0'
862
-        );
863
-        return $transaction->set_reg_step_completed($reg_step_slug);
864
-    }
865
-
866
-
867
-    /**
868
-     * set_reg_step_completed
869
-     * given a valid TXN_reg_step slug, this sets the step as NOT completed
870
-     *
871
-     * @deprecated 4.9.12
872
-     * @access     public
873
-     * @param \EE_Transaction $transaction
874
-     * @param string          $reg_step_slug
875
-     * @return boolean
876
-     * @throws \EE_Error
877
-     */
878
-    public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug)
879
-    {
880
-        EE_Error::doing_it_wrong(
881
-            __METHOD__,
882
-            esc_html__(
883
-                'This logic has been moved into \EE_Transaction::set_reg_step_not_completed(), please use that method instead.',
884
-                'event_espresso'
885
-            ),
886
-            '4.9.12',
887
-            '5.0.0'
888
-        );
889
-        return $transaction->set_reg_step_not_completed($reg_step_slug);
890
-    }
891
-
892
-
893
-    /**
894
-     * remove_reg_step
895
-     * given a valid TXN_reg_step slug, this will remove (unset)
896
-     * the reg step from the TXN reg step array
897
-     *
898
-     * @deprecated 4.9.12
899
-     * @access     public
900
-     * @param \EE_Transaction $transaction
901
-     * @param string          $reg_step_slug
902
-     * @return void
903
-     */
904
-    public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug)
905
-    {
906
-        EE_Error::doing_it_wrong(
907
-            __METHOD__,
908
-            esc_html__(
909
-                'This logic has been moved into \EE_Transaction::remove_reg_step(), please use that method instead.',
910
-                'event_espresso'
911
-            ),
912
-            '4.9.12',
913
-            '5.0.0'
914
-        );
915
-        $transaction->remove_reg_step($reg_step_slug);
916
-    }
917
-
918
-
919
-    /**
920
-     *    toggle_failed_transaction_status
921
-     * upgrades a TXNs status from failed to abandoned,
922
-     * meaning that contact information has been captured for at least one registrant
923
-     *
924
-     * @deprecated 4.9.12
925
-     * @access     public
926
-     * @param EE_Transaction $transaction
927
-     * @return    boolean
928
-     * @throws \EE_Error
929
-     */
930
-    public function toggle_failed_transaction_status(EE_Transaction $transaction)
931
-    {
932
-        EE_Error::doing_it_wrong(
933
-            __METHOD__,
934
-            esc_html__(
935
-                'This logic has been moved into \EE_Transaction::toggle_failed_transaction_status(), please use that method instead.',
936
-                'event_espresso'
937
-            ),
938
-            '4.9.12',
939
-            '5.0.0'
940
-        );
941
-        return $transaction->toggle_failed_transaction_status();
942
-    }
943
-
944
-
945
-    /**
946
-     * toggle_abandoned_transaction_status
947
-     * upgrades a TXNs status from failed or abandoned to incomplete
948
-     *
949
-     * @deprecated 4.9.12
950
-     * @access     public
951
-     * @param  EE_Transaction $transaction
952
-     * @return boolean
953
-     */
954
-    public function toggle_abandoned_transaction_status(EE_Transaction $transaction)
955
-    {
956
-        EE_Error::doing_it_wrong(
957
-            __METHOD__,
958
-            esc_html__(
959
-                'This logic has been moved into \EE_Transaction::toggle_abandoned_transaction_status(), please use that method instead.',
960
-                'event_espresso'
961
-            ),
962
-            '4.9.12',
963
-            '5.0.0'
964
-        );
965
-        return $transaction->toggle_abandoned_transaction_status();
966
-    }
19
+	/**
20
+	 * @var EE_Registration_Processor $_instance
21
+	 * @access    private
22
+	 */
23
+	private static $_instance;
24
+
25
+	/**
26
+	 * array of query WHERE params to use when retrieving cached registrations from a transaction
27
+	 *
28
+	 * @var array $registration_query_params
29
+	 * @access private
30
+	 */
31
+	private $_registration_query_params = array();
32
+
33
+	/**
34
+	 * @deprecated
35
+	 * @var string
36
+	 */
37
+	protected $_old_txn_status;
38
+
39
+	/**
40
+	 * @deprecated
41
+	 * @var string
42
+	 */
43
+	protected $_new_txn_status;
44
+
45
+
46
+	/**
47
+	 * @singleton method used to instantiate class object
48
+	 * @access    public
49
+	 * @param array $registration_query_params
50
+	 * @return EE_Transaction_Processor instance
51
+	 */
52
+	public static function instance($registration_query_params = array())
53
+	{
54
+		// check if class object is instantiated
55
+		if (! self::$_instance instanceof EE_Transaction_Processor) {
56
+			self::$_instance = new self($registration_query_params);
57
+		}
58
+		return self::$_instance;
59
+	}
60
+
61
+
62
+	/**
63
+	 * @param array $registration_query_params
64
+	 */
65
+	private function __construct($registration_query_params = array())
66
+	{
67
+		// make sure some query params are set for retrieving registrations
68
+		$this->_set_registration_query_params($registration_query_params);
69
+	}
70
+
71
+
72
+	/**
73
+	 * @access private
74
+	 * @param array $registration_query_params
75
+	 */
76
+	private function _set_registration_query_params($registration_query_params)
77
+	{
78
+		$this->_registration_query_params = ! empty($registration_query_params) ? $registration_query_params
79
+			: array('order_by' => array('REG_count' => 'ASC'));
80
+	}
81
+
82
+
83
+	/**
84
+	 * manually_update_registration_statuses
85
+	 *
86
+	 * @access public
87
+	 * @param EE_Transaction $transaction
88
+	 * @param string         $new_reg_status
89
+	 * @param array          $registration_query_params array of query WHERE params to use
90
+	 *                                                  when retrieving cached registrations from a transaction
91
+	 * @return    boolean
92
+	 * @throws \EE_Error
93
+	 */
94
+	public function manually_update_registration_statuses(
95
+		EE_Transaction $transaction,
96
+		$new_reg_status = '',
97
+		$registration_query_params = array()
98
+	) {
99
+		$status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
100
+			'manually_update_registration_status',
101
+			$transaction,
102
+			$registration_query_params,
103
+			$new_reg_status
104
+		);
105
+		// send messages
106
+		/** @type EE_Registration_Processor $registration_processor */
107
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
108
+		$registration_processor->trigger_registration_update_notifications(
109
+			$transaction->primary_registration(),
110
+			array('manually_updated' => true)
111
+		);
112
+		do_action(
113
+			'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
114
+			$transaction,
115
+			$status_updates
116
+		);
117
+		return $status_updates;
118
+	}
119
+
120
+
121
+	/**
122
+	 * toggle_registration_statuses_for_default_approved_events
123
+	 *
124
+	 * @access public
125
+	 * @param EE_Transaction $transaction
126
+	 * @param array          $registration_query_params array of query WHERE params to use
127
+	 *                                                  when retrieving cached registrations from a transaction
128
+	 * @return    boolean
129
+	 * @throws \EE_Error
130
+	 */
131
+	public function toggle_registration_statuses_for_default_approved_events(
132
+		EE_Transaction $transaction,
133
+		$registration_query_params = array()
134
+	) {
135
+		$status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
136
+			'toggle_registration_status_for_default_approved_events',
137
+			$transaction,
138
+			$registration_query_params
139
+		);
140
+		do_action(
141
+			'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
142
+			$transaction,
143
+			$status_updates
144
+		);
145
+		return $status_updates;
146
+	}
147
+
148
+
149
+	/**
150
+	 * toggle_registration_statuses_if_no_monies_owing
151
+	 *
152
+	 * @access public
153
+	 * @param EE_Transaction $transaction
154
+	 * @param array          $registration_query_params array of query WHERE params to use
155
+	 *                                                  when retrieving cached registrations from a transaction
156
+	 * @return    boolean
157
+	 * @throws \EE_Error
158
+	 */
159
+	public function toggle_registration_statuses_if_no_monies_owing(
160
+		EE_Transaction $transaction,
161
+		$registration_query_params = array()
162
+	) {
163
+		$status_updates = $this->_call_method_on_registrations_via_Registration_Processor(
164
+			'toggle_registration_status_if_no_monies_owing',
165
+			$transaction,
166
+			$registration_query_params
167
+		);
168
+		do_action(
169
+			'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing',
170
+			$transaction,
171
+			$status_updates
172
+		);
173
+		return $status_updates;
174
+	}
175
+
176
+
177
+	/**
178
+	 * update_transaction_and_registrations_after_checkout_or_payment
179
+	 * cycles thru related registrations and calls update_registration_after_checkout_or_payment() on each
180
+	 *
181
+	 * @param EE_Transaction     $transaction
182
+	 * @param \EE_Payment | NULL $payment
183
+	 * @param array              $registration_query_params    array of query WHERE params to use
184
+	 *                                                         when retrieving cached registrations from a transaction
185
+	 * @param bool               $trigger_notifications        whether or not to call
186
+	 *                                                         \EE_Registration_Processor::trigger_registration_update_notifications()
187
+	 * @return array
188
+	 * @throws \EE_Error
189
+	 */
190
+	public function update_transaction_and_registrations_after_checkout_or_payment(
191
+		EE_Transaction $transaction,
192
+		$payment = null,
193
+		$registration_query_params = array(),
194
+		$trigger_notifications = true
195
+	) {
196
+		// make sure some query params are set for retrieving registrations
197
+		$this->_set_registration_query_params($registration_query_params);
198
+		// get final reg step status
199
+		$finalized = $transaction->final_reg_step_completed();
200
+		// if the 'finalize_registration' step has been initiated (has a timestamp)
201
+		// but has not yet been fully completed (TRUE)
202
+		if (is_int($finalized) && $finalized !== false && $finalized !== true) {
203
+			$transaction->set_reg_step_completed('finalize_registration');
204
+			$finalized = true;
205
+		}
206
+		$transaction->save();
207
+		// array of details to aid in decision making by systems
208
+		$update_params = array(
209
+			'old_txn_status'  => $transaction->old_txn_status(),
210
+			'new_txn_status'  => $transaction->status_ID(),
211
+			'finalized'       => $finalized,
212
+			'revisit'         => $this->_revisit,
213
+			'payment_updates' => $payment instanceof EE_Payment ? true : false,
214
+			'last_payment'    => $payment,
215
+		);
216
+		// now update the registrations and add the results to our $update_params
217
+		$update_params['status_updates'] = $this->_call_method_on_registrations_via_Registration_Processor(
218
+			'update_registration_after_checkout_or_payment',
219
+			$transaction,
220
+			$this->_registration_query_params,
221
+			$update_params
222
+		);
223
+		if ($trigger_notifications) {
224
+			// send messages
225
+			/** @type EE_Registration_Processor $registration_processor */
226
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
227
+			$registration_processor->trigger_registration_update_notifications(
228
+				$transaction->primary_registration(),
229
+				$update_params
230
+			);
231
+		}
232
+		do_action(
233
+			'AHEE__EE_Transaction_Processor__update_transaction_and_registrations_after_checkout_or_payment',
234
+			$transaction,
235
+			$update_params
236
+		);
237
+		return $update_params;
238
+	}
239
+
240
+
241
+	/**
242
+	 * update_transaction_after_registration_reopened
243
+	 * readjusts TXN and Line Item totals after a registration is changed from
244
+	 * cancelled or declined to another reg status such as pending payment or approved
245
+	 *
246
+	 * @param \EE_Registration $registration
247
+	 * @param array            $closed_reg_statuses
248
+	 * @param bool             $update_txn
249
+	 * @return bool
250
+	 * @throws \EE_Error
251
+	 */
252
+	public function update_transaction_after_reinstating_canceled_registration(
253
+		EE_Registration $registration,
254
+		$closed_reg_statuses = array(),
255
+		$update_txn = true
256
+	) {
257
+		// these reg statuses should not be considered in any calculations involving monies owing
258
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
259
+			: EEM_Registration::closed_reg_statuses();
260
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
261
+			return false;
262
+		}
263
+		try {
264
+			$transaction = $this->get_transaction_for_registration($registration);
265
+			$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
266
+				$transaction,
267
+				$registration
268
+			);
269
+			// un-cancel the ticket
270
+			$success = EEH_Line_Item::reinstate_canceled_ticket_line_item($ticket_line_item);
271
+		} catch (EE_Error $e) {
272
+			EE_Error::add_error(
273
+				sprintf(
274
+					esc_html__(
275
+						'The Ticket Line Item for Registration %1$d could not be reinstated because :%2$s%3$s',
276
+						'event_espresso'
277
+					),
278
+					$registration->ID(),
279
+					'<br />',
280
+					$e->getMessage()
281
+				),
282
+				__FILE__,
283
+				__FUNCTION__,
284
+				__LINE__
285
+			);
286
+			return false;
287
+		}
288
+		if ($update_txn) {
289
+			return $transaction->save() ? $success : false;
290
+		}
291
+		return $success;
292
+	}
293
+
294
+
295
+	/**
296
+	 * update_transaction_after_canceled_or_declined_registration
297
+	 * readjusts TXN and Line Item totals after a registration is cancelled or declined
298
+	 *
299
+	 * @param \EE_Registration $registration
300
+	 * @param array            $closed_reg_statuses
301
+	 * @param bool             $update_txn
302
+	 * @return bool
303
+	 * @throws \EE_Error
304
+	 */
305
+	public function update_transaction_after_canceled_or_declined_registration(
306
+		EE_Registration $registration,
307
+		$closed_reg_statuses = array(),
308
+		$update_txn = true
309
+	) {
310
+		// these reg statuses should not be considered in any calculations involving monies owing
311
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
312
+			: EEM_Registration::closed_reg_statuses();
313
+		if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
314
+			return false;
315
+		}
316
+		try {
317
+			$transaction = $this->get_transaction_for_registration($registration);
318
+			if (
319
+				apply_filters(
320
+					'FHEE__EE_Transaction_Processor__update_transaction_after_canceled_or_declined_registration__cancel_ticket_line_item',
321
+					true,
322
+					$registration,
323
+					$transaction
324
+				)
325
+			) {
326
+				$ticket_line_item = $this->get_ticket_line_item_for_transaction_registration(
327
+					$transaction,
328
+					$registration
329
+				);
330
+				EEH_Line_Item::cancel_ticket_line_item($ticket_line_item);
331
+			}
332
+		} catch (EE_Error $e) {
333
+			EE_Error::add_error(
334
+				sprintf(
335
+					esc_html__(
336
+						'The Ticket Line Item for Registration %1$d could not be cancelled because :%2$s%3$s',
337
+						'event_espresso'
338
+					),
339
+					$registration->ID(),
340
+					'<br />',
341
+					$e->getMessage()
342
+				),
343
+				__FILE__,
344
+				__FUNCTION__,
345
+				__LINE__
346
+			);
347
+			return false;
348
+		}
349
+		if ($update_txn) {
350
+			return $transaction->save() ? true : false;
351
+		}
352
+		return true;
353
+	}
354
+
355
+
356
+	/**
357
+	 * get_transaction_for_registration
358
+	 *
359
+	 * @access    public
360
+	 * @param    EE_Registration $registration
361
+	 * @return    EE_Transaction
362
+	 * @throws    EE_Error
363
+	 */
364
+	public function get_transaction_for_registration(EE_Registration $registration)
365
+	{
366
+		$transaction = $registration->transaction();
367
+		if (! $transaction instanceof EE_Transaction) {
368
+			throw new EE_Error(
369
+				sprintf(
370
+					esc_html__('The Transaction for Registration %1$d was not found or is invalid.', 'event_espresso'),
371
+					$registration->ID()
372
+				)
373
+			);
374
+		}
375
+		return $transaction;
376
+	}
377
+
378
+
379
+	/**
380
+	 * get_ticket_line_item_for_transaction_registration
381
+	 *
382
+	 * @access    public
383
+	 * @param    EE_Transaction  $transaction
384
+	 * @param    EE_Registration $registration
385
+	 * @return    EE_Line_Item
386
+	 * @throws    EE_Error
387
+	 */
388
+	public function get_ticket_line_item_for_transaction_registration(
389
+		EE_Transaction $transaction,
390
+		EE_Registration $registration
391
+	) {
392
+		EE_Registry::instance()->load_helper('Line_Item');
393
+		$ticket_line_item = EEM_Line_Item::instance()->get_ticket_line_item_for_transaction(
394
+			$transaction->ID(),
395
+			$registration->ticket_ID()
396
+		);
397
+		if (! $ticket_line_item instanceof EE_Line_Item) {
398
+			throw new EE_Error(
399
+				sprintf(
400
+					esc_html__(
401
+						'The Line Item for Transaction %1$d and Ticket %2$d was not found or is invalid.',
402
+						'event_espresso'
403
+					),
404
+					$transaction->ID(),
405
+					$registration->ticket_ID()
406
+				)
407
+			);
408
+		}
409
+		return $ticket_line_item;
410
+	}
411
+
412
+
413
+	/**
414
+	 * cancel_transaction_if_all_registrations_canceled
415
+	 * cycles thru related registrations and checks their statuses
416
+	 * if ALL registrations are Cancelled or Declined, then this sets the TXN status to
417
+	 *
418
+	 * @access    public
419
+	 * @param    EE_Transaction $transaction
420
+	 * @param    string         $new_TXN_status
421
+	 * @param    array          $registration_query_params - array of query WHERE params to use when
422
+	 *                                                     retrieving cached registrations from a transaction
423
+	 * @param    array          $closed_reg_statuses
424
+	 * @param    bool           $update_txn
425
+	 * @return    bool            true if TXN status was updated, false if not
426
+	 */
427
+	public function toggle_transaction_status_if_all_registrations_canceled_or_declined(
428
+		EE_Transaction $transaction,
429
+		$new_TXN_status = '',
430
+		$registration_query_params = array(),
431
+		$closed_reg_statuses = array(),
432
+		$update_txn = true
433
+	) {
434
+		// make sure some query params are set for retrieving registrations
435
+		$this->_set_registration_query_params($registration_query_params);
436
+		// these reg statuses should not be considered in any calculations involving monies owing
437
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
438
+			: EEM_Registration::closed_reg_statuses();
439
+		// loop through cached registrations
440
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
441
+			if (
442
+				$registration instanceof EE_Registration
443
+				&& ! in_array($registration->status_ID(), $closed_reg_statuses)
444
+			) {
445
+				return false;
446
+			}
447
+		}
448
+		if (in_array($new_TXN_status, EEM_Transaction::txn_status_array())) {
449
+			$transaction->set_status($new_TXN_status);
450
+		}
451
+		if ($update_txn) {
452
+			return $transaction->save() ? true : false;
453
+		}
454
+		return true;
455
+	}
456
+
457
+
458
+	/**
459
+	 * _call_method_on_registrations_via_Registration_Processor
460
+	 * cycles thru related registrations and calls the requested method on each
461
+	 *
462
+	 * @access private
463
+	 * @param string         $method_name
464
+	 * @param EE_Transaction $transaction
465
+	 * @param array          $registration_query_params array of query WHERE params to use
466
+	 *                                                  when retrieving cached registrations from a transaction
467
+	 * @param string         $additional_param
468
+	 * @throws \EE_Error
469
+	 * @return boolean
470
+	 */
471
+	private function _call_method_on_registrations_via_Registration_Processor(
472
+		$method_name,
473
+		EE_Transaction $transaction,
474
+		$registration_query_params = array(),
475
+		$additional_param = null
476
+	) {
477
+		$response = false;
478
+		/** @type EE_Registration_Processor $registration_processor */
479
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
480
+		// check that method exists
481
+		if (! method_exists($registration_processor, $method_name)) {
482
+			throw new EE_Error(esc_html__('Method does not exist.', 'event_espresso'));
483
+		}
484
+		// make sure some query params are set for retrieving registrations
485
+		$this->_set_registration_query_params($registration_query_params);
486
+		// loop through cached registrations
487
+		foreach ($transaction->registrations($this->_registration_query_params) as $registration) {
488
+			if ($registration instanceof EE_Registration) {
489
+				if ($additional_param) {
490
+					$response = $registration_processor->{$method_name}($registration, $additional_param)
491
+						? true
492
+						: $response;
493
+				} else {
494
+					$response = $registration_processor->{$method_name}($registration)
495
+						? true
496
+						: $response;
497
+				}
498
+			}
499
+		}
500
+		return $response;
501
+	}
502
+
503
+
504
+	/**
505
+	 * set_transaction_payment_method_based_on_registration_statuses
506
+	 * sets or unsets the PMD_ID field on the TXN based on the related REG statuses
507
+	 * basically if ALL Registrations are "Not Approved", then the EE_Transaction.PMD_ID is set to null,
508
+	 * but if any Registration has a different status, then EE_Transaction.PMD_ID is set to either:
509
+	 *        the first "default" Payment Method
510
+	 *        the first active Payment Method
511
+	 *    whichever is found first.
512
+	 *
513
+	 * @param  EE_Registration $edited_registration
514
+	 * @return void
515
+	 * @throws \EE_Error
516
+	 */
517
+	public function set_transaction_payment_method_based_on_registration_statuses(
518
+		EE_Registration $edited_registration
519
+	) {
520
+		if ($edited_registration instanceof EE_Registration) {
521
+			$transaction = $edited_registration->transaction();
522
+			if ($transaction instanceof EE_Transaction) {
523
+				$all_not_approved = true;
524
+				foreach ($transaction->registrations() as $registration) {
525
+					if ($registration instanceof EE_Registration) {
526
+						// if any REG != "Not Approved" then toggle to false
527
+						$all_not_approved = $registration->is_not_approved() ? $all_not_approved : false;
528
+					}
529
+				}
530
+				// if ALL Registrations are "Not Approved"
531
+				if ($all_not_approved) {
532
+					$transaction->set_payment_method_ID(null);
533
+					$transaction->save();
534
+				} else {
535
+					$available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
536
+						$transaction,
537
+						EEM_Payment_Method::scope_cart
538
+					);
539
+					if (! empty($available_payment_methods)) {
540
+						$PMD_ID = 0;
541
+						foreach ($available_payment_methods as $available_payment_method) {
542
+							if (
543
+								$available_payment_method instanceof EE_Payment_Method
544
+								&& $available_payment_method->open_by_default()
545
+							) {
546
+								$PMD_ID = $available_payment_method->ID();
547
+								break;
548
+							}
549
+						}
550
+						if (! $PMD_ID) {
551
+							$first_payment_method = reset($available_payment_methods);
552
+							if ($first_payment_method instanceof EE_Payment_Method) {
553
+								$PMD_ID = $first_payment_method->ID();
554
+							} else {
555
+								EE_Error::add_error(
556
+									esc_html__(
557
+										'A valid Payment Method could not be determined. Please ensure that at least one Payment Method is activated.',
558
+										'event_espresso'
559
+									),
560
+									__FILE__,
561
+									__LINE__,
562
+									__FUNCTION__
563
+								);
564
+							}
565
+						}
566
+						$transaction->set_payment_method_ID($PMD_ID);
567
+						$transaction->save();
568
+					} else {
569
+						EE_Error::add_error(
570
+							esc_html__(
571
+								'Please activate at least one Payment Method in order for things to operate correctly.',
572
+								'event_espresso'
573
+							),
574
+							__FILE__,
575
+							__LINE__,
576
+							__FUNCTION__
577
+						);
578
+					}
579
+				}
580
+			}
581
+		}
582
+	}
583
+
584
+
585
+
586
+	/********************************** DEPRECATED METHODS **********************************/
587
+
588
+
589
+	/**
590
+	 * @deprecated 4.9.12
591
+	 * @return string
592
+	 */
593
+	public function old_txn_status()
594
+	{
595
+		EE_Error::doing_it_wrong(
596
+			__METHOD__,
597
+			esc_html__(
598
+				'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
599
+				'event_espresso'
600
+			),
601
+			'4.9.12'
602
+		);
603
+		return $this->_old_txn_status;
604
+	}
605
+
606
+
607
+	/**
608
+	 * @deprecated 4.9.12
609
+	 * @param string $old_txn_status
610
+	 */
611
+	public function set_old_txn_status($old_txn_status)
612
+	{
613
+		EE_Error::doing_it_wrong(
614
+			__METHOD__,
615
+			esc_html__(
616
+				'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
617
+				'event_espresso'
618
+			),
619
+			'4.9.12'
620
+		);
621
+		// only set the first time
622
+		if ($this->_old_txn_status === null) {
623
+			$this->_old_txn_status = $old_txn_status;
624
+		}
625
+	}
626
+
627
+
628
+	/**
629
+	 * @deprecated 4.9.12
630
+	 * @return string
631
+	 */
632
+	public function new_txn_status()
633
+	{
634
+		EE_Error::doing_it_wrong(
635
+			__METHOD__,
636
+			esc_html__(
637
+				'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
638
+				'event_espresso'
639
+			),
640
+			'4.9.12'
641
+		);
642
+		return $this->_new_txn_status;
643
+	}
644
+
645
+
646
+	/**
647
+	 * @deprecated 4.9.12
648
+	 * @param string $new_txn_status
649
+	 */
650
+	public function set_new_txn_status($new_txn_status)
651
+	{
652
+		EE_Error::doing_it_wrong(
653
+			__METHOD__,
654
+			esc_html__(
655
+				'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
656
+				'event_espresso'
657
+			),
658
+			'4.9.12'
659
+		);
660
+		$this->_new_txn_status = $new_txn_status;
661
+	}
662
+
663
+
664
+	/**
665
+	 * reg_status_updated
666
+	 *
667
+	 * @deprecated 4.9.12
668
+	 * @return bool
669
+	 */
670
+	public function txn_status_updated()
671
+	{
672
+		EE_Error::doing_it_wrong(
673
+			__METHOD__,
674
+			esc_html__(
675
+				'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
676
+				'event_espresso'
677
+			),
678
+			'4.9.12'
679
+		);
680
+		return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
681
+	}
682
+
683
+
684
+	/**
685
+	 * all_reg_steps_completed
686
+	 * returns:
687
+	 *    true if ALL reg steps have been marked as completed
688
+	 *        or false if any step is not completed
689
+	 *
690
+	 * @deprecated 4.9.12
691
+	 * @param EE_Transaction $transaction
692
+	 * @return boolean
693
+	 */
694
+	public function all_reg_steps_completed(EE_Transaction $transaction)
695
+	{
696
+		EE_Error::doing_it_wrong(
697
+			__METHOD__,
698
+			esc_html__(
699
+				'This logic has been moved into \EE_Transaction::all_reg_steps_completed(), please use that method instead.',
700
+				'event_espresso'
701
+			),
702
+			'4.9.12',
703
+			'5.0.0'
704
+		);
705
+		return $transaction->all_reg_steps_completed();
706
+	}
707
+
708
+
709
+	/**
710
+	 * all_reg_steps_completed_except
711
+	 * returns:
712
+	 *        true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed
713
+	 *        or false if any other step is not completed
714
+	 *        or false if ALL steps are completed including the exception you are testing !!!
715
+	 *
716
+	 * @deprecated 4.9.12
717
+	 * @param EE_Transaction $transaction
718
+	 * @param string         $exception
719
+	 * @return boolean
720
+	 */
721
+	public function all_reg_steps_completed_except(EE_Transaction $transaction, $exception = '')
722
+	{
723
+		EE_Error::doing_it_wrong(
724
+			__METHOD__,
725
+			esc_html__(
726
+				'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except(), please use that method instead.',
727
+				'event_espresso'
728
+			),
729
+			'4.9.12',
730
+			'5.0.0'
731
+		);
732
+		return $transaction->all_reg_steps_completed_except($exception);
733
+	}
734
+
735
+
736
+	/**
737
+	 * all_reg_steps_completed_except
738
+	 * returns:
739
+	 *        true if ALL reg steps, except the final step, have been marked as completed
740
+	 *        or false if any step is not completed
741
+	 *    or false if ALL steps are completed including the final step !!!
742
+	 *
743
+	 * @deprecated 4.9.12
744
+	 * @param EE_Transaction $transaction
745
+	 * @return boolean
746
+	 */
747
+	public function all_reg_steps_completed_except_final_step(EE_Transaction $transaction)
748
+	{
749
+		EE_Error::doing_it_wrong(
750
+			__METHOD__,
751
+			esc_html__(
752
+				'This logic has been moved into \EE_Transaction::all_reg_steps_completed_except_final_step(), please use that method instead.',
753
+				'event_espresso'
754
+			),
755
+			'4.9.12',
756
+			'5.0.0'
757
+		);
758
+		return $transaction->all_reg_steps_completed_except_final_step();
759
+	}
760
+
761
+
762
+	/**
763
+	 * reg_step_completed
764
+	 * returns:
765
+	 *    true if a specific reg step has been marked as completed
766
+	 *    a Unix timestamp if it has been initialized but not yet completed,
767
+	 *    or false if it has not yet been initialized
768
+	 *
769
+	 * @deprecated 4.9.12
770
+	 * @param EE_Transaction $transaction
771
+	 * @param string         $reg_step_slug
772
+	 * @return boolean | int
773
+	 */
774
+	public function reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
775
+	{
776
+		EE_Error::doing_it_wrong(
777
+			__METHOD__,
778
+			esc_html__(
779
+				'This logic has been moved into \EE_Transaction::reg_step_completed(), please use that method instead.',
780
+				'event_espresso'
781
+			),
782
+			'4.9.12',
783
+			'5.0.0'
784
+		);
785
+		return $transaction->reg_step_completed($reg_step_slug);
786
+	}
787
+
788
+
789
+	/**
790
+	 * completed_final_reg_step
791
+	 * returns:
792
+	 *    true if the finalize_registration reg step has been marked as completed
793
+	 *    a Unix timestamp if it has been initialized but not yet completed,
794
+	 *    or false if it has not yet been initialized
795
+	 *
796
+	 * @deprecated 4.9.12
797
+	 * @param EE_Transaction $transaction
798
+	 * @return boolean | int
799
+	 */
800
+	public function final_reg_step_completed(EE_Transaction $transaction)
801
+	{
802
+		EE_Error::doing_it_wrong(
803
+			__METHOD__,
804
+			esc_html__(
805
+				'This logic has been moved into \EE_Transaction::final_reg_step_completed(), please use that method instead.',
806
+				'event_espresso'
807
+			),
808
+			'4.9.12',
809
+			'5.0.0'
810
+		);
811
+		return $transaction->final_reg_step_completed();
812
+	}
813
+
814
+
815
+	/**
816
+	 * set_reg_step_initiated
817
+	 * given a valid TXN_reg_step, this sets it's value to a unix timestamp
818
+	 *
819
+	 * @deprecated 4.9.12
820
+	 * @access     public
821
+	 * @param \EE_Transaction $transaction
822
+	 * @param string          $reg_step_slug
823
+	 * @return boolean
824
+	 * @throws \EE_Error
825
+	 */
826
+	public function set_reg_step_initiated(EE_Transaction $transaction, $reg_step_slug)
827
+	{
828
+		EE_Error::doing_it_wrong(
829
+			__METHOD__,
830
+			esc_html__(
831
+				'This logic has been moved into \EE_Transaction::set_reg_step_initiated(), please use that method instead.',
832
+				'event_espresso'
833
+			),
834
+			'4.9.12',
835
+			'5.0.0'
836
+		);
837
+		return $transaction->set_reg_step_initiated($reg_step_slug);
838
+	}
839
+
840
+
841
+	/**
842
+	 * set_reg_step_completed
843
+	 * given a valid TXN_reg_step, this sets the step as completed
844
+	 *
845
+	 * @deprecated 4.9.12
846
+	 * @access     public
847
+	 * @param \EE_Transaction $transaction
848
+	 * @param string          $reg_step_slug
849
+	 * @return boolean
850
+	 * @throws \EE_Error
851
+	 */
852
+	public function set_reg_step_completed(EE_Transaction $transaction, $reg_step_slug)
853
+	{
854
+		EE_Error::doing_it_wrong(
855
+			__METHOD__,
856
+			esc_html__(
857
+				'This logic has been moved into \EE_Transaction::set_reg_step_completed(), please use that method instead.',
858
+				'event_espresso'
859
+			),
860
+			'4.9.12',
861
+			'5.0.0'
862
+		);
863
+		return $transaction->set_reg_step_completed($reg_step_slug);
864
+	}
865
+
866
+
867
+	/**
868
+	 * set_reg_step_completed
869
+	 * given a valid TXN_reg_step slug, this sets the step as NOT completed
870
+	 *
871
+	 * @deprecated 4.9.12
872
+	 * @access     public
873
+	 * @param \EE_Transaction $transaction
874
+	 * @param string          $reg_step_slug
875
+	 * @return boolean
876
+	 * @throws \EE_Error
877
+	 */
878
+	public function set_reg_step_not_completed(EE_Transaction $transaction, $reg_step_slug)
879
+	{
880
+		EE_Error::doing_it_wrong(
881
+			__METHOD__,
882
+			esc_html__(
883
+				'This logic has been moved into \EE_Transaction::set_reg_step_not_completed(), please use that method instead.',
884
+				'event_espresso'
885
+			),
886
+			'4.9.12',
887
+			'5.0.0'
888
+		);
889
+		return $transaction->set_reg_step_not_completed($reg_step_slug);
890
+	}
891
+
892
+
893
+	/**
894
+	 * remove_reg_step
895
+	 * given a valid TXN_reg_step slug, this will remove (unset)
896
+	 * the reg step from the TXN reg step array
897
+	 *
898
+	 * @deprecated 4.9.12
899
+	 * @access     public
900
+	 * @param \EE_Transaction $transaction
901
+	 * @param string          $reg_step_slug
902
+	 * @return void
903
+	 */
904
+	public function remove_reg_step(EE_Transaction $transaction, $reg_step_slug)
905
+	{
906
+		EE_Error::doing_it_wrong(
907
+			__METHOD__,
908
+			esc_html__(
909
+				'This logic has been moved into \EE_Transaction::remove_reg_step(), please use that method instead.',
910
+				'event_espresso'
911
+			),
912
+			'4.9.12',
913
+			'5.0.0'
914
+		);
915
+		$transaction->remove_reg_step($reg_step_slug);
916
+	}
917
+
918
+
919
+	/**
920
+	 *    toggle_failed_transaction_status
921
+	 * upgrades a TXNs status from failed to abandoned,
922
+	 * meaning that contact information has been captured for at least one registrant
923
+	 *
924
+	 * @deprecated 4.9.12
925
+	 * @access     public
926
+	 * @param EE_Transaction $transaction
927
+	 * @return    boolean
928
+	 * @throws \EE_Error
929
+	 */
930
+	public function toggle_failed_transaction_status(EE_Transaction $transaction)
931
+	{
932
+		EE_Error::doing_it_wrong(
933
+			__METHOD__,
934
+			esc_html__(
935
+				'This logic has been moved into \EE_Transaction::toggle_failed_transaction_status(), please use that method instead.',
936
+				'event_espresso'
937
+			),
938
+			'4.9.12',
939
+			'5.0.0'
940
+		);
941
+		return $transaction->toggle_failed_transaction_status();
942
+	}
943
+
944
+
945
+	/**
946
+	 * toggle_abandoned_transaction_status
947
+	 * upgrades a TXNs status from failed or abandoned to incomplete
948
+	 *
949
+	 * @deprecated 4.9.12
950
+	 * @access     public
951
+	 * @param  EE_Transaction $transaction
952
+	 * @return boolean
953
+	 */
954
+	public function toggle_abandoned_transaction_status(EE_Transaction $transaction)
955
+	{
956
+		EE_Error::doing_it_wrong(
957
+			__METHOD__,
958
+			esc_html__(
959
+				'This logic has been moved into \EE_Transaction::toggle_abandoned_transaction_status(), please use that method instead.',
960
+				'event_espresso'
961
+			),
962
+			'4.9.12',
963
+			'5.0.0'
964
+		);
965
+		return $transaction->toggle_abandoned_transaction_status();
966
+	}
967 967
 }
Please login to merge, or discard this patch.
core/business/EE_Transaction_Payments.class.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     public static function instance()
43 43
     {
44 44
         // check if class object is instantiated
45
-        if (! self::$_instance instanceof EE_Transaction_Payments) {
45
+        if ( ! self::$_instance instanceof EE_Transaction_Payments) {
46 46
             self::$_instance = new self();
47 47
         }
48 48
         return self::$_instance;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true)
62 62
     {
63 63
         $total_line_item = $transaction->total_line_item();
64
-        if (! $total_line_item instanceof EE_Line_Item) {
64
+        if ( ! $total_line_item instanceof EE_Line_Item) {
65 65
             EE_Error::add_error(
66 66
                 sprintf(
67 67
                     esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'),
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true)
101 101
     {
102 102
         // verify transaction
103
-        if (! $transaction instanceof EE_Transaction) {
103
+        if ( ! $transaction instanceof EE_Transaction) {
104 104
             EE_Error::add_error(
105 105
                 esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
106 106
                 __FILE__,
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
116 116
             $transaction->set_paid($total_paid);
117 117
             // maybe update status, and make sure to save transaction if not done already
118
-            if (! $transaction->update_status_based_on_total_paid($update_txn)) {
118
+            if ( ! $transaction->update_status_based_on_total_paid($update_txn)) {
119 119
                 if ($update_txn) {
120 120
                     return $transaction->save() ? true : false;
121 121
                 }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
         $payment_status = EEM_Payment::status_id_approved
145 145
     ) {
146 146
         // verify transaction
147
-        if (! $transaction instanceof EE_Transaction) {
147
+        if ( ! $transaction instanceof EE_Transaction) {
148 148
             EE_Error::add_error(
149 149
                 esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
150 150
                 __FILE__,
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     public function delete_payment_and_update_transaction(EE_Payment $payment)
178 178
     {
179 179
         // verify payment
180
-        if (! $payment instanceof EE_Payment) {
180
+        if ( ! $payment instanceof EE_Payment) {
181 181
             EE_Error::add_error(
182 182
                 esc_html__('A valid Payment object was not received.', 'event_espresso'),
183 183
                 __FILE__,
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
             );
187 187
             return false;
188 188
         }
189
-        if (! $this->delete_registration_payments_and_update_registrations($payment)) {
189
+        if ( ! $this->delete_registration_payments_and_update_registrations($payment)) {
190 190
             return false;
191 191
         }
192
-        if (! $payment->delete()) {
192
+        if ( ! $payment->delete()) {
193 193
             EE_Error::add_error(
194 194
                 esc_html__('The payment could not be deleted.', 'event_espresso'),
195 195
                 __FILE__,
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 
214 214
         // if this fails, that just means that the transaction didn't get its status changed and/or updated.
215 215
         // however the payment was still deleted.
216
-        if (! $this->calculate_total_payments_and_update_status($transaction)) {
216
+        if ( ! $this->calculate_total_payments_and_update_status($transaction)) {
217 217
             EE_Error::add_attention(
218 218
                 esc_html__(
219 219
                     'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..',
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params
256 256
             : array(array('PAY_ID' => $payment->ID()));
257 257
         $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
258
-        if (! empty($registration_payments)) {
258
+        if ( ! empty($registration_payments)) {
259 259
             foreach ($registration_payments as $registration_payment) {
260 260
                 if ($registration_payment instanceof EE_Registration_Payment) {
261 261
                     $amount_paid = $registration_payment->amount();
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
322 322
     {
323 323
         EE_Error::doing_it_wrong(
324
-            __CLASS__ . '::' . __FUNCTION__,
324
+            __CLASS__.'::'.__FUNCTION__,
325 325
             sprintf(
326 326
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
327 327
                 'EE_Transaction::update_status_based_on_total_paid()'
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
             '5.0.0'
331 331
         );
332 332
         // verify transaction
333
-        if (! $transaction instanceof EE_Transaction) {
333
+        if ( ! $transaction instanceof EE_Transaction) {
334 334
             EE_Error::add_error(
335 335
                 esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
336 336
                 __FILE__,
Please login to merge, or discard this patch.
Indentation   +420 added lines, -420 removed lines patch added patch discarded remove patch
@@ -14,424 +14,424 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Transaction_Payments
16 16
 {
17
-    /**
18
-     * @var EE_Transaction_Payments $_instance
19
-     * @access    private
20
-     */
21
-    private static $_instance;
22
-
23
-    /**
24
-     * @deprecated
25
-     * @var string
26
-     */
27
-    protected $_old_txn_status;
28
-
29
-    /**
30
-     * @deprecated
31
-     * @var string
32
-     */
33
-    protected $_new_txn_status;
34
-
35
-
36
-    /**
37
-     * @singleton method used to instantiate class object
38
-     * @access    public
39
-     * @return EE_Transaction_Payments instance
40
-     */
41
-    public static function instance()
42
-    {
43
-        // check if class object is instantiated
44
-        if (! self::$_instance instanceof EE_Transaction_Payments) {
45
-            self::$_instance = new self();
46
-        }
47
-        return self::$_instance;
48
-    }
49
-
50
-
51
-    /**
52
-     * recalculate_transaction_total
53
-     *
54
-     * @access private
55
-     * @param EE_Transaction $transaction
56
-     * @param bool           $update_txn
57
-     * @return bool true if TXN total was updated, false if not
58
-     * @throws \EE_Error
59
-     */
60
-    public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true)
61
-    {
62
-        $total_line_item = $transaction->total_line_item();
63
-        if (! $total_line_item instanceof EE_Line_Item) {
64
-            EE_Error::add_error(
65
-                sprintf(
66
-                    esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'),
67
-                    $transaction->ID()
68
-                ),
69
-                __FILE__,
70
-                __FUNCTION__,
71
-                __LINE__
72
-            );
73
-            return false;
74
-        }
75
-        $new_total = $total_line_item->recalculate_total_including_taxes();
76
-        $transaction->set_total($new_total);
77
-        if ($update_txn) {
78
-            return $transaction->save() ? true : false;
79
-        }
80
-        return false;
81
-    }
82
-
83
-
84
-    /**
85
-     * Updates the provided EE_Transaction with all the applicable payments
86
-     * returns a boolean for whether the TXN was saved to the db
87
-     * (meaning a status change occurred)
88
-     * or not saved (which could **still** mean that
89
-     * the TXN status changed, but just was not yet saved).
90
-     * So if passing a value of false for the $update_txn param,
91
-     * then client code needs to take responsibility for saving the TXN
92
-     * regardless of what happens within EE_Transaction_Payments;
93
-     *
94
-     * @param            EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID
95
-     * @param    boolean $update_txn whether to save the TXN
96
-     * @return    boolean        whether the TXN was saved
97
-     * @throws \EE_Error
98
-     */
99
-    public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true)
100
-    {
101
-        // verify transaction
102
-        if (! $transaction instanceof EE_Transaction) {
103
-            EE_Error::add_error(
104
-                esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
105
-                __FILE__,
106
-                __FUNCTION__,
107
-                __LINE__
108
-            );
109
-            return false;
110
-        }
111
-        // calculate total paid
112
-        $total_paid = $this->recalculate_total_payments_for_transaction($transaction);
113
-        // if total paid has changed
114
-        if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
115
-            $transaction->set_paid($total_paid);
116
-            // maybe update status, and make sure to save transaction if not done already
117
-            if (! $transaction->update_status_based_on_total_paid($update_txn)) {
118
-                if ($update_txn) {
119
-                    return $transaction->save() ? true : false;
120
-                }
121
-            } else {
122
-                // the status got updated and was saved by
123
-                // update_transaction_status_based_on_total_paid()
124
-                return true;
125
-            }
126
-        }
127
-        return false;
128
-    }
129
-
130
-
131
-    /**
132
-     * recalculate_total_payments_for_transaction
133
-     *
134
-     * @access public
135
-     * @param EE_Transaction $transaction
136
-     * @param string         $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved).
137
-     *                                       By default, searches for approved payments
138
-     * @return float|false   float on success, false on fail
139
-     * @throws \EE_Error
140
-     */
141
-    public function recalculate_total_payments_for_transaction(
142
-        EE_Transaction $transaction,
143
-        $payment_status = EEM_Payment::status_id_approved
144
-    ) {
145
-        // verify transaction
146
-        if (! $transaction instanceof EE_Transaction) {
147
-            EE_Error::add_error(
148
-                esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
149
-                __FILE__,
150
-                __FUNCTION__,
151
-                __LINE__
152
-            );
153
-            return false;
154
-        }
155
-        // ensure Payment model is loaded
156
-        EE_Registry::instance()->load_model('Payment');
157
-        // calls EEM_Base::sum()
158
-        return EEM_Payment::instance()->sum(
159
-            // query params
160
-            array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)),
161
-            // field to sum
162
-            'PAY_amount'
163
-        );
164
-    }
165
-
166
-
167
-    /**
168
-     * delete_payment_and_update_transaction
169
-     * Before deleting the selected payment, we fetch it's transaction,
170
-     * then delete the payment, and update the transactions' amount paid.
171
-     *
172
-     * @param EE_Payment $payment
173
-     * @return boolean
174
-     * @throws \EE_Error
175
-     */
176
-    public function delete_payment_and_update_transaction(EE_Payment $payment)
177
-    {
178
-        // verify payment
179
-        if (! $payment instanceof EE_Payment) {
180
-            EE_Error::add_error(
181
-                esc_html__('A valid Payment object was not received.', 'event_espresso'),
182
-                __FILE__,
183
-                __FUNCTION__,
184
-                __LINE__
185
-            );
186
-            return false;
187
-        }
188
-        if (! $this->delete_registration_payments_and_update_registrations($payment)) {
189
-            return false;
190
-        }
191
-        if (! $payment->delete()) {
192
-            EE_Error::add_error(
193
-                esc_html__('The payment could not be deleted.', 'event_espresso'),
194
-                __FILE__,
195
-                __FUNCTION__,
196
-                __LINE__
197
-            );
198
-            return false;
199
-        }
200
-
201
-        $transaction = $payment->transaction();
202
-        $TXN_status = $transaction->status_ID();
203
-        if (
204
-            $TXN_status === EEM_Transaction::abandoned_status_code
205
-            || $TXN_status === EEM_Transaction::failed_status_code
206
-            || $payment->amount() === 0
207
-        ) {
208
-            EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso'));
209
-            return true;
210
-        }
211
-
212
-
213
-        // if this fails, that just means that the transaction didn't get its status changed and/or updated.
214
-        // however the payment was still deleted.
215
-        if (! $this->calculate_total_payments_and_update_status($transaction)) {
216
-            EE_Error::add_attention(
217
-                esc_html__(
218
-                    'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..',
219
-                    'event_espresso'
220
-                ),
221
-                __FILE__,
222
-                __FUNCTION__,
223
-                __LINE__
224
-            );
225
-            return true;
226
-        }
227
-
228
-        EE_Error::add_success(
229
-            esc_html__(
230
-                'The Payment was successfully deleted, and the Transaction has been updated accordingly.',
231
-                'event_espresso'
232
-            )
233
-        );
234
-        return true;
235
-    }
236
-
237
-
238
-    /**
239
-     * delete_registration_payments_and_update_registrations
240
-     *
241
-     * removes all registration payment records associated with a payment
242
-     * and subtracts their amounts from the corresponding registrations REG_paid field
243
-     *
244
-     * @param EE_Payment $payment
245
-     * @param array      $reg_payment_query_params
246
-     * @return bool
247
-     * @throws \EE_Error
248
-     */
249
-    public function delete_registration_payments_and_update_registrations(
250
-        EE_Payment $payment,
251
-        $reg_payment_query_params = array()
252
-    ) {
253
-        $save_payment = false;
254
-        $reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params
255
-            : array(array('PAY_ID' => $payment->ID()));
256
-        $registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
257
-        if (! empty($registration_payments)) {
258
-            foreach ($registration_payments as $registration_payment) {
259
-                if ($registration_payment instanceof EE_Registration_Payment) {
260
-                    $amount_paid = $registration_payment->amount();
261
-                    $registration = $registration_payment->registration();
262
-                    if ($registration instanceof EE_Registration) {
263
-                        $registration->set_paid($registration->paid() - $amount_paid);
264
-                        if ($registration->save() !== false) {
265
-                            $registration_payment->delete_permanently();
266
-                            $save_payment = true;
267
-                        }
268
-                    } else {
269
-                        EE_Error::add_error(
270
-                            sprintf(
271
-                                esc_html__(
272
-                                    'An invalid Registration object was associated with Registration Payment ID# %1$d.',
273
-                                    'event_espresso'
274
-                                ),
275
-                                $registration_payment->ID()
276
-                            ),
277
-                            __FILE__,
278
-                            __FUNCTION__,
279
-                            __LINE__
280
-                        );
281
-                        return false;
282
-                    }
283
-                } else {
284
-                    EE_Error::add_error(
285
-                        sprintf(
286
-                            esc_html__(
287
-                                'An invalid Registration Payment object was associated with payment ID# %1$d.',
288
-                                'event_espresso'
289
-                            ),
290
-                            $payment->ID()
291
-                        ),
292
-                        __FILE__,
293
-                        __FUNCTION__,
294
-                        __LINE__
295
-                    );
296
-                    return false;
297
-                }
298
-            }
299
-        }
300
-        if ($save_payment) {
301
-            $payment->save();
302
-        }
303
-        return true;
304
-    }
305
-
306
-
307
-
308
-    /********************************** DEPRECATED METHODS **********************************/
309
-
310
-
311
-    /**
312
-     * possibly toggles TXN status
313
-     *
314
-     * @deprecated 4.9.1
315
-     * @param EE_Transaction $transaction
316
-     * @param    boolean     $update_txn whether to save the TXN
317
-     * @return    boolean        whether the TXN was saved
318
-     * @throws \EE_Error
319
-     */
320
-    public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
321
-    {
322
-        EE_Error::doing_it_wrong(
323
-            __CLASS__ . '::' . __FUNCTION__,
324
-            sprintf(
325
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
326
-                'EE_Transaction::update_status_based_on_total_paid()'
327
-            ),
328
-            '4.9.1',
329
-            '5.0.0'
330
-        );
331
-        // verify transaction
332
-        if (! $transaction instanceof EE_Transaction) {
333
-            EE_Error::add_error(
334
-                esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
335
-                __FILE__,
336
-                __FUNCTION__,
337
-                __LINE__
338
-            );
339
-            return false;
340
-        }
341
-        // set transaction status based on comparison of TXN_paid vs TXN_total
342
-        return $transaction->update_status_based_on_total_paid($update_txn);
343
-    }
344
-
345
-
346
-    /**
347
-     * @deprecated 4.9.12
348
-     * @return string
349
-     */
350
-    public function old_txn_status()
351
-    {
352
-        EE_Error::doing_it_wrong(
353
-            __METHOD__,
354
-            esc_html__(
355
-                'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
356
-                'event_espresso'
357
-            ),
358
-            '4.9.12'
359
-        );
360
-        return $this->_old_txn_status;
361
-    }
362
-
363
-
364
-    /**
365
-     * @deprecated 4.9.12
366
-     * @param string $old_txn_status
367
-     */
368
-    public function set_old_txn_status($old_txn_status)
369
-    {
370
-        EE_Error::doing_it_wrong(
371
-            __METHOD__,
372
-            esc_html__(
373
-                'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
374
-                'event_espresso'
375
-            ),
376
-            '4.9.12'
377
-        );
378
-        // only set the first time
379
-        if ($this->_old_txn_status === null) {
380
-            $this->_old_txn_status = $old_txn_status;
381
-        }
382
-    }
383
-
384
-
385
-    /**
386
-     * @deprecated 4.9.12
387
-     * @return string
388
-     */
389
-    public function new_txn_status()
390
-    {
391
-        EE_Error::doing_it_wrong(
392
-            __METHOD__,
393
-            esc_html__(
394
-                'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
395
-                'event_espresso'
396
-            ),
397
-            '4.9.12'
398
-        );
399
-        return $this->_new_txn_status;
400
-    }
401
-
402
-
403
-    /**
404
-     * @deprecated 4.9.12
405
-     * @param string $new_txn_status
406
-     */
407
-    public function set_new_txn_status($new_txn_status)
408
-    {
409
-        EE_Error::doing_it_wrong(
410
-            __METHOD__,
411
-            esc_html__(
412
-                'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
413
-                'event_espresso'
414
-            ),
415
-            '4.9.12'
416
-        );
417
-        $this->_new_txn_status = $new_txn_status;
418
-    }
419
-
420
-
421
-    /**
422
-     * @deprecated 4.9.12
423
-     * @return bool
424
-     */
425
-    public function txn_status_updated()
426
-    {
427
-        EE_Error::doing_it_wrong(
428
-            __METHOD__,
429
-            esc_html__(
430
-                'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
431
-                'event_espresso'
432
-            ),
433
-            '4.9.12'
434
-        );
435
-        return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
436
-    }
17
+	/**
18
+	 * @var EE_Transaction_Payments $_instance
19
+	 * @access    private
20
+	 */
21
+	private static $_instance;
22
+
23
+	/**
24
+	 * @deprecated
25
+	 * @var string
26
+	 */
27
+	protected $_old_txn_status;
28
+
29
+	/**
30
+	 * @deprecated
31
+	 * @var string
32
+	 */
33
+	protected $_new_txn_status;
34
+
35
+
36
+	/**
37
+	 * @singleton method used to instantiate class object
38
+	 * @access    public
39
+	 * @return EE_Transaction_Payments instance
40
+	 */
41
+	public static function instance()
42
+	{
43
+		// check if class object is instantiated
44
+		if (! self::$_instance instanceof EE_Transaction_Payments) {
45
+			self::$_instance = new self();
46
+		}
47
+		return self::$_instance;
48
+	}
49
+
50
+
51
+	/**
52
+	 * recalculate_transaction_total
53
+	 *
54
+	 * @access private
55
+	 * @param EE_Transaction $transaction
56
+	 * @param bool           $update_txn
57
+	 * @return bool true if TXN total was updated, false if not
58
+	 * @throws \EE_Error
59
+	 */
60
+	public function recalculate_transaction_total(EE_Transaction $transaction, $update_txn = true)
61
+	{
62
+		$total_line_item = $transaction->total_line_item();
63
+		if (! $total_line_item instanceof EE_Line_Item) {
64
+			EE_Error::add_error(
65
+				sprintf(
66
+					esc_html__('The Total Line Item for Transaction %1$d\'s was not found or is invalid.', 'event_espresso'),
67
+					$transaction->ID()
68
+				),
69
+				__FILE__,
70
+				__FUNCTION__,
71
+				__LINE__
72
+			);
73
+			return false;
74
+		}
75
+		$new_total = $total_line_item->recalculate_total_including_taxes();
76
+		$transaction->set_total($new_total);
77
+		if ($update_txn) {
78
+			return $transaction->save() ? true : false;
79
+		}
80
+		return false;
81
+	}
82
+
83
+
84
+	/**
85
+	 * Updates the provided EE_Transaction with all the applicable payments
86
+	 * returns a boolean for whether the TXN was saved to the db
87
+	 * (meaning a status change occurred)
88
+	 * or not saved (which could **still** mean that
89
+	 * the TXN status changed, but just was not yet saved).
90
+	 * So if passing a value of false for the $update_txn param,
91
+	 * then client code needs to take responsibility for saving the TXN
92
+	 * regardless of what happens within EE_Transaction_Payments;
93
+	 *
94
+	 * @param            EE_Transaction /int $transaction_obj_or_id EE_Transaction or its ID
95
+	 * @param    boolean $update_txn whether to save the TXN
96
+	 * @return    boolean        whether the TXN was saved
97
+	 * @throws \EE_Error
98
+	 */
99
+	public function calculate_total_payments_and_update_status(EE_Transaction $transaction, $update_txn = true)
100
+	{
101
+		// verify transaction
102
+		if (! $transaction instanceof EE_Transaction) {
103
+			EE_Error::add_error(
104
+				esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
105
+				__FILE__,
106
+				__FUNCTION__,
107
+				__LINE__
108
+			);
109
+			return false;
110
+		}
111
+		// calculate total paid
112
+		$total_paid = $this->recalculate_total_payments_for_transaction($transaction);
113
+		// if total paid has changed
114
+		if ($total_paid !== false && (float) $total_paid !== $transaction->paid()) {
115
+			$transaction->set_paid($total_paid);
116
+			// maybe update status, and make sure to save transaction if not done already
117
+			if (! $transaction->update_status_based_on_total_paid($update_txn)) {
118
+				if ($update_txn) {
119
+					return $transaction->save() ? true : false;
120
+				}
121
+			} else {
122
+				// the status got updated and was saved by
123
+				// update_transaction_status_based_on_total_paid()
124
+				return true;
125
+			}
126
+		}
127
+		return false;
128
+	}
129
+
130
+
131
+	/**
132
+	 * recalculate_total_payments_for_transaction
133
+	 *
134
+	 * @access public
135
+	 * @param EE_Transaction $transaction
136
+	 * @param string         $payment_status One of EEM_Payment's statuses, like 'PAP' (Approved).
137
+	 *                                       By default, searches for approved payments
138
+	 * @return float|false   float on success, false on fail
139
+	 * @throws \EE_Error
140
+	 */
141
+	public function recalculate_total_payments_for_transaction(
142
+		EE_Transaction $transaction,
143
+		$payment_status = EEM_Payment::status_id_approved
144
+	) {
145
+		// verify transaction
146
+		if (! $transaction instanceof EE_Transaction) {
147
+			EE_Error::add_error(
148
+				esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
149
+				__FILE__,
150
+				__FUNCTION__,
151
+				__LINE__
152
+			);
153
+			return false;
154
+		}
155
+		// ensure Payment model is loaded
156
+		EE_Registry::instance()->load_model('Payment');
157
+		// calls EEM_Base::sum()
158
+		return EEM_Payment::instance()->sum(
159
+			// query params
160
+			array(array('TXN_ID' => $transaction->ID(), 'STS_ID' => $payment_status)),
161
+			// field to sum
162
+			'PAY_amount'
163
+		);
164
+	}
165
+
166
+
167
+	/**
168
+	 * delete_payment_and_update_transaction
169
+	 * Before deleting the selected payment, we fetch it's transaction,
170
+	 * then delete the payment, and update the transactions' amount paid.
171
+	 *
172
+	 * @param EE_Payment $payment
173
+	 * @return boolean
174
+	 * @throws \EE_Error
175
+	 */
176
+	public function delete_payment_and_update_transaction(EE_Payment $payment)
177
+	{
178
+		// verify payment
179
+		if (! $payment instanceof EE_Payment) {
180
+			EE_Error::add_error(
181
+				esc_html__('A valid Payment object was not received.', 'event_espresso'),
182
+				__FILE__,
183
+				__FUNCTION__,
184
+				__LINE__
185
+			);
186
+			return false;
187
+		}
188
+		if (! $this->delete_registration_payments_and_update_registrations($payment)) {
189
+			return false;
190
+		}
191
+		if (! $payment->delete()) {
192
+			EE_Error::add_error(
193
+				esc_html__('The payment could not be deleted.', 'event_espresso'),
194
+				__FILE__,
195
+				__FUNCTION__,
196
+				__LINE__
197
+			);
198
+			return false;
199
+		}
200
+
201
+		$transaction = $payment->transaction();
202
+		$TXN_status = $transaction->status_ID();
203
+		if (
204
+			$TXN_status === EEM_Transaction::abandoned_status_code
205
+			|| $TXN_status === EEM_Transaction::failed_status_code
206
+			|| $payment->amount() === 0
207
+		) {
208
+			EE_Error::add_success(esc_html__('The Payment was successfully deleted.', 'event_espresso'));
209
+			return true;
210
+		}
211
+
212
+
213
+		// if this fails, that just means that the transaction didn't get its status changed and/or updated.
214
+		// however the payment was still deleted.
215
+		if (! $this->calculate_total_payments_and_update_status($transaction)) {
216
+			EE_Error::add_attention(
217
+				esc_html__(
218
+					'It appears that the Payment was deleted but no change was recorded for the Transaction for an unknown reason. Please verify that all data for this Transaction looks correct..',
219
+					'event_espresso'
220
+				),
221
+				__FILE__,
222
+				__FUNCTION__,
223
+				__LINE__
224
+			);
225
+			return true;
226
+		}
227
+
228
+		EE_Error::add_success(
229
+			esc_html__(
230
+				'The Payment was successfully deleted, and the Transaction has been updated accordingly.',
231
+				'event_espresso'
232
+			)
233
+		);
234
+		return true;
235
+	}
236
+
237
+
238
+	/**
239
+	 * delete_registration_payments_and_update_registrations
240
+	 *
241
+	 * removes all registration payment records associated with a payment
242
+	 * and subtracts their amounts from the corresponding registrations REG_paid field
243
+	 *
244
+	 * @param EE_Payment $payment
245
+	 * @param array      $reg_payment_query_params
246
+	 * @return bool
247
+	 * @throws \EE_Error
248
+	 */
249
+	public function delete_registration_payments_and_update_registrations(
250
+		EE_Payment $payment,
251
+		$reg_payment_query_params = array()
252
+	) {
253
+		$save_payment = false;
254
+		$reg_payment_query_params = ! empty($reg_payment_query_params) ? $reg_payment_query_params
255
+			: array(array('PAY_ID' => $payment->ID()));
256
+		$registration_payments = EEM_Registration_Payment::instance()->get_all($reg_payment_query_params);
257
+		if (! empty($registration_payments)) {
258
+			foreach ($registration_payments as $registration_payment) {
259
+				if ($registration_payment instanceof EE_Registration_Payment) {
260
+					$amount_paid = $registration_payment->amount();
261
+					$registration = $registration_payment->registration();
262
+					if ($registration instanceof EE_Registration) {
263
+						$registration->set_paid($registration->paid() - $amount_paid);
264
+						if ($registration->save() !== false) {
265
+							$registration_payment->delete_permanently();
266
+							$save_payment = true;
267
+						}
268
+					} else {
269
+						EE_Error::add_error(
270
+							sprintf(
271
+								esc_html__(
272
+									'An invalid Registration object was associated with Registration Payment ID# %1$d.',
273
+									'event_espresso'
274
+								),
275
+								$registration_payment->ID()
276
+							),
277
+							__FILE__,
278
+							__FUNCTION__,
279
+							__LINE__
280
+						);
281
+						return false;
282
+					}
283
+				} else {
284
+					EE_Error::add_error(
285
+						sprintf(
286
+							esc_html__(
287
+								'An invalid Registration Payment object was associated with payment ID# %1$d.',
288
+								'event_espresso'
289
+							),
290
+							$payment->ID()
291
+						),
292
+						__FILE__,
293
+						__FUNCTION__,
294
+						__LINE__
295
+					);
296
+					return false;
297
+				}
298
+			}
299
+		}
300
+		if ($save_payment) {
301
+			$payment->save();
302
+		}
303
+		return true;
304
+	}
305
+
306
+
307
+
308
+	/********************************** DEPRECATED METHODS **********************************/
309
+
310
+
311
+	/**
312
+	 * possibly toggles TXN status
313
+	 *
314
+	 * @deprecated 4.9.1
315
+	 * @param EE_Transaction $transaction
316
+	 * @param    boolean     $update_txn whether to save the TXN
317
+	 * @return    boolean        whether the TXN was saved
318
+	 * @throws \EE_Error
319
+	 */
320
+	public function update_transaction_status_based_on_total_paid(EE_Transaction $transaction, $update_txn = true)
321
+	{
322
+		EE_Error::doing_it_wrong(
323
+			__CLASS__ . '::' . __FUNCTION__,
324
+			sprintf(
325
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
326
+				'EE_Transaction::update_status_based_on_total_paid()'
327
+			),
328
+			'4.9.1',
329
+			'5.0.0'
330
+		);
331
+		// verify transaction
332
+		if (! $transaction instanceof EE_Transaction) {
333
+			EE_Error::add_error(
334
+				esc_html__('Please provide a valid EE_Transaction object.', 'event_espresso'),
335
+				__FILE__,
336
+				__FUNCTION__,
337
+				__LINE__
338
+			);
339
+			return false;
340
+		}
341
+		// set transaction status based on comparison of TXN_paid vs TXN_total
342
+		return $transaction->update_status_based_on_total_paid($update_txn);
343
+	}
344
+
345
+
346
+	/**
347
+	 * @deprecated 4.9.12
348
+	 * @return string
349
+	 */
350
+	public function old_txn_status()
351
+	{
352
+		EE_Error::doing_it_wrong(
353
+			__METHOD__,
354
+			esc_html__(
355
+				'This logic has been moved into \EE_Transaction::old_txn_status(), please use that method instead.',
356
+				'event_espresso'
357
+			),
358
+			'4.9.12'
359
+		);
360
+		return $this->_old_txn_status;
361
+	}
362
+
363
+
364
+	/**
365
+	 * @deprecated 4.9.12
366
+	 * @param string $old_txn_status
367
+	 */
368
+	public function set_old_txn_status($old_txn_status)
369
+	{
370
+		EE_Error::doing_it_wrong(
371
+			__METHOD__,
372
+			esc_html__(
373
+				'This logic has been moved into \EE_Transaction::set_old_txn_status(), please use that method instead.',
374
+				'event_espresso'
375
+			),
376
+			'4.9.12'
377
+		);
378
+		// only set the first time
379
+		if ($this->_old_txn_status === null) {
380
+			$this->_old_txn_status = $old_txn_status;
381
+		}
382
+	}
383
+
384
+
385
+	/**
386
+	 * @deprecated 4.9.12
387
+	 * @return string
388
+	 */
389
+	public function new_txn_status()
390
+	{
391
+		EE_Error::doing_it_wrong(
392
+			__METHOD__,
393
+			esc_html__(
394
+				'This logic has been removed. Please just use \EE_Transaction::status_ID() instead.',
395
+				'event_espresso'
396
+			),
397
+			'4.9.12'
398
+		);
399
+		return $this->_new_txn_status;
400
+	}
401
+
402
+
403
+	/**
404
+	 * @deprecated 4.9.12
405
+	 * @param string $new_txn_status
406
+	 */
407
+	public function set_new_txn_status($new_txn_status)
408
+	{
409
+		EE_Error::doing_it_wrong(
410
+			__METHOD__,
411
+			esc_html__(
412
+				'This logic has been removed. Please just use \EE_Transaction::set_status() instead.',
413
+				'event_espresso'
414
+			),
415
+			'4.9.12'
416
+		);
417
+		$this->_new_txn_status = $new_txn_status;
418
+	}
419
+
420
+
421
+	/**
422
+	 * @deprecated 4.9.12
423
+	 * @return bool
424
+	 */
425
+	public function txn_status_updated()
426
+	{
427
+		EE_Error::doing_it_wrong(
428
+			__METHOD__,
429
+			esc_html__(
430
+				'This logic has been moved into \EE_Transaction::txn_status_updated(), please use that method instead.',
431
+				'event_espresso'
432
+			),
433
+			'4.9.12'
434
+		);
435
+		return $this->_new_txn_status !== $this->_old_txn_status && $this->_old_txn_status !== null ? true : false;
436
+	}
437 437
 }
Please login to merge, or discard this patch.
services/admin/registrations/list_table/page_header/TicketFilterHeader.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
         if ($TKT_ID) {
60 60
             $ticket = $this->ticket_model->get_one_by_ID($TKT_ID);
61 61
             if ($ticket instanceof EE_Ticket) {
62
-                $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> ';
62
+                $ticket_details = '<span class="ee-ticket-name">'.$ticket->name().'</span> ';
63 63
                 $ticket_details .= ! $ticket->is_free()
64
-                    ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>'
64
+                    ? '<span class="ee-ticket-price">'.$ticket->pretty_price().'</span>'
65 65
                     : '<span class="reg-overview-free-event-spn">'
66 66
                       . esc_html__('free', 'event_espresso')
67 67
                       . '</span>';
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
                 $text .= '&nbsp; &nbsp; ';
79 79
                 $text .= '<span class="drk-grey-text" style="font-size:.9em;">';
80 80
                 $text .= '<span class="dashicons dashicons-tickets-alt"></span>';
81
-                $text .= $ticket_details . '</span></h3>';
81
+                $text .= $ticket_details.'</span></h3>';
82 82
             }
83 83
         }
84 84
         return $text;
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -22,64 +22,64 @@
 block discarded – undo
22 22
  */
23 23
 class TicketFilterHeader extends AdminPageHeaderDecorator
24 24
 {
25
-    /**
26
-     * @var EEM_Ticket $ticket_model
27
-     */
28
-    private $ticket_model;
25
+	/**
26
+	 * @var EEM_Ticket $ticket_model
27
+	 */
28
+	private $ticket_model;
29 29
 
30 30
 
31
-    /**
32
-     * TicketFilterHeader constructor.
33
-     *
34
-     * @param RequestInterface $request
35
-     * @param EEM_Ticket       $ticket_model
36
-     */
37
-    public function __construct(RequestInterface $request, EEM_Ticket $ticket_model)
38
-    {
39
-        parent::__construct($request);
40
-        $this->ticket_model = $ticket_model;
41
-    }
31
+	/**
32
+	 * TicketFilterHeader constructor.
33
+	 *
34
+	 * @param RequestInterface $request
35
+	 * @param EEM_Ticket       $ticket_model
36
+	 */
37
+	public function __construct(RequestInterface $request, EEM_Ticket $ticket_model)
38
+	{
39
+		parent::__construct($request);
40
+		$this->ticket_model = $ticket_model;
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * @param string $text
46
-     * @return string
47
-     * @throws EE_Error
48
-     * @throws InvalidDataTypeException
49
-     * @throws InvalidInterfaceException
50
-     * @throws InvalidArgumentException
51
-     * @throws ReflectionException
52
-     * @since 4.10.2.p
53
-     */
54
-    public function getHeaderText($text = '')
55
-    {
56
-        $TKT_ID = $this->request->getRequestParam('TKT_ID');
57
-        $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int');
58
-        if ($TKT_ID) {
59
-            $ticket = $this->ticket_model->get_one_by_ID($TKT_ID);
60
-            if ($ticket instanceof EE_Ticket) {
61
-                $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> ';
62
-                $ticket_details .= ! $ticket->is_free()
63
-                    ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>'
64
-                    : '<span class="reg-overview-free-event-spn">'
65
-                      . esc_html__('free', 'event_espresso')
66
-                      . '</span>';
67
-                // remove the closing h3 heading tag if it exists
68
-                $text = str_replace(
69
-                    '</h3>',
70
-                    '',
71
-                    $text
72
-                );
73
-                if (empty($text)) {
74
-                    $text = '<h3 style="line-height:1.5em;">';
75
-                    $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso');
76
-                }
77
-                $text .= '&nbsp; &nbsp; ';
78
-                $text .= '<span class="drk-grey-text" style="font-size:.9em;">';
79
-                $text .= '<span class="dashicons dashicons-tickets-alt"></span>';
80
-                $text .= $ticket_details . '</span></h3>';
81
-            }
82
-        }
83
-        return $text;
84
-    }
44
+	/**
45
+	 * @param string $text
46
+	 * @return string
47
+	 * @throws EE_Error
48
+	 * @throws InvalidDataTypeException
49
+	 * @throws InvalidInterfaceException
50
+	 * @throws InvalidArgumentException
51
+	 * @throws ReflectionException
52
+	 * @since 4.10.2.p
53
+	 */
54
+	public function getHeaderText($text = '')
55
+	{
56
+		$TKT_ID = $this->request->getRequestParam('TKT_ID');
57
+		$TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID, 'int');
58
+		if ($TKT_ID) {
59
+			$ticket = $this->ticket_model->get_one_by_ID($TKT_ID);
60
+			if ($ticket instanceof EE_Ticket) {
61
+				$ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> ';
62
+				$ticket_details .= ! $ticket->is_free()
63
+					? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>'
64
+					: '<span class="reg-overview-free-event-spn">'
65
+					  . esc_html__('free', 'event_espresso')
66
+					  . '</span>';
67
+				// remove the closing h3 heading tag if it exists
68
+				$text = str_replace(
69
+					'</h3>',
70
+					'',
71
+					$text
72
+				);
73
+				if (empty($text)) {
74
+					$text = '<h3 style="line-height:1.5em;">';
75
+					$text .= esc_html__('Viewing registrations for ticket:', 'event_espresso');
76
+				}
77
+				$text .= '&nbsp; &nbsp; ';
78
+				$text .= '<span class="drk-grey-text" style="font-size:.9em;">';
79
+				$text .= '<span class="dashicons dashicons-tickets-alt"></span>';
80
+				$text .= $ticket_details . '</span></h3>';
81
+			}
82
+		}
83
+		return $text;
84
+	}
85 85
 }
Please login to merge, or discard this patch.
core/domain/services/admin/ajax/ThankYouPageIpnMonitor.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -67,12 +67,12 @@  discard block
 block discarded – undo
67 67
     public function heartbeatResponse($response = array(), $data = array())
68 68
     {
69 69
         // does this heartbeat contain our data ?
70
-        if (! isset($data[ $this->heartbeat ])) {
70
+        if ( ! isset($data[$this->heartbeat])) {
71 71
             return $response;
72 72
         }
73 73
         // check for reg_url_link in the incoming heartbeat data
74
-        if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) {
75
-            $response[ $this->heartbeat ] = array(
74
+        if ( ! isset($data[$this->heartbeat]['e_reg_url_link'])) {
75
+            $response[$this->heartbeat] = array(
76 76
                 'errors' => ! empty($notices['errors'])
77 77
                     ? $notices['errors']
78 78
                     : esc_html__(
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
         // kk heartbeat has our data
86 86
         $response = $this->initializeThankYouPageAndTransaction($response, $data);
87 87
         // if something went wrong...
88
-        if (isset($response[ $this->heartbeat ]['errors'])) {
88
+        if (isset($response[$this->heartbeat]['errors'])) {
89 89
             return $response;
90 90
         }
91 91
         // grab transient of Transaction's status
92
-        $txn_status = isset($data[ $this->heartbeat ]['txn_status'])
93
-            ? $data[ $this->heartbeat ]['txn_status']
92
+        $txn_status = isset($data[$this->heartbeat]['txn_status'])
93
+            ? $data[$this->heartbeat]['txn_status']
94 94
             : null;
95 95
         $response = $this->getTransactionDetails($txn_status, $response, $data);
96 96
         // no payment data yet?
97
-        if (isset($response[ $this->heartbeat ]['still_waiting'])) {
97
+        if (isset($response[$this->heartbeat]['still_waiting'])) {
98 98
             return $response;
99 99
         }
100 100
         // TXN is happening so let's get the payments now
101 101
         // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
102
-        $since = isset($data[ $this->heartbeat ]['get_payments_since'])
103
-            ? $data[ $this->heartbeat ]['get_payments_since']
102
+        $since = isset($data[$this->heartbeat]['get_payments_since'])
103
+            ? $data[$this->heartbeat]['get_payments_since']
104 104
             : 0;
105 105
         return $this->paymentDetails($response, $since);
106 106
     }
@@ -117,18 +117,18 @@  discard block
 block discarded – undo
117 117
      */
118 118
     private function initializeThankYouPageAndTransaction($response, $data)
119 119
     {
120
-        require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
120
+        require_once EE_MODULES.'thank_you_page/EED_Thank_You_Page.module.php';
121 121
         // set_definitions, instantiate the thank you page class, and get the ball rolling
122 122
         EED_Thank_You_Page::set_definitions();
123 123
         $this->thank_you_page = EED_Thank_You_Page::instance();
124
-        $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']);
124
+        $this->thank_you_page->set_reg_url_link($data[$this->heartbeat]['e_reg_url_link']);
125 125
         $this->thank_you_page->init();
126 126
         // get TXN
127 127
         $transaction = $this->thank_you_page->get_txn();
128 128
         // no TXN? then get out
129
-        if (! $transaction instanceof EE_Transaction) {
129
+        if ( ! $transaction instanceof EE_Transaction) {
130 130
             $notices = EE_Error::get_notices();
131
-            $response[ $this->heartbeat ] = array(
131
+            $response[$this->heartbeat] = array(
132 132
                 'errors' => ! empty($notices['errors'])
133 133
                     ? $notices['errors']
134 134
                     : sprintf(
@@ -173,12 +173,12 @@  discard block
 block discarded – undo
173 173
                 case EEM_Transaction::failed_status_code:
174 174
                 default:
175 175
                     // keep on waiting...
176
-                    return $this->updateServerWaitTime($data[ $this->heartbeat ]);
176
+                    return $this->updateServerWaitTime($data[$this->heartbeat]);
177 177
             }
178 178
             // or is the TXN still failed (never been updated) ???
179 179
         } elseif ($this->transaction->failed()) {
180 180
             // keep on waiting...
181
-            return $this->updateServerWaitTime($data[ $this->heartbeat ]);
181
+            return $this->updateServerWaitTime($data[$this->heartbeat]);
182 182
         }
183 183
         return $response;
184 184
     }
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
      */
197 197
     private function setTransactionDetails($response, $status_only = false)
198 198
     {
199
-        if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) {
200
-            $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details();
199
+        if ( ! $status_only && ! isset($response[$this->heartbeat]['transaction_details'])) {
200
+            $response[$this->heartbeat]['transaction_details'] = $this->thank_you_page->get_transaction_details();
201 201
         }
202
-        if (! isset($response[ $this->heartbeat ]['txn_status'])) {
203
-            $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID();
202
+        if ( ! isset($response[$this->heartbeat]['txn_status'])) {
203
+            $response[$this->heartbeat]['txn_status'] = $this->transaction->status_ID();
204 204
         }
205 205
         return $response;
206 206
     }
@@ -221,19 +221,19 @@  discard block
 block discarded – undo
221 221
         // then check for payments
222 222
         $payments = $this->thank_you_page->get_txn_payments($since);
223 223
         // has a payment been processed ?
224
-        if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
224
+        if ( ! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
225 225
             if ($since) {
226
-                $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments);
226
+                $response[$this->heartbeat]['new_payments'] = $this->thank_you_page->get_new_payments($payments);
227 227
                 $response = $this->setTransactionDetails($response);
228 228
             } else {
229
-                $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details(
229
+                $response[$this->heartbeat]['payment_details'] = $this->thank_you_page->get_payment_details(
230 230
                     $payments
231 231
                 );
232 232
             }
233 233
             // reset time to check for payments
234
-            $response[ $this->heartbeat ]['get_payments_since'] = time();
234
+            $response[$this->heartbeat]['get_payments_since'] = time();
235 235
         } else {
236
-            $response[ $this->heartbeat ]['get_payments_since'] = $since;
236
+            $response[$this->heartbeat]['get_payments_since'] = $since;
237 237
         }
238 238
         return $response;
239 239
     }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
      */
252 252
     private function updateServerWaitTime($thank_you_page_data)
253 253
     {
254
-        $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access'])
254
+        $response[$this->heartbeat]['still_waiting'] = isset($thank_you_page_data['initial_access'])
255 255
             ? time() - $thank_you_page_data['initial_access']
256 256
             : 0;
257 257
         $response = $this->setTransactionDetails($response, true);
Please login to merge, or discard this patch.
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -21,239 +21,239 @@
 block discarded – undo
21 21
  */
22 22
 class ThankYouPageIpnMonitor
23 23
 {
24
-    /**
25
-     * @var string $heartbeat
26
-     */
27
-    private $heartbeat;
24
+	/**
25
+	 * @var string $heartbeat
26
+	 */
27
+	private $heartbeat;
28 28
 
29
-    /**
30
-     * @var EED_Thank_You_Page $thank_you_page
31
-     */
32
-    private $thank_you_page;
29
+	/**
30
+	 * @var EED_Thank_You_Page $thank_you_page
31
+	 */
32
+	private $thank_you_page;
33 33
 
34
-    /**
35
-     * @var EE_Transaction $transaction
36
-     */
37
-    private $transaction;
34
+	/**
35
+	 * @var EE_Transaction $transaction
36
+	 */
37
+	private $transaction;
38 38
 
39 39
 
40
-    /**
41
-     * EventEditorHeartbeat constructor.
42
-     */
43
-    public function __construct()
44
-    {
45
-        $this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE;
46
-        add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3);
47
-        add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3);
48
-    }
40
+	/**
41
+	 * EventEditorHeartbeat constructor.
42
+	 */
43
+	public function __construct()
44
+	{
45
+		$this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE;
46
+		add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3);
47
+		add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3);
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * thank_you_page_IPN_monitor
53
-     * this basically just pulls the TXN based on the reg_url_link sent from the server,
54
-     * then checks that the TXN status is not failed, and that no other errors have been generated.
55
-     * it also calculates the IPN wait time since the Thank You page was first loaded
56
-     *
57
-     * @param array $response
58
-     * @param array $data
59
-     * @return array
60
-     * @throws EE_Error
61
-     * @throws InvalidArgumentException
62
-     * @throws InvalidDataTypeException
63
-     * @throws InvalidInterfaceException
64
-     * @throws ReflectionException
65
-     */
66
-    public function heartbeatResponse($response = array(), $data = array())
67
-    {
68
-        // does this heartbeat contain our data ?
69
-        if (! isset($data[ $this->heartbeat ])) {
70
-            return $response;
71
-        }
72
-        // check for reg_url_link in the incoming heartbeat data
73
-        if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) {
74
-            $response[ $this->heartbeat ] = array(
75
-                'errors' => ! empty($notices['errors'])
76
-                    ? $notices['errors']
77
-                    : esc_html__(
78
-                        'No transaction information could be retrieved because the registration URL link is missing or invalid.',
79
-                        'event_espresso'
80
-                    ),
81
-            );
82
-            return $response;
83
-        }
84
-        // kk heartbeat has our data
85
-        $response = $this->initializeThankYouPageAndTransaction($response, $data);
86
-        // if something went wrong...
87
-        if (isset($response[ $this->heartbeat ]['errors'])) {
88
-            return $response;
89
-        }
90
-        // grab transient of Transaction's status
91
-        $txn_status = isset($data[ $this->heartbeat ]['txn_status'])
92
-            ? $data[ $this->heartbeat ]['txn_status']
93
-            : null;
94
-        $response = $this->getTransactionDetails($txn_status, $response, $data);
95
-        // no payment data yet?
96
-        if (isset($response[ $this->heartbeat ]['still_waiting'])) {
97
-            return $response;
98
-        }
99
-        // TXN is happening so let's get the payments now
100
-        // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
101
-        $since = isset($data[ $this->heartbeat ]['get_payments_since'])
102
-            ? $data[ $this->heartbeat ]['get_payments_since']
103
-            : 0;
104
-        return $this->paymentDetails($response, $since);
105
-    }
51
+	/**
52
+	 * thank_you_page_IPN_monitor
53
+	 * this basically just pulls the TXN based on the reg_url_link sent from the server,
54
+	 * then checks that the TXN status is not failed, and that no other errors have been generated.
55
+	 * it also calculates the IPN wait time since the Thank You page was first loaded
56
+	 *
57
+	 * @param array $response
58
+	 * @param array $data
59
+	 * @return array
60
+	 * @throws EE_Error
61
+	 * @throws InvalidArgumentException
62
+	 * @throws InvalidDataTypeException
63
+	 * @throws InvalidInterfaceException
64
+	 * @throws ReflectionException
65
+	 */
66
+	public function heartbeatResponse($response = array(), $data = array())
67
+	{
68
+		// does this heartbeat contain our data ?
69
+		if (! isset($data[ $this->heartbeat ])) {
70
+			return $response;
71
+		}
72
+		// check for reg_url_link in the incoming heartbeat data
73
+		if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) {
74
+			$response[ $this->heartbeat ] = array(
75
+				'errors' => ! empty($notices['errors'])
76
+					? $notices['errors']
77
+					: esc_html__(
78
+						'No transaction information could be retrieved because the registration URL link is missing or invalid.',
79
+						'event_espresso'
80
+					),
81
+			);
82
+			return $response;
83
+		}
84
+		// kk heartbeat has our data
85
+		$response = $this->initializeThankYouPageAndTransaction($response, $data);
86
+		// if something went wrong...
87
+		if (isset($response[ $this->heartbeat ]['errors'])) {
88
+			return $response;
89
+		}
90
+		// grab transient of Transaction's status
91
+		$txn_status = isset($data[ $this->heartbeat ]['txn_status'])
92
+			? $data[ $this->heartbeat ]['txn_status']
93
+			: null;
94
+		$response = $this->getTransactionDetails($txn_status, $response, $data);
95
+		// no payment data yet?
96
+		if (isset($response[ $this->heartbeat ]['still_waiting'])) {
97
+			return $response;
98
+		}
99
+		// TXN is happening so let's get the payments now
100
+		// if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
101
+		$since = isset($data[ $this->heartbeat ]['get_payments_since'])
102
+			? $data[ $this->heartbeat ]['get_payments_since']
103
+			: 0;
104
+		return $this->paymentDetails($response, $since);
105
+	}
106 106
 
107 107
 
108
-    /**
109
-     * @param array $response
110
-     * @param array $data
111
-     * @return array
112
-     * @throws EE_Error
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidInterfaceException
116
-     */
117
-    private function initializeThankYouPageAndTransaction($response, $data)
118
-    {
119
-        require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
120
-        // set_definitions, instantiate the thank you page class, and get the ball rolling
121
-        EED_Thank_You_Page::set_definitions();
122
-        $this->thank_you_page = EED_Thank_You_Page::instance();
123
-        $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']);
124
-        $this->thank_you_page->init();
125
-        // get TXN
126
-        $transaction = $this->thank_you_page->get_txn();
127
-        // no TXN? then get out
128
-        if (! $transaction instanceof EE_Transaction) {
129
-            $notices = EE_Error::get_notices();
130
-            $response[ $this->heartbeat ] = array(
131
-                'errors' => ! empty($notices['errors'])
132
-                    ? $notices['errors']
133
-                    : sprintf(
134
-                        esc_html__(
135
-                            'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
136
-                            'event_espresso'
137
-                        ),
138
-                        __LINE__
139
-                    ),
140
-            );
141
-            return $response;
142
-        }
143
-        $this->transaction = $transaction;
144
-        return $response;
145
-    }
108
+	/**
109
+	 * @param array $response
110
+	 * @param array $data
111
+	 * @return array
112
+	 * @throws EE_Error
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidInterfaceException
116
+	 */
117
+	private function initializeThankYouPageAndTransaction($response, $data)
118
+	{
119
+		require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
120
+		// set_definitions, instantiate the thank you page class, and get the ball rolling
121
+		EED_Thank_You_Page::set_definitions();
122
+		$this->thank_you_page = EED_Thank_You_Page::instance();
123
+		$this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']);
124
+		$this->thank_you_page->init();
125
+		// get TXN
126
+		$transaction = $this->thank_you_page->get_txn();
127
+		// no TXN? then get out
128
+		if (! $transaction instanceof EE_Transaction) {
129
+			$notices = EE_Error::get_notices();
130
+			$response[ $this->heartbeat ] = array(
131
+				'errors' => ! empty($notices['errors'])
132
+					? $notices['errors']
133
+					: sprintf(
134
+						esc_html__(
135
+							'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
136
+							'event_espresso'
137
+						),
138
+						__LINE__
139
+					),
140
+			);
141
+			return $response;
142
+		}
143
+		$this->transaction = $transaction;
144
+		return $response;
145
+	}
146 146
 
147 147
 
148
-    /**
149
-     * @param string $txn_status
150
-     * @param array  $response
151
-     * @param array  $data
152
-     * @return array
153
-     * @throws EE_Error
154
-     * @throws InvalidArgumentException
155
-     * @throws InvalidDataTypeException
156
-     * @throws InvalidInterfaceException
157
-     * @throws ReflectionException
158
-     */
159
-    private function getTransactionDetails($txn_status, $response, $data)
160
-    {
161
-        // has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
162
-        if ($txn_status !== $this->transaction->status_ID()) {
163
-            // switch between two possible basic outcomes
164
-            switch ($this->transaction->status_ID()) {
165
-                // TXN has been updated in some way
166
-                case EEM_Transaction::overpaid_status_code:
167
-                case EEM_Transaction::complete_status_code:
168
-                case EEM_Transaction::incomplete_status_code:
169
-                    // send updated TXN results back to client,
170
-                    return $this->setTransactionDetails($response);
171
-                // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
172
-                case EEM_Transaction::failed_status_code:
173
-                default:
174
-                    // keep on waiting...
175
-                    return $this->updateServerWaitTime($data[ $this->heartbeat ]);
176
-            }
177
-            // or is the TXN still failed (never been updated) ???
178
-        } elseif ($this->transaction->failed()) {
179
-            // keep on waiting...
180
-            return $this->updateServerWaitTime($data[ $this->heartbeat ]);
181
-        }
182
-        return $response;
183
-    }
148
+	/**
149
+	 * @param string $txn_status
150
+	 * @param array  $response
151
+	 * @param array  $data
152
+	 * @return array
153
+	 * @throws EE_Error
154
+	 * @throws InvalidArgumentException
155
+	 * @throws InvalidDataTypeException
156
+	 * @throws InvalidInterfaceException
157
+	 * @throws ReflectionException
158
+	 */
159
+	private function getTransactionDetails($txn_status, $response, $data)
160
+	{
161
+		// has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
162
+		if ($txn_status !== $this->transaction->status_ID()) {
163
+			// switch between two possible basic outcomes
164
+			switch ($this->transaction->status_ID()) {
165
+				// TXN has been updated in some way
166
+				case EEM_Transaction::overpaid_status_code:
167
+				case EEM_Transaction::complete_status_code:
168
+				case EEM_Transaction::incomplete_status_code:
169
+					// send updated TXN results back to client,
170
+					return $this->setTransactionDetails($response);
171
+				// or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
172
+				case EEM_Transaction::failed_status_code:
173
+				default:
174
+					// keep on waiting...
175
+					return $this->updateServerWaitTime($data[ $this->heartbeat ]);
176
+			}
177
+			// or is the TXN still failed (never been updated) ???
178
+		} elseif ($this->transaction->failed()) {
179
+			// keep on waiting...
180
+			return $this->updateServerWaitTime($data[ $this->heartbeat ]);
181
+		}
182
+		return $response;
183
+	}
184 184
 
185 185
 
186
-    /**
187
-     * @param array $response
188
-     * @param boolean $status_only
189
-     * @return array
190
-     * @throws EE_Error
191
-     * @throws InvalidArgumentException
192
-     * @throws InvalidDataTypeException
193
-     * @throws InvalidInterfaceException
194
-     * @throws ReflectionException
195
-     */
196
-    private function setTransactionDetails($response, $status_only = false)
197
-    {
198
-        if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) {
199
-            $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details();
200
-        }
201
-        if (! isset($response[ $this->heartbeat ]['txn_status'])) {
202
-            $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID();
203
-        }
204
-        return $response;
205
-    }
186
+	/**
187
+	 * @param array $response
188
+	 * @param boolean $status_only
189
+	 * @return array
190
+	 * @throws EE_Error
191
+	 * @throws InvalidArgumentException
192
+	 * @throws InvalidDataTypeException
193
+	 * @throws InvalidInterfaceException
194
+	 * @throws ReflectionException
195
+	 */
196
+	private function setTransactionDetails($response, $status_only = false)
197
+	{
198
+		if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) {
199
+			$response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details();
200
+		}
201
+		if (! isset($response[ $this->heartbeat ]['txn_status'])) {
202
+			$response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID();
203
+		}
204
+		return $response;
205
+	}
206 206
 
207 207
 
208
-    /**
209
-     * @param array $response
210
-     * @param int $since
211
-     * @return array
212
-     * @throws EE_Error
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidDataTypeException
215
-     * @throws InvalidInterfaceException
216
-     * @throws ReflectionException
217
-     */
218
-    private function paymentDetails($response, $since)
219
-    {
220
-        // then check for payments
221
-        $payments = $this->thank_you_page->get_txn_payments($since);
222
-        // has a payment been processed ?
223
-        if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
224
-            if ($since) {
225
-                $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments);
226
-                $response = $this->setTransactionDetails($response);
227
-            } else {
228
-                $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details(
229
-                    $payments
230
-                );
231
-            }
232
-            // reset time to check for payments
233
-            $response[ $this->heartbeat ]['get_payments_since'] = time();
234
-        } else {
235
-            $response[ $this->heartbeat ]['get_payments_since'] = $since;
236
-        }
237
-        return $response;
238
-    }
208
+	/**
209
+	 * @param array $response
210
+	 * @param int $since
211
+	 * @return array
212
+	 * @throws EE_Error
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidDataTypeException
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws ReflectionException
217
+	 */
218
+	private function paymentDetails($response, $since)
219
+	{
220
+		// then check for payments
221
+		$payments = $this->thank_you_page->get_txn_payments($since);
222
+		// has a payment been processed ?
223
+		if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
224
+			if ($since) {
225
+				$response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments);
226
+				$response = $this->setTransactionDetails($response);
227
+			} else {
228
+				$response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details(
229
+					$payments
230
+				);
231
+			}
232
+			// reset time to check for payments
233
+			$response[ $this->heartbeat ]['get_payments_since'] = time();
234
+		} else {
235
+			$response[ $this->heartbeat ]['get_payments_since'] = $since;
236
+		}
237
+		return $response;
238
+	}
239 239
 
240 240
 
241
-    /**
242
-     * @param array $thank_you_page_data    thank you page portion of the incoming JSON array
243
-     *                                      from the WP heartbeat data
244
-     * @return array
245
-     * @throws EE_Error
246
-     * @throws InvalidArgumentException
247
-     * @throws InvalidDataTypeException
248
-     * @throws InvalidInterfaceException
249
-     * @throws ReflectionException
250
-     */
251
-    private function updateServerWaitTime($thank_you_page_data)
252
-    {
253
-        $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access'])
254
-            ? time() - $thank_you_page_data['initial_access']
255
-            : 0;
256
-        $response = $this->setTransactionDetails($response, true);
257
-        return $response;
258
-    }
241
+	/**
242
+	 * @param array $thank_you_page_data    thank you page portion of the incoming JSON array
243
+	 *                                      from the WP heartbeat data
244
+	 * @return array
245
+	 * @throws EE_Error
246
+	 * @throws InvalidArgumentException
247
+	 * @throws InvalidDataTypeException
248
+	 * @throws InvalidInterfaceException
249
+	 * @throws ReflectionException
250
+	 */
251
+	private function updateServerWaitTime($thank_you_page_data)
252
+	{
253
+		$response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access'])
254
+			? time() - $thank_you_page_data['initial_access']
255
+			: 0;
256
+		$response = $this->setTransactionDetails($response, true);
257
+		return $response;
258
+	}
259 259
 }
Please login to merge, or discard this patch.
core/domain/services/ticket/CancelTicketLineItemService.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
             );
89 89
             $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item);
90 90
         }
91
-        if (! $success) {
91
+        if ( ! $success) {
92 92
             throw new \RuntimeException(
93 93
                 sprintf(
94 94
                     esc_html__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'),
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
                 break;
126 126
             }
127 127
         }
128
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
128
+        if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
129 129
             throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
130 130
         }
131 131
         return $line_item;
Please login to merge, or discard this patch.
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -18,114 +18,114 @@
 block discarded – undo
18 18
  */
19 19
 class CancelTicketLineItemService extends DomainService
20 20
 {
21
-    /**
22
-     * @param \EE_Registration $registration
23
-     * @param int              $quantity
24
-     * @return bool|int
25
-     */
26
-    public function forRegistration(\EE_Registration $registration, $quantity = 1)
27
-    {
28
-        return $this->cancel(
29
-            $registration->transaction(),
30
-            $registration->ticket(),
31
-            $quantity,
32
-            $registration->ticket_line_item()
33
-        );
34
-    }
21
+	/**
22
+	 * @param \EE_Registration $registration
23
+	 * @param int              $quantity
24
+	 * @return bool|int
25
+	 */
26
+	public function forRegistration(\EE_Registration $registration, $quantity = 1)
27
+	{
28
+		return $this->cancel(
29
+			$registration->transaction(),
30
+			$registration->ticket(),
31
+			$quantity,
32
+			$registration->ticket_line_item()
33
+		);
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * @param \EE_Transaction $transaction
39
-     * @param \EE_Ticket      $ticket
40
-     * @param int             $quantity
41
-     * @param \EE_Line_Item   $ticket_line_item
42
-     * @return bool|int
43
-     */
44
-    public function cancel(
45
-        \EE_Transaction $transaction,
46
-        \EE_Ticket $ticket,
47
-        $quantity = 1,
48
-        \EE_Line_Item $ticket_line_item = null
49
-    ) {
50
-        $ticket_line_item = $ticket_line_item instanceof \EE_Line_Item
51
-            ? $ticket_line_item
52
-            : $this->getTicketLineItem($transaction, $ticket);
53
-        // first we need to decrement the ticket quantity
54
-        \EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity);
55
-        // no tickets left for this line item ?
56
-        if ((int) $ticket_line_item->quantity() === 0) {
57
-            // then just set this line item as cancelled, save, and get out
58
-            $ticket_line_item->set_type(\EEM_Line_Item::type_cancellation);
59
-            $success = $ticket_line_item->save();
60
-        } else {
61
-            // otherwise create a new cancelled line item, so that we have a record of the cancellation
62
-            $items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal(
63
-                \EEH_Line_Item::get_event_line_item_for_ticket(
64
-                    $transaction->total_line_item(),
65
-                    $ticket
66
-                )
67
-            );
68
-            $cancelled_line_item = \EE_Line_Item::new_instance(
69
-                array(
70
-                    'LIN_name'       => $ticket_line_item->name(),
71
-                    'LIN_desc'       => sprintf(
72
-                        esc_html__('%1$s Cancelled: %2$s', 'event_espresso'),
73
-                        $ticket_line_item->desc(),
74
-                        date('Y-m-d h:i a')
75
-                    ),
76
-                    'LIN_unit_price' => (float) $ticket_line_item->unit_price(),
77
-                    'LIN_quantity'   => $quantity,
78
-                    'LIN_percent'    => null,
79
-                    'LIN_is_taxable' => false,
80
-                    'LIN_order'      => $items_subtotal instanceof \EE_Line_Item
81
-                        ? count($items_subtotal->children())
82
-                        : 0,
83
-                    'LIN_total'      => (float) $ticket_line_item->unit_price(),
84
-                    'LIN_type'       => \EEM_Line_Item::type_cancellation,
85
-                )
86
-            );
87
-            $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item);
88
-        }
89
-        if (! $success) {
90
-            throw new \RuntimeException(
91
-                sprintf(
92
-                    esc_html__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'),
93
-                    $ticket_line_item->ID()
94
-                )
95
-            );
96
-        }
97
-        return $success;
98
-    }
37
+	/**
38
+	 * @param \EE_Transaction $transaction
39
+	 * @param \EE_Ticket      $ticket
40
+	 * @param int             $quantity
41
+	 * @param \EE_Line_Item   $ticket_line_item
42
+	 * @return bool|int
43
+	 */
44
+	public function cancel(
45
+		\EE_Transaction $transaction,
46
+		\EE_Ticket $ticket,
47
+		$quantity = 1,
48
+		\EE_Line_Item $ticket_line_item = null
49
+	) {
50
+		$ticket_line_item = $ticket_line_item instanceof \EE_Line_Item
51
+			? $ticket_line_item
52
+			: $this->getTicketLineItem($transaction, $ticket);
53
+		// first we need to decrement the ticket quantity
54
+		\EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity);
55
+		// no tickets left for this line item ?
56
+		if ((int) $ticket_line_item->quantity() === 0) {
57
+			// then just set this line item as cancelled, save, and get out
58
+			$ticket_line_item->set_type(\EEM_Line_Item::type_cancellation);
59
+			$success = $ticket_line_item->save();
60
+		} else {
61
+			// otherwise create a new cancelled line item, so that we have a record of the cancellation
62
+			$items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal(
63
+				\EEH_Line_Item::get_event_line_item_for_ticket(
64
+					$transaction->total_line_item(),
65
+					$ticket
66
+				)
67
+			);
68
+			$cancelled_line_item = \EE_Line_Item::new_instance(
69
+				array(
70
+					'LIN_name'       => $ticket_line_item->name(),
71
+					'LIN_desc'       => sprintf(
72
+						esc_html__('%1$s Cancelled: %2$s', 'event_espresso'),
73
+						$ticket_line_item->desc(),
74
+						date('Y-m-d h:i a')
75
+					),
76
+					'LIN_unit_price' => (float) $ticket_line_item->unit_price(),
77
+					'LIN_quantity'   => $quantity,
78
+					'LIN_percent'    => null,
79
+					'LIN_is_taxable' => false,
80
+					'LIN_order'      => $items_subtotal instanceof \EE_Line_Item
81
+						? count($items_subtotal->children())
82
+						: 0,
83
+					'LIN_total'      => (float) $ticket_line_item->unit_price(),
84
+					'LIN_type'       => \EEM_Line_Item::type_cancellation,
85
+				)
86
+			);
87
+			$success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item);
88
+		}
89
+		if (! $success) {
90
+			throw new \RuntimeException(
91
+				sprintf(
92
+					esc_html__('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'),
93
+					$ticket_line_item->ID()
94
+				)
95
+			);
96
+		}
97
+		return $success;
98
+	}
99 99
 
100 100
 
101
-    /**
102
-     * @param \EE_Transaction $transaction
103
-     * @param \EE_Ticket      $ticket
104
-     * @return \EE_Line_Item
105
-     * @throws EntityNotFoundException
106
-     * @throws \EE_Error
107
-     */
108
-    protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket)
109
-    {
110
-        $line_item = null;
111
-        $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
112
-            $transaction->total_line_item(),
113
-            'Ticket',
114
-            array($ticket->ID())
115
-        );
116
-        foreach ($ticket_line_items as $ticket_line_item) {
117
-            if (
118
-                $ticket_line_item instanceof \EE_Line_Item
119
-                && $ticket_line_item->OBJ_type() === 'Ticket'
120
-                && $ticket_line_item->OBJ_ID() === $ticket->ID()
121
-            ) {
122
-                $line_item = $ticket_line_item;
123
-                break;
124
-            }
125
-        }
126
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
127
-            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
128
-        }
129
-        return $line_item;
130
-    }
101
+	/**
102
+	 * @param \EE_Transaction $transaction
103
+	 * @param \EE_Ticket      $ticket
104
+	 * @return \EE_Line_Item
105
+	 * @throws EntityNotFoundException
106
+	 * @throws \EE_Error
107
+	 */
108
+	protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket)
109
+	{
110
+		$line_item = null;
111
+		$ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
112
+			$transaction->total_line_item(),
113
+			'Ticket',
114
+			array($ticket->ID())
115
+		);
116
+		foreach ($ticket_line_items as $ticket_line_item) {
117
+			if (
118
+				$ticket_line_item instanceof \EE_Line_Item
119
+				&& $ticket_line_item->OBJ_type() === 'Ticket'
120
+				&& $ticket_line_item->OBJ_ID() === $ticket->ID()
121
+			) {
122
+				$line_item = $ticket_line_item;
123
+				break;
124
+			}
125
+		}
126
+		if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
127
+			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
128
+		}
129
+		return $line_item;
130
+	}
131 131
 }
Please login to merge, or discard this patch.
core/domain/services/validation/email/strategies/InternationalDNS.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
             $email_address,
31 31
             $this->getAtIndex($email_address)
32 32
         );
33
-        if (! checkdnsrr($domain, 'MX')) {
33
+        if ( ! checkdnsrr($domain, 'MX')) {
34 34
             // domain not found in MX records
35 35
             throw new EmailValidationException(
36 36
                 esc_html__(
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
                 )
42 42
             );
43 43
         }
44
-        if (! checkdnsrr($domain, 'A')) {
44
+        if ( ! checkdnsrr($domain, 'A')) {
45 45
             // domain not found in A records
46 46
             throw new EmailValidationException(
47 47
                 esc_html__(
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -14,43 +14,43 @@
 block discarded – undo
14 14
  */
15 15
 class InternationalDNS extends International
16 16
 {
17
-    /**
18
-     * Validates the email in teh same way as the parent, but also
19
-     * verifies the domain exists.
20
-     *
21
-     * @param string $email_address
22
-     * @return bool
23
-     * @throws EmailValidationException
24
-     */
25
-    public function validate($email_address)
26
-    {
27
-        parent::validate($email_address);
28
-        $domain = $this->getDomainPartOfEmail(
29
-            $email_address,
30
-            $this->getAtIndex($email_address)
31
-        );
32
-        if (! checkdnsrr($domain, 'MX')) {
33
-            // domain not found in MX records
34
-            throw new EmailValidationException(
35
-                esc_html__(
36
-                // @codingStandardsIgnoreStart
37
-                    'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.',
38
-                    // @codingStandardsIgnoreEnd
39
-                    'event_espresso'
40
-                )
41
-            );
42
-        }
43
-        if (! checkdnsrr($domain, 'A')) {
44
-            // domain not found in A records
45
-            throw new EmailValidationException(
46
-                esc_html__(
47
-                // @codingStandardsIgnoreStart
48
-                    'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.',
49
-                    // @codingStandardsIgnoreEnd
50
-                    'event_espresso'
51
-                )
52
-            );
53
-        }
54
-        return true;
55
-    }
17
+	/**
18
+	 * Validates the email in teh same way as the parent, but also
19
+	 * verifies the domain exists.
20
+	 *
21
+	 * @param string $email_address
22
+	 * @return bool
23
+	 * @throws EmailValidationException
24
+	 */
25
+	public function validate($email_address)
26
+	{
27
+		parent::validate($email_address);
28
+		$domain = $this->getDomainPartOfEmail(
29
+			$email_address,
30
+			$this->getAtIndex($email_address)
31
+		);
32
+		if (! checkdnsrr($domain, 'MX')) {
33
+			// domain not found in MX records
34
+			throw new EmailValidationException(
35
+				esc_html__(
36
+				// @codingStandardsIgnoreStart
37
+					'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.',
38
+					// @codingStandardsIgnoreEnd
39
+					'event_espresso'
40
+				)
41
+			);
42
+		}
43
+		if (! checkdnsrr($domain, 'A')) {
44
+			// domain not found in A records
45
+			throw new EmailValidationException(
46
+				esc_html__(
47
+				// @codingStandardsIgnoreStart
48
+					'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.',
49
+					// @codingStandardsIgnoreEnd
50
+					'event_espresso'
51
+				)
52
+			);
53
+		}
54
+		return true;
55
+	}
56 56
 }
Please login to merge, or discard this patch.
core/EE_Module_Request_Router.core.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         // assume this if first route being called
61 61
         $previous_route = false;
62 62
         // but is it really ???
63
-        if (! empty(self::$_previous_routes)) {
63
+        if ( ! empty(self::$_previous_routes)) {
64 64
             // get last run route
65 65
             $previous_routes = array_values(self::$_previous_routes);
66 66
             $previous_route = array_pop($previous_routes);
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             $current_route = $this->get_forward($previous_route);
72 72
             try {
73 73
                 // check for recursive forwarding
74
-                if (isset(self::$_previous_routes[ $current_route ])) {
74
+                if (isset(self::$_previous_routes[$current_route])) {
75 75
                     throw new EE_Error(
76 76
                         sprintf(
77 77
                             esc_html__(
@@ -144,38 +144,38 @@  discard block
 block discarded – undo
144 144
             return false;
145 145
         }
146 146
         // verify that result is an array
147
-        if (! is_array($module_method)) {
147
+        if ( ! is_array($module_method)) {
148 148
             $msg = sprintf(esc_html__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
149
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
149
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
150 150
             return false;
151 151
         }
152 152
         // grab module name
153 153
         $module_name = $module_method[0];
154 154
         // verify that a class method was registered properly
155
-        if (! isset($module_method[1])) {
155
+        if ( ! isset($module_method[1])) {
156 156
             $msg = sprintf(
157 157
                 esc_html__('A class method for the %s  route has not been properly registered.', 'event_espresso'),
158 158
                 $current_route
159 159
             );
160
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
160
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
161 161
             return false;
162 162
         }
163 163
         // grab method
164 164
         $method = $module_method[1];
165 165
         // verify that class exists
166
-        if (! class_exists($module_name)) {
166
+        if ( ! class_exists($module_name)) {
167 167
             $msg = sprintf(esc_html__('The requested %s class could not be found.', 'event_espresso'), $module_name);
168 168
             EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
169 169
             return false;
170 170
         }
171 171
         // verify that method exists
172
-        if (! method_exists($module_name, $method)) {
172
+        if ( ! method_exists($module_name, $method)) {
173 173
             $msg = sprintf(
174 174
                 esc_html__('The class method %s for the %s route is in invalid.', 'event_espresso'),
175 175
                 $method,
176 176
                 $current_route
177 177
             );
178
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
178
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
179 179
             return false;
180 180
         }
181 181
         // instantiate module and call route method
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
         // instantiate module class
210 210
         $module = new $module_name();
211 211
         // ensure that class is actually a module
212
-        if (! $module instanceof EED_Module) {
212
+        if ( ! $module instanceof EED_Module) {
213 213
             EE_Error::add_error(
214 214
                 sprintf(esc_html__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
215 215
                 __FILE__,
Please login to merge, or discard this patch.
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -15,254 +15,254 @@
 block discarded – undo
15 15
  */
16 16
 final class EE_Module_Request_Router implements InterminableInterface
17 17
 {
18
-    /**
19
-     * @var RequestInterface $request
20
-     */
21
-    private $request;
18
+	/**
19
+	 * @var RequestInterface $request
20
+	 */
21
+	private $request;
22 22
 
23
-    /**
24
-     * @var array $_previous_routes
25
-     */
26
-    private static $_previous_routes = array();
23
+	/**
24
+	 * @var array $_previous_routes
25
+	 */
26
+	private static $_previous_routes = array();
27 27
 
28
-    /**
29
-     * @var WP_Query $WP_Query
30
-     */
31
-    public $WP_Query;
28
+	/**
29
+	 * @var WP_Query $WP_Query
30
+	 */
31
+	public $WP_Query;
32 32
 
33 33
 
34
-    /**
35
-     * EE_Module_Request_Router constructor.
36
-     *
37
-     * @param RequestInterface $request
38
-     */
39
-    public function __construct(RequestInterface $request)
40
-    {
41
-        $this->request = $request;
42
-    }
34
+	/**
35
+	 * EE_Module_Request_Router constructor.
36
+	 *
37
+	 * @param RequestInterface $request
38
+	 */
39
+	public function __construct(RequestInterface $request)
40
+	{
41
+		$this->request = $request;
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * on the first call  to this method, it checks the Request for a "route"
47
-     * on subsequent calls to this method,
48
-     * instead of checking the Request for a route, it checks the previous routes array,
49
-     * and checks if the last called route has any forwarding routes registered for it
50
-     *
51
-     * @param WP_Query $WP_Query
52
-     * @return NULL|string
53
-     * @throws EE_Error
54
-     * @throws ReflectionException
55
-     */
56
-    public function get_route(WP_Query $WP_Query)
57
-    {
58
-        $this->WP_Query = $WP_Query;
59
-        // assume this if first route being called
60
-        $previous_route = false;
61
-        // but is it really ???
62
-        if (! empty(self::$_previous_routes)) {
63
-            // get last run route
64
-            $previous_routes = array_values(self::$_previous_routes);
65
-            $previous_route = array_pop($previous_routes);
66
-        }
67
-        //  has another route already been run ?
68
-        if ($previous_route) {
69
-            // check if  forwarding has been set
70
-            $current_route = $this->get_forward($previous_route);
71
-            try {
72
-                // check for recursive forwarding
73
-                if (isset(self::$_previous_routes[ $current_route ])) {
74
-                    throw new EE_Error(
75
-                        sprintf(
76
-                            esc_html__(
77
-                                'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
78
-                                'event_espresso'
79
-                            ),
80
-                            $current_route
81
-                        )
82
-                    );
83
-                }
84
-            } catch (EE_Error $e) {
85
-                $e->get_error();
86
-                return null;
87
-            }
88
-        } else {
89
-            // first route called
90
-            $current_route = null;
91
-            // grab all routes
92
-            $routes = EE_Config::get_routes();
93
-            foreach ($routes as $key => $route) {
94
-                // first determine if route key uses w?ldc*rds
95
-                $uses_wildcards = strpos($key, '?') !== false
96
-                                  || strpos($key, '*') !== false;
97
-                // check request for module route
98
-                $route_found = $uses_wildcards
99
-                    ? $this->request->matches($key)
100
-                    : $this->request->requestParamIsSet($key);
101
-                if ($route_found) {
102
-                    $current_route = $uses_wildcards
103
-                        ? $this->request->getMatch($key)
104
-                        : $this->request->getRequestParam($key);
105
-                    $current_route = sanitize_text_field($current_route);
106
-                    if ($current_route) {
107
-                        $current_route = array($key, $current_route);
108
-                        break;
109
-                    }
110
-                }
111
-            }
112
-        }
113
-        // sorry, but I can't read what you route !
114
-        if (empty($current_route)) {
115
-            return null;
116
-        }
117
-        // add route to previous routes array
118
-        self::$_previous_routes[] = $current_route;
119
-        return $current_route;
120
-    }
45
+	/**
46
+	 * on the first call  to this method, it checks the Request for a "route"
47
+	 * on subsequent calls to this method,
48
+	 * instead of checking the Request for a route, it checks the previous routes array,
49
+	 * and checks if the last called route has any forwarding routes registered for it
50
+	 *
51
+	 * @param WP_Query $WP_Query
52
+	 * @return NULL|string
53
+	 * @throws EE_Error
54
+	 * @throws ReflectionException
55
+	 */
56
+	public function get_route(WP_Query $WP_Query)
57
+	{
58
+		$this->WP_Query = $WP_Query;
59
+		// assume this if first route being called
60
+		$previous_route = false;
61
+		// but is it really ???
62
+		if (! empty(self::$_previous_routes)) {
63
+			// get last run route
64
+			$previous_routes = array_values(self::$_previous_routes);
65
+			$previous_route = array_pop($previous_routes);
66
+		}
67
+		//  has another route already been run ?
68
+		if ($previous_route) {
69
+			// check if  forwarding has been set
70
+			$current_route = $this->get_forward($previous_route);
71
+			try {
72
+				// check for recursive forwarding
73
+				if (isset(self::$_previous_routes[ $current_route ])) {
74
+					throw new EE_Error(
75
+						sprintf(
76
+							esc_html__(
77
+								'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.',
78
+								'event_espresso'
79
+							),
80
+							$current_route
81
+						)
82
+					);
83
+				}
84
+			} catch (EE_Error $e) {
85
+				$e->get_error();
86
+				return null;
87
+			}
88
+		} else {
89
+			// first route called
90
+			$current_route = null;
91
+			// grab all routes
92
+			$routes = EE_Config::get_routes();
93
+			foreach ($routes as $key => $route) {
94
+				// first determine if route key uses w?ldc*rds
95
+				$uses_wildcards = strpos($key, '?') !== false
96
+								  || strpos($key, '*') !== false;
97
+				// check request for module route
98
+				$route_found = $uses_wildcards
99
+					? $this->request->matches($key)
100
+					: $this->request->requestParamIsSet($key);
101
+				if ($route_found) {
102
+					$current_route = $uses_wildcards
103
+						? $this->request->getMatch($key)
104
+						: $this->request->getRequestParam($key);
105
+					$current_route = sanitize_text_field($current_route);
106
+					if ($current_route) {
107
+						$current_route = array($key, $current_route);
108
+						break;
109
+					}
110
+				}
111
+			}
112
+		}
113
+		// sorry, but I can't read what you route !
114
+		if (empty($current_route)) {
115
+			return null;
116
+		}
117
+		// add route to previous routes array
118
+		self::$_previous_routes[] = $current_route;
119
+		return $current_route;
120
+	}
121 121
 
122 122
 
123
-    /**
124
-     * this method simply takes a valid route, and resolves what module class method the route points to
125
-     *
126
-     * @param string $key
127
-     * @param string $current_route
128
-     * @return EED_Module|object|boolean|null
129
-     * @throws EE_Error
130
-     * @throws ReflectionException
131
-     */
132
-    public function resolve_route($key, $current_route)
133
-    {
134
-        // get module method that route has been mapped to
135
-        $module_method = EE_Config::get_route($current_route, $key);
136
-        // verify result was returned
137
-        if (empty($module_method)) {
138
-            $msg = sprintf(
139
-                esc_html__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
140
-                $current_route
141
-            );
142
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
143
-            return false;
144
-        }
145
-        // verify that result is an array
146
-        if (! is_array($module_method)) {
147
-            $msg = sprintf(esc_html__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
148
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
149
-            return false;
150
-        }
151
-        // grab module name
152
-        $module_name = $module_method[0];
153
-        // verify that a class method was registered properly
154
-        if (! isset($module_method[1])) {
155
-            $msg = sprintf(
156
-                esc_html__('A class method for the %s  route has not been properly registered.', 'event_espresso'),
157
-                $current_route
158
-            );
159
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
160
-            return false;
161
-        }
162
-        // grab method
163
-        $method = $module_method[1];
164
-        // verify that class exists
165
-        if (! class_exists($module_name)) {
166
-            $msg = sprintf(esc_html__('The requested %s class could not be found.', 'event_espresso'), $module_name);
167
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
168
-            return false;
169
-        }
170
-        // verify that method exists
171
-        if (! method_exists($module_name, $method)) {
172
-            $msg = sprintf(
173
-                esc_html__('The class method %s for the %s route is in invalid.', 'event_espresso'),
174
-                $method,
175
-                $current_route
176
-            );
177
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
178
-            return false;
179
-        }
180
-        // instantiate module and call route method
181
-        return $this->_module_router($module_name, $method);
182
-    }
123
+	/**
124
+	 * this method simply takes a valid route, and resolves what module class method the route points to
125
+	 *
126
+	 * @param string $key
127
+	 * @param string $current_route
128
+	 * @return EED_Module|object|boolean|null
129
+	 * @throws EE_Error
130
+	 * @throws ReflectionException
131
+	 */
132
+	public function resolve_route($key, $current_route)
133
+	{
134
+		// get module method that route has been mapped to
135
+		$module_method = EE_Config::get_route($current_route, $key);
136
+		// verify result was returned
137
+		if (empty($module_method)) {
138
+			$msg = sprintf(
139
+				esc_html__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'),
140
+				$current_route
141
+			);
142
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
143
+			return false;
144
+		}
145
+		// verify that result is an array
146
+		if (! is_array($module_method)) {
147
+			$msg = sprintf(esc_html__('The %s  route has not been properly registered.', 'event_espresso'), $current_route);
148
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
149
+			return false;
150
+		}
151
+		// grab module name
152
+		$module_name = $module_method[0];
153
+		// verify that a class method was registered properly
154
+		if (! isset($module_method[1])) {
155
+			$msg = sprintf(
156
+				esc_html__('A class method for the %s  route has not been properly registered.', 'event_espresso'),
157
+				$current_route
158
+			);
159
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
160
+			return false;
161
+		}
162
+		// grab method
163
+		$method = $module_method[1];
164
+		// verify that class exists
165
+		if (! class_exists($module_name)) {
166
+			$msg = sprintf(esc_html__('The requested %s class could not be found.', 'event_espresso'), $module_name);
167
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
168
+			return false;
169
+		}
170
+		// verify that method exists
171
+		if (! method_exists($module_name, $method)) {
172
+			$msg = sprintf(
173
+				esc_html__('The class method %s for the %s route is in invalid.', 'event_espresso'),
174
+				$method,
175
+				$current_route
176
+			);
177
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
178
+			return false;
179
+		}
180
+		// instantiate module and call route method
181
+		return $this->_module_router($module_name, $method);
182
+	}
183 183
 
184 184
 
185
-    /**
186
-     * this method instantiates modules and calls the method that was defined when the route was registered
187
-     *
188
-     * @param string $module_name
189
-     * @return EED_Module|object|null
190
-     */
191
-    public static function module_factory($module_name)
192
-    {
193
-        if ($module_name === 'EED_Module') {
194
-            EE_Error::add_error(
195
-                sprintf(
196
-                    esc_html__(
197
-                        'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
198
-                        'event_espresso'
199
-                    ),
200
-                    $module_name
201
-                ),
202
-                __FILE__,
203
-                __FUNCTION__,
204
-                __LINE__
205
-            );
206
-            return null;
207
-        }
208
-        // instantiate module class
209
-        $module = new $module_name();
210
-        // ensure that class is actually a module
211
-        if (! $module instanceof EED_Module) {
212
-            EE_Error::add_error(
213
-                sprintf(esc_html__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
214
-                __FILE__,
215
-                __FUNCTION__,
216
-                __LINE__
217
-            );
218
-            return null;
219
-        }
220
-        return $module;
221
-    }
185
+	/**
186
+	 * this method instantiates modules and calls the method that was defined when the route was registered
187
+	 *
188
+	 * @param string $module_name
189
+	 * @return EED_Module|object|null
190
+	 */
191
+	public static function module_factory($module_name)
192
+	{
193
+		if ($module_name === 'EED_Module') {
194
+			EE_Error::add_error(
195
+				sprintf(
196
+					esc_html__(
197
+						'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.',
198
+						'event_espresso'
199
+					),
200
+					$module_name
201
+				),
202
+				__FILE__,
203
+				__FUNCTION__,
204
+				__LINE__
205
+			);
206
+			return null;
207
+		}
208
+		// instantiate module class
209
+		$module = new $module_name();
210
+		// ensure that class is actually a module
211
+		if (! $module instanceof EED_Module) {
212
+			EE_Error::add_error(
213
+				sprintf(esc_html__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name),
214
+				__FILE__,
215
+				__FUNCTION__,
216
+				__LINE__
217
+			);
218
+			return null;
219
+		}
220
+		return $module;
221
+	}
222 222
 
223 223
 
224
-    /**
225
-     * this method instantiates modules and calls the method that was defined when the route was registered
226
-     *
227
-     * @param string $module_name
228
-     * @param string $method
229
-     * @return EED_Module|null
230
-     * @throws EE_Error
231
-     * @throws ReflectionException
232
-     */
233
-    private function _module_router($module_name, $method)
234
-    {
235
-        // instantiate module class
236
-        $module = EE_Module_Request_Router::module_factory($module_name);
237
-        if ($module instanceof EED_Module) {
238
-            // and call whatever action the route was for
239
-            try {
240
-                $module->{$method}($this->WP_Query);
241
-            } catch (EE_Error $e) {
242
-                $e->get_error();
243
-                return null;
244
-            }
245
-        }
246
-        return $module;
247
-    }
224
+	/**
225
+	 * this method instantiates modules and calls the method that was defined when the route was registered
226
+	 *
227
+	 * @param string $module_name
228
+	 * @param string $method
229
+	 * @return EED_Module|null
230
+	 * @throws EE_Error
231
+	 * @throws ReflectionException
232
+	 */
233
+	private function _module_router($module_name, $method)
234
+	{
235
+		// instantiate module class
236
+		$module = EE_Module_Request_Router::module_factory($module_name);
237
+		if ($module instanceof EED_Module) {
238
+			// and call whatever action the route was for
239
+			try {
240
+				$module->{$method}($this->WP_Query);
241
+			} catch (EE_Error $e) {
242
+				$e->get_error();
243
+				return null;
244
+			}
245
+		}
246
+		return $module;
247
+	}
248 248
 
249 249
 
250
-    /**
251
-     * @param $current_route
252
-     * @return string
253
-     */
254
-    public function get_forward($current_route)
255
-    {
256
-        return EE_Config::get_forward($current_route);
257
-    }
250
+	/**
251
+	 * @param $current_route
252
+	 * @return string
253
+	 */
254
+	public function get_forward($current_route)
255
+	{
256
+		return EE_Config::get_forward($current_route);
257
+	}
258 258
 
259 259
 
260
-    /**
261
-     * @param $current_route
262
-     * @return string
263
-     */
264
-    public function get_view($current_route)
265
-    {
266
-        return EE_Config::get_view($current_route);
267
-    }
260
+	/**
261
+	 * @param $current_route
262
+	 * @return string
263
+	 */
264
+	public function get_view($current_route)
265
+	{
266
+		return EE_Config::get_view($current_route);
267
+	}
268 268
 }
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_Data_Migration_Class_Base.core.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      */
186 186
     public function add_error($error, $force = false)
187 187
     {
188
-        if (! defined('EE_DMS_ERROR_LIMIT')) {
188
+        if ( ! defined('EE_DMS_ERROR_LIMIT')) {
189 189
             $limit = 50;
190 190
         } else {
191 191
             $limit = EE_DMS_ERROR_LIMIT;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
                 $this->_errors[] = "Limit reached; removed first half of errors to save space";
202 202
                 $this->_errors[] = $error;
203 203
             } else {
204
-                $this->_errors[ $limit ] = 'More, but limit reached...';
204
+                $this->_errors[$limit] = 'More, but limit reached...';
205 205
             }
206 206
         } else {
207 207
             $this->_errors[] = $error;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
         $new_columns_and_values_for_string = array();
346 346
         $count = 0;
347 347
         foreach ($new_row_as_array as $column => $value) {
348
-            $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
348
+            $new_columns_and_values_for_string[] = " $column => $value (".$data_types[$count++].")";
349 349
         }
350 350
         return sprintf(
351 351
             esc_html__(
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
         foreach ($array_of_data as $name => $value) {
377 377
             $unserialized_data = @unserialize($value);
378 378
             if ($unserialized_data === false) {
379
-                $fields_to_include[ $name ] = $value;
379
+                $fields_to_include[$name] = $value;
380 380
             }
381 381
         }
382 382
         return wp_json_encode($fields_to_include);
Please login to merge, or discard this patch.
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -16,408 +16,408 @@
 block discarded – undo
16 16
  */
17 17
 abstract class EE_Data_Migration_Class_Base
18 18
 {
19
-    /**
20
-     * @var $records_to_migrate int count of all that have been migrated
21
-     */
22
-    protected $_records_to_migrate = 0;
23
-
24
-    /**
25
-     *
26
-     * @var $records_migrated int
27
-     */
28
-    protected $_records_migrated = 0;
29
-
30
-    /**
31
-     * Whether this migration script is done or not. This COULD be deduced by
32
-     * _records_to_migrate and _records_migrated, but that might nto be accurate
33
-     *
34
-     * @var string one of EE_Data_migration_Manager::status_* constants
35
-     */
36
-    protected $_status = null;
37
-
38
-    /**
39
-     * internationalized name of this class. Convention is to NOT restate that
40
-     * this class if a migration script or a migration script stage
41
-     *
42
-     * @var string (i18ned)
43
-     */
44
-    protected $_pretty_name = null;
45
-
46
-    /**
47
-     * @var array
48
-     */
49
-    protected $_errors = array();
50
-
51
-    /**
52
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
53
-     */
54
-    protected $_table_manager;
55
-
56
-    /**
57
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
58
-     */
59
-    protected $_table_analysis;
60
-
61
-
62
-    /**
63
-     * Just initializes the status of the migration
64
-     *
65
-     * @param TableManager  $table_manager
66
-     * @param TableAnalysis $table_analysis
67
-     */
68
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
69
-    {
70
-        $this->_table_manager = $table_manager;
71
-        $this->_table_analysis = $table_analysis;
72
-        $this->set_status(EE_Data_Migration_Manager::status_continue);
73
-    }
74
-
75
-
76
-    /**
77
-     * Just gets the pretty name for this migration script or stage
78
-     *
79
-     * @throws EE_Error
80
-     * @return string
81
-     */
82
-    public function pretty_name()
83
-    {
84
-        if ($this->_pretty_name === null) {
85
-            throw new EE_Error(
86
-                sprintf(
87
-                    esc_html__(
88
-                        "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
89
-                        "event_espresso"
90
-                    ),
91
-                    get_class($this)
92
-                )
93
-            );
94
-        }
95
-        return $this->_pretty_name;
96
-    }
97
-
98
-    /**
99
-     *
100
-     * @return int
101
-     */
102
-    public function count_records_to_migrate()
103
-    {
104
-        if ($this->_records_to_migrate == null) {
105
-            $this->_records_to_migrate = $this->_count_records_to_migrate();
106
-        }
107
-        return $this->_records_to_migrate;
108
-    }
109
-
110
-    /**
111
-     * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
112
-     * EE_Data_migration_Script_Stage
113
-     *
114
-     * @return int
115
-     */
116
-    abstract public function count_records_migrated();
117
-
118
-    /**
119
-     * Counts the records to migrate; the public version may cache it
120
-     *
121
-     * @return int
122
-     */
123
-    abstract protected function _count_records_to_migrate();
124
-
125
-    /**
126
-     * Returns a string indicating the migration script's status.
127
-     *
128
-     * @return string one of EE_Data_Migration_Manager::status_* constants
129
-     * @throws EE_Error
130
-     */
131
-    public function get_status()
132
-    {
133
-        if ($this->_status === null) {
134
-            throw new EE_Error(
135
-                sprintf(
136
-                    esc_html__(
137
-                        "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
138
-                        "event_espresso"
139
-                    ),
140
-                    get_class($this)
141
-                )
142
-            );
143
-        }
144
-        return $this->_status;
145
-    }
146
-
147
-    /**
148
-     *
149
-     * @param string $status
150
-     * @return void
151
-     */
152
-    protected function set_status($status)
153
-    {
154
-        $this->_status = $status;
155
-    }
156
-
157
-    /**
158
-     * @return array of strings
159
-     */
160
-    abstract public function get_errors();
161
-
162
-    /**
163
-     * Returns the last error that occurred. If none occurred, returns null
164
-     *
165
-     * @return string
166
-     */
167
-    public function get_last_error()
168
-    {
169
-        $errors = $this->get_errors();
170
-        if ($errors) {
171
-            return end($errors);
172
-        } else {
173
-            return null;
174
-        }
175
-    }
176
-
177
-    /**
178
-     * Adds an error to the array of errors on this class.
179
-     *
180
-     * @param string  $error a string describing the error that will be useful for debugging. Consider including all
181
-     *                       the data that led to the error, and a stack trace etc.
182
-     * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
183
-     *                       already at their limit, we will purposefully forget the first half
184
-     */
185
-    public function add_error($error, $force = false)
186
-    {
187
-        if (! defined('EE_DMS_ERROR_LIMIT')) {
188
-            $limit = 50;
189
-        } else {
190
-            $limit = EE_DMS_ERROR_LIMIT;
191
-        }
192
-        // make sure errors is an array, see ticket #8261
193
-        if (is_string($this->_errors)) {
194
-            $this->_errors = array($this->_errors);
195
-        }
196
-        if (count($this->_errors) >= $limit) {
197
-            if ($force) {
198
-                // get rid of the first half of the errors and any above the limit
199
-                $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
200
-                $this->_errors[] = "Limit reached; removed first half of errors to save space";
201
-                $this->_errors[] = $error;
202
-            } else {
203
-                $this->_errors[ $limit ] = 'More, but limit reached...';
204
-            }
205
-        } else {
206
-            $this->_errors[] = $error;
207
-        }
208
-    }
209
-
210
-    /**
211
-     * Indicates there was a fatal error and the migration cannot possibly continue
212
-     *
213
-     * @return boolean
214
-     */
215
-    public function is_broken()
216
-    {
217
-        return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
218
-    }
219
-
220
-    /**
221
-     * @deprecated since 4.6.12
222
-     */
223
-    public function is_borked()
224
-    {
225
-        EE_Error::doing_it_wrong(
226
-            'is_borked',
227
-            esc_html__(
228
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
229
-                'event_espresso'
230
-            ),
231
-            '4.6.12'
232
-        );
233
-        return $this->is_broken();
234
-    }
235
-
236
-    /**
237
-     * Sets the status to as having a fatal error
238
-     */
239
-    public function set_broken()
240
-    {
241
-        $this->_status = EE_Data_Migration_Manager::status_fatal_error;
242
-    }
243
-
244
-    /**
245
-     *
246
-     * @deprecated since 4.6.12
247
-     */
248
-    public function set_borked()
249
-    {
250
-        EE_Error::doing_it_wrong(
251
-            'is_borked',
252
-            esc_html__(
253
-                'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
254
-                'event_espresso'
255
-            ),
256
-            '4.6.12'
257
-        );
258
-        return $this->set_broken();
259
-    }
260
-
261
-    /**
262
-     * Checks if this thing believes it is completed
263
-     *
264
-     * @return boolean
265
-     */
266
-    public function is_completed()
267
-    {
268
-        return $this->get_status() == EE_Data_Migration_Manager::status_completed;
269
-    }
270
-
271
-    /**
272
-     * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
273
-     *
274
-     * @return boolean
275
-     */
276
-    public function has_more_to_do()
277
-    {
278
-        return $this->get_status() == EE_Data_Migration_Manager::status_continue;
279
-    }
280
-
281
-    /**
282
-     * Marks that we believe this migration thing is completed
283
-     */
284
-    public function set_completed()
285
-    {
286
-        $this->_status = EE_Data_Migration_Manager::status_completed;
287
-    }
288
-
289
-    /**
290
-     * Marks that we think this migration class can continue to migrate
291
-     */
292
-    public function reattempt()
293
-    {
294
-        $this->_status = EE_Data_Migration_Manager::status_continue;
295
-        $this->add_error(esc_html__('Reattempt migration', 'event_espresso'), true);
296
-    }
297
-
298
-    /**
299
-     * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
300
-     * properties to the DB. However, we don't want to use __sleep() because its quite
301
-     * possible that this class is defined when it goes to sleep, but NOT available when it
302
-     * awakes (eg, this class is part of an addon that is deactivated at some point).
303
-     */
304
-    public function properties_as_array()
305
-    {
306
-        $properties = get_object_vars($this);
307
-        $properties['class'] = get_class($this);
308
-        unset($properties['_migration_script']);
309
-        unset($properties['_table_manager']);
310
-        unset($properties['_table_analysis']);
311
-        return $properties;
312
-    }
313
-
314
-    /**
315
-     * Sets all of the properties of this script stage to match what's in the array, which is assumed
316
-     * to have been made from the properties_as_array() function.
317
-     *
318
-     * @param array $array_of_properties like what's produced from properties_as_array() method
319
-     */
320
-    abstract public function instantiate_from_array_of_properties($array_of_properties);
321
-
322
-    /**
323
-     * Convenience method for showing a database insertion error
324
-     *
325
-     * @param string $old_table
326
-     * @param array  $old_row_as_array
327
-     * @param string $new_table
328
-     * @param array  $new_row_as_array columns=>values like used in wpdb->insert
329
-     * @param array  $data_types       numerically indexed
330
-     * @return string
331
-     */
332
-    protected function _create_error_message_for_db_insertion(
333
-        $old_table,
334
-        $old_row_as_array,
335
-        $new_table,
336
-        $new_row_as_array,
337
-        $data_types
338
-    ) {
339
-        global $wpdb;
340
-        $old_columns_and_values_for_string = array();
341
-        foreach ($old_row_as_array as $column => $value) {
342
-            $old_columns_and_values_for_string[] = "$column => $value";
343
-        }
344
-        $new_columns_and_values_for_string = array();
345
-        $count = 0;
346
-        foreach ($new_row_as_array as $column => $value) {
347
-            $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
348
-        }
349
-        return sprintf(
350
-            esc_html__(
351
-                'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
352
-                'event_espresso'
353
-            ),
354
-            implode(", ", $new_columns_and_values_for_string),
355
-            $new_table,
356
-            implode(", ", $old_columns_and_values_for_string),
357
-            $old_table,
358
-            '<br/>',
359
-            $wpdb->last_error
360
-        );
361
-    }
362
-
363
-
364
-    /**
365
-     * Same as json_encode, just avoids putting
366
-     * serialized arrays into the http build query, as that would
367
-     *
368
-     * @param array $array_of_data
369
-     * @return string
370
-     */
371
-    protected function _json_encode($array_of_data)
372
-    {
373
-        // we'd rather NOT serialize the transaction details
374
-        $fields_to_include = array();
375
-        foreach ($array_of_data as $name => $value) {
376
-            $unserialized_data = @unserialize($value);
377
-            if ($unserialized_data === false) {
378
-                $fields_to_include[ $name ] = $value;
379
-            }
380
-        }
381
-        return wp_json_encode($fields_to_include);
382
-    }
383
-
384
-    /**
385
-     * Gets the table manager (or throws an exception if it cannot be retrieved)
386
-     *
387
-     * @return TableManager
388
-     * @throws EE_Error
389
-     */
390
-    protected function _get_table_manager()
391
-    {
392
-        if ($this->_table_manager instanceof TableManager) {
393
-            return $this->_table_manager;
394
-        } else {
395
-            throw new EE_Error(
396
-                sprintf(
397
-                    esc_html__('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
398
-                    get_class($this)
399
-                )
400
-            );
401
-        }
402
-    }
403
-
404
-    /**
405
-     * Gets the injected table analyzer, or throws an exception
406
-     *
407
-     * @return TableAnalysis
408
-     * @throws EE_Error
409
-     */
410
-    protected function _get_table_analysis()
411
-    {
412
-        if ($this->_table_analysis instanceof TableAnalysis) {
413
-            return $this->_table_analysis;
414
-        } else {
415
-            throw new EE_Error(
416
-                sprintf(
417
-                    esc_html__('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
418
-                    get_class($this)
419
-                )
420
-            );
421
-        }
422
-    }
19
+	/**
20
+	 * @var $records_to_migrate int count of all that have been migrated
21
+	 */
22
+	protected $_records_to_migrate = 0;
23
+
24
+	/**
25
+	 *
26
+	 * @var $records_migrated int
27
+	 */
28
+	protected $_records_migrated = 0;
29
+
30
+	/**
31
+	 * Whether this migration script is done or not. This COULD be deduced by
32
+	 * _records_to_migrate and _records_migrated, but that might nto be accurate
33
+	 *
34
+	 * @var string one of EE_Data_migration_Manager::status_* constants
35
+	 */
36
+	protected $_status = null;
37
+
38
+	/**
39
+	 * internationalized name of this class. Convention is to NOT restate that
40
+	 * this class if a migration script or a migration script stage
41
+	 *
42
+	 * @var string (i18ned)
43
+	 */
44
+	protected $_pretty_name = null;
45
+
46
+	/**
47
+	 * @var array
48
+	 */
49
+	protected $_errors = array();
50
+
51
+	/**
52
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
53
+	 */
54
+	protected $_table_manager;
55
+
56
+	/**
57
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
58
+	 */
59
+	protected $_table_analysis;
60
+
61
+
62
+	/**
63
+	 * Just initializes the status of the migration
64
+	 *
65
+	 * @param TableManager  $table_manager
66
+	 * @param TableAnalysis $table_analysis
67
+	 */
68
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
69
+	{
70
+		$this->_table_manager = $table_manager;
71
+		$this->_table_analysis = $table_analysis;
72
+		$this->set_status(EE_Data_Migration_Manager::status_continue);
73
+	}
74
+
75
+
76
+	/**
77
+	 * Just gets the pretty name for this migration script or stage
78
+	 *
79
+	 * @throws EE_Error
80
+	 * @return string
81
+	 */
82
+	public function pretty_name()
83
+	{
84
+		if ($this->_pretty_name === null) {
85
+			throw new EE_Error(
86
+				sprintf(
87
+					esc_html__(
88
+						"Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor",
89
+						"event_espresso"
90
+					),
91
+					get_class($this)
92
+				)
93
+			);
94
+		}
95
+		return $this->_pretty_name;
96
+	}
97
+
98
+	/**
99
+	 *
100
+	 * @return int
101
+	 */
102
+	public function count_records_to_migrate()
103
+	{
104
+		if ($this->_records_to_migrate == null) {
105
+			$this->_records_to_migrate = $this->_count_records_to_migrate();
106
+		}
107
+		return $this->_records_to_migrate;
108
+	}
109
+
110
+	/**
111
+	 * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and
112
+	 * EE_Data_migration_Script_Stage
113
+	 *
114
+	 * @return int
115
+	 */
116
+	abstract public function count_records_migrated();
117
+
118
+	/**
119
+	 * Counts the records to migrate; the public version may cache it
120
+	 *
121
+	 * @return int
122
+	 */
123
+	abstract protected function _count_records_to_migrate();
124
+
125
+	/**
126
+	 * Returns a string indicating the migration script's status.
127
+	 *
128
+	 * @return string one of EE_Data_Migration_Manager::status_* constants
129
+	 * @throws EE_Error
130
+	 */
131
+	public function get_status()
132
+	{
133
+		if ($this->_status === null) {
134
+			throw new EE_Error(
135
+				sprintf(
136
+					esc_html__(
137
+						"Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.",
138
+						"event_espresso"
139
+					),
140
+					get_class($this)
141
+				)
142
+			);
143
+		}
144
+		return $this->_status;
145
+	}
146
+
147
+	/**
148
+	 *
149
+	 * @param string $status
150
+	 * @return void
151
+	 */
152
+	protected function set_status($status)
153
+	{
154
+		$this->_status = $status;
155
+	}
156
+
157
+	/**
158
+	 * @return array of strings
159
+	 */
160
+	abstract public function get_errors();
161
+
162
+	/**
163
+	 * Returns the last error that occurred. If none occurred, returns null
164
+	 *
165
+	 * @return string
166
+	 */
167
+	public function get_last_error()
168
+	{
169
+		$errors = $this->get_errors();
170
+		if ($errors) {
171
+			return end($errors);
172
+		} else {
173
+			return null;
174
+		}
175
+	}
176
+
177
+	/**
178
+	 * Adds an error to the array of errors on this class.
179
+	 *
180
+	 * @param string  $error a string describing the error that will be useful for debugging. Consider including all
181
+	 *                       the data that led to the error, and a stack trace etc.
182
+	 * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are
183
+	 *                       already at their limit, we will purposefully forget the first half
184
+	 */
185
+	public function add_error($error, $force = false)
186
+	{
187
+		if (! defined('EE_DMS_ERROR_LIMIT')) {
188
+			$limit = 50;
189
+		} else {
190
+			$limit = EE_DMS_ERROR_LIMIT;
191
+		}
192
+		// make sure errors is an array, see ticket #8261
193
+		if (is_string($this->_errors)) {
194
+			$this->_errors = array($this->_errors);
195
+		}
196
+		if (count($this->_errors) >= $limit) {
197
+			if ($force) {
198
+				// get rid of the first half of the errors and any above the limit
199
+				$this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2);
200
+				$this->_errors[] = "Limit reached; removed first half of errors to save space";
201
+				$this->_errors[] = $error;
202
+			} else {
203
+				$this->_errors[ $limit ] = 'More, but limit reached...';
204
+			}
205
+		} else {
206
+			$this->_errors[] = $error;
207
+		}
208
+	}
209
+
210
+	/**
211
+	 * Indicates there was a fatal error and the migration cannot possibly continue
212
+	 *
213
+	 * @return boolean
214
+	 */
215
+	public function is_broken()
216
+	{
217
+		return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error;
218
+	}
219
+
220
+	/**
221
+	 * @deprecated since 4.6.12
222
+	 */
223
+	public function is_borked()
224
+	{
225
+		EE_Error::doing_it_wrong(
226
+			'is_borked',
227
+			esc_html__(
228
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
229
+				'event_espresso'
230
+			),
231
+			'4.6.12'
232
+		);
233
+		return $this->is_broken();
234
+	}
235
+
236
+	/**
237
+	 * Sets the status to as having a fatal error
238
+	 */
239
+	public function set_broken()
240
+	{
241
+		$this->_status = EE_Data_Migration_Manager::status_fatal_error;
242
+	}
243
+
244
+	/**
245
+	 *
246
+	 * @deprecated since 4.6.12
247
+	 */
248
+	public function set_borked()
249
+	{
250
+		EE_Error::doing_it_wrong(
251
+			'is_borked',
252
+			esc_html__(
253
+				'The cheeky "is_borked" method had been replaced with the more proper "is_broken"',
254
+				'event_espresso'
255
+			),
256
+			'4.6.12'
257
+		);
258
+		return $this->set_broken();
259
+	}
260
+
261
+	/**
262
+	 * Checks if this thing believes it is completed
263
+	 *
264
+	 * @return boolean
265
+	 */
266
+	public function is_completed()
267
+	{
268
+		return $this->get_status() == EE_Data_Migration_Manager::status_completed;
269
+	}
270
+
271
+	/**
272
+	 * Checks if the current script has more to do or not (ie, if it's status is CONTINUE)
273
+	 *
274
+	 * @return boolean
275
+	 */
276
+	public function has_more_to_do()
277
+	{
278
+		return $this->get_status() == EE_Data_Migration_Manager::status_continue;
279
+	}
280
+
281
+	/**
282
+	 * Marks that we believe this migration thing is completed
283
+	 */
284
+	public function set_completed()
285
+	{
286
+		$this->_status = EE_Data_Migration_Manager::status_completed;
287
+	}
288
+
289
+	/**
290
+	 * Marks that we think this migration class can continue to migrate
291
+	 */
292
+	public function reattempt()
293
+	{
294
+		$this->_status = EE_Data_Migration_Manager::status_continue;
295
+		$this->add_error(esc_html__('Reattempt migration', 'event_espresso'), true);
296
+	}
297
+
298
+	/**
299
+	 * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class'
300
+	 * properties to the DB. However, we don't want to use __sleep() because its quite
301
+	 * possible that this class is defined when it goes to sleep, but NOT available when it
302
+	 * awakes (eg, this class is part of an addon that is deactivated at some point).
303
+	 */
304
+	public function properties_as_array()
305
+	{
306
+		$properties = get_object_vars($this);
307
+		$properties['class'] = get_class($this);
308
+		unset($properties['_migration_script']);
309
+		unset($properties['_table_manager']);
310
+		unset($properties['_table_analysis']);
311
+		return $properties;
312
+	}
313
+
314
+	/**
315
+	 * Sets all of the properties of this script stage to match what's in the array, which is assumed
316
+	 * to have been made from the properties_as_array() function.
317
+	 *
318
+	 * @param array $array_of_properties like what's produced from properties_as_array() method
319
+	 */
320
+	abstract public function instantiate_from_array_of_properties($array_of_properties);
321
+
322
+	/**
323
+	 * Convenience method for showing a database insertion error
324
+	 *
325
+	 * @param string $old_table
326
+	 * @param array  $old_row_as_array
327
+	 * @param string $new_table
328
+	 * @param array  $new_row_as_array columns=>values like used in wpdb->insert
329
+	 * @param array  $data_types       numerically indexed
330
+	 * @return string
331
+	 */
332
+	protected function _create_error_message_for_db_insertion(
333
+		$old_table,
334
+		$old_row_as_array,
335
+		$new_table,
336
+		$new_row_as_array,
337
+		$data_types
338
+	) {
339
+		global $wpdb;
340
+		$old_columns_and_values_for_string = array();
341
+		foreach ($old_row_as_array as $column => $value) {
342
+			$old_columns_and_values_for_string[] = "$column => $value";
343
+		}
344
+		$new_columns_and_values_for_string = array();
345
+		$count = 0;
346
+		foreach ($new_row_as_array as $column => $value) {
347
+			$new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")";
348
+		}
349
+		return sprintf(
350
+			esc_html__(
351
+				'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.',
352
+				'event_espresso'
353
+			),
354
+			implode(", ", $new_columns_and_values_for_string),
355
+			$new_table,
356
+			implode(", ", $old_columns_and_values_for_string),
357
+			$old_table,
358
+			'<br/>',
359
+			$wpdb->last_error
360
+		);
361
+	}
362
+
363
+
364
+	/**
365
+	 * Same as json_encode, just avoids putting
366
+	 * serialized arrays into the http build query, as that would
367
+	 *
368
+	 * @param array $array_of_data
369
+	 * @return string
370
+	 */
371
+	protected function _json_encode($array_of_data)
372
+	{
373
+		// we'd rather NOT serialize the transaction details
374
+		$fields_to_include = array();
375
+		foreach ($array_of_data as $name => $value) {
376
+			$unserialized_data = @unserialize($value);
377
+			if ($unserialized_data === false) {
378
+				$fields_to_include[ $name ] = $value;
379
+			}
380
+		}
381
+		return wp_json_encode($fields_to_include);
382
+	}
383
+
384
+	/**
385
+	 * Gets the table manager (or throws an exception if it cannot be retrieved)
386
+	 *
387
+	 * @return TableManager
388
+	 * @throws EE_Error
389
+	 */
390
+	protected function _get_table_manager()
391
+	{
392
+		if ($this->_table_manager instanceof TableManager) {
393
+			return $this->_table_manager;
394
+		} else {
395
+			throw new EE_Error(
396
+				sprintf(
397
+					esc_html__('Table manager on migration class %1$s is not set properly.', 'event_espresso'),
398
+					get_class($this)
399
+				)
400
+			);
401
+		}
402
+	}
403
+
404
+	/**
405
+	 * Gets the injected table analyzer, or throws an exception
406
+	 *
407
+	 * @return TableAnalysis
408
+	 * @throws EE_Error
409
+	 */
410
+	protected function _get_table_analysis()
411
+	{
412
+		if ($this->_table_analysis instanceof TableAnalysis) {
413
+			return $this->_table_analysis;
414
+		} else {
415
+			throw new EE_Error(
416
+				sprintf(
417
+					esc_html__('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'),
418
+					get_class($this)
419
+				)
420
+			);
421
+		}
422
+	}
423 423
 }
Please login to merge, or discard this patch.