@@ -11,592 +11,592 @@ |
||
11 | 11 | class EEG_Paypal_Pro extends EE_Onsite_Gateway |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @var $_paypal_api_username string |
|
16 | - */ |
|
17 | - protected $_username = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var $_password string |
|
21 | - */ |
|
22 | - protected $_password = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var $_signature string |
|
26 | - */ |
|
27 | - protected $_signature = null; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | - */ |
|
32 | - protected $_credit_card_types = null; |
|
33 | - |
|
34 | - protected $_currencies_supported = array( |
|
35 | - 'USD', |
|
36 | - 'GBP', |
|
37 | - 'CAD', |
|
38 | - 'AUD', |
|
39 | - 'BRL', |
|
40 | - 'CHF', |
|
41 | - 'CZK', |
|
42 | - 'DKK', |
|
43 | - 'EUR', |
|
44 | - 'HKD', |
|
45 | - 'HUF', |
|
46 | - 'ILS', |
|
47 | - 'JPY', |
|
48 | - 'MXN', |
|
49 | - 'MYR', |
|
50 | - 'NOK', |
|
51 | - 'NZD', |
|
52 | - 'PHP', |
|
53 | - 'PLN', |
|
54 | - 'SEK', |
|
55 | - 'SGD', |
|
56 | - 'THB', |
|
57 | - 'TRY', |
|
58 | - 'TWD', |
|
59 | - 'RUB', |
|
60 | - 'INR', |
|
61 | - ); |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param EEI_Payment $payment |
|
67 | - * @param array $billing_info { |
|
68 | - * @type string $credit_card |
|
69 | - * @type string $credit_card_type |
|
70 | - * @type string $exp_month always 2 characters |
|
71 | - * @type string $exp_year always 4 characters |
|
72 | - * @type string $cvv |
|
73 | - * } |
|
74 | - * @see parent::do_direct_payment for more info |
|
75 | - * @return EE_Payment|EEI_Payment |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public function do_direct_payment($payment, $billing_info = null) |
|
79 | - { |
|
80 | - $transaction = $payment->transaction(); |
|
81 | - if (! $transaction instanceof EEI_Transaction) { |
|
82 | - throw new EE_Error( |
|
83 | - esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | - ); |
|
85 | - } |
|
86 | - $primary_registrant = $transaction->primary_registration(); |
|
87 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | - throw new EE_Error( |
|
89 | - esc_html__( |
|
90 | - 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | - 'event_espresso' |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - $attendee = $primary_registrant->attendee(); |
|
96 | - if (! $attendee instanceof EEI_Attendee) { |
|
97 | - throw new EE_Error( |
|
98 | - esc_html__( |
|
99 | - 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | - 'event_espresso' |
|
101 | - ) |
|
102 | - ); |
|
103 | - } |
|
104 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | - $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | - // charge for the full amount. Show itemized list |
|
107 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
108 | - $item_num = 1; |
|
109 | - $total_line_item = $transaction->total_line_item(); |
|
110 | - $order_items = array(); |
|
111 | - foreach ($total_line_item->get_items() as $line_item) { |
|
112 | - // ignore line items with a quantity of 0 |
|
113 | - if ($line_item->quantity() == 0) { |
|
114 | - continue; |
|
115 | - } |
|
116 | - $item = array( |
|
117 | - // Item Name. 127 char max. |
|
118 | - 'l_name' => substr( |
|
119 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
120 | - 0, |
|
121 | - 127 |
|
122 | - ), |
|
123 | - // Item description. 127 char max. |
|
124 | - 'l_desc' => substr( |
|
125 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
126 | - 0, |
|
127 | - 127 |
|
128 | - ), |
|
129 | - // Cost of individual item. |
|
130 | - 'l_amt' => $line_item->unit_price(), |
|
131 | - // Item Number. 127 char max. |
|
132 | - 'l_number' => $item_num++, |
|
133 | - // Item quantity. Must be any positive integer. |
|
134 | - 'l_qty' => $line_item->quantity(), |
|
135 | - // Item's sales tax amount. |
|
136 | - 'l_taxamt' => '', |
|
137 | - // eBay auction number of item. |
|
138 | - 'l_ebayitemnumber' => '', |
|
139 | - // eBay transaction ID of purchased item. |
|
140 | - 'l_ebayitemauctiontxnid' => '', |
|
141 | - // eBay order ID for the item. |
|
142 | - 'l_ebayitemorderid' => '', |
|
143 | - ); |
|
144 | - // add to array of all items |
|
145 | - array_push($order_items, $item); |
|
146 | - } |
|
147 | - $item_amount = $total_line_item->get_items_total(); |
|
148 | - $tax_amount = $total_line_item->get_total_tax(); |
|
149 | - } else { |
|
150 | - $order_items = array(); |
|
151 | - $item_amount = $payment->amount(); |
|
152 | - $tax_amount = 0; |
|
153 | - array_push($order_items, array( |
|
154 | - // Item Name. 127 char max. |
|
155 | - 'l_name' => substr( |
|
156 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
157 | - 0, |
|
158 | - 127 |
|
159 | - ), |
|
160 | - // Item description. 127 char max. |
|
161 | - 'l_desc' => substr( |
|
162 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
163 | - 0, |
|
164 | - 127 |
|
165 | - ), |
|
166 | - // Cost of individual item. |
|
167 | - 'l_amt' => $payment->amount(), |
|
168 | - // Item Number. 127 char max. |
|
169 | - 'l_number' => 1, |
|
170 | - // Item quantity. Must be any positive integer. |
|
171 | - 'l_qty' => 1, |
|
172 | - )); |
|
173 | - } |
|
174 | - // Populate data arrays with order data. |
|
175 | - $DPFields = array( |
|
176 | - // How you want to obtain payment ? |
|
177 | - // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
178 | - // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
179 | - 'paymentaction' => 'Sale', |
|
180 | - // Required. IP address of the payer's browser. |
|
181 | - 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
182 | - // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
183 | - 'returnfmfdetails' => '1', |
|
184 | - ); |
|
185 | - $CCDetails = array( |
|
186 | - // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
187 | - // If Maestro or Solo, the currency code must be GBP. |
|
188 | - // In addition, either start date or issue number must be specified. |
|
189 | - 'creditcardtype' => $billing_info['credit_card_type'], |
|
190 | - // Required. Credit card number. No spaces or punctuation. |
|
191 | - 'acct' => $billing_info['credit_card'], |
|
192 | - // Required. Credit card expiration date. Format is MMYYYY |
|
193 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
194 | - // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
195 | - 'cvv2' => $billing_info['cvv'], |
|
196 | - ); |
|
197 | - $PayerInfo = array( |
|
198 | - // Email address of payer. |
|
199 | - 'email' => $billing_info['email'], |
|
200 | - // Unique PayPal customer ID for payer. |
|
201 | - 'payerid' => '', |
|
202 | - // Status of payer. Values are verified or unverified |
|
203 | - 'payerstatus' => '', |
|
204 | - // Payer's business name. |
|
205 | - 'business' => '', |
|
206 | - ); |
|
207 | - $PayerName = array( |
|
208 | - // Payer's salutation. 20 char max. |
|
209 | - 'salutation' => '', |
|
210 | - // Payer's first name. 25 char max. |
|
211 | - 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
212 | - // Payer's middle name. 25 char max. |
|
213 | - 'middlename' => '', |
|
214 | - // Payer's last name. 25 char max. |
|
215 | - 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
216 | - // Payer's suffix. 12 char max. |
|
217 | - 'suffix' => '', |
|
218 | - ); |
|
219 | - $BillingAddress = array( |
|
220 | - // Required. First street address. |
|
221 | - 'street' => $billing_info['address'], |
|
222 | - // Second street address. |
|
223 | - 'street2' => $billing_info['address2'], |
|
224 | - // Required. Name of City. |
|
225 | - 'city' => $billing_info['city'], |
|
226 | - // Required. Name of State or Province. |
|
227 | - 'state' => substr($billing_info['state'], 0, 40), |
|
228 | - // Required. Country code. |
|
229 | - 'countrycode' => $billing_info['country'], |
|
230 | - // Required. Postal code of payer. |
|
231 | - 'zip' => $billing_info['zip'], |
|
232 | - ); |
|
233 | - // check if the registration info contains the needed fields for paypal pro |
|
234 | - // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
235 | - if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
236 | - $use_registration_address_info = true; |
|
237 | - } else { |
|
238 | - $use_registration_address_info = false; |
|
239 | - } |
|
240 | - // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
241 | - // If not, use the billing info again |
|
242 | - $ShippingAddress = array( |
|
243 | - 'shiptoname' => substr($use_registration_address_info |
|
244 | - ? $attendee->full_name() |
|
245 | - : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
246 | - 'shiptostreet' => substr($use_registration_address_info |
|
247 | - ? $attendee->address() |
|
248 | - : $billing_info['address'], 0, 100), |
|
249 | - 'shiptostreet2' => substr($use_registration_address_info |
|
250 | - ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
251 | - 'shiptocity' => substr($use_registration_address_info |
|
252 | - ? $attendee->city() |
|
253 | - : $billing_info['city'], 0, 40), |
|
254 | - 'state' => substr($use_registration_address_info |
|
255 | - ? $attendee->state_name() |
|
256 | - : $billing_info['state'], 0, 40), |
|
257 | - 'shiptocountry' => $use_registration_address_info |
|
258 | - ? $attendee->country_ID() |
|
259 | - : $billing_info['country'], |
|
260 | - 'shiptozip' => substr($use_registration_address_info |
|
261 | - ? $attendee->zip() |
|
262 | - : $billing_info['zip'], 0, 20), |
|
263 | - 'shiptophonenum' => substr($use_registration_address_info |
|
264 | - ? $attendee->phone() |
|
265 | - : $billing_info['phone'], 0, 20), |
|
266 | - ); |
|
267 | - $PaymentDetails = array( |
|
268 | - // Required. Total amount of order, including shipping, handling, and tax. |
|
269 | - 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
270 | - // Required. Three-letter currency code. Default is USD. |
|
271 | - 'currencycode' => $payment->currency_code(), |
|
272 | - // Required if you include itemized cart details. (L_AMTn, etc.) |
|
273 | - // Subtotal of items not including S&H, or tax. |
|
274 | - 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
275 | - // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
276 | - 'shippingamt' => '', |
|
277 | - // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
278 | - 'handlingamt' => '', |
|
279 | - // Required if you specify itemized cart tax details. |
|
280 | - // Sum of tax for all items on the order. Total sales tax. |
|
281 | - 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
282 | - // Description of the order the customer is purchasing. 127 char max. |
|
283 | - 'desc' => $order_description, |
|
284 | - // Free-form field for your own use. 256 char max. |
|
285 | - 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
286 | - // Your own invoice or tracking number |
|
287 | - 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
288 | - // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
289 | - 'notifyurl' => '', |
|
290 | - 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
291 | - ); |
|
292 | - // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
293 | - $PayPalRequestData = array( |
|
294 | - 'DPFields' => $DPFields, |
|
295 | - 'CCDetails' => $CCDetails, |
|
296 | - 'PayerInfo' => $PayerInfo, |
|
297 | - 'PayerName' => $PayerName, |
|
298 | - 'BillingAddress' => $BillingAddress, |
|
299 | - 'ShippingAddress' => $ShippingAddress, |
|
300 | - 'PaymentDetails' => $PaymentDetails, |
|
301 | - 'OrderItems' => $order_items, |
|
302 | - ); |
|
303 | - $this->_log_clean_request($PayPalRequestData, $payment); |
|
304 | - try { |
|
305 | - $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
306 | - // remove PCI-sensitive data so it doesn't get stored |
|
307 | - $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
308 | - $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK']; |
|
309 | - if (empty($PayPalResult['RAWRESPONSE'])) { |
|
310 | - $payment->set_status($this->_pay_model->failed_status()); |
|
311 | - $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
312 | - $payment->set_details($PayPalResult); |
|
313 | - } else { |
|
314 | - if ($this->_APICallSuccessful($PayPalResult)) { |
|
315 | - $payment->set_status($this->_pay_model->approved_status()); |
|
316 | - } else { |
|
317 | - $payment->set_status($this->_pay_model->declined_status()); |
|
318 | - } |
|
319 | - // make sure we interpret the AMT as a float, not an international string |
|
320 | - // (where periods are thousand separators) |
|
321 | - $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
322 | - $payment->set_gateway_response($message); |
|
323 | - $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
324 | - ? $PayPalResult['TRANSACTIONID'] |
|
325 | - : null); |
|
326 | - $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
327 | - ? $primary_registrant->reg_code() |
|
328 | - : ''; |
|
329 | - $payment->set_extra_accntng($primary_registration_code); |
|
330 | - $payment->set_details($PayPalResult); |
|
331 | - } |
|
332 | - } catch (Exception $e) { |
|
333 | - $payment->set_status($this->_pay_model->failed_status()); |
|
334 | - $payment->set_gateway_response($e->getMessage()); |
|
335 | - } |
|
336 | - // $payment->set_status( $this->_pay_model->declined_status() ); |
|
337 | - // $payment->set_gateway_response( '' ); |
|
338 | - return $payment; |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
345 | - * |
|
346 | - * @param array $request |
|
347 | - * @param EEI_Payment $payment |
|
348 | - * @return void |
|
349 | - */ |
|
350 | - private function _log_clean_request($request, $payment) |
|
351 | - { |
|
352 | - $cleaned_request_data = $request; |
|
353 | - unset($cleaned_request_data['CCDetails']['acct']); |
|
354 | - unset($cleaned_request_data['CCDetails']['cvv2']); |
|
355 | - unset($cleaned_request_data['CCDetails']['expdate']); |
|
356 | - $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Cleans the response, logs it, and returns it |
|
363 | - * |
|
364 | - * @param array $response |
|
365 | - * @param EEI_Payment $payment |
|
366 | - * @return array cleaned |
|
367 | - */ |
|
368 | - private function _log_clean_response($response, $payment) |
|
369 | - { |
|
370 | - unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
371 | - unset($response['REQUESTDATA']['ACCT']); |
|
372 | - unset($response['REQUESTDATA']['EXPDATE']); |
|
373 | - unset($response['REQUESTDATA']['CVV2']); |
|
374 | - unset($response['RAWREQUEST']); |
|
375 | - $this->log(array('Paypal Response' => $response), $payment); |
|
376 | - return $response; |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * @param $DataArray |
|
383 | - * @return array |
|
384 | - */ |
|
385 | - private function prep_and_curl_request($DataArray) |
|
386 | - { |
|
387 | - // Create empty holders for each portion of the NVP string |
|
388 | - $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
389 | - $CCDetailsNVP = ''; |
|
390 | - $PayerInfoNVP = ''; |
|
391 | - $PayerNameNVP = ''; |
|
392 | - $BillingAddressNVP = ''; |
|
393 | - $ShippingAddressNVP = ''; |
|
394 | - $PaymentDetailsNVP = ''; |
|
395 | - $OrderItemsNVP = ''; |
|
396 | - $Secure3DNVP = ''; |
|
397 | - // DP Fields |
|
398 | - $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
399 | - foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
400 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
401 | - } |
|
402 | - // CC Details Fields |
|
403 | - $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
404 | - foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
405 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
406 | - } |
|
407 | - // PayerInfo Type Fields |
|
408 | - $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
409 | - foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
410 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
411 | - } |
|
412 | - // Payer Name Fields |
|
413 | - $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
414 | - foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
415 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
416 | - } |
|
417 | - // Address Fields (Billing) |
|
418 | - $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
419 | - foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
420 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
421 | - } |
|
422 | - // Payment Details Type Fields |
|
423 | - $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
424 | - foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
425 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
426 | - } |
|
427 | - // Payment Details Item Type Fields |
|
428 | - $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
429 | - $n = 0; |
|
430 | - foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
431 | - $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
432 | - foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
433 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
434 | - } |
|
435 | - $n++; |
|
436 | - } |
|
437 | - // Ship To Address Fields |
|
438 | - $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
439 | - foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
440 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
441 | - } |
|
442 | - // 3D Secure Fields |
|
443 | - $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
444 | - foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
445 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
446 | - } |
|
447 | - // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
448 | - $NVPRequest = 'USER=' |
|
449 | - . $this->_username |
|
450 | - . '&PWD=' |
|
451 | - . $this->_password |
|
452 | - . '&VERSION=64.0' |
|
453 | - . '&SIGNATURE=' |
|
454 | - . $this->_signature |
|
455 | - . $DPFieldsNVP |
|
456 | - . $CCDetailsNVP |
|
457 | - . $PayerInfoNVP |
|
458 | - . $PayerNameNVP |
|
459 | - . $BillingAddressNVP |
|
460 | - . $PaymentDetailsNVP |
|
461 | - . $OrderItemsNVP |
|
462 | - . $ShippingAddressNVP |
|
463 | - . $Secure3DNVP; |
|
464 | - $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
465 | - $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
466 | - $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
467 | - $Errors = $this->_GetErrors($NVPResponseArray); |
|
468 | - $NVPResponseArray['ERRORS'] = $Errors; |
|
469 | - $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
470 | - $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
471 | - $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
472 | - return $NVPResponseArray; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * @param $Request |
|
479 | - * @return mixed |
|
480 | - */ |
|
481 | - private function _CURLRequest($Request) |
|
482 | - { |
|
483 | - $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
484 | - $curl = curl_init(); |
|
485 | - curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
486 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
487 | - curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
488 | - curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
489 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
490 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
491 | - curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
492 | - // execute the curl POST |
|
493 | - $Response = curl_exec($curl); |
|
494 | - curl_close($curl); |
|
495 | - return $Response; |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @param $NVPString |
|
502 | - * @return array |
|
503 | - */ |
|
504 | - private function _NVPToArray($NVPString) |
|
505 | - { |
|
506 | - // prepare responses into array |
|
507 | - $proArray = array(); |
|
508 | - while (strlen($NVPString)) { |
|
509 | - // name |
|
510 | - $keypos = strpos($NVPString, '='); |
|
511 | - $keyval = substr($NVPString, 0, $keypos); |
|
512 | - // value |
|
513 | - $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
514 | - $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
515 | - // decoding the response |
|
516 | - $proArray[ $keyval ] = urldecode($valval); |
|
517 | - $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
518 | - } |
|
519 | - return $proArray; |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * @param array $PayPalResult |
|
526 | - * @return bool |
|
527 | - */ |
|
528 | - private function _APICallSuccessful($PayPalResult) |
|
529 | - { |
|
530 | - $approved = false; |
|
531 | - // check main response message from PayPal |
|
532 | - if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
533 | - $ack = strtoupper($PayPalResult['ACK']); |
|
534 | - $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
535 | - } |
|
536 | - return $approved; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @param $DataArray |
|
543 | - * @return array |
|
544 | - */ |
|
545 | - private function _GetErrors($DataArray) |
|
546 | - { |
|
547 | - $Errors = array(); |
|
548 | - $n = 0; |
|
549 | - while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
550 | - $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
551 | - $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
552 | - ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
553 | - : ''; |
|
554 | - $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
555 | - ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
556 | - : ''; |
|
557 | - $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
558 | - ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
559 | - : ''; |
|
560 | - $CurrentItem = array( |
|
561 | - 'L_ERRORCODE' => $LErrorCode, |
|
562 | - 'L_SHORTMESSAGE' => $LShortMessage, |
|
563 | - 'L_LONGMESSAGE' => $LLongMessage, |
|
564 | - 'L_SEVERITYCODE' => $LSeverityCode, |
|
565 | - ); |
|
566 | - array_push($Errors, $CurrentItem); |
|
567 | - $n++; |
|
568 | - } |
|
569 | - return $Errors; |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - |
|
574 | - /** |
|
575 | - * nothing to see here... move along.... |
|
576 | - * |
|
577 | - * @access protected |
|
578 | - * @param $Errors |
|
579 | - * @return string |
|
580 | - */ |
|
581 | - private function _DisplayErrors($Errors) |
|
582 | - { |
|
583 | - $error = ''; |
|
584 | - foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
585 | - $CurrentError = $Errors[ $ErrorVar ]; |
|
586 | - foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
587 | - $CurrentVarName = ''; |
|
588 | - if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
589 | - $CurrentVarName = 'Error Code'; |
|
590 | - } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
591 | - $CurrentVarName = 'Short Message'; |
|
592 | - } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
593 | - $CurrentVarName = 'Long Message'; |
|
594 | - } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
595 | - $CurrentVarName = 'Severity Code'; |
|
596 | - } |
|
597 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
598 | - } |
|
599 | - } |
|
600 | - return $error; |
|
601 | - } |
|
14 | + /** |
|
15 | + * @var $_paypal_api_username string |
|
16 | + */ |
|
17 | + protected $_username = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var $_password string |
|
21 | + */ |
|
22 | + protected $_password = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var $_signature string |
|
26 | + */ |
|
27 | + protected $_signature = null; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | + */ |
|
32 | + protected $_credit_card_types = null; |
|
33 | + |
|
34 | + protected $_currencies_supported = array( |
|
35 | + 'USD', |
|
36 | + 'GBP', |
|
37 | + 'CAD', |
|
38 | + 'AUD', |
|
39 | + 'BRL', |
|
40 | + 'CHF', |
|
41 | + 'CZK', |
|
42 | + 'DKK', |
|
43 | + 'EUR', |
|
44 | + 'HKD', |
|
45 | + 'HUF', |
|
46 | + 'ILS', |
|
47 | + 'JPY', |
|
48 | + 'MXN', |
|
49 | + 'MYR', |
|
50 | + 'NOK', |
|
51 | + 'NZD', |
|
52 | + 'PHP', |
|
53 | + 'PLN', |
|
54 | + 'SEK', |
|
55 | + 'SGD', |
|
56 | + 'THB', |
|
57 | + 'TRY', |
|
58 | + 'TWD', |
|
59 | + 'RUB', |
|
60 | + 'INR', |
|
61 | + ); |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param EEI_Payment $payment |
|
67 | + * @param array $billing_info { |
|
68 | + * @type string $credit_card |
|
69 | + * @type string $credit_card_type |
|
70 | + * @type string $exp_month always 2 characters |
|
71 | + * @type string $exp_year always 4 characters |
|
72 | + * @type string $cvv |
|
73 | + * } |
|
74 | + * @see parent::do_direct_payment for more info |
|
75 | + * @return EE_Payment|EEI_Payment |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public function do_direct_payment($payment, $billing_info = null) |
|
79 | + { |
|
80 | + $transaction = $payment->transaction(); |
|
81 | + if (! $transaction instanceof EEI_Transaction) { |
|
82 | + throw new EE_Error( |
|
83 | + esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | + ); |
|
85 | + } |
|
86 | + $primary_registrant = $transaction->primary_registration(); |
|
87 | + if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | + throw new EE_Error( |
|
89 | + esc_html__( |
|
90 | + 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | + 'event_espresso' |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + $attendee = $primary_registrant->attendee(); |
|
96 | + if (! $attendee instanceof EEI_Attendee) { |
|
97 | + throw new EE_Error( |
|
98 | + esc_html__( |
|
99 | + 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | + 'event_espresso' |
|
101 | + ) |
|
102 | + ); |
|
103 | + } |
|
104 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | + $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | + // charge for the full amount. Show itemized list |
|
107 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
108 | + $item_num = 1; |
|
109 | + $total_line_item = $transaction->total_line_item(); |
|
110 | + $order_items = array(); |
|
111 | + foreach ($total_line_item->get_items() as $line_item) { |
|
112 | + // ignore line items with a quantity of 0 |
|
113 | + if ($line_item->quantity() == 0) { |
|
114 | + continue; |
|
115 | + } |
|
116 | + $item = array( |
|
117 | + // Item Name. 127 char max. |
|
118 | + 'l_name' => substr( |
|
119 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
120 | + 0, |
|
121 | + 127 |
|
122 | + ), |
|
123 | + // Item description. 127 char max. |
|
124 | + 'l_desc' => substr( |
|
125 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
126 | + 0, |
|
127 | + 127 |
|
128 | + ), |
|
129 | + // Cost of individual item. |
|
130 | + 'l_amt' => $line_item->unit_price(), |
|
131 | + // Item Number. 127 char max. |
|
132 | + 'l_number' => $item_num++, |
|
133 | + // Item quantity. Must be any positive integer. |
|
134 | + 'l_qty' => $line_item->quantity(), |
|
135 | + // Item's sales tax amount. |
|
136 | + 'l_taxamt' => '', |
|
137 | + // eBay auction number of item. |
|
138 | + 'l_ebayitemnumber' => '', |
|
139 | + // eBay transaction ID of purchased item. |
|
140 | + 'l_ebayitemauctiontxnid' => '', |
|
141 | + // eBay order ID for the item. |
|
142 | + 'l_ebayitemorderid' => '', |
|
143 | + ); |
|
144 | + // add to array of all items |
|
145 | + array_push($order_items, $item); |
|
146 | + } |
|
147 | + $item_amount = $total_line_item->get_items_total(); |
|
148 | + $tax_amount = $total_line_item->get_total_tax(); |
|
149 | + } else { |
|
150 | + $order_items = array(); |
|
151 | + $item_amount = $payment->amount(); |
|
152 | + $tax_amount = 0; |
|
153 | + array_push($order_items, array( |
|
154 | + // Item Name. 127 char max. |
|
155 | + 'l_name' => substr( |
|
156 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
157 | + 0, |
|
158 | + 127 |
|
159 | + ), |
|
160 | + // Item description. 127 char max. |
|
161 | + 'l_desc' => substr( |
|
162 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
163 | + 0, |
|
164 | + 127 |
|
165 | + ), |
|
166 | + // Cost of individual item. |
|
167 | + 'l_amt' => $payment->amount(), |
|
168 | + // Item Number. 127 char max. |
|
169 | + 'l_number' => 1, |
|
170 | + // Item quantity. Must be any positive integer. |
|
171 | + 'l_qty' => 1, |
|
172 | + )); |
|
173 | + } |
|
174 | + // Populate data arrays with order data. |
|
175 | + $DPFields = array( |
|
176 | + // How you want to obtain payment ? |
|
177 | + // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
178 | + // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
179 | + 'paymentaction' => 'Sale', |
|
180 | + // Required. IP address of the payer's browser. |
|
181 | + 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
182 | + // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
183 | + 'returnfmfdetails' => '1', |
|
184 | + ); |
|
185 | + $CCDetails = array( |
|
186 | + // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
187 | + // If Maestro or Solo, the currency code must be GBP. |
|
188 | + // In addition, either start date or issue number must be specified. |
|
189 | + 'creditcardtype' => $billing_info['credit_card_type'], |
|
190 | + // Required. Credit card number. No spaces or punctuation. |
|
191 | + 'acct' => $billing_info['credit_card'], |
|
192 | + // Required. Credit card expiration date. Format is MMYYYY |
|
193 | + 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
194 | + // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
195 | + 'cvv2' => $billing_info['cvv'], |
|
196 | + ); |
|
197 | + $PayerInfo = array( |
|
198 | + // Email address of payer. |
|
199 | + 'email' => $billing_info['email'], |
|
200 | + // Unique PayPal customer ID for payer. |
|
201 | + 'payerid' => '', |
|
202 | + // Status of payer. Values are verified or unverified |
|
203 | + 'payerstatus' => '', |
|
204 | + // Payer's business name. |
|
205 | + 'business' => '', |
|
206 | + ); |
|
207 | + $PayerName = array( |
|
208 | + // Payer's salutation. 20 char max. |
|
209 | + 'salutation' => '', |
|
210 | + // Payer's first name. 25 char max. |
|
211 | + 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
212 | + // Payer's middle name. 25 char max. |
|
213 | + 'middlename' => '', |
|
214 | + // Payer's last name. 25 char max. |
|
215 | + 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
216 | + // Payer's suffix. 12 char max. |
|
217 | + 'suffix' => '', |
|
218 | + ); |
|
219 | + $BillingAddress = array( |
|
220 | + // Required. First street address. |
|
221 | + 'street' => $billing_info['address'], |
|
222 | + // Second street address. |
|
223 | + 'street2' => $billing_info['address2'], |
|
224 | + // Required. Name of City. |
|
225 | + 'city' => $billing_info['city'], |
|
226 | + // Required. Name of State or Province. |
|
227 | + 'state' => substr($billing_info['state'], 0, 40), |
|
228 | + // Required. Country code. |
|
229 | + 'countrycode' => $billing_info['country'], |
|
230 | + // Required. Postal code of payer. |
|
231 | + 'zip' => $billing_info['zip'], |
|
232 | + ); |
|
233 | + // check if the registration info contains the needed fields for paypal pro |
|
234 | + // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
235 | + if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
236 | + $use_registration_address_info = true; |
|
237 | + } else { |
|
238 | + $use_registration_address_info = false; |
|
239 | + } |
|
240 | + // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
241 | + // If not, use the billing info again |
|
242 | + $ShippingAddress = array( |
|
243 | + 'shiptoname' => substr($use_registration_address_info |
|
244 | + ? $attendee->full_name() |
|
245 | + : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
246 | + 'shiptostreet' => substr($use_registration_address_info |
|
247 | + ? $attendee->address() |
|
248 | + : $billing_info['address'], 0, 100), |
|
249 | + 'shiptostreet2' => substr($use_registration_address_info |
|
250 | + ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
251 | + 'shiptocity' => substr($use_registration_address_info |
|
252 | + ? $attendee->city() |
|
253 | + : $billing_info['city'], 0, 40), |
|
254 | + 'state' => substr($use_registration_address_info |
|
255 | + ? $attendee->state_name() |
|
256 | + : $billing_info['state'], 0, 40), |
|
257 | + 'shiptocountry' => $use_registration_address_info |
|
258 | + ? $attendee->country_ID() |
|
259 | + : $billing_info['country'], |
|
260 | + 'shiptozip' => substr($use_registration_address_info |
|
261 | + ? $attendee->zip() |
|
262 | + : $billing_info['zip'], 0, 20), |
|
263 | + 'shiptophonenum' => substr($use_registration_address_info |
|
264 | + ? $attendee->phone() |
|
265 | + : $billing_info['phone'], 0, 20), |
|
266 | + ); |
|
267 | + $PaymentDetails = array( |
|
268 | + // Required. Total amount of order, including shipping, handling, and tax. |
|
269 | + 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
270 | + // Required. Three-letter currency code. Default is USD. |
|
271 | + 'currencycode' => $payment->currency_code(), |
|
272 | + // Required if you include itemized cart details. (L_AMTn, etc.) |
|
273 | + // Subtotal of items not including S&H, or tax. |
|
274 | + 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
275 | + // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
276 | + 'shippingamt' => '', |
|
277 | + // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
278 | + 'handlingamt' => '', |
|
279 | + // Required if you specify itemized cart tax details. |
|
280 | + // Sum of tax for all items on the order. Total sales tax. |
|
281 | + 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
282 | + // Description of the order the customer is purchasing. 127 char max. |
|
283 | + 'desc' => $order_description, |
|
284 | + // Free-form field for your own use. 256 char max. |
|
285 | + 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
286 | + // Your own invoice or tracking number |
|
287 | + 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
288 | + // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
289 | + 'notifyurl' => '', |
|
290 | + 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
291 | + ); |
|
292 | + // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
293 | + $PayPalRequestData = array( |
|
294 | + 'DPFields' => $DPFields, |
|
295 | + 'CCDetails' => $CCDetails, |
|
296 | + 'PayerInfo' => $PayerInfo, |
|
297 | + 'PayerName' => $PayerName, |
|
298 | + 'BillingAddress' => $BillingAddress, |
|
299 | + 'ShippingAddress' => $ShippingAddress, |
|
300 | + 'PaymentDetails' => $PaymentDetails, |
|
301 | + 'OrderItems' => $order_items, |
|
302 | + ); |
|
303 | + $this->_log_clean_request($PayPalRequestData, $payment); |
|
304 | + try { |
|
305 | + $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
306 | + // remove PCI-sensitive data so it doesn't get stored |
|
307 | + $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
308 | + $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK']; |
|
309 | + if (empty($PayPalResult['RAWRESPONSE'])) { |
|
310 | + $payment->set_status($this->_pay_model->failed_status()); |
|
311 | + $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
312 | + $payment->set_details($PayPalResult); |
|
313 | + } else { |
|
314 | + if ($this->_APICallSuccessful($PayPalResult)) { |
|
315 | + $payment->set_status($this->_pay_model->approved_status()); |
|
316 | + } else { |
|
317 | + $payment->set_status($this->_pay_model->declined_status()); |
|
318 | + } |
|
319 | + // make sure we interpret the AMT as a float, not an international string |
|
320 | + // (where periods are thousand separators) |
|
321 | + $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
322 | + $payment->set_gateway_response($message); |
|
323 | + $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
324 | + ? $PayPalResult['TRANSACTIONID'] |
|
325 | + : null); |
|
326 | + $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
327 | + ? $primary_registrant->reg_code() |
|
328 | + : ''; |
|
329 | + $payment->set_extra_accntng($primary_registration_code); |
|
330 | + $payment->set_details($PayPalResult); |
|
331 | + } |
|
332 | + } catch (Exception $e) { |
|
333 | + $payment->set_status($this->_pay_model->failed_status()); |
|
334 | + $payment->set_gateway_response($e->getMessage()); |
|
335 | + } |
|
336 | + // $payment->set_status( $this->_pay_model->declined_status() ); |
|
337 | + // $payment->set_gateway_response( '' ); |
|
338 | + return $payment; |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
345 | + * |
|
346 | + * @param array $request |
|
347 | + * @param EEI_Payment $payment |
|
348 | + * @return void |
|
349 | + */ |
|
350 | + private function _log_clean_request($request, $payment) |
|
351 | + { |
|
352 | + $cleaned_request_data = $request; |
|
353 | + unset($cleaned_request_data['CCDetails']['acct']); |
|
354 | + unset($cleaned_request_data['CCDetails']['cvv2']); |
|
355 | + unset($cleaned_request_data['CCDetails']['expdate']); |
|
356 | + $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Cleans the response, logs it, and returns it |
|
363 | + * |
|
364 | + * @param array $response |
|
365 | + * @param EEI_Payment $payment |
|
366 | + * @return array cleaned |
|
367 | + */ |
|
368 | + private function _log_clean_response($response, $payment) |
|
369 | + { |
|
370 | + unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
371 | + unset($response['REQUESTDATA']['ACCT']); |
|
372 | + unset($response['REQUESTDATA']['EXPDATE']); |
|
373 | + unset($response['REQUESTDATA']['CVV2']); |
|
374 | + unset($response['RAWREQUEST']); |
|
375 | + $this->log(array('Paypal Response' => $response), $payment); |
|
376 | + return $response; |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * @param $DataArray |
|
383 | + * @return array |
|
384 | + */ |
|
385 | + private function prep_and_curl_request($DataArray) |
|
386 | + { |
|
387 | + // Create empty holders for each portion of the NVP string |
|
388 | + $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
389 | + $CCDetailsNVP = ''; |
|
390 | + $PayerInfoNVP = ''; |
|
391 | + $PayerNameNVP = ''; |
|
392 | + $BillingAddressNVP = ''; |
|
393 | + $ShippingAddressNVP = ''; |
|
394 | + $PaymentDetailsNVP = ''; |
|
395 | + $OrderItemsNVP = ''; |
|
396 | + $Secure3DNVP = ''; |
|
397 | + // DP Fields |
|
398 | + $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
399 | + foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
400 | + $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
401 | + } |
|
402 | + // CC Details Fields |
|
403 | + $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
404 | + foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
405 | + $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
406 | + } |
|
407 | + // PayerInfo Type Fields |
|
408 | + $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
409 | + foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
410 | + $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
411 | + } |
|
412 | + // Payer Name Fields |
|
413 | + $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
414 | + foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
415 | + $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
416 | + } |
|
417 | + // Address Fields (Billing) |
|
418 | + $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
419 | + foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
420 | + $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
421 | + } |
|
422 | + // Payment Details Type Fields |
|
423 | + $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
424 | + foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
425 | + $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
426 | + } |
|
427 | + // Payment Details Item Type Fields |
|
428 | + $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
429 | + $n = 0; |
|
430 | + foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
431 | + $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
432 | + foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
433 | + $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
434 | + } |
|
435 | + $n++; |
|
436 | + } |
|
437 | + // Ship To Address Fields |
|
438 | + $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
439 | + foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
440 | + $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
441 | + } |
|
442 | + // 3D Secure Fields |
|
443 | + $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
444 | + foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
445 | + $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
446 | + } |
|
447 | + // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
448 | + $NVPRequest = 'USER=' |
|
449 | + . $this->_username |
|
450 | + . '&PWD=' |
|
451 | + . $this->_password |
|
452 | + . '&VERSION=64.0' |
|
453 | + . '&SIGNATURE=' |
|
454 | + . $this->_signature |
|
455 | + . $DPFieldsNVP |
|
456 | + . $CCDetailsNVP |
|
457 | + . $PayerInfoNVP |
|
458 | + . $PayerNameNVP |
|
459 | + . $BillingAddressNVP |
|
460 | + . $PaymentDetailsNVP |
|
461 | + . $OrderItemsNVP |
|
462 | + . $ShippingAddressNVP |
|
463 | + . $Secure3DNVP; |
|
464 | + $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
465 | + $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
466 | + $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
467 | + $Errors = $this->_GetErrors($NVPResponseArray); |
|
468 | + $NVPResponseArray['ERRORS'] = $Errors; |
|
469 | + $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
470 | + $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
471 | + $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
472 | + return $NVPResponseArray; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * @param $Request |
|
479 | + * @return mixed |
|
480 | + */ |
|
481 | + private function _CURLRequest($Request) |
|
482 | + { |
|
483 | + $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
484 | + $curl = curl_init(); |
|
485 | + curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
486 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
487 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
488 | + curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
489 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
490 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
491 | + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
492 | + // execute the curl POST |
|
493 | + $Response = curl_exec($curl); |
|
494 | + curl_close($curl); |
|
495 | + return $Response; |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @param $NVPString |
|
502 | + * @return array |
|
503 | + */ |
|
504 | + private function _NVPToArray($NVPString) |
|
505 | + { |
|
506 | + // prepare responses into array |
|
507 | + $proArray = array(); |
|
508 | + while (strlen($NVPString)) { |
|
509 | + // name |
|
510 | + $keypos = strpos($NVPString, '='); |
|
511 | + $keyval = substr($NVPString, 0, $keypos); |
|
512 | + // value |
|
513 | + $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
514 | + $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
515 | + // decoding the response |
|
516 | + $proArray[ $keyval ] = urldecode($valval); |
|
517 | + $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
518 | + } |
|
519 | + return $proArray; |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * @param array $PayPalResult |
|
526 | + * @return bool |
|
527 | + */ |
|
528 | + private function _APICallSuccessful($PayPalResult) |
|
529 | + { |
|
530 | + $approved = false; |
|
531 | + // check main response message from PayPal |
|
532 | + if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
533 | + $ack = strtoupper($PayPalResult['ACK']); |
|
534 | + $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
535 | + } |
|
536 | + return $approved; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @param $DataArray |
|
543 | + * @return array |
|
544 | + */ |
|
545 | + private function _GetErrors($DataArray) |
|
546 | + { |
|
547 | + $Errors = array(); |
|
548 | + $n = 0; |
|
549 | + while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
550 | + $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
551 | + $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
552 | + ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
553 | + : ''; |
|
554 | + $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
555 | + ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
556 | + : ''; |
|
557 | + $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
558 | + ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
559 | + : ''; |
|
560 | + $CurrentItem = array( |
|
561 | + 'L_ERRORCODE' => $LErrorCode, |
|
562 | + 'L_SHORTMESSAGE' => $LShortMessage, |
|
563 | + 'L_LONGMESSAGE' => $LLongMessage, |
|
564 | + 'L_SEVERITYCODE' => $LSeverityCode, |
|
565 | + ); |
|
566 | + array_push($Errors, $CurrentItem); |
|
567 | + $n++; |
|
568 | + } |
|
569 | + return $Errors; |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + |
|
574 | + /** |
|
575 | + * nothing to see here... move along.... |
|
576 | + * |
|
577 | + * @access protected |
|
578 | + * @param $Errors |
|
579 | + * @return string |
|
580 | + */ |
|
581 | + private function _DisplayErrors($Errors) |
|
582 | + { |
|
583 | + $error = ''; |
|
584 | + foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
585 | + $CurrentError = $Errors[ $ErrorVar ]; |
|
586 | + foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
587 | + $CurrentVarName = ''; |
|
588 | + if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
589 | + $CurrentVarName = 'Error Code'; |
|
590 | + } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
591 | + $CurrentVarName = 'Short Message'; |
|
592 | + } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
593 | + $CurrentVarName = 'Long Message'; |
|
594 | + } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
595 | + $CurrentVarName = 'Severity Code'; |
|
596 | + } |
|
597 | + $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
598 | + } |
|
599 | + } |
|
600 | + return $error; |
|
601 | + } |
|
602 | 602 | } |
@@ -11,676 +11,676 @@ |
||
11 | 11 | */ |
12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
13 | 13 | if (! function_exists('mb_strcut')) { |
14 | - /** |
|
15 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
16 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
17 | - * @param $string |
|
18 | - * @param $start |
|
19 | - * @param $length |
|
20 | - * @return bool|string |
|
21 | - */ |
|
22 | - function mb_strcut($string, $start, $length = null) |
|
23 | - { |
|
24 | - return mb_substr($string, $start, $length); |
|
25 | - } |
|
14 | + /** |
|
15 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
16 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
17 | + * @param $string |
|
18 | + * @param $start |
|
19 | + * @param $length |
|
20 | + * @return bool|string |
|
21 | + */ |
|
22 | + function mb_strcut($string, $start, $length = null) |
|
23 | + { |
|
24 | + return mb_substr($string, $start, $length); |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Merchant API Username. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $_api_username; |
|
36 | - |
|
37 | - /** |
|
38 | - * Merchant API Password. |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_api_password; |
|
43 | - |
|
44 | - /** |
|
45 | - * API Signature. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $_api_signature; |
|
50 | - |
|
51 | - /** |
|
52 | - * Request Shipping address on PP checkout page. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $_request_shipping_addr; |
|
57 | - |
|
58 | - /** |
|
59 | - * Business/personal logo. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - protected $_image_url; |
|
64 | - |
|
65 | - /** |
|
66 | - * gateway URL variable |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - protected $_base_gateway_url = ''; |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * EEG_Paypal_Express constructor. |
|
76 | - */ |
|
77 | - public function __construct() |
|
78 | - { |
|
79 | - $this->_currencies_supported = array( |
|
80 | - 'USD', |
|
81 | - 'AUD', |
|
82 | - 'BRL', |
|
83 | - 'CAD', |
|
84 | - 'CZK', |
|
85 | - 'DKK', |
|
86 | - 'EUR', |
|
87 | - 'HKD', |
|
88 | - 'HUF', |
|
89 | - 'ILS', |
|
90 | - 'JPY', |
|
91 | - 'MYR', |
|
92 | - 'MXN', |
|
93 | - 'NOK', |
|
94 | - 'NZD', |
|
95 | - 'PHP', |
|
96 | - 'PLN', |
|
97 | - 'GBP', |
|
98 | - 'RUB', |
|
99 | - 'SGD', |
|
100 | - 'SEK', |
|
101 | - 'CHF', |
|
102 | - 'TWD', |
|
103 | - 'THB', |
|
104 | - 'TRY', |
|
105 | - 'INR', |
|
106 | - ); |
|
107 | - parent::__construct(); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
114 | - * |
|
115 | - * @param array $settings_array |
|
116 | - */ |
|
117 | - public function set_settings($settings_array) |
|
118 | - { |
|
119 | - parent::set_settings($settings_array); |
|
120 | - // Redirect URL. |
|
121 | - $this->_base_gateway_url = $this->_debug_mode |
|
122 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
123 | - : 'https://api-3t.paypal.com/nvp'; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param EEI_Payment $payment |
|
130 | - * @param array $billing_info |
|
131 | - * @param string $return_url |
|
132 | - * @param string $notify_url |
|
133 | - * @param string $cancel_url |
|
134 | - * @return \EE_Payment|\EEI_Payment |
|
135 | - * @throws \EE_Error |
|
136 | - */ |
|
137 | - public function set_redirection_info( |
|
138 | - $payment, |
|
139 | - $billing_info = array(), |
|
140 | - $return_url = null, |
|
141 | - $notify_url = null, |
|
142 | - $cancel_url = null |
|
143 | - ) { |
|
144 | - if (! $payment instanceof EEI_Payment) { |
|
145 | - $payment->set_gateway_response( |
|
146 | - esc_html__( |
|
147 | - 'Error. No associated payment was found.', |
|
148 | - 'event_espresso' |
|
149 | - ) |
|
150 | - ); |
|
151 | - $payment->set_status($this->_pay_model->failed_status()); |
|
152 | - return $payment; |
|
153 | - } |
|
154 | - $transaction = $payment->transaction(); |
|
155 | - if (! $transaction instanceof EEI_Transaction) { |
|
156 | - $payment->set_gateway_response( |
|
157 | - esc_html__( |
|
158 | - 'Could not process this payment because it has no associated transaction.', |
|
159 | - 'event_espresso' |
|
160 | - ) |
|
161 | - ); |
|
162 | - $payment->set_status($this->_pay_model->failed_status()); |
|
163 | - return $payment; |
|
164 | - } |
|
165 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
166 | - $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
167 | - $primary_registration = $transaction->primary_registration(); |
|
168 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
169 | - ? $primary_registration->attendee() |
|
170 | - : false; |
|
171 | - $locale = explode('-', get_bloginfo('language')); |
|
172 | - // Gather request parameters. |
|
173 | - $token_request_dtls = array( |
|
174 | - 'METHOD' => 'SetExpressCheckout', |
|
175 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
176 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
177 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
178 | - 'RETURNURL' => $return_url, |
|
179 | - 'CANCELURL' => $cancel_url, |
|
180 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
181 | - // Buyer does not need to create a PayPal account to check out. |
|
182 | - // This is referred to as PayPal Account Optional. |
|
183 | - 'SOLUTIONTYPE' => 'Sole', |
|
184 | - // EE will blow up if you change this |
|
185 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
186 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
187 | - 'LOCALECODE' => $locale[1] |
|
188 | - ); |
|
189 | - // Show itemized list. |
|
190 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
191 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
192 | - // Automatically filling out shipping and contact information. |
|
193 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
194 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
195 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
196 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
197 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
198 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
199 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
200 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
201 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
202 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
203 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
204 | - } elseif (! $this->_request_shipping_addr) { |
|
205 | - // Do not request shipping details on the PP Checkout page. |
|
206 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
207 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
208 | - } |
|
209 | - // Used a business/personal logo on the PayPal page. |
|
210 | - if (! empty($this->_image_url)) { |
|
211 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
212 | - } |
|
213 | - $token_request_dtls = apply_filters( |
|
214 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
215 | - $token_request_dtls, |
|
216 | - $this |
|
217 | - ); |
|
218 | - // Request PayPal token. |
|
219 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
220 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
221 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
222 | - ? $token_rstatus['args'] |
|
223 | - : array(); |
|
224 | - if ($token_rstatus['status']) { |
|
225 | - // We got the Token so we may continue with the payment and redirect the client. |
|
226 | - $payment->set_details($response_args); |
|
227 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
228 | - $payment->set_redirect_url( |
|
229 | - $gateway_url |
|
230 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
231 | - . $response_args['TOKEN'] |
|
232 | - ); |
|
233 | - } else { |
|
234 | - if (isset($response_args['L_ERRORCODE'])) { |
|
235 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
236 | - } else { |
|
237 | - $payment->set_gateway_response( |
|
238 | - esc_html__( |
|
239 | - 'Error occurred while trying to setup the Express Checkout.', |
|
240 | - 'event_espresso' |
|
241 | - ) |
|
242 | - ); |
|
243 | - } |
|
244 | - $payment->set_details($response_args); |
|
245 | - $payment->set_status($this->_pay_model->failed_status()); |
|
246 | - } |
|
247 | - return $payment; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param array $update_info { |
|
254 | - * @type string $gateway_txn_id |
|
255 | - * @type string status an EEMI_Payment status |
|
256 | - * } |
|
257 | - * @param EEI_Transaction $transaction |
|
258 | - * @return EEI_Payment |
|
259 | - */ |
|
260 | - public function handle_payment_update($update_info, $transaction) |
|
261 | - { |
|
262 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
263 | - if ($payment instanceof EEI_Payment) { |
|
264 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
265 | - $transaction = $payment->transaction(); |
|
266 | - if (! $transaction instanceof EEI_Transaction) { |
|
267 | - $payment->set_gateway_response( |
|
268 | - esc_html__( |
|
269 | - 'Could not process this payment because it has no associated transaction.', |
|
270 | - 'event_espresso' |
|
271 | - ) |
|
272 | - ); |
|
273 | - $payment->set_status($this->_pay_model->failed_status()); |
|
274 | - return $payment; |
|
275 | - } |
|
276 | - $primary_registrant = $transaction->primary_registration(); |
|
277 | - $payment_details = $payment->details(); |
|
278 | - // Check if we still have the token. |
|
279 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
280 | - $payment->set_status($this->_pay_model->failed_status()); |
|
281 | - return $payment; |
|
282 | - } |
|
283 | - $cdetails_request_dtls = array( |
|
284 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
285 | - 'TOKEN' => $payment_details['TOKEN'], |
|
286 | - ); |
|
287 | - // Request Customer Details. |
|
288 | - $cdetails_request_response = $this->_ppExpress_request( |
|
289 | - $cdetails_request_dtls, |
|
290 | - 'Customer Details', |
|
291 | - $payment |
|
292 | - ); |
|
293 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
294 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
295 | - ? $cdetails_rstatus['args'] |
|
296 | - : array(); |
|
297 | - if ($cdetails_rstatus['status']) { |
|
298 | - // We got the PayerID so now we can Complete the transaction. |
|
299 | - $docheckout_request_dtls = array( |
|
300 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
301 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
302 | - 'TOKEN' => $payment_details['TOKEN'], |
|
303 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
304 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
305 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
306 | - // EE will blow up if you change this |
|
307 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
308 | - ); |
|
309 | - // Include itemized list. |
|
310 | - $itemized_list = $this->itemize_list( |
|
311 | - $payment, |
|
312 | - $transaction, |
|
313 | - $cdata_response_args |
|
314 | - ); |
|
315 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
316 | - // Payment Checkout/Capture. |
|
317 | - $docheckout_request_response = $this->_ppExpress_request( |
|
318 | - $docheckout_request_dtls, |
|
319 | - 'Do Payment', |
|
320 | - $payment |
|
321 | - ); |
|
322 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
323 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
324 | - ? $docheckout_rstatus['args'] |
|
325 | - : array(); |
|
326 | - if ($docheckout_rstatus['status']) { |
|
327 | - // All is well, payment approved. |
|
328 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
329 | - $primary_registrant->reg_code() |
|
330 | - : ''; |
|
331 | - $payment->set_extra_accntng($primary_registration_code); |
|
332 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
333 | - ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
334 | - : 0); |
|
335 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
336 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
337 | - : null); |
|
338 | - $payment->set_details($cdata_response_args); |
|
339 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
340 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
341 | - : ''); |
|
342 | - $payment->set_status($this->_pay_model->approved_status()); |
|
343 | - } else { |
|
344 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
345 | - $payment->set_gateway_response( |
|
346 | - $docheckout_response_args['L_ERRORCODE'] |
|
347 | - . '; ' |
|
348 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
349 | - ); |
|
350 | - } else { |
|
351 | - $payment->set_gateway_response( |
|
352 | - esc_html__( |
|
353 | - 'Error occurred while trying to Capture the funds.', |
|
354 | - 'event_espresso' |
|
355 | - ) |
|
356 | - ); |
|
357 | - } |
|
358 | - $payment->set_details($docheckout_response_args); |
|
359 | - $payment->set_status($this->_pay_model->declined_status()); |
|
360 | - } |
|
361 | - } else { |
|
362 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
363 | - $payment->set_gateway_response( |
|
364 | - $cdata_response_args['L_ERRORCODE'] |
|
365 | - . '; ' |
|
366 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
367 | - ); |
|
368 | - } else { |
|
369 | - $payment->set_gateway_response( |
|
370 | - esc_html__( |
|
371 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
372 | - 'event_espresso' |
|
373 | - ) |
|
374 | - ); |
|
375 | - } |
|
376 | - $payment->set_details($cdata_response_args); |
|
377 | - $payment->set_status($this->_pay_model->failed_status()); |
|
378 | - } |
|
379 | - } else { |
|
380 | - $payment->set_gateway_response( |
|
381 | - esc_html__( |
|
382 | - 'Error occurred while trying to process the payment.', |
|
383 | - 'event_espresso' |
|
384 | - ) |
|
385 | - ); |
|
386 | - $payment->set_status($this->_pay_model->failed_status()); |
|
387 | - } |
|
388 | - return $payment; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * Make a list of items that are in the giver transaction. |
|
395 | - * |
|
396 | - * @param EEI_Payment $payment |
|
397 | - * @param EEI_Transaction $transaction |
|
398 | - * @param array $request_response_args Data from a previous communication with PP. |
|
399 | - * @return array |
|
400 | - */ |
|
401 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
402 | - { |
|
403 | - $itemized_list = array(); |
|
404 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
405 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
406 | - if (! empty($request_response_args) |
|
407 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
408 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
409 | - ) { |
|
410 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
411 | - if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
412 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
413 | - ) { |
|
414 | - $itemized_list[ $arg_key ] = $arg_val; |
|
415 | - } |
|
416 | - } |
|
417 | - // If we got only a few Items then something is not right. |
|
418 | - if (count($itemized_list) > 2) { |
|
419 | - return $itemized_list; |
|
420 | - } else { |
|
421 | - if (WP_DEBUG) { |
|
422 | - throw new EE_Error( |
|
423 | - sprintf( |
|
424 | - esc_html__( |
|
425 | - // @codingStandardsIgnoreStart |
|
426 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
427 | - // @codingStandardsIgnoreEnd |
|
428 | - 'event_espresso' |
|
429 | - ), |
|
430 | - wp_json_encode($itemized_list) |
|
431 | - ) |
|
432 | - ); |
|
433 | - } |
|
434 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
435 | - $itemized_list = array(); |
|
436 | - $this->log( |
|
437 | - array( |
|
438 | - esc_html__( |
|
439 | - 'Could not generate a proper item list with:', |
|
440 | - 'event_espresso' |
|
441 | - ) => $request_response_args |
|
442 | - ), |
|
443 | - $payment |
|
444 | - ); |
|
445 | - } |
|
446 | - } |
|
447 | - // ...otherwise we generate a new list for this transaction. |
|
448 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
449 | - $item_num = 0; |
|
450 | - $itemized_sum = 0; |
|
451 | - $total_line_items = $transaction->total_line_item(); |
|
452 | - // Go through each item in the list. |
|
453 | - foreach ($total_line_items->get_items() as $line_item) { |
|
454 | - if ($line_item instanceof EE_Line_Item) { |
|
455 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
456 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
457 | - continue; |
|
458 | - } |
|
459 | - $unit_price = $line_item->unit_price(); |
|
460 | - $line_item_quantity = $line_item->quantity(); |
|
461 | - // This is a discount. |
|
462 | - if ($line_item->is_percent()) { |
|
463 | - $unit_price = $line_item->total(); |
|
464 | - $line_item_quantity = 1; |
|
465 | - } |
|
466 | - // Item Name. |
|
467 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
468 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
469 | - 0, |
|
470 | - 127 |
|
471 | - ); |
|
472 | - // Item description. |
|
473 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
474 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
475 | - 0, |
|
476 | - 127 |
|
477 | - ); |
|
478 | - // Cost of individual item. |
|
479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
480 | - // Item Number. |
|
481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
482 | - // Item quantity. |
|
483 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
484 | - // Digital item is sold. |
|
485 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
486 | - $itemized_sum += $line_item->total(); |
|
487 | - ++$item_num; |
|
488 | - } |
|
489 | - } |
|
490 | - // Item's sales S/H and tax amount. |
|
491 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
492 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
493 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
494 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
495 | - $itemized_sum_diff_from_txn_total = round( |
|
496 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
497 | - 2 |
|
498 | - ); |
|
499 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
500 | - // add the difference as an extra line item. |
|
501 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
502 | - // Item Name. |
|
503 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
504 | - esc_html__( |
|
505 | - 'Other (promotion/surcharge/cancellation)', |
|
506 | - 'event_espresso' |
|
507 | - ), |
|
508 | - 0, |
|
509 | - 127 |
|
510 | - ); |
|
511 | - // Item description. |
|
512 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
513 | - // Cost of individual item. |
|
514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
515 | - $itemized_sum_diff_from_txn_total |
|
516 | - ); |
|
517 | - // Item Number. |
|
518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
519 | - // Item quantity. |
|
520 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
521 | - // Digital item is sold. |
|
522 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
523 | - $item_num++; |
|
524 | - } |
|
525 | - } else { |
|
526 | - // Just one Item. |
|
527 | - // Item Name. |
|
528 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
529 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
530 | - 0, |
|
531 | - 127 |
|
532 | - ); |
|
533 | - // Item description. |
|
534 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
535 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
536 | - 0, |
|
537 | - 127 |
|
538 | - ); |
|
539 | - // Cost of individual item. |
|
540 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
541 | - // Item Number. |
|
542 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
543 | - // Item quantity. |
|
544 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
545 | - // Digital item is sold. |
|
546 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
547 | - // Item's sales S/H and tax amount. |
|
548 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
549 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
550 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
551 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
552 | - } |
|
553 | - return $itemized_list; |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Make the Express checkout request. |
|
560 | - * |
|
561 | - * @param array $request_params |
|
562 | - * @param string $request_text |
|
563 | - * @param EEI_Payment $payment |
|
564 | - * @return mixed |
|
565 | - */ |
|
566 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
567 | - { |
|
568 | - $request_dtls = array( |
|
569 | - 'VERSION' => '204.0', |
|
570 | - 'USER' => urlencode($this->_api_username), |
|
571 | - 'PWD' => urlencode($this->_api_password), |
|
572 | - 'SIGNATURE' => urlencode($this->_api_signature), |
|
573 | - ); |
|
574 | - $dtls = array_merge($request_dtls, $request_params); |
|
575 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
576 | - // Request Customer Details. |
|
577 | - $request_response = wp_remote_post( |
|
578 | - $this->_base_gateway_url, |
|
579 | - array( |
|
580 | - 'method' => 'POST', |
|
581 | - 'timeout' => 45, |
|
582 | - 'httpversion' => '1.1', |
|
583 | - 'cookies' => array(), |
|
584 | - 'headers' => array(), |
|
585 | - 'body' => http_build_query($dtls, '', '&'), |
|
586 | - ) |
|
587 | - ); |
|
588 | - // Log the response. |
|
589 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
590 | - return $request_response; |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * Check the response status. |
|
597 | - * |
|
598 | - * @param mixed $request_response |
|
599 | - * @return array |
|
600 | - */ |
|
601 | - public function _ppExpress_check_response($request_response) |
|
602 | - { |
|
603 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
604 | - // If we got here then there was an error in this request. |
|
605 | - return array('status' => false, 'args' => $request_response); |
|
606 | - } |
|
607 | - $response_args = array(); |
|
608 | - parse_str(urldecode($request_response['body']), $response_args); |
|
609 | - if (! isset($response_args['ACK'])) { |
|
610 | - return array('status' => false, 'args' => $request_response); |
|
611 | - } |
|
612 | - if (( |
|
613 | - isset($response_args['PAYERID']) |
|
614 | - || isset($response_args['TOKEN']) |
|
615 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
616 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
617 | - ) |
|
618 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
619 | - ) { |
|
620 | - // Response status OK, return response parameters for further processing. |
|
621 | - return array('status' => true, 'args' => $response_args); |
|
622 | - } |
|
623 | - $errors = $this->_get_errors($response_args); |
|
624 | - return array('status' => false, 'args' => $errors); |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - |
|
629 | - /** |
|
630 | - * Log a "Cleared" request. |
|
631 | - * |
|
632 | - * @param array $request |
|
633 | - * @param EEI_Payment $payment |
|
634 | - * @param string $info |
|
635 | - * @return void |
|
636 | - */ |
|
637 | - private function _log_clean_request($request, $payment, $info) |
|
638 | - { |
|
639 | - $cleaned_request_data = $request; |
|
640 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
641 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
642 | - } |
|
643 | - |
|
644 | - |
|
645 | - |
|
646 | - /** |
|
647 | - * Get error from the response data. |
|
648 | - * |
|
649 | - * @param array $data_array |
|
650 | - * @return array |
|
651 | - */ |
|
652 | - private function _get_errors($data_array) |
|
653 | - { |
|
654 | - $errors = array(); |
|
655 | - $n = 0; |
|
656 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
657 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
658 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
659 | - : ''; |
|
660 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
661 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
662 | - : ''; |
|
663 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
664 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
665 | - : ''; |
|
666 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
667 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
668 | - : ''; |
|
669 | - if ($n === 0) { |
|
670 | - $errors = array( |
|
671 | - 'L_ERRORCODE' => $l_error_code, |
|
672 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
673 | - 'L_LONGMESSAGE' => $l_long_message, |
|
674 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
675 | - ); |
|
676 | - } else { |
|
677 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
678 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
679 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
680 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
681 | - } |
|
682 | - $n++; |
|
683 | - } |
|
684 | - return $errors; |
|
685 | - } |
|
30 | + /** |
|
31 | + * Merchant API Username. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $_api_username; |
|
36 | + |
|
37 | + /** |
|
38 | + * Merchant API Password. |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_api_password; |
|
43 | + |
|
44 | + /** |
|
45 | + * API Signature. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $_api_signature; |
|
50 | + |
|
51 | + /** |
|
52 | + * Request Shipping address on PP checkout page. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $_request_shipping_addr; |
|
57 | + |
|
58 | + /** |
|
59 | + * Business/personal logo. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + protected $_image_url; |
|
64 | + |
|
65 | + /** |
|
66 | + * gateway URL variable |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + protected $_base_gateway_url = ''; |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * EEG_Paypal_Express constructor. |
|
76 | + */ |
|
77 | + public function __construct() |
|
78 | + { |
|
79 | + $this->_currencies_supported = array( |
|
80 | + 'USD', |
|
81 | + 'AUD', |
|
82 | + 'BRL', |
|
83 | + 'CAD', |
|
84 | + 'CZK', |
|
85 | + 'DKK', |
|
86 | + 'EUR', |
|
87 | + 'HKD', |
|
88 | + 'HUF', |
|
89 | + 'ILS', |
|
90 | + 'JPY', |
|
91 | + 'MYR', |
|
92 | + 'MXN', |
|
93 | + 'NOK', |
|
94 | + 'NZD', |
|
95 | + 'PHP', |
|
96 | + 'PLN', |
|
97 | + 'GBP', |
|
98 | + 'RUB', |
|
99 | + 'SGD', |
|
100 | + 'SEK', |
|
101 | + 'CHF', |
|
102 | + 'TWD', |
|
103 | + 'THB', |
|
104 | + 'TRY', |
|
105 | + 'INR', |
|
106 | + ); |
|
107 | + parent::__construct(); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
114 | + * |
|
115 | + * @param array $settings_array |
|
116 | + */ |
|
117 | + public function set_settings($settings_array) |
|
118 | + { |
|
119 | + parent::set_settings($settings_array); |
|
120 | + // Redirect URL. |
|
121 | + $this->_base_gateway_url = $this->_debug_mode |
|
122 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
123 | + : 'https://api-3t.paypal.com/nvp'; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param EEI_Payment $payment |
|
130 | + * @param array $billing_info |
|
131 | + * @param string $return_url |
|
132 | + * @param string $notify_url |
|
133 | + * @param string $cancel_url |
|
134 | + * @return \EE_Payment|\EEI_Payment |
|
135 | + * @throws \EE_Error |
|
136 | + */ |
|
137 | + public function set_redirection_info( |
|
138 | + $payment, |
|
139 | + $billing_info = array(), |
|
140 | + $return_url = null, |
|
141 | + $notify_url = null, |
|
142 | + $cancel_url = null |
|
143 | + ) { |
|
144 | + if (! $payment instanceof EEI_Payment) { |
|
145 | + $payment->set_gateway_response( |
|
146 | + esc_html__( |
|
147 | + 'Error. No associated payment was found.', |
|
148 | + 'event_espresso' |
|
149 | + ) |
|
150 | + ); |
|
151 | + $payment->set_status($this->_pay_model->failed_status()); |
|
152 | + return $payment; |
|
153 | + } |
|
154 | + $transaction = $payment->transaction(); |
|
155 | + if (! $transaction instanceof EEI_Transaction) { |
|
156 | + $payment->set_gateway_response( |
|
157 | + esc_html__( |
|
158 | + 'Could not process this payment because it has no associated transaction.', |
|
159 | + 'event_espresso' |
|
160 | + ) |
|
161 | + ); |
|
162 | + $payment->set_status($this->_pay_model->failed_status()); |
|
163 | + return $payment; |
|
164 | + } |
|
165 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
166 | + $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
167 | + $primary_registration = $transaction->primary_registration(); |
|
168 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
169 | + ? $primary_registration->attendee() |
|
170 | + : false; |
|
171 | + $locale = explode('-', get_bloginfo('language')); |
|
172 | + // Gather request parameters. |
|
173 | + $token_request_dtls = array( |
|
174 | + 'METHOD' => 'SetExpressCheckout', |
|
175 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
176 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
177 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
178 | + 'RETURNURL' => $return_url, |
|
179 | + 'CANCELURL' => $cancel_url, |
|
180 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
181 | + // Buyer does not need to create a PayPal account to check out. |
|
182 | + // This is referred to as PayPal Account Optional. |
|
183 | + 'SOLUTIONTYPE' => 'Sole', |
|
184 | + // EE will blow up if you change this |
|
185 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
186 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
187 | + 'LOCALECODE' => $locale[1] |
|
188 | + ); |
|
189 | + // Show itemized list. |
|
190 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
191 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
192 | + // Automatically filling out shipping and contact information. |
|
193 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
194 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
195 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
196 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
197 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
198 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
199 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
200 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
201 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
202 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
203 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
204 | + } elseif (! $this->_request_shipping_addr) { |
|
205 | + // Do not request shipping details on the PP Checkout page. |
|
206 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
207 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
208 | + } |
|
209 | + // Used a business/personal logo on the PayPal page. |
|
210 | + if (! empty($this->_image_url)) { |
|
211 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
212 | + } |
|
213 | + $token_request_dtls = apply_filters( |
|
214 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
215 | + $token_request_dtls, |
|
216 | + $this |
|
217 | + ); |
|
218 | + // Request PayPal token. |
|
219 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
220 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
221 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
222 | + ? $token_rstatus['args'] |
|
223 | + : array(); |
|
224 | + if ($token_rstatus['status']) { |
|
225 | + // We got the Token so we may continue with the payment and redirect the client. |
|
226 | + $payment->set_details($response_args); |
|
227 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
228 | + $payment->set_redirect_url( |
|
229 | + $gateway_url |
|
230 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
231 | + . $response_args['TOKEN'] |
|
232 | + ); |
|
233 | + } else { |
|
234 | + if (isset($response_args['L_ERRORCODE'])) { |
|
235 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
236 | + } else { |
|
237 | + $payment->set_gateway_response( |
|
238 | + esc_html__( |
|
239 | + 'Error occurred while trying to setup the Express Checkout.', |
|
240 | + 'event_espresso' |
|
241 | + ) |
|
242 | + ); |
|
243 | + } |
|
244 | + $payment->set_details($response_args); |
|
245 | + $payment->set_status($this->_pay_model->failed_status()); |
|
246 | + } |
|
247 | + return $payment; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param array $update_info { |
|
254 | + * @type string $gateway_txn_id |
|
255 | + * @type string status an EEMI_Payment status |
|
256 | + * } |
|
257 | + * @param EEI_Transaction $transaction |
|
258 | + * @return EEI_Payment |
|
259 | + */ |
|
260 | + public function handle_payment_update($update_info, $transaction) |
|
261 | + { |
|
262 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
263 | + if ($payment instanceof EEI_Payment) { |
|
264 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
265 | + $transaction = $payment->transaction(); |
|
266 | + if (! $transaction instanceof EEI_Transaction) { |
|
267 | + $payment->set_gateway_response( |
|
268 | + esc_html__( |
|
269 | + 'Could not process this payment because it has no associated transaction.', |
|
270 | + 'event_espresso' |
|
271 | + ) |
|
272 | + ); |
|
273 | + $payment->set_status($this->_pay_model->failed_status()); |
|
274 | + return $payment; |
|
275 | + } |
|
276 | + $primary_registrant = $transaction->primary_registration(); |
|
277 | + $payment_details = $payment->details(); |
|
278 | + // Check if we still have the token. |
|
279 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
280 | + $payment->set_status($this->_pay_model->failed_status()); |
|
281 | + return $payment; |
|
282 | + } |
|
283 | + $cdetails_request_dtls = array( |
|
284 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
285 | + 'TOKEN' => $payment_details['TOKEN'], |
|
286 | + ); |
|
287 | + // Request Customer Details. |
|
288 | + $cdetails_request_response = $this->_ppExpress_request( |
|
289 | + $cdetails_request_dtls, |
|
290 | + 'Customer Details', |
|
291 | + $payment |
|
292 | + ); |
|
293 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
294 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
295 | + ? $cdetails_rstatus['args'] |
|
296 | + : array(); |
|
297 | + if ($cdetails_rstatus['status']) { |
|
298 | + // We got the PayerID so now we can Complete the transaction. |
|
299 | + $docheckout_request_dtls = array( |
|
300 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
301 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
302 | + 'TOKEN' => $payment_details['TOKEN'], |
|
303 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
304 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
305 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
306 | + // EE will blow up if you change this |
|
307 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
308 | + ); |
|
309 | + // Include itemized list. |
|
310 | + $itemized_list = $this->itemize_list( |
|
311 | + $payment, |
|
312 | + $transaction, |
|
313 | + $cdata_response_args |
|
314 | + ); |
|
315 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
316 | + // Payment Checkout/Capture. |
|
317 | + $docheckout_request_response = $this->_ppExpress_request( |
|
318 | + $docheckout_request_dtls, |
|
319 | + 'Do Payment', |
|
320 | + $payment |
|
321 | + ); |
|
322 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
323 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
324 | + ? $docheckout_rstatus['args'] |
|
325 | + : array(); |
|
326 | + if ($docheckout_rstatus['status']) { |
|
327 | + // All is well, payment approved. |
|
328 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
329 | + $primary_registrant->reg_code() |
|
330 | + : ''; |
|
331 | + $payment->set_extra_accntng($primary_registration_code); |
|
332 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
333 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
334 | + : 0); |
|
335 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
336 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
337 | + : null); |
|
338 | + $payment->set_details($cdata_response_args); |
|
339 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
340 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
341 | + : ''); |
|
342 | + $payment->set_status($this->_pay_model->approved_status()); |
|
343 | + } else { |
|
344 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
345 | + $payment->set_gateway_response( |
|
346 | + $docheckout_response_args['L_ERRORCODE'] |
|
347 | + . '; ' |
|
348 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
349 | + ); |
|
350 | + } else { |
|
351 | + $payment->set_gateway_response( |
|
352 | + esc_html__( |
|
353 | + 'Error occurred while trying to Capture the funds.', |
|
354 | + 'event_espresso' |
|
355 | + ) |
|
356 | + ); |
|
357 | + } |
|
358 | + $payment->set_details($docheckout_response_args); |
|
359 | + $payment->set_status($this->_pay_model->declined_status()); |
|
360 | + } |
|
361 | + } else { |
|
362 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
363 | + $payment->set_gateway_response( |
|
364 | + $cdata_response_args['L_ERRORCODE'] |
|
365 | + . '; ' |
|
366 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
367 | + ); |
|
368 | + } else { |
|
369 | + $payment->set_gateway_response( |
|
370 | + esc_html__( |
|
371 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
372 | + 'event_espresso' |
|
373 | + ) |
|
374 | + ); |
|
375 | + } |
|
376 | + $payment->set_details($cdata_response_args); |
|
377 | + $payment->set_status($this->_pay_model->failed_status()); |
|
378 | + } |
|
379 | + } else { |
|
380 | + $payment->set_gateway_response( |
|
381 | + esc_html__( |
|
382 | + 'Error occurred while trying to process the payment.', |
|
383 | + 'event_espresso' |
|
384 | + ) |
|
385 | + ); |
|
386 | + $payment->set_status($this->_pay_model->failed_status()); |
|
387 | + } |
|
388 | + return $payment; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * Make a list of items that are in the giver transaction. |
|
395 | + * |
|
396 | + * @param EEI_Payment $payment |
|
397 | + * @param EEI_Transaction $transaction |
|
398 | + * @param array $request_response_args Data from a previous communication with PP. |
|
399 | + * @return array |
|
400 | + */ |
|
401 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
402 | + { |
|
403 | + $itemized_list = array(); |
|
404 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
405 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
406 | + if (! empty($request_response_args) |
|
407 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
408 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
409 | + ) { |
|
410 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
411 | + if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
412 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
413 | + ) { |
|
414 | + $itemized_list[ $arg_key ] = $arg_val; |
|
415 | + } |
|
416 | + } |
|
417 | + // If we got only a few Items then something is not right. |
|
418 | + if (count($itemized_list) > 2) { |
|
419 | + return $itemized_list; |
|
420 | + } else { |
|
421 | + if (WP_DEBUG) { |
|
422 | + throw new EE_Error( |
|
423 | + sprintf( |
|
424 | + esc_html__( |
|
425 | + // @codingStandardsIgnoreStart |
|
426 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
427 | + // @codingStandardsIgnoreEnd |
|
428 | + 'event_espresso' |
|
429 | + ), |
|
430 | + wp_json_encode($itemized_list) |
|
431 | + ) |
|
432 | + ); |
|
433 | + } |
|
434 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
435 | + $itemized_list = array(); |
|
436 | + $this->log( |
|
437 | + array( |
|
438 | + esc_html__( |
|
439 | + 'Could not generate a proper item list with:', |
|
440 | + 'event_espresso' |
|
441 | + ) => $request_response_args |
|
442 | + ), |
|
443 | + $payment |
|
444 | + ); |
|
445 | + } |
|
446 | + } |
|
447 | + // ...otherwise we generate a new list for this transaction. |
|
448 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
449 | + $item_num = 0; |
|
450 | + $itemized_sum = 0; |
|
451 | + $total_line_items = $transaction->total_line_item(); |
|
452 | + // Go through each item in the list. |
|
453 | + foreach ($total_line_items->get_items() as $line_item) { |
|
454 | + if ($line_item instanceof EE_Line_Item) { |
|
455 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
456 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
457 | + continue; |
|
458 | + } |
|
459 | + $unit_price = $line_item->unit_price(); |
|
460 | + $line_item_quantity = $line_item->quantity(); |
|
461 | + // This is a discount. |
|
462 | + if ($line_item->is_percent()) { |
|
463 | + $unit_price = $line_item->total(); |
|
464 | + $line_item_quantity = 1; |
|
465 | + } |
|
466 | + // Item Name. |
|
467 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
468 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
469 | + 0, |
|
470 | + 127 |
|
471 | + ); |
|
472 | + // Item description. |
|
473 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
474 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
475 | + 0, |
|
476 | + 127 |
|
477 | + ); |
|
478 | + // Cost of individual item. |
|
479 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
480 | + // Item Number. |
|
481 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
482 | + // Item quantity. |
|
483 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
484 | + // Digital item is sold. |
|
485 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
486 | + $itemized_sum += $line_item->total(); |
|
487 | + ++$item_num; |
|
488 | + } |
|
489 | + } |
|
490 | + // Item's sales S/H and tax amount. |
|
491 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
492 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
493 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
494 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
495 | + $itemized_sum_diff_from_txn_total = round( |
|
496 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
497 | + 2 |
|
498 | + ); |
|
499 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
500 | + // add the difference as an extra line item. |
|
501 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
502 | + // Item Name. |
|
503 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
504 | + esc_html__( |
|
505 | + 'Other (promotion/surcharge/cancellation)', |
|
506 | + 'event_espresso' |
|
507 | + ), |
|
508 | + 0, |
|
509 | + 127 |
|
510 | + ); |
|
511 | + // Item description. |
|
512 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
513 | + // Cost of individual item. |
|
514 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
515 | + $itemized_sum_diff_from_txn_total |
|
516 | + ); |
|
517 | + // Item Number. |
|
518 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
519 | + // Item quantity. |
|
520 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
521 | + // Digital item is sold. |
|
522 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
523 | + $item_num++; |
|
524 | + } |
|
525 | + } else { |
|
526 | + // Just one Item. |
|
527 | + // Item Name. |
|
528 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
529 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
530 | + 0, |
|
531 | + 127 |
|
532 | + ); |
|
533 | + // Item description. |
|
534 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
535 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
536 | + 0, |
|
537 | + 127 |
|
538 | + ); |
|
539 | + // Cost of individual item. |
|
540 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
541 | + // Item Number. |
|
542 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
543 | + // Item quantity. |
|
544 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
545 | + // Digital item is sold. |
|
546 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
547 | + // Item's sales S/H and tax amount. |
|
548 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
549 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
550 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
551 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
552 | + } |
|
553 | + return $itemized_list; |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Make the Express checkout request. |
|
560 | + * |
|
561 | + * @param array $request_params |
|
562 | + * @param string $request_text |
|
563 | + * @param EEI_Payment $payment |
|
564 | + * @return mixed |
|
565 | + */ |
|
566 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
567 | + { |
|
568 | + $request_dtls = array( |
|
569 | + 'VERSION' => '204.0', |
|
570 | + 'USER' => urlencode($this->_api_username), |
|
571 | + 'PWD' => urlencode($this->_api_password), |
|
572 | + 'SIGNATURE' => urlencode($this->_api_signature), |
|
573 | + ); |
|
574 | + $dtls = array_merge($request_dtls, $request_params); |
|
575 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
576 | + // Request Customer Details. |
|
577 | + $request_response = wp_remote_post( |
|
578 | + $this->_base_gateway_url, |
|
579 | + array( |
|
580 | + 'method' => 'POST', |
|
581 | + 'timeout' => 45, |
|
582 | + 'httpversion' => '1.1', |
|
583 | + 'cookies' => array(), |
|
584 | + 'headers' => array(), |
|
585 | + 'body' => http_build_query($dtls, '', '&'), |
|
586 | + ) |
|
587 | + ); |
|
588 | + // Log the response. |
|
589 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
590 | + return $request_response; |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * Check the response status. |
|
597 | + * |
|
598 | + * @param mixed $request_response |
|
599 | + * @return array |
|
600 | + */ |
|
601 | + public function _ppExpress_check_response($request_response) |
|
602 | + { |
|
603 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
604 | + // If we got here then there was an error in this request. |
|
605 | + return array('status' => false, 'args' => $request_response); |
|
606 | + } |
|
607 | + $response_args = array(); |
|
608 | + parse_str(urldecode($request_response['body']), $response_args); |
|
609 | + if (! isset($response_args['ACK'])) { |
|
610 | + return array('status' => false, 'args' => $request_response); |
|
611 | + } |
|
612 | + if (( |
|
613 | + isset($response_args['PAYERID']) |
|
614 | + || isset($response_args['TOKEN']) |
|
615 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
616 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
617 | + ) |
|
618 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
619 | + ) { |
|
620 | + // Response status OK, return response parameters for further processing. |
|
621 | + return array('status' => true, 'args' => $response_args); |
|
622 | + } |
|
623 | + $errors = $this->_get_errors($response_args); |
|
624 | + return array('status' => false, 'args' => $errors); |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + |
|
629 | + /** |
|
630 | + * Log a "Cleared" request. |
|
631 | + * |
|
632 | + * @param array $request |
|
633 | + * @param EEI_Payment $payment |
|
634 | + * @param string $info |
|
635 | + * @return void |
|
636 | + */ |
|
637 | + private function _log_clean_request($request, $payment, $info) |
|
638 | + { |
|
639 | + $cleaned_request_data = $request; |
|
640 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
641 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
642 | + } |
|
643 | + |
|
644 | + |
|
645 | + |
|
646 | + /** |
|
647 | + * Get error from the response data. |
|
648 | + * |
|
649 | + * @param array $data_array |
|
650 | + * @return array |
|
651 | + */ |
|
652 | + private function _get_errors($data_array) |
|
653 | + { |
|
654 | + $errors = array(); |
|
655 | + $n = 0; |
|
656 | + while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
657 | + $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
658 | + ? $data_array[ "L_ERRORCODE{$n}" ] |
|
659 | + : ''; |
|
660 | + $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
661 | + ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
662 | + : ''; |
|
663 | + $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
664 | + ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
665 | + : ''; |
|
666 | + $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
667 | + ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
668 | + : ''; |
|
669 | + if ($n === 0) { |
|
670 | + $errors = array( |
|
671 | + 'L_ERRORCODE' => $l_error_code, |
|
672 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
673 | + 'L_LONGMESSAGE' => $l_long_message, |
|
674 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
675 | + ); |
|
676 | + } else { |
|
677 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
678 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
679 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
680 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
681 | + } |
|
682 | + $n++; |
|
683 | + } |
|
684 | + return $errors; |
|
685 | + } |
|
686 | 686 | } |
@@ -25,427 +25,427 @@ discard block |
||
25 | 25 | class EEG_Aim extends EE_Onsite_Gateway |
26 | 26 | { |
27 | 27 | |
28 | - const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL |
|
29 | - |
|
30 | - const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
31 | - |
|
32 | - protected $_login_id; |
|
33 | - |
|
34 | - protected $_transaction_key; |
|
35 | - |
|
36 | - protected $_server; |
|
37 | - |
|
38 | - protected $_currencies_supported = array( |
|
39 | - 'AUD', |
|
40 | - 'USD', |
|
41 | - 'CAD', |
|
42 | - 'EUR', |
|
43 | - 'GBP', |
|
44 | - 'NZD', |
|
45 | - ); |
|
46 | - |
|
47 | - /** |
|
48 | - * Whether to send test transactions (even to live site) |
|
49 | - * |
|
50 | - * @var boolean |
|
51 | - */ |
|
52 | - protected $_test_transactions; |
|
53 | - |
|
54 | - private $VERIFY_PEER = false; |
|
55 | - |
|
56 | - private $_x_post_fields = array( |
|
57 | - "version" => "3.1", |
|
58 | - "delim_char" => ",", |
|
59 | - "delim_data" => "TRUE", |
|
60 | - "relay_response" => "FALSE", |
|
61 | - "encap_char" => "|", |
|
62 | - ); |
|
63 | - |
|
64 | - private $_additional_line_items = array(); |
|
65 | - |
|
66 | - /** |
|
67 | - * A list of all fields in the AIM API. |
|
68 | - * Used to warn user if they try to set a field not offered in the API. |
|
69 | - */ |
|
70 | - private $_all_aim_fields = array( |
|
71 | - "address", |
|
72 | - "allow_partial_auth", |
|
73 | - "amount", |
|
74 | - "auth_code", |
|
75 | - "authentication_indicator", |
|
76 | - "bank_aba_code", |
|
77 | - "bank_acct_name", |
|
78 | - "bank_acct_num", |
|
79 | - "bank_acct_type", |
|
80 | - "bank_check_number", |
|
81 | - "bank_name", |
|
82 | - "card_code", |
|
83 | - "card_num", |
|
84 | - "cardholder_authentication_value", |
|
85 | - "city", |
|
86 | - "company", |
|
87 | - "country", |
|
88 | - "cust_id", |
|
89 | - "customer_ip", |
|
90 | - "delim_char", |
|
91 | - "delim_data", |
|
92 | - "description", |
|
93 | - "duplicate_window", |
|
94 | - "duty", |
|
95 | - "echeck_type", |
|
96 | - "email", |
|
97 | - "email_customer", |
|
98 | - "encap_char", |
|
99 | - "exp_date", |
|
100 | - "fax", |
|
101 | - "first_name", |
|
102 | - "footer_email_receipt", |
|
103 | - "freight", |
|
104 | - "header_email_receipt", |
|
105 | - "invoice_num", |
|
106 | - "last_name", |
|
107 | - "line_item", |
|
108 | - "login", |
|
109 | - "method", |
|
110 | - "phone", |
|
111 | - "po_num", |
|
112 | - "recurring_billing", |
|
113 | - "relay_response", |
|
114 | - "ship_to_address", |
|
115 | - "ship_to_city", |
|
116 | - "ship_to_company", |
|
117 | - "ship_to_country", |
|
118 | - "ship_to_first_name", |
|
119 | - "ship_to_last_name", |
|
120 | - "ship_to_state", |
|
121 | - "ship_to_zip", |
|
122 | - "split_tender_id", |
|
123 | - "state", |
|
124 | - "tax", |
|
125 | - "tax_exempt", |
|
126 | - "test_request", |
|
127 | - "tran_key", |
|
128 | - "trans_id", |
|
129 | - "type", |
|
130 | - "version", |
|
131 | - "zip", |
|
132 | - "solution_id", |
|
133 | - "currency_code" |
|
134 | - ); |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Gets the URL where the request should go. This is filterable |
|
139 | - * |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - protected function _get_server_url() |
|
143 | - { |
|
144 | - return apply_filters( |
|
145 | - 'FHEE__EEG_Aim___get_server_url', |
|
146 | - $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
147 | - $this |
|
148 | - ); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * TEMPORARY CALLBACK! Do not use |
|
154 | - * Callback which filters the server url. This is added so site admins can revert to using |
|
155 | - * the old AIM server in case Akamai service breaks their integration. |
|
156 | - * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
157 | - * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
158 | - * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
159 | - * |
|
160 | - * @param string $url |
|
161 | - * @param EEG_Aim $gateway_object |
|
162 | - * @return string |
|
163 | - */ |
|
164 | - public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
165 | - { |
|
166 | - if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
167 | - return 'https://secure.authorize.net/gateway/transact.dll'; |
|
168 | - } else { |
|
169 | - return $url; |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
176 | - * usually send a request directly to the payment provider and update the payment's status based on that; |
|
177 | - * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
178 | - * for sending the request via http_remote_request() |
|
179 | - * |
|
180 | - * @param EEI_Payment $payment |
|
181 | - * @param array $billing_info { |
|
182 | - * @type $credit_card string |
|
183 | - * @type $cvv string |
|
184 | - * @type $exp_month string |
|
185 | - * @type $exp_year string |
|
186 | - * @see parent::do_direct_payment |
|
187 | - * } |
|
188 | - * @return EEI_Payment updated |
|
189 | - */ |
|
190 | - public function do_direct_payment($payment, $billing_info = null) |
|
191 | - { |
|
192 | - add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
193 | - // Enable test mode if needed |
|
194 | - // 4007000000027 <-- test successful visa |
|
195 | - // 4222222222222 <-- test failure card number |
|
196 | - |
|
197 | - $item_num = 1; |
|
198 | - $transaction = $payment->transaction(); |
|
199 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
200 | - $order_description = $gateway_formatter->formatOrderDescription($payment); |
|
201 | - $primary_registrant = $transaction->primary_registration(); |
|
202 | - // if we're are charging for the full amount, show the normal line items |
|
203 | - // and the itemized total adds up properly |
|
204 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
205 | - $total_line_item = $transaction->total_line_item(); |
|
206 | - foreach ($total_line_item->get_items() as $line_item) { |
|
207 | - if ($line_item->quantity() == 0) { |
|
208 | - continue; |
|
209 | - } |
|
210 | - $this->addLineItem( |
|
211 | - $item_num++, |
|
212 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
213 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
214 | - $line_item->quantity(), |
|
215 | - $line_item->unit_price(), |
|
216 | - 'N' |
|
217 | - ); |
|
218 | - $order_description .= $line_item->desc().', '; |
|
219 | - } |
|
220 | - foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
221 | - $this->addLineItem( |
|
222 | - $item_num++, |
|
223 | - $tax_line_item->name(), |
|
224 | - $tax_line_item->desc(), |
|
225 | - 1, |
|
226 | - $tax_line_item->total(), |
|
227 | - 'N' |
|
228 | - ); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - // start transaction |
|
233 | - // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
234 | - $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
235 | - $this->setField('solution_id', $partner_id); |
|
236 | - $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
237 | - $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
238 | - $this->_set_sensitive_billing_data($billing_info); |
|
239 | - $this->setField('first_name', $billing_info['first_name']); |
|
240 | - $this->setField('last_name', $billing_info['last_name']); |
|
241 | - $this->setField('email', $billing_info['email']); |
|
242 | - $this->setField('company', $billing_info['company']); |
|
243 | - $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
244 | - $this->setField('city', $billing_info['city']); |
|
245 | - $this->setField('state', $billing_info['state']); |
|
246 | - $this->setField('country', $billing_info['country']); |
|
247 | - $this->setField('zip', $billing_info['zip']); |
|
248 | - $this->setField('fax', $billing_info['fax']); |
|
249 | - $this->setField('cust_id', $primary_registrant->ID()); |
|
250 | - $this->setField('phone', $billing_info['phone']); |
|
251 | - $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config'); |
|
252 | - $this->setField('currency_code', $currency_config->code); |
|
253 | - // invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
254 | - // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
255 | - // in which case, we need to generate teh invoice num per request right here... |
|
256 | - $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
257 | - // tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
258 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
259 | - |
|
260 | - if ($this->_test_transactions) { |
|
261 | - $this->test_request = "true"; |
|
262 | - } |
|
263 | - |
|
264 | - // Capture response |
|
265 | - $this->type = "AUTH_CAPTURE"; |
|
266 | - $response = $this->_sendRequest($payment); |
|
267 | - if (! empty($response)) { |
|
268 | - if ($response->error_message) { |
|
269 | - $payment->set_status($this->_pay_model->failed_status()); |
|
270 | - $payment->set_gateway_response($response->error_message); |
|
271 | - } else { |
|
272 | - $payment_status = $response->approved |
|
273 | - ? $this->_pay_model->approved_status() |
|
274 | - : $this->_pay_model->declined_status(); |
|
275 | - $payment->set_status($payment_status); |
|
276 | - // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
277 | - $payment->set_amount((float) $response->amount); |
|
278 | - $payment->set_gateway_response( |
|
279 | - sprintf( |
|
280 | - esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
281 | - $response->response_reason_text, |
|
282 | - $response->response_reason_code |
|
283 | - ) |
|
284 | - ); |
|
285 | - if ($this->_debug_mode) { |
|
286 | - $txn_id = $response->invoice_number; |
|
287 | - } else { |
|
288 | - $txn_id = $response->transaction_id; |
|
289 | - } |
|
290 | - $payment->set_txn_id_chq_nmbr($txn_id); |
|
291 | - } |
|
292 | - $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
293 | - $payment->set_details(print_r($response, true)); |
|
294 | - } else { |
|
295 | - $payment->set_status($this->_pay_model->failed_status()); |
|
296 | - $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
297 | - $payment->set_details(print_r($response, true)); |
|
298 | - } |
|
299 | - return $payment; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
305 | - * also this method can be overridden by children classes to easily change |
|
306 | - * what billing data gets sent |
|
307 | - * |
|
308 | - * @param array $billing_info |
|
309 | - */ |
|
310 | - protected function _set_sensitive_billing_data($billing_info) |
|
311 | - { |
|
312 | - $this->setField('card_num', $billing_info['credit_card']); |
|
313 | - $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
314 | - $this->setField('card_code', $billing_info['cvv']); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Add a line item. |
|
320 | - * |
|
321 | - * @param string $item_id |
|
322 | - * @param string $item_name |
|
323 | - * @param string $item_description |
|
324 | - * @param string $item_quantity |
|
325 | - * @param string $item_unit_price |
|
326 | - * @param string $item_taxable |
|
327 | - */ |
|
328 | - public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
329 | - { |
|
330 | - $args = array( |
|
331 | - substr($item_id, 0, 31), |
|
332 | - substr($item_name, 0, 31), |
|
333 | - substr($item_description, 0, 255), |
|
334 | - number_format(abs($item_quantity), 2, '.', ''), |
|
335 | - number_format(abs($item_unit_price), 2, '.', ''), |
|
336 | - $item_taxable === 'N' ? 'N' : 'Y' |
|
337 | - ); |
|
338 | - $this->_additional_line_items[] = implode('<|>', $args); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * Set an individual name/value pair. This will append x_ to the name |
|
344 | - * before posting. |
|
345 | - * |
|
346 | - * @param string $name |
|
347 | - * @param string $value |
|
348 | - * @throws AuthorizeNetException |
|
349 | - */ |
|
350 | - protected function setField($name, $value) |
|
351 | - { |
|
352 | - if (in_array($name, $this->_all_aim_fields)) { |
|
353 | - $this->_x_post_fields[ $name ] = $value; |
|
354 | - } else { |
|
355 | - throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
28 | + const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL |
|
29 | + |
|
30 | + const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
31 | + |
|
32 | + protected $_login_id; |
|
33 | + |
|
34 | + protected $_transaction_key; |
|
35 | + |
|
36 | + protected $_server; |
|
37 | + |
|
38 | + protected $_currencies_supported = array( |
|
39 | + 'AUD', |
|
40 | + 'USD', |
|
41 | + 'CAD', |
|
42 | + 'EUR', |
|
43 | + 'GBP', |
|
44 | + 'NZD', |
|
45 | + ); |
|
46 | + |
|
47 | + /** |
|
48 | + * Whether to send test transactions (even to live site) |
|
49 | + * |
|
50 | + * @var boolean |
|
51 | + */ |
|
52 | + protected $_test_transactions; |
|
53 | + |
|
54 | + private $VERIFY_PEER = false; |
|
55 | + |
|
56 | + private $_x_post_fields = array( |
|
57 | + "version" => "3.1", |
|
58 | + "delim_char" => ",", |
|
59 | + "delim_data" => "TRUE", |
|
60 | + "relay_response" => "FALSE", |
|
61 | + "encap_char" => "|", |
|
62 | + ); |
|
63 | + |
|
64 | + private $_additional_line_items = array(); |
|
65 | + |
|
66 | + /** |
|
67 | + * A list of all fields in the AIM API. |
|
68 | + * Used to warn user if they try to set a field not offered in the API. |
|
69 | + */ |
|
70 | + private $_all_aim_fields = array( |
|
71 | + "address", |
|
72 | + "allow_partial_auth", |
|
73 | + "amount", |
|
74 | + "auth_code", |
|
75 | + "authentication_indicator", |
|
76 | + "bank_aba_code", |
|
77 | + "bank_acct_name", |
|
78 | + "bank_acct_num", |
|
79 | + "bank_acct_type", |
|
80 | + "bank_check_number", |
|
81 | + "bank_name", |
|
82 | + "card_code", |
|
83 | + "card_num", |
|
84 | + "cardholder_authentication_value", |
|
85 | + "city", |
|
86 | + "company", |
|
87 | + "country", |
|
88 | + "cust_id", |
|
89 | + "customer_ip", |
|
90 | + "delim_char", |
|
91 | + "delim_data", |
|
92 | + "description", |
|
93 | + "duplicate_window", |
|
94 | + "duty", |
|
95 | + "echeck_type", |
|
96 | + "email", |
|
97 | + "email_customer", |
|
98 | + "encap_char", |
|
99 | + "exp_date", |
|
100 | + "fax", |
|
101 | + "first_name", |
|
102 | + "footer_email_receipt", |
|
103 | + "freight", |
|
104 | + "header_email_receipt", |
|
105 | + "invoice_num", |
|
106 | + "last_name", |
|
107 | + "line_item", |
|
108 | + "login", |
|
109 | + "method", |
|
110 | + "phone", |
|
111 | + "po_num", |
|
112 | + "recurring_billing", |
|
113 | + "relay_response", |
|
114 | + "ship_to_address", |
|
115 | + "ship_to_city", |
|
116 | + "ship_to_company", |
|
117 | + "ship_to_country", |
|
118 | + "ship_to_first_name", |
|
119 | + "ship_to_last_name", |
|
120 | + "ship_to_state", |
|
121 | + "ship_to_zip", |
|
122 | + "split_tender_id", |
|
123 | + "state", |
|
124 | + "tax", |
|
125 | + "tax_exempt", |
|
126 | + "test_request", |
|
127 | + "tran_key", |
|
128 | + "trans_id", |
|
129 | + "type", |
|
130 | + "version", |
|
131 | + "zip", |
|
132 | + "solution_id", |
|
133 | + "currency_code" |
|
134 | + ); |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Gets the URL where the request should go. This is filterable |
|
139 | + * |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + protected function _get_server_url() |
|
143 | + { |
|
144 | + return apply_filters( |
|
145 | + 'FHEE__EEG_Aim___get_server_url', |
|
146 | + $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
147 | + $this |
|
148 | + ); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * TEMPORARY CALLBACK! Do not use |
|
154 | + * Callback which filters the server url. This is added so site admins can revert to using |
|
155 | + * the old AIM server in case Akamai service breaks their integration. |
|
156 | + * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
157 | + * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
158 | + * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
159 | + * |
|
160 | + * @param string $url |
|
161 | + * @param EEG_Aim $gateway_object |
|
162 | + * @return string |
|
163 | + */ |
|
164 | + public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
165 | + { |
|
166 | + if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
167 | + return 'https://secure.authorize.net/gateway/transact.dll'; |
|
168 | + } else { |
|
169 | + return $url; |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
176 | + * usually send a request directly to the payment provider and update the payment's status based on that; |
|
177 | + * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
178 | + * for sending the request via http_remote_request() |
|
179 | + * |
|
180 | + * @param EEI_Payment $payment |
|
181 | + * @param array $billing_info { |
|
182 | + * @type $credit_card string |
|
183 | + * @type $cvv string |
|
184 | + * @type $exp_month string |
|
185 | + * @type $exp_year string |
|
186 | + * @see parent::do_direct_payment |
|
187 | + * } |
|
188 | + * @return EEI_Payment updated |
|
189 | + */ |
|
190 | + public function do_direct_payment($payment, $billing_info = null) |
|
191 | + { |
|
192 | + add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
193 | + // Enable test mode if needed |
|
194 | + // 4007000000027 <-- test successful visa |
|
195 | + // 4222222222222 <-- test failure card number |
|
196 | + |
|
197 | + $item_num = 1; |
|
198 | + $transaction = $payment->transaction(); |
|
199 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
200 | + $order_description = $gateway_formatter->formatOrderDescription($payment); |
|
201 | + $primary_registrant = $transaction->primary_registration(); |
|
202 | + // if we're are charging for the full amount, show the normal line items |
|
203 | + // and the itemized total adds up properly |
|
204 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
205 | + $total_line_item = $transaction->total_line_item(); |
|
206 | + foreach ($total_line_item->get_items() as $line_item) { |
|
207 | + if ($line_item->quantity() == 0) { |
|
208 | + continue; |
|
209 | + } |
|
210 | + $this->addLineItem( |
|
211 | + $item_num++, |
|
212 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
213 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
214 | + $line_item->quantity(), |
|
215 | + $line_item->unit_price(), |
|
216 | + 'N' |
|
217 | + ); |
|
218 | + $order_description .= $line_item->desc().', '; |
|
219 | + } |
|
220 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
221 | + $this->addLineItem( |
|
222 | + $item_num++, |
|
223 | + $tax_line_item->name(), |
|
224 | + $tax_line_item->desc(), |
|
225 | + 1, |
|
226 | + $tax_line_item->total(), |
|
227 | + 'N' |
|
228 | + ); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + // start transaction |
|
233 | + // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
234 | + $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
235 | + $this->setField('solution_id', $partner_id); |
|
236 | + $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
237 | + $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
238 | + $this->_set_sensitive_billing_data($billing_info); |
|
239 | + $this->setField('first_name', $billing_info['first_name']); |
|
240 | + $this->setField('last_name', $billing_info['last_name']); |
|
241 | + $this->setField('email', $billing_info['email']); |
|
242 | + $this->setField('company', $billing_info['company']); |
|
243 | + $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
244 | + $this->setField('city', $billing_info['city']); |
|
245 | + $this->setField('state', $billing_info['state']); |
|
246 | + $this->setField('country', $billing_info['country']); |
|
247 | + $this->setField('zip', $billing_info['zip']); |
|
248 | + $this->setField('fax', $billing_info['fax']); |
|
249 | + $this->setField('cust_id', $primary_registrant->ID()); |
|
250 | + $this->setField('phone', $billing_info['phone']); |
|
251 | + $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config'); |
|
252 | + $this->setField('currency_code', $currency_config->code); |
|
253 | + // invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
254 | + // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
255 | + // in which case, we need to generate teh invoice num per request right here... |
|
256 | + $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
257 | + // tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
258 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
259 | + |
|
260 | + if ($this->_test_transactions) { |
|
261 | + $this->test_request = "true"; |
|
262 | + } |
|
263 | + |
|
264 | + // Capture response |
|
265 | + $this->type = "AUTH_CAPTURE"; |
|
266 | + $response = $this->_sendRequest($payment); |
|
267 | + if (! empty($response)) { |
|
268 | + if ($response->error_message) { |
|
269 | + $payment->set_status($this->_pay_model->failed_status()); |
|
270 | + $payment->set_gateway_response($response->error_message); |
|
271 | + } else { |
|
272 | + $payment_status = $response->approved |
|
273 | + ? $this->_pay_model->approved_status() |
|
274 | + : $this->_pay_model->declined_status(); |
|
275 | + $payment->set_status($payment_status); |
|
276 | + // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
277 | + $payment->set_amount((float) $response->amount); |
|
278 | + $payment->set_gateway_response( |
|
279 | + sprintf( |
|
280 | + esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
281 | + $response->response_reason_text, |
|
282 | + $response->response_reason_code |
|
283 | + ) |
|
284 | + ); |
|
285 | + if ($this->_debug_mode) { |
|
286 | + $txn_id = $response->invoice_number; |
|
287 | + } else { |
|
288 | + $txn_id = $response->transaction_id; |
|
289 | + } |
|
290 | + $payment->set_txn_id_chq_nmbr($txn_id); |
|
291 | + } |
|
292 | + $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
293 | + $payment->set_details(print_r($response, true)); |
|
294 | + } else { |
|
295 | + $payment->set_status($this->_pay_model->failed_status()); |
|
296 | + $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
297 | + $payment->set_details(print_r($response, true)); |
|
298 | + } |
|
299 | + return $payment; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
305 | + * also this method can be overridden by children classes to easily change |
|
306 | + * what billing data gets sent |
|
307 | + * |
|
308 | + * @param array $billing_info |
|
309 | + */ |
|
310 | + protected function _set_sensitive_billing_data($billing_info) |
|
311 | + { |
|
312 | + $this->setField('card_num', $billing_info['credit_card']); |
|
313 | + $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
314 | + $this->setField('card_code', $billing_info['cvv']); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Add a line item. |
|
320 | + * |
|
321 | + * @param string $item_id |
|
322 | + * @param string $item_name |
|
323 | + * @param string $item_description |
|
324 | + * @param string $item_quantity |
|
325 | + * @param string $item_unit_price |
|
326 | + * @param string $item_taxable |
|
327 | + */ |
|
328 | + public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
329 | + { |
|
330 | + $args = array( |
|
331 | + substr($item_id, 0, 31), |
|
332 | + substr($item_name, 0, 31), |
|
333 | + substr($item_description, 0, 255), |
|
334 | + number_format(abs($item_quantity), 2, '.', ''), |
|
335 | + number_format(abs($item_unit_price), 2, '.', ''), |
|
336 | + $item_taxable === 'N' ? 'N' : 'Y' |
|
337 | + ); |
|
338 | + $this->_additional_line_items[] = implode('<|>', $args); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * Set an individual name/value pair. This will append x_ to the name |
|
344 | + * before posting. |
|
345 | + * |
|
346 | + * @param string $name |
|
347 | + * @param string $value |
|
348 | + * @throws AuthorizeNetException |
|
349 | + */ |
|
350 | + protected function setField($name, $value) |
|
351 | + { |
|
352 | + if (in_array($name, $this->_all_aim_fields)) { |
|
353 | + $this->_x_post_fields[ $name ] = $value; |
|
354 | + } else { |
|
355 | + throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
356 | 356 | To set a custom field use setCustomField('field','value') instead."); |
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Posts the request to AuthorizeNet & returns response. |
|
363 | - * |
|
364 | - * @param $payment |
|
365 | - * @return \EE_AuthorizeNetAIM_Response |
|
366 | - */ |
|
367 | - private function _sendRequest($payment) |
|
368 | - { |
|
369 | - $this->_x_post_fields['login'] = $this->_login_id; |
|
370 | - $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
371 | - $x_keys = array(); |
|
372 | - foreach ($this->_x_post_fields as $key => $value) { |
|
373 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
374 | - } |
|
375 | - // Add line items |
|
376 | - foreach ($this->_additional_line_items as $key => $value) { |
|
377 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
378 | - } |
|
379 | - $this->_log_clean_request($x_keys, $payment); |
|
380 | - $post_url = $this->_get_server_url(); |
|
381 | - $curl_request = curl_init($post_url); |
|
382 | - $post_body = implode("&", $x_keys); |
|
383 | - curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
384 | - curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
385 | - curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
386 | - curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
387 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
388 | - if ($this->VERIFY_PEER) { |
|
389 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
390 | - } else { |
|
391 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
392 | - } |
|
393 | - |
|
394 | - if (preg_match('/xml/', $post_url)) { |
|
395 | - curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); |
|
396 | - } |
|
397 | - |
|
398 | - $response = curl_exec($curl_request); |
|
399 | - |
|
400 | - curl_close($curl_request); |
|
401 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
402 | - |
|
403 | - return $this->_log_and_clean_response($response_obj, $payment); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Logs the clean data only |
|
409 | - * |
|
410 | - * @param array $request_array |
|
411 | - * @param EEI_Payment $payment |
|
412 | - */ |
|
413 | - protected function _log_clean_request($request_array, $payment) |
|
414 | - { |
|
415 | - $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
416 | - foreach ($request_array as $index => $keyvaltogether) { |
|
417 | - foreach ($keys_to_filter_out as $key) { |
|
418 | - if (strpos($keyvaltogether, $key) === 0) { |
|
419 | - // found it at the first character |
|
420 | - // so its one of them |
|
421 | - unset($request_array[ $index ]); |
|
422 | - } |
|
423 | - } |
|
424 | - } |
|
425 | - $this->log( |
|
426 | - array( |
|
427 | - 'AIM Request sent:' => $request_array, |
|
428 | - 'Server URL' => $this->_get_server_url() |
|
429 | - ), |
|
430 | - $payment |
|
431 | - ); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Logs the response and cleans it |
|
438 | - * |
|
439 | - * @param EE_AuthorizeNetAIM_Response $response_obj |
|
440 | - * @param EE_Payment $payment |
|
441 | - * @return \EE_AuthorizeNetAIM_Response |
|
442 | - */ |
|
443 | - private function _log_and_clean_response($response_obj, $payment) |
|
444 | - { |
|
445 | - $response_obj->account_number = ''; |
|
446 | - $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
447 | - return $response_obj; |
|
448 | - } |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Posts the request to AuthorizeNet & returns response. |
|
363 | + * |
|
364 | + * @param $payment |
|
365 | + * @return \EE_AuthorizeNetAIM_Response |
|
366 | + */ |
|
367 | + private function _sendRequest($payment) |
|
368 | + { |
|
369 | + $this->_x_post_fields['login'] = $this->_login_id; |
|
370 | + $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
371 | + $x_keys = array(); |
|
372 | + foreach ($this->_x_post_fields as $key => $value) { |
|
373 | + $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
374 | + } |
|
375 | + // Add line items |
|
376 | + foreach ($this->_additional_line_items as $key => $value) { |
|
377 | + $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
378 | + } |
|
379 | + $this->_log_clean_request($x_keys, $payment); |
|
380 | + $post_url = $this->_get_server_url(); |
|
381 | + $curl_request = curl_init($post_url); |
|
382 | + $post_body = implode("&", $x_keys); |
|
383 | + curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
384 | + curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
385 | + curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
386 | + curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
387 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
388 | + if ($this->VERIFY_PEER) { |
|
389 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
390 | + } else { |
|
391 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
392 | + } |
|
393 | + |
|
394 | + if (preg_match('/xml/', $post_url)) { |
|
395 | + curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); |
|
396 | + } |
|
397 | + |
|
398 | + $response = curl_exec($curl_request); |
|
399 | + |
|
400 | + curl_close($curl_request); |
|
401 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
402 | + |
|
403 | + return $this->_log_and_clean_response($response_obj, $payment); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Logs the clean data only |
|
409 | + * |
|
410 | + * @param array $request_array |
|
411 | + * @param EEI_Payment $payment |
|
412 | + */ |
|
413 | + protected function _log_clean_request($request_array, $payment) |
|
414 | + { |
|
415 | + $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
416 | + foreach ($request_array as $index => $keyvaltogether) { |
|
417 | + foreach ($keys_to_filter_out as $key) { |
|
418 | + if (strpos($keyvaltogether, $key) === 0) { |
|
419 | + // found it at the first character |
|
420 | + // so its one of them |
|
421 | + unset($request_array[ $index ]); |
|
422 | + } |
|
423 | + } |
|
424 | + } |
|
425 | + $this->log( |
|
426 | + array( |
|
427 | + 'AIM Request sent:' => $request_array, |
|
428 | + 'Server URL' => $this->_get_server_url() |
|
429 | + ), |
|
430 | + $payment |
|
431 | + ); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Logs the response and cleans it |
|
438 | + * |
|
439 | + * @param EE_AuthorizeNetAIM_Response $response_obj |
|
440 | + * @param EE_Payment $payment |
|
441 | + * @return \EE_AuthorizeNetAIM_Response |
|
442 | + */ |
|
443 | + private function _log_and_clean_response($response_obj, $payment) |
|
444 | + { |
|
445 | + $response_obj->account_number = ''; |
|
446 | + $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
447 | + return $response_obj; |
|
448 | + } |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | |
@@ -461,192 +461,192 @@ discard block |
||
461 | 461 | class EE_AuthorizeNetAIM_Response |
462 | 462 | { |
463 | 463 | |
464 | - const APPROVED = '1'; |
|
465 | - const DECLINED = '2'; |
|
466 | - const ERROR = '3'; |
|
467 | - const HELD = '4'; |
|
468 | - |
|
469 | - protected $_x_post_fields = array( |
|
470 | - "version" => "3.1", |
|
471 | - "delim_char" => ",", |
|
472 | - "delim_data" => "TRUE", |
|
473 | - "relay_response" => "FALSE", |
|
474 | - "encap_char" => "|", |
|
475 | - ); |
|
476 | - public $approved; |
|
477 | - public $declined; |
|
478 | - public $error; |
|
479 | - public $held; |
|
480 | - public $response_code; |
|
481 | - public $response_subcode; |
|
482 | - public $response_reason_code; |
|
483 | - public $response_reason_text; |
|
484 | - public $authorization_code; |
|
485 | - public $avs_response; |
|
486 | - public $transaction_id; |
|
487 | - public $invoice_number; |
|
488 | - public $description; |
|
489 | - public $amount; |
|
490 | - public $method; |
|
491 | - public $transaction_type; |
|
492 | - public $customer_id; |
|
493 | - public $first_name; |
|
494 | - public $last_name; |
|
495 | - public $company; |
|
496 | - public $address; |
|
497 | - public $city; |
|
498 | - public $state; |
|
499 | - public $zip_code; |
|
500 | - public $country; |
|
501 | - public $phone; |
|
502 | - public $fax; |
|
503 | - public $email_address; |
|
504 | - public $ship_to_first_name; |
|
505 | - public $ship_to_last_name; |
|
506 | - public $ship_to_company; |
|
507 | - public $ship_to_address; |
|
508 | - public $ship_to_city; |
|
509 | - public $ship_to_state; |
|
510 | - public $ship_to_zip_code; |
|
511 | - public $ship_to_country; |
|
512 | - public $tax; |
|
513 | - public $duty; |
|
514 | - public $freight; |
|
515 | - public $tax_exempt; |
|
516 | - public $purchase_order_number; |
|
517 | - public $md5_hash; |
|
518 | - public $card_code_response; |
|
519 | - public $cavv_response; // cardholder_authentication_verification_response |
|
520 | - public $account_number; |
|
521 | - public $card_type; |
|
522 | - public $split_tender_id; |
|
523 | - public $requested_amount; |
|
524 | - public $balance_on_card; |
|
525 | - public $response; // The response string from AuthorizeNet. |
|
526 | - public $error_message; |
|
527 | - private $_response_array = array(); // An array with the split response. |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * Constructor. Parses the AuthorizeNet response string |
|
532 | - * |
|
533 | - * @param string $response The response from the AuthNet server. |
|
534 | - * @var string $delimiter The delimiter used (default is ",") |
|
535 | - * @var string $encap_char The encap_char used (default is "|") |
|
536 | - * @var array $custom_fields Any custom fields set in the request. |
|
537 | - */ |
|
538 | - |
|
539 | - public function __construct($response) |
|
540 | - { |
|
541 | - $encap_char = $this->_x_post_fields['encap_char']; |
|
542 | - $delimiter = $this->_x_post_fields['delim_char']; |
|
543 | - if ($response) { |
|
544 | - // Split Array |
|
545 | - $this->response = $response; |
|
546 | - if ($encap_char) { |
|
547 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
548 | - } else { |
|
549 | - $this->_response_array = explode($delimiter, $response); |
|
550 | - } |
|
551 | - |
|
552 | - /** |
|
553 | - * If AuthorizeNet doesn't return a delimited response. |
|
554 | - */ |
|
555 | - if (count($this->_response_array) < 10) { |
|
556 | - $this->approved = false; |
|
557 | - $this->error = true; |
|
558 | - $this->error_message = sprintf( |
|
559 | - esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
560 | - esc_html($response) |
|
561 | - ); |
|
562 | - return; |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - |
|
567 | - // Set all fields |
|
568 | - $this->response_code = $this->_response_array[0]; |
|
569 | - $this->response_subcode = $this->_response_array[1]; |
|
570 | - $this->response_reason_code = $this->_response_array[2]; |
|
571 | - $this->response_reason_text = $this->_response_array[3]; |
|
572 | - $this->authorization_code = $this->_response_array[4]; |
|
573 | - $this->avs_response = $this->_response_array[5]; |
|
574 | - $this->transaction_id = $this->_response_array[6]; |
|
575 | - $this->invoice_number = $this->_response_array[7]; |
|
576 | - $this->description = $this->_response_array[8]; |
|
577 | - $this->amount = $this->_response_array[9]; |
|
578 | - $this->method = $this->_response_array[10]; |
|
579 | - $this->transaction_type = $this->_response_array[11]; |
|
580 | - $this->customer_id = $this->_response_array[12]; |
|
581 | - $this->first_name = $this->_response_array[13]; |
|
582 | - $this->last_name = $this->_response_array[14]; |
|
583 | - $this->company = $this->_response_array[15]; |
|
584 | - $this->address = $this->_response_array[16]; |
|
585 | - $this->city = $this->_response_array[17]; |
|
586 | - $this->state = $this->_response_array[18]; |
|
587 | - $this->zip_code = $this->_response_array[19]; |
|
588 | - $this->country = $this->_response_array[20]; |
|
589 | - $this->phone = $this->_response_array[21]; |
|
590 | - $this->fax = $this->_response_array[22]; |
|
591 | - $this->email_address = $this->_response_array[23]; |
|
592 | - $this->ship_to_first_name = $this->_response_array[24]; |
|
593 | - $this->ship_to_last_name = $this->_response_array[25]; |
|
594 | - $this->ship_to_company = $this->_response_array[26]; |
|
595 | - $this->ship_to_address = $this->_response_array[27]; |
|
596 | - $this->ship_to_city = $this->_response_array[28]; |
|
597 | - $this->ship_to_state = $this->_response_array[29]; |
|
598 | - $this->ship_to_zip_code = $this->_response_array[30]; |
|
599 | - $this->ship_to_country = $this->_response_array[31]; |
|
600 | - $this->tax = $this->_response_array[32]; |
|
601 | - $this->duty = $this->_response_array[33]; |
|
602 | - $this->freight = $this->_response_array[34]; |
|
603 | - $this->tax_exempt = $this->_response_array[35]; |
|
604 | - $this->purchase_order_number = $this->_response_array[36]; |
|
605 | - $this->md5_hash = $this->_response_array[37]; |
|
606 | - $this->card_code_response = $this->_response_array[38]; |
|
607 | - $this->cavv_response = $this->_response_array[39]; |
|
608 | - $this->account_number = $this->_response_array[50]; |
|
609 | - $this->card_type = $this->_response_array[51]; |
|
610 | - $this->split_tender_id = $this->_response_array[52]; |
|
611 | - $this->requested_amount = $this->_response_array[53]; |
|
612 | - $this->balance_on_card = $this->_response_array[54]; |
|
613 | - |
|
614 | - $this->approved = ($this->response_code === self::APPROVED); |
|
615 | - $this->declined = ($this->response_code === self::DECLINED); |
|
616 | - $this->error = ($this->response_code === self::ERROR); |
|
617 | - $this->held = ($this->response_code === self::HELD); |
|
618 | - } else { |
|
619 | - $this->approved = false; |
|
620 | - $this->error = true; |
|
621 | - $this->error_message = esc_html__( |
|
622 | - 'Error connecting to Authorize.net', |
|
623 | - 'event_espresso' |
|
624 | - ); |
|
625 | - } |
|
626 | - } |
|
464 | + const APPROVED = '1'; |
|
465 | + const DECLINED = '2'; |
|
466 | + const ERROR = '3'; |
|
467 | + const HELD = '4'; |
|
468 | + |
|
469 | + protected $_x_post_fields = array( |
|
470 | + "version" => "3.1", |
|
471 | + "delim_char" => ",", |
|
472 | + "delim_data" => "TRUE", |
|
473 | + "relay_response" => "FALSE", |
|
474 | + "encap_char" => "|", |
|
475 | + ); |
|
476 | + public $approved; |
|
477 | + public $declined; |
|
478 | + public $error; |
|
479 | + public $held; |
|
480 | + public $response_code; |
|
481 | + public $response_subcode; |
|
482 | + public $response_reason_code; |
|
483 | + public $response_reason_text; |
|
484 | + public $authorization_code; |
|
485 | + public $avs_response; |
|
486 | + public $transaction_id; |
|
487 | + public $invoice_number; |
|
488 | + public $description; |
|
489 | + public $amount; |
|
490 | + public $method; |
|
491 | + public $transaction_type; |
|
492 | + public $customer_id; |
|
493 | + public $first_name; |
|
494 | + public $last_name; |
|
495 | + public $company; |
|
496 | + public $address; |
|
497 | + public $city; |
|
498 | + public $state; |
|
499 | + public $zip_code; |
|
500 | + public $country; |
|
501 | + public $phone; |
|
502 | + public $fax; |
|
503 | + public $email_address; |
|
504 | + public $ship_to_first_name; |
|
505 | + public $ship_to_last_name; |
|
506 | + public $ship_to_company; |
|
507 | + public $ship_to_address; |
|
508 | + public $ship_to_city; |
|
509 | + public $ship_to_state; |
|
510 | + public $ship_to_zip_code; |
|
511 | + public $ship_to_country; |
|
512 | + public $tax; |
|
513 | + public $duty; |
|
514 | + public $freight; |
|
515 | + public $tax_exempt; |
|
516 | + public $purchase_order_number; |
|
517 | + public $md5_hash; |
|
518 | + public $card_code_response; |
|
519 | + public $cavv_response; // cardholder_authentication_verification_response |
|
520 | + public $account_number; |
|
521 | + public $card_type; |
|
522 | + public $split_tender_id; |
|
523 | + public $requested_amount; |
|
524 | + public $balance_on_card; |
|
525 | + public $response; // The response string from AuthorizeNet. |
|
526 | + public $error_message; |
|
527 | + private $_response_array = array(); // An array with the split response. |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * Constructor. Parses the AuthorizeNet response string |
|
532 | + * |
|
533 | + * @param string $response The response from the AuthNet server. |
|
534 | + * @var string $delimiter The delimiter used (default is ",") |
|
535 | + * @var string $encap_char The encap_char used (default is "|") |
|
536 | + * @var array $custom_fields Any custom fields set in the request. |
|
537 | + */ |
|
538 | + |
|
539 | + public function __construct($response) |
|
540 | + { |
|
541 | + $encap_char = $this->_x_post_fields['encap_char']; |
|
542 | + $delimiter = $this->_x_post_fields['delim_char']; |
|
543 | + if ($response) { |
|
544 | + // Split Array |
|
545 | + $this->response = $response; |
|
546 | + if ($encap_char) { |
|
547 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
548 | + } else { |
|
549 | + $this->_response_array = explode($delimiter, $response); |
|
550 | + } |
|
551 | + |
|
552 | + /** |
|
553 | + * If AuthorizeNet doesn't return a delimited response. |
|
554 | + */ |
|
555 | + if (count($this->_response_array) < 10) { |
|
556 | + $this->approved = false; |
|
557 | + $this->error = true; |
|
558 | + $this->error_message = sprintf( |
|
559 | + esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
560 | + esc_html($response) |
|
561 | + ); |
|
562 | + return; |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + |
|
567 | + // Set all fields |
|
568 | + $this->response_code = $this->_response_array[0]; |
|
569 | + $this->response_subcode = $this->_response_array[1]; |
|
570 | + $this->response_reason_code = $this->_response_array[2]; |
|
571 | + $this->response_reason_text = $this->_response_array[3]; |
|
572 | + $this->authorization_code = $this->_response_array[4]; |
|
573 | + $this->avs_response = $this->_response_array[5]; |
|
574 | + $this->transaction_id = $this->_response_array[6]; |
|
575 | + $this->invoice_number = $this->_response_array[7]; |
|
576 | + $this->description = $this->_response_array[8]; |
|
577 | + $this->amount = $this->_response_array[9]; |
|
578 | + $this->method = $this->_response_array[10]; |
|
579 | + $this->transaction_type = $this->_response_array[11]; |
|
580 | + $this->customer_id = $this->_response_array[12]; |
|
581 | + $this->first_name = $this->_response_array[13]; |
|
582 | + $this->last_name = $this->_response_array[14]; |
|
583 | + $this->company = $this->_response_array[15]; |
|
584 | + $this->address = $this->_response_array[16]; |
|
585 | + $this->city = $this->_response_array[17]; |
|
586 | + $this->state = $this->_response_array[18]; |
|
587 | + $this->zip_code = $this->_response_array[19]; |
|
588 | + $this->country = $this->_response_array[20]; |
|
589 | + $this->phone = $this->_response_array[21]; |
|
590 | + $this->fax = $this->_response_array[22]; |
|
591 | + $this->email_address = $this->_response_array[23]; |
|
592 | + $this->ship_to_first_name = $this->_response_array[24]; |
|
593 | + $this->ship_to_last_name = $this->_response_array[25]; |
|
594 | + $this->ship_to_company = $this->_response_array[26]; |
|
595 | + $this->ship_to_address = $this->_response_array[27]; |
|
596 | + $this->ship_to_city = $this->_response_array[28]; |
|
597 | + $this->ship_to_state = $this->_response_array[29]; |
|
598 | + $this->ship_to_zip_code = $this->_response_array[30]; |
|
599 | + $this->ship_to_country = $this->_response_array[31]; |
|
600 | + $this->tax = $this->_response_array[32]; |
|
601 | + $this->duty = $this->_response_array[33]; |
|
602 | + $this->freight = $this->_response_array[34]; |
|
603 | + $this->tax_exempt = $this->_response_array[35]; |
|
604 | + $this->purchase_order_number = $this->_response_array[36]; |
|
605 | + $this->md5_hash = $this->_response_array[37]; |
|
606 | + $this->card_code_response = $this->_response_array[38]; |
|
607 | + $this->cavv_response = $this->_response_array[39]; |
|
608 | + $this->account_number = $this->_response_array[50]; |
|
609 | + $this->card_type = $this->_response_array[51]; |
|
610 | + $this->split_tender_id = $this->_response_array[52]; |
|
611 | + $this->requested_amount = $this->_response_array[53]; |
|
612 | + $this->balance_on_card = $this->_response_array[54]; |
|
613 | + |
|
614 | + $this->approved = ($this->response_code === self::APPROVED); |
|
615 | + $this->declined = ($this->response_code === self::DECLINED); |
|
616 | + $this->error = ($this->response_code === self::ERROR); |
|
617 | + $this->held = ($this->response_code === self::HELD); |
|
618 | + } else { |
|
619 | + $this->approved = false; |
|
620 | + $this->error = true; |
|
621 | + $this->error_message = esc_html__( |
|
622 | + 'Error connecting to Authorize.net', |
|
623 | + 'event_espresso' |
|
624 | + ); |
|
625 | + } |
|
626 | + } |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | if (! class_exists('AuthorizeNetException')) { |
630 | - /** |
|
631 | - * Class AuthorizeNetException |
|
632 | - * |
|
633 | - * @package AuthorizeNet |
|
634 | - */ |
|
635 | - class AuthorizeNetException extends Exception |
|
636 | - { |
|
637 | - |
|
638 | - /** |
|
639 | - * Construct the exception. Note: The message is NOT binary safe. |
|
640 | - * |
|
641 | - * @link http://php.net/manual/en/exception.construct.php |
|
642 | - * @param string $message [optional] The Exception message to throw. |
|
643 | - * @param int $code [optional] The Exception code. |
|
644 | - * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
645 | - * @since 5.1.0 |
|
646 | - */ |
|
647 | - public function __construct($message = "", $code = 0, Exception $previous = null) |
|
648 | - { |
|
649 | - parent::__construct($message, $code, $previous); |
|
650 | - } |
|
651 | - } |
|
630 | + /** |
|
631 | + * Class AuthorizeNetException |
|
632 | + * |
|
633 | + * @package AuthorizeNet |
|
634 | + */ |
|
635 | + class AuthorizeNetException extends Exception |
|
636 | + { |
|
637 | + |
|
638 | + /** |
|
639 | + * Construct the exception. Note: The message is NOT binary safe. |
|
640 | + * |
|
641 | + * @link http://php.net/manual/en/exception.construct.php |
|
642 | + * @param string $message [optional] The Exception message to throw. |
|
643 | + * @param int $code [optional] The Exception code. |
|
644 | + * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
645 | + * @since 5.1.0 |
|
646 | + */ |
|
647 | + public function __construct($message = "", $code = 0, Exception $previous = null) |
|
648 | + { |
|
649 | + parent::__construct($message, $code, $previous); |
|
650 | + } |
|
651 | + } |
|
652 | 652 | } |
@@ -17,158 +17,158 @@ |
||
17 | 17 | class CachingLoader extends CachingLoaderDecorator |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $identifier |
|
22 | - */ |
|
23 | - protected $identifier; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var CollectionInterface $cache |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var ObjectIdentifier |
|
32 | - */ |
|
33 | - private $object_identifier; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * CachingLoader constructor. |
|
38 | - * |
|
39 | - * @param LoaderDecoratorInterface $loader |
|
40 | - * @param CollectionInterface $cache |
|
41 | - * @param ObjectIdentifier $object_identifier |
|
42 | - * @param string $identifier |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - LoaderDecoratorInterface $loader, |
|
47 | - CollectionInterface $cache, |
|
48 | - ObjectIdentifier $object_identifier, |
|
49 | - $identifier = '' |
|
50 | - ) { |
|
51 | - parent::__construct($loader); |
|
52 | - $this->cache = $cache; |
|
53 | - $this->object_identifier = $object_identifier; |
|
54 | - $this->setIdentifier($identifier); |
|
55 | - if ($this->identifier !== '') { |
|
56 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
57 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
58 | - // where "IDENTIFIER" = the string that was set during construction |
|
59 | - add_action( |
|
60 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
61 | - array($this, 'reset') |
|
62 | - ); |
|
63 | - } |
|
64 | - // to clear ALL caches, simply do the following: |
|
65 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
66 | - add_action( |
|
67 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
68 | - array($this, 'reset') |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function identifier() |
|
77 | - { |
|
78 | - return $this->identifier; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $identifier |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - */ |
|
86 | - private function setIdentifier($identifier) |
|
87 | - { |
|
88 | - if (! is_string($identifier)) { |
|
89 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | - } |
|
91 | - $this->identifier = $identifier; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param FullyQualifiedName|string $fqcn |
|
97 | - * @param mixed $object |
|
98 | - * @param array $arguments |
|
99 | - * @return bool |
|
100 | - * @throws InvalidArgumentException |
|
101 | - */ |
|
102 | - public function share($fqcn, $object, array $arguments = array()) |
|
103 | - { |
|
104 | - if ($object instanceof $fqcn) { |
|
105 | - return $this->cache->add( |
|
106 | - $object, |
|
107 | - $this->object_identifier->getIdentifier($fqcn, $arguments) |
|
108 | - ); |
|
109 | - } |
|
110 | - throw new InvalidArgumentException( |
|
111 | - sprintf( |
|
112 | - esc_html__( |
|
113 | - 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - $fqcn |
|
117 | - ) |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @param FullyQualifiedName|string $fqcn |
|
124 | - * @param array $arguments |
|
125 | - * @param bool $shared |
|
126 | - * @param array $interfaces |
|
127 | - * @return mixed |
|
128 | - */ |
|
129 | - public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
130 | - { |
|
131 | - $fqcn = ltrim($fqcn, '\\'); |
|
132 | - // caching can be turned off via the following code: |
|
133 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
134 | - if (apply_filters( |
|
135 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
136 | - false, |
|
137 | - $this |
|
138 | - )) { |
|
139 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
140 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
141 | - return $this->loader->load($fqcn, $arguments, false); |
|
142 | - } |
|
143 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
144 | - if ($this->cache->has($object_identifier)) { |
|
145 | - return $this->cache->get($object_identifier); |
|
146 | - } |
|
147 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
148 | - if ($object instanceof $fqcn) { |
|
149 | - $this->cache->add($object, $object_identifier); |
|
150 | - } |
|
151 | - return $object; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * empties cache and calls reset() on loader if method exists |
|
157 | - */ |
|
158 | - public function reset() |
|
159 | - { |
|
160 | - $this->clearCache(); |
|
161 | - $this->loader->reset(); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * unsets and detaches ALL objects from the cache |
|
167 | - * |
|
168 | - * @since 4.9.62.p |
|
169 | - */ |
|
170 | - public function clearCache() |
|
171 | - { |
|
172 | - $this->cache->trashAndDetachAll(); |
|
173 | - } |
|
20 | + /** |
|
21 | + * @var string $identifier |
|
22 | + */ |
|
23 | + protected $identifier; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var CollectionInterface $cache |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var ObjectIdentifier |
|
32 | + */ |
|
33 | + private $object_identifier; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * CachingLoader constructor. |
|
38 | + * |
|
39 | + * @param LoaderDecoratorInterface $loader |
|
40 | + * @param CollectionInterface $cache |
|
41 | + * @param ObjectIdentifier $object_identifier |
|
42 | + * @param string $identifier |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + LoaderDecoratorInterface $loader, |
|
47 | + CollectionInterface $cache, |
|
48 | + ObjectIdentifier $object_identifier, |
|
49 | + $identifier = '' |
|
50 | + ) { |
|
51 | + parent::__construct($loader); |
|
52 | + $this->cache = $cache; |
|
53 | + $this->object_identifier = $object_identifier; |
|
54 | + $this->setIdentifier($identifier); |
|
55 | + if ($this->identifier !== '') { |
|
56 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
57 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
58 | + // where "IDENTIFIER" = the string that was set during construction |
|
59 | + add_action( |
|
60 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
61 | + array($this, 'reset') |
|
62 | + ); |
|
63 | + } |
|
64 | + // to clear ALL caches, simply do the following: |
|
65 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
66 | + add_action( |
|
67 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
68 | + array($this, 'reset') |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function identifier() |
|
77 | + { |
|
78 | + return $this->identifier; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $identifier |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + */ |
|
86 | + private function setIdentifier($identifier) |
|
87 | + { |
|
88 | + if (! is_string($identifier)) { |
|
89 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | + } |
|
91 | + $this->identifier = $identifier; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param FullyQualifiedName|string $fqcn |
|
97 | + * @param mixed $object |
|
98 | + * @param array $arguments |
|
99 | + * @return bool |
|
100 | + * @throws InvalidArgumentException |
|
101 | + */ |
|
102 | + public function share($fqcn, $object, array $arguments = array()) |
|
103 | + { |
|
104 | + if ($object instanceof $fqcn) { |
|
105 | + return $this->cache->add( |
|
106 | + $object, |
|
107 | + $this->object_identifier->getIdentifier($fqcn, $arguments) |
|
108 | + ); |
|
109 | + } |
|
110 | + throw new InvalidArgumentException( |
|
111 | + sprintf( |
|
112 | + esc_html__( |
|
113 | + 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + $fqcn |
|
117 | + ) |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @param FullyQualifiedName|string $fqcn |
|
124 | + * @param array $arguments |
|
125 | + * @param bool $shared |
|
126 | + * @param array $interfaces |
|
127 | + * @return mixed |
|
128 | + */ |
|
129 | + public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
130 | + { |
|
131 | + $fqcn = ltrim($fqcn, '\\'); |
|
132 | + // caching can be turned off via the following code: |
|
133 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
134 | + if (apply_filters( |
|
135 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
136 | + false, |
|
137 | + $this |
|
138 | + )) { |
|
139 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
140 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
141 | + return $this->loader->load($fqcn, $arguments, false); |
|
142 | + } |
|
143 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
144 | + if ($this->cache->has($object_identifier)) { |
|
145 | + return $this->cache->get($object_identifier); |
|
146 | + } |
|
147 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
148 | + if ($object instanceof $fqcn) { |
|
149 | + $this->cache->add($object, $object_identifier); |
|
150 | + } |
|
151 | + return $object; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * empties cache and calls reset() on loader if method exists |
|
157 | + */ |
|
158 | + public function reset() |
|
159 | + { |
|
160 | + $this->clearCache(); |
|
161 | + $this->loader->reset(); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * unsets and detaches ALL objects from the cache |
|
167 | + * |
|
168 | + * @since 4.9.62.p |
|
169 | + */ |
|
170 | + public function clearCache() |
|
171 | + { |
|
172 | + $this->cache->trashAndDetachAll(); |
|
173 | + } |
|
174 | 174 | } |
@@ -6,22 +6,22 @@ discard block |
||
6 | 6 | */ |
7 | 7 | function espresso_load_error_handling() |
8 | 8 | { |
9 | - static $error_handling_loaded = false; |
|
10 | - if ($error_handling_loaded) { |
|
11 | - return; |
|
12 | - } |
|
13 | - // load debugging tools |
|
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | - \EEH_Debug_Tools::instance(); |
|
17 | - } |
|
18 | - // load error handling |
|
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | - } else { |
|
22 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | - } |
|
24 | - $error_handling_loaded = true; |
|
9 | + static $error_handling_loaded = false; |
|
10 | + if ($error_handling_loaded) { |
|
11 | + return; |
|
12 | + } |
|
13 | + // load debugging tools |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
16 | + \EEH_Debug_Tools::instance(); |
|
17 | + } |
|
18 | + // load error handling |
|
19 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
21 | + } else { |
|
22 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
23 | + } |
|
24 | + $error_handling_loaded = true; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | |
@@ -35,19 +35,19 @@ discard block |
||
35 | 35 | */ |
36 | 36 | function espresso_load_required($classname, $full_path_to_file) |
37 | 37 | { |
38 | - if (is_readable($full_path_to_file)) { |
|
39 | - require_once $full_path_to_file; |
|
40 | - } else { |
|
41 | - throw new \EE_Error( |
|
42 | - sprintf( |
|
43 | - esc_html__( |
|
44 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | - 'event_espresso' |
|
46 | - ), |
|
47 | - $classname |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
38 | + if (is_readable($full_path_to_file)) { |
|
39 | + require_once $full_path_to_file; |
|
40 | + } else { |
|
41 | + throw new \EE_Error( |
|
42 | + sprintf( |
|
43 | + esc_html__( |
|
44 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
45 | + 'event_espresso' |
|
46 | + ), |
|
47 | + $classname |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | |
@@ -66,43 +66,43 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | - try { |
|
71 | - espresso_load_error_handling(); |
|
72 | - espresso_load_required( |
|
73 | - 'EEH_Base', |
|
74 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
75 | - ); |
|
76 | - espresso_load_required( |
|
77 | - 'EEH_File', |
|
78 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
79 | - ); |
|
80 | - espresso_load_required( |
|
81 | - 'EEH_File', |
|
82 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
83 | - ); |
|
84 | - espresso_load_required( |
|
85 | - 'EEH_Array', |
|
86 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
87 | - ); |
|
88 | - espresso_load_required( |
|
89 | - 'EE_Base', |
|
90 | - EE_CORE . 'EE_Base.core.php' |
|
91 | - ); |
|
92 | - // instantiate and configure PSR4 autoloader |
|
93 | - espresso_load_required( |
|
94 | - 'Psr4Autoloader', |
|
95 | - EE_CORE . 'Psr4Autoloader.php' |
|
96 | - ); |
|
97 | - espresso_load_required( |
|
98 | - 'EE_Psr4AutoloaderInit', |
|
99 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
100 | - ); |
|
101 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
102 | - $AutoloaderInit->initializeAutoloader(); |
|
103 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
104 | - } catch (Exception $e) { |
|
105 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
106 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
107 | - } |
|
69 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
70 | + try { |
|
71 | + espresso_load_error_handling(); |
|
72 | + espresso_load_required( |
|
73 | + 'EEH_Base', |
|
74 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
75 | + ); |
|
76 | + espresso_load_required( |
|
77 | + 'EEH_File', |
|
78 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
79 | + ); |
|
80 | + espresso_load_required( |
|
81 | + 'EEH_File', |
|
82 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
83 | + ); |
|
84 | + espresso_load_required( |
|
85 | + 'EEH_Array', |
|
86 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
87 | + ); |
|
88 | + espresso_load_required( |
|
89 | + 'EE_Base', |
|
90 | + EE_CORE . 'EE_Base.core.php' |
|
91 | + ); |
|
92 | + // instantiate and configure PSR4 autoloader |
|
93 | + espresso_load_required( |
|
94 | + 'Psr4Autoloader', |
|
95 | + EE_CORE . 'Psr4Autoloader.php' |
|
96 | + ); |
|
97 | + espresso_load_required( |
|
98 | + 'EE_Psr4AutoloaderInit', |
|
99 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
100 | + ); |
|
101 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
102 | + $AutoloaderInit->initializeAutoloader(); |
|
103 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
104 | + } catch (Exception $e) { |
|
105 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
106 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
107 | + } |
|
108 | 108 | } |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | return; |
12 | 12 | } |
13 | 13 | // load debugging tools |
14 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
15 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
14 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
15 | + require_once EE_HELPERS.'EEH_Debug_Tools.helper.php'; |
|
16 | 16 | \EEH_Debug_Tools::instance(); |
17 | 17 | } |
18 | 18 | // load error handling |
19 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
20 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
19 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
20 | + require_once EE_CORE.'EE_Error.core.php'; |
|
21 | 21 | } else { |
22 | 22 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
23 | 23 | } |
@@ -66,43 +66,43 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function bootstrap_espresso() |
68 | 68 | { |
69 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
69 | + require_once __DIR__.'/espresso_definitions.php'; |
|
70 | 70 | try { |
71 | 71 | espresso_load_error_handling(); |
72 | 72 | espresso_load_required( |
73 | 73 | 'EEH_Base', |
74 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
74 | + EE_CORE.'helpers'.DS.'EEH_Base.helper.php' |
|
75 | 75 | ); |
76 | 76 | espresso_load_required( |
77 | 77 | 'EEH_File', |
78 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
78 | + EE_CORE.'interfaces'.DS.'EEHI_File.interface.php' |
|
79 | 79 | ); |
80 | 80 | espresso_load_required( |
81 | 81 | 'EEH_File', |
82 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
82 | + EE_CORE.'helpers'.DS.'EEH_File.helper.php' |
|
83 | 83 | ); |
84 | 84 | espresso_load_required( |
85 | 85 | 'EEH_Array', |
86 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
86 | + EE_CORE.'helpers'.DS.'EEH_Array.helper.php' |
|
87 | 87 | ); |
88 | 88 | espresso_load_required( |
89 | 89 | 'EE_Base', |
90 | - EE_CORE . 'EE_Base.core.php' |
|
90 | + EE_CORE.'EE_Base.core.php' |
|
91 | 91 | ); |
92 | 92 | // instantiate and configure PSR4 autoloader |
93 | 93 | espresso_load_required( |
94 | 94 | 'Psr4Autoloader', |
95 | - EE_CORE . 'Psr4Autoloader.php' |
|
95 | + EE_CORE.'Psr4Autoloader.php' |
|
96 | 96 | ); |
97 | 97 | espresso_load_required( |
98 | 98 | 'EE_Psr4AutoloaderInit', |
99 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
99 | + EE_CORE.'EE_Psr4AutoloaderInit.core.php' |
|
100 | 100 | ); |
101 | 101 | $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
102 | 102 | $AutoloaderInit->initializeAutoloader(); |
103 | 103 | new EventEspresso\core\services\bootstrap\BootstrapCore(); |
104 | 104 | } catch (Exception $e) { |
105 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
105 | + require_once EE_CORE.'exceptions'.DS.'ExceptionStackTraceDisplay.php'; |
|
106 | 106 | new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
107 | 107 | } |
108 | 108 | } |
@@ -14,12 +14,12 @@ discard block |
||
14 | 14 | * @param int | \EE_Event $event |
15 | 15 | * @return bool |
16 | 16 | */ |
17 | -function is_espresso_event( $event = NULL ) { |
|
18 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
17 | +function is_espresso_event($event = NULL) { |
|
18 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
19 | 19 | // extract EE_Event object from passed param regardless of what it is (within reason of course) |
20 | - $event = EEH_Event_View::get_event( $event ); |
|
20 | + $event = EEH_Event_View::get_event($event); |
|
21 | 21 | // do we have a valid event ? |
22 | - return $event instanceof EE_Event ? TRUE : FALSE; |
|
22 | + return $event instanceof EE_Event ? TRUE : FALSE; |
|
23 | 23 | } |
24 | 24 | return FALSE; |
25 | 25 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @return bool |
32 | 32 | */ |
33 | 33 | function is_espresso_event_single() { |
34 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
34 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
35 | 35 | global $wp_query; |
36 | 36 | // return conditionals set by CPTs |
37 | 37 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : FALSE; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return bool |
47 | 47 | */ |
48 | 48 | function is_espresso_event_archive() { |
49 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
49 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
50 | 50 | global $wp_query; |
51 | 51 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : FALSE; |
52 | 52 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @return bool |
61 | 61 | */ |
62 | 62 | function is_espresso_event_taxonomy() { |
63 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
63 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
64 | 64 | global $wp_query; |
65 | 65 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : FALSE; |
66 | 66 | } |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | * @param int | \EE_Venue $venue |
75 | 75 | * @return bool |
76 | 76 | */ |
77 | -function is_espresso_venue( $venue = NULL ) { |
|
78 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
77 | +function is_espresso_venue($venue = NULL) { |
|
78 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
79 | 79 | // extract EE_Venue object from passed param regardless of what it is (within reason of course) |
80 | - $venue = EEH_Venue_View::get_venue( $venue, FALSE ); |
|
80 | + $venue = EEH_Venue_View::get_venue($venue, FALSE); |
|
81 | 81 | // do we have a valid event ? |
82 | 82 | return $venue instanceof EE_Venue ? TRUE : FALSE; |
83 | 83 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return bool |
92 | 92 | */ |
93 | 93 | function is_espresso_venue_single() { |
94 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
94 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
95 | 95 | global $wp_query; |
96 | 96 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : FALSE; |
97 | 97 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @return bool |
106 | 106 | */ |
107 | 107 | function is_espresso_venue_archive() { |
108 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
108 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
109 | 109 | global $wp_query; |
110 | 110 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : FALSE; |
111 | 111 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return bool |
120 | 120 | */ |
121 | 121 | function is_espresso_venue_taxonomy() { |
122 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
122 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
123 | 123 | global $wp_query; |
124 | 124 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : FALSE; |
125 | 125 | } |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | * @param $conditional_tag |
134 | 134 | * @return bool |
135 | 135 | */ |
136 | -function can_use_espresso_conditionals( $conditional_tag ) { |
|
137 | - if ( ! did_action( 'AHEE__EE_System__initialize' )) { |
|
136 | +function can_use_espresso_conditionals($conditional_tag) { |
|
137 | + if ( ! did_action('AHEE__EE_System__initialize')) { |
|
138 | 138 | EE_Error::doing_it_wrong( |
139 | 139 | __FUNCTION__, |
140 | 140 | sprintf( |
141 | - __( 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.','event_espresso'), |
|
141 | + __('The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', 'event_espresso'), |
|
142 | 142 | $conditional_tag |
143 | 143 | ), |
144 | 144 | '4.4.0' |
@@ -153,13 +153,13 @@ discard block |
||
153 | 153 | |
154 | 154 | /*************************** Event Queries ***************************/ |
155 | 155 | |
156 | -if ( ! function_exists( 'espresso_get_events' )) { |
|
156 | +if ( ! function_exists('espresso_get_events')) { |
|
157 | 157 | /** |
158 | 158 | * espresso_get_events |
159 | 159 | * @param array $params |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - function espresso_get_events( $params = array() ) { |
|
162 | + function espresso_get_events($params = array()) { |
|
163 | 163 | //set default params |
164 | 164 | $default_espresso_events_params = array( |
165 | 165 | 'limit' => 10, |
@@ -170,18 +170,18 @@ discard block |
||
170 | 170 | 'sort' => 'ASC' |
171 | 171 | ); |
172 | 172 | // allow the defaults to be filtered |
173 | - $default_espresso_events_params = apply_filters( 'espresso_get_events__default_espresso_events_params', $default_espresso_events_params ); |
|
173 | + $default_espresso_events_params = apply_filters('espresso_get_events__default_espresso_events_params', $default_espresso_events_params); |
|
174 | 174 | // grab params and merge with defaults, then extract |
175 | - $params = array_merge( $default_espresso_events_params, $params ); |
|
175 | + $params = array_merge($default_espresso_events_params, $params); |
|
176 | 176 | // run the query |
177 | - $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $params ); |
|
177 | + $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params); |
|
178 | 178 | // assign results to a variable so we can return it |
179 | 179 | $events = $events_query->have_posts() ? $events_query->posts : array(); |
180 | 180 | // but first reset the query and postdata |
181 | 181 | wp_reset_query(); |
182 | 182 | wp_reset_postdata(); |
183 | 183 | EED_Events_Archive::remove_all_events_archive_filters(); |
184 | - unset( $events_query ); |
|
184 | + unset($events_query); |
|
185 | 185 | return $events; |
186 | 186 | } |
187 | 187 | } |
@@ -195,33 +195,33 @@ discard block |
||
195 | 195 | * espresso_load_ticket_selector |
196 | 196 | */ |
197 | 197 | function espresso_load_ticket_selector() { |
198 | - EE_Registry::instance()->load_file( EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module' ); |
|
198 | + EE_Registry::instance()->load_file(EE_MODULES.'ticket_selector', 'EED_Ticket_Selector', 'module'); |
|
199 | 199 | } |
200 | 200 | |
201 | -if ( ! function_exists( 'espresso_ticket_selector' )) { |
|
201 | +if ( ! function_exists('espresso_ticket_selector')) { |
|
202 | 202 | /** |
203 | 203 | * espresso_ticket_selector |
204 | 204 | * @param null $event |
205 | 205 | */ |
206 | - function espresso_ticket_selector( $event = NULL ) { |
|
207 | - if ( ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) { |
|
206 | + function espresso_ticket_selector($event = NULL) { |
|
207 | + if ( ! apply_filters('FHEE_disable_espresso_ticket_selector', FALSE)) { |
|
208 | 208 | espresso_load_ticket_selector(); |
209 | 209 | \EED_Ticket_Selector::set_definitions(); |
210 | - echo EED_Ticket_Selector::display_ticket_selector( $event ); |
|
210 | + echo EED_Ticket_Selector::display_ticket_selector($event); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | } |
214 | 214 | |
215 | 215 | |
216 | - if ( ! function_exists( 'espresso_view_details_btn' )) { |
|
216 | + if ( ! function_exists('espresso_view_details_btn')) { |
|
217 | 217 | /** |
218 | 218 | * espresso_view_details_btn |
219 | 219 | * @param null $event |
220 | 220 | */ |
221 | - function espresso_view_details_btn( $event = NULL ) { |
|
222 | - if ( ! apply_filters( 'FHEE_disable_espresso_view_details_btn', FALSE ) ) { |
|
221 | + function espresso_view_details_btn($event = NULL) { |
|
222 | + if ( ! apply_filters('FHEE_disable_espresso_view_details_btn', FALSE)) { |
|
223 | 223 | espresso_load_ticket_selector(); |
224 | - echo EED_Ticket_Selector::display_ticket_selector( $event, TRUE ); |
|
224 | + echo EED_Ticket_Selector::display_ticket_selector($event, TRUE); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | |
232 | 232 | /*************************** EEH_Event_View ***************************/ |
233 | 233 | |
234 | -if ( ! function_exists( 'espresso_load_event_list_assets' )) { |
|
234 | +if ( ! function_exists('espresso_load_event_list_assets')) { |
|
235 | 235 | /** |
236 | 236 | * espresso_load_event_list_assets |
237 | 237 | * ensures that event list styles and scripts are loaded |
@@ -240,13 +240,13 @@ discard block |
||
240 | 240 | */ |
241 | 241 | function espresso_load_event_list_assets() { |
242 | 242 | $event_list = EED_Events_Archive::instance(); |
243 | - add_action( 'AHEE__EE_System__initialize_last', array( $event_list, 'load_event_list_assets' ), 10 ); |
|
244 | - add_filter( 'FHEE_enable_default_espresso_css', '__return_true' ); |
|
243 | + add_action('AHEE__EE_System__initialize_last', array($event_list, 'load_event_list_assets'), 10); |
|
244 | + add_filter('FHEE_enable_default_espresso_css', '__return_true'); |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | 248 | |
249 | -if ( ! function_exists( 'espresso_event_reg_button' )) { |
|
249 | +if ( ! function_exists('espresso_event_reg_button')) { |
|
250 | 250 | /** |
251 | 251 | * espresso_event_reg_button |
252 | 252 | * returns the "Register Now" button if event is active, |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | * @param bool $EVT_ID |
259 | 259 | * @return string |
260 | 260 | */ |
261 | - function espresso_event_reg_button( $btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE ) { |
|
262 | - $event_status = EEH_Event_View::event_active_status( $EVT_ID ); |
|
263 | - switch ( $event_status ) { |
|
261 | + function espresso_event_reg_button($btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE) { |
|
262 | + $event_status = EEH_Event_View::event_active_status($EVT_ID); |
|
263 | + switch ($event_status) { |
|
264 | 264 | case EE_Datetime::sold_out : |
265 | 265 | $btn_text = __('Sold Out', 'event_espresso'); |
266 | 266 | $class = 'ee-pink'; |
@@ -276,10 +276,10 @@ discard block |
||
276 | 276 | case EE_Datetime::upcoming : |
277 | 277 | case EE_Datetime::active : |
278 | 278 | default : |
279 | - $btn_text =! empty( $btn_text_if_active ) ? $btn_text_if_active : __( 'Register Now', 'event_espresso' ); |
|
279 | + $btn_text = ! empty($btn_text_if_active) ? $btn_text_if_active : __('Register Now', 'event_espresso'); |
|
280 | 280 | $class = 'ee-green'; |
281 | 281 | } |
282 | - if ( $event_status < 1 && ! empty( $btn_text_if_inactive )) { |
|
282 | + if ($event_status < 1 && ! empty($btn_text_if_inactive)) { |
|
283 | 283 | $btn_text = $btn_text_if_inactive; |
284 | 284 | $class = 'ee-grey'; |
285 | 285 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | |
294 | 294 | |
295 | 295 | |
296 | -if ( ! function_exists( 'espresso_display_ticket_selector' )) { |
|
296 | +if ( ! function_exists('espresso_display_ticket_selector')) { |
|
297 | 297 | /** |
298 | 298 | * espresso_display_ticket_selector |
299 | 299 | * whether or not to display the Ticket Selector for an event |
@@ -301,14 +301,14 @@ discard block |
||
301 | 301 | * @param bool $EVT_ID |
302 | 302 | * @return boolean |
303 | 303 | */ |
304 | - function espresso_display_ticket_selector( $EVT_ID = FALSE ) { |
|
305 | - return EEH_Event_View::display_ticket_selector( $EVT_ID ); |
|
304 | + function espresso_display_ticket_selector($EVT_ID = FALSE) { |
|
305 | + return EEH_Event_View::display_ticket_selector($EVT_ID); |
|
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | 309 | |
310 | 310 | |
311 | -if ( ! function_exists( 'espresso_event_status_banner' )) { |
|
311 | +if ( ! function_exists('espresso_event_status_banner')) { |
|
312 | 312 | /** |
313 | 313 | * espresso_event_status |
314 | 314 | * returns a banner showing the event status if it is sold out, expired, or inactive |
@@ -316,13 +316,13 @@ discard block |
||
316 | 316 | * @param bool $EVT_ID |
317 | 317 | * @return string |
318 | 318 | */ |
319 | - function espresso_event_status_banner( $EVT_ID = FALSE ) { |
|
320 | - return EEH_Event_View::event_status( $EVT_ID ); |
|
319 | + function espresso_event_status_banner($EVT_ID = FALSE) { |
|
320 | + return EEH_Event_View::event_status($EVT_ID); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
324 | 324 | |
325 | -if ( ! function_exists( 'espresso_event_status' )) { |
|
325 | +if ( ! function_exists('espresso_event_status')) { |
|
326 | 326 | /** |
327 | 327 | * espresso_event_status |
328 | 328 | * returns the event status if it is sold out, expired, or inactive |
@@ -331,17 +331,17 @@ discard block |
||
331 | 331 | * @param bool $echo |
332 | 332 | * @return string |
333 | 333 | */ |
334 | - function espresso_event_status( $EVT_ID = 0, $echo = TRUE ) { |
|
335 | - if ( $echo ) { |
|
336 | - echo EEH_Event_View::event_active_status( $EVT_ID ); |
|
334 | + function espresso_event_status($EVT_ID = 0, $echo = TRUE) { |
|
335 | + if ($echo) { |
|
336 | + echo EEH_Event_View::event_active_status($EVT_ID); |
|
337 | 337 | return ''; |
338 | 338 | } |
339 | - return EEH_Event_View::event_active_status( $EVT_ID ); |
|
339 | + return EEH_Event_View::event_active_status($EVT_ID); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
343 | 343 | |
344 | -if ( ! function_exists( 'espresso_event_categories' )) { |
|
344 | +if ( ! function_exists('espresso_event_categories')) { |
|
345 | 345 | /** |
346 | 346 | * espresso_event_categories |
347 | 347 | * returns the terms associated with an event |
@@ -351,17 +351,17 @@ discard block |
||
351 | 351 | * @param bool $echo |
352 | 352 | * @return string |
353 | 353 | */ |
354 | - function espresso_event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
355 | - if ( $echo ) { |
|
356 | - echo EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
354 | + function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
355 | + if ($echo) { |
|
356 | + echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
357 | 357 | return ''; |
358 | 358 | } |
359 | - return EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
359 | + return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
360 | 360 | } |
361 | 361 | } |
362 | 362 | |
363 | 363 | |
364 | -if ( ! function_exists( 'espresso_event_tickets_available' )) { |
|
364 | +if ( ! function_exists('espresso_event_tickets_available')) { |
|
365 | 365 | /** |
366 | 366 | * espresso_event_tickets_available |
367 | 367 | * returns the ticket types available for purchase for an event |
@@ -371,26 +371,26 @@ discard block |
||
371 | 371 | * @param bool $format |
372 | 372 | * @return string |
373 | 373 | */ |
374 | - function espresso_event_tickets_available( $EVT_ID = 0, $echo = TRUE, $format = TRUE ) { |
|
375 | - $tickets = EEH_Event_View::event_tickets_available( $EVT_ID ); |
|
376 | - if ( is_array( $tickets ) && ! empty( $tickets )) { |
|
374 | + function espresso_event_tickets_available($EVT_ID = 0, $echo = TRUE, $format = TRUE) { |
|
375 | + $tickets = EEH_Event_View::event_tickets_available($EVT_ID); |
|
376 | + if (is_array($tickets) && ! empty($tickets)) { |
|
377 | 377 | // if formatting then $html will be a string, else it will be an array of ticket objects |
378 | - $html = $format ? '<ul id="ee-event-tickets-ul-' . $EVT_ID . '" class="ee-event-tickets-ul">' : array(); |
|
379 | - foreach ( $tickets as $ticket ) { |
|
380 | - if ( $ticket instanceof EE_Ticket ) { |
|
381 | - if ( $format ) { |
|
382 | - $html .= '<li id="ee-event-tickets-li-' . $ticket->ID() . '" class="ee-event-tickets-li">'; |
|
383 | - $html .= $ticket->name() . ' ' . EEH_Template::format_currency( $ticket->get_ticket_total_with_taxes() ); |
|
378 | + $html = $format ? '<ul id="ee-event-tickets-ul-'.$EVT_ID.'" class="ee-event-tickets-ul">' : array(); |
|
379 | + foreach ($tickets as $ticket) { |
|
380 | + if ($ticket instanceof EE_Ticket) { |
|
381 | + if ($format) { |
|
382 | + $html .= '<li id="ee-event-tickets-li-'.$ticket->ID().'" class="ee-event-tickets-li">'; |
|
383 | + $html .= $ticket->name().' '.EEH_Template::format_currency($ticket->get_ticket_total_with_taxes()); |
|
384 | 384 | $html .= '</li>'; |
385 | 385 | } else { |
386 | 386 | $html[] = $ticket; |
387 | 387 | } |
388 | 388 | } |
389 | 389 | } |
390 | - if ( $format ) { |
|
390 | + if ($format) { |
|
391 | 391 | $html .= '</ul>'; |
392 | 392 | } |
393 | - if ( $echo && $format ) { |
|
393 | + if ($echo && $format) { |
|
394 | 394 | echo $html; |
395 | 395 | return ''; |
396 | 396 | } |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | -if ( ! function_exists( 'espresso_event_date_obj' )) { |
|
403 | +if ( ! function_exists('espresso_event_date_obj')) { |
|
404 | 404 | /** |
405 | 405 | * espresso_event_date_obj |
406 | 406 | * returns the primary date object for an event |
@@ -408,13 +408,13 @@ discard block |
||
408 | 408 | * @param bool $EVT_ID |
409 | 409 | * @return object |
410 | 410 | */ |
411 | - function espresso_event_date_obj( $EVT_ID = FALSE ) { |
|
412 | - return EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
411 | + function espresso_event_date_obj($EVT_ID = FALSE) { |
|
412 | + return EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | 416 | |
417 | -if ( ! function_exists( 'espresso_event_date' )) { |
|
417 | +if ( ! function_exists('espresso_event_date')) { |
|
418 | 418 | /** |
419 | 419 | * espresso_event_date |
420 | 420 | * returns the primary date for an event |
@@ -425,22 +425,22 @@ discard block |
||
425 | 425 | * @param bool $echo |
426 | 426 | * @return string |
427 | 427 | */ |
428 | - function espresso_event_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
429 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
430 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
431 | - $date_format = apply_filters( 'FHEE__espresso_event_date__date_format', $date_format ); |
|
432 | - $time_format = apply_filters( 'FHEE__espresso_event_date__time_format', $time_format ); |
|
433 | - if($echo){ |
|
434 | - echo EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
428 | + function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
429 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
430 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
431 | + $date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format); |
|
432 | + $time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format); |
|
433 | + if ($echo) { |
|
434 | + echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
435 | 435 | return ''; |
436 | 436 | } |
437 | - return EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
437 | + return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
438 | 438 | |
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | 442 | |
443 | -if ( ! function_exists( 'espresso_list_of_event_dates' )) { |
|
443 | +if ( ! function_exists('espresso_list_of_event_dates')) { |
|
444 | 444 | /** |
445 | 445 | * espresso_list_of_event_dates |
446 | 446 | * returns a unordered list of dates for an event |
@@ -455,40 +455,40 @@ discard block |
||
455 | 455 | * @param null $limit |
456 | 456 | * @return string |
457 | 457 | */ |
458 | - function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) { |
|
459 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
460 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
461 | - $date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format ); |
|
462 | - $time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format ); |
|
463 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit ); |
|
464 | - if ( ! $format ) { |
|
465 | - return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes ); |
|
458 | + function espresso_list_of_event_dates($EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL) { |
|
459 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
460 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
461 | + $date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format); |
|
462 | + $time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format); |
|
463 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, FALSE, $limit); |
|
464 | + if ( ! $format) { |
|
465 | + return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes); |
|
466 | 466 | } |
467 | 467 | //d( $datetimes ); |
468 | - if ( is_array( $datetimes ) && ! empty( $datetimes )) { |
|
468 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
469 | 469 | global $post; |
470 | - $html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
471 | - foreach ( $datetimes as $datetime ) { |
|
472 | - if ( $datetime instanceof EE_Datetime ) { |
|
473 | - $html .= '<li id="ee-event-datetimes-li-' . $datetime->ID(); |
|
474 | - $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-' . $datetime->get_active_status() . '">'; |
|
470 | + $html = $format ? '<ul id="ee-event-datetimes-ul-'.$post->ID.'" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
471 | + foreach ($datetimes as $datetime) { |
|
472 | + if ($datetime instanceof EE_Datetime) { |
|
473 | + $html .= '<li id="ee-event-datetimes-li-'.$datetime->ID(); |
|
474 | + $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-'.$datetime->get_active_status().'">'; |
|
475 | 475 | $datetime_name = $datetime->name(); |
476 | - $html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : ''; |
|
477 | - $html .= ! empty( $datetime_name ) && $add_breaks ? '<br />' : ''; |
|
478 | - $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">' . $datetime->date_range( $date_format ) . '</span><br/>'; |
|
479 | - $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">' . $datetime->time_range( $time_format ) . '</span>'; |
|
476 | + $html .= ! empty($datetime_name) ? '<strong>'.$datetime_name.'</strong>' : ''; |
|
477 | + $html .= ! empty($datetime_name) && $add_breaks ? '<br />' : ''; |
|
478 | + $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">'.$datetime->date_range($date_format).'</span><br/>'; |
|
479 | + $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">'.$datetime->time_range($time_format).'</span>'; |
|
480 | 480 | $datetime_description = $datetime->description(); |
481 | - $html .= ! empty( $datetime_description ) && $add_breaks ? '<br />' : ''; |
|
482 | - $html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : ''; |
|
483 | - $html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime ); |
|
481 | + $html .= ! empty($datetime_description) && $add_breaks ? '<br />' : ''; |
|
482 | + $html .= ! empty($datetime_description) ? ' - '.$datetime_description : ''; |
|
483 | + $html = apply_filters('FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime); |
|
484 | 484 | $html .= '</li>'; |
485 | 485 | } |
486 | 486 | } |
487 | 487 | $html .= $format ? '</ul>' : ''; |
488 | 488 | } else { |
489 | - $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : ''; |
|
489 | + $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>'.__('There are no upcoming dates for this event.', 'event_espresso').'</p><br/>' : ''; |
|
490 | 490 | } |
491 | - if ( $echo ) { |
|
491 | + if ($echo) { |
|
492 | 492 | echo $html; |
493 | 493 | return ''; |
494 | 494 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | } |
498 | 498 | |
499 | 499 | |
500 | -if ( ! function_exists( 'espresso_event_end_date' )) { |
|
500 | +if ( ! function_exists('espresso_event_end_date')) { |
|
501 | 501 | /** |
502 | 502 | * espresso_event_end_date |
503 | 503 | * returns the last date for an event |
@@ -508,20 +508,20 @@ discard block |
||
508 | 508 | * @param bool $echo |
509 | 509 | * @return string |
510 | 510 | */ |
511 | - function espresso_event_end_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
512 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
513 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
514 | - $date_format = apply_filters( 'FHEE__espresso_event_end_date__date_format', $date_format ); |
|
515 | - $time_format = apply_filters( 'FHEE__espresso_event_end_date__time_format', $time_format ); |
|
516 | - if($echo){ |
|
517 | - echo EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
511 | + function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
512 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
513 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
514 | + $date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format); |
|
515 | + $time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format); |
|
516 | + if ($echo) { |
|
517 | + echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
518 | 518 | return ''; |
519 | 519 | } |
520 | - return EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
520 | + return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
521 | 521 | } |
522 | 522 | } |
523 | 523 | |
524 | -if ( ! function_exists( 'espresso_event_date_range' )) { |
|
524 | +if ( ! function_exists('espresso_event_date_range')) { |
|
525 | 525 | /** |
526 | 526 | * espresso_event_date_range |
527 | 527 | * returns the first and last chronologically ordered dates for an event (if different) |
@@ -534,31 +534,31 @@ discard block |
||
534 | 534 | * @param bool $echo |
535 | 535 | * @return string |
536 | 536 | */ |
537 | - function espresso_event_date_range( $date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
537 | + function espresso_event_date_range($date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
538 | 538 | // set and filter date and time formats when a range is returned |
539 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
540 | - $date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', $date_format ); |
|
539 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
540 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format); |
|
541 | 541 | // get the start and end date with NO time portion |
542 | - $the_event_date = EEH_Event_View::the_earliest_event_date( $date_format, '', $EVT_ID ); |
|
543 | - $the_event_end_date = EEH_Event_View::the_latest_event_date( $date_format, '', $EVT_ID ); |
|
542 | + $the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID); |
|
543 | + $the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID); |
|
544 | 544 | // now we can determine if date range spans more than one day |
545 | - if ( $the_event_date != $the_event_end_date ) { |
|
546 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
547 | - $time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', $time_format ); |
|
545 | + if ($the_event_date != $the_event_end_date) { |
|
546 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
547 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format); |
|
548 | 548 | $html = sprintf( |
549 | - __( '%1$s - %2$s', 'event_espresso' ), |
|
550 | - EEH_Event_View::the_earliest_event_date( $date_format, $time_format, $EVT_ID ), |
|
551 | - EEH_Event_View::the_latest_event_date( $date_format, $time_format, $EVT_ID ) |
|
549 | + __('%1$s - %2$s', 'event_espresso'), |
|
550 | + EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID), |
|
551 | + EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID) |
|
552 | 552 | ); |
553 | 553 | } else { |
554 | 554 | // set and filter date and time formats when only a single datetime is returned |
555 | - $single_date_format = ! empty( $single_date_format ) ? $single_date_format : get_option( 'date_format' ); |
|
556 | - $single_time_format = ! empty( $single_time_format ) ? $single_time_format : get_option( 'time_format' ); |
|
557 | - $single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', $single_date_format ); |
|
558 | - $single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', $single_time_format ); |
|
559 | - $html = EEH_Event_View::the_earliest_event_date( $single_date_format, $single_time_format, $EVT_ID ); |
|
555 | + $single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format'); |
|
556 | + $single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format'); |
|
557 | + $single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format); |
|
558 | + $single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format); |
|
559 | + $html = EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID); |
|
560 | 560 | } |
561 | - if ( $echo ) { |
|
561 | + if ($echo) { |
|
562 | 562 | echo $html; |
563 | 563 | return ''; |
564 | 564 | } |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | } |
567 | 567 | } |
568 | 568 | |
569 | -if ( ! function_exists( 'espresso_next_upcoming_datetime_obj' )) { |
|
569 | +if ( ! function_exists('espresso_next_upcoming_datetime_obj')) { |
|
570 | 570 | /** |
571 | 571 | * espresso_next_upcoming_datetime_obj |
572 | 572 | * returns the next upcoming datetime object for an event |
@@ -574,12 +574,12 @@ discard block |
||
574 | 574 | * @param int $EVT_ID |
575 | 575 | * @return EE_Datetime|null |
576 | 576 | */ |
577 | - function espresso_next_upcoming_datetime_obj( $EVT_ID = 0 ) { |
|
578 | - return EEH_Event_View::get_next_upcoming_date_obj( $EVT_ID ); |
|
577 | + function espresso_next_upcoming_datetime_obj($EVT_ID = 0) { |
|
578 | + return EEH_Event_View::get_next_upcoming_date_obj($EVT_ID); |
|
579 | 579 | } |
580 | 580 | } |
581 | 581 | |
582 | -if ( ! function_exists( 'espresso_next_upcoming_datetime' ) ) { |
|
582 | +if ( ! function_exists('espresso_next_upcoming_datetime')) { |
|
583 | 583 | /** |
584 | 584 | * espresso_next_upcoming_datetime |
585 | 585 | * returns the start date and time for the next upcoming event. |
@@ -590,30 +590,30 @@ discard block |
||
590 | 590 | * @param bool $echo |
591 | 591 | * @return string |
592 | 592 | */ |
593 | - function espresso_next_upcoming_datetime( $date_format = '', $time_format = '', $EVT_ID = 0, $echo = true ) { |
|
593 | + function espresso_next_upcoming_datetime($date_format = '', $time_format = '', $EVT_ID = 0, $echo = true) { |
|
594 | 594 | |
595 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
596 | - $date_format = apply_filters( 'FHEE__espresso_next_upcoming_datetime__date_format', $date_format ); |
|
595 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
596 | + $date_format = apply_filters('FHEE__espresso_next_upcoming_datetime__date_format', $date_format); |
|
597 | 597 | |
598 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
599 | - $time_format = apply_filters( 'FHEE__espresso_next_upcoming_datetime__time_format', $time_format ); |
|
598 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
599 | + $time_format = apply_filters('FHEE__espresso_next_upcoming_datetime__time_format', $time_format); |
|
600 | 600 | |
601 | - $datetime_format = trim( $date_format . ' ' . $time_format); |
|
601 | + $datetime_format = trim($date_format.' '.$time_format); |
|
602 | 602 | |
603 | - $datetime = espresso_next_upcoming_datetime_obj( $EVT_ID ); |
|
603 | + $datetime = espresso_next_upcoming_datetime_obj($EVT_ID); |
|
604 | 604 | |
605 | - if( ! $datetime instanceof EE_Datetime ) { |
|
605 | + if ( ! $datetime instanceof EE_Datetime) { |
|
606 | 606 | return ''; |
607 | 607 | } |
608 | - if ( $echo ){ |
|
609 | - echo $datetime->get_i18n_datetime( 'DTT_EVT_start', $datetime_format ); |
|
608 | + if ($echo) { |
|
609 | + echo $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
610 | 610 | return ''; |
611 | 611 | } |
612 | - return $datetime->get_i18n_datetime( 'DTT_EVT_start', $datetime_format ); |
|
612 | + return $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
616 | -if ( ! function_exists( 'espresso_event_date_as_calendar_page' )) { |
|
616 | +if ( ! function_exists('espresso_event_date_as_calendar_page')) { |
|
617 | 617 | /** |
618 | 618 | * espresso_event_date_as_calendar_page |
619 | 619 | * returns the primary date for an event, stylized to appear as the page of a calendar |
@@ -621,15 +621,15 @@ discard block |
||
621 | 621 | * @param bool $EVT_ID |
622 | 622 | * @return string |
623 | 623 | */ |
624 | - function espresso_event_date_as_calendar_page( $EVT_ID = FALSE ) { |
|
625 | - EEH_Event_View::event_date_as_calendar_page( $EVT_ID ); |
|
624 | + function espresso_event_date_as_calendar_page($EVT_ID = FALSE) { |
|
625 | + EEH_Event_View::event_date_as_calendar_page($EVT_ID); |
|
626 | 626 | } |
627 | 627 | } |
628 | 628 | |
629 | 629 | |
630 | 630 | |
631 | 631 | |
632 | -if ( ! function_exists( 'espresso_event_link_url' )) { |
|
632 | +if ( ! function_exists('espresso_event_link_url')) { |
|
633 | 633 | /** |
634 | 634 | * espresso_event_link_url |
635 | 635 | * |
@@ -637,18 +637,18 @@ discard block |
||
637 | 637 | * @param bool $echo |
638 | 638 | * @return string |
639 | 639 | */ |
640 | - function espresso_event_link_url( $EVT_ID = 0, $echo = TRUE ) { |
|
641 | - if ( $echo ) { |
|
642 | - echo EEH_Event_View::event_link_url( $EVT_ID ); |
|
640 | + function espresso_event_link_url($EVT_ID = 0, $echo = TRUE) { |
|
641 | + if ($echo) { |
|
642 | + echo EEH_Event_View::event_link_url($EVT_ID); |
|
643 | 643 | return ''; |
644 | 644 | } |
645 | - return EEH_Event_View::event_link_url( $EVT_ID ); |
|
645 | + return EEH_Event_View::event_link_url($EVT_ID); |
|
646 | 646 | } |
647 | 647 | } |
648 | 648 | |
649 | 649 | |
650 | 650 | |
651 | -if ( ! function_exists( 'espresso_event_has_content_or_excerpt' )) { |
|
651 | +if ( ! function_exists('espresso_event_has_content_or_excerpt')) { |
|
652 | 652 | /** |
653 | 653 | * espresso_event_has_content_or_excerpt |
654 | 654 | * |
@@ -656,15 +656,15 @@ discard block |
||
656 | 656 | * @param bool $EVT_ID |
657 | 657 | * @return boolean |
658 | 658 | */ |
659 | - function espresso_event_has_content_or_excerpt( $EVT_ID = FALSE ) { |
|
660 | - return EEH_Event_View::event_has_content_or_excerpt( $EVT_ID ); |
|
659 | + function espresso_event_has_content_or_excerpt($EVT_ID = FALSE) { |
|
660 | + return EEH_Event_View::event_has_content_or_excerpt($EVT_ID); |
|
661 | 661 | } |
662 | 662 | } |
663 | 663 | |
664 | 664 | |
665 | 665 | |
666 | 666 | |
667 | -if ( ! function_exists( 'espresso_event_content_or_excerpt' )) { |
|
667 | +if ( ! function_exists('espresso_event_content_or_excerpt')) { |
|
668 | 668 | /** |
669 | 669 | * espresso_event_content_or_excerpt |
670 | 670 | * |
@@ -673,18 +673,18 @@ discard block |
||
673 | 673 | * @param bool $echo |
674 | 674 | * @return string |
675 | 675 | */ |
676 | - function espresso_event_content_or_excerpt( $num_words = 55, $more = NULL, $echo = TRUE ) { |
|
677 | - if ( $echo ) { |
|
678 | - echo EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
676 | + function espresso_event_content_or_excerpt($num_words = 55, $more = NULL, $echo = TRUE) { |
|
677 | + if ($echo) { |
|
678 | + echo EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
679 | 679 | return ''; |
680 | 680 | } |
681 | - return EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
681 | + return EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
682 | 682 | } |
683 | 683 | } |
684 | 684 | |
685 | 685 | |
686 | 686 | |
687 | -if ( ! function_exists( 'espresso_event_phone' )) { |
|
687 | +if ( ! function_exists('espresso_event_phone')) { |
|
688 | 688 | /** |
689 | 689 | * espresso_event_phone |
690 | 690 | * |
@@ -692,18 +692,18 @@ discard block |
||
692 | 692 | * @param bool $echo |
693 | 693 | * @return string |
694 | 694 | */ |
695 | - function espresso_event_phone( $EVT_ID = 0, $echo = TRUE ) { |
|
696 | - if ( $echo ) { |
|
697 | - echo EEH_Event_View::event_phone( $EVT_ID ); |
|
695 | + function espresso_event_phone($EVT_ID = 0, $echo = TRUE) { |
|
696 | + if ($echo) { |
|
697 | + echo EEH_Event_View::event_phone($EVT_ID); |
|
698 | 698 | return ''; |
699 | 699 | } |
700 | - return EEH_Event_View::event_phone( $EVT_ID ); |
|
700 | + return EEH_Event_View::event_phone($EVT_ID); |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | |
704 | 704 | |
705 | 705 | |
706 | -if ( ! function_exists( 'espresso_edit_event_link' )) { |
|
706 | +if ( ! function_exists('espresso_edit_event_link')) { |
|
707 | 707 | /** |
708 | 708 | * espresso_edit_event_link |
709 | 709 | * returns a link to edit an event |
@@ -712,39 +712,39 @@ discard block |
||
712 | 712 | * @param bool $echo |
713 | 713 | * @return string |
714 | 714 | */ |
715 | - function espresso_edit_event_link( $EVT_ID = 0, $echo = TRUE ) { |
|
716 | - if ( $echo ) { |
|
717 | - echo EEH_Event_View::edit_event_link( $EVT_ID ); |
|
715 | + function espresso_edit_event_link($EVT_ID = 0, $echo = TRUE) { |
|
716 | + if ($echo) { |
|
717 | + echo EEH_Event_View::edit_event_link($EVT_ID); |
|
718 | 718 | return ''; |
719 | 719 | } |
720 | - return EEH_Event_View::edit_event_link( $EVT_ID ); |
|
720 | + return EEH_Event_View::edit_event_link($EVT_ID); |
|
721 | 721 | } |
722 | 722 | } |
723 | 723 | |
724 | 724 | |
725 | -if ( ! function_exists( 'espresso_organization_name' )) { |
|
725 | +if ( ! function_exists('espresso_organization_name')) { |
|
726 | 726 | /** |
727 | 727 | * espresso_organization_name |
728 | 728 | * @param bool $echo |
729 | 729 | * @return string |
730 | 730 | */ |
731 | 731 | function espresso_organization_name($echo = TRUE) { |
732 | - if($echo){ |
|
733 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
732 | + if ($echo) { |
|
733 | + echo EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
734 | 734 | return ''; |
735 | 735 | } |
736 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
736 | + return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | |
740 | -if ( ! function_exists( 'espresso_organization_address' )) { |
|
740 | +if ( ! function_exists('espresso_organization_address')) { |
|
741 | 741 | /** |
742 | 742 | * espresso_organization_address |
743 | 743 | * @param string $type |
744 | 744 | * @return string |
745 | 745 | */ |
746 | - function espresso_organization_address( $type = 'inline' ) { |
|
747 | - if ( EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config ) { |
|
746 | + function espresso_organization_address($type = 'inline') { |
|
747 | + if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) { |
|
748 | 748 | $address = new EventEspresso\core\domain\entities\GenericAddress( |
749 | 749 | EE_Registry::instance()->CFG->organization->address_1, |
750 | 750 | EE_Registry::instance()->CFG->organization->address_2, |
@@ -753,129 +753,129 @@ discard block |
||
753 | 753 | EE_Registry::instance()->CFG->organization->zip, |
754 | 754 | EE_Registry::instance()->CFG->organization->CNT_ISO |
755 | 755 | ); |
756 | - return EEH_Address::format( $address, $type ); |
|
756 | + return EEH_Address::format($address, $type); |
|
757 | 757 | } |
758 | 758 | return ''; |
759 | 759 | } |
760 | 760 | } |
761 | 761 | |
762 | -if ( ! function_exists( 'espresso_organization_email' )) { |
|
762 | +if ( ! function_exists('espresso_organization_email')) { |
|
763 | 763 | /** |
764 | 764 | * espresso_organization_email |
765 | 765 | * @param bool $echo |
766 | 766 | * @return string |
767 | 767 | */ |
768 | - function espresso_organization_email( $echo = TRUE ) { |
|
769 | - if($echo){ |
|
770 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
768 | + function espresso_organization_email($echo = TRUE) { |
|
769 | + if ($echo) { |
|
770 | + echo EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
771 | 771 | return ''; |
772 | 772 | } |
773 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
773 | + return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
774 | 774 | } |
775 | 775 | } |
776 | 776 | |
777 | -if ( ! function_exists( 'espresso_organization_logo_url' )) { |
|
777 | +if ( ! function_exists('espresso_organization_logo_url')) { |
|
778 | 778 | /** |
779 | 779 | * espresso_organization_logo_url |
780 | 780 | * @param bool $echo |
781 | 781 | * @return string |
782 | 782 | */ |
783 | - function espresso_organization_logo_url( $echo = TRUE ) { |
|
784 | - if($echo){ |
|
785 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
783 | + function espresso_organization_logo_url($echo = TRUE) { |
|
784 | + if ($echo) { |
|
785 | + echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
786 | 786 | return ''; |
787 | 787 | } |
788 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
788 | + return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
789 | 789 | } |
790 | 790 | } |
791 | 791 | |
792 | -if ( ! function_exists( 'espresso_organization_facebook' )) { |
|
792 | +if ( ! function_exists('espresso_organization_facebook')) { |
|
793 | 793 | /** |
794 | 794 | * espresso_organization_facebook |
795 | 795 | * @param bool $echo |
796 | 796 | * @return string |
797 | 797 | */ |
798 | - function espresso_organization_facebook( $echo = TRUE ) { |
|
799 | - if($echo){ |
|
800 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
798 | + function espresso_organization_facebook($echo = TRUE) { |
|
799 | + if ($echo) { |
|
800 | + echo EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
801 | 801 | return ''; |
802 | 802 | } |
803 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
803 | + return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
804 | 804 | } |
805 | 805 | } |
806 | 806 | |
807 | -if ( ! function_exists( 'espresso_organization_twitter' )) { |
|
807 | +if ( ! function_exists('espresso_organization_twitter')) { |
|
808 | 808 | /** |
809 | 809 | * espresso_organization_twitter |
810 | 810 | * @param bool $echo |
811 | 811 | * @return string |
812 | 812 | */ |
813 | - function espresso_organization_twitter( $echo = TRUE ) { |
|
814 | - if($echo){ |
|
815 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
813 | + function espresso_organization_twitter($echo = TRUE) { |
|
814 | + if ($echo) { |
|
815 | + echo EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
816 | 816 | return ''; |
817 | 817 | } |
818 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
818 | + return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
819 | 819 | } |
820 | 820 | } |
821 | 821 | |
822 | -if ( ! function_exists( 'espresso_organization_linkedin' )) { |
|
822 | +if ( ! function_exists('espresso_organization_linkedin')) { |
|
823 | 823 | /** |
824 | 824 | * espresso_organization_linkedin |
825 | 825 | * @param bool $echo |
826 | 826 | * @return string |
827 | 827 | */ |
828 | - function espresso_organization_linkedin( $echo = TRUE ) { |
|
829 | - if($echo){ |
|
830 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
828 | + function espresso_organization_linkedin($echo = TRUE) { |
|
829 | + if ($echo) { |
|
830 | + echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
831 | 831 | return ''; |
832 | 832 | } |
833 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
833 | + return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
834 | 834 | } |
835 | 835 | } |
836 | 836 | |
837 | -if ( ! function_exists( 'espresso_organization_pinterest' )) { |
|
837 | +if ( ! function_exists('espresso_organization_pinterest')) { |
|
838 | 838 | /** |
839 | 839 | * espresso_organization_pinterest |
840 | 840 | * @param bool $echo |
841 | 841 | * @return string |
842 | 842 | */ |
843 | - function espresso_organization_pinterest( $echo = TRUE ) { |
|
844 | - if($echo){ |
|
845 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
843 | + function espresso_organization_pinterest($echo = TRUE) { |
|
844 | + if ($echo) { |
|
845 | + echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
846 | 846 | return ''; |
847 | 847 | } |
848 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
848 | + return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
849 | 849 | } |
850 | 850 | } |
851 | 851 | |
852 | -if ( ! function_exists( 'espresso_organization_google' )) { |
|
852 | +if ( ! function_exists('espresso_organization_google')) { |
|
853 | 853 | /** |
854 | 854 | * espresso_organization_google |
855 | 855 | * @param bool $echo |
856 | 856 | * @return string |
857 | 857 | */ |
858 | - function espresso_organization_google( $echo = TRUE ) { |
|
859 | - if($echo){ |
|
860 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
858 | + function espresso_organization_google($echo = TRUE) { |
|
859 | + if ($echo) { |
|
860 | + echo EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
861 | 861 | return ''; |
862 | 862 | } |
863 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
863 | + return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
864 | 864 | } |
865 | 865 | } |
866 | 866 | |
867 | -if ( ! function_exists( 'espresso_organization_instagram' )) { |
|
867 | +if ( ! function_exists('espresso_organization_instagram')) { |
|
868 | 868 | /** |
869 | 869 | * espresso_organization_instagram |
870 | 870 | * @param bool $echo |
871 | 871 | * @return string |
872 | 872 | */ |
873 | - function espresso_organization_instagram( $echo = TRUE ) { |
|
874 | - if($echo){ |
|
875 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
873 | + function espresso_organization_instagram($echo = TRUE) { |
|
874 | + if ($echo) { |
|
875 | + echo EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
876 | 876 | return ''; |
877 | 877 | } |
878 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
878 | + return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
879 | 879 | } |
880 | 880 | } |
881 | 881 | |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | |
886 | 886 | |
887 | 887 | |
888 | -if ( ! function_exists( 'espresso_event_venues' )) { |
|
888 | +if ( ! function_exists('espresso_event_venues')) { |
|
889 | 889 | /** |
890 | 890 | * espresso_event_venues |
891 | 891 | * |
@@ -899,7 +899,7 @@ discard block |
||
899 | 899 | |
900 | 900 | |
901 | 901 | |
902 | -if ( ! function_exists( 'espresso_venue_id' )) { |
|
902 | +if ( ! function_exists('espresso_venue_id')) { |
|
903 | 903 | /** |
904 | 904 | * espresso_venue_name |
905 | 905 | * |
@@ -907,15 +907,15 @@ discard block |
||
907 | 907 | * @param int $EVT_ID |
908 | 908 | * @return string |
909 | 909 | */ |
910 | - function espresso_venue_id( $EVT_ID = 0 ) { |
|
911 | - $venue = EEH_Venue_View::get_venue( $EVT_ID ); |
|
910 | + function espresso_venue_id($EVT_ID = 0) { |
|
911 | + $venue = EEH_Venue_View::get_venue($EVT_ID); |
|
912 | 912 | return $venue instanceof EE_Venue ? $venue->ID() : 0; |
913 | 913 | } |
914 | 914 | } |
915 | 915 | |
916 | 916 | |
917 | 917 | |
918 | -if ( ! function_exists( 'espresso_is_venue_private' ) ) { |
|
918 | +if ( ! function_exists('espresso_is_venue_private')) { |
|
919 | 919 | /** |
920 | 920 | * Return whether a venue is private or not. |
921 | 921 | * @see EEH_Venue_View::get_venue() for more info on expected return results. |
@@ -924,45 +924,45 @@ discard block |
||
924 | 924 | * |
925 | 925 | * @return bool | null |
926 | 926 | */ |
927 | - function espresso_is_venue_private( $VNU_ID = 0 ) { |
|
928 | - return EEH_Venue_View::is_venue_private( $VNU_ID ); |
|
927 | + function espresso_is_venue_private($VNU_ID = 0) { |
|
928 | + return EEH_Venue_View::is_venue_private($VNU_ID); |
|
929 | 929 | } |
930 | 930 | } |
931 | 931 | |
932 | 932 | |
933 | 933 | |
934 | -if ( ! function_exists( 'espresso_venue_is_password_protected' ) ) { |
|
934 | +if ( ! function_exists('espresso_venue_is_password_protected')) { |
|
935 | 935 | /** |
936 | 936 | * returns true or false if a venue is password protected or not |
937 | 937 | * |
938 | 938 | * @param int $VNU_ID optional, the venue id to check. |
939 | 939 | * @return string |
940 | 940 | */ |
941 | - function espresso_venue_is_password_protected( $VNU_ID = 0 ) { |
|
942 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
943 | - return EEH_Venue_View::is_venue_password_protected( $VNU_ID ); |
|
941 | + function espresso_venue_is_password_protected($VNU_ID = 0) { |
|
942 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
943 | + return EEH_Venue_View::is_venue_password_protected($VNU_ID); |
|
944 | 944 | } |
945 | 945 | } |
946 | 946 | |
947 | 947 | |
948 | 948 | |
949 | -if ( ! function_exists( 'espresso_password_protected_venue_form' ) ) { |
|
949 | +if ( ! function_exists('espresso_password_protected_venue_form')) { |
|
950 | 950 | /** |
951 | 951 | * Returns a password form if venue is password protected. |
952 | 952 | * |
953 | 953 | * @param int $VNU_ID optional, the venue id to check. |
954 | 954 | * @return string |
955 | 955 | */ |
956 | - function espresso_password_protected_venue_form( $VNU_ID = 0 ) { |
|
957 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
958 | - return EEH_Venue_View::password_protected_venue_form( $VNU_ID ); |
|
956 | + function espresso_password_protected_venue_form($VNU_ID = 0) { |
|
957 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
958 | + return EEH_Venue_View::password_protected_venue_form($VNU_ID); |
|
959 | 959 | } |
960 | 960 | } |
961 | 961 | |
962 | 962 | |
963 | 963 | |
964 | 964 | |
965 | -if ( ! function_exists( 'espresso_venue_name' )) { |
|
965 | +if ( ! function_exists('espresso_venue_name')) { |
|
966 | 966 | /** |
967 | 967 | * espresso_venue_name |
968 | 968 | * |
@@ -972,19 +972,19 @@ discard block |
||
972 | 972 | * @param bool $echo |
973 | 973 | * @return string |
974 | 974 | */ |
975 | - function espresso_venue_name( $VNU_ID = 0, $link_to = 'details', $echo = TRUE ) { |
|
976 | - if($echo){ |
|
977 | - echo EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
975 | + function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = TRUE) { |
|
976 | + if ($echo) { |
|
977 | + echo EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
978 | 978 | return ''; |
979 | 979 | } |
980 | - return EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
980 | + return EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
981 | 981 | } |
982 | 982 | } |
983 | 983 | |
984 | 984 | |
985 | 985 | |
986 | 986 | |
987 | -if ( ! function_exists( 'espresso_venue_link' )) { |
|
987 | +if ( ! function_exists('espresso_venue_link')) { |
|
988 | 988 | /** |
989 | 989 | * espresso_venue_link |
990 | 990 | * |
@@ -993,14 +993,14 @@ discard block |
||
993 | 993 | * @param string $text |
994 | 994 | * @return string |
995 | 995 | */ |
996 | - function espresso_venue_link( $VNU_ID = 0, $text = '' ) { |
|
997 | - return EEH_Venue_View::venue_details_link( $VNU_ID, $text ); |
|
996 | + function espresso_venue_link($VNU_ID = 0, $text = '') { |
|
997 | + return EEH_Venue_View::venue_details_link($VNU_ID, $text); |
|
998 | 998 | } |
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | |
1002 | 1002 | |
1003 | -if ( ! function_exists( 'espresso_venue_description' )) { |
|
1003 | +if ( ! function_exists('espresso_venue_description')) { |
|
1004 | 1004 | /** |
1005 | 1005 | * espresso_venue_description |
1006 | 1006 | * |
@@ -1009,17 +1009,17 @@ discard block |
||
1009 | 1009 | * @param bool $echo |
1010 | 1010 | * @return string |
1011 | 1011 | */ |
1012 | - function espresso_venue_description( $VNU_ID = FALSE, $echo = TRUE ) { |
|
1013 | - if($echo){ |
|
1014 | - echo EEH_Venue_View::venue_description( $VNU_ID ); |
|
1012 | + function espresso_venue_description($VNU_ID = FALSE, $echo = TRUE) { |
|
1013 | + if ($echo) { |
|
1014 | + echo EEH_Venue_View::venue_description($VNU_ID); |
|
1015 | 1015 | return ''; |
1016 | 1016 | } |
1017 | - return EEH_Venue_View::venue_description( $VNU_ID ); |
|
1017 | + return EEH_Venue_View::venue_description($VNU_ID); |
|
1018 | 1018 | } |
1019 | 1019 | } |
1020 | 1020 | |
1021 | 1021 | |
1022 | -if ( ! function_exists( 'espresso_venue_excerpt' )) { |
|
1022 | +if ( ! function_exists('espresso_venue_excerpt')) { |
|
1023 | 1023 | /** |
1024 | 1024 | * espresso_venue_excerpt |
1025 | 1025 | * |
@@ -1028,18 +1028,18 @@ discard block |
||
1028 | 1028 | * @param bool $echo |
1029 | 1029 | * @return string |
1030 | 1030 | */ |
1031 | - function espresso_venue_excerpt( $VNU_ID = 0, $echo = TRUE ) { |
|
1032 | - if ( $echo ) { |
|
1033 | - echo EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
1031 | + function espresso_venue_excerpt($VNU_ID = 0, $echo = TRUE) { |
|
1032 | + if ($echo) { |
|
1033 | + echo EEH_Venue_View::venue_excerpt($VNU_ID); |
|
1034 | 1034 | return ''; |
1035 | 1035 | } |
1036 | - return EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
1036 | + return EEH_Venue_View::venue_excerpt($VNU_ID); |
|
1037 | 1037 | } |
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | |
1041 | 1041 | |
1042 | -if ( ! function_exists( 'espresso_venue_categories' )) { |
|
1042 | +if ( ! function_exists('espresso_venue_categories')) { |
|
1043 | 1043 | /** |
1044 | 1044 | * espresso_venue_categories |
1045 | 1045 | * returns the terms associated with a venue |
@@ -1049,17 +1049,17 @@ discard block |
||
1049 | 1049 | * @param bool $echo |
1050 | 1050 | * @return string |
1051 | 1051 | */ |
1052 | - function espresso_venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
1053 | - if ( $echo ) { |
|
1054 | - echo EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
1052 | + function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
1053 | + if ($echo) { |
|
1054 | + echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1055 | 1055 | return ''; |
1056 | 1056 | } |
1057 | - return EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
1057 | + return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
1058 | 1058 | } |
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | |
1062 | -if ( ! function_exists( 'espresso_venue_address' )) { |
|
1062 | +if ( ! function_exists('espresso_venue_address')) { |
|
1063 | 1063 | /** |
1064 | 1064 | * espresso_venue_address |
1065 | 1065 | * returns a formatted block of html for displaying a venue's address |
@@ -1069,17 +1069,17 @@ discard block |
||
1069 | 1069 | * @param bool $echo |
1070 | 1070 | * @return string |
1071 | 1071 | */ |
1072 | - function espresso_venue_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
1073 | - if ( $echo ) { |
|
1074 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
1072 | + function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
1073 | + if ($echo) { |
|
1074 | + echo EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1075 | 1075 | return ''; |
1076 | 1076 | } |
1077 | - return EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
1077 | + return EEH_Venue_View::venue_address($type, $VNU_ID); |
|
1078 | 1078 | } |
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | |
1082 | -if ( ! function_exists( 'espresso_venue_raw_address' )) { |
|
1082 | +if ( ! function_exists('espresso_venue_raw_address')) { |
|
1083 | 1083 | /** |
1084 | 1084 | * espresso_venue_address |
1085 | 1085 | * returns an UN-formatted string containing a venue's address |
@@ -1089,17 +1089,17 @@ discard block |
||
1089 | 1089 | * @param bool $echo |
1090 | 1090 | * @return string |
1091 | 1091 | */ |
1092 | - function espresso_venue_raw_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
1093 | - if ( $echo ) { |
|
1094 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
1092 | + function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
1093 | + if ($echo) { |
|
1094 | + echo EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
1095 | 1095 | return ''; |
1096 | 1096 | } |
1097 | - return EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
1097 | + return EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
1098 | 1098 | } |
1099 | 1099 | } |
1100 | 1100 | |
1101 | 1101 | |
1102 | -if ( ! function_exists( 'espresso_venue_has_address' )) { |
|
1102 | +if ( ! function_exists('espresso_venue_has_address')) { |
|
1103 | 1103 | /** |
1104 | 1104 | * espresso_venue_has_address |
1105 | 1105 | * returns TRUE or FALSE if a Venue has address information |
@@ -1107,13 +1107,13 @@ discard block |
||
1107 | 1107 | * @param int $VNU_ID |
1108 | 1108 | * @return bool |
1109 | 1109 | */ |
1110 | - function espresso_venue_has_address( $VNU_ID = 0 ) { |
|
1111 | - return EEH_Venue_View::venue_has_address( $VNU_ID ); |
|
1110 | + function espresso_venue_has_address($VNU_ID = 0) { |
|
1111 | + return EEH_Venue_View::venue_has_address($VNU_ID); |
|
1112 | 1112 | } |
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | |
1116 | -if ( ! function_exists( 'espresso_venue_gmap' )) { |
|
1116 | +if ( ! function_exists('espresso_venue_gmap')) { |
|
1117 | 1117 | /** |
1118 | 1118 | * espresso_venue_gmap |
1119 | 1119 | * returns a google map for the venue address |
@@ -1124,17 +1124,17 @@ discard block |
||
1124 | 1124 | * @param bool $echo |
1125 | 1125 | * @return string |
1126 | 1126 | */ |
1127 | - function espresso_venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE ) { |
|
1128 | - if ( $echo ) { |
|
1129 | - echo EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
1127 | + function espresso_venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE) { |
|
1128 | + if ($echo) { |
|
1129 | + echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1130 | 1130 | return ''; |
1131 | 1131 | } |
1132 | - return EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
1132 | + return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
1133 | 1133 | } |
1134 | 1134 | } |
1135 | 1135 | |
1136 | 1136 | |
1137 | -if ( ! function_exists( 'espresso_venue_phone' )) { |
|
1137 | +if ( ! function_exists('espresso_venue_phone')) { |
|
1138 | 1138 | /** |
1139 | 1139 | * espresso_venue_phone |
1140 | 1140 | * |
@@ -1142,18 +1142,18 @@ discard block |
||
1142 | 1142 | * @param bool $echo |
1143 | 1143 | * @return string |
1144 | 1144 | */ |
1145 | - function espresso_venue_phone( $VNU_ID = 0, $echo = TRUE ) { |
|
1146 | - if ( $echo ) { |
|
1147 | - echo EEH_Venue_View::venue_phone( $VNU_ID ); |
|
1145 | + function espresso_venue_phone($VNU_ID = 0, $echo = TRUE) { |
|
1146 | + if ($echo) { |
|
1147 | + echo EEH_Venue_View::venue_phone($VNU_ID); |
|
1148 | 1148 | return ''; |
1149 | 1149 | } |
1150 | - return EEH_Venue_View::venue_phone( $VNU_ID ); |
|
1150 | + return EEH_Venue_View::venue_phone($VNU_ID); |
|
1151 | 1151 | } |
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | |
1155 | 1155 | |
1156 | -if ( ! function_exists( 'espresso_venue_website' )) { |
|
1156 | +if ( ! function_exists('espresso_venue_website')) { |
|
1157 | 1157 | /** |
1158 | 1158 | * espresso_venue_website |
1159 | 1159 | * |
@@ -1161,18 +1161,18 @@ discard block |
||
1161 | 1161 | * @param bool $echo |
1162 | 1162 | * @return string |
1163 | 1163 | */ |
1164 | - function espresso_venue_website( $VNU_ID = 0, $echo = TRUE ) { |
|
1165 | - if ( $echo ) { |
|
1166 | - echo EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
1164 | + function espresso_venue_website($VNU_ID = 0, $echo = TRUE) { |
|
1165 | + if ($echo) { |
|
1166 | + echo EEH_Venue_View::venue_website_link($VNU_ID); |
|
1167 | 1167 | return ''; |
1168 | 1168 | } |
1169 | - return EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
1169 | + return EEH_Venue_View::venue_website_link($VNU_ID); |
|
1170 | 1170 | } |
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | |
1174 | 1174 | |
1175 | -if ( ! function_exists( 'espresso_edit_venue_link' )) { |
|
1175 | +if ( ! function_exists('espresso_edit_venue_link')) { |
|
1176 | 1176 | /** |
1177 | 1177 | * espresso_edit_venue_link |
1178 | 1178 | * |
@@ -1180,12 +1180,12 @@ discard block |
||
1180 | 1180 | * @param bool $echo |
1181 | 1181 | * @return string |
1182 | 1182 | */ |
1183 | - function espresso_edit_venue_link( $VNU_ID = 0, $echo = TRUE ) { |
|
1184 | - if($echo){ |
|
1185 | - echo EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
1183 | + function espresso_edit_venue_link($VNU_ID = 0, $echo = TRUE) { |
|
1184 | + if ($echo) { |
|
1185 | + echo EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1186 | 1186 | return ''; |
1187 | 1187 | } |
1188 | - return EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
1188 | + return EEH_Venue_View::edit_venue_link($VNU_ID); |
|
1189 | 1189 | } |
1190 | 1190 | } |
1191 | 1191 |
@@ -31,385 +31,385 @@ |
||
31 | 31 | class PersistentAdminNoticeManager |
32 | 32 | { |
33 | 33 | |
34 | - const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Collection|PersistentAdminNotice[] $notice_collection |
|
38 | - */ |
|
39 | - private $notice_collection; |
|
40 | - |
|
41 | - /** |
|
42 | - * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
43 | - * persistent admin notice was displayed, and ultimately dismissed from. |
|
44 | - * |
|
45 | - * @var string $return_url |
|
46 | - */ |
|
47 | - private $return_url; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var CapabilitiesChecker $capabilities_checker |
|
51 | - */ |
|
52 | - private $capabilities_checker; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var RequestInterface $request |
|
56 | - */ |
|
57 | - private $request; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * PersistentAdminNoticeManager constructor |
|
62 | - * |
|
63 | - * @param string $return_url where to redirect to after dismissing notices |
|
64 | - * @param CapabilitiesChecker $capabilities_checker |
|
65 | - * @param RequestInterface $request |
|
66 | - * @throws InvalidDataTypeException |
|
67 | - */ |
|
68 | - public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request) |
|
69 | - { |
|
70 | - $this->setReturnUrl($return_url); |
|
71 | - $this->capabilities_checker = $capabilities_checker; |
|
72 | - $this->request = $request; |
|
73 | - // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
74 | - // and we want to retrieve and generate any nag notices at the last possible moment |
|
75 | - add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
76 | - add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
77 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
78 | - add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $return_url |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - */ |
|
86 | - public function setReturnUrl($return_url) |
|
87 | - { |
|
88 | - if (! is_string($return_url)) { |
|
89 | - throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
90 | - } |
|
91 | - $this->return_url = $return_url; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @return Collection |
|
97 | - * @throws InvalidEntityException |
|
98 | - * @throws InvalidInterfaceException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws DomainException |
|
101 | - * @throws DuplicateCollectionIdentifierException |
|
102 | - */ |
|
103 | - protected function getPersistentAdminNoticeCollection() |
|
104 | - { |
|
105 | - if (! $this->notice_collection instanceof Collection) { |
|
106 | - $this->notice_collection = new Collection( |
|
107 | - 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
108 | - ); |
|
109 | - $this->retrieveStoredNotices(); |
|
110 | - $this->registerNotices(); |
|
111 | - } |
|
112 | - return $this->notice_collection; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
118 | - * |
|
119 | - * @return void |
|
120 | - * @throws InvalidEntityException |
|
121 | - * @throws DomainException |
|
122 | - * @throws InvalidDataTypeException |
|
123 | - * @throws DuplicateCollectionIdentifierException |
|
124 | - */ |
|
125 | - protected function retrieveStoredNotices() |
|
126 | - { |
|
127 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
128 | - if (! empty($persistent_admin_notices)) { |
|
129 | - foreach ($persistent_admin_notices as $name => $details) { |
|
130 | - if (is_array($details)) { |
|
131 | - if (! isset( |
|
132 | - $details['message'], |
|
133 | - $details['capability'], |
|
134 | - $details['cap_context'], |
|
135 | - $details['dismissed'] |
|
136 | - )) { |
|
137 | - throw new DomainException( |
|
138 | - sprintf( |
|
139 | - esc_html__( |
|
140 | - 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
141 | - 'event_espresso' |
|
142 | - ), |
|
143 | - $name |
|
144 | - ) |
|
145 | - ); |
|
146 | - } |
|
147 | - // new format for nag notices |
|
148 | - $this->notice_collection->add( |
|
149 | - new PersistentAdminNotice( |
|
150 | - $name, |
|
151 | - $details['message'], |
|
152 | - false, |
|
153 | - $details['capability'], |
|
154 | - $details['cap_context'], |
|
155 | - $details['dismissed'] |
|
156 | - ), |
|
157 | - sanitize_key($name) |
|
158 | - ); |
|
159 | - } else { |
|
160 | - try { |
|
161 | - // old nag notices, that we want to convert to the new format |
|
162 | - $this->notice_collection->add( |
|
163 | - new PersistentAdminNotice( |
|
164 | - $name, |
|
165 | - (string) $details, |
|
166 | - false, |
|
167 | - '', |
|
168 | - '', |
|
169 | - empty($details) |
|
170 | - ), |
|
171 | - sanitize_key($name) |
|
172 | - ); |
|
173 | - } catch (Exception $e) { |
|
174 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
175 | - } |
|
176 | - } |
|
177 | - // each notice will self register when the action hook in registerNotices is triggered |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * exposes the Persistent Admin Notice Collection via an action |
|
185 | - * so that PersistentAdminNotice objects can be added and/or removed |
|
186 | - * without compromising the actual collection like a filter would |
|
187 | - */ |
|
188 | - protected function registerNotices() |
|
189 | - { |
|
190 | - do_action( |
|
191 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
192 | - $this->notice_collection |
|
193 | - ); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @throws DomainException |
|
199 | - * @throws InvalidClassException |
|
200 | - * @throws InvalidDataTypeException |
|
201 | - * @throws InvalidInterfaceException |
|
202 | - * @throws InvalidEntityException |
|
203 | - * @throws DuplicateCollectionIdentifierException |
|
204 | - */ |
|
205 | - public function displayNotices() |
|
206 | - { |
|
207 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
208 | - if ($this->notice_collection->hasObjects()) { |
|
209 | - $enqueue_assets = false; |
|
210 | - // and display notices |
|
211 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
212 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
213 | - // don't display notices that have already been dismissed |
|
214 | - if ($persistent_admin_notice->getDismissed()) { |
|
215 | - continue; |
|
216 | - } |
|
217 | - try { |
|
218 | - $this->capabilities_checker->processCapCheck( |
|
219 | - $persistent_admin_notice->getCapCheck() |
|
220 | - ); |
|
221 | - } catch (InsufficientPermissionsException $e) { |
|
222 | - // user does not have required cap, so skip to next notice |
|
223 | - // and just eat the exception - nom nom nom nom |
|
224 | - continue; |
|
225 | - } |
|
226 | - if ($persistent_admin_notice->getMessage() === '') { |
|
227 | - continue; |
|
228 | - } |
|
229 | - $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
230 | - $enqueue_assets = true; |
|
231 | - } |
|
232 | - if ($enqueue_assets) { |
|
233 | - $this->enqueueAssets(); |
|
234 | - } |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * does what it's named |
|
241 | - * |
|
242 | - * @return void |
|
243 | - */ |
|
244 | - public function enqueueAssets() |
|
245 | - { |
|
246 | - wp_register_script( |
|
247 | - 'espresso_core', |
|
248 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
249 | - array('jquery'), |
|
250 | - EVENT_ESPRESSO_VERSION, |
|
251 | - true |
|
252 | - ); |
|
253 | - wp_register_script( |
|
254 | - 'ee_error_js', |
|
255 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
256 | - array('espresso_core'), |
|
257 | - EVENT_ESPRESSO_VERSION, |
|
258 | - true |
|
259 | - ); |
|
260 | - wp_localize_script( |
|
261 | - 'ee_error_js', |
|
262 | - 'ee_dismiss', |
|
263 | - array( |
|
264 | - 'return_url' => urlencode($this->return_url), |
|
265 | - 'ajax_url' => WP_AJAX_URL, |
|
266 | - 'unknown_error' => esc_html__( |
|
267 | - 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
268 | - 'event_espresso' |
|
269 | - ), |
|
270 | - ) |
|
271 | - ); |
|
272 | - wp_enqueue_script('ee_error_js'); |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * displayPersistentAdminNoticeHtml |
|
278 | - * |
|
279 | - * @param PersistentAdminNotice $persistent_admin_notice |
|
280 | - */ |
|
281 | - protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
282 | - { |
|
283 | - // used in template |
|
284 | - $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
285 | - $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
286 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * dismissNotice |
|
292 | - * |
|
293 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
294 | - * @param bool $purge if true, then delete it from the db |
|
295 | - * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
296 | - * @return void |
|
297 | - * @throws InvalidEntityException |
|
298 | - * @throws InvalidInterfaceException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws DomainException |
|
301 | - * @throws InvalidArgumentException |
|
302 | - * @throws InvalidArgumentException |
|
303 | - * @throws InvalidArgumentException |
|
304 | - * @throws InvalidArgumentException |
|
305 | - * @throws DuplicateCollectionIdentifierException |
|
306 | - */ |
|
307 | - public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
308 | - { |
|
309 | - $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name); |
|
310 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
311 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
312 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
313 | - $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
314 | - $persistent_admin_notice->setDismissed(true); |
|
315 | - $persistent_admin_notice->setPurge($purge); |
|
316 | - $this->saveNotices(); |
|
317 | - } |
|
318 | - if ($return) { |
|
319 | - return; |
|
320 | - } |
|
321 | - if ($this->request->isAjax()) { |
|
322 | - // grab any notices and concatenate into string |
|
323 | - echo wp_json_encode( |
|
324 | - array( |
|
325 | - 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
326 | - ) |
|
327 | - ); |
|
328 | - exit(); |
|
329 | - } |
|
330 | - // save errors to a transient to be displayed on next request (after redirect) |
|
331 | - EE_Error::get_notices(false, true); |
|
332 | - wp_safe_redirect( |
|
333 | - urldecode( |
|
334 | - $this->request->getRequestParam('return_url', '') |
|
335 | - ) |
|
336 | - ); |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * saveNotices |
|
342 | - * |
|
343 | - * @throws DomainException |
|
344 | - * @throws InvalidDataTypeException |
|
345 | - * @throws InvalidInterfaceException |
|
346 | - * @throws InvalidEntityException |
|
347 | - * @throws DuplicateCollectionIdentifierException |
|
348 | - */ |
|
349 | - public function saveNotices() |
|
350 | - { |
|
351 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
352 | - if ($this->notice_collection->hasObjects()) { |
|
353 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
354 | - // maybe initialize persistent_admin_notices |
|
355 | - if (empty($persistent_admin_notices)) { |
|
356 | - add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
357 | - } |
|
358 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
359 | - // are we deleting this notice ? |
|
360 | - if ($persistent_admin_notice->getPurge()) { |
|
361 | - unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]); |
|
362 | - } else { |
|
363 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
364 | - $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array( |
|
365 | - 'message' => $persistent_admin_notice->getMessage(), |
|
366 | - 'capability' => $persistent_admin_notice->getCapability(), |
|
367 | - 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
368 | - 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
369 | - ); |
|
370 | - } |
|
371 | - } |
|
372 | - update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @throws DomainException |
|
379 | - * @throws InvalidDataTypeException |
|
380 | - * @throws InvalidEntityException |
|
381 | - * @throws InvalidInterfaceException |
|
382 | - * @throws DuplicateCollectionIdentifierException |
|
383 | - */ |
|
384 | - public function registerAndSaveNotices() |
|
385 | - { |
|
386 | - $this->getPersistentAdminNoticeCollection(); |
|
387 | - $this->registerNotices(); |
|
388 | - $this->saveNotices(); |
|
389 | - add_filter( |
|
390 | - 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
391 | - '__return_true' |
|
392 | - ); |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * @throws DomainException |
|
398 | - * @throws InvalidDataTypeException |
|
399 | - * @throws InvalidEntityException |
|
400 | - * @throws InvalidInterfaceException |
|
401 | - * @throws InvalidArgumentException |
|
402 | - * @throws DuplicateCollectionIdentifierException |
|
403 | - */ |
|
404 | - public static function loadRegisterAndSaveNotices() |
|
405 | - { |
|
406 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
407 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
408 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
409 | - ); |
|
410 | - // if shutdown has already run, then call registerAndSaveNotices() manually |
|
411 | - if (did_action('shutdown')) { |
|
412 | - $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
413 | - } |
|
414 | - } |
|
34 | + const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Collection|PersistentAdminNotice[] $notice_collection |
|
38 | + */ |
|
39 | + private $notice_collection; |
|
40 | + |
|
41 | + /** |
|
42 | + * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
43 | + * persistent admin notice was displayed, and ultimately dismissed from. |
|
44 | + * |
|
45 | + * @var string $return_url |
|
46 | + */ |
|
47 | + private $return_url; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var CapabilitiesChecker $capabilities_checker |
|
51 | + */ |
|
52 | + private $capabilities_checker; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var RequestInterface $request |
|
56 | + */ |
|
57 | + private $request; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * PersistentAdminNoticeManager constructor |
|
62 | + * |
|
63 | + * @param string $return_url where to redirect to after dismissing notices |
|
64 | + * @param CapabilitiesChecker $capabilities_checker |
|
65 | + * @param RequestInterface $request |
|
66 | + * @throws InvalidDataTypeException |
|
67 | + */ |
|
68 | + public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request) |
|
69 | + { |
|
70 | + $this->setReturnUrl($return_url); |
|
71 | + $this->capabilities_checker = $capabilities_checker; |
|
72 | + $this->request = $request; |
|
73 | + // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
74 | + // and we want to retrieve and generate any nag notices at the last possible moment |
|
75 | + add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
76 | + add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
77 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
78 | + add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $return_url |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + */ |
|
86 | + public function setReturnUrl($return_url) |
|
87 | + { |
|
88 | + if (! is_string($return_url)) { |
|
89 | + throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
90 | + } |
|
91 | + $this->return_url = $return_url; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @return Collection |
|
97 | + * @throws InvalidEntityException |
|
98 | + * @throws InvalidInterfaceException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws DomainException |
|
101 | + * @throws DuplicateCollectionIdentifierException |
|
102 | + */ |
|
103 | + protected function getPersistentAdminNoticeCollection() |
|
104 | + { |
|
105 | + if (! $this->notice_collection instanceof Collection) { |
|
106 | + $this->notice_collection = new Collection( |
|
107 | + 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
108 | + ); |
|
109 | + $this->retrieveStoredNotices(); |
|
110 | + $this->registerNotices(); |
|
111 | + } |
|
112 | + return $this->notice_collection; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
118 | + * |
|
119 | + * @return void |
|
120 | + * @throws InvalidEntityException |
|
121 | + * @throws DomainException |
|
122 | + * @throws InvalidDataTypeException |
|
123 | + * @throws DuplicateCollectionIdentifierException |
|
124 | + */ |
|
125 | + protected function retrieveStoredNotices() |
|
126 | + { |
|
127 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
128 | + if (! empty($persistent_admin_notices)) { |
|
129 | + foreach ($persistent_admin_notices as $name => $details) { |
|
130 | + if (is_array($details)) { |
|
131 | + if (! isset( |
|
132 | + $details['message'], |
|
133 | + $details['capability'], |
|
134 | + $details['cap_context'], |
|
135 | + $details['dismissed'] |
|
136 | + )) { |
|
137 | + throw new DomainException( |
|
138 | + sprintf( |
|
139 | + esc_html__( |
|
140 | + 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
141 | + 'event_espresso' |
|
142 | + ), |
|
143 | + $name |
|
144 | + ) |
|
145 | + ); |
|
146 | + } |
|
147 | + // new format for nag notices |
|
148 | + $this->notice_collection->add( |
|
149 | + new PersistentAdminNotice( |
|
150 | + $name, |
|
151 | + $details['message'], |
|
152 | + false, |
|
153 | + $details['capability'], |
|
154 | + $details['cap_context'], |
|
155 | + $details['dismissed'] |
|
156 | + ), |
|
157 | + sanitize_key($name) |
|
158 | + ); |
|
159 | + } else { |
|
160 | + try { |
|
161 | + // old nag notices, that we want to convert to the new format |
|
162 | + $this->notice_collection->add( |
|
163 | + new PersistentAdminNotice( |
|
164 | + $name, |
|
165 | + (string) $details, |
|
166 | + false, |
|
167 | + '', |
|
168 | + '', |
|
169 | + empty($details) |
|
170 | + ), |
|
171 | + sanitize_key($name) |
|
172 | + ); |
|
173 | + } catch (Exception $e) { |
|
174 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
175 | + } |
|
176 | + } |
|
177 | + // each notice will self register when the action hook in registerNotices is triggered |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * exposes the Persistent Admin Notice Collection via an action |
|
185 | + * so that PersistentAdminNotice objects can be added and/or removed |
|
186 | + * without compromising the actual collection like a filter would |
|
187 | + */ |
|
188 | + protected function registerNotices() |
|
189 | + { |
|
190 | + do_action( |
|
191 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
192 | + $this->notice_collection |
|
193 | + ); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @throws DomainException |
|
199 | + * @throws InvalidClassException |
|
200 | + * @throws InvalidDataTypeException |
|
201 | + * @throws InvalidInterfaceException |
|
202 | + * @throws InvalidEntityException |
|
203 | + * @throws DuplicateCollectionIdentifierException |
|
204 | + */ |
|
205 | + public function displayNotices() |
|
206 | + { |
|
207 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
208 | + if ($this->notice_collection->hasObjects()) { |
|
209 | + $enqueue_assets = false; |
|
210 | + // and display notices |
|
211 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
212 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
213 | + // don't display notices that have already been dismissed |
|
214 | + if ($persistent_admin_notice->getDismissed()) { |
|
215 | + continue; |
|
216 | + } |
|
217 | + try { |
|
218 | + $this->capabilities_checker->processCapCheck( |
|
219 | + $persistent_admin_notice->getCapCheck() |
|
220 | + ); |
|
221 | + } catch (InsufficientPermissionsException $e) { |
|
222 | + // user does not have required cap, so skip to next notice |
|
223 | + // and just eat the exception - nom nom nom nom |
|
224 | + continue; |
|
225 | + } |
|
226 | + if ($persistent_admin_notice->getMessage() === '') { |
|
227 | + continue; |
|
228 | + } |
|
229 | + $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
230 | + $enqueue_assets = true; |
|
231 | + } |
|
232 | + if ($enqueue_assets) { |
|
233 | + $this->enqueueAssets(); |
|
234 | + } |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * does what it's named |
|
241 | + * |
|
242 | + * @return void |
|
243 | + */ |
|
244 | + public function enqueueAssets() |
|
245 | + { |
|
246 | + wp_register_script( |
|
247 | + 'espresso_core', |
|
248 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
249 | + array('jquery'), |
|
250 | + EVENT_ESPRESSO_VERSION, |
|
251 | + true |
|
252 | + ); |
|
253 | + wp_register_script( |
|
254 | + 'ee_error_js', |
|
255 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
256 | + array('espresso_core'), |
|
257 | + EVENT_ESPRESSO_VERSION, |
|
258 | + true |
|
259 | + ); |
|
260 | + wp_localize_script( |
|
261 | + 'ee_error_js', |
|
262 | + 'ee_dismiss', |
|
263 | + array( |
|
264 | + 'return_url' => urlencode($this->return_url), |
|
265 | + 'ajax_url' => WP_AJAX_URL, |
|
266 | + 'unknown_error' => esc_html__( |
|
267 | + 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
268 | + 'event_espresso' |
|
269 | + ), |
|
270 | + ) |
|
271 | + ); |
|
272 | + wp_enqueue_script('ee_error_js'); |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * displayPersistentAdminNoticeHtml |
|
278 | + * |
|
279 | + * @param PersistentAdminNotice $persistent_admin_notice |
|
280 | + */ |
|
281 | + protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
282 | + { |
|
283 | + // used in template |
|
284 | + $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
285 | + $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
286 | + require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * dismissNotice |
|
292 | + * |
|
293 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
294 | + * @param bool $purge if true, then delete it from the db |
|
295 | + * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
296 | + * @return void |
|
297 | + * @throws InvalidEntityException |
|
298 | + * @throws InvalidInterfaceException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws DomainException |
|
301 | + * @throws InvalidArgumentException |
|
302 | + * @throws InvalidArgumentException |
|
303 | + * @throws InvalidArgumentException |
|
304 | + * @throws InvalidArgumentException |
|
305 | + * @throws DuplicateCollectionIdentifierException |
|
306 | + */ |
|
307 | + public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
308 | + { |
|
309 | + $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name); |
|
310 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
311 | + if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
312 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
313 | + $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
314 | + $persistent_admin_notice->setDismissed(true); |
|
315 | + $persistent_admin_notice->setPurge($purge); |
|
316 | + $this->saveNotices(); |
|
317 | + } |
|
318 | + if ($return) { |
|
319 | + return; |
|
320 | + } |
|
321 | + if ($this->request->isAjax()) { |
|
322 | + // grab any notices and concatenate into string |
|
323 | + echo wp_json_encode( |
|
324 | + array( |
|
325 | + 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
326 | + ) |
|
327 | + ); |
|
328 | + exit(); |
|
329 | + } |
|
330 | + // save errors to a transient to be displayed on next request (after redirect) |
|
331 | + EE_Error::get_notices(false, true); |
|
332 | + wp_safe_redirect( |
|
333 | + urldecode( |
|
334 | + $this->request->getRequestParam('return_url', '') |
|
335 | + ) |
|
336 | + ); |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * saveNotices |
|
342 | + * |
|
343 | + * @throws DomainException |
|
344 | + * @throws InvalidDataTypeException |
|
345 | + * @throws InvalidInterfaceException |
|
346 | + * @throws InvalidEntityException |
|
347 | + * @throws DuplicateCollectionIdentifierException |
|
348 | + */ |
|
349 | + public function saveNotices() |
|
350 | + { |
|
351 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
352 | + if ($this->notice_collection->hasObjects()) { |
|
353 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
354 | + // maybe initialize persistent_admin_notices |
|
355 | + if (empty($persistent_admin_notices)) { |
|
356 | + add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
357 | + } |
|
358 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
359 | + // are we deleting this notice ? |
|
360 | + if ($persistent_admin_notice->getPurge()) { |
|
361 | + unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]); |
|
362 | + } else { |
|
363 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
364 | + $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array( |
|
365 | + 'message' => $persistent_admin_notice->getMessage(), |
|
366 | + 'capability' => $persistent_admin_notice->getCapability(), |
|
367 | + 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
368 | + 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
369 | + ); |
|
370 | + } |
|
371 | + } |
|
372 | + update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @throws DomainException |
|
379 | + * @throws InvalidDataTypeException |
|
380 | + * @throws InvalidEntityException |
|
381 | + * @throws InvalidInterfaceException |
|
382 | + * @throws DuplicateCollectionIdentifierException |
|
383 | + */ |
|
384 | + public function registerAndSaveNotices() |
|
385 | + { |
|
386 | + $this->getPersistentAdminNoticeCollection(); |
|
387 | + $this->registerNotices(); |
|
388 | + $this->saveNotices(); |
|
389 | + add_filter( |
|
390 | + 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
391 | + '__return_true' |
|
392 | + ); |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * @throws DomainException |
|
398 | + * @throws InvalidDataTypeException |
|
399 | + * @throws InvalidEntityException |
|
400 | + * @throws InvalidInterfaceException |
|
401 | + * @throws InvalidArgumentException |
|
402 | + * @throws DuplicateCollectionIdentifierException |
|
403 | + */ |
|
404 | + public static function loadRegisterAndSaveNotices() |
|
405 | + { |
|
406 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
407 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
408 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
409 | + ); |
|
410 | + // if shutdown has already run, then call registerAndSaveNotices() manually |
|
411 | + if (did_action('shutdown')) { |
|
412 | + $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
413 | + } |
|
414 | + } |
|
415 | 415 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function setReturnUrl($return_url) |
87 | 87 | { |
88 | - if (! is_string($return_url)) { |
|
88 | + if ( ! is_string($return_url)) { |
|
89 | 89 | throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
90 | 90 | } |
91 | 91 | $this->return_url = $return_url; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function getPersistentAdminNoticeCollection() |
104 | 104 | { |
105 | - if (! $this->notice_collection instanceof Collection) { |
|
105 | + if ( ! $this->notice_collection instanceof Collection) { |
|
106 | 106 | $this->notice_collection = new Collection( |
107 | 107 | 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
108 | 108 | ); |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | protected function retrieveStoredNotices() |
126 | 126 | { |
127 | 127 | $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
128 | - if (! empty($persistent_admin_notices)) { |
|
128 | + if ( ! empty($persistent_admin_notices)) { |
|
129 | 129 | foreach ($persistent_admin_notices as $name => $details) { |
130 | 130 | if (is_array($details)) { |
131 | - if (! isset( |
|
131 | + if ( ! isset( |
|
132 | 132 | $details['message'], |
133 | 133 | $details['capability'], |
134 | 134 | $details['cap_context'], |
@@ -245,14 +245,14 @@ discard block |
||
245 | 245 | { |
246 | 246 | wp_register_script( |
247 | 247 | 'espresso_core', |
248 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
248 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
249 | 249 | array('jquery'), |
250 | 250 | EVENT_ESPRESSO_VERSION, |
251 | 251 | true |
252 | 252 | ); |
253 | 253 | wp_register_script( |
254 | 254 | 'ee_error_js', |
255 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
255 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
256 | 256 | array('espresso_core'), |
257 | 257 | EVENT_ESPRESSO_VERSION, |
258 | 258 | true |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | // used in template |
284 | 284 | $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
285 | 285 | $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
286 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
286 | + require EE_TEMPLATES.DS.'notifications'.DS.'persistent_admin_notice.template.php'; |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | { |
309 | 309 | $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name); |
310 | 310 | $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
311 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
311 | + if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
312 | 312 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
313 | 313 | $persistent_admin_notice = $this->notice_collection->get($pan_name); |
314 | 314 | $persistent_admin_notice->setDismissed(true); |
@@ -358,10 +358,10 @@ discard block |
||
358 | 358 | foreach ($this->notice_collection as $persistent_admin_notice) { |
359 | 359 | // are we deleting this notice ? |
360 | 360 | if ($persistent_admin_notice->getPurge()) { |
361 | - unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]); |
|
361 | + unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
362 | 362 | } else { |
363 | 363 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
364 | - $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array( |
|
364 | + $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
365 | 365 | 'message' => $persistent_admin_notice->getMessage(), |
366 | 366 | 'capability' => $persistent_admin_notice->getCapability(), |
367 | 367 | 'cap_context' => $persistent_admin_notice->getCapContext(), |
@@ -25,316 +25,316 @@ |
||
25 | 25 | class PersistentAdminNotice implements RequiresCapCheckInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var string $name |
|
30 | - */ |
|
31 | - protected $name = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string $message |
|
35 | - */ |
|
36 | - protected $message = ''; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var boolean $force_update |
|
40 | - */ |
|
41 | - protected $force_update = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string $capability |
|
45 | - */ |
|
46 | - protected $capability = 'manage_options'; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string $cap_context |
|
50 | - */ |
|
51 | - protected $cap_context = 'view persistent admin notice'; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var boolean $dismissed |
|
55 | - */ |
|
56 | - protected $dismissed = false; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var CapCheckInterface $cap_check |
|
60 | - */ |
|
61 | - protected $cap_check; |
|
62 | - |
|
63 | - /** |
|
64 | - * if true, then this notice will be deleted from the database |
|
65 | - * |
|
66 | - * @var boolean $purge |
|
67 | - */ |
|
68 | - protected $purge = false; |
|
69 | - |
|
70 | - /** |
|
71 | - * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
72 | - * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
73 | - * |
|
74 | - * @var boolean $registered |
|
75 | - */ |
|
76 | - private $registered = false; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * PersistentAdminNotice constructor |
|
81 | - * |
|
82 | - * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
83 | - * @param string $message [required] the message to be stored persistently until dismissed |
|
84 | - * @param bool $force_update enforce the reappearance of a persistent message |
|
85 | - * @param string $capability user capability required to view this notice |
|
86 | - * @param string $cap_context description for why the cap check is being performed |
|
87 | - * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
88 | - * @throws InvalidDataTypeException |
|
89 | - */ |
|
90 | - public function __construct( |
|
91 | - $name, |
|
92 | - $message, |
|
93 | - $force_update = false, |
|
94 | - $capability = 'manage_options', |
|
95 | - $cap_context = 'view persistent admin notice', |
|
96 | - $dismissed = false |
|
97 | - ) { |
|
98 | - $this->setName($name); |
|
99 | - $this->setMessage($message); |
|
100 | - $this->setForceUpdate($force_update); |
|
101 | - $this->setCapability($capability); |
|
102 | - $this->setCapContext($cap_context); |
|
103 | - $this->setDismissed($dismissed); |
|
104 | - add_action( |
|
105 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
106 | - array($this, 'registerPersistentAdminNotice') |
|
107 | - ); |
|
108 | - add_action('shutdown', array($this, 'confirmRegistered'), 999); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public function getName() |
|
116 | - { |
|
117 | - return $this->name; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $name |
|
123 | - * @throws InvalidDataTypeException |
|
124 | - */ |
|
125 | - private function setName($name) |
|
126 | - { |
|
127 | - if (! is_string($name)) { |
|
128 | - throw new InvalidDataTypeException('$name', $name, 'string'); |
|
129 | - } |
|
130 | - $this->name = sanitize_key($name); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public function getMessage() |
|
138 | - { |
|
139 | - return $this->message; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param string $message |
|
145 | - * @throws InvalidDataTypeException |
|
146 | - */ |
|
147 | - private function setMessage($message) |
|
148 | - { |
|
149 | - if (! is_string($message)) { |
|
150 | - throw new InvalidDataTypeException('$message', $message, 'string'); |
|
151 | - } |
|
152 | - global $allowedtags; |
|
153 | - $allowedtags['br'] = array(); |
|
154 | - $this->message = wp_kses($message, $allowedtags); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - public function getForceUpdate() |
|
162 | - { |
|
163 | - return $this->force_update; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @param bool $force_update |
|
169 | - */ |
|
170 | - private function setForceUpdate($force_update) |
|
171 | - { |
|
172 | - $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - public function getCapability() |
|
180 | - { |
|
181 | - return $this->capability; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $capability |
|
187 | - * @throws InvalidDataTypeException |
|
188 | - */ |
|
189 | - private function setCapability($capability) |
|
190 | - { |
|
191 | - if (! is_string($capability)) { |
|
192 | - throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
193 | - } |
|
194 | - $this->capability = ! empty($capability) ? $capability : 'manage_options'; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public function getCapContext() |
|
202 | - { |
|
203 | - return $this->cap_context; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * @param string $cap_context |
|
209 | - * @throws InvalidDataTypeException |
|
210 | - */ |
|
211 | - private function setCapContext($cap_context) |
|
212 | - { |
|
213 | - if (! is_string($cap_context)) { |
|
214 | - throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
215 | - } |
|
216 | - $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice'; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @return bool |
|
222 | - */ |
|
223 | - public function getDismissed() |
|
224 | - { |
|
225 | - return $this->dismissed; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * @param bool $dismissed |
|
231 | - */ |
|
232 | - public function setDismissed($dismissed) |
|
233 | - { |
|
234 | - $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @return CapCheckInterface |
|
240 | - * @throws InvalidDataTypeException |
|
241 | - */ |
|
242 | - public function getCapCheck() |
|
243 | - { |
|
244 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
245 | - $this->setCapCheck( |
|
246 | - new CapCheck( |
|
247 | - $this->capability, |
|
248 | - $this->cap_context |
|
249 | - ) |
|
250 | - ); |
|
251 | - } |
|
252 | - return $this->cap_check; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @param CapCheckInterface $cap_check |
|
258 | - */ |
|
259 | - private function setCapCheck(CapCheckInterface $cap_check) |
|
260 | - { |
|
261 | - $this->cap_check = $cap_check; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return bool |
|
267 | - */ |
|
268 | - public function getPurge() |
|
269 | - { |
|
270 | - return $this->purge; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @param bool $purge |
|
276 | - */ |
|
277 | - public function setPurge($purge) |
|
278 | - { |
|
279 | - $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * given a valid PersistentAdminNotice Collection, |
|
285 | - * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
286 | - * if an existing notice is found that has already been dismissed, |
|
287 | - * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
288 | - * so that the notice is displayed again |
|
289 | - * |
|
290 | - * @param Collection $persistent_admin_notice_collection |
|
291 | - * @throws InvalidEntityException |
|
292 | - * @throws InvalidDataTypeException |
|
293 | - * @throws DuplicateCollectionIdentifierException |
|
294 | - */ |
|
295 | - public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
296 | - { |
|
297 | - if ($this->registered) { |
|
298 | - return; |
|
299 | - } |
|
300 | - // first check if this notice has already been added to the collection |
|
301 | - if ($persistent_admin_notice_collection->has($this->name)) { |
|
302 | - /** @var PersistentAdminNotice $existing */ |
|
303 | - $existing = $persistent_admin_notice_collection->get($this->name); |
|
304 | - // we don't need to add it again (we can't actually) |
|
305 | - // but if it has already been dismissed, and we are overriding with a forced update |
|
306 | - if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
307 | - // then toggle the notice's dismissed state to true |
|
308 | - // so that it gets displayed again |
|
309 | - $existing->setDismissed(false); |
|
310 | - // and make sure the message is set |
|
311 | - $existing->setMessage($this->message); |
|
312 | - } |
|
313 | - } else { |
|
314 | - $persistent_admin_notice_collection->add($this, $this->name); |
|
315 | - } |
|
316 | - $this->registered = true; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @throws Exception |
|
322 | - */ |
|
323 | - public function confirmRegistered() |
|
324 | - { |
|
325 | - if (! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) { |
|
326 | - PersistentAdminNoticeManager::loadRegisterAndSaveNotices(); |
|
327 | - } |
|
328 | - if (! $this->registered && WP_DEBUG) { |
|
329 | - throw new DomainException( |
|
330 | - sprintf( |
|
331 | - esc_html__( |
|
332 | - 'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.', |
|
333 | - 'event_espresso' |
|
334 | - ), |
|
335 | - $this->name |
|
336 | - ) |
|
337 | - ); |
|
338 | - } |
|
339 | - } |
|
28 | + /** |
|
29 | + * @var string $name |
|
30 | + */ |
|
31 | + protected $name = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string $message |
|
35 | + */ |
|
36 | + protected $message = ''; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var boolean $force_update |
|
40 | + */ |
|
41 | + protected $force_update = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string $capability |
|
45 | + */ |
|
46 | + protected $capability = 'manage_options'; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string $cap_context |
|
50 | + */ |
|
51 | + protected $cap_context = 'view persistent admin notice'; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var boolean $dismissed |
|
55 | + */ |
|
56 | + protected $dismissed = false; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var CapCheckInterface $cap_check |
|
60 | + */ |
|
61 | + protected $cap_check; |
|
62 | + |
|
63 | + /** |
|
64 | + * if true, then this notice will be deleted from the database |
|
65 | + * |
|
66 | + * @var boolean $purge |
|
67 | + */ |
|
68 | + protected $purge = false; |
|
69 | + |
|
70 | + /** |
|
71 | + * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
72 | + * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
73 | + * |
|
74 | + * @var boolean $registered |
|
75 | + */ |
|
76 | + private $registered = false; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * PersistentAdminNotice constructor |
|
81 | + * |
|
82 | + * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
83 | + * @param string $message [required] the message to be stored persistently until dismissed |
|
84 | + * @param bool $force_update enforce the reappearance of a persistent message |
|
85 | + * @param string $capability user capability required to view this notice |
|
86 | + * @param string $cap_context description for why the cap check is being performed |
|
87 | + * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
88 | + * @throws InvalidDataTypeException |
|
89 | + */ |
|
90 | + public function __construct( |
|
91 | + $name, |
|
92 | + $message, |
|
93 | + $force_update = false, |
|
94 | + $capability = 'manage_options', |
|
95 | + $cap_context = 'view persistent admin notice', |
|
96 | + $dismissed = false |
|
97 | + ) { |
|
98 | + $this->setName($name); |
|
99 | + $this->setMessage($message); |
|
100 | + $this->setForceUpdate($force_update); |
|
101 | + $this->setCapability($capability); |
|
102 | + $this->setCapContext($cap_context); |
|
103 | + $this->setDismissed($dismissed); |
|
104 | + add_action( |
|
105 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
106 | + array($this, 'registerPersistentAdminNotice') |
|
107 | + ); |
|
108 | + add_action('shutdown', array($this, 'confirmRegistered'), 999); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public function getName() |
|
116 | + { |
|
117 | + return $this->name; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $name |
|
123 | + * @throws InvalidDataTypeException |
|
124 | + */ |
|
125 | + private function setName($name) |
|
126 | + { |
|
127 | + if (! is_string($name)) { |
|
128 | + throw new InvalidDataTypeException('$name', $name, 'string'); |
|
129 | + } |
|
130 | + $this->name = sanitize_key($name); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public function getMessage() |
|
138 | + { |
|
139 | + return $this->message; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param string $message |
|
145 | + * @throws InvalidDataTypeException |
|
146 | + */ |
|
147 | + private function setMessage($message) |
|
148 | + { |
|
149 | + if (! is_string($message)) { |
|
150 | + throw new InvalidDataTypeException('$message', $message, 'string'); |
|
151 | + } |
|
152 | + global $allowedtags; |
|
153 | + $allowedtags['br'] = array(); |
|
154 | + $this->message = wp_kses($message, $allowedtags); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + public function getForceUpdate() |
|
162 | + { |
|
163 | + return $this->force_update; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @param bool $force_update |
|
169 | + */ |
|
170 | + private function setForceUpdate($force_update) |
|
171 | + { |
|
172 | + $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + public function getCapability() |
|
180 | + { |
|
181 | + return $this->capability; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $capability |
|
187 | + * @throws InvalidDataTypeException |
|
188 | + */ |
|
189 | + private function setCapability($capability) |
|
190 | + { |
|
191 | + if (! is_string($capability)) { |
|
192 | + throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
193 | + } |
|
194 | + $this->capability = ! empty($capability) ? $capability : 'manage_options'; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public function getCapContext() |
|
202 | + { |
|
203 | + return $this->cap_context; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * @param string $cap_context |
|
209 | + * @throws InvalidDataTypeException |
|
210 | + */ |
|
211 | + private function setCapContext($cap_context) |
|
212 | + { |
|
213 | + if (! is_string($cap_context)) { |
|
214 | + throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
215 | + } |
|
216 | + $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice'; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @return bool |
|
222 | + */ |
|
223 | + public function getDismissed() |
|
224 | + { |
|
225 | + return $this->dismissed; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * @param bool $dismissed |
|
231 | + */ |
|
232 | + public function setDismissed($dismissed) |
|
233 | + { |
|
234 | + $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @return CapCheckInterface |
|
240 | + * @throws InvalidDataTypeException |
|
241 | + */ |
|
242 | + public function getCapCheck() |
|
243 | + { |
|
244 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
245 | + $this->setCapCheck( |
|
246 | + new CapCheck( |
|
247 | + $this->capability, |
|
248 | + $this->cap_context |
|
249 | + ) |
|
250 | + ); |
|
251 | + } |
|
252 | + return $this->cap_check; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @param CapCheckInterface $cap_check |
|
258 | + */ |
|
259 | + private function setCapCheck(CapCheckInterface $cap_check) |
|
260 | + { |
|
261 | + $this->cap_check = $cap_check; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return bool |
|
267 | + */ |
|
268 | + public function getPurge() |
|
269 | + { |
|
270 | + return $this->purge; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @param bool $purge |
|
276 | + */ |
|
277 | + public function setPurge($purge) |
|
278 | + { |
|
279 | + $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * given a valid PersistentAdminNotice Collection, |
|
285 | + * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
286 | + * if an existing notice is found that has already been dismissed, |
|
287 | + * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
288 | + * so that the notice is displayed again |
|
289 | + * |
|
290 | + * @param Collection $persistent_admin_notice_collection |
|
291 | + * @throws InvalidEntityException |
|
292 | + * @throws InvalidDataTypeException |
|
293 | + * @throws DuplicateCollectionIdentifierException |
|
294 | + */ |
|
295 | + public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
296 | + { |
|
297 | + if ($this->registered) { |
|
298 | + return; |
|
299 | + } |
|
300 | + // first check if this notice has already been added to the collection |
|
301 | + if ($persistent_admin_notice_collection->has($this->name)) { |
|
302 | + /** @var PersistentAdminNotice $existing */ |
|
303 | + $existing = $persistent_admin_notice_collection->get($this->name); |
|
304 | + // we don't need to add it again (we can't actually) |
|
305 | + // but if it has already been dismissed, and we are overriding with a forced update |
|
306 | + if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
307 | + // then toggle the notice's dismissed state to true |
|
308 | + // so that it gets displayed again |
|
309 | + $existing->setDismissed(false); |
|
310 | + // and make sure the message is set |
|
311 | + $existing->setMessage($this->message); |
|
312 | + } |
|
313 | + } else { |
|
314 | + $persistent_admin_notice_collection->add($this, $this->name); |
|
315 | + } |
|
316 | + $this->registered = true; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @throws Exception |
|
322 | + */ |
|
323 | + public function confirmRegistered() |
|
324 | + { |
|
325 | + if (! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) { |
|
326 | + PersistentAdminNoticeManager::loadRegisterAndSaveNotices(); |
|
327 | + } |
|
328 | + if (! $this->registered && WP_DEBUG) { |
|
329 | + throw new DomainException( |
|
330 | + sprintf( |
|
331 | + esc_html__( |
|
332 | + 'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.', |
|
333 | + 'event_espresso' |
|
334 | + ), |
|
335 | + $this->name |
|
336 | + ) |
|
337 | + ); |
|
338 | + } |
|
339 | + } |
|
340 | 340 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.022'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.022'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |