@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -36,82 +36,82 @@ discard block |
||
36 | 36 | { |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * _init_props |
|
41 | - * |
|
42 | - * @access protected |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - protected function _init_props() |
|
46 | - { |
|
47 | - $this->label = __('Attendee Shortcodes', 'event_espresso'); |
|
48 | - $this->description = __('All shortcodes specific to attendee related data', 'event_espresso'); |
|
49 | - $this->_shortcodes = array( |
|
50 | - '[QUESTION]' => __('Will parse to a question.', 'event_espresso'), |
|
51 | - '[ANSWER]' => __('Will parse to the answer for a question', 'event_espresso') |
|
52 | - ); |
|
53 | - } |
|
39 | + /** |
|
40 | + * _init_props |
|
41 | + * |
|
42 | + * @access protected |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + protected function _init_props() |
|
46 | + { |
|
47 | + $this->label = __('Attendee Shortcodes', 'event_espresso'); |
|
48 | + $this->description = __('All shortcodes specific to attendee related data', 'event_espresso'); |
|
49 | + $this->_shortcodes = array( |
|
50 | + '[QUESTION]' => __('Will parse to a question.', 'event_espresso'), |
|
51 | + '[ANSWER]' => __('Will parse to the answer for a question', 'event_espresso') |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
58 | - * will have to take care of handling. |
|
59 | - * |
|
60 | - * @access protected |
|
61 | - * |
|
62 | - * @param string $shortcode the shortcode to be parsed. |
|
63 | - * |
|
64 | - * @return string parsed shortcode |
|
65 | - */ |
|
66 | - protected function _parser($shortcode) |
|
67 | - { |
|
56 | + /** |
|
57 | + * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
58 | + * will have to take care of handling. |
|
59 | + * |
|
60 | + * @access protected |
|
61 | + * |
|
62 | + * @param string $shortcode the shortcode to be parsed. |
|
63 | + * |
|
64 | + * @return string parsed shortcode |
|
65 | + */ |
|
66 | + protected function _parser($shortcode) |
|
67 | + { |
|
68 | 68 | |
69 | - if ( ! $this->_data instanceof EE_Answer || ! isset($this->_extra_data['data']) || ! $this->_extra_data['data'] instanceof EE_Messages_Addressee) { |
|
70 | - return ''; |
|
71 | - } |
|
69 | + if ( ! $this->_data instanceof EE_Answer || ! isset($this->_extra_data['data']) || ! $this->_extra_data['data'] instanceof EE_Messages_Addressee) { |
|
70 | + return ''; |
|
71 | + } |
|
72 | 72 | |
73 | - switch ($shortcode) { |
|
73 | + switch ($shortcode) { |
|
74 | 74 | |
75 | - case '[QUESTION]' : |
|
76 | - $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); |
|
77 | - if ( ! $question instanceof EE_Question) { |
|
78 | - return ''; //get out because we can't figure out what the question is. |
|
79 | - } |
|
75 | + case '[QUESTION]' : |
|
76 | + $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); |
|
77 | + if ( ! $question instanceof EE_Question) { |
|
78 | + return ''; //get out because we can't figure out what the question is. |
|
79 | + } |
|
80 | 80 | |
81 | - return $question->get('QST_display_text'); |
|
82 | - break; |
|
81 | + return $question->get('QST_display_text'); |
|
82 | + break; |
|
83 | 83 | |
84 | - case '[ANSWER]' : |
|
85 | - //need to get the question to determine the type of question (some questions require translation of the answer). |
|
86 | - $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); |
|
87 | - if ( ! $question instanceof EE_Question) { |
|
88 | - return ''; //get out cause we can't figure out what the question type is! |
|
89 | - } |
|
84 | + case '[ANSWER]' : |
|
85 | + //need to get the question to determine the type of question (some questions require translation of the answer). |
|
86 | + $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); |
|
87 | + if ( ! $question instanceof EE_Question) { |
|
88 | + return ''; //get out cause we can't figure out what the question type is! |
|
89 | + } |
|
90 | 90 | |
91 | - //what we show for the answer depends on the question type! |
|
92 | - switch ($question->get('QST_type')) { |
|
91 | + //what we show for the answer depends on the question type! |
|
92 | + switch ($question->get('QST_type')) { |
|
93 | 93 | |
94 | - case 'STATE' : |
|
95 | - $state = EEM_State::instance()->get_one_by_ID($this->_data->get('ANS_value')); |
|
96 | - $answer = $state instanceof EE_State ? $state->name() : ''; |
|
97 | - break; |
|
94 | + case 'STATE' : |
|
95 | + $state = EEM_State::instance()->get_one_by_ID($this->_data->get('ANS_value')); |
|
96 | + $answer = $state instanceof EE_State ? $state->name() : ''; |
|
97 | + break; |
|
98 | 98 | |
99 | - case 'COUNTRY' : |
|
100 | - $country = EEM_Country::instance()->get_one_by_ID($this->_data->get('ANS_value')); |
|
101 | - $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
102 | - break; |
|
99 | + case 'COUNTRY' : |
|
100 | + $country = EEM_Country::instance()->get_one_by_ID($this->_data->get('ANS_value')); |
|
101 | + $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
102 | + break; |
|
103 | 103 | |
104 | - default : |
|
105 | - $answer = $this->_data->get_pretty('ANS_value', 'no_wpautop'); |
|
106 | - break; |
|
107 | - } |
|
104 | + default : |
|
105 | + $answer = $this->_data->get_pretty('ANS_value', 'no_wpautop'); |
|
106 | + break; |
|
107 | + } |
|
108 | 108 | |
109 | - return $answer; |
|
110 | - break; |
|
109 | + return $answer; |
|
110 | + break; |
|
111 | 111 | |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - return ''; |
|
115 | - } |
|
114 | + return ''; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | } //end EE_Question_Shortcodes class |
@@ -450,7 +450,7 @@ |
||
450 | 450 | |
451 | 451 | |
452 | 452 | /** |
453 | - * @param $Request |
|
453 | + * @param string $Request |
|
454 | 454 | * @return mixed |
455 | 455 | */ |
456 | 456 | private function _CURLRequest($Request) |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -25,549 +25,549 @@ discard block |
||
25 | 25 | class EEG_Paypal_Pro extends EE_Onsite_Gateway |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var $_paypal_api_username string |
|
30 | - */ |
|
31 | - protected $_username = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var $_password string |
|
35 | - */ |
|
36 | - protected $_password = null; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var $_signature string |
|
40 | - */ |
|
41 | - protected $_signature = null; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
45 | - */ |
|
46 | - protected $_credit_card_types = null; |
|
47 | - |
|
48 | - protected $_currencies_supported = array( |
|
49 | - 'USD', |
|
50 | - 'GBP', |
|
51 | - 'CAD', |
|
52 | - 'AUD', |
|
53 | - 'BRL', |
|
54 | - 'CHF', |
|
55 | - 'CZK', |
|
56 | - 'DKK', |
|
57 | - 'EUR', |
|
58 | - 'HKD', |
|
59 | - 'HUF', |
|
60 | - 'ILS', |
|
61 | - 'JPY', |
|
62 | - 'MXN', |
|
63 | - 'MYR', |
|
64 | - 'NOK', |
|
65 | - 'NZD', |
|
66 | - 'PHP', |
|
67 | - 'PLN', |
|
68 | - 'SEK', |
|
69 | - 'SGD', |
|
70 | - 'THB', |
|
71 | - 'TRY', |
|
72 | - 'TWD', |
|
73 | - 'RUB', |
|
74 | - ); |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param EEI_Payment $payment |
|
80 | - * @param array $billing_info { |
|
81 | - * @type $credit_card string |
|
82 | - * @type $credit_card_type string |
|
83 | - * @type $exp_month string always 2 characters |
|
84 | - * @type $exp_year string always 4 characters |
|
85 | - * @type $cvv string |
|
86 | - * } @see parent::do_direct_payment for more info |
|
87 | - * @return \EE_Payment|\EEI_Payment |
|
88 | - */ |
|
89 | - public function do_direct_payment($payment, $billing_info = null) |
|
90 | - { |
|
91 | - $transaction = $payment->transaction(); |
|
92 | - if (! $transaction instanceof EEI_Transaction) { |
|
93 | - throw new EE_Error(esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')); |
|
94 | - } |
|
95 | - $primary_registrant = $transaction->primary_registration(); |
|
96 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
97 | - throw new EE_Error(esc_html__('No primary registration on transaction while paying with PayPal Pro.', |
|
98 | - 'event_espresso')); |
|
99 | - } |
|
100 | - $attendee = $primary_registrant->attendee(); |
|
101 | - if (! $attendee instanceof EEI_Attendee) { |
|
102 | - throw new EE_Error(esc_html__('No attendee on primary registration while paying with PayPal Pro.', |
|
103 | - 'event_espresso')); |
|
104 | - } |
|
105 | - $order_description = $this->_format_order_description($payment); |
|
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 | - $this->_format_line_item_name($line_item, $payment), |
|
120 | - 0, |
|
121 | - 127 |
|
122 | - ), |
|
123 | - // Item description. 127 char max. |
|
124 | - 'l_desc' => substr( |
|
125 | - $this->_format_line_item_desc($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 | - $this->_format_partial_payment_line_item_name($payment), |
|
157 | - 0, |
|
158 | - 127 |
|
159 | - ), |
|
160 | - // Item description. 127 char max. |
|
161 | - 'l_desc' => substr( |
|
162 | - $this->_format_partial_payment_line_item_desc($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 indidicates 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. In addition, either start date or issue number must be specified. |
|
188 | - 'creditcardtype' => $billing_info['credit_card_type'], |
|
189 | - // Required. Credit card number. No spaces or punctuation. |
|
190 | - 'acct' => $billing_info['credit_card'], |
|
191 | - // Required. Credit card expiration date. Format is MMYYYY |
|
192 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
193 | - // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
194 | - 'cvv2' => $billing_info['cvv'], |
|
195 | - ); |
|
196 | - $PayerInfo = array( |
|
197 | - // Email address of payer. |
|
198 | - 'email' => $billing_info['email'], |
|
199 | - // Unique PayPal customer ID for payer. |
|
200 | - 'payerid' => '', |
|
201 | - // Status of payer. Values are verified or unverified |
|
202 | - 'payerstatus' => '', |
|
203 | - // Payer's business name. |
|
204 | - 'business' => '', |
|
205 | - ); |
|
206 | - $PayerName = array( |
|
207 | - // Payer's salutation. 20 char max. |
|
208 | - 'salutation' => '', |
|
209 | - // Payer's first name. 25 char max. |
|
210 | - 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
211 | - // Payer's middle name. 25 char max. |
|
212 | - 'middlename' => '', |
|
213 | - // Payer's last name. 25 char max. |
|
214 | - 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
215 | - // Payer's suffix. 12 char max. |
|
216 | - 'suffix' => '', |
|
217 | - ); |
|
218 | - $BillingAddress = array( |
|
219 | - // Required. First street address. |
|
220 | - 'street' => $billing_info['address'], |
|
221 | - // Second street address. |
|
222 | - 'street2' => $billing_info['address2'], |
|
223 | - // Required. Name of City. |
|
224 | - 'city' => $billing_info['city'], |
|
225 | - // Required. Name of State or Province. |
|
226 | - 'state' => substr($billing_info['state'], 0, 40), |
|
227 | - // Required. Country code. |
|
228 | - 'countrycode' => $billing_info['country'], |
|
229 | - // Required. Postal code of payer. |
|
230 | - 'zip' => $billing_info['zip'], |
|
231 | - ); |
|
232 | - //check if the registration info contains the needed fields for paypal pro (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
233 | - if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
234 | - $use_registration_address_info = true; |
|
235 | - } else { |
|
236 | - $use_registration_address_info = false; |
|
237 | - } |
|
238 | - //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. If not, use the billing info again |
|
239 | - $ShippingAddress = array( |
|
240 | - 'shiptoname' => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
241 | - 'shiptostreet' => substr($use_registration_address_info ? $attendee->address() : $billing_info['address'], 0, 100), |
|
242 | - 'shiptostreet2' => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
243 | - 'shiptocity' => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'], 0, 40), |
|
244 | - 'state' => substr($use_registration_address_info ? $attendee->state_name() : $billing_info['state'], 0, 40), |
|
245 | - 'shiptocountry' => $use_registration_address_info ? $attendee->country_ID() : $billing_info['country'], |
|
246 | - 'shiptozip' => substr($use_registration_address_info ? $attendee->zip() : $billing_info['zip'], 0, 20), |
|
247 | - 'shiptophonenum' => substr($use_registration_address_info ? $attendee->phone() : $billing_info['phone'], 0, 20), |
|
248 | - ); |
|
249 | - $PaymentDetails = array( |
|
250 | - // Required. Total amount of order, including shipping, handling, and tax. |
|
251 | - 'amt' => $this->format_currency($payment->amount()), |
|
252 | - // Required. Three-letter currency code. Default is USD. |
|
253 | - 'currencycode' => $payment->currency_code(), |
|
254 | - // Required if you include itemized cart details. (L_AMTn, etc.) Subtotal of items not including S&H, or tax. |
|
255 | - 'itemamt' => $this->format_currency($item_amount),// |
|
256 | - // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
257 | - 'shippingamt' => '', |
|
258 | - // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
259 | - 'handlingamt' => '', |
|
260 | - // Required if you specify itemized cart tax details. Sum of tax for all items on the order. Total sales tax. |
|
261 | - 'taxamt' => $this->format_currency($tax_amount), |
|
262 | - // Description of the order the customer is purchasing. 127 char max. |
|
263 | - 'desc' => $order_description, |
|
264 | - // Free-form field for your own use. 256 char max. |
|
265 | - 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
266 | - // Your own invoice or tracking number |
|
267 | - 'invnum' => wp_generate_password(12, false),//$transaction->ID(), |
|
268 | - // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
269 | - 'notifyurl' => '', |
|
270 | - 'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this |
|
271 | - ); |
|
272 | - // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
273 | - $PayPalRequestData = array( |
|
274 | - 'DPFields' => $DPFields, |
|
275 | - 'CCDetails' => $CCDetails, |
|
276 | - 'PayerInfo' => $PayerInfo, |
|
277 | - 'PayerName' => $PayerName, |
|
278 | - 'BillingAddress' => $BillingAddress, |
|
279 | - 'ShippingAddress' => $ShippingAddress, |
|
280 | - 'PaymentDetails' => $PaymentDetails, |
|
281 | - 'OrderItems' => $order_items, |
|
282 | - ); |
|
283 | - $this->_log_clean_request($PayPalRequestData, $payment); |
|
284 | - try { |
|
285 | - $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
286 | - //remove PCI-sensitive data so it doesn't get stored |
|
287 | - $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
288 | - $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK']; |
|
289 | - if (empty($PayPalResult['RAWRESPONSE'])) { |
|
290 | - $payment->set_status($this->_pay_model->failed_status()); |
|
291 | - $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
292 | - $payment->set_details($PayPalResult); |
|
293 | - } else { |
|
294 | - if ($this->_APICallSuccessful($PayPalResult)) { |
|
295 | - $payment->set_status($this->_pay_model->approved_status()); |
|
296 | - } else { |
|
297 | - $payment->set_status($this->_pay_model->declined_status()); |
|
298 | - } |
|
299 | - //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
300 | - $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
301 | - $payment->set_gateway_response($message); |
|
302 | - $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) ? $PayPalResult['TRANSACTIONID'] : null); |
|
303 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : ''; |
|
304 | - $payment->set_extra_accntng($primary_registration_code); |
|
305 | - $payment->set_details($PayPalResult); |
|
306 | - } |
|
307 | - } catch (Exception $e) { |
|
308 | - $payment->set_status($this->_pay_model->failed_status()); |
|
309 | - $payment->set_gateway_response($e->getMessage()); |
|
310 | - } |
|
311 | - //$payment->set_status( $this->_pay_model->declined_status() ); |
|
312 | - //$payment->set_gateway_response( '' ); |
|
313 | - return $payment; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
320 | - * |
|
321 | - * @param array $request |
|
322 | - * @param EEI_Payment $payment |
|
323 | - * @return array |
|
324 | - */ |
|
325 | - private function _log_clean_request($request, $payment) |
|
326 | - { |
|
327 | - $cleaned_request_data = $request; |
|
328 | - unset($cleaned_request_data['CCDetails']['acct']); |
|
329 | - unset($cleaned_request_data['CCDetails']['cvv2']); |
|
330 | - unset($cleaned_request_data['CCDetails']['expdate']); |
|
331 | - $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Cleans the response, logs it, and returns it |
|
338 | - * |
|
339 | - * @param array $response |
|
340 | - * @param EEI_Payment $payment |
|
341 | - * @return array cleaned |
|
342 | - */ |
|
343 | - private function _log_clean_response($response, $payment) |
|
344 | - { |
|
345 | - unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
346 | - unset($response['REQUESTDATA']['ACCT']); |
|
347 | - unset($response['REQUESTDATA']['EXPDATE']); |
|
348 | - unset($response['REQUESTDATA']['CVV2']); |
|
349 | - unset($response['RAWREQUEST']); |
|
350 | - $this->log(array('Paypal Response' => $response), $payment); |
|
351 | - return $response; |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * @param $DataArray |
|
358 | - * @return array |
|
359 | - */ |
|
360 | - private function prep_and_curl_request($DataArray) |
|
361 | - { |
|
362 | - // Create empty holders for each portion of the NVP string |
|
363 | - $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
364 | - $CCDetailsNVP = ''; |
|
365 | - $PayerInfoNVP = ''; |
|
366 | - $PayerNameNVP = ''; |
|
367 | - $BillingAddressNVP = ''; |
|
368 | - $ShippingAddressNVP = ''; |
|
369 | - $PaymentDetailsNVP = ''; |
|
370 | - $OrderItemsNVP = ''; |
|
371 | - $Secure3DNVP = ''; |
|
372 | - // DP Fields |
|
373 | - $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
374 | - foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
375 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
376 | - } |
|
377 | - // CC Details Fields |
|
378 | - $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
379 | - foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
380 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
381 | - } |
|
382 | - // PayerInfo Type Fields |
|
383 | - $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
384 | - foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
385 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
386 | - } |
|
387 | - // Payer Name Fields |
|
388 | - $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
389 | - foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
390 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
391 | - } |
|
392 | - // Address Fields (Billing) |
|
393 | - $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
394 | - foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
395 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
396 | - } |
|
397 | - // Payment Details Type Fields |
|
398 | - $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
399 | - foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
400 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
401 | - } |
|
402 | - // Payment Details Item Type Fields |
|
403 | - $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
404 | - $n = 0; |
|
405 | - foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
406 | - $CurrentItem = $OrderItems[$OrderItemsVar]; |
|
407 | - foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
408 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
409 | - } |
|
410 | - $n++; |
|
411 | - } |
|
412 | - // Ship To Address Fields |
|
413 | - $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
414 | - foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
415 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
416 | - } |
|
417 | - // 3D Secure Fields |
|
418 | - $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
419 | - foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
420 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
421 | - } |
|
422 | - // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
423 | - $NVPRequest = 'USER=' |
|
424 | - . $this->_username |
|
425 | - . '&PWD=' |
|
426 | - . $this->_password |
|
427 | - . '&VERSION=64.0' |
|
428 | - . '&SIGNATURE=' |
|
429 | - . $this->_signature |
|
430 | - . $DPFieldsNVP |
|
431 | - . $CCDetailsNVP |
|
432 | - . $PayerInfoNVP |
|
433 | - . $PayerNameNVP |
|
434 | - . $BillingAddressNVP |
|
435 | - . $PaymentDetailsNVP |
|
436 | - . $OrderItemsNVP |
|
437 | - . $ShippingAddressNVP |
|
438 | - . $Secure3DNVP; |
|
439 | - $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
440 | - $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
441 | - $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
442 | - $Errors = $this->_GetErrors($NVPResponseArray); |
|
443 | - $NVPResponseArray['ERRORS'] = $Errors; |
|
444 | - $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
445 | - $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
446 | - $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
447 | - return $NVPResponseArray; |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * @param $Request |
|
454 | - * @return mixed |
|
455 | - */ |
|
456 | - private function _CURLRequest($Request) |
|
457 | - { |
|
458 | - $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
459 | - $curl = curl_init(); |
|
460 | - curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
461 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
462 | - curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
463 | - curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
464 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
465 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
466 | - curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
467 | - //execute the curl POST |
|
468 | - $Response = curl_exec($curl); |
|
469 | - curl_close($curl); |
|
470 | - return $Response; |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * @param $NVPString |
|
477 | - * @return array |
|
478 | - */ |
|
479 | - private function _NVPToArray($NVPString) |
|
480 | - { |
|
481 | - // prepare responses into array |
|
482 | - $proArray = array(); |
|
483 | - while (strlen($NVPString)) { |
|
484 | - // name |
|
485 | - $keypos = strpos($NVPString, '='); |
|
486 | - $keyval = substr($NVPString, 0, $keypos); |
|
487 | - // value |
|
488 | - $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
489 | - $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
490 | - // decoding the respose |
|
491 | - $proArray[$keyval] = urldecode($valval); |
|
492 | - $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
493 | - } |
|
494 | - return $proArray; |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * @param array $PayPalResult |
|
501 | - * @return bool |
|
502 | - */ |
|
503 | - private function _APICallSuccessful($PayPalResult) |
|
504 | - { |
|
505 | - $approved = false; |
|
506 | - // check main response message from PayPal |
|
507 | - if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
508 | - $ack = strtoupper($PayPalResult['ACK']); |
|
509 | - $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
510 | - } |
|
511 | - return $approved; |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * @param $DataArray |
|
518 | - * @return array |
|
519 | - */ |
|
520 | - private function _GetErrors($DataArray) |
|
521 | - { |
|
522 | - $Errors = array(); |
|
523 | - $n = 0; |
|
524 | - while (isset($DataArray['L_ERRORCODE' . $n . ''])) { |
|
525 | - $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : ''; |
|
526 | - $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) ? $DataArray['L_SHORTMESSAGE' . $n . ''] : ''; |
|
527 | - $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) ? $DataArray['L_LONGMESSAGE' . $n . ''] : ''; |
|
528 | - $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) ? $DataArray['L_SEVERITYCODE' . $n . ''] : ''; |
|
529 | - $CurrentItem = array( |
|
530 | - 'L_ERRORCODE' => $LErrorCode, |
|
531 | - 'L_SHORTMESSAGE' => $LShortMessage, |
|
532 | - 'L_LONGMESSAGE' => $LLongMessage, |
|
533 | - 'L_SEVERITYCODE' => $LSeverityCode, |
|
534 | - ); |
|
535 | - array_push($Errors, $CurrentItem); |
|
536 | - $n++; |
|
537 | - } |
|
538 | - return $Errors; |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * nothing to see here... move along.... |
|
545 | - * |
|
546 | - * @access protected |
|
547 | - * @param $Errors |
|
548 | - * @return string |
|
549 | - */ |
|
550 | - private function _DisplayErrors($Errors) |
|
551 | - { |
|
552 | - $error = ''; |
|
553 | - foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
554 | - $CurrentError = $Errors[$ErrorVar]; |
|
555 | - foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
556 | - $CurrentVarName = ''; |
|
557 | - if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
558 | - $CurrentVarName = 'Error Code'; |
|
559 | - } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
560 | - $CurrentVarName = 'Short Message'; |
|
561 | - } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
562 | - $CurrentVarName = 'Long Message'; |
|
563 | - } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
564 | - $CurrentVarName = 'Severity Code'; |
|
565 | - } |
|
566 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
567 | - } |
|
568 | - } |
|
569 | - return $error; |
|
570 | - } |
|
28 | + /** |
|
29 | + * @var $_paypal_api_username string |
|
30 | + */ |
|
31 | + protected $_username = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var $_password string |
|
35 | + */ |
|
36 | + protected $_password = null; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var $_signature string |
|
40 | + */ |
|
41 | + protected $_signature = null; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
45 | + */ |
|
46 | + protected $_credit_card_types = null; |
|
47 | + |
|
48 | + protected $_currencies_supported = array( |
|
49 | + 'USD', |
|
50 | + 'GBP', |
|
51 | + 'CAD', |
|
52 | + 'AUD', |
|
53 | + 'BRL', |
|
54 | + 'CHF', |
|
55 | + 'CZK', |
|
56 | + 'DKK', |
|
57 | + 'EUR', |
|
58 | + 'HKD', |
|
59 | + 'HUF', |
|
60 | + 'ILS', |
|
61 | + 'JPY', |
|
62 | + 'MXN', |
|
63 | + 'MYR', |
|
64 | + 'NOK', |
|
65 | + 'NZD', |
|
66 | + 'PHP', |
|
67 | + 'PLN', |
|
68 | + 'SEK', |
|
69 | + 'SGD', |
|
70 | + 'THB', |
|
71 | + 'TRY', |
|
72 | + 'TWD', |
|
73 | + 'RUB', |
|
74 | + ); |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param EEI_Payment $payment |
|
80 | + * @param array $billing_info { |
|
81 | + * @type $credit_card string |
|
82 | + * @type $credit_card_type string |
|
83 | + * @type $exp_month string always 2 characters |
|
84 | + * @type $exp_year string always 4 characters |
|
85 | + * @type $cvv string |
|
86 | + * } @see parent::do_direct_payment for more info |
|
87 | + * @return \EE_Payment|\EEI_Payment |
|
88 | + */ |
|
89 | + public function do_direct_payment($payment, $billing_info = null) |
|
90 | + { |
|
91 | + $transaction = $payment->transaction(); |
|
92 | + if (! $transaction instanceof EEI_Transaction) { |
|
93 | + throw new EE_Error(esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')); |
|
94 | + } |
|
95 | + $primary_registrant = $transaction->primary_registration(); |
|
96 | + if (! $primary_registrant instanceof EEI_Registration) { |
|
97 | + throw new EE_Error(esc_html__('No primary registration on transaction while paying with PayPal Pro.', |
|
98 | + 'event_espresso')); |
|
99 | + } |
|
100 | + $attendee = $primary_registrant->attendee(); |
|
101 | + if (! $attendee instanceof EEI_Attendee) { |
|
102 | + throw new EE_Error(esc_html__('No attendee on primary registration while paying with PayPal Pro.', |
|
103 | + 'event_espresso')); |
|
104 | + } |
|
105 | + $order_description = $this->_format_order_description($payment); |
|
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 | + $this->_format_line_item_name($line_item, $payment), |
|
120 | + 0, |
|
121 | + 127 |
|
122 | + ), |
|
123 | + // Item description. 127 char max. |
|
124 | + 'l_desc' => substr( |
|
125 | + $this->_format_line_item_desc($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 | + $this->_format_partial_payment_line_item_name($payment), |
|
157 | + 0, |
|
158 | + 127 |
|
159 | + ), |
|
160 | + // Item description. 127 char max. |
|
161 | + 'l_desc' => substr( |
|
162 | + $this->_format_partial_payment_line_item_desc($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 indidicates 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. In addition, either start date or issue number must be specified. |
|
188 | + 'creditcardtype' => $billing_info['credit_card_type'], |
|
189 | + // Required. Credit card number. No spaces or punctuation. |
|
190 | + 'acct' => $billing_info['credit_card'], |
|
191 | + // Required. Credit card expiration date. Format is MMYYYY |
|
192 | + 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
193 | + // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
194 | + 'cvv2' => $billing_info['cvv'], |
|
195 | + ); |
|
196 | + $PayerInfo = array( |
|
197 | + // Email address of payer. |
|
198 | + 'email' => $billing_info['email'], |
|
199 | + // Unique PayPal customer ID for payer. |
|
200 | + 'payerid' => '', |
|
201 | + // Status of payer. Values are verified or unverified |
|
202 | + 'payerstatus' => '', |
|
203 | + // Payer's business name. |
|
204 | + 'business' => '', |
|
205 | + ); |
|
206 | + $PayerName = array( |
|
207 | + // Payer's salutation. 20 char max. |
|
208 | + 'salutation' => '', |
|
209 | + // Payer's first name. 25 char max. |
|
210 | + 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
211 | + // Payer's middle name. 25 char max. |
|
212 | + 'middlename' => '', |
|
213 | + // Payer's last name. 25 char max. |
|
214 | + 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
215 | + // Payer's suffix. 12 char max. |
|
216 | + 'suffix' => '', |
|
217 | + ); |
|
218 | + $BillingAddress = array( |
|
219 | + // Required. First street address. |
|
220 | + 'street' => $billing_info['address'], |
|
221 | + // Second street address. |
|
222 | + 'street2' => $billing_info['address2'], |
|
223 | + // Required. Name of City. |
|
224 | + 'city' => $billing_info['city'], |
|
225 | + // Required. Name of State or Province. |
|
226 | + 'state' => substr($billing_info['state'], 0, 40), |
|
227 | + // Required. Country code. |
|
228 | + 'countrycode' => $billing_info['country'], |
|
229 | + // Required. Postal code of payer. |
|
230 | + 'zip' => $billing_info['zip'], |
|
231 | + ); |
|
232 | + //check if the registration info contains the needed fields for paypal pro (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
233 | + if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
234 | + $use_registration_address_info = true; |
|
235 | + } else { |
|
236 | + $use_registration_address_info = false; |
|
237 | + } |
|
238 | + //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. If not, use the billing info again |
|
239 | + $ShippingAddress = array( |
|
240 | + 'shiptoname' => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
241 | + 'shiptostreet' => substr($use_registration_address_info ? $attendee->address() : $billing_info['address'], 0, 100), |
|
242 | + 'shiptostreet2' => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
243 | + 'shiptocity' => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'], 0, 40), |
|
244 | + 'state' => substr($use_registration_address_info ? $attendee->state_name() : $billing_info['state'], 0, 40), |
|
245 | + 'shiptocountry' => $use_registration_address_info ? $attendee->country_ID() : $billing_info['country'], |
|
246 | + 'shiptozip' => substr($use_registration_address_info ? $attendee->zip() : $billing_info['zip'], 0, 20), |
|
247 | + 'shiptophonenum' => substr($use_registration_address_info ? $attendee->phone() : $billing_info['phone'], 0, 20), |
|
248 | + ); |
|
249 | + $PaymentDetails = array( |
|
250 | + // Required. Total amount of order, including shipping, handling, and tax. |
|
251 | + 'amt' => $this->format_currency($payment->amount()), |
|
252 | + // Required. Three-letter currency code. Default is USD. |
|
253 | + 'currencycode' => $payment->currency_code(), |
|
254 | + // Required if you include itemized cart details. (L_AMTn, etc.) Subtotal of items not including S&H, or tax. |
|
255 | + 'itemamt' => $this->format_currency($item_amount),// |
|
256 | + // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
257 | + 'shippingamt' => '', |
|
258 | + // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
259 | + 'handlingamt' => '', |
|
260 | + // Required if you specify itemized cart tax details. Sum of tax for all items on the order. Total sales tax. |
|
261 | + 'taxamt' => $this->format_currency($tax_amount), |
|
262 | + // Description of the order the customer is purchasing. 127 char max. |
|
263 | + 'desc' => $order_description, |
|
264 | + // Free-form field for your own use. 256 char max. |
|
265 | + 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
266 | + // Your own invoice or tracking number |
|
267 | + 'invnum' => wp_generate_password(12, false),//$transaction->ID(), |
|
268 | + // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
269 | + 'notifyurl' => '', |
|
270 | + 'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this |
|
271 | + ); |
|
272 | + // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
273 | + $PayPalRequestData = array( |
|
274 | + 'DPFields' => $DPFields, |
|
275 | + 'CCDetails' => $CCDetails, |
|
276 | + 'PayerInfo' => $PayerInfo, |
|
277 | + 'PayerName' => $PayerName, |
|
278 | + 'BillingAddress' => $BillingAddress, |
|
279 | + 'ShippingAddress' => $ShippingAddress, |
|
280 | + 'PaymentDetails' => $PaymentDetails, |
|
281 | + 'OrderItems' => $order_items, |
|
282 | + ); |
|
283 | + $this->_log_clean_request($PayPalRequestData, $payment); |
|
284 | + try { |
|
285 | + $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
286 | + //remove PCI-sensitive data so it doesn't get stored |
|
287 | + $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
288 | + $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK']; |
|
289 | + if (empty($PayPalResult['RAWRESPONSE'])) { |
|
290 | + $payment->set_status($this->_pay_model->failed_status()); |
|
291 | + $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
292 | + $payment->set_details($PayPalResult); |
|
293 | + } else { |
|
294 | + if ($this->_APICallSuccessful($PayPalResult)) { |
|
295 | + $payment->set_status($this->_pay_model->approved_status()); |
|
296 | + } else { |
|
297 | + $payment->set_status($this->_pay_model->declined_status()); |
|
298 | + } |
|
299 | + //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
300 | + $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
301 | + $payment->set_gateway_response($message); |
|
302 | + $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) ? $PayPalResult['TRANSACTIONID'] : null); |
|
303 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : ''; |
|
304 | + $payment->set_extra_accntng($primary_registration_code); |
|
305 | + $payment->set_details($PayPalResult); |
|
306 | + } |
|
307 | + } catch (Exception $e) { |
|
308 | + $payment->set_status($this->_pay_model->failed_status()); |
|
309 | + $payment->set_gateway_response($e->getMessage()); |
|
310 | + } |
|
311 | + //$payment->set_status( $this->_pay_model->declined_status() ); |
|
312 | + //$payment->set_gateway_response( '' ); |
|
313 | + return $payment; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
320 | + * |
|
321 | + * @param array $request |
|
322 | + * @param EEI_Payment $payment |
|
323 | + * @return array |
|
324 | + */ |
|
325 | + private function _log_clean_request($request, $payment) |
|
326 | + { |
|
327 | + $cleaned_request_data = $request; |
|
328 | + unset($cleaned_request_data['CCDetails']['acct']); |
|
329 | + unset($cleaned_request_data['CCDetails']['cvv2']); |
|
330 | + unset($cleaned_request_data['CCDetails']['expdate']); |
|
331 | + $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Cleans the response, logs it, and returns it |
|
338 | + * |
|
339 | + * @param array $response |
|
340 | + * @param EEI_Payment $payment |
|
341 | + * @return array cleaned |
|
342 | + */ |
|
343 | + private function _log_clean_response($response, $payment) |
|
344 | + { |
|
345 | + unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
346 | + unset($response['REQUESTDATA']['ACCT']); |
|
347 | + unset($response['REQUESTDATA']['EXPDATE']); |
|
348 | + unset($response['REQUESTDATA']['CVV2']); |
|
349 | + unset($response['RAWREQUEST']); |
|
350 | + $this->log(array('Paypal Response' => $response), $payment); |
|
351 | + return $response; |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * @param $DataArray |
|
358 | + * @return array |
|
359 | + */ |
|
360 | + private function prep_and_curl_request($DataArray) |
|
361 | + { |
|
362 | + // Create empty holders for each portion of the NVP string |
|
363 | + $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
364 | + $CCDetailsNVP = ''; |
|
365 | + $PayerInfoNVP = ''; |
|
366 | + $PayerNameNVP = ''; |
|
367 | + $BillingAddressNVP = ''; |
|
368 | + $ShippingAddressNVP = ''; |
|
369 | + $PaymentDetailsNVP = ''; |
|
370 | + $OrderItemsNVP = ''; |
|
371 | + $Secure3DNVP = ''; |
|
372 | + // DP Fields |
|
373 | + $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
374 | + foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
375 | + $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
376 | + } |
|
377 | + // CC Details Fields |
|
378 | + $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
379 | + foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
380 | + $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
381 | + } |
|
382 | + // PayerInfo Type Fields |
|
383 | + $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
384 | + foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
385 | + $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
386 | + } |
|
387 | + // Payer Name Fields |
|
388 | + $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
389 | + foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
390 | + $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
391 | + } |
|
392 | + // Address Fields (Billing) |
|
393 | + $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
394 | + foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
395 | + $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
396 | + } |
|
397 | + // Payment Details Type Fields |
|
398 | + $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
399 | + foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
400 | + $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
401 | + } |
|
402 | + // Payment Details Item Type Fields |
|
403 | + $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
404 | + $n = 0; |
|
405 | + foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
406 | + $CurrentItem = $OrderItems[$OrderItemsVar]; |
|
407 | + foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
408 | + $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
409 | + } |
|
410 | + $n++; |
|
411 | + } |
|
412 | + // Ship To Address Fields |
|
413 | + $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
414 | + foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
415 | + $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
416 | + } |
|
417 | + // 3D Secure Fields |
|
418 | + $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
419 | + foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
420 | + $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
421 | + } |
|
422 | + // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
423 | + $NVPRequest = 'USER=' |
|
424 | + . $this->_username |
|
425 | + . '&PWD=' |
|
426 | + . $this->_password |
|
427 | + . '&VERSION=64.0' |
|
428 | + . '&SIGNATURE=' |
|
429 | + . $this->_signature |
|
430 | + . $DPFieldsNVP |
|
431 | + . $CCDetailsNVP |
|
432 | + . $PayerInfoNVP |
|
433 | + . $PayerNameNVP |
|
434 | + . $BillingAddressNVP |
|
435 | + . $PaymentDetailsNVP |
|
436 | + . $OrderItemsNVP |
|
437 | + . $ShippingAddressNVP |
|
438 | + . $Secure3DNVP; |
|
439 | + $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
440 | + $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
441 | + $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
442 | + $Errors = $this->_GetErrors($NVPResponseArray); |
|
443 | + $NVPResponseArray['ERRORS'] = $Errors; |
|
444 | + $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
445 | + $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
446 | + $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
447 | + return $NVPResponseArray; |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * @param $Request |
|
454 | + * @return mixed |
|
455 | + */ |
|
456 | + private function _CURLRequest($Request) |
|
457 | + { |
|
458 | + $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
459 | + $curl = curl_init(); |
|
460 | + curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
461 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
462 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
463 | + curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
464 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
465 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
466 | + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
467 | + //execute the curl POST |
|
468 | + $Response = curl_exec($curl); |
|
469 | + curl_close($curl); |
|
470 | + return $Response; |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * @param $NVPString |
|
477 | + * @return array |
|
478 | + */ |
|
479 | + private function _NVPToArray($NVPString) |
|
480 | + { |
|
481 | + // prepare responses into array |
|
482 | + $proArray = array(); |
|
483 | + while (strlen($NVPString)) { |
|
484 | + // name |
|
485 | + $keypos = strpos($NVPString, '='); |
|
486 | + $keyval = substr($NVPString, 0, $keypos); |
|
487 | + // value |
|
488 | + $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
489 | + $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
490 | + // decoding the respose |
|
491 | + $proArray[$keyval] = urldecode($valval); |
|
492 | + $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
493 | + } |
|
494 | + return $proArray; |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * @param array $PayPalResult |
|
501 | + * @return bool |
|
502 | + */ |
|
503 | + private function _APICallSuccessful($PayPalResult) |
|
504 | + { |
|
505 | + $approved = false; |
|
506 | + // check main response message from PayPal |
|
507 | + if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
508 | + $ack = strtoupper($PayPalResult['ACK']); |
|
509 | + $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
510 | + } |
|
511 | + return $approved; |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * @param $DataArray |
|
518 | + * @return array |
|
519 | + */ |
|
520 | + private function _GetErrors($DataArray) |
|
521 | + { |
|
522 | + $Errors = array(); |
|
523 | + $n = 0; |
|
524 | + while (isset($DataArray['L_ERRORCODE' . $n . ''])) { |
|
525 | + $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : ''; |
|
526 | + $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) ? $DataArray['L_SHORTMESSAGE' . $n . ''] : ''; |
|
527 | + $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) ? $DataArray['L_LONGMESSAGE' . $n . ''] : ''; |
|
528 | + $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) ? $DataArray['L_SEVERITYCODE' . $n . ''] : ''; |
|
529 | + $CurrentItem = array( |
|
530 | + 'L_ERRORCODE' => $LErrorCode, |
|
531 | + 'L_SHORTMESSAGE' => $LShortMessage, |
|
532 | + 'L_LONGMESSAGE' => $LLongMessage, |
|
533 | + 'L_SEVERITYCODE' => $LSeverityCode, |
|
534 | + ); |
|
535 | + array_push($Errors, $CurrentItem); |
|
536 | + $n++; |
|
537 | + } |
|
538 | + return $Errors; |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * nothing to see here... move along.... |
|
545 | + * |
|
546 | + * @access protected |
|
547 | + * @param $Errors |
|
548 | + * @return string |
|
549 | + */ |
|
550 | + private function _DisplayErrors($Errors) |
|
551 | + { |
|
552 | + $error = ''; |
|
553 | + foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
554 | + $CurrentError = $Errors[$ErrorVar]; |
|
555 | + foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
556 | + $CurrentVarName = ''; |
|
557 | + if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
558 | + $CurrentVarName = 'Error Code'; |
|
559 | + } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
560 | + $CurrentVarName = 'Short Message'; |
|
561 | + } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
562 | + $CurrentVarName = 'Long Message'; |
|
563 | + } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
564 | + $CurrentVarName = 'Severity Code'; |
|
565 | + } |
|
566 | + $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
567 | + } |
|
568 | + } |
|
569 | + return $error; |
|
570 | + } |
|
571 | 571 | |
572 | 572 | |
573 | 573 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -89,16 +89,16 @@ discard block |
||
89 | 89 | public function do_direct_payment($payment, $billing_info = null) |
90 | 90 | { |
91 | 91 | $transaction = $payment->transaction(); |
92 | - if (! $transaction instanceof EEI_Transaction) { |
|
92 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
93 | 93 | throw new EE_Error(esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')); |
94 | 94 | } |
95 | 95 | $primary_registrant = $transaction->primary_registration(); |
96 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
96 | + if ( ! $primary_registrant instanceof EEI_Registration) { |
|
97 | 97 | throw new EE_Error(esc_html__('No primary registration on transaction while paying with PayPal Pro.', |
98 | 98 | 'event_espresso')); |
99 | 99 | } |
100 | 100 | $attendee = $primary_registrant->attendee(); |
101 | - if (! $attendee instanceof EEI_Attendee) { |
|
101 | + if ( ! $attendee instanceof EEI_Attendee) { |
|
102 | 102 | throw new EE_Error(esc_html__('No attendee on primary registration while paying with PayPal Pro.', |
103 | 103 | 'event_espresso')); |
104 | 104 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | // Required. Credit card number. No spaces or punctuation. |
190 | 190 | 'acct' => $billing_info['credit_card'], |
191 | 191 | // Required. Credit card expiration date. Format is MMYYYY |
192 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
192 | + 'expdate' => $billing_info['exp_month'].$billing_info['exp_year'], |
|
193 | 193 | // Requirements determined by your PayPal account settings. Security digits for credit card. |
194 | 194 | 'cvv2' => $billing_info['cvv'], |
195 | 195 | ); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | } |
238 | 238 | //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. If not, use the billing info again |
239 | 239 | $ShippingAddress = array( |
240 | - 'shiptoname' => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
240 | + 'shiptoname' => substr($use_registration_address_info ? $attendee->full_name() : $billing_info['first_name'].' '.$billing_info['last_name'], 0, 32), |
|
241 | 241 | 'shiptostreet' => substr($use_registration_address_info ? $attendee->address() : $billing_info['address'], 0, 100), |
242 | 242 | 'shiptostreet2' => substr($use_registration_address_info ? $attendee->address2() : $billing_info['address2'], 0, 100), |
243 | 243 | 'shiptocity' => substr($use_registration_address_info ? $attendee->city() : $billing_info['city'], 0, 40), |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | // Required. Three-letter currency code. Default is USD. |
253 | 253 | 'currencycode' => $payment->currency_code(), |
254 | 254 | // Required if you include itemized cart details. (L_AMTn, etc.) Subtotal of items not including S&H, or tax. |
255 | - 'itemamt' => $this->format_currency($item_amount),// |
|
255 | + 'itemamt' => $this->format_currency($item_amount), // |
|
256 | 256 | // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
257 | 257 | 'shippingamt' => '', |
258 | 258 | // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | // Free-form field for your own use. 256 char max. |
265 | 265 | 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
266 | 266 | // Your own invoice or tracking number |
267 | - 'invnum' => wp_generate_password(12, false),//$transaction->ID(), |
|
267 | + 'invnum' => wp_generate_password(12, false), //$transaction->ID(), |
|
268 | 268 | // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
269 | 269 | 'notifyurl' => '', |
270 | - 'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this |
|
270 | + 'buttonsource' => 'EventEspresso_SP', //EE will blow up if you change this |
|
271 | 271 | ); |
272 | 272 | // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
273 | 273 | $PayPalRequestData = array( |
@@ -372,32 +372,32 @@ discard block |
||
372 | 372 | // DP Fields |
373 | 373 | $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
374 | 374 | foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
375 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
375 | + $DPFieldsNVP .= '&'.strtoupper($DPFieldsVar).'='.urlencode($DPFieldsVal); |
|
376 | 376 | } |
377 | 377 | // CC Details Fields |
378 | 378 | $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
379 | 379 | foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
380 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
380 | + $CCDetailsNVP .= '&'.strtoupper($CCDetailsVar).'='.urlencode($CCDetailsVal); |
|
381 | 381 | } |
382 | 382 | // PayerInfo Type Fields |
383 | 383 | $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
384 | 384 | foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
385 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
385 | + $PayerInfoNVP .= '&'.strtoupper($PayerInfoVar).'='.urlencode($PayerInfoVal); |
|
386 | 386 | } |
387 | 387 | // Payer Name Fields |
388 | 388 | $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
389 | 389 | foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
390 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
390 | + $PayerNameNVP .= '&'.strtoupper($PayerNameVar).'='.urlencode($PayerNameVal); |
|
391 | 391 | } |
392 | 392 | // Address Fields (Billing) |
393 | 393 | $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
394 | 394 | foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
395 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
395 | + $BillingAddressNVP .= '&'.strtoupper($BillingAddressVar).'='.urlencode($BillingAddressVal); |
|
396 | 396 | } |
397 | 397 | // Payment Details Type Fields |
398 | 398 | $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
399 | 399 | foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
400 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
400 | + $PaymentDetailsNVP .= '&'.strtoupper($PaymentDetailsVar).'='.urlencode($PaymentDetailsVal); |
|
401 | 401 | } |
402 | 402 | // Payment Details Item Type Fields |
403 | 403 | $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
@@ -405,19 +405,19 @@ discard block |
||
405 | 405 | foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
406 | 406 | $CurrentItem = $OrderItems[$OrderItemsVar]; |
407 | 407 | foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
408 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
408 | + $OrderItemsNVP .= '&'.strtoupper($CurrentItemVar).$n.'='.urlencode($CurrentItemVal); |
|
409 | 409 | } |
410 | 410 | $n++; |
411 | 411 | } |
412 | 412 | // Ship To Address Fields |
413 | 413 | $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
414 | 414 | foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
415 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
415 | + $ShippingAddressNVP .= '&'.strtoupper($ShippingAddressVar).'='.urlencode($ShippingAddressVal); |
|
416 | 416 | } |
417 | 417 | // 3D Secure Fields |
418 | 418 | $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
419 | 419 | foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
420 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
420 | + $Secure3DNVP .= '&'.strtoupper($Secure3DVar).'='.urlencode($Secure3DVal); |
|
421 | 421 | } |
422 | 422 | // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
423 | 423 | $NVPRequest = 'USER=' |
@@ -521,11 +521,11 @@ discard block |
||
521 | 521 | { |
522 | 522 | $Errors = array(); |
523 | 523 | $n = 0; |
524 | - while (isset($DataArray['L_ERRORCODE' . $n . ''])) { |
|
525 | - $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : ''; |
|
526 | - $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) ? $DataArray['L_SHORTMESSAGE' . $n . ''] : ''; |
|
527 | - $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) ? $DataArray['L_LONGMESSAGE' . $n . ''] : ''; |
|
528 | - $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) ? $DataArray['L_SEVERITYCODE' . $n . ''] : ''; |
|
524 | + while (isset($DataArray['L_ERRORCODE'.$n.''])) { |
|
525 | + $LErrorCode = isset($DataArray['L_ERRORCODE'.$n.'']) ? $DataArray['L_ERRORCODE'.$n.''] : ''; |
|
526 | + $LShortMessage = isset($DataArray['L_SHORTMESSAGE'.$n.'']) ? $DataArray['L_SHORTMESSAGE'.$n.''] : ''; |
|
527 | + $LLongMessage = isset($DataArray['L_LONGMESSAGE'.$n.'']) ? $DataArray['L_LONGMESSAGE'.$n.''] : ''; |
|
528 | + $LSeverityCode = isset($DataArray['L_SEVERITYCODE'.$n.'']) ? $DataArray['L_SEVERITYCODE'.$n.''] : ''; |
|
529 | 529 | $CurrentItem = array( |
530 | 530 | 'L_ERRORCODE' => $LErrorCode, |
531 | 531 | 'L_SHORTMESSAGE' => $LShortMessage, |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
564 | 564 | $CurrentVarName = 'Severity Code'; |
565 | 565 | } |
566 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
566 | + $error .= '<br />'.$CurrentVarName.': '.$CurrentErrorVal; |
|
567 | 567 | } |
568 | 568 | } |
569 | 569 | return $error; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @param EE_Line_Item $line_item |
78 | 78 | * @param array $options |
79 | 79 | * @param EE_Line_Item $parent_line_item |
80 | - * @return mixed |
|
80 | + * @return string |
|
81 | 81 | * @throws EE_Error |
82 | 82 | */ |
83 | 83 | public function display_line_item( |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * _event_row - basically a Heading row displayed once above each event's ticket rows |
224 | 224 | * |
225 | 225 | * @param EE_Line_Item $line_item |
226 | - * @return mixed |
|
226 | + * @return string |
|
227 | 227 | */ |
228 | 228 | private function _event_row(EE_Line_Item $line_item) |
229 | 229 | { |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @param EE_Line_Item $line_item |
251 | 251 | * @param array $options |
252 | - * @return mixed |
|
252 | + * @return string |
|
253 | 253 | * @throws EE_Error |
254 | 254 | */ |
255 | 255 | private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @param EE_Line_Item $line_item |
305 | 305 | * @param array $options |
306 | - * @return mixed |
|
306 | + * @return string |
|
307 | 307 | * @throws EE_Error |
308 | 308 | */ |
309 | 309 | private function _item_row(EE_Line_Item $line_item, $options = array()) |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * @param EE_Line_Item $line_item |
364 | 364 | * @param array $options |
365 | 365 | * @param EE_Line_Item $parent_line_item |
366 | - * @return mixed |
|
366 | + * @return string |
|
367 | 367 | * @throws EE_Error |
368 | 368 | */ |
369 | 369 | private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | * |
408 | 408 | * @param EE_Line_Item $line_item |
409 | 409 | * @param array $options |
410 | - * @return mixed |
|
410 | + * @return string |
|
411 | 411 | * @throws EE_Error |
412 | 412 | */ |
413 | 413 | private function _tax_row(EE_Line_Item $line_item, $options = array()) |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | * |
445 | 445 | * @param EE_Line_Item $line_item |
446 | 446 | * @param string $text |
447 | - * @return mixed |
|
447 | + * @return string |
|
448 | 448 | * @throws EE_Error |
449 | 449 | */ |
450 | 450 | private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | * @param EE_Line_Item $line_item |
484 | 484 | * @param string $text |
485 | 485 | * @param array $options |
486 | - * @return mixed |
|
486 | + * @return string |
|
487 | 487 | * @throws EE_Error |
488 | 488 | */ |
489 | 489 | private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | * |
520 | 520 | * @param EE_Line_Item $line_item |
521 | 521 | * @param string $text |
522 | - * @return mixed |
|
522 | + * @return string |
|
523 | 523 | * @throws EE_Error |
524 | 524 | */ |
525 | 525 | private function _total_row(EE_Line_Item $line_item, $text = '') |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | * |
547 | 547 | * @param EE_Line_Item $line_item |
548 | 548 | * @param array $options |
549 | - * @return mixed |
|
549 | + * @return string |
|
550 | 550 | * @throws EE_Error |
551 | 551 | */ |
552 | 552 | private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
@@ -16,609 +16,609 @@ |
||
16 | 16 | class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * array of events |
|
21 | - * |
|
22 | - * @type EE_Line_Item[] $_events |
|
23 | - */ |
|
24 | - private $_events = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * whether to display the taxes row or not |
|
28 | - * |
|
29 | - * @type bool $_show_taxes |
|
30 | - */ |
|
31 | - private $_show_taxes = false; |
|
32 | - |
|
33 | - /** |
|
34 | - * html for any tax rows |
|
35 | - * |
|
36 | - * @type string $_show_taxes |
|
37 | - */ |
|
38 | - private $_taxes_html = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * total amount including tax we can bill for at this time |
|
42 | - * |
|
43 | - * @type float $_grand_total |
|
44 | - */ |
|
45 | - private $_grand_total = 0.00; |
|
46 | - |
|
47 | - /** |
|
48 | - * total number of items being billed for |
|
49 | - * |
|
50 | - * @type int $_total_items |
|
51 | - */ |
|
52 | - private $_total_items = 0; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @return float |
|
58 | - */ |
|
59 | - public function grand_total() |
|
60 | - { |
|
61 | - return $this->_grand_total; |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @return int |
|
68 | - */ |
|
69 | - public function total_items() |
|
70 | - { |
|
71 | - return $this->_total_items; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param EE_Line_Item $line_item |
|
78 | - * @param array $options |
|
79 | - * @param EE_Line_Item $parent_line_item |
|
80 | - * @return mixed |
|
81 | - * @throws EE_Error |
|
82 | - */ |
|
83 | - public function display_line_item( |
|
84 | - EE_Line_Item $line_item, |
|
85 | - $options = array(), |
|
86 | - EE_Line_Item $parent_line_item = null |
|
87 | - ) { |
|
88 | - $html = ''; |
|
89 | - // set some default options and merge with incoming |
|
90 | - $default_options = array( |
|
91 | - 'show_desc' => true, // true false |
|
92 | - 'odd' => false, |
|
93 | - ); |
|
94 | - $options = array_merge($default_options, (array)$options); |
|
95 | - switch ($line_item->type()) { |
|
96 | - case EEM_Line_Item::type_line_item: |
|
97 | - $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
98 | - if ($line_item->OBJ_type() === 'Ticket') { |
|
99 | - // item row |
|
100 | - $html .= $this->_ticket_row($line_item, $options); |
|
101 | - } else { |
|
102 | - // item row |
|
103 | - $html .= $this->_item_row($line_item, $options); |
|
104 | - } |
|
105 | - if ( |
|
106 | - apply_filters( |
|
107 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
108 | - true |
|
109 | - ) |
|
110 | - ) { |
|
111 | - // got any kids? |
|
112 | - foreach ($line_item->children() as $child_line_item) { |
|
113 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
114 | - } |
|
115 | - } |
|
116 | - break; |
|
117 | - case EEM_Line_Item::type_sub_line_item: |
|
118 | - $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
119 | - break; |
|
120 | - case EEM_Line_Item::type_sub_total: |
|
121 | - static $sub_total = 0; |
|
122 | - $event_sub_total = 0; |
|
123 | - $text = esc_html__('Sub-Total', 'event_espresso'); |
|
124 | - if ($line_item->OBJ_type() === 'Event') { |
|
125 | - $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
126 | - if (! isset($this->_events[$options['event_id']])) { |
|
127 | - $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
128 | - // if event has default reg status of Not Approved, then don't display info on it |
|
129 | - if ( |
|
130 | - $event instanceof EE_Event |
|
131 | - && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
132 | - ) { |
|
133 | - $display_event = false; |
|
134 | - // unless there are registrations for it that are returning to pay |
|
135 | - if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
136 | - foreach ($options['registrations'] as $registration) { |
|
137 | - if (! $registration instanceof EE_Registration) { |
|
138 | - continue; |
|
139 | - } |
|
140 | - $display_event = $registration->event_ID() === $options['event_id'] |
|
141 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
142 | - ? true |
|
143 | - : $display_event; |
|
144 | - } |
|
145 | - } |
|
146 | - if (! $display_event) { |
|
147 | - return ''; |
|
148 | - } |
|
149 | - } |
|
150 | - $this->_events[$options['event_id']] = 0; |
|
151 | - $html .= $this->_event_row($line_item); |
|
152 | - $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
153 | - } |
|
154 | - } |
|
155 | - $child_line_items = $line_item->children(); |
|
156 | - // loop thru children |
|
157 | - foreach ($child_line_items as $child_line_item) { |
|
158 | - // recursively feed children back into this method |
|
159 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
160 | - } |
|
161 | - $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
162 | - $sub_total += $event_sub_total; |
|
163 | - if ( |
|
164 | - ( |
|
165 | - // event subtotals |
|
166 | - $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
167 | - ) |
|
168 | - || ( |
|
169 | - // pre-tax subtotals |
|
170 | - $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
171 | - ) |
|
172 | - ) { |
|
173 | - $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
174 | - $html .= $this->_sub_total_row($line_item, $text, $options); |
|
175 | - } |
|
176 | - break; |
|
177 | - case EEM_Line_Item::type_tax: |
|
178 | - if ($this->_show_taxes) { |
|
179 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
180 | - } |
|
181 | - break; |
|
182 | - case EEM_Line_Item::type_tax_sub_total: |
|
183 | - if ($this->_show_taxes) { |
|
184 | - $child_line_items = $line_item->children(); |
|
185 | - // loop thru children |
|
186 | - foreach ($child_line_items as $child_line_item) { |
|
187 | - // recursively feed children back into this method |
|
188 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
189 | - } |
|
190 | - if (count($child_line_items) > 1) { |
|
191 | - $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
192 | - } |
|
193 | - } |
|
194 | - break; |
|
195 | - case EEM_Line_Item::type_total: |
|
196 | - // get all child line items |
|
197 | - $children = $line_item->children(); |
|
198 | - // loop thru all non-tax child line items |
|
199 | - foreach ($children as $child_line_item) { |
|
200 | - if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
201 | - // recursively feed children back into this method |
|
202 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
203 | - } |
|
204 | - } |
|
205 | - // now loop thru tax child line items |
|
206 | - foreach ($children as $child_line_item) { |
|
207 | - if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
208 | - // recursively feed children back into this method |
|
209 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
210 | - } |
|
211 | - } |
|
212 | - $html .= $this->_taxes_html; |
|
213 | - $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
214 | - $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
215 | - break; |
|
216 | - } |
|
217 | - return $html; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
224 | - * |
|
225 | - * @param EE_Line_Item $line_item |
|
226 | - * @return mixed |
|
227 | - */ |
|
228 | - private function _event_row(EE_Line_Item $line_item) |
|
229 | - { |
|
230 | - // start of row |
|
231 | - $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
232 | - // event name td |
|
233 | - $html .= EEH_HTML::td( |
|
234 | - EEH_HTML::strong($line_item->name()), |
|
235 | - '', |
|
236 | - 'event-header', |
|
237 | - '', |
|
238 | - ' colspan="4"' |
|
239 | - ); |
|
240 | - // end of row |
|
241 | - $html .= EEH_HTML::trx(); |
|
242 | - return $html; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * _ticket_row |
|
249 | - * |
|
250 | - * @param EE_Line_Item $line_item |
|
251 | - * @param array $options |
|
252 | - * @return mixed |
|
253 | - * @throws EE_Error |
|
254 | - */ |
|
255 | - private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
256 | - { |
|
257 | - // start of row |
|
258 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
259 | - $html = EEH_HTML::tr('', '', $row_class); |
|
260 | - // name && desc |
|
261 | - $name_and_desc = apply_filters( |
|
262 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
263 | - $line_item->name(), |
|
264 | - $line_item |
|
265 | - ); |
|
266 | - $name_and_desc .= apply_filters( |
|
267 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
268 | - ( |
|
269 | - $options['show_desc'] |
|
270 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
271 | - : '' |
|
272 | - ), |
|
273 | - $line_item, |
|
274 | - $options |
|
275 | - ); |
|
276 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
277 | - // name td |
|
278 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
279 | - $name_and_desc, '', 'item_l'); |
|
280 | - // price td |
|
281 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
282 | - // quantity td |
|
283 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
284 | - $this->_total_items += $line_item->quantity(); |
|
285 | - // determine total for line item |
|
286 | - $total = $line_item->total(); |
|
287 | - $this->_events[$options['event_id']] += $total; |
|
288 | - // total td |
|
289 | - $html .= EEH_HTML::td( |
|
290 | - EEH_Template::format_currency($total, false, false), |
|
291 | - '', |
|
292 | - 'item_r jst-rght' |
|
293 | - ); |
|
294 | - // end of row |
|
295 | - $html .= EEH_HTML::trx(); |
|
296 | - return $html; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * _item_row |
|
303 | - * |
|
304 | - * @param EE_Line_Item $line_item |
|
305 | - * @param array $options |
|
306 | - * @return mixed |
|
307 | - * @throws EE_Error |
|
308 | - */ |
|
309 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
310 | - { |
|
311 | - // start of row |
|
312 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
313 | - $html = EEH_HTML::tr('', '', $row_class); |
|
314 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
315 | - // name && desc |
|
316 | - $name_and_desc = apply_filters( |
|
317 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
318 | - $obj_name . $line_item->name(), |
|
319 | - $line_item |
|
320 | - ); |
|
321 | - $name_and_desc .= apply_filters( |
|
322 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
323 | - ( |
|
324 | - $options['show_desc'] |
|
325 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
326 | - : '' |
|
327 | - ), |
|
328 | - $line_item, |
|
329 | - $options |
|
330 | - ); |
|
331 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
332 | - // name td |
|
333 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
334 | - // price td |
|
335 | - if ($line_item->is_percent()) { |
|
336 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
337 | - } else { |
|
338 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
339 | - } |
|
340 | - // quantity td |
|
341 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
342 | - //$total = $line_item->total() * $line_item->quantity(); |
|
343 | - $total = $line_item->total(); |
|
344 | - if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
345 | - $this->_events[$options['event_id']] += $total; |
|
346 | - } |
|
347 | - // total td |
|
348 | - $html .= EEH_HTML::td( |
|
349 | - EEH_Template::format_currency($total, false, false), |
|
350 | - '', |
|
351 | - 'item_r jst-rght' |
|
352 | - ); |
|
353 | - // end of row |
|
354 | - $html .= EEH_HTML::trx(); |
|
355 | - return $html; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * _sub_item_row |
|
362 | - * |
|
363 | - * @param EE_Line_Item $line_item |
|
364 | - * @param array $options |
|
365 | - * @param EE_Line_Item $parent_line_item |
|
366 | - * @return mixed |
|
367 | - * @throws EE_Error |
|
368 | - */ |
|
369 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
370 | - { |
|
371 | - // start of row |
|
372 | - $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
373 | - // name && desc |
|
374 | - $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
375 | - . $line_item->name(); |
|
376 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
377 | - . $line_item->desc() |
|
378 | - . '</span>' : ''; |
|
379 | - // name td |
|
380 | - $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item'); |
|
381 | - $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
382 | - // discount/surcharge td |
|
383 | - if ($line_item->is_percent()) { |
|
384 | - $html .= EEH_HTML::td( |
|
385 | - EEH_Template::format_currency( |
|
386 | - $line_item->total() / $qty, |
|
387 | - false, false |
|
388 | - ), |
|
389 | - '', 'item_c jst-rght' |
|
390 | - ); |
|
391 | - } else { |
|
392 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
393 | - } |
|
394 | - // no quantity td |
|
395 | - $html .= EEH_HTML::td(); |
|
396 | - // no total td |
|
397 | - $html .= EEH_HTML::td(); |
|
398 | - // end of row |
|
399 | - $html .= EEH_HTML::trx(); |
|
400 | - return $html; |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * _tax_row |
|
407 | - * |
|
408 | - * @param EE_Line_Item $line_item |
|
409 | - * @param array $options |
|
410 | - * @return mixed |
|
411 | - * @throws EE_Error |
|
412 | - */ |
|
413 | - private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
414 | - { |
|
415 | - // start of row |
|
416 | - $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
417 | - // name && desc |
|
418 | - $name_and_desc = $line_item->name(); |
|
419 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
420 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
421 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
422 | - // name td |
|
423 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
424 | - $name_and_desc, '', 'item_l sub-item'); |
|
425 | - // percent td |
|
426 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
427 | - // empty td (price) |
|
428 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
429 | - // total td |
|
430 | - $html .= EEH_HTML::td(EEH_Template::format_currency( |
|
431 | - $line_item->total(), false, false), |
|
432 | - '', |
|
433 | - 'item_r jst-rght' |
|
434 | - ); |
|
435 | - // end of row |
|
436 | - $html .= EEH_HTML::trx(); |
|
437 | - return $html; |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * _total_row |
|
444 | - * |
|
445 | - * @param EE_Line_Item $line_item |
|
446 | - * @param string $text |
|
447 | - * @return mixed |
|
448 | - * @throws EE_Error |
|
449 | - */ |
|
450 | - private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
451 | - { |
|
452 | - $html = ''; |
|
453 | - if ($line_item->total()) { |
|
454 | - // start of row |
|
455 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
456 | - // total td |
|
457 | - $html .= EEH_HTML::td( |
|
458 | - $text, |
|
459 | - '', |
|
460 | - 'total_currency total jst-rght', |
|
461 | - '', |
|
462 | - ' colspan="2"' |
|
463 | - ); |
|
464 | - // empty td (price) |
|
465 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
466 | - // total td |
|
467 | - $html .= EEH_HTML::td( |
|
468 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
469 | - '', |
|
470 | - 'total jst-rght' |
|
471 | - ); |
|
472 | - // end of row |
|
473 | - $html .= EEH_HTML::trx(); |
|
474 | - } |
|
475 | - return $html; |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * _total_row |
|
482 | - * |
|
483 | - * @param EE_Line_Item $line_item |
|
484 | - * @param string $text |
|
485 | - * @param array $options |
|
486 | - * @return mixed |
|
487 | - * @throws EE_Error |
|
488 | - */ |
|
489 | - private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
490 | - { |
|
491 | - $html = ''; |
|
492 | - if ($line_item->total()) { |
|
493 | - // start of row |
|
494 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
495 | - // total td |
|
496 | - $html .= EEH_HTML::td( |
|
497 | - $text, |
|
498 | - '', |
|
499 | - 'total_currency total jst-rght', |
|
500 | - '', |
|
501 | - ' colspan="3"' |
|
502 | - ); |
|
503 | - // total td |
|
504 | - $html .= EEH_HTML::td( |
|
505 | - EEH_Template::format_currency($options['sub_total'], false, false), |
|
506 | - '', |
|
507 | - 'total jst-rght' |
|
508 | - ); |
|
509 | - // end of row |
|
510 | - $html .= EEH_HTML::trx(); |
|
511 | - } |
|
512 | - return $html; |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * _total_row |
|
519 | - * |
|
520 | - * @param EE_Line_Item $line_item |
|
521 | - * @param string $text |
|
522 | - * @return mixed |
|
523 | - * @throws EE_Error |
|
524 | - */ |
|
525 | - private function _total_row(EE_Line_Item $line_item, $text = '') |
|
526 | - { |
|
527 | - // start of row |
|
528 | - $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
529 | - // total td |
|
530 | - $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
531 | - // total td |
|
532 | - $html .= EEH_HTML::td( |
|
533 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
534 | - '', |
|
535 | - 'total jst-rght' |
|
536 | - ); |
|
537 | - // end of row |
|
538 | - $html .= EEH_HTML::trx(); |
|
539 | - return $html; |
|
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * _payments_and_amount_owing_rows |
|
546 | - * |
|
547 | - * @param EE_Line_Item $line_item |
|
548 | - * @param array $options |
|
549 | - * @return mixed |
|
550 | - * @throws EE_Error |
|
551 | - */ |
|
552 | - private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
553 | - { |
|
554 | - $html = ''; |
|
555 | - $owing = $line_item->total(); |
|
556 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
557 | - if ($transaction instanceof EE_Transaction) { |
|
558 | - $registration_payments = array(); |
|
559 | - $registrations = ! empty($options['registrations']) |
|
560 | - ? $options['registrations'] |
|
561 | - : $transaction->registrations(); |
|
562 | - foreach ($registrations as $registration) { |
|
563 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
564 | - $registration_payments += $registration->registration_payments(); |
|
565 | - } |
|
566 | - } |
|
567 | - if (! empty($registration_payments)) { |
|
568 | - foreach ($registration_payments as $registration_payment) { |
|
569 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
570 | - $owing -= $registration_payment->amount(); |
|
571 | - $payment = $registration_payment->payment(); |
|
572 | - $payment_desc = ''; |
|
573 | - if ($payment instanceof EE_Payment) { |
|
574 | - $payment_desc = sprintf( |
|
575 | - esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
576 | - $payment->txn_id_chq_nmbr() !== '' |
|
577 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
578 | - : '', |
|
579 | - $payment->timestamp() |
|
580 | - ); |
|
581 | - } |
|
582 | - // start of row |
|
583 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
584 | - // payment desc |
|
585 | - $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
586 | - // total td |
|
587 | - $html .= EEH_HTML::td( |
|
588 | - EEH_Template::format_currency( |
|
589 | - $registration_payment->amount(), |
|
590 | - false, |
|
591 | - false |
|
592 | - ), |
|
593 | - '', |
|
594 | - 'total jst-rght' |
|
595 | - ); |
|
596 | - // end of row |
|
597 | - $html .= EEH_HTML::trx(); |
|
598 | - } |
|
599 | - } |
|
600 | - if ($line_item->total()) { |
|
601 | - // start of row |
|
602 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
603 | - // total td |
|
604 | - $html .= EEH_HTML::td( |
|
605 | - esc_html__('Amount Owing', 'event_espresso'), |
|
606 | - '', 'total_currency total jst-rght', '', ' colspan="3"' |
|
607 | - ); |
|
608 | - // total td |
|
609 | - $html .= EEH_HTML::td( |
|
610 | - EEH_Template::format_currency($owing, false, false), |
|
611 | - '', |
|
612 | - 'total jst-rght' |
|
613 | - ); |
|
614 | - // end of row |
|
615 | - $html .= EEH_HTML::trx(); |
|
616 | - } |
|
617 | - } |
|
618 | - } |
|
619 | - $this->_grand_total = $owing; |
|
620 | - return $html; |
|
621 | - } |
|
19 | + /** |
|
20 | + * array of events |
|
21 | + * |
|
22 | + * @type EE_Line_Item[] $_events |
|
23 | + */ |
|
24 | + private $_events = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * whether to display the taxes row or not |
|
28 | + * |
|
29 | + * @type bool $_show_taxes |
|
30 | + */ |
|
31 | + private $_show_taxes = false; |
|
32 | + |
|
33 | + /** |
|
34 | + * html for any tax rows |
|
35 | + * |
|
36 | + * @type string $_show_taxes |
|
37 | + */ |
|
38 | + private $_taxes_html = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * total amount including tax we can bill for at this time |
|
42 | + * |
|
43 | + * @type float $_grand_total |
|
44 | + */ |
|
45 | + private $_grand_total = 0.00; |
|
46 | + |
|
47 | + /** |
|
48 | + * total number of items being billed for |
|
49 | + * |
|
50 | + * @type int $_total_items |
|
51 | + */ |
|
52 | + private $_total_items = 0; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @return float |
|
58 | + */ |
|
59 | + public function grand_total() |
|
60 | + { |
|
61 | + return $this->_grand_total; |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @return int |
|
68 | + */ |
|
69 | + public function total_items() |
|
70 | + { |
|
71 | + return $this->_total_items; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param EE_Line_Item $line_item |
|
78 | + * @param array $options |
|
79 | + * @param EE_Line_Item $parent_line_item |
|
80 | + * @return mixed |
|
81 | + * @throws EE_Error |
|
82 | + */ |
|
83 | + public function display_line_item( |
|
84 | + EE_Line_Item $line_item, |
|
85 | + $options = array(), |
|
86 | + EE_Line_Item $parent_line_item = null |
|
87 | + ) { |
|
88 | + $html = ''; |
|
89 | + // set some default options and merge with incoming |
|
90 | + $default_options = array( |
|
91 | + 'show_desc' => true, // true false |
|
92 | + 'odd' => false, |
|
93 | + ); |
|
94 | + $options = array_merge($default_options, (array)$options); |
|
95 | + switch ($line_item->type()) { |
|
96 | + case EEM_Line_Item::type_line_item: |
|
97 | + $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
98 | + if ($line_item->OBJ_type() === 'Ticket') { |
|
99 | + // item row |
|
100 | + $html .= $this->_ticket_row($line_item, $options); |
|
101 | + } else { |
|
102 | + // item row |
|
103 | + $html .= $this->_item_row($line_item, $options); |
|
104 | + } |
|
105 | + if ( |
|
106 | + apply_filters( |
|
107 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
108 | + true |
|
109 | + ) |
|
110 | + ) { |
|
111 | + // got any kids? |
|
112 | + foreach ($line_item->children() as $child_line_item) { |
|
113 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
114 | + } |
|
115 | + } |
|
116 | + break; |
|
117 | + case EEM_Line_Item::type_sub_line_item: |
|
118 | + $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
119 | + break; |
|
120 | + case EEM_Line_Item::type_sub_total: |
|
121 | + static $sub_total = 0; |
|
122 | + $event_sub_total = 0; |
|
123 | + $text = esc_html__('Sub-Total', 'event_espresso'); |
|
124 | + if ($line_item->OBJ_type() === 'Event') { |
|
125 | + $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
126 | + if (! isset($this->_events[$options['event_id']])) { |
|
127 | + $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
128 | + // if event has default reg status of Not Approved, then don't display info on it |
|
129 | + if ( |
|
130 | + $event instanceof EE_Event |
|
131 | + && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
132 | + ) { |
|
133 | + $display_event = false; |
|
134 | + // unless there are registrations for it that are returning to pay |
|
135 | + if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
136 | + foreach ($options['registrations'] as $registration) { |
|
137 | + if (! $registration instanceof EE_Registration) { |
|
138 | + continue; |
|
139 | + } |
|
140 | + $display_event = $registration->event_ID() === $options['event_id'] |
|
141 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
142 | + ? true |
|
143 | + : $display_event; |
|
144 | + } |
|
145 | + } |
|
146 | + if (! $display_event) { |
|
147 | + return ''; |
|
148 | + } |
|
149 | + } |
|
150 | + $this->_events[$options['event_id']] = 0; |
|
151 | + $html .= $this->_event_row($line_item); |
|
152 | + $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
153 | + } |
|
154 | + } |
|
155 | + $child_line_items = $line_item->children(); |
|
156 | + // loop thru children |
|
157 | + foreach ($child_line_items as $child_line_item) { |
|
158 | + // recursively feed children back into this method |
|
159 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
160 | + } |
|
161 | + $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
162 | + $sub_total += $event_sub_total; |
|
163 | + if ( |
|
164 | + ( |
|
165 | + // event subtotals |
|
166 | + $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
167 | + ) |
|
168 | + || ( |
|
169 | + // pre-tax subtotals |
|
170 | + $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
171 | + ) |
|
172 | + ) { |
|
173 | + $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
174 | + $html .= $this->_sub_total_row($line_item, $text, $options); |
|
175 | + } |
|
176 | + break; |
|
177 | + case EEM_Line_Item::type_tax: |
|
178 | + if ($this->_show_taxes) { |
|
179 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
180 | + } |
|
181 | + break; |
|
182 | + case EEM_Line_Item::type_tax_sub_total: |
|
183 | + if ($this->_show_taxes) { |
|
184 | + $child_line_items = $line_item->children(); |
|
185 | + // loop thru children |
|
186 | + foreach ($child_line_items as $child_line_item) { |
|
187 | + // recursively feed children back into this method |
|
188 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
189 | + } |
|
190 | + if (count($child_line_items) > 1) { |
|
191 | + $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
192 | + } |
|
193 | + } |
|
194 | + break; |
|
195 | + case EEM_Line_Item::type_total: |
|
196 | + // get all child line items |
|
197 | + $children = $line_item->children(); |
|
198 | + // loop thru all non-tax child line items |
|
199 | + foreach ($children as $child_line_item) { |
|
200 | + if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
201 | + // recursively feed children back into this method |
|
202 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
203 | + } |
|
204 | + } |
|
205 | + // now loop thru tax child line items |
|
206 | + foreach ($children as $child_line_item) { |
|
207 | + if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
208 | + // recursively feed children back into this method |
|
209 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
210 | + } |
|
211 | + } |
|
212 | + $html .= $this->_taxes_html; |
|
213 | + $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
214 | + $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
215 | + break; |
|
216 | + } |
|
217 | + return $html; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
224 | + * |
|
225 | + * @param EE_Line_Item $line_item |
|
226 | + * @return mixed |
|
227 | + */ |
|
228 | + private function _event_row(EE_Line_Item $line_item) |
|
229 | + { |
|
230 | + // start of row |
|
231 | + $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
232 | + // event name td |
|
233 | + $html .= EEH_HTML::td( |
|
234 | + EEH_HTML::strong($line_item->name()), |
|
235 | + '', |
|
236 | + 'event-header', |
|
237 | + '', |
|
238 | + ' colspan="4"' |
|
239 | + ); |
|
240 | + // end of row |
|
241 | + $html .= EEH_HTML::trx(); |
|
242 | + return $html; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * _ticket_row |
|
249 | + * |
|
250 | + * @param EE_Line_Item $line_item |
|
251 | + * @param array $options |
|
252 | + * @return mixed |
|
253 | + * @throws EE_Error |
|
254 | + */ |
|
255 | + private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
256 | + { |
|
257 | + // start of row |
|
258 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
259 | + $html = EEH_HTML::tr('', '', $row_class); |
|
260 | + // name && desc |
|
261 | + $name_and_desc = apply_filters( |
|
262 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
263 | + $line_item->name(), |
|
264 | + $line_item |
|
265 | + ); |
|
266 | + $name_and_desc .= apply_filters( |
|
267 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
268 | + ( |
|
269 | + $options['show_desc'] |
|
270 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
271 | + : '' |
|
272 | + ), |
|
273 | + $line_item, |
|
274 | + $options |
|
275 | + ); |
|
276 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
277 | + // name td |
|
278 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
279 | + $name_and_desc, '', 'item_l'); |
|
280 | + // price td |
|
281 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
282 | + // quantity td |
|
283 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
284 | + $this->_total_items += $line_item->quantity(); |
|
285 | + // determine total for line item |
|
286 | + $total = $line_item->total(); |
|
287 | + $this->_events[$options['event_id']] += $total; |
|
288 | + // total td |
|
289 | + $html .= EEH_HTML::td( |
|
290 | + EEH_Template::format_currency($total, false, false), |
|
291 | + '', |
|
292 | + 'item_r jst-rght' |
|
293 | + ); |
|
294 | + // end of row |
|
295 | + $html .= EEH_HTML::trx(); |
|
296 | + return $html; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * _item_row |
|
303 | + * |
|
304 | + * @param EE_Line_Item $line_item |
|
305 | + * @param array $options |
|
306 | + * @return mixed |
|
307 | + * @throws EE_Error |
|
308 | + */ |
|
309 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
310 | + { |
|
311 | + // start of row |
|
312 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
313 | + $html = EEH_HTML::tr('', '', $row_class); |
|
314 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
315 | + // name && desc |
|
316 | + $name_and_desc = apply_filters( |
|
317 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
318 | + $obj_name . $line_item->name(), |
|
319 | + $line_item |
|
320 | + ); |
|
321 | + $name_and_desc .= apply_filters( |
|
322 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
323 | + ( |
|
324 | + $options['show_desc'] |
|
325 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
326 | + : '' |
|
327 | + ), |
|
328 | + $line_item, |
|
329 | + $options |
|
330 | + ); |
|
331 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
332 | + // name td |
|
333 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
334 | + // price td |
|
335 | + if ($line_item->is_percent()) { |
|
336 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
337 | + } else { |
|
338 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
339 | + } |
|
340 | + // quantity td |
|
341 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
342 | + //$total = $line_item->total() * $line_item->quantity(); |
|
343 | + $total = $line_item->total(); |
|
344 | + if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
345 | + $this->_events[$options['event_id']] += $total; |
|
346 | + } |
|
347 | + // total td |
|
348 | + $html .= EEH_HTML::td( |
|
349 | + EEH_Template::format_currency($total, false, false), |
|
350 | + '', |
|
351 | + 'item_r jst-rght' |
|
352 | + ); |
|
353 | + // end of row |
|
354 | + $html .= EEH_HTML::trx(); |
|
355 | + return $html; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * _sub_item_row |
|
362 | + * |
|
363 | + * @param EE_Line_Item $line_item |
|
364 | + * @param array $options |
|
365 | + * @param EE_Line_Item $parent_line_item |
|
366 | + * @return mixed |
|
367 | + * @throws EE_Error |
|
368 | + */ |
|
369 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
370 | + { |
|
371 | + // start of row |
|
372 | + $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
373 | + // name && desc |
|
374 | + $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
375 | + . $line_item->name(); |
|
376 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
377 | + . $line_item->desc() |
|
378 | + . '</span>' : ''; |
|
379 | + // name td |
|
380 | + $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item'); |
|
381 | + $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
382 | + // discount/surcharge td |
|
383 | + if ($line_item->is_percent()) { |
|
384 | + $html .= EEH_HTML::td( |
|
385 | + EEH_Template::format_currency( |
|
386 | + $line_item->total() / $qty, |
|
387 | + false, false |
|
388 | + ), |
|
389 | + '', 'item_c jst-rght' |
|
390 | + ); |
|
391 | + } else { |
|
392 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
393 | + } |
|
394 | + // no quantity td |
|
395 | + $html .= EEH_HTML::td(); |
|
396 | + // no total td |
|
397 | + $html .= EEH_HTML::td(); |
|
398 | + // end of row |
|
399 | + $html .= EEH_HTML::trx(); |
|
400 | + return $html; |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * _tax_row |
|
407 | + * |
|
408 | + * @param EE_Line_Item $line_item |
|
409 | + * @param array $options |
|
410 | + * @return mixed |
|
411 | + * @throws EE_Error |
|
412 | + */ |
|
413 | + private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
414 | + { |
|
415 | + // start of row |
|
416 | + $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
417 | + // name && desc |
|
418 | + $name_and_desc = $line_item->name(); |
|
419 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
420 | + . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
421 | + $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
422 | + // name td |
|
423 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
424 | + $name_and_desc, '', 'item_l sub-item'); |
|
425 | + // percent td |
|
426 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
427 | + // empty td (price) |
|
428 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
429 | + // total td |
|
430 | + $html .= EEH_HTML::td(EEH_Template::format_currency( |
|
431 | + $line_item->total(), false, false), |
|
432 | + '', |
|
433 | + 'item_r jst-rght' |
|
434 | + ); |
|
435 | + // end of row |
|
436 | + $html .= EEH_HTML::trx(); |
|
437 | + return $html; |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * _total_row |
|
444 | + * |
|
445 | + * @param EE_Line_Item $line_item |
|
446 | + * @param string $text |
|
447 | + * @return mixed |
|
448 | + * @throws EE_Error |
|
449 | + */ |
|
450 | + private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
451 | + { |
|
452 | + $html = ''; |
|
453 | + if ($line_item->total()) { |
|
454 | + // start of row |
|
455 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
456 | + // total td |
|
457 | + $html .= EEH_HTML::td( |
|
458 | + $text, |
|
459 | + '', |
|
460 | + 'total_currency total jst-rght', |
|
461 | + '', |
|
462 | + ' colspan="2"' |
|
463 | + ); |
|
464 | + // empty td (price) |
|
465 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
466 | + // total td |
|
467 | + $html .= EEH_HTML::td( |
|
468 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
469 | + '', |
|
470 | + 'total jst-rght' |
|
471 | + ); |
|
472 | + // end of row |
|
473 | + $html .= EEH_HTML::trx(); |
|
474 | + } |
|
475 | + return $html; |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * _total_row |
|
482 | + * |
|
483 | + * @param EE_Line_Item $line_item |
|
484 | + * @param string $text |
|
485 | + * @param array $options |
|
486 | + * @return mixed |
|
487 | + * @throws EE_Error |
|
488 | + */ |
|
489 | + private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
490 | + { |
|
491 | + $html = ''; |
|
492 | + if ($line_item->total()) { |
|
493 | + // start of row |
|
494 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
495 | + // total td |
|
496 | + $html .= EEH_HTML::td( |
|
497 | + $text, |
|
498 | + '', |
|
499 | + 'total_currency total jst-rght', |
|
500 | + '', |
|
501 | + ' colspan="3"' |
|
502 | + ); |
|
503 | + // total td |
|
504 | + $html .= EEH_HTML::td( |
|
505 | + EEH_Template::format_currency($options['sub_total'], false, false), |
|
506 | + '', |
|
507 | + 'total jst-rght' |
|
508 | + ); |
|
509 | + // end of row |
|
510 | + $html .= EEH_HTML::trx(); |
|
511 | + } |
|
512 | + return $html; |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * _total_row |
|
519 | + * |
|
520 | + * @param EE_Line_Item $line_item |
|
521 | + * @param string $text |
|
522 | + * @return mixed |
|
523 | + * @throws EE_Error |
|
524 | + */ |
|
525 | + private function _total_row(EE_Line_Item $line_item, $text = '') |
|
526 | + { |
|
527 | + // start of row |
|
528 | + $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
529 | + // total td |
|
530 | + $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
531 | + // total td |
|
532 | + $html .= EEH_HTML::td( |
|
533 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
534 | + '', |
|
535 | + 'total jst-rght' |
|
536 | + ); |
|
537 | + // end of row |
|
538 | + $html .= EEH_HTML::trx(); |
|
539 | + return $html; |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * _payments_and_amount_owing_rows |
|
546 | + * |
|
547 | + * @param EE_Line_Item $line_item |
|
548 | + * @param array $options |
|
549 | + * @return mixed |
|
550 | + * @throws EE_Error |
|
551 | + */ |
|
552 | + private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
553 | + { |
|
554 | + $html = ''; |
|
555 | + $owing = $line_item->total(); |
|
556 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
557 | + if ($transaction instanceof EE_Transaction) { |
|
558 | + $registration_payments = array(); |
|
559 | + $registrations = ! empty($options['registrations']) |
|
560 | + ? $options['registrations'] |
|
561 | + : $transaction->registrations(); |
|
562 | + foreach ($registrations as $registration) { |
|
563 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
564 | + $registration_payments += $registration->registration_payments(); |
|
565 | + } |
|
566 | + } |
|
567 | + if (! empty($registration_payments)) { |
|
568 | + foreach ($registration_payments as $registration_payment) { |
|
569 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
570 | + $owing -= $registration_payment->amount(); |
|
571 | + $payment = $registration_payment->payment(); |
|
572 | + $payment_desc = ''; |
|
573 | + if ($payment instanceof EE_Payment) { |
|
574 | + $payment_desc = sprintf( |
|
575 | + esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
576 | + $payment->txn_id_chq_nmbr() !== '' |
|
577 | + ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
578 | + : '', |
|
579 | + $payment->timestamp() |
|
580 | + ); |
|
581 | + } |
|
582 | + // start of row |
|
583 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
584 | + // payment desc |
|
585 | + $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
586 | + // total td |
|
587 | + $html .= EEH_HTML::td( |
|
588 | + EEH_Template::format_currency( |
|
589 | + $registration_payment->amount(), |
|
590 | + false, |
|
591 | + false |
|
592 | + ), |
|
593 | + '', |
|
594 | + 'total jst-rght' |
|
595 | + ); |
|
596 | + // end of row |
|
597 | + $html .= EEH_HTML::trx(); |
|
598 | + } |
|
599 | + } |
|
600 | + if ($line_item->total()) { |
|
601 | + // start of row |
|
602 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
603 | + // total td |
|
604 | + $html .= EEH_HTML::td( |
|
605 | + esc_html__('Amount Owing', 'event_espresso'), |
|
606 | + '', 'total_currency total jst-rght', '', ' colspan="3"' |
|
607 | + ); |
|
608 | + // total td |
|
609 | + $html .= EEH_HTML::td( |
|
610 | + EEH_Template::format_currency($owing, false, false), |
|
611 | + '', |
|
612 | + 'total jst-rght' |
|
613 | + ); |
|
614 | + // end of row |
|
615 | + $html .= EEH_HTML::trx(); |
|
616 | + } |
|
617 | + } |
|
618 | + } |
|
619 | + $this->_grand_total = $owing; |
|
620 | + return $html; |
|
621 | + } |
|
622 | 622 | |
623 | 623 | |
624 | 624 | } |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | $html = ''; |
89 | 89 | // set some default options and merge with incoming |
90 | 90 | $default_options = array( |
91 | - 'show_desc' => true, // true false |
|
91 | + 'show_desc' => true, // true false |
|
92 | 92 | 'odd' => false, |
93 | 93 | ); |
94 | - $options = array_merge($default_options, (array)$options); |
|
94 | + $options = array_merge($default_options, (array) $options); |
|
95 | 95 | switch ($line_item->type()) { |
96 | 96 | case EEM_Line_Item::type_line_item: |
97 | 97 | $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $text = esc_html__('Sub-Total', 'event_espresso'); |
124 | 124 | if ($line_item->OBJ_type() === 'Event') { |
125 | 125 | $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
126 | - if (! isset($this->_events[$options['event_id']])) { |
|
126 | + if ( ! isset($this->_events[$options['event_id']])) { |
|
127 | 127 | $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
128 | 128 | // if event has default reg status of Not Approved, then don't display info on it |
129 | 129 | if ( |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | // unless there are registrations for it that are returning to pay |
135 | 135 | if (isset($options['registrations']) && is_array($options['registrations'])) { |
136 | 136 | foreach ($options['registrations'] as $registration) { |
137 | - if (! $registration instanceof EE_Registration) { |
|
137 | + if ( ! $registration instanceof EE_Registration) { |
|
138 | 138 | continue; |
139 | 139 | } |
140 | 140 | $display_event = $registration->event_ID() === $options['event_id'] |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | : $display_event; |
144 | 144 | } |
145 | 145 | } |
146 | - if (! $display_event) { |
|
146 | + if ( ! $display_event) { |
|
147 | 147 | return ''; |
148 | 148 | } |
149 | 149 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
268 | 268 | ( |
269 | 269 | $options['show_desc'] |
270 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
270 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
271 | 271 | : '' |
272 | 272 | ), |
273 | 273 | $line_item, |
@@ -311,18 +311,18 @@ discard block |
||
311 | 311 | // start of row |
312 | 312 | $row_class = $options['odd'] ? 'item odd' : 'item'; |
313 | 313 | $html = EEH_HTML::tr('', '', $row_class); |
314 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
314 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : ''; |
|
315 | 315 | // name && desc |
316 | 316 | $name_and_desc = apply_filters( |
317 | 317 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
318 | - $obj_name . $line_item->name(), |
|
318 | + $obj_name.$line_item->name(), |
|
319 | 319 | $line_item |
320 | 320 | ); |
321 | 321 | $name_and_desc .= apply_filters( |
322 | 322 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
323 | 323 | ( |
324 | 324 | $options['show_desc'] |
325 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
325 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
326 | 326 | : '' |
327 | 327 | ), |
328 | 328 | $line_item, |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
334 | 334 | // price td |
335 | 335 | if ($line_item->is_percent()) { |
336 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
336 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght'); |
|
337 | 337 | } else { |
338 | 338 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
339 | 339 | } |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | . $line_item->desc() |
378 | 378 | . '</span>' : ''; |
379 | 379 | // name td |
380 | - $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item'); |
|
380 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
381 | 381 | $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
382 | 382 | // discount/surcharge td |
383 | 383 | if ($line_item->is_percent()) { |
@@ -417,13 +417,13 @@ discard block |
||
417 | 417 | // name && desc |
418 | 418 | $name_and_desc = $line_item->name(); |
419 | 419 | $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
420 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
421 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
420 | + . esc_html__(' * taxable items', 'event_espresso').'</span>'; |
|
421 | + $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : ''; |
|
422 | 422 | // name td |
423 | 423 | $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
424 | 424 | $name_and_desc, '', 'item_l sub-item'); |
425 | 425 | // percent td |
426 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
426 | + $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', ''); |
|
427 | 427 | // empty td (price) |
428 | 428 | $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
429 | 429 | // total td |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | $registration_payments += $registration->registration_payments(); |
565 | 565 | } |
566 | 566 | } |
567 | - if (! empty($registration_payments)) { |
|
567 | + if ( ! empty($registration_payments)) { |
|
568 | 568 | foreach ($registration_payments as $registration_payment) { |
569 | 569 | if ($registration_payment instanceof EE_Registration_Payment) { |
570 | 570 | $owing -= $registration_payment->amount(); |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | $payment_desc = sprintf( |
575 | 575 | esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
576 | 576 | $payment->txn_id_chq_nmbr() !== '' |
577 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
577 | + ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> ' |
|
578 | 578 | : '', |
579 | 579 | $payment->timestamp() |
580 | 580 | ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php 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 | - ); ?> |
|
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 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
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.3.9'); |
|
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 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.018'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.018'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -19,102 +19,102 @@ discard block |
||
19 | 19 | class EE_Non_Zero_Line_Item_Filter extends EE_Line_Item_Filter_Base |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * EE_Non_Zero_Line_Item_Filter constructor. |
|
24 | - */ |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Creates a duplicate of the line item tree, except only includes billable items |
|
33 | - * and the portion of line items attributed to billable things |
|
34 | - * |
|
35 | - * @param EEI_Line_Item $line_item |
|
36 | - * @return EEI_Line_Item |
|
37 | - */ |
|
38 | - public function process(EEI_Line_Item $line_item) |
|
39 | - { |
|
40 | - $non_zero_line_item = $this->_filter_zero_line_item($line_item); |
|
41 | - if (! $non_zero_line_item instanceof EEI_Line_Item) { |
|
42 | - return null; |
|
43 | - } |
|
44 | - //if this is an event subtotal, we want to only include it if it |
|
45 | - //has a non-zero total and at least one ticket line item child |
|
46 | - if ($line_item->children()) { |
|
47 | - $ticket_or_subtotals_with_tkt_children_count = 0; |
|
48 | - foreach ($line_item->children() as $child_line_item) { |
|
49 | - $code = $child_line_item->code(); |
|
50 | - $child_line_item = $this->process($child_line_item); |
|
51 | - if (! $child_line_item instanceof EEI_Line_Item) { |
|
52 | - $line_item->delete_child_line_item($code); |
|
53 | - continue; |
|
54 | - } |
|
55 | - if ( |
|
56 | - ( |
|
57 | - $child_line_item instanceof EEI_Line_Item |
|
58 | - && $child_line_item->type() === EEM_Line_Item::type_sub_total |
|
59 | - ) |
|
60 | - || ( |
|
61 | - $child_line_item instanceof EEI_Line_Item |
|
62 | - && $child_line_item->type() === EEM_Line_Item::type_line_item |
|
63 | - && $child_line_item->OBJ_type() === 'Ticket' |
|
64 | - ) |
|
65 | - ) { |
|
66 | - $ticket_or_subtotals_with_tkt_children_count++; |
|
67 | - } |
|
68 | - } |
|
69 | - // if this is an event subtotal with NO ticket children |
|
70 | - // we basically want to ignore it |
|
71 | - return $this->_filter_zero_subtotal_line_item($non_zero_line_item, |
|
72 | - $ticket_or_subtotals_with_tkt_children_count); |
|
73 | - } |
|
74 | - return $non_zero_line_item; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Creates a new, unsaved line item, but if it's a ticket line item |
|
81 | - * with a total of 0, or a subtotal of 0, returns null instead |
|
82 | - * |
|
83 | - * @param EEI_Line_Item $line_item |
|
84 | - * @return EEI_Line_Item |
|
85 | - */ |
|
86 | - protected function _filter_zero_line_item(EEI_Line_Item $line_item) |
|
87 | - { |
|
88 | - if ( |
|
89 | - $line_item->type() === EEM_Line_Item::type_line_item |
|
90 | - && $line_item->OBJ_type() === 'Ticket' |
|
91 | - && (int)$line_item->quantity() === 0 |
|
92 | - ) { |
|
93 | - return null; |
|
94 | - } |
|
95 | - return $line_item; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Creates a new, unsaved line item, but if it's a ticket line item |
|
102 | - * with a total of 0, or a subtotal of 0, returns null instead |
|
103 | - * |
|
104 | - * @param EEI_Line_Item $line_item |
|
105 | - * @param int $ticket_children |
|
106 | - * @return EEI_Line_Item |
|
107 | - */ |
|
108 | - protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0) |
|
109 | - { |
|
110 | - if ( |
|
111 | - (int)$ticket_children === 0 |
|
112 | - && $line_item->type() === EEM_Line_Item::type_sub_total |
|
113 | - ) { |
|
114 | - return null; |
|
115 | - } |
|
116 | - return $line_item; |
|
117 | - } |
|
22 | + /** |
|
23 | + * EE_Non_Zero_Line_Item_Filter constructor. |
|
24 | + */ |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Creates a duplicate of the line item tree, except only includes billable items |
|
33 | + * and the portion of line items attributed to billable things |
|
34 | + * |
|
35 | + * @param EEI_Line_Item $line_item |
|
36 | + * @return EEI_Line_Item |
|
37 | + */ |
|
38 | + public function process(EEI_Line_Item $line_item) |
|
39 | + { |
|
40 | + $non_zero_line_item = $this->_filter_zero_line_item($line_item); |
|
41 | + if (! $non_zero_line_item instanceof EEI_Line_Item) { |
|
42 | + return null; |
|
43 | + } |
|
44 | + //if this is an event subtotal, we want to only include it if it |
|
45 | + //has a non-zero total and at least one ticket line item child |
|
46 | + if ($line_item->children()) { |
|
47 | + $ticket_or_subtotals_with_tkt_children_count = 0; |
|
48 | + foreach ($line_item->children() as $child_line_item) { |
|
49 | + $code = $child_line_item->code(); |
|
50 | + $child_line_item = $this->process($child_line_item); |
|
51 | + if (! $child_line_item instanceof EEI_Line_Item) { |
|
52 | + $line_item->delete_child_line_item($code); |
|
53 | + continue; |
|
54 | + } |
|
55 | + if ( |
|
56 | + ( |
|
57 | + $child_line_item instanceof EEI_Line_Item |
|
58 | + && $child_line_item->type() === EEM_Line_Item::type_sub_total |
|
59 | + ) |
|
60 | + || ( |
|
61 | + $child_line_item instanceof EEI_Line_Item |
|
62 | + && $child_line_item->type() === EEM_Line_Item::type_line_item |
|
63 | + && $child_line_item->OBJ_type() === 'Ticket' |
|
64 | + ) |
|
65 | + ) { |
|
66 | + $ticket_or_subtotals_with_tkt_children_count++; |
|
67 | + } |
|
68 | + } |
|
69 | + // if this is an event subtotal with NO ticket children |
|
70 | + // we basically want to ignore it |
|
71 | + return $this->_filter_zero_subtotal_line_item($non_zero_line_item, |
|
72 | + $ticket_or_subtotals_with_tkt_children_count); |
|
73 | + } |
|
74 | + return $non_zero_line_item; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Creates a new, unsaved line item, but if it's a ticket line item |
|
81 | + * with a total of 0, or a subtotal of 0, returns null instead |
|
82 | + * |
|
83 | + * @param EEI_Line_Item $line_item |
|
84 | + * @return EEI_Line_Item |
|
85 | + */ |
|
86 | + protected function _filter_zero_line_item(EEI_Line_Item $line_item) |
|
87 | + { |
|
88 | + if ( |
|
89 | + $line_item->type() === EEM_Line_Item::type_line_item |
|
90 | + && $line_item->OBJ_type() === 'Ticket' |
|
91 | + && (int)$line_item->quantity() === 0 |
|
92 | + ) { |
|
93 | + return null; |
|
94 | + } |
|
95 | + return $line_item; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Creates a new, unsaved line item, but if it's a ticket line item |
|
102 | + * with a total of 0, or a subtotal of 0, returns null instead |
|
103 | + * |
|
104 | + * @param EEI_Line_Item $line_item |
|
105 | + * @param int $ticket_children |
|
106 | + * @return EEI_Line_Item |
|
107 | + */ |
|
108 | + protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0) |
|
109 | + { |
|
110 | + if ( |
|
111 | + (int)$ticket_children === 0 |
|
112 | + && $line_item->type() === EEM_Line_Item::type_sub_total |
|
113 | + ) { |
|
114 | + return null; |
|
115 | + } |
|
116 | + return $line_item; |
|
117 | + } |
|
118 | 118 | |
119 | 119 | |
120 | 120 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | public function process(EEI_Line_Item $line_item) |
39 | 39 | { |
40 | 40 | $non_zero_line_item = $this->_filter_zero_line_item($line_item); |
41 | - if (! $non_zero_line_item instanceof EEI_Line_Item) { |
|
41 | + if ( ! $non_zero_line_item instanceof EEI_Line_Item) { |
|
42 | 42 | return null; |
43 | 43 | } |
44 | 44 | //if this is an event subtotal, we want to only include it if it |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | foreach ($line_item->children() as $child_line_item) { |
49 | 49 | $code = $child_line_item->code(); |
50 | 50 | $child_line_item = $this->process($child_line_item); |
51 | - if (! $child_line_item instanceof EEI_Line_Item) { |
|
51 | + if ( ! $child_line_item instanceof EEI_Line_Item) { |
|
52 | 52 | $line_item->delete_child_line_item($code); |
53 | 53 | continue; |
54 | 54 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | if ( |
89 | 89 | $line_item->type() === EEM_Line_Item::type_line_item |
90 | 90 | && $line_item->OBJ_type() === 'Ticket' |
91 | - && (int)$line_item->quantity() === 0 |
|
91 | + && (int) $line_item->quantity() === 0 |
|
92 | 92 | ) { |
93 | 93 | return null; |
94 | 94 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0) |
109 | 109 | { |
110 | 110 | if ( |
111 | - (int)$ticket_children === 0 |
|
111 | + (int) $ticket_children === 0 |
|
112 | 112 | && $line_item->type() === EEM_Line_Item::type_sub_total |
113 | 113 | ) { |
114 | 114 | return null; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -18,192 +18,192 @@ discard block |
||
18 | 18 | class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * array of line item codes and their corresponding quantities for registrations |
|
23 | - * |
|
24 | - * @type array $_line_item_registrations |
|
25 | - */ |
|
26 | - protected $_line_item_registrations = array(); |
|
27 | - |
|
28 | - /** |
|
29 | - * Just kept in case we want it someday. Currently unused |
|
30 | - * |
|
31 | - * @var EE_Registration[] |
|
32 | - */ |
|
33 | - protected $_registrations = array(); |
|
34 | - |
|
35 | - /** |
|
36 | - * @var EE_Registration |
|
37 | - */ |
|
38 | - protected $_current_registration; |
|
39 | - |
|
40 | - /** |
|
41 | - * these reg statuses should NOT increment the line item quantity |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - protected $_closed_reg_statuses = array(); |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * EE_Billable_Line_Item_Filter constructor. |
|
51 | - * |
|
52 | - * @param EE_Registration[] $registrations |
|
53 | - * @throws EE_Error |
|
54 | - */ |
|
55 | - public function __construct($registrations) |
|
56 | - { |
|
57 | - $this->_registrations = $registrations; |
|
58 | - $this->_calculate_registrations_per_line_item_code($registrations); |
|
59 | - // these reg statuses should NOT increment the line item quantity |
|
60 | - $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * sets the _line_item_registrations from the provided registrations |
|
67 | - * |
|
68 | - * @param EE_Registration[] $registrations |
|
69 | - * @return void |
|
70 | - * @throws EE_Error |
|
71 | - */ |
|
72 | - protected function _calculate_registrations_per_line_item_code($registrations) |
|
73 | - { |
|
74 | - foreach ($registrations as $registration) { |
|
75 | - $line_item_code = EEM_Line_Item::instance()->get_var( |
|
76 | - EEM_Line_Item::instance()->line_item_for_registration_query_params( |
|
77 | - $registration, |
|
78 | - array('limit' => 1) |
|
79 | - ), |
|
80 | - 'LIN_code' |
|
81 | - ); |
|
82 | - if ($line_item_code) { |
|
83 | - if (! isset($this->_line_item_registrations[$line_item_code])) { |
|
84 | - $this->_line_item_registrations[$line_item_code] = array(); |
|
85 | - } |
|
86 | - $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration; |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Creates a duplicate of the line item tree, except only includes billable items |
|
95 | - * and the portion of line items attributed to billable things |
|
96 | - * |
|
97 | - * @param EEI_Line_Item $line_item |
|
98 | - * @return EEI_Line_Item |
|
99 | - * @throws EE_Error |
|
100 | - */ |
|
101 | - public function process(EEI_Line_Item $line_item) |
|
102 | - { |
|
103 | - $this->_adjust_line_item_quantity($line_item); |
|
104 | - if (! $line_item->children()) { |
|
105 | - return $line_item; |
|
106 | - } |
|
107 | - //the original running total (taking ALL tickets into account) |
|
108 | - $running_total_of_children = 0; |
|
109 | - //the new running total (only taking the specified ticket quantities into account) |
|
110 | - $running_total_of_children_under_consideration = 0; |
|
111 | - // let's also track the quantity of tickets that pertain to the registrations |
|
112 | - $total_child_ticket_quantity = 0; |
|
113 | - foreach ($line_item->children() as $child_line_item) { |
|
114 | - $original_li_total = $child_line_item->is_percent() |
|
115 | - ? $running_total_of_children * $child_line_item->percent() / 100 |
|
116 | - : $child_line_item->unit_price() * $child_line_item->quantity(); |
|
117 | - $this->process($child_line_item); |
|
118 | - // If this line item is a normal line item that isn't for a ticket, |
|
119 | - // we want to modify its total (and unit price if not a percentage line item) |
|
120 | - // so it reflects only that portion of the surcharge/discount shared by these registrations |
|
121 | - if ( |
|
122 | - $child_line_item->type() === EEM_Line_Item::type_line_item |
|
123 | - && $child_line_item->OBJ_type() !== 'Ticket' |
|
124 | - ) { |
|
125 | - $percent_of_running_total = $running_total_of_children |
|
126 | - ? $original_li_total / $running_total_of_children |
|
127 | - : 0; |
|
128 | - $child_line_item->set_total( |
|
129 | - $running_total_of_children_under_consideration * $percent_of_running_total |
|
130 | - ); |
|
131 | - if (! $child_line_item->is_percent()) { |
|
132 | - $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
|
133 | - } |
|
134 | - } else if ( |
|
135 | - //make sure this item's quantity and total matches its parent |
|
136 | - $line_item->type() === EEM_Line_Item::type_line_item |
|
137 | - && $line_item->OBJ_type() === 'Ticket' |
|
138 | - // but not if it's a percentage modifier |
|
139 | - && ! $child_line_item->is_percent() |
|
140 | - && ! ( |
|
141 | - // or a cancellation |
|
142 | - $child_line_item->is_cancelled() |
|
143 | - && ! ( |
|
144 | - // unless it IS a cancellation and the current registration is cancelled |
|
145 | - $child_line_item->is_cancelled() |
|
146 | - && $this->_current_registration instanceof EE_Registration |
|
147 | - && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true) |
|
148 | - ) |
|
149 | - ) |
|
150 | - ) { |
|
151 | - $child_line_item->set_quantity($line_item->quantity()); |
|
152 | - $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity()); |
|
153 | - } |
|
154 | - $running_total_of_children += $original_li_total; |
|
155 | - $running_total_of_children_under_consideration += $child_line_item->total(); |
|
156 | - if ($child_line_item->OBJ_type() === 'Ticket') { |
|
157 | - $total_child_ticket_quantity += $child_line_item->quantity(); |
|
158 | - } |
|
159 | - } |
|
160 | - $line_item->set_total($running_total_of_children_under_consideration); |
|
161 | - if ($line_item->quantity()) { |
|
162 | - $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity()); |
|
163 | - } else { |
|
164 | - $line_item->set_unit_price(0); |
|
165 | - } |
|
166 | - if ($line_item->OBJ_type() === 'Event') { |
|
167 | - $line_item->set_quantity($total_child_ticket_quantity); |
|
168 | - } |
|
169 | - return $line_item; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Adjusts quantities for line items for tickets according to the registrations provided |
|
176 | - * in the constructor |
|
177 | - * |
|
178 | - * @param EEI_Line_Item $line_item |
|
179 | - * @return EEI_Line_Item |
|
180 | - */ |
|
181 | - protected function _adjust_line_item_quantity(EEI_Line_Item $line_item) |
|
182 | - { |
|
183 | - // is this a ticket ? |
|
184 | - if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') { |
|
185 | - $this->_current_registration = null; |
|
186 | - $quantity = 0; |
|
187 | - // if this ticket is billable at this moment, then we should have a positive quantity |
|
188 | - if ( |
|
189 | - isset($this->_line_item_registrations[$line_item->code()]) |
|
190 | - && is_array($this->_line_item_registrations[$line_item->code()]) |
|
191 | - ) { |
|
192 | - // set quantity based on number of open registrations for this ticket |
|
193 | - foreach ($this->_line_item_registrations[$line_item->code()] as $registration) { |
|
194 | - if ( |
|
195 | - $registration instanceof EE_Registration |
|
196 | - ) { |
|
197 | - $quantity++; |
|
198 | - $this->_current_registration = $registration; |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - $line_item->set_quantity($quantity); |
|
203 | - $line_item->set_total($line_item->unit_price() * $line_item->quantity()); |
|
204 | - } |
|
205 | - return $line_item; |
|
206 | - } |
|
21 | + /** |
|
22 | + * array of line item codes and their corresponding quantities for registrations |
|
23 | + * |
|
24 | + * @type array $_line_item_registrations |
|
25 | + */ |
|
26 | + protected $_line_item_registrations = array(); |
|
27 | + |
|
28 | + /** |
|
29 | + * Just kept in case we want it someday. Currently unused |
|
30 | + * |
|
31 | + * @var EE_Registration[] |
|
32 | + */ |
|
33 | + protected $_registrations = array(); |
|
34 | + |
|
35 | + /** |
|
36 | + * @var EE_Registration |
|
37 | + */ |
|
38 | + protected $_current_registration; |
|
39 | + |
|
40 | + /** |
|
41 | + * these reg statuses should NOT increment the line item quantity |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + protected $_closed_reg_statuses = array(); |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * EE_Billable_Line_Item_Filter constructor. |
|
51 | + * |
|
52 | + * @param EE_Registration[] $registrations |
|
53 | + * @throws EE_Error |
|
54 | + */ |
|
55 | + public function __construct($registrations) |
|
56 | + { |
|
57 | + $this->_registrations = $registrations; |
|
58 | + $this->_calculate_registrations_per_line_item_code($registrations); |
|
59 | + // these reg statuses should NOT increment the line item quantity |
|
60 | + $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * sets the _line_item_registrations from the provided registrations |
|
67 | + * |
|
68 | + * @param EE_Registration[] $registrations |
|
69 | + * @return void |
|
70 | + * @throws EE_Error |
|
71 | + */ |
|
72 | + protected function _calculate_registrations_per_line_item_code($registrations) |
|
73 | + { |
|
74 | + foreach ($registrations as $registration) { |
|
75 | + $line_item_code = EEM_Line_Item::instance()->get_var( |
|
76 | + EEM_Line_Item::instance()->line_item_for_registration_query_params( |
|
77 | + $registration, |
|
78 | + array('limit' => 1) |
|
79 | + ), |
|
80 | + 'LIN_code' |
|
81 | + ); |
|
82 | + if ($line_item_code) { |
|
83 | + if (! isset($this->_line_item_registrations[$line_item_code])) { |
|
84 | + $this->_line_item_registrations[$line_item_code] = array(); |
|
85 | + } |
|
86 | + $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration; |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Creates a duplicate of the line item tree, except only includes billable items |
|
95 | + * and the portion of line items attributed to billable things |
|
96 | + * |
|
97 | + * @param EEI_Line_Item $line_item |
|
98 | + * @return EEI_Line_Item |
|
99 | + * @throws EE_Error |
|
100 | + */ |
|
101 | + public function process(EEI_Line_Item $line_item) |
|
102 | + { |
|
103 | + $this->_adjust_line_item_quantity($line_item); |
|
104 | + if (! $line_item->children()) { |
|
105 | + return $line_item; |
|
106 | + } |
|
107 | + //the original running total (taking ALL tickets into account) |
|
108 | + $running_total_of_children = 0; |
|
109 | + //the new running total (only taking the specified ticket quantities into account) |
|
110 | + $running_total_of_children_under_consideration = 0; |
|
111 | + // let's also track the quantity of tickets that pertain to the registrations |
|
112 | + $total_child_ticket_quantity = 0; |
|
113 | + foreach ($line_item->children() as $child_line_item) { |
|
114 | + $original_li_total = $child_line_item->is_percent() |
|
115 | + ? $running_total_of_children * $child_line_item->percent() / 100 |
|
116 | + : $child_line_item->unit_price() * $child_line_item->quantity(); |
|
117 | + $this->process($child_line_item); |
|
118 | + // If this line item is a normal line item that isn't for a ticket, |
|
119 | + // we want to modify its total (and unit price if not a percentage line item) |
|
120 | + // so it reflects only that portion of the surcharge/discount shared by these registrations |
|
121 | + if ( |
|
122 | + $child_line_item->type() === EEM_Line_Item::type_line_item |
|
123 | + && $child_line_item->OBJ_type() !== 'Ticket' |
|
124 | + ) { |
|
125 | + $percent_of_running_total = $running_total_of_children |
|
126 | + ? $original_li_total / $running_total_of_children |
|
127 | + : 0; |
|
128 | + $child_line_item->set_total( |
|
129 | + $running_total_of_children_under_consideration * $percent_of_running_total |
|
130 | + ); |
|
131 | + if (! $child_line_item->is_percent()) { |
|
132 | + $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
|
133 | + } |
|
134 | + } else if ( |
|
135 | + //make sure this item's quantity and total matches its parent |
|
136 | + $line_item->type() === EEM_Line_Item::type_line_item |
|
137 | + && $line_item->OBJ_type() === 'Ticket' |
|
138 | + // but not if it's a percentage modifier |
|
139 | + && ! $child_line_item->is_percent() |
|
140 | + && ! ( |
|
141 | + // or a cancellation |
|
142 | + $child_line_item->is_cancelled() |
|
143 | + && ! ( |
|
144 | + // unless it IS a cancellation and the current registration is cancelled |
|
145 | + $child_line_item->is_cancelled() |
|
146 | + && $this->_current_registration instanceof EE_Registration |
|
147 | + && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true) |
|
148 | + ) |
|
149 | + ) |
|
150 | + ) { |
|
151 | + $child_line_item->set_quantity($line_item->quantity()); |
|
152 | + $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity()); |
|
153 | + } |
|
154 | + $running_total_of_children += $original_li_total; |
|
155 | + $running_total_of_children_under_consideration += $child_line_item->total(); |
|
156 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
157 | + $total_child_ticket_quantity += $child_line_item->quantity(); |
|
158 | + } |
|
159 | + } |
|
160 | + $line_item->set_total($running_total_of_children_under_consideration); |
|
161 | + if ($line_item->quantity()) { |
|
162 | + $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity()); |
|
163 | + } else { |
|
164 | + $line_item->set_unit_price(0); |
|
165 | + } |
|
166 | + if ($line_item->OBJ_type() === 'Event') { |
|
167 | + $line_item->set_quantity($total_child_ticket_quantity); |
|
168 | + } |
|
169 | + return $line_item; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Adjusts quantities for line items for tickets according to the registrations provided |
|
176 | + * in the constructor |
|
177 | + * |
|
178 | + * @param EEI_Line_Item $line_item |
|
179 | + * @return EEI_Line_Item |
|
180 | + */ |
|
181 | + protected function _adjust_line_item_quantity(EEI_Line_Item $line_item) |
|
182 | + { |
|
183 | + // is this a ticket ? |
|
184 | + if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') { |
|
185 | + $this->_current_registration = null; |
|
186 | + $quantity = 0; |
|
187 | + // if this ticket is billable at this moment, then we should have a positive quantity |
|
188 | + if ( |
|
189 | + isset($this->_line_item_registrations[$line_item->code()]) |
|
190 | + && is_array($this->_line_item_registrations[$line_item->code()]) |
|
191 | + ) { |
|
192 | + // set quantity based on number of open registrations for this ticket |
|
193 | + foreach ($this->_line_item_registrations[$line_item->code()] as $registration) { |
|
194 | + if ( |
|
195 | + $registration instanceof EE_Registration |
|
196 | + ) { |
|
197 | + $quantity++; |
|
198 | + $this->_current_registration = $registration; |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + $line_item->set_quantity($quantity); |
|
203 | + $line_item->set_total($line_item->unit_price() * $line_item->quantity()); |
|
204 | + } |
|
205 | + return $line_item; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | 209 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | 'LIN_code' |
81 | 81 | ); |
82 | 82 | if ($line_item_code) { |
83 | - if (! isset($this->_line_item_registrations[$line_item_code])) { |
|
83 | + if ( ! isset($this->_line_item_registrations[$line_item_code])) { |
|
84 | 84 | $this->_line_item_registrations[$line_item_code] = array(); |
85 | 85 | } |
86 | 86 | $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration; |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | public function process(EEI_Line_Item $line_item) |
102 | 102 | { |
103 | 103 | $this->_adjust_line_item_quantity($line_item); |
104 | - if (! $line_item->children()) { |
|
104 | + if ( ! $line_item->children()) { |
|
105 | 105 | return $line_item; |
106 | 106 | } |
107 | 107 | //the original running total (taking ALL tickets into account) |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $child_line_item->set_total( |
129 | 129 | $running_total_of_children_under_consideration * $percent_of_running_total |
130 | 130 | ); |
131 | - if (! $child_line_item->is_percent()) { |
|
131 | + if ( ! $child_line_item->is_percent()) { |
|
132 | 132 | $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
133 | 133 | } |
134 | 134 | } else if ( |