@@ -15,89 +15,89 @@ |
||
15 | 15 | class EE_PMT_Paypal_Express extends EE_PMT_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * EE_PMT_Paypal_Express constructor. |
|
20 | - */ |
|
21 | - public function __construct($pm_instance = null) |
|
22 | - { |
|
23 | - require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
24 | - $this->_gateway = new EEG_Paypal_Express(); |
|
18 | + /** |
|
19 | + * EE_PMT_Paypal_Express constructor. |
|
20 | + */ |
|
21 | + public function __construct($pm_instance = null) |
|
22 | + { |
|
23 | + require_once($this->file_folder() . 'EEG_Paypal_Express.gateway.php'); |
|
24 | + $this->_gateway = new EEG_Paypal_Express(); |
|
25 | 25 | |
26 | - $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
27 | - $this->_template_path = $this->file_folder() . 'templates' . DS; |
|
28 | - $this->_default_description = esc_html__( |
|
29 | - // @codingStandardsIgnoreStart |
|
30 | - 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
31 | - // @codingStandardsIgnoreEnd |
|
32 | - 'event_espresso' |
|
33 | - ); |
|
34 | - $this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo-gold-160.png'; |
|
26 | + $this->_pretty_name = esc_html__('PayPal Express', 'event_espresso'); |
|
27 | + $this->_template_path = $this->file_folder() . 'templates' . DS; |
|
28 | + $this->_default_description = esc_html__( |
|
29 | + // @codingStandardsIgnoreStart |
|
30 | + 'After clicking \'Finalize Registration\', you will be forwarded to PayPal website to Login and make your payment.', |
|
31 | + // @codingStandardsIgnoreEnd |
|
32 | + 'event_espresso' |
|
33 | + ); |
|
34 | + $this->_default_button_url = $this->file_url() . 'lib' . DS . 'paypal-express-checkout-logo-gold-160.png'; |
|
35 | 35 | |
36 | - parent::__construct($pm_instance); |
|
37 | - } |
|
36 | + parent::__construct($pm_instance); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Adds the help tab. |
|
42 | - * |
|
43 | - * @see EE_PMT_Base::help_tabs_config() |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function help_tabs_config() |
|
47 | - { |
|
48 | - return array( |
|
49 | - $this->get_help_tab_name() => array( |
|
50 | - 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
51 | - 'filename' => 'payment_methods_overview_paypal_express' |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
40 | + /** |
|
41 | + * Adds the help tab. |
|
42 | + * |
|
43 | + * @see EE_PMT_Base::help_tabs_config() |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function help_tabs_config() |
|
47 | + { |
|
48 | + return array( |
|
49 | + $this->get_help_tab_name() => array( |
|
50 | + 'title' => esc_html__('PayPal Express Settings', 'event_espresso'), |
|
51 | + 'filename' => 'payment_methods_overview_paypal_express' |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Gets the form for all the settings related to this payment method type. |
|
59 | - * |
|
60 | - * @return EE_Payment_Method_Form |
|
61 | - */ |
|
62 | - public function generate_new_settings_form() |
|
63 | - { |
|
64 | - return new SettingsForm(array(), $this->get_help_tab_link()); |
|
65 | - } |
|
57 | + /** |
|
58 | + * Gets the form for all the settings related to this payment method type. |
|
59 | + * |
|
60 | + * @return EE_Payment_Method_Form |
|
61 | + */ |
|
62 | + public function generate_new_settings_form() |
|
63 | + { |
|
64 | + return new SettingsForm(array(), $this->get_help_tab_link()); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Creates a billing form for this payment method type. |
|
70 | - * |
|
71 | - * @param \EE_Transaction $transaction |
|
72 | - * @return \EE_Billing_Info_Form |
|
73 | - */ |
|
74 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
75 | - { |
|
76 | - if ($this->_pm_instance->debug_mode()) { |
|
77 | - $form = new EE_Billing_Info_Form( |
|
78 | - $this->_pm_instance, |
|
79 | - array( |
|
80 | - 'name' => 'paypal_express_Info_Form', |
|
81 | - 'subsections' => array( |
|
82 | - 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
83 | - array( |
|
84 | - 'layout_strategy' => new EE_Template_Layout( |
|
85 | - array( |
|
86 | - 'layout_template_file' => $this->_template_path |
|
87 | - . 'paypal_express_debug_info.template.php', |
|
88 | - 'template_args' => array( |
|
89 | - 'debug_mode' => $this->_pm_instance->debug_mode() |
|
90 | - ) |
|
91 | - ) |
|
92 | - ) |
|
93 | - ) |
|
94 | - ) |
|
95 | - ) |
|
96 | - ) |
|
97 | - ); |
|
98 | - return $form; |
|
99 | - } |
|
68 | + /** |
|
69 | + * Creates a billing form for this payment method type. |
|
70 | + * |
|
71 | + * @param \EE_Transaction $transaction |
|
72 | + * @return \EE_Billing_Info_Form |
|
73 | + */ |
|
74 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
75 | + { |
|
76 | + if ($this->_pm_instance->debug_mode()) { |
|
77 | + $form = new EE_Billing_Info_Form( |
|
78 | + $this->_pm_instance, |
|
79 | + array( |
|
80 | + 'name' => 'paypal_express_Info_Form', |
|
81 | + 'subsections' => array( |
|
82 | + 'paypal_express_debug_info' => new EE_Form_Section_Proper( |
|
83 | + array( |
|
84 | + 'layout_strategy' => new EE_Template_Layout( |
|
85 | + array( |
|
86 | + 'layout_template_file' => $this->_template_path |
|
87 | + . 'paypal_express_debug_info.template.php', |
|
88 | + 'template_args' => array( |
|
89 | + 'debug_mode' => $this->_pm_instance->debug_mode() |
|
90 | + ) |
|
91 | + ) |
|
92 | + ) |
|
93 | + ) |
|
94 | + ) |
|
95 | + ) |
|
96 | + ) |
|
97 | + ); |
|
98 | + return $form; |
|
99 | + } |
|
100 | 100 | |
101 | - return false; |
|
102 | - } |
|
101 | + return false; |
|
102 | + } |
|
103 | 103 | } |
@@ -11,598 +11,598 @@ |
||
11 | 11 | class EEG_Paypal_Pro extends EE_Onsite_Gateway |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @var $_paypal_api_username string |
|
16 | - */ |
|
17 | - protected $_username = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var $_password string |
|
21 | - */ |
|
22 | - protected $_password = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var $_signature string |
|
26 | - */ |
|
27 | - protected $_signature = null; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | - */ |
|
32 | - protected $_credit_card_types = null; |
|
33 | - |
|
34 | - protected $_currencies_supported = array( |
|
35 | - 'USD', |
|
36 | - 'GBP', |
|
37 | - 'CAD', |
|
38 | - 'AUD', |
|
39 | - 'BRL', |
|
40 | - 'CHF', |
|
41 | - 'CZK', |
|
42 | - 'DKK', |
|
43 | - 'EUR', |
|
44 | - 'HKD', |
|
45 | - 'HUF', |
|
46 | - 'ILS', |
|
47 | - 'JPY', |
|
48 | - 'MXN', |
|
49 | - 'MYR', |
|
50 | - 'NOK', |
|
51 | - 'NZD', |
|
52 | - 'PHP', |
|
53 | - 'PLN', |
|
54 | - 'SEK', |
|
55 | - 'SGD', |
|
56 | - 'THB', |
|
57 | - 'TRY', |
|
58 | - 'TWD', |
|
59 | - 'RUB', |
|
60 | - 'INR', |
|
61 | - ); |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param EEI_Payment $payment |
|
67 | - * @param array $billing_info { |
|
68 | - * @type string $credit_card |
|
69 | - * @type string $credit_card_type |
|
70 | - * @type string $exp_month always 2 characters |
|
71 | - * @type string $exp_year always 4 characters |
|
72 | - * @type string $cvv |
|
73 | - * } |
|
74 | - * @see parent::do_direct_payment for more info |
|
75 | - * @return EE_Payment|EEI_Payment |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public function do_direct_payment($payment, $billing_info = null) |
|
79 | - { |
|
80 | - $transaction = $payment->transaction(); |
|
81 | - if (! $transaction instanceof EEI_Transaction) { |
|
82 | - throw new EE_Error( |
|
83 | - esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | - ); |
|
85 | - } |
|
86 | - $primary_registrant = $transaction->primary_registration(); |
|
87 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | - throw new EE_Error( |
|
89 | - esc_html__( |
|
90 | - 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | - 'event_espresso' |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - $attendee = $primary_registrant->attendee(); |
|
96 | - if (! $attendee instanceof EEI_Attendee) { |
|
97 | - throw new EE_Error( |
|
98 | - esc_html__( |
|
99 | - 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | - 'event_espresso' |
|
101 | - ) |
|
102 | - ); |
|
103 | - } |
|
104 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | - $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | - // charge for the full amount. Show itemized list |
|
107 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
108 | - $item_num = 1; |
|
109 | - $total_line_item = $transaction->total_line_item(); |
|
110 | - $order_items = array(); |
|
111 | - foreach ($total_line_item->get_items() as $line_item) { |
|
112 | - // ignore line items with a quantity of 0 |
|
113 | - if ($line_item->quantity() == 0) { |
|
114 | - continue; |
|
115 | - } |
|
116 | - $item = array( |
|
117 | - // Item Name. 127 char max. |
|
118 | - 'l_name' => substr( |
|
119 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
120 | - 0, |
|
121 | - 127 |
|
122 | - ), |
|
123 | - // Item description. 127 char max. |
|
124 | - 'l_desc' => substr( |
|
125 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
126 | - 0, |
|
127 | - 127 |
|
128 | - ), |
|
129 | - // Cost of individual item. |
|
130 | - 'l_amt' => $line_item->unit_price(), |
|
131 | - // Item Number. 127 char max. |
|
132 | - 'l_number' => $item_num++, |
|
133 | - // Item quantity. Must be any positive integer. |
|
134 | - 'l_qty' => $line_item->quantity(), |
|
135 | - // Item's sales tax amount. |
|
136 | - 'l_taxamt' => '', |
|
137 | - // eBay auction number of item. |
|
138 | - 'l_ebayitemnumber' => '', |
|
139 | - // eBay transaction ID of purchased item. |
|
140 | - 'l_ebayitemauctiontxnid' => '', |
|
141 | - // eBay order ID for the item. |
|
142 | - 'l_ebayitemorderid' => '', |
|
143 | - ); |
|
144 | - // add to array of all items |
|
145 | - array_push($order_items, $item); |
|
146 | - } |
|
147 | - $item_amount = $total_line_item->get_items_total(); |
|
148 | - $tax_amount = $total_line_item->get_total_tax(); |
|
149 | - } else { |
|
150 | - $order_items = array(); |
|
151 | - $item_amount = $payment->amount(); |
|
152 | - $tax_amount = 0; |
|
153 | - array_push($order_items, array( |
|
154 | - // Item Name. 127 char max. |
|
155 | - 'l_name' => substr( |
|
156 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
157 | - 0, |
|
158 | - 127 |
|
159 | - ), |
|
160 | - // Item description. 127 char max. |
|
161 | - 'l_desc' => substr( |
|
162 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
163 | - 0, |
|
164 | - 127 |
|
165 | - ), |
|
166 | - // Cost of individual item. |
|
167 | - 'l_amt' => $payment->amount(), |
|
168 | - // Item Number. 127 char max. |
|
169 | - 'l_number' => 1, |
|
170 | - // Item quantity. Must be any positive integer. |
|
171 | - 'l_qty' => 1, |
|
172 | - )); |
|
173 | - } |
|
174 | - // Populate data arrays with order data. |
|
175 | - $DPFields = array( |
|
176 | - // How you want to obtain payment ? |
|
177 | - // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
178 | - // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
179 | - 'paymentaction' => 'Sale', |
|
180 | - // Required. IP address of the payer's browser. |
|
181 | - 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
182 | - // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
183 | - 'returnfmfdetails' => '1', |
|
184 | - ); |
|
185 | - $CCDetails = array( |
|
186 | - // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
187 | - // If Maestro or Solo, the currency code must be GBP. |
|
188 | - // In addition, either start date or issue number must be specified. |
|
189 | - 'creditcardtype' => $billing_info['credit_card_type'], |
|
190 | - // Required. Credit card number. No spaces or punctuation. |
|
191 | - 'acct' => $billing_info['credit_card'], |
|
192 | - // Required. Credit card expiration date. Format is MMYYYY |
|
193 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
194 | - // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
195 | - 'cvv2' => $billing_info['cvv'], |
|
196 | - ); |
|
197 | - $PayerInfo = array( |
|
198 | - // Email address of payer. |
|
199 | - 'email' => $billing_info['email'], |
|
200 | - // Unique PayPal customer ID for payer. |
|
201 | - 'payerid' => '', |
|
202 | - // Status of payer. Values are verified or unverified |
|
203 | - 'payerstatus' => '', |
|
204 | - // Payer's business name. |
|
205 | - 'business' => '', |
|
206 | - ); |
|
207 | - $PayerName = array( |
|
208 | - // Payer's salutation. 20 char max. |
|
209 | - 'salutation' => '', |
|
210 | - // Payer's first name. 25 char max. |
|
211 | - 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
212 | - // Payer's middle name. 25 char max. |
|
213 | - 'middlename' => '', |
|
214 | - // Payer's last name. 25 char max. |
|
215 | - 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
216 | - // Payer's suffix. 12 char max. |
|
217 | - 'suffix' => '', |
|
218 | - ); |
|
219 | - $BillingAddress = array( |
|
220 | - // Required. First street address. |
|
221 | - 'street' => $billing_info['address'], |
|
222 | - // Second street address. |
|
223 | - 'street2' => $billing_info['address2'], |
|
224 | - // Required. Name of City. |
|
225 | - 'city' => $billing_info['city'], |
|
226 | - // Required. Name of State or Province. |
|
227 | - 'state' => substr($billing_info['state'], 0, 40), |
|
228 | - // Required. Country code. |
|
229 | - 'countrycode' => $billing_info['country'], |
|
230 | - // Required. Postal code of payer. |
|
231 | - 'zip' => $billing_info['zip'], |
|
232 | - ); |
|
233 | - // check if the registration info contains the needed fields for paypal pro |
|
234 | - // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
235 | - if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
236 | - $use_registration_address_info = true; |
|
237 | - } else { |
|
238 | - $use_registration_address_info = false; |
|
239 | - } |
|
240 | - // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
241 | - // If not, use the billing info again |
|
242 | - $ShippingAddress = array( |
|
243 | - 'shiptoname' => substr($use_registration_address_info |
|
244 | - ? $attendee->full_name() |
|
245 | - : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
246 | - 'shiptostreet' => substr($use_registration_address_info |
|
247 | - ? $attendee->address() |
|
248 | - : $billing_info['address'], 0, 100), |
|
249 | - 'shiptostreet2' => substr($use_registration_address_info |
|
250 | - ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
251 | - 'shiptocity' => substr($use_registration_address_info |
|
252 | - ? $attendee->city() |
|
253 | - : $billing_info['city'], 0, 40), |
|
254 | - 'state' => substr($use_registration_address_info |
|
255 | - ? $attendee->state_name() |
|
256 | - : $billing_info['state'], 0, 40), |
|
257 | - 'shiptocountry' => $use_registration_address_info |
|
258 | - ? $attendee->country_ID() |
|
259 | - : $billing_info['country'], |
|
260 | - 'shiptozip' => substr($use_registration_address_info |
|
261 | - ? $attendee->zip() |
|
262 | - : $billing_info['zip'], 0, 20), |
|
263 | - 'shiptophonenum' => substr($use_registration_address_info |
|
264 | - ? $attendee->phone() |
|
265 | - : $billing_info['phone'], 0, 20), |
|
266 | - ); |
|
267 | - $PaymentDetails = array( |
|
268 | - // Required. Total amount of order, including shipping, handling, and tax. |
|
269 | - 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
270 | - // Required. Three-letter currency code. Default is USD. |
|
271 | - 'currencycode' => $payment->currency_code(), |
|
272 | - // Required if you include itemized cart details. (L_AMTn, etc.) |
|
273 | - // Subtotal of items not including S&H, or tax. |
|
274 | - 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
275 | - // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
276 | - 'shippingamt' => '', |
|
277 | - // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
278 | - 'handlingamt' => '', |
|
279 | - // Required if you specify itemized cart tax details. |
|
280 | - // Sum of tax for all items on the order. Total sales tax. |
|
281 | - 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
282 | - // Description of the order the customer is purchasing. 127 char max. |
|
283 | - 'desc' => $order_description, |
|
284 | - // Free-form field for your own use. 256 char max. |
|
285 | - 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
286 | - // Your own invoice or tracking number |
|
287 | - 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
288 | - // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
289 | - 'notifyurl' => '', |
|
290 | - 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
291 | - ); |
|
292 | - // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
293 | - $PayPalRequestData = array( |
|
294 | - 'DPFields' => $DPFields, |
|
295 | - 'CCDetails' => $CCDetails, |
|
296 | - 'PayerInfo' => $PayerInfo, |
|
297 | - 'PayerName' => $PayerName, |
|
298 | - 'BillingAddress' => $BillingAddress, |
|
299 | - 'ShippingAddress' => $ShippingAddress, |
|
300 | - 'PaymentDetails' => $PaymentDetails, |
|
301 | - 'OrderItems' => $order_items, |
|
302 | - ); |
|
303 | - $this->_log_clean_request($PayPalRequestData, $payment); |
|
304 | - try { |
|
305 | - $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
306 | - // remove PCI-sensitive data so it doesn't get stored |
|
307 | - $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
308 | - if (isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
309 | - $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso'); |
|
310 | - } elseif (isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
311 | - $message = $PayPalResult['L_LONGMESSAGE0']; |
|
312 | - } else { |
|
313 | - $message = $PayPalResult['ACK']; |
|
314 | - } |
|
315 | - if (empty($PayPalResult['RAWRESPONSE'])) { |
|
316 | - $payment->set_status($this->_pay_model->failed_status()); |
|
317 | - $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
318 | - $payment->set_details($PayPalResult); |
|
319 | - } else { |
|
320 | - if ($this->_APICallSuccessful($PayPalResult)) { |
|
321 | - $payment->set_status($this->_pay_model->approved_status()); |
|
322 | - } else { |
|
323 | - $payment->set_status($this->_pay_model->declined_status()); |
|
324 | - } |
|
325 | - // make sure we interpret the AMT as a float, not an international string |
|
326 | - // (where periods are thousand separators) |
|
327 | - $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
328 | - $payment->set_gateway_response($message); |
|
329 | - $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
330 | - ? $PayPalResult['TRANSACTIONID'] |
|
331 | - : null); |
|
332 | - $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
333 | - ? $primary_registrant->reg_code() |
|
334 | - : ''; |
|
335 | - $payment->set_extra_accntng($primary_registration_code); |
|
336 | - $payment->set_details($PayPalResult); |
|
337 | - } |
|
338 | - } catch (Exception $e) { |
|
339 | - $payment->set_status($this->_pay_model->failed_status()); |
|
340 | - $payment->set_gateway_response($e->getMessage()); |
|
341 | - } |
|
342 | - // $payment->set_status( $this->_pay_model->declined_status() ); |
|
343 | - // $payment->set_gateway_response( '' ); |
|
344 | - return $payment; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
351 | - * |
|
352 | - * @param array $request |
|
353 | - * @param EEI_Payment $payment |
|
354 | - * @return void |
|
355 | - */ |
|
356 | - private function _log_clean_request($request, $payment) |
|
357 | - { |
|
358 | - $cleaned_request_data = $request; |
|
359 | - unset($cleaned_request_data['CCDetails']['acct']); |
|
360 | - unset($cleaned_request_data['CCDetails']['cvv2']); |
|
361 | - unset($cleaned_request_data['CCDetails']['expdate']); |
|
362 | - $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * Cleans the response, logs it, and returns it |
|
369 | - * |
|
370 | - * @param array $response |
|
371 | - * @param EEI_Payment $payment |
|
372 | - * @return array cleaned |
|
373 | - */ |
|
374 | - private function _log_clean_response($response, $payment) |
|
375 | - { |
|
376 | - unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
377 | - unset($response['REQUESTDATA']['ACCT']); |
|
378 | - unset($response['REQUESTDATA']['EXPDATE']); |
|
379 | - unset($response['REQUESTDATA']['CVV2']); |
|
380 | - unset($response['RAWREQUEST']); |
|
381 | - $this->log(array('Paypal Response' => $response), $payment); |
|
382 | - return $response; |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @param $DataArray |
|
389 | - * @return array |
|
390 | - */ |
|
391 | - private function prep_and_curl_request($DataArray) |
|
392 | - { |
|
393 | - // Create empty holders for each portion of the NVP string |
|
394 | - $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
395 | - $CCDetailsNVP = ''; |
|
396 | - $PayerInfoNVP = ''; |
|
397 | - $PayerNameNVP = ''; |
|
398 | - $BillingAddressNVP = ''; |
|
399 | - $ShippingAddressNVP = ''; |
|
400 | - $PaymentDetailsNVP = ''; |
|
401 | - $OrderItemsNVP = ''; |
|
402 | - $Secure3DNVP = ''; |
|
403 | - // DP Fields |
|
404 | - $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
405 | - foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
406 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
407 | - } |
|
408 | - // CC Details Fields |
|
409 | - $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
410 | - foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
411 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
412 | - } |
|
413 | - // PayerInfo Type Fields |
|
414 | - $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
415 | - foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
416 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
417 | - } |
|
418 | - // Payer Name Fields |
|
419 | - $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
420 | - foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
421 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
422 | - } |
|
423 | - // Address Fields (Billing) |
|
424 | - $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
425 | - foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
426 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
427 | - } |
|
428 | - // Payment Details Type Fields |
|
429 | - $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
430 | - foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
431 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
432 | - } |
|
433 | - // Payment Details Item Type Fields |
|
434 | - $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
435 | - $n = 0; |
|
436 | - foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
437 | - $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
438 | - foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
439 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
440 | - } |
|
441 | - $n++; |
|
442 | - } |
|
443 | - // Ship To Address Fields |
|
444 | - $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
445 | - foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
446 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
447 | - } |
|
448 | - // 3D Secure Fields |
|
449 | - $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
450 | - foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
451 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
452 | - } |
|
453 | - // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
454 | - $NVPRequest = 'USER=' |
|
455 | - . $this->_username |
|
456 | - . '&PWD=' |
|
457 | - . $this->_password |
|
458 | - . '&VERSION=64.0' |
|
459 | - . '&SIGNATURE=' |
|
460 | - . $this->_signature |
|
461 | - . $DPFieldsNVP |
|
462 | - . $CCDetailsNVP |
|
463 | - . $PayerInfoNVP |
|
464 | - . $PayerNameNVP |
|
465 | - . $BillingAddressNVP |
|
466 | - . $PaymentDetailsNVP |
|
467 | - . $OrderItemsNVP |
|
468 | - . $ShippingAddressNVP |
|
469 | - . $Secure3DNVP; |
|
470 | - $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
471 | - $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
472 | - $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
473 | - $Errors = $this->_GetErrors($NVPResponseArray); |
|
474 | - $NVPResponseArray['ERRORS'] = $Errors; |
|
475 | - $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
476 | - $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
477 | - $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
478 | - return $NVPResponseArray; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @param $Request |
|
485 | - * @return mixed |
|
486 | - */ |
|
487 | - private function _CURLRequest($Request) |
|
488 | - { |
|
489 | - $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
490 | - $curl = curl_init(); |
|
491 | - curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
492 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
493 | - curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
494 | - curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
495 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
496 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
497 | - curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
498 | - // execute the curl POST |
|
499 | - $Response = curl_exec($curl); |
|
500 | - curl_close($curl); |
|
501 | - return $Response; |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * @param $NVPString |
|
508 | - * @return array |
|
509 | - */ |
|
510 | - private function _NVPToArray($NVPString) |
|
511 | - { |
|
512 | - // prepare responses into array |
|
513 | - $proArray = array(); |
|
514 | - while (strlen($NVPString)) { |
|
515 | - // name |
|
516 | - $keypos = strpos($NVPString, '='); |
|
517 | - $keyval = substr($NVPString, 0, $keypos); |
|
518 | - // value |
|
519 | - $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
520 | - $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
521 | - // decoding the response |
|
522 | - $proArray[ $keyval ] = urldecode($valval); |
|
523 | - $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
524 | - } |
|
525 | - return $proArray; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * @param array $PayPalResult |
|
532 | - * @return bool |
|
533 | - */ |
|
534 | - private function _APICallSuccessful($PayPalResult) |
|
535 | - { |
|
536 | - $approved = false; |
|
537 | - // check main response message from PayPal |
|
538 | - if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
539 | - $ack = strtoupper($PayPalResult['ACK']); |
|
540 | - $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
541 | - } |
|
542 | - return $approved; |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * @param $DataArray |
|
549 | - * @return array |
|
550 | - */ |
|
551 | - private function _GetErrors($DataArray) |
|
552 | - { |
|
553 | - $Errors = array(); |
|
554 | - $n = 0; |
|
555 | - while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
556 | - $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
557 | - $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
558 | - ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
559 | - : ''; |
|
560 | - $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
561 | - ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
562 | - : ''; |
|
563 | - $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
564 | - ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
565 | - : ''; |
|
566 | - $CurrentItem = array( |
|
567 | - 'L_ERRORCODE' => $LErrorCode, |
|
568 | - 'L_SHORTMESSAGE' => $LShortMessage, |
|
569 | - 'L_LONGMESSAGE' => $LLongMessage, |
|
570 | - 'L_SEVERITYCODE' => $LSeverityCode, |
|
571 | - ); |
|
572 | - array_push($Errors, $CurrentItem); |
|
573 | - $n++; |
|
574 | - } |
|
575 | - return $Errors; |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * nothing to see here... move along.... |
|
582 | - * |
|
583 | - * @access protected |
|
584 | - * @param $Errors |
|
585 | - * @return string |
|
586 | - */ |
|
587 | - private function _DisplayErrors($Errors) |
|
588 | - { |
|
589 | - $error = ''; |
|
590 | - foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
591 | - $CurrentError = $Errors[ $ErrorVar ]; |
|
592 | - foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
593 | - $CurrentVarName = ''; |
|
594 | - if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
595 | - $CurrentVarName = 'Error Code'; |
|
596 | - } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
597 | - $CurrentVarName = 'Short Message'; |
|
598 | - } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
599 | - $CurrentVarName = 'Long Message'; |
|
600 | - } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
601 | - $CurrentVarName = 'Severity Code'; |
|
602 | - } |
|
603 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
604 | - } |
|
605 | - } |
|
606 | - return $error; |
|
607 | - } |
|
14 | + /** |
|
15 | + * @var $_paypal_api_username string |
|
16 | + */ |
|
17 | + protected $_username = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var $_password string |
|
21 | + */ |
|
22 | + protected $_password = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var $_signature string |
|
26 | + */ |
|
27 | + protected $_signature = null; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
31 | + */ |
|
32 | + protected $_credit_card_types = null; |
|
33 | + |
|
34 | + protected $_currencies_supported = array( |
|
35 | + 'USD', |
|
36 | + 'GBP', |
|
37 | + 'CAD', |
|
38 | + 'AUD', |
|
39 | + 'BRL', |
|
40 | + 'CHF', |
|
41 | + 'CZK', |
|
42 | + 'DKK', |
|
43 | + 'EUR', |
|
44 | + 'HKD', |
|
45 | + 'HUF', |
|
46 | + 'ILS', |
|
47 | + 'JPY', |
|
48 | + 'MXN', |
|
49 | + 'MYR', |
|
50 | + 'NOK', |
|
51 | + 'NZD', |
|
52 | + 'PHP', |
|
53 | + 'PLN', |
|
54 | + 'SEK', |
|
55 | + 'SGD', |
|
56 | + 'THB', |
|
57 | + 'TRY', |
|
58 | + 'TWD', |
|
59 | + 'RUB', |
|
60 | + 'INR', |
|
61 | + ); |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param EEI_Payment $payment |
|
67 | + * @param array $billing_info { |
|
68 | + * @type string $credit_card |
|
69 | + * @type string $credit_card_type |
|
70 | + * @type string $exp_month always 2 characters |
|
71 | + * @type string $exp_year always 4 characters |
|
72 | + * @type string $cvv |
|
73 | + * } |
|
74 | + * @see parent::do_direct_payment for more info |
|
75 | + * @return EE_Payment|EEI_Payment |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public function do_direct_payment($payment, $billing_info = null) |
|
79 | + { |
|
80 | + $transaction = $payment->transaction(); |
|
81 | + if (! $transaction instanceof EEI_Transaction) { |
|
82 | + throw new EE_Error( |
|
83 | + esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
84 | + ); |
|
85 | + } |
|
86 | + $primary_registrant = $transaction->primary_registration(); |
|
87 | + if (! $primary_registrant instanceof EEI_Registration) { |
|
88 | + throw new EE_Error( |
|
89 | + esc_html__( |
|
90 | + 'No primary registration on transaction while paying with PayPal Pro.', |
|
91 | + 'event_espresso' |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + $attendee = $primary_registrant->attendee(); |
|
96 | + if (! $attendee instanceof EEI_Attendee) { |
|
97 | + throw new EE_Error( |
|
98 | + esc_html__( |
|
99 | + 'No attendee on primary registration while paying with PayPal Pro.', |
|
100 | + 'event_espresso' |
|
101 | + ) |
|
102 | + ); |
|
103 | + } |
|
104 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
105 | + $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
106 | + // charge for the full amount. Show itemized list |
|
107 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
108 | + $item_num = 1; |
|
109 | + $total_line_item = $transaction->total_line_item(); |
|
110 | + $order_items = array(); |
|
111 | + foreach ($total_line_item->get_items() as $line_item) { |
|
112 | + // ignore line items with a quantity of 0 |
|
113 | + if ($line_item->quantity() == 0) { |
|
114 | + continue; |
|
115 | + } |
|
116 | + $item = array( |
|
117 | + // Item Name. 127 char max. |
|
118 | + 'l_name' => substr( |
|
119 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
120 | + 0, |
|
121 | + 127 |
|
122 | + ), |
|
123 | + // Item description. 127 char max. |
|
124 | + 'l_desc' => substr( |
|
125 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
126 | + 0, |
|
127 | + 127 |
|
128 | + ), |
|
129 | + // Cost of individual item. |
|
130 | + 'l_amt' => $line_item->unit_price(), |
|
131 | + // Item Number. 127 char max. |
|
132 | + 'l_number' => $item_num++, |
|
133 | + // Item quantity. Must be any positive integer. |
|
134 | + 'l_qty' => $line_item->quantity(), |
|
135 | + // Item's sales tax amount. |
|
136 | + 'l_taxamt' => '', |
|
137 | + // eBay auction number of item. |
|
138 | + 'l_ebayitemnumber' => '', |
|
139 | + // eBay transaction ID of purchased item. |
|
140 | + 'l_ebayitemauctiontxnid' => '', |
|
141 | + // eBay order ID for the item. |
|
142 | + 'l_ebayitemorderid' => '', |
|
143 | + ); |
|
144 | + // add to array of all items |
|
145 | + array_push($order_items, $item); |
|
146 | + } |
|
147 | + $item_amount = $total_line_item->get_items_total(); |
|
148 | + $tax_amount = $total_line_item->get_total_tax(); |
|
149 | + } else { |
|
150 | + $order_items = array(); |
|
151 | + $item_amount = $payment->amount(); |
|
152 | + $tax_amount = 0; |
|
153 | + array_push($order_items, array( |
|
154 | + // Item Name. 127 char max. |
|
155 | + 'l_name' => substr( |
|
156 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
157 | + 0, |
|
158 | + 127 |
|
159 | + ), |
|
160 | + // Item description. 127 char max. |
|
161 | + 'l_desc' => substr( |
|
162 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
163 | + 0, |
|
164 | + 127 |
|
165 | + ), |
|
166 | + // Cost of individual item. |
|
167 | + 'l_amt' => $payment->amount(), |
|
168 | + // Item Number. 127 char max. |
|
169 | + 'l_number' => 1, |
|
170 | + // Item quantity. Must be any positive integer. |
|
171 | + 'l_qty' => 1, |
|
172 | + )); |
|
173 | + } |
|
174 | + // Populate data arrays with order data. |
|
175 | + $DPFields = array( |
|
176 | + // How you want to obtain payment ? |
|
177 | + // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
178 | + // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
179 | + 'paymentaction' => 'Sale', |
|
180 | + // Required. IP address of the payer's browser. |
|
181 | + 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
182 | + // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
183 | + 'returnfmfdetails' => '1', |
|
184 | + ); |
|
185 | + $CCDetails = array( |
|
186 | + // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
187 | + // If Maestro or Solo, the currency code must be GBP. |
|
188 | + // In addition, either start date or issue number must be specified. |
|
189 | + 'creditcardtype' => $billing_info['credit_card_type'], |
|
190 | + // Required. Credit card number. No spaces or punctuation. |
|
191 | + 'acct' => $billing_info['credit_card'], |
|
192 | + // Required. Credit card expiration date. Format is MMYYYY |
|
193 | + 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
194 | + // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
195 | + 'cvv2' => $billing_info['cvv'], |
|
196 | + ); |
|
197 | + $PayerInfo = array( |
|
198 | + // Email address of payer. |
|
199 | + 'email' => $billing_info['email'], |
|
200 | + // Unique PayPal customer ID for payer. |
|
201 | + 'payerid' => '', |
|
202 | + // Status of payer. Values are verified or unverified |
|
203 | + 'payerstatus' => '', |
|
204 | + // Payer's business name. |
|
205 | + 'business' => '', |
|
206 | + ); |
|
207 | + $PayerName = array( |
|
208 | + // Payer's salutation. 20 char max. |
|
209 | + 'salutation' => '', |
|
210 | + // Payer's first name. 25 char max. |
|
211 | + 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
212 | + // Payer's middle name. 25 char max. |
|
213 | + 'middlename' => '', |
|
214 | + // Payer's last name. 25 char max. |
|
215 | + 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
216 | + // Payer's suffix. 12 char max. |
|
217 | + 'suffix' => '', |
|
218 | + ); |
|
219 | + $BillingAddress = array( |
|
220 | + // Required. First street address. |
|
221 | + 'street' => $billing_info['address'], |
|
222 | + // Second street address. |
|
223 | + 'street2' => $billing_info['address2'], |
|
224 | + // Required. Name of City. |
|
225 | + 'city' => $billing_info['city'], |
|
226 | + // Required. Name of State or Province. |
|
227 | + 'state' => substr($billing_info['state'], 0, 40), |
|
228 | + // Required. Country code. |
|
229 | + 'countrycode' => $billing_info['country'], |
|
230 | + // Required. Postal code of payer. |
|
231 | + 'zip' => $billing_info['zip'], |
|
232 | + ); |
|
233 | + // check if the registration info contains the needed fields for paypal pro |
|
234 | + // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
235 | + if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
236 | + $use_registration_address_info = true; |
|
237 | + } else { |
|
238 | + $use_registration_address_info = false; |
|
239 | + } |
|
240 | + // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
241 | + // If not, use the billing info again |
|
242 | + $ShippingAddress = array( |
|
243 | + 'shiptoname' => substr($use_registration_address_info |
|
244 | + ? $attendee->full_name() |
|
245 | + : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
246 | + 'shiptostreet' => substr($use_registration_address_info |
|
247 | + ? $attendee->address() |
|
248 | + : $billing_info['address'], 0, 100), |
|
249 | + 'shiptostreet2' => substr($use_registration_address_info |
|
250 | + ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
251 | + 'shiptocity' => substr($use_registration_address_info |
|
252 | + ? $attendee->city() |
|
253 | + : $billing_info['city'], 0, 40), |
|
254 | + 'state' => substr($use_registration_address_info |
|
255 | + ? $attendee->state_name() |
|
256 | + : $billing_info['state'], 0, 40), |
|
257 | + 'shiptocountry' => $use_registration_address_info |
|
258 | + ? $attendee->country_ID() |
|
259 | + : $billing_info['country'], |
|
260 | + 'shiptozip' => substr($use_registration_address_info |
|
261 | + ? $attendee->zip() |
|
262 | + : $billing_info['zip'], 0, 20), |
|
263 | + 'shiptophonenum' => substr($use_registration_address_info |
|
264 | + ? $attendee->phone() |
|
265 | + : $billing_info['phone'], 0, 20), |
|
266 | + ); |
|
267 | + $PaymentDetails = array( |
|
268 | + // Required. Total amount of order, including shipping, handling, and tax. |
|
269 | + 'amt' => $gateway_formatter->formatCurrency($payment->amount()), |
|
270 | + // Required. Three-letter currency code. Default is USD. |
|
271 | + 'currencycode' => $payment->currency_code(), |
|
272 | + // Required if you include itemized cart details. (L_AMTn, etc.) |
|
273 | + // Subtotal of items not including S&H, or tax. |
|
274 | + 'itemamt' => $gateway_formatter->formatCurrency($item_amount),// |
|
275 | + // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
276 | + 'shippingamt' => '', |
|
277 | + // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
278 | + 'handlingamt' => '', |
|
279 | + // Required if you specify itemized cart tax details. |
|
280 | + // Sum of tax for all items on the order. Total sales tax. |
|
281 | + 'taxamt' => $gateway_formatter->formatCurrency($tax_amount), |
|
282 | + // Description of the order the customer is purchasing. 127 char max. |
|
283 | + 'desc' => $order_description, |
|
284 | + // Free-form field for your own use. 256 char max. |
|
285 | + 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
286 | + // Your own invoice or tracking number |
|
287 | + 'invnum' => wp_generate_password(12, false),// $transaction->ID(), |
|
288 | + // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
289 | + 'notifyurl' => '', |
|
290 | + 'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this |
|
291 | + ); |
|
292 | + // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
293 | + $PayPalRequestData = array( |
|
294 | + 'DPFields' => $DPFields, |
|
295 | + 'CCDetails' => $CCDetails, |
|
296 | + 'PayerInfo' => $PayerInfo, |
|
297 | + 'PayerName' => $PayerName, |
|
298 | + 'BillingAddress' => $BillingAddress, |
|
299 | + 'ShippingAddress' => $ShippingAddress, |
|
300 | + 'PaymentDetails' => $PaymentDetails, |
|
301 | + 'OrderItems' => $order_items, |
|
302 | + ); |
|
303 | + $this->_log_clean_request($PayPalRequestData, $payment); |
|
304 | + try { |
|
305 | + $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
306 | + // remove PCI-sensitive data so it doesn't get stored |
|
307 | + $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
308 | + if (isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') { |
|
309 | + $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso'); |
|
310 | + } elseif (isset($PayPalResult['L_LONGMESSAGE0'])) { |
|
311 | + $message = $PayPalResult['L_LONGMESSAGE0']; |
|
312 | + } else { |
|
313 | + $message = $PayPalResult['ACK']; |
|
314 | + } |
|
315 | + if (empty($PayPalResult['RAWRESPONSE'])) { |
|
316 | + $payment->set_status($this->_pay_model->failed_status()); |
|
317 | + $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
318 | + $payment->set_details($PayPalResult); |
|
319 | + } else { |
|
320 | + if ($this->_APICallSuccessful($PayPalResult)) { |
|
321 | + $payment->set_status($this->_pay_model->approved_status()); |
|
322 | + } else { |
|
323 | + $payment->set_status($this->_pay_model->declined_status()); |
|
324 | + } |
|
325 | + // make sure we interpret the AMT as a float, not an international string |
|
326 | + // (where periods are thousand separators) |
|
327 | + $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
328 | + $payment->set_gateway_response($message); |
|
329 | + $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
330 | + ? $PayPalResult['TRANSACTIONID'] |
|
331 | + : null); |
|
332 | + $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
333 | + ? $primary_registrant->reg_code() |
|
334 | + : ''; |
|
335 | + $payment->set_extra_accntng($primary_registration_code); |
|
336 | + $payment->set_details($PayPalResult); |
|
337 | + } |
|
338 | + } catch (Exception $e) { |
|
339 | + $payment->set_status($this->_pay_model->failed_status()); |
|
340 | + $payment->set_gateway_response($e->getMessage()); |
|
341 | + } |
|
342 | + // $payment->set_status( $this->_pay_model->declined_status() ); |
|
343 | + // $payment->set_gateway_response( '' ); |
|
344 | + return $payment; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
351 | + * |
|
352 | + * @param array $request |
|
353 | + * @param EEI_Payment $payment |
|
354 | + * @return void |
|
355 | + */ |
|
356 | + private function _log_clean_request($request, $payment) |
|
357 | + { |
|
358 | + $cleaned_request_data = $request; |
|
359 | + unset($cleaned_request_data['CCDetails']['acct']); |
|
360 | + unset($cleaned_request_data['CCDetails']['cvv2']); |
|
361 | + unset($cleaned_request_data['CCDetails']['expdate']); |
|
362 | + $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * Cleans the response, logs it, and returns it |
|
369 | + * |
|
370 | + * @param array $response |
|
371 | + * @param EEI_Payment $payment |
|
372 | + * @return array cleaned |
|
373 | + */ |
|
374 | + private function _log_clean_response($response, $payment) |
|
375 | + { |
|
376 | + unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
377 | + unset($response['REQUESTDATA']['ACCT']); |
|
378 | + unset($response['REQUESTDATA']['EXPDATE']); |
|
379 | + unset($response['REQUESTDATA']['CVV2']); |
|
380 | + unset($response['RAWREQUEST']); |
|
381 | + $this->log(array('Paypal Response' => $response), $payment); |
|
382 | + return $response; |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @param $DataArray |
|
389 | + * @return array |
|
390 | + */ |
|
391 | + private function prep_and_curl_request($DataArray) |
|
392 | + { |
|
393 | + // Create empty holders for each portion of the NVP string |
|
394 | + $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
395 | + $CCDetailsNVP = ''; |
|
396 | + $PayerInfoNVP = ''; |
|
397 | + $PayerNameNVP = ''; |
|
398 | + $BillingAddressNVP = ''; |
|
399 | + $ShippingAddressNVP = ''; |
|
400 | + $PaymentDetailsNVP = ''; |
|
401 | + $OrderItemsNVP = ''; |
|
402 | + $Secure3DNVP = ''; |
|
403 | + // DP Fields |
|
404 | + $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
405 | + foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
406 | + $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
407 | + } |
|
408 | + // CC Details Fields |
|
409 | + $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
410 | + foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
411 | + $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
412 | + } |
|
413 | + // PayerInfo Type Fields |
|
414 | + $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
415 | + foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
416 | + $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
417 | + } |
|
418 | + // Payer Name Fields |
|
419 | + $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
420 | + foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
421 | + $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
422 | + } |
|
423 | + // Address Fields (Billing) |
|
424 | + $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
425 | + foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
426 | + $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
427 | + } |
|
428 | + // Payment Details Type Fields |
|
429 | + $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
430 | + foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
431 | + $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
432 | + } |
|
433 | + // Payment Details Item Type Fields |
|
434 | + $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
435 | + $n = 0; |
|
436 | + foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
437 | + $CurrentItem = $OrderItems[ $OrderItemsVar ]; |
|
438 | + foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
439 | + $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
440 | + } |
|
441 | + $n++; |
|
442 | + } |
|
443 | + // Ship To Address Fields |
|
444 | + $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
445 | + foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
446 | + $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
447 | + } |
|
448 | + // 3D Secure Fields |
|
449 | + $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
450 | + foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
451 | + $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
452 | + } |
|
453 | + // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
454 | + $NVPRequest = 'USER=' |
|
455 | + . $this->_username |
|
456 | + . '&PWD=' |
|
457 | + . $this->_password |
|
458 | + . '&VERSION=64.0' |
|
459 | + . '&SIGNATURE=' |
|
460 | + . $this->_signature |
|
461 | + . $DPFieldsNVP |
|
462 | + . $CCDetailsNVP |
|
463 | + . $PayerInfoNVP |
|
464 | + . $PayerNameNVP |
|
465 | + . $BillingAddressNVP |
|
466 | + . $PaymentDetailsNVP |
|
467 | + . $OrderItemsNVP |
|
468 | + . $ShippingAddressNVP |
|
469 | + . $Secure3DNVP; |
|
470 | + $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
471 | + $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
472 | + $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
473 | + $Errors = $this->_GetErrors($NVPResponseArray); |
|
474 | + $NVPResponseArray['ERRORS'] = $Errors; |
|
475 | + $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
476 | + $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
477 | + $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
478 | + return $NVPResponseArray; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @param $Request |
|
485 | + * @return mixed |
|
486 | + */ |
|
487 | + private function _CURLRequest($Request) |
|
488 | + { |
|
489 | + $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
490 | + $curl = curl_init(); |
|
491 | + curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
492 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
493 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
494 | + curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
495 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
496 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
497 | + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
498 | + // execute the curl POST |
|
499 | + $Response = curl_exec($curl); |
|
500 | + curl_close($curl); |
|
501 | + return $Response; |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * @param $NVPString |
|
508 | + * @return array |
|
509 | + */ |
|
510 | + private function _NVPToArray($NVPString) |
|
511 | + { |
|
512 | + // prepare responses into array |
|
513 | + $proArray = array(); |
|
514 | + while (strlen($NVPString)) { |
|
515 | + // name |
|
516 | + $keypos = strpos($NVPString, '='); |
|
517 | + $keyval = substr($NVPString, 0, $keypos); |
|
518 | + // value |
|
519 | + $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
520 | + $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
521 | + // decoding the response |
|
522 | + $proArray[ $keyval ] = urldecode($valval); |
|
523 | + $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
524 | + } |
|
525 | + return $proArray; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * @param array $PayPalResult |
|
532 | + * @return bool |
|
533 | + */ |
|
534 | + private function _APICallSuccessful($PayPalResult) |
|
535 | + { |
|
536 | + $approved = false; |
|
537 | + // check main response message from PayPal |
|
538 | + if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
539 | + $ack = strtoupper($PayPalResult['ACK']); |
|
540 | + $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
541 | + } |
|
542 | + return $approved; |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * @param $DataArray |
|
549 | + * @return array |
|
550 | + */ |
|
551 | + private function _GetErrors($DataArray) |
|
552 | + { |
|
553 | + $Errors = array(); |
|
554 | + $n = 0; |
|
555 | + while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) { |
|
556 | + $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : ''; |
|
557 | + $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ]) |
|
558 | + ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ] |
|
559 | + : ''; |
|
560 | + $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ]) |
|
561 | + ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ] |
|
562 | + : ''; |
|
563 | + $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ]) |
|
564 | + ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ] |
|
565 | + : ''; |
|
566 | + $CurrentItem = array( |
|
567 | + 'L_ERRORCODE' => $LErrorCode, |
|
568 | + 'L_SHORTMESSAGE' => $LShortMessage, |
|
569 | + 'L_LONGMESSAGE' => $LLongMessage, |
|
570 | + 'L_SEVERITYCODE' => $LSeverityCode, |
|
571 | + ); |
|
572 | + array_push($Errors, $CurrentItem); |
|
573 | + $n++; |
|
574 | + } |
|
575 | + return $Errors; |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * nothing to see here... move along.... |
|
582 | + * |
|
583 | + * @access protected |
|
584 | + * @param $Errors |
|
585 | + * @return string |
|
586 | + */ |
|
587 | + private function _DisplayErrors($Errors) |
|
588 | + { |
|
589 | + $error = ''; |
|
590 | + foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
591 | + $CurrentError = $Errors[ $ErrorVar ]; |
|
592 | + foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
593 | + $CurrentVarName = ''; |
|
594 | + if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
595 | + $CurrentVarName = 'Error Code'; |
|
596 | + } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
597 | + $CurrentVarName = 'Short Message'; |
|
598 | + } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
599 | + $CurrentVarName = 'Long Message'; |
|
600 | + } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
601 | + $CurrentVarName = 'Severity Code'; |
|
602 | + } |
|
603 | + $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
604 | + } |
|
605 | + } |
|
606 | + return $error; |
|
607 | + } |
|
608 | 608 | } |
@@ -14,150 +14,150 @@ |
||
14 | 14 | class EE_PMT_Paypal_Pro extends EE_PMT_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param EE_Payment_Method $pm_instance |
|
19 | - * @return EE_PMT_Paypal_Pro |
|
20 | - */ |
|
21 | - public function __construct($pm_instance = null) |
|
22 | - { |
|
23 | - require_once($this->file_folder().'EEG_Paypal_Pro.gateway.php'); |
|
24 | - $this->_gateway = new EEG_Paypal_Pro(); |
|
25 | - $this->_pretty_name = __("Paypal Pro", 'event_espresso'); |
|
26 | - $this->_default_description = __('Please provide the following billing information.', 'event_espresso'); |
|
27 | - $this->_requires_https = true; |
|
28 | - parent::__construct($pm_instance); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Gets the form for all the settings related to this payment method type |
|
34 | - * @return EE_Payment_Method_Form |
|
35 | - * @throws InvalidArgumentException |
|
36 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
37 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
38 | - */ |
|
39 | - public function generate_new_settings_form() |
|
40 | - { |
|
41 | - return new PayPalProSettingsForm(array(), $this->get_help_tab_link()); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Creates the billing form for this payment method type |
|
47 | - * @param \EE_Transaction $transaction |
|
48 | - * @throws \EE_Error |
|
49 | - * @return EE_Billing_Info_Form |
|
50 | - */ |
|
51 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
52 | - { |
|
53 | - $allowed_types = $this->_pm_instance->get_extra_meta('credit_card_types', true); |
|
54 | - // if allowed types is a string or empty array or null... |
|
55 | - if (empty($allowed_types)) { |
|
56 | - $allowed_types = array(); |
|
57 | - } |
|
58 | - |
|
59 | - $billing_form = new EE_Billing_Attendee_Info_Form( |
|
60 | - $this->_pm_instance, |
|
61 | - array( |
|
62 | - 'name'=> 'Paypal_Pro_Billing_Form', |
|
63 | - // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
|
64 | - 'subsections'=>array( |
|
65 | - 'credit_card'=>new EE_Credit_Card_Input( |
|
66 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
67 | - ), |
|
68 | - 'credit_card_type'=>new EE_Select_Input( |
|
69 | - // the options are set dynamically |
|
70 | - array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
|
71 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
72 | - ), |
|
73 | - 'exp_month'=>new EE_Credit_Card_Month_Input( |
|
74 | - true, |
|
75 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
76 | - ), |
|
77 | - 'exp_year'=>new EE_Credit_Card_Year_Input( |
|
78 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
79 | - ), |
|
80 | - 'cvv'=>new EE_CVV_Input( |
|
81 | - array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
82 | - ), |
|
83 | - ) |
|
84 | - ) |
|
85 | - ); |
|
86 | - return $this->apply_billing_form_debug_settings($billing_form); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * apply_billing_form_debug_settings |
|
93 | - * applies debug data to the form |
|
94 | - * |
|
95 | - * @param \EE_Billing_Info_Form $billing_form |
|
96 | - * @return \EE_Billing_Info_Form |
|
97 | - */ |
|
98 | - public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
99 | - { |
|
100 | - if ($this->_pm_instance->debug_mode()) { |
|
101 | - $billing_form->add_subsections( |
|
102 | - array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
103 | - 'credit_card' |
|
104 | - ); |
|
105 | - $billing_form->add_subsections( |
|
106 | - array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
107 | - 'first_name' |
|
108 | - ); |
|
109 | - $billing_form->get_input('credit_card_type')->set_default('Visa'); |
|
110 | - $billing_form->get_input('exp_year')->set_default(2018); |
|
111 | - $billing_form->get_input('cvv')->set_default('115'); |
|
112 | - } |
|
113 | - return $billing_form; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Returns an array of all the payment cards possibly supported by paypal pro. |
|
120 | - * Keys are their values, values are their pretty names. |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - public static function card_types_supported() |
|
124 | - { |
|
125 | - return array( |
|
126 | - 'Visa'=> __("Visa", 'event_espresso'), |
|
127 | - 'MasterCard'=> __("MasterCard", 'event_espresso'), |
|
128 | - 'Amex'=> __("American Express", 'event_espresso'), |
|
129 | - 'Discover'=> __("Discover", 'event_espresso') |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Adds the help tab |
|
137 | - * @see EE_PMT_Base::help_tabs_config() |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - public function help_tabs_config() |
|
141 | - { |
|
142 | - return array( |
|
143 | - $this->get_help_tab_name() => array( |
|
144 | - 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
145 | - 'filename' => 'payment_methods_overview_paypalpro' |
|
146 | - ), |
|
147 | - ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Overrides parent's _get_billing_values_from_form because we want to |
|
152 | - * get the country's 2-character ISO code, not the name like most gateways |
|
153 | - * @param EE_Billing_Info_Form $billing_form |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - protected function _get_billing_values_from_form($billing_form) |
|
157 | - { |
|
158 | - $billing_values = parent::_get_billing_values_from_form($billing_form); |
|
159 | - $billing_values['country'] = $billing_form->get_input_value('country'); |
|
160 | - $billing_values['credit_card_type'] = $billing_form->get_input_value('credit_card_type'); |
|
161 | - return $billing_values; |
|
162 | - } |
|
17 | + /** |
|
18 | + * @param EE_Payment_Method $pm_instance |
|
19 | + * @return EE_PMT_Paypal_Pro |
|
20 | + */ |
|
21 | + public function __construct($pm_instance = null) |
|
22 | + { |
|
23 | + require_once($this->file_folder().'EEG_Paypal_Pro.gateway.php'); |
|
24 | + $this->_gateway = new EEG_Paypal_Pro(); |
|
25 | + $this->_pretty_name = __("Paypal Pro", 'event_espresso'); |
|
26 | + $this->_default_description = __('Please provide the following billing information.', 'event_espresso'); |
|
27 | + $this->_requires_https = true; |
|
28 | + parent::__construct($pm_instance); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Gets the form for all the settings related to this payment method type |
|
34 | + * @return EE_Payment_Method_Form |
|
35 | + * @throws InvalidArgumentException |
|
36 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
37 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
38 | + */ |
|
39 | + public function generate_new_settings_form() |
|
40 | + { |
|
41 | + return new PayPalProSettingsForm(array(), $this->get_help_tab_link()); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Creates the billing form for this payment method type |
|
47 | + * @param \EE_Transaction $transaction |
|
48 | + * @throws \EE_Error |
|
49 | + * @return EE_Billing_Info_Form |
|
50 | + */ |
|
51 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
52 | + { |
|
53 | + $allowed_types = $this->_pm_instance->get_extra_meta('credit_card_types', true); |
|
54 | + // if allowed types is a string or empty array or null... |
|
55 | + if (empty($allowed_types)) { |
|
56 | + $allowed_types = array(); |
|
57 | + } |
|
58 | + |
|
59 | + $billing_form = new EE_Billing_Attendee_Info_Form( |
|
60 | + $this->_pm_instance, |
|
61 | + array( |
|
62 | + 'name'=> 'Paypal_Pro_Billing_Form', |
|
63 | + // 'html_id'=> 'ee-Paypal_Pro-billing-form', |
|
64 | + 'subsections'=>array( |
|
65 | + 'credit_card'=>new EE_Credit_Card_Input( |
|
66 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Number', 'event_espresso')) |
|
67 | + ), |
|
68 | + 'credit_card_type'=>new EE_Select_Input( |
|
69 | + // the options are set dynamically |
|
70 | + array_intersect_key(EE_PMT_Paypal_Pro::card_types_supported(), array_flip($allowed_types)), |
|
71 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Card Type', 'event_espresso')) |
|
72 | + ), |
|
73 | + 'exp_month'=>new EE_Credit_Card_Month_Input( |
|
74 | + true, |
|
75 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Month', 'event_espresso') ) |
|
76 | + ), |
|
77 | + 'exp_year'=>new EE_Credit_Card_Year_Input( |
|
78 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('Expiry Year', 'event_espresso') ) |
|
79 | + ), |
|
80 | + 'cvv'=>new EE_CVV_Input( |
|
81 | + array( 'required'=>true, 'html_class' => 'ee-billing-qstn', 'html_label_text' => __('CVV', 'event_espresso') ) |
|
82 | + ), |
|
83 | + ) |
|
84 | + ) |
|
85 | + ); |
|
86 | + return $this->apply_billing_form_debug_settings($billing_form); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * apply_billing_form_debug_settings |
|
93 | + * applies debug data to the form |
|
94 | + * |
|
95 | + * @param \EE_Billing_Info_Form $billing_form |
|
96 | + * @return \EE_Billing_Info_Form |
|
97 | + */ |
|
98 | + public function apply_billing_form_debug_settings(EE_Billing_Info_Form $billing_form) |
|
99 | + { |
|
100 | + if ($this->_pm_instance->debug_mode()) { |
|
101 | + $billing_form->add_subsections( |
|
102 | + array( 'fyi_about_autofill' => $billing_form->payment_fields_autofilled_notice_html() ), |
|
103 | + 'credit_card' |
|
104 | + ); |
|
105 | + $billing_form->add_subsections( |
|
106 | + array( 'debug_content' => new EE_Form_Section_HTML_From_Template(dirname(__FILE__).DS.'templates'.DS.'paypal_pro_debug_info.template.php')), |
|
107 | + 'first_name' |
|
108 | + ); |
|
109 | + $billing_form->get_input('credit_card_type')->set_default('Visa'); |
|
110 | + $billing_form->get_input('exp_year')->set_default(2018); |
|
111 | + $billing_form->get_input('cvv')->set_default('115'); |
|
112 | + } |
|
113 | + return $billing_form; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Returns an array of all the payment cards possibly supported by paypal pro. |
|
120 | + * Keys are their values, values are their pretty names. |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + public static function card_types_supported() |
|
124 | + { |
|
125 | + return array( |
|
126 | + 'Visa'=> __("Visa", 'event_espresso'), |
|
127 | + 'MasterCard'=> __("MasterCard", 'event_espresso'), |
|
128 | + 'Amex'=> __("American Express", 'event_espresso'), |
|
129 | + 'Discover'=> __("Discover", 'event_espresso') |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Adds the help tab |
|
137 | + * @see EE_PMT_Base::help_tabs_config() |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + public function help_tabs_config() |
|
141 | + { |
|
142 | + return array( |
|
143 | + $this->get_help_tab_name() => array( |
|
144 | + 'title' => __('PayPal Pro Settings', 'event_espresso'), |
|
145 | + 'filename' => 'payment_methods_overview_paypalpro' |
|
146 | + ), |
|
147 | + ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Overrides parent's _get_billing_values_from_form because we want to |
|
152 | + * get the country's 2-character ISO code, not the name like most gateways |
|
153 | + * @param EE_Billing_Info_Form $billing_form |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + protected function _get_billing_values_from_form($billing_form) |
|
157 | + { |
|
158 | + $billing_values = parent::_get_billing_values_from_form($billing_form); |
|
159 | + $billing_values['country'] = $billing_form->get_input_value('country'); |
|
160 | + $billing_values['credit_card_type'] = $billing_form->get_input_value('credit_card_type'); |
|
161 | + return $billing_values; |
|
162 | + } |
|
163 | 163 | } |
@@ -19,201 +19,201 @@ |
||
19 | 19 | */ |
20 | 20 | class PayPalSettingsForm extends EE_Payment_Method_Form |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string of HTML being the help tab link |
|
24 | - */ |
|
25 | - protected $helpTabLink; |
|
22 | + /** |
|
23 | + * @var string of HTML being the help tab link |
|
24 | + */ |
|
25 | + protected $helpTabLink; |
|
26 | 26 | |
27 | - public function __construct(array $options_array = array(), $help_tab_link = '') |
|
28 | - { |
|
29 | - $this->helpTabLink = $help_tab_link; |
|
30 | - $options_array = array_replace_recursive( |
|
31 | - array( |
|
32 | - 'extra_meta_inputs' => array( |
|
33 | - 'api_username' => new EE_Text_Input( |
|
34 | - array( |
|
35 | - 'html_label_text' => sprintf( |
|
36 | - // translators: %s link to help doc |
|
37 | - esc_html__('API Username %s', 'event_espresso'), |
|
38 | - $help_tab_link |
|
39 | - ), |
|
40 | - 'required' => true, |
|
41 | - ) |
|
42 | - ), |
|
43 | - 'api_password' => new EE_Text_Input( |
|
44 | - array( |
|
45 | - 'html_label_text' => sprintf( |
|
46 | - // translators: %s link to help doc |
|
47 | - esc_html__('API Password %s', 'event_espresso'), |
|
48 | - $help_tab_link |
|
49 | - ), |
|
50 | - 'required' => true, |
|
51 | - ) |
|
52 | - ), |
|
53 | - 'api_signature' => new EE_Text_Input( |
|
54 | - array( |
|
55 | - 'html_label_text' => sprintf( |
|
56 | - // translators: %s link to help doc |
|
57 | - esc_html__('API Signature %s', 'event_espresso'), |
|
58 | - $help_tab_link |
|
59 | - ), |
|
60 | - 'required' => true, |
|
61 | - ) |
|
62 | - ), |
|
63 | - ) |
|
64 | - ), |
|
65 | - $options_array |
|
66 | - ); |
|
67 | - parent::__construct($options_array); |
|
68 | - } |
|
27 | + public function __construct(array $options_array = array(), $help_tab_link = '') |
|
28 | + { |
|
29 | + $this->helpTabLink = $help_tab_link; |
|
30 | + $options_array = array_replace_recursive( |
|
31 | + array( |
|
32 | + 'extra_meta_inputs' => array( |
|
33 | + 'api_username' => new EE_Text_Input( |
|
34 | + array( |
|
35 | + 'html_label_text' => sprintf( |
|
36 | + // translators: %s link to help doc |
|
37 | + esc_html__('API Username %s', 'event_espresso'), |
|
38 | + $help_tab_link |
|
39 | + ), |
|
40 | + 'required' => true, |
|
41 | + ) |
|
42 | + ), |
|
43 | + 'api_password' => new EE_Text_Input( |
|
44 | + array( |
|
45 | + 'html_label_text' => sprintf( |
|
46 | + // translators: %s link to help doc |
|
47 | + esc_html__('API Password %s', 'event_espresso'), |
|
48 | + $help_tab_link |
|
49 | + ), |
|
50 | + 'required' => true, |
|
51 | + ) |
|
52 | + ), |
|
53 | + 'api_signature' => new EE_Text_Input( |
|
54 | + array( |
|
55 | + 'html_label_text' => sprintf( |
|
56 | + // translators: %s link to help doc |
|
57 | + esc_html__('API Signature %s', 'event_espresso'), |
|
58 | + $help_tab_link |
|
59 | + ), |
|
60 | + 'required' => true, |
|
61 | + ) |
|
62 | + ), |
|
63 | + ) |
|
64 | + ), |
|
65 | + $options_array |
|
66 | + ); |
|
67 | + parent::__construct($options_array); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Tests the the PayPal API credentials work ok |
|
72 | - * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string |
|
73 | - * @throws EE_Error |
|
74 | - */ |
|
75 | - protected function checkForCredentialsErrors() |
|
76 | - { |
|
77 | - $request_params = array( |
|
78 | - 'METHOD' => 'GetBalance', |
|
79 | - 'VERSION' => '204.0', |
|
80 | - 'USER' => urlencode($this->get_input_value('api_username')), |
|
81 | - 'PWD' => urlencode($this->get_input_value('api_password')), |
|
82 | - 'SIGNATURE' => urlencode($this->get_input_value('api_signature')), |
|
83 | - ); |
|
84 | - $gateway_url = $this->get_input_value('PMD_debug_mode') |
|
85 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
86 | - : 'https://api-3t.paypal.com/nvp'; |
|
87 | - // Request Customer Details. |
|
88 | - $response = wp_remote_post( |
|
89 | - $gateway_url, |
|
90 | - array( |
|
91 | - 'method' => 'POST', |
|
92 | - 'timeout' => 45, |
|
93 | - 'httpversion' => '1.1', |
|
94 | - 'cookies' => array(), |
|
95 | - 'headers' => array(), |
|
96 | - 'body' => http_build_query($request_params, '', '&'), |
|
97 | - ) |
|
98 | - ); |
|
99 | - if (is_wp_error($response) || empty($response['body'])) { |
|
100 | - // If we got here then there was an error in this request. |
|
101 | - // maybe is turned off. We don't know the credentials are invalid |
|
102 | - EE_Error::add_error( |
|
103 | - sprintf( |
|
104 | - // translators: %1$s Error message received from PayPal |
|
105 | - esc_html__( |
|
106 | - // @codingStandardsIgnoreStart |
|
107 | - 'Your PayPal credentials could not be verified. The following error occurred while communicating with PayPal: %1$s', |
|
108 | - // @codingStandardsIgnoreEnd |
|
109 | - 'event_espresso' |
|
110 | - ), |
|
111 | - $response->get_error_message() |
|
112 | - ), |
|
113 | - __FILE__, |
|
114 | - __FUNCTION__, |
|
115 | - __LINE__ |
|
116 | - ); |
|
117 | - } |
|
118 | - $response_args = array(); |
|
119 | - parse_str(urldecode($response['body']), $response_args); |
|
70 | + /** |
|
71 | + * Tests the the PayPal API credentials work ok |
|
72 | + * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string |
|
73 | + * @throws EE_Error |
|
74 | + */ |
|
75 | + protected function checkForCredentialsErrors() |
|
76 | + { |
|
77 | + $request_params = array( |
|
78 | + 'METHOD' => 'GetBalance', |
|
79 | + 'VERSION' => '204.0', |
|
80 | + 'USER' => urlencode($this->get_input_value('api_username')), |
|
81 | + 'PWD' => urlencode($this->get_input_value('api_password')), |
|
82 | + 'SIGNATURE' => urlencode($this->get_input_value('api_signature')), |
|
83 | + ); |
|
84 | + $gateway_url = $this->get_input_value('PMD_debug_mode') |
|
85 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
86 | + : 'https://api-3t.paypal.com/nvp'; |
|
87 | + // Request Customer Details. |
|
88 | + $response = wp_remote_post( |
|
89 | + $gateway_url, |
|
90 | + array( |
|
91 | + 'method' => 'POST', |
|
92 | + 'timeout' => 45, |
|
93 | + 'httpversion' => '1.1', |
|
94 | + 'cookies' => array(), |
|
95 | + 'headers' => array(), |
|
96 | + 'body' => http_build_query($request_params, '', '&'), |
|
97 | + ) |
|
98 | + ); |
|
99 | + if (is_wp_error($response) || empty($response['body'])) { |
|
100 | + // If we got here then there was an error in this request. |
|
101 | + // maybe is turned off. We don't know the credentials are invalid |
|
102 | + EE_Error::add_error( |
|
103 | + sprintf( |
|
104 | + // translators: %1$s Error message received from PayPal |
|
105 | + esc_html__( |
|
106 | + // @codingStandardsIgnoreStart |
|
107 | + 'Your PayPal credentials could not be verified. The following error occurred while communicating with PayPal: %1$s', |
|
108 | + // @codingStandardsIgnoreEnd |
|
109 | + 'event_espresso' |
|
110 | + ), |
|
111 | + $response->get_error_message() |
|
112 | + ), |
|
113 | + __FILE__, |
|
114 | + __FUNCTION__, |
|
115 | + __LINE__ |
|
116 | + ); |
|
117 | + } |
|
118 | + $response_args = array(); |
|
119 | + parse_str(urldecode($response['body']), $response_args); |
|
120 | 120 | |
121 | - if (empty($response_args['ACK'])) { |
|
122 | - EE_Error::add_error( |
|
123 | - esc_html__( |
|
124 | - 'Your PayPal credentials could not be verified. Part of their response was missing.', |
|
125 | - 'event_espresso' |
|
126 | - ), |
|
127 | - __FILE__, |
|
128 | - __FUNCTION__, |
|
129 | - __LINE__ |
|
130 | - ); |
|
131 | - } |
|
132 | - if (in_array( |
|
133 | - $response_args['ACK'], |
|
134 | - array( |
|
135 | - 'Success', |
|
136 | - 'SuccessWithWarning' |
|
137 | - ), |
|
138 | - true |
|
139 | - ) |
|
140 | - ) { |
|
141 | - return ''; |
|
142 | - } else { |
|
143 | - return sprintf( |
|
144 | - // translators: %1$s: PayPal response message, %2$s: PayPal response code |
|
145 | - esc_html__( |
|
146 | - // @codingStandardsIgnoreStart |
|
147 | - 'Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', |
|
148 | - // @codingStandardsIgnoreEnd |
|
149 | - 'event_espresso' |
|
150 | - ), |
|
151 | - isset($response_args['L_LONGMESSAGE0']) |
|
152 | - ? $response_args['L_LONGMESSAGE0'] |
|
153 | - : esc_html__('No error message received from PayPal', 'event_espresso'), |
|
154 | - isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0 |
|
155 | - ); |
|
156 | - } |
|
157 | - } |
|
121 | + if (empty($response_args['ACK'])) { |
|
122 | + EE_Error::add_error( |
|
123 | + esc_html__( |
|
124 | + 'Your PayPal credentials could not be verified. Part of their response was missing.', |
|
125 | + 'event_espresso' |
|
126 | + ), |
|
127 | + __FILE__, |
|
128 | + __FUNCTION__, |
|
129 | + __LINE__ |
|
130 | + ); |
|
131 | + } |
|
132 | + if (in_array( |
|
133 | + $response_args['ACK'], |
|
134 | + array( |
|
135 | + 'Success', |
|
136 | + 'SuccessWithWarning' |
|
137 | + ), |
|
138 | + true |
|
139 | + ) |
|
140 | + ) { |
|
141 | + return ''; |
|
142 | + } else { |
|
143 | + return sprintf( |
|
144 | + // translators: %1$s: PayPal response message, %2$s: PayPal response code |
|
145 | + esc_html__( |
|
146 | + // @codingStandardsIgnoreStart |
|
147 | + 'Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', |
|
148 | + // @codingStandardsIgnoreEnd |
|
149 | + 'event_espresso' |
|
150 | + ), |
|
151 | + isset($response_args['L_LONGMESSAGE0']) |
|
152 | + ? $response_args['L_LONGMESSAGE0'] |
|
153 | + : esc_html__('No error message received from PayPal', 'event_espresso'), |
|
154 | + isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0 |
|
155 | + ); |
|
156 | + } |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Gets the HTML to show the link to the help tab |
|
161 | - * @return string |
|
162 | - */ |
|
163 | - protected function helpTabLink() |
|
164 | - { |
|
165 | - return $this->helpTabLink; |
|
166 | - } |
|
159 | + /** |
|
160 | + * Gets the HTML to show the link to the help tab |
|
161 | + * @return string |
|
162 | + */ |
|
163 | + protected function helpTabLink() |
|
164 | + { |
|
165 | + return $this->helpTabLink; |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * Does the normal validation, but also verifies the PayPal API credentials work. |
|
170 | - * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more |
|
171 | - * tips) on each of the inputs that could be the cause of the problem. |
|
172 | - * @throws EE_Error |
|
173 | - */ |
|
174 | - public function _validate() |
|
175 | - { |
|
176 | - parent::_validate(); |
|
177 | - $credentials_message = $this->checkForCredentialsErrors(); |
|
178 | - if ($credentials_message !== '') { |
|
179 | - $this->add_validation_error($credentials_message); |
|
180 | - $this->get_input('PMD_debug_mode')->add_validation_error( |
|
181 | - esc_html__( |
|
182 | - // @codingStandardsIgnoreStart |
|
183 | - 'If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', |
|
184 | - // @codingStandardsIgnoreEnd |
|
185 | - 'event_espresso' |
|
186 | - ) |
|
187 | - ); |
|
188 | - $this->get_input('api_username')->add_validation_error( |
|
189 | - sprintf( |
|
190 | - // translators: $1$s HTML for a link to the help tab |
|
191 | - esc_html__( |
|
192 | - 'Are you sure this is your API username, not your login username? %1$s', |
|
193 | - 'event_espresso' |
|
194 | - ), |
|
195 | - $this->helpTabLink() |
|
196 | - ) |
|
197 | - ); |
|
198 | - $this->get_input('api_password')->add_validation_error( |
|
199 | - sprintf( |
|
200 | - // translators: $1$s HTML for a link to the help tab |
|
201 | - esc_html__( |
|
202 | - 'Are you sure this is your API password, not your login password? %1$s', |
|
203 | - 'event_espresso' |
|
204 | - ), |
|
205 | - $this->helpTabLink() |
|
206 | - ) |
|
207 | - ); |
|
208 | - $this->get_input('api_signature')->add_validation_error( |
|
209 | - sprintf( |
|
210 | - // translators: $1$s HTML for a link to the help tab |
|
211 | - esc_html__('Please verify your API signature is correct. %1$s', 'event_espresso'), |
|
212 | - $this->helpTabLink() |
|
213 | - ) |
|
214 | - ); |
|
215 | - } |
|
216 | - } |
|
168 | + /** |
|
169 | + * Does the normal validation, but also verifies the PayPal API credentials work. |
|
170 | + * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more |
|
171 | + * tips) on each of the inputs that could be the cause of the problem. |
|
172 | + * @throws EE_Error |
|
173 | + */ |
|
174 | + public function _validate() |
|
175 | + { |
|
176 | + parent::_validate(); |
|
177 | + $credentials_message = $this->checkForCredentialsErrors(); |
|
178 | + if ($credentials_message !== '') { |
|
179 | + $this->add_validation_error($credentials_message); |
|
180 | + $this->get_input('PMD_debug_mode')->add_validation_error( |
|
181 | + esc_html__( |
|
182 | + // @codingStandardsIgnoreStart |
|
183 | + 'If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', |
|
184 | + // @codingStandardsIgnoreEnd |
|
185 | + 'event_espresso' |
|
186 | + ) |
|
187 | + ); |
|
188 | + $this->get_input('api_username')->add_validation_error( |
|
189 | + sprintf( |
|
190 | + // translators: $1$s HTML for a link to the help tab |
|
191 | + esc_html__( |
|
192 | + 'Are you sure this is your API username, not your login username? %1$s', |
|
193 | + 'event_espresso' |
|
194 | + ), |
|
195 | + $this->helpTabLink() |
|
196 | + ) |
|
197 | + ); |
|
198 | + $this->get_input('api_password')->add_validation_error( |
|
199 | + sprintf( |
|
200 | + // translators: $1$s HTML for a link to the help tab |
|
201 | + esc_html__( |
|
202 | + 'Are you sure this is your API password, not your login password? %1$s', |
|
203 | + 'event_espresso' |
|
204 | + ), |
|
205 | + $this->helpTabLink() |
|
206 | + ) |
|
207 | + ); |
|
208 | + $this->get_input('api_signature')->add_validation_error( |
|
209 | + sprintf( |
|
210 | + // translators: $1$s HTML for a link to the help tab |
|
211 | + esc_html__('Please verify your API signature is correct. %1$s', 'event_espresso'), |
|
212 | + $this->helpTabLink() |
|
213 | + ) |
|
214 | + ); |
|
215 | + } |
|
216 | + } |
|
217 | 217 | } |
218 | 218 | // End of file PayPalSettingsForm.php |
219 | 219 | // Location: ${NAMESPACE}/PayPalSettingsForm.php |
@@ -17,30 +17,30 @@ |
||
17 | 17 | */ |
18 | 18 | class PayPalProSettingsForm extends PayPalSettingsForm |
19 | 19 | { |
20 | - /** |
|
21 | - * SettingsForm constructor. |
|
22 | - * |
|
23 | - * @param array $options_array |
|
24 | - * @param string $help_tab_link |
|
25 | - */ |
|
26 | - public function __construct(array $options_array = array(), $help_tab_link = '') |
|
27 | - { |
|
28 | - $options_array = array_replace_recursive( |
|
29 | - array( |
|
30 | - 'extra_meta_inputs' => array( |
|
31 | - 'credit_card_types' => new EE_Checkbox_Multi_Input( |
|
32 | - EE_PMT_Paypal_Pro::card_types_supported(), |
|
33 | - array( |
|
34 | - 'html_label_text' => __('Card Types Supported', 'event_espresso'), |
|
35 | - 'required' => true |
|
36 | - ) |
|
37 | - ), |
|
38 | - ) |
|
39 | - ), |
|
40 | - $options_array |
|
41 | - ); |
|
42 | - parent::__construct($options_array, $help_tab_link); |
|
43 | - } |
|
20 | + /** |
|
21 | + * SettingsForm constructor. |
|
22 | + * |
|
23 | + * @param array $options_array |
|
24 | + * @param string $help_tab_link |
|
25 | + */ |
|
26 | + public function __construct(array $options_array = array(), $help_tab_link = '') |
|
27 | + { |
|
28 | + $options_array = array_replace_recursive( |
|
29 | + array( |
|
30 | + 'extra_meta_inputs' => array( |
|
31 | + 'credit_card_types' => new EE_Checkbox_Multi_Input( |
|
32 | + EE_PMT_Paypal_Pro::card_types_supported(), |
|
33 | + array( |
|
34 | + 'html_label_text' => __('Card Types Supported', 'event_espresso'), |
|
35 | + 'required' => true |
|
36 | + ) |
|
37 | + ), |
|
38 | + ) |
|
39 | + ), |
|
40 | + $options_array |
|
41 | + ); |
|
42 | + parent::__construct($options_array, $help_tab_link); |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | // End of file SettingsForm.php |
46 | 46 | // Location: EventEspresso/caffeinated/payment_methods/PayPal_Pro/forms/PayPalProSettingsForm.php |
@@ -19,53 +19,53 @@ |
||
19 | 19 | */ |
20 | 20 | class SettingsForm extends PayPalSettingsForm |
21 | 21 | { |
22 | - /** |
|
23 | - * SettingsForm constructor. |
|
24 | - * |
|
25 | - * @param array $options_array |
|
26 | - * @param string $help_tab_link |
|
27 | - * @throws InvalidDataTypeException |
|
28 | - * @throws InvalidInterfaceException |
|
29 | - * @throws InvalidArgumentException |
|
30 | - */ |
|
31 | - public function __construct(array $options_array = array(), $help_tab_link = '') |
|
32 | - { |
|
33 | - $options_array = array_replace_recursive( |
|
34 | - array( |
|
35 | - 'extra_meta_inputs' => array( |
|
36 | - 'request_shipping_addr' => new EE_Yes_No_Input( |
|
37 | - array( |
|
38 | - 'html_label_text' => sprintf( |
|
39 | - esc_html__('Request Shipping Address %s', 'event_espresso'), |
|
40 | - $help_tab_link |
|
41 | - ), |
|
42 | - 'html_help_text' => esc_html__( |
|
43 | - // @codingStandardsIgnoreStart |
|
44 | - 'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.', |
|
45 | - // @codingStandardsIgnoreEnd |
|
46 | - 'event_espresso' |
|
47 | - ), |
|
48 | - 'required' => true, |
|
49 | - 'default' => false, |
|
50 | - ) |
|
51 | - ), |
|
52 | - 'image_url' => new EE_Admin_File_Uploader_Input( |
|
53 | - array( |
|
54 | - 'html_label_text' => sprintf( |
|
55 | - esc_html__('Image URL %s', 'event_espresso'), |
|
56 | - $help_tab_link |
|
57 | - ), |
|
58 | - 'html_help_text' => esc_html__( |
|
59 | - 'Used for your business/personal logo on the PayPal page', |
|
60 | - 'event_espresso' |
|
61 | - ), |
|
62 | - 'required' => false, |
|
63 | - ) |
|
64 | - ), |
|
65 | - ) |
|
66 | - ), |
|
67 | - $options_array |
|
68 | - ); |
|
69 | - parent::__construct($options_array, $help_tab_link); |
|
70 | - } |
|
22 | + /** |
|
23 | + * SettingsForm constructor. |
|
24 | + * |
|
25 | + * @param array $options_array |
|
26 | + * @param string $help_tab_link |
|
27 | + * @throws InvalidDataTypeException |
|
28 | + * @throws InvalidInterfaceException |
|
29 | + * @throws InvalidArgumentException |
|
30 | + */ |
|
31 | + public function __construct(array $options_array = array(), $help_tab_link = '') |
|
32 | + { |
|
33 | + $options_array = array_replace_recursive( |
|
34 | + array( |
|
35 | + 'extra_meta_inputs' => array( |
|
36 | + 'request_shipping_addr' => new EE_Yes_No_Input( |
|
37 | + array( |
|
38 | + 'html_label_text' => sprintf( |
|
39 | + esc_html__('Request Shipping Address %s', 'event_espresso'), |
|
40 | + $help_tab_link |
|
41 | + ), |
|
42 | + 'html_help_text' => esc_html__( |
|
43 | + // @codingStandardsIgnoreStart |
|
44 | + 'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.', |
|
45 | + // @codingStandardsIgnoreEnd |
|
46 | + 'event_espresso' |
|
47 | + ), |
|
48 | + 'required' => true, |
|
49 | + 'default' => false, |
|
50 | + ) |
|
51 | + ), |
|
52 | + 'image_url' => new EE_Admin_File_Uploader_Input( |
|
53 | + array( |
|
54 | + 'html_label_text' => sprintf( |
|
55 | + esc_html__('Image URL %s', 'event_espresso'), |
|
56 | + $help_tab_link |
|
57 | + ), |
|
58 | + 'html_help_text' => esc_html__( |
|
59 | + 'Used for your business/personal logo on the PayPal page', |
|
60 | + 'event_espresso' |
|
61 | + ), |
|
62 | + 'required' => false, |
|
63 | + ) |
|
64 | + ), |
|
65 | + ) |
|
66 | + ), |
|
67 | + $options_array |
|
68 | + ); |
|
69 | + parent::__construct($options_array, $help_tab_link); |
|
70 | + } |
|
71 | 71 | } |
@@ -31,338 +31,338 @@ |
||
31 | 31 | class EspressoEventAttendees extends EspressoShortcode |
32 | 32 | { |
33 | 33 | |
34 | - private $query_params = array( |
|
35 | - 0 => array(), |
|
36 | - ); |
|
34 | + private $query_params = array( |
|
35 | + 0 => array(), |
|
36 | + ); |
|
37 | 37 | |
38 | - private $template_args = array( |
|
39 | - 'contacts' => array(), |
|
40 | - 'event' => null, |
|
41 | - 'datetime' => null, |
|
42 | - 'ticket' => null, |
|
43 | - ); |
|
38 | + private $template_args = array( |
|
39 | + 'contacts' => array(), |
|
40 | + 'event' => null, |
|
41 | + 'datetime' => null, |
|
42 | + 'ticket' => null, |
|
43 | + ); |
|
44 | 44 | |
45 | - /** |
|
46 | - * the actual shortcode tag that gets registered with WordPress |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getTag() |
|
51 | - { |
|
52 | - return 'ESPRESSO_EVENT_ATTENDEES'; |
|
53 | - } |
|
45 | + /** |
|
46 | + * the actual shortcode tag that gets registered with WordPress |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getTag() |
|
51 | + { |
|
52 | + return 'ESPRESSO_EVENT_ATTENDEES'; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * the time in seconds to cache the results of the processShortcode() method |
|
58 | - * 0 means the processShortcode() results will NOT be cached at all |
|
59 | - * |
|
60 | - * @return int |
|
61 | - */ |
|
62 | - public function cacheExpiration() |
|
63 | - { |
|
64 | - return 0; |
|
65 | - } |
|
56 | + /** |
|
57 | + * the time in seconds to cache the results of the processShortcode() method |
|
58 | + * 0 means the processShortcode() results will NOT be cached at all |
|
59 | + * |
|
60 | + * @return int |
|
61 | + */ |
|
62 | + public function cacheExpiration() |
|
63 | + { |
|
64 | + return 0; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
70 | - * this may be required for shortcodes that utilize a corresponding module, |
|
71 | - * and need to enqueue assets for that module |
|
72 | - * |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function initializeShortcode() |
|
76 | - { |
|
77 | - $this->shortcodeHasBeenInitialized(); |
|
78 | - } |
|
68 | + /** |
|
69 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
70 | + * this may be required for shortcodes that utilize a corresponding module, |
|
71 | + * and need to enqueue assets for that module |
|
72 | + * |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function initializeShortcode() |
|
76 | + { |
|
77 | + $this->shortcodeHasBeenInitialized(); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event. |
|
83 | - * [ESPRESSO_EVENT_ATTENDEES] |
|
84 | - * - defaults to attendees for earliest active event, or earliest upcoming event. |
|
85 | - * [ESPRESSO_EVENT_ATTENDEES event_id=123] |
|
86 | - * - attendees for specific event. |
|
87 | - * [ESPRESSO_EVENT_ATTENDEES datetime_id=245] |
|
88 | - * - attendees for a specific datetime. |
|
89 | - * [ESPRESSO_EVENT_ATTENDEES ticket_id=123] |
|
90 | - * - attendees for a specific ticket. |
|
91 | - * [ESPRESSO_EVENT_ATTENDEES status=all] |
|
92 | - * - specific registration status (use status id) or all for all attendees regardless of status. |
|
93 | - * Note default is to only return approved attendees |
|
94 | - * [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] |
|
95 | - * - default is to not return gravatar. Otherwise if this is set then return gravatar for email address given. |
|
96 | - * [ESPRESSO_EVENT_ATTENDEES display_on_archives=true] |
|
97 | - * - default is to not display attendees list on archive pages. |
|
98 | - * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
99 | - * If more than one of those params is included, then preference is given to the following: |
|
100 | - * - event_id is used whenever its present and any others are ignored. |
|
101 | - * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
102 | - * - otherwise ticket_id is used if present. |
|
103 | - * |
|
104 | - * @param array $attributes |
|
105 | - * @return string |
|
106 | - * @throws EE_Error |
|
107 | - * @throws InvalidDataTypeException |
|
108 | - * @throws InvalidInterfaceException |
|
109 | - * @throws InvalidArgumentException |
|
110 | - * @throws DomainException |
|
111 | - */ |
|
112 | - public function processShortcode($attributes = array()) |
|
113 | - { |
|
114 | - // grab attributes and merge with defaults |
|
115 | - $attributes = $this->getAttributes((array) $attributes); |
|
116 | - $attributes['limit'] = (int) $attributes['limit']; |
|
117 | - $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
|
118 | - // don't display on archives unless 'display_on_archives' is true |
|
119 | - if ($attributes['limit'] === 0 || (! $display_on_archives && is_archive())) { |
|
120 | - return ''; |
|
121 | - } |
|
122 | - try { |
|
123 | - $this->setBaseTemplateArguments($attributes); |
|
124 | - $this->validateEntities($attributes); |
|
125 | - $this->setBaseQueryParams(); |
|
126 | - } catch (EntityNotFoundException $e) { |
|
127 | - if (WP_DEBUG) { |
|
128 | - return '<div class="important-notice ee-error">' |
|
129 | - . $e->getMessage() |
|
130 | - . '</div>'; |
|
131 | - } |
|
132 | - return ''; |
|
133 | - } |
|
134 | - $this->setAdditionalQueryParams($attributes); |
|
135 | - // get contacts! |
|
136 | - $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params); |
|
137 | - // all set let's load up the template and return. |
|
138 | - return EEH_Template::locate_template( |
|
139 | - 'loop-espresso_event_attendees.php', |
|
140 | - $this->template_args |
|
141 | - ); |
|
142 | - } |
|
81 | + /** |
|
82 | + * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event. |
|
83 | + * [ESPRESSO_EVENT_ATTENDEES] |
|
84 | + * - defaults to attendees for earliest active event, or earliest upcoming event. |
|
85 | + * [ESPRESSO_EVENT_ATTENDEES event_id=123] |
|
86 | + * - attendees for specific event. |
|
87 | + * [ESPRESSO_EVENT_ATTENDEES datetime_id=245] |
|
88 | + * - attendees for a specific datetime. |
|
89 | + * [ESPRESSO_EVENT_ATTENDEES ticket_id=123] |
|
90 | + * - attendees for a specific ticket. |
|
91 | + * [ESPRESSO_EVENT_ATTENDEES status=all] |
|
92 | + * - specific registration status (use status id) or all for all attendees regardless of status. |
|
93 | + * Note default is to only return approved attendees |
|
94 | + * [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] |
|
95 | + * - default is to not return gravatar. Otherwise if this is set then return gravatar for email address given. |
|
96 | + * [ESPRESSO_EVENT_ATTENDEES display_on_archives=true] |
|
97 | + * - default is to not display attendees list on archive pages. |
|
98 | + * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
99 | + * If more than one of those params is included, then preference is given to the following: |
|
100 | + * - event_id is used whenever its present and any others are ignored. |
|
101 | + * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
102 | + * - otherwise ticket_id is used if present. |
|
103 | + * |
|
104 | + * @param array $attributes |
|
105 | + * @return string |
|
106 | + * @throws EE_Error |
|
107 | + * @throws InvalidDataTypeException |
|
108 | + * @throws InvalidInterfaceException |
|
109 | + * @throws InvalidArgumentException |
|
110 | + * @throws DomainException |
|
111 | + */ |
|
112 | + public function processShortcode($attributes = array()) |
|
113 | + { |
|
114 | + // grab attributes and merge with defaults |
|
115 | + $attributes = $this->getAttributes((array) $attributes); |
|
116 | + $attributes['limit'] = (int) $attributes['limit']; |
|
117 | + $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
|
118 | + // don't display on archives unless 'display_on_archives' is true |
|
119 | + if ($attributes['limit'] === 0 || (! $display_on_archives && is_archive())) { |
|
120 | + return ''; |
|
121 | + } |
|
122 | + try { |
|
123 | + $this->setBaseTemplateArguments($attributes); |
|
124 | + $this->validateEntities($attributes); |
|
125 | + $this->setBaseQueryParams(); |
|
126 | + } catch (EntityNotFoundException $e) { |
|
127 | + if (WP_DEBUG) { |
|
128 | + return '<div class="important-notice ee-error">' |
|
129 | + . $e->getMessage() |
|
130 | + . '</div>'; |
|
131 | + } |
|
132 | + return ''; |
|
133 | + } |
|
134 | + $this->setAdditionalQueryParams($attributes); |
|
135 | + // get contacts! |
|
136 | + $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params); |
|
137 | + // all set let's load up the template and return. |
|
138 | + return EEH_Template::locate_template( |
|
139 | + 'loop-espresso_event_attendees.php', |
|
140 | + $this->template_args |
|
141 | + ); |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | - /** |
|
146 | - * merge incoming attributes with filtered defaults |
|
147 | - * |
|
148 | - * @param array $attributes |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - private function getAttributes(array $attributes) |
|
152 | - { |
|
153 | - return (array) apply_filters( |
|
154 | - 'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', |
|
155 | - $attributes + array( |
|
156 | - 'event_id' => null, |
|
157 | - 'datetime_id' => null, |
|
158 | - 'ticket_id' => null, |
|
159 | - 'status' => EEM_Registration::status_id_approved, |
|
160 | - 'show_gravatar' => false, |
|
161 | - 'display_on_archives' => false, |
|
162 | - 'limit' => 999, |
|
163 | - ) |
|
164 | - ); |
|
165 | - } |
|
145 | + /** |
|
146 | + * merge incoming attributes with filtered defaults |
|
147 | + * |
|
148 | + * @param array $attributes |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + private function getAttributes(array $attributes) |
|
152 | + { |
|
153 | + return (array) apply_filters( |
|
154 | + 'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', |
|
155 | + $attributes + array( |
|
156 | + 'event_id' => null, |
|
157 | + 'datetime_id' => null, |
|
158 | + 'ticket_id' => null, |
|
159 | + 'status' => EEM_Registration::status_id_approved, |
|
160 | + 'show_gravatar' => false, |
|
161 | + 'display_on_archives' => false, |
|
162 | + 'limit' => 999, |
|
163 | + ) |
|
164 | + ); |
|
165 | + } |
|
166 | 166 | |
167 | 167 | |
168 | - /** |
|
169 | - * Set all the base template arguments from the incoming attributes. |
|
170 | - * * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
171 | - * If more than one of those params is included, then preference is given to the following: |
|
172 | - * - event_id is used whenever its present and any others are ignored. |
|
173 | - * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
174 | - * - otherwise ticket_id is used if present. |
|
175 | - * |
|
176 | - * @param array $attributes |
|
177 | - * @throws EE_Error |
|
178 | - * @throws InvalidDataTypeException |
|
179 | - * @throws InvalidInterfaceException |
|
180 | - * @throws InvalidArgumentException |
|
181 | - */ |
|
182 | - private function setBaseTemplateArguments(array $attributes) |
|
183 | - { |
|
184 | - $this->template_args['show_gravatar'] = $attributes['show_gravatar']; |
|
185 | - $this->template_args['event'] = $this->getEvent($attributes); |
|
186 | - $this->template_args['datetime'] = empty($attributes['event_id']) |
|
187 | - ? $this->getDatetime($attributes) |
|
188 | - : null; |
|
189 | - $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id']) |
|
190 | - ? $this->getTicket($attributes) |
|
191 | - : null; |
|
192 | - } |
|
168 | + /** |
|
169 | + * Set all the base template arguments from the incoming attributes. |
|
170 | + * * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
171 | + * If more than one of those params is included, then preference is given to the following: |
|
172 | + * - event_id is used whenever its present and any others are ignored. |
|
173 | + * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
174 | + * - otherwise ticket_id is used if present. |
|
175 | + * |
|
176 | + * @param array $attributes |
|
177 | + * @throws EE_Error |
|
178 | + * @throws InvalidDataTypeException |
|
179 | + * @throws InvalidInterfaceException |
|
180 | + * @throws InvalidArgumentException |
|
181 | + */ |
|
182 | + private function setBaseTemplateArguments(array $attributes) |
|
183 | + { |
|
184 | + $this->template_args['show_gravatar'] = $attributes['show_gravatar']; |
|
185 | + $this->template_args['event'] = $this->getEvent($attributes); |
|
186 | + $this->template_args['datetime'] = empty($attributes['event_id']) |
|
187 | + ? $this->getDatetime($attributes) |
|
188 | + : null; |
|
189 | + $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id']) |
|
190 | + ? $this->getTicket($attributes) |
|
191 | + : null; |
|
192 | + } |
|
193 | 193 | |
194 | 194 | |
195 | - /** |
|
196 | - * Validates the presence of entities for the given attribute values. |
|
197 | - * |
|
198 | - * @param array $attributes |
|
199 | - * @throws EntityNotFoundException |
|
200 | - */ |
|
201 | - private function validateEntities(array $attributes) |
|
202 | - { |
|
203 | - if (! $this->template_args['event'] instanceof EE_Event |
|
204 | - || ( |
|
205 | - empty($attributes['event_id']) |
|
206 | - && $attributes['datetime_id'] |
|
207 | - && ! $this->template_args['datetime'] instanceof EE_Datetime |
|
208 | - ) |
|
209 | - || ( |
|
210 | - empty($attributes['event_id']) |
|
211 | - && empty($attributes['datetime_id']) |
|
212 | - && $attributes['ticket_id'] |
|
213 | - && ! $this->template_args['ticket'] instanceof EE_Ticket |
|
214 | - ) |
|
215 | - ) { |
|
216 | - throw new EntityNotFoundException( |
|
217 | - '', |
|
218 | - '', |
|
219 | - esc_html__( |
|
220 | - 'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', |
|
221 | - 'event_espresso' |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - } |
|
195 | + /** |
|
196 | + * Validates the presence of entities for the given attribute values. |
|
197 | + * |
|
198 | + * @param array $attributes |
|
199 | + * @throws EntityNotFoundException |
|
200 | + */ |
|
201 | + private function validateEntities(array $attributes) |
|
202 | + { |
|
203 | + if (! $this->template_args['event'] instanceof EE_Event |
|
204 | + || ( |
|
205 | + empty($attributes['event_id']) |
|
206 | + && $attributes['datetime_id'] |
|
207 | + && ! $this->template_args['datetime'] instanceof EE_Datetime |
|
208 | + ) |
|
209 | + || ( |
|
210 | + empty($attributes['event_id']) |
|
211 | + && empty($attributes['datetime_id']) |
|
212 | + && $attributes['ticket_id'] |
|
213 | + && ! $this->template_args['ticket'] instanceof EE_Ticket |
|
214 | + ) |
|
215 | + ) { |
|
216 | + throw new EntityNotFoundException( |
|
217 | + '', |
|
218 | + '', |
|
219 | + esc_html__( |
|
220 | + 'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', |
|
221 | + 'event_espresso' |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + } |
|
226 | 226 | |
227 | 227 | |
228 | - /** |
|
229 | - * Sets the query params for the base query elements. |
|
230 | - */ |
|
231 | - private function setBaseQueryParams() |
|
232 | - { |
|
233 | - switch (true) { |
|
234 | - case $this->template_args['datetime'] instanceof EE_Datetime: |
|
235 | - $this->query_params = array( |
|
236 | - 0 => array( |
|
237 | - 'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID(), |
|
238 | - ), |
|
239 | - 'default_where_conditions' => 'this_model_only', |
|
240 | - ); |
|
241 | - break; |
|
242 | - case $this->template_args['ticket'] instanceof EE_Ticket: |
|
243 | - $this->query_params[0] = array( |
|
244 | - 'Registration.TKT_ID' => $this->template_args['ticket']->ID(), |
|
245 | - ); |
|
246 | - break; |
|
247 | - case $this->template_args['event'] instanceof EE_Event: |
|
248 | - $this->query_params[0] = array( |
|
249 | - 'Registration.EVT_ID' => $this->template_args['event']->ID(), |
|
250 | - ); |
|
251 | - break; |
|
252 | - } |
|
253 | - } |
|
228 | + /** |
|
229 | + * Sets the query params for the base query elements. |
|
230 | + */ |
|
231 | + private function setBaseQueryParams() |
|
232 | + { |
|
233 | + switch (true) { |
|
234 | + case $this->template_args['datetime'] instanceof EE_Datetime: |
|
235 | + $this->query_params = array( |
|
236 | + 0 => array( |
|
237 | + 'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID(), |
|
238 | + ), |
|
239 | + 'default_where_conditions' => 'this_model_only', |
|
240 | + ); |
|
241 | + break; |
|
242 | + case $this->template_args['ticket'] instanceof EE_Ticket: |
|
243 | + $this->query_params[0] = array( |
|
244 | + 'Registration.TKT_ID' => $this->template_args['ticket']->ID(), |
|
245 | + ); |
|
246 | + break; |
|
247 | + case $this->template_args['event'] instanceof EE_Event: |
|
248 | + $this->query_params[0] = array( |
|
249 | + 'Registration.EVT_ID' => $this->template_args['event']->ID(), |
|
250 | + ); |
|
251 | + break; |
|
252 | + } |
|
253 | + } |
|
254 | 254 | |
255 | 255 | |
256 | - /** |
|
257 | - * @param array $attributes |
|
258 | - * @return EE_Event|null |
|
259 | - * @throws EE_Error |
|
260 | - * @throws InvalidDataTypeException |
|
261 | - * @throws InvalidInterfaceException |
|
262 | - * @throws InvalidArgumentException |
|
263 | - */ |
|
264 | - private function getEvent(array $attributes) |
|
265 | - { |
|
266 | - switch (true) { |
|
267 | - case ! empty($attributes['event_id']): |
|
268 | - $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
|
269 | - break; |
|
270 | - case ! empty($attributes['datetime_id']): |
|
271 | - $event = EEM_Event::instance()->get_one(array( |
|
272 | - array( |
|
273 | - 'Datetime.DTT_ID' => $attributes['datetime_id'], |
|
274 | - ), |
|
275 | - )); |
|
276 | - break; |
|
277 | - case ! empty($attributes['ticket_id']): |
|
278 | - $event = EEM_Event::instance()->get_one(array( |
|
279 | - array( |
|
280 | - 'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'], |
|
281 | - ), |
|
282 | - 'default_where_conditions' => 'none' |
|
283 | - )); |
|
284 | - break; |
|
285 | - case is_espresso_event(): |
|
286 | - $event = EEH_Event_View::get_event(); |
|
287 | - break; |
|
288 | - default: |
|
289 | - // one last shot... |
|
290 | - // try getting the earliest active event |
|
291 | - $events = EEM_Event::instance()->get_active_events(array( |
|
292 | - 'limit' => 1, |
|
293 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'), |
|
294 | - )); |
|
295 | - // if none then get the next upcoming |
|
296 | - $events = empty($events) |
|
297 | - ? EEM_Event::instance()->get_upcoming_events(array( |
|
298 | - 'limit' => 1, |
|
299 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'), |
|
300 | - )) |
|
301 | - : $events; |
|
302 | - $event = reset($events); |
|
303 | - } |
|
256 | + /** |
|
257 | + * @param array $attributes |
|
258 | + * @return EE_Event|null |
|
259 | + * @throws EE_Error |
|
260 | + * @throws InvalidDataTypeException |
|
261 | + * @throws InvalidInterfaceException |
|
262 | + * @throws InvalidArgumentException |
|
263 | + */ |
|
264 | + private function getEvent(array $attributes) |
|
265 | + { |
|
266 | + switch (true) { |
|
267 | + case ! empty($attributes['event_id']): |
|
268 | + $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
|
269 | + break; |
|
270 | + case ! empty($attributes['datetime_id']): |
|
271 | + $event = EEM_Event::instance()->get_one(array( |
|
272 | + array( |
|
273 | + 'Datetime.DTT_ID' => $attributes['datetime_id'], |
|
274 | + ), |
|
275 | + )); |
|
276 | + break; |
|
277 | + case ! empty($attributes['ticket_id']): |
|
278 | + $event = EEM_Event::instance()->get_one(array( |
|
279 | + array( |
|
280 | + 'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'], |
|
281 | + ), |
|
282 | + 'default_where_conditions' => 'none' |
|
283 | + )); |
|
284 | + break; |
|
285 | + case is_espresso_event(): |
|
286 | + $event = EEH_Event_View::get_event(); |
|
287 | + break; |
|
288 | + default: |
|
289 | + // one last shot... |
|
290 | + // try getting the earliest active event |
|
291 | + $events = EEM_Event::instance()->get_active_events(array( |
|
292 | + 'limit' => 1, |
|
293 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'), |
|
294 | + )); |
|
295 | + // if none then get the next upcoming |
|
296 | + $events = empty($events) |
|
297 | + ? EEM_Event::instance()->get_upcoming_events(array( |
|
298 | + 'limit' => 1, |
|
299 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'), |
|
300 | + )) |
|
301 | + : $events; |
|
302 | + $event = reset($events); |
|
303 | + } |
|
304 | 304 | |
305 | - return $event instanceof EE_Event ? $event : null; |
|
306 | - } |
|
305 | + return $event instanceof EE_Event ? $event : null; |
|
306 | + } |
|
307 | 307 | |
308 | 308 | |
309 | - /** |
|
310 | - * @param array $attributes |
|
311 | - * @return EE_Datetime|null |
|
312 | - * @throws EE_Error |
|
313 | - * @throws InvalidDataTypeException |
|
314 | - * @throws InvalidInterfaceException |
|
315 | - * @throws InvalidArgumentException |
|
316 | - */ |
|
317 | - private function getDatetime(array $attributes) |
|
318 | - { |
|
319 | - if (! empty($attributes['datetime_id'])) { |
|
320 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
|
321 | - if ($datetime instanceof EE_Datetime) { |
|
322 | - return $datetime; |
|
323 | - } |
|
324 | - } |
|
325 | - return null; |
|
326 | - } |
|
309 | + /** |
|
310 | + * @param array $attributes |
|
311 | + * @return EE_Datetime|null |
|
312 | + * @throws EE_Error |
|
313 | + * @throws InvalidDataTypeException |
|
314 | + * @throws InvalidInterfaceException |
|
315 | + * @throws InvalidArgumentException |
|
316 | + */ |
|
317 | + private function getDatetime(array $attributes) |
|
318 | + { |
|
319 | + if (! empty($attributes['datetime_id'])) { |
|
320 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
|
321 | + if ($datetime instanceof EE_Datetime) { |
|
322 | + return $datetime; |
|
323 | + } |
|
324 | + } |
|
325 | + return null; |
|
326 | + } |
|
327 | 327 | |
328 | 328 | |
329 | - /** |
|
330 | - * @param array $attributes |
|
331 | - * @return \EE_Base_Class|EE_Ticket|null |
|
332 | - * @throws EE_Error |
|
333 | - * @throws InvalidDataTypeException |
|
334 | - * @throws InvalidInterfaceException |
|
335 | - * @throws InvalidArgumentException |
|
336 | - */ |
|
337 | - private function getTicket(array $attributes) |
|
338 | - { |
|
339 | - if (! empty($attributes['ticket_id'])) { |
|
340 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
|
341 | - if ($ticket instanceof EE_Ticket) { |
|
342 | - return $ticket; |
|
343 | - } |
|
344 | - } |
|
345 | - return null; |
|
346 | - } |
|
329 | + /** |
|
330 | + * @param array $attributes |
|
331 | + * @return \EE_Base_Class|EE_Ticket|null |
|
332 | + * @throws EE_Error |
|
333 | + * @throws InvalidDataTypeException |
|
334 | + * @throws InvalidInterfaceException |
|
335 | + * @throws InvalidArgumentException |
|
336 | + */ |
|
337 | + private function getTicket(array $attributes) |
|
338 | + { |
|
339 | + if (! empty($attributes['ticket_id'])) { |
|
340 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
|
341 | + if ($ticket instanceof EE_Ticket) { |
|
342 | + return $ticket; |
|
343 | + } |
|
344 | + } |
|
345 | + return null; |
|
346 | + } |
|
347 | 347 | |
348 | 348 | |
349 | - /** |
|
350 | - * @param array $attributes |
|
351 | - * @throws EE_Error |
|
352 | - */ |
|
353 | - private function setAdditionalQueryParams(array $attributes) |
|
354 | - { |
|
355 | - $reg_status_array = EEM_Registration::reg_status_array(); |
|
356 | - if (isset($reg_status_array[ $attributes['status'] ])) { |
|
357 | - $this->query_params[0]['Registration.STS_ID'] = $attributes['status']; |
|
358 | - } |
|
359 | - if (absint($attributes['limit'])) { |
|
360 | - $this->query_params['limit'] = $attributes['limit']; |
|
361 | - } |
|
362 | - $this->query_params['group_by'] = array('ATT_ID'); |
|
363 | - $this->query_params['order_by'] = (array) apply_filters( |
|
364 | - 'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', |
|
365 | - array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC') |
|
366 | - ); |
|
367 | - } |
|
349 | + /** |
|
350 | + * @param array $attributes |
|
351 | + * @throws EE_Error |
|
352 | + */ |
|
353 | + private function setAdditionalQueryParams(array $attributes) |
|
354 | + { |
|
355 | + $reg_status_array = EEM_Registration::reg_status_array(); |
|
356 | + if (isset($reg_status_array[ $attributes['status'] ])) { |
|
357 | + $this->query_params[0]['Registration.STS_ID'] = $attributes['status']; |
|
358 | + } |
|
359 | + if (absint($attributes['limit'])) { |
|
360 | + $this->query_params['limit'] = $attributes['limit']; |
|
361 | + } |
|
362 | + $this->query_params['group_by'] = array('ATT_ID'); |
|
363 | + $this->query_params['order_by'] = (array) apply_filters( |
|
364 | + 'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', |
|
365 | + array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC') |
|
366 | + ); |
|
367 | + } |
|
368 | 368 | } |
@@ -23,336 +23,336 @@ |
||
23 | 23 | class EED_Batch extends EED_Module |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
28 | - * processes data only |
|
29 | - */ |
|
30 | - const batch_job = 'job'; |
|
31 | - /** |
|
32 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
33 | - * produces a file for download |
|
34 | - */ |
|
35 | - const batch_file_job = 'file'; |
|
36 | - /** |
|
37 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
38 | - * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
39 | - * at all |
|
40 | - */ |
|
41 | - const batch_not_job = 'none'; |
|
26 | + /** |
|
27 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
28 | + * processes data only |
|
29 | + */ |
|
30 | + const batch_job = 'job'; |
|
31 | + /** |
|
32 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
33 | + * produces a file for download |
|
34 | + */ |
|
35 | + const batch_file_job = 'file'; |
|
36 | + /** |
|
37 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
38 | + * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
39 | + * at all |
|
40 | + */ |
|
41 | + const batch_not_job = 'none'; |
|
42 | 42 | |
43 | - /** |
|
44 | - * |
|
45 | - * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
46 | - */ |
|
47 | - protected $_batch_request_type = null; |
|
43 | + /** |
|
44 | + * |
|
45 | + * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
46 | + */ |
|
47 | + protected $_batch_request_type = null; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Because we want to use the response in both the localized JS and in the body |
|
51 | - * we need to make this response available between method calls |
|
52 | - * |
|
53 | - * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
54 | - */ |
|
55 | - protected $_job_step_response = null; |
|
49 | + /** |
|
50 | + * Because we want to use the response in both the localized JS and in the body |
|
51 | + * we need to make this response available between method calls |
|
52 | + * |
|
53 | + * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
54 | + */ |
|
55 | + protected $_job_step_response = null; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Gets the batch instance |
|
59 | - * |
|
60 | - * @return EED_Batch |
|
61 | - */ |
|
62 | - public static function instance() |
|
63 | - { |
|
64 | - return self::get_instance(); |
|
65 | - } |
|
57 | + /** |
|
58 | + * Gets the batch instance |
|
59 | + * |
|
60 | + * @return EED_Batch |
|
61 | + */ |
|
62 | + public static function instance() |
|
63 | + { |
|
64 | + return self::get_instance(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
69 | - * because it's an attack vector and there are currently no implementations |
|
70 | - */ |
|
71 | - public static function set_hooks() |
|
72 | - { |
|
73 | - // because this is a possibel attack vector, let's have this disabled until |
|
74 | - // we at least have a real use for it on the frontend |
|
75 | - if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
76 | - add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
77 | - add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
78 | - } |
|
79 | - } |
|
67 | + /** |
|
68 | + * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
69 | + * because it's an attack vector and there are currently no implementations |
|
70 | + */ |
|
71 | + public static function set_hooks() |
|
72 | + { |
|
73 | + // because this is a possibel attack vector, let's have this disabled until |
|
74 | + // we at least have a real use for it on the frontend |
|
75 | + if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
76 | + add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
77 | + add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Initializes some hooks for the admin in order to run batch jobs |
|
83 | - */ |
|
84 | - public static function set_hooks_admin() |
|
85 | - { |
|
86 | - add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
87 | - add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
81 | + /** |
|
82 | + * Initializes some hooks for the admin in order to run batch jobs |
|
83 | + */ |
|
84 | + public static function set_hooks_admin() |
|
85 | + { |
|
86 | + add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
87 | + add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
88 | 88 | |
89 | - // ajax |
|
90 | - add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
91 | - add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
92 | - add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
93 | - add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
94 | - } |
|
89 | + // ajax |
|
90 | + add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
91 | + add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
92 | + add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
93 | + add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Enqueues batch scripts on the frontend or admin, and creates a job |
|
98 | - */ |
|
99 | - public function enqueue_scripts() |
|
100 | - { |
|
101 | - if (isset($_REQUEST['espresso_batch']) |
|
102 | - || |
|
103 | - ( |
|
104 | - isset($_REQUEST['page']) |
|
105 | - && $_REQUEST['page'] == 'espresso_batch' |
|
106 | - ) |
|
107 | - ) { |
|
108 | - switch ($this->batch_request_type()) { |
|
109 | - case self::batch_job: |
|
110 | - $this->enqueue_scripts_styles_batch_create(); |
|
111 | - break; |
|
112 | - case self::batch_file_job: |
|
113 | - $this->enqueue_scripts_styles_batch_file_create(); |
|
114 | - break; |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
96 | + /** |
|
97 | + * Enqueues batch scripts on the frontend or admin, and creates a job |
|
98 | + */ |
|
99 | + public function enqueue_scripts() |
|
100 | + { |
|
101 | + if (isset($_REQUEST['espresso_batch']) |
|
102 | + || |
|
103 | + ( |
|
104 | + isset($_REQUEST['page']) |
|
105 | + && $_REQUEST['page'] == 'espresso_batch' |
|
106 | + ) |
|
107 | + ) { |
|
108 | + switch ($this->batch_request_type()) { |
|
109 | + case self::batch_job: |
|
110 | + $this->enqueue_scripts_styles_batch_create(); |
|
111 | + break; |
|
112 | + case self::batch_file_job: |
|
113 | + $this->enqueue_scripts_styles_batch_file_create(); |
|
114 | + break; |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
121 | - */ |
|
122 | - public function enqueue_scripts_styles_batch_create() |
|
123 | - { |
|
124 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
125 | - wp_enqueue_script( |
|
126 | - 'batch_runner_init', |
|
127 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
128 | - array('batch_runner'), |
|
129 | - EVENT_ESPRESSO_VERSION, |
|
130 | - true |
|
131 | - ); |
|
132 | - wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
133 | - wp_localize_script( |
|
134 | - 'batch_runner_init', |
|
135 | - 'ee_job_i18n', |
|
136 | - array( |
|
137 | - 'return_url' => $_REQUEST['return_url'], |
|
138 | - ) |
|
139 | - ); |
|
140 | - } |
|
119 | + /** |
|
120 | + * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
121 | + */ |
|
122 | + public function enqueue_scripts_styles_batch_create() |
|
123 | + { |
|
124 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
125 | + wp_enqueue_script( |
|
126 | + 'batch_runner_init', |
|
127 | + BATCH_URL . 'assets/batch_runner_init.js', |
|
128 | + array('batch_runner'), |
|
129 | + EVENT_ESPRESSO_VERSION, |
|
130 | + true |
|
131 | + ); |
|
132 | + wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
133 | + wp_localize_script( |
|
134 | + 'batch_runner_init', |
|
135 | + 'ee_job_i18n', |
|
136 | + array( |
|
137 | + 'return_url' => $_REQUEST['return_url'], |
|
138 | + ) |
|
139 | + ); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
144 | - */ |
|
145 | - public function enqueue_scripts_styles_batch_file_create() |
|
146 | - { |
|
147 | - // creates a job based on the request variable |
|
148 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
149 | - wp_enqueue_script( |
|
150 | - 'batch_file_runner_init', |
|
151 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
152 | - array('batch_runner'), |
|
153 | - EVENT_ESPRESSO_VERSION, |
|
154 | - true |
|
155 | - ); |
|
156 | - wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
157 | - wp_localize_script( |
|
158 | - 'batch_file_runner_init', |
|
159 | - 'ee_job_i18n', |
|
160 | - array( |
|
161 | - 'download_and_redirecting' => sprintf( |
|
162 | - __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
163 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
164 | - '</a>' |
|
165 | - ), |
|
166 | - 'return_url' => $_REQUEST['return_url'], |
|
167 | - ) |
|
168 | - ); |
|
169 | - } |
|
142 | + /** |
|
143 | + * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
144 | + */ |
|
145 | + public function enqueue_scripts_styles_batch_file_create() |
|
146 | + { |
|
147 | + // creates a job based on the request variable |
|
148 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
149 | + wp_enqueue_script( |
|
150 | + 'batch_file_runner_init', |
|
151 | + BATCH_URL . 'assets/batch_file_runner_init.js', |
|
152 | + array('batch_runner'), |
|
153 | + EVENT_ESPRESSO_VERSION, |
|
154 | + true |
|
155 | + ); |
|
156 | + wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
157 | + wp_localize_script( |
|
158 | + 'batch_file_runner_init', |
|
159 | + 'ee_job_i18n', |
|
160 | + array( |
|
161 | + 'download_and_redirecting' => sprintf( |
|
162 | + __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
163 | + '<a href="' . $_REQUEST['return_url'] . '">', |
|
164 | + '</a>' |
|
165 | + ), |
|
166 | + 'return_url' => $_REQUEST['return_url'], |
|
167 | + ) |
|
168 | + ); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Enqueues scripts and styles common to any batch job, and creates |
|
173 | - * a job from the request data, and stores the response in the |
|
174 | - * $this->_job_step_response property |
|
175 | - * |
|
176 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
177 | - */ |
|
178 | - protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
179 | - { |
|
180 | - wp_register_script( |
|
181 | - 'progress_bar', |
|
182 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
183 | - array('jquery') |
|
184 | - ); |
|
185 | - wp_enqueue_style( |
|
186 | - 'progress_bar', |
|
187 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
188 | - array(), |
|
189 | - EVENT_ESPRESSO_VERSION |
|
190 | - ); |
|
191 | - wp_enqueue_script( |
|
192 | - 'batch_runner', |
|
193 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
194 | - array('progress_bar') |
|
195 | - ); |
|
196 | - // just copy the bits of EE admin's eei18n that we need in the JS |
|
197 | - wp_localize_script( |
|
198 | - 'batch_runner', |
|
199 | - 'eei18n', |
|
200 | - array( |
|
201 | - 'ajax_url' => WP_AJAX_URL, |
|
202 | - 'is_admin' => (bool) is_admin(), |
|
203 | - 'error_message' => esc_html__('An error occurred and the job has been stopped. Please refresh the page to try again.', 'event_espresso'), |
|
204 | - ) |
|
205 | - ); |
|
206 | - $job_handler_classname = stripslashes($_GET['job_handler']); |
|
207 | - $request_data = array_diff_key( |
|
208 | - $_REQUEST, |
|
209 | - array_flip(array('action', 'page', 'ee', 'batch')) |
|
210 | - ); |
|
211 | - $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor(); |
|
212 | - // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
213 | - $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
214 | - // remember the response for later. We need it to display the page body |
|
215 | - $this->_job_step_response = $job_response; |
|
216 | - return $job_response; |
|
217 | - } |
|
171 | + /** |
|
172 | + * Enqueues scripts and styles common to any batch job, and creates |
|
173 | + * a job from the request data, and stores the response in the |
|
174 | + * $this->_job_step_response property |
|
175 | + * |
|
176 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
177 | + */ |
|
178 | + protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
179 | + { |
|
180 | + wp_register_script( |
|
181 | + 'progress_bar', |
|
182 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
183 | + array('jquery') |
|
184 | + ); |
|
185 | + wp_enqueue_style( |
|
186 | + 'progress_bar', |
|
187 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
188 | + array(), |
|
189 | + EVENT_ESPRESSO_VERSION |
|
190 | + ); |
|
191 | + wp_enqueue_script( |
|
192 | + 'batch_runner', |
|
193 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
194 | + array('progress_bar') |
|
195 | + ); |
|
196 | + // just copy the bits of EE admin's eei18n that we need in the JS |
|
197 | + wp_localize_script( |
|
198 | + 'batch_runner', |
|
199 | + 'eei18n', |
|
200 | + array( |
|
201 | + 'ajax_url' => WP_AJAX_URL, |
|
202 | + 'is_admin' => (bool) is_admin(), |
|
203 | + 'error_message' => esc_html__('An error occurred and the job has been stopped. Please refresh the page to try again.', 'event_espresso'), |
|
204 | + ) |
|
205 | + ); |
|
206 | + $job_handler_classname = stripslashes($_GET['job_handler']); |
|
207 | + $request_data = array_diff_key( |
|
208 | + $_REQUEST, |
|
209 | + array_flip(array('action', 'page', 'ee', 'batch')) |
|
210 | + ); |
|
211 | + $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor(); |
|
212 | + // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
213 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
214 | + // remember the response for later. We need it to display the page body |
|
215 | + $this->_job_step_response = $job_response; |
|
216 | + return $job_response; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
221 | - * |
|
222 | - * @param string $template |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public function override_template($template) |
|
226 | - { |
|
227 | - if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
228 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
229 | - } |
|
230 | - return $template; |
|
231 | - } |
|
219 | + /** |
|
220 | + * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
221 | + * |
|
222 | + * @param string $template |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public function override_template($template) |
|
226 | + { |
|
227 | + if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
228 | + return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
229 | + } |
|
230 | + return $template; |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Adds an admin page which doesn't appear in the admin menu |
|
235 | - */ |
|
236 | - public function register_admin_pages() |
|
237 | - { |
|
238 | - add_submenu_page( |
|
239 | - '', // parent slug. we don't want this to actually appear in the menu |
|
240 | - __('Batch Job', 'event_espresso'), // page title |
|
241 | - 'n/a', // menu title |
|
242 | - 'read', // we want this page to actually be accessible to anyone, |
|
243 | - 'espresso_batch', // menu slug |
|
244 | - array(self::instance(), 'show_admin_page') |
|
245 | - ); |
|
246 | - } |
|
233 | + /** |
|
234 | + * Adds an admin page which doesn't appear in the admin menu |
|
235 | + */ |
|
236 | + public function register_admin_pages() |
|
237 | + { |
|
238 | + add_submenu_page( |
|
239 | + '', // parent slug. we don't want this to actually appear in the menu |
|
240 | + __('Batch Job', 'event_espresso'), // page title |
|
241 | + 'n/a', // menu title |
|
242 | + 'read', // we want this page to actually be accessible to anyone, |
|
243 | + 'espresso_batch', // menu slug |
|
244 | + array(self::instance(), 'show_admin_page') |
|
245 | + ); |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
250 | - * of creating the job and localizing some data |
|
251 | - */ |
|
252 | - public function show_admin_page() |
|
253 | - { |
|
254 | - echo EEH_Template::locate_template( |
|
255 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
256 | - array('batch_request_type' => $this->batch_request_type()) |
|
257 | - ); |
|
258 | - } |
|
248 | + /** |
|
249 | + * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
250 | + * of creating the job and localizing some data |
|
251 | + */ |
|
252 | + public function show_admin_page() |
|
253 | + { |
|
254 | + echo EEH_Template::locate_template( |
|
255 | + EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
256 | + array('batch_request_type' => $this->batch_request_type()) |
|
257 | + ); |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * Receives ajax calls for continuing a job |
|
262 | - */ |
|
263 | - public function batch_continue() |
|
264 | - { |
|
265 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
266 | - $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor(); |
|
267 | - $response_obj = $batch_runner->continue_job($job_id); |
|
268 | - $this->_return_json($response_obj->to_array()); |
|
269 | - } |
|
260 | + /** |
|
261 | + * Receives ajax calls for continuing a job |
|
262 | + */ |
|
263 | + public function batch_continue() |
|
264 | + { |
|
265 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
266 | + $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor(); |
|
267 | + $response_obj = $batch_runner->continue_job($job_id); |
|
268 | + $this->_return_json($response_obj->to_array()); |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * Receives the ajax call to cleanup a job |
|
273 | - * |
|
274 | - * @return type |
|
275 | - */ |
|
276 | - public function batch_cleanup() |
|
277 | - { |
|
278 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
279 | - $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor(); |
|
280 | - $response_obj = $batch_runner->cleanup_job($job_id); |
|
281 | - $this->_return_json($response_obj->to_array()); |
|
282 | - } |
|
271 | + /** |
|
272 | + * Receives the ajax call to cleanup a job |
|
273 | + * |
|
274 | + * @return type |
|
275 | + */ |
|
276 | + public function batch_cleanup() |
|
277 | + { |
|
278 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
279 | + $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor(); |
|
280 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
281 | + $this->_return_json($response_obj->to_array()); |
|
282 | + } |
|
283 | 283 | |
284 | 284 | |
285 | - /** |
|
286 | - * Returns a json response |
|
287 | - * |
|
288 | - * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
289 | - * |
|
290 | - * The returned json object is created from an array in the following format: |
|
291 | - * array( |
|
292 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
293 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
294 | - * We're also going to include the template args with every package (so js can pick out any specific template |
|
295 | - * args that might be included in here) |
|
296 | - * 'isEEajax' => true,//indicates this is a response from EE |
|
297 | - * ) |
|
298 | - */ |
|
299 | - protected function _return_json($data) |
|
300 | - { |
|
301 | - $json = array( |
|
302 | - 'notices' => EE_Error::get_notices(), |
|
303 | - 'data' => $data, |
|
304 | - 'isEEajax' => true |
|
305 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
306 | - ); |
|
285 | + /** |
|
286 | + * Returns a json response |
|
287 | + * |
|
288 | + * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
289 | + * |
|
290 | + * The returned json object is created from an array in the following format: |
|
291 | + * array( |
|
292 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
293 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
294 | + * We're also going to include the template args with every package (so js can pick out any specific template |
|
295 | + * args that might be included in here) |
|
296 | + * 'isEEajax' => true,//indicates this is a response from EE |
|
297 | + * ) |
|
298 | + */ |
|
299 | + protected function _return_json($data) |
|
300 | + { |
|
301 | + $json = array( |
|
302 | + 'notices' => EE_Error::get_notices(), |
|
303 | + 'data' => $data, |
|
304 | + 'isEEajax' => true |
|
305 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
306 | + ); |
|
307 | 307 | |
308 | 308 | |
309 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
310 | - if (null === error_get_last() || ! headers_sent()) { |
|
311 | - header('Content-Type: application/json; charset=UTF-8'); |
|
312 | - } |
|
313 | - echo wp_json_encode($json); |
|
314 | - exit(); |
|
315 | - } |
|
309 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
310 | + if (null === error_get_last() || ! headers_sent()) { |
|
311 | + header('Content-Type: application/json; charset=UTF-8'); |
|
312 | + } |
|
313 | + echo wp_json_encode($json); |
|
314 | + exit(); |
|
315 | + } |
|
316 | 316 | |
317 | - /** |
|
318 | - * Gets the job step response which was done during the enqueuing of scripts |
|
319 | - * |
|
320 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
321 | - */ |
|
322 | - public function job_step_response() |
|
323 | - { |
|
324 | - return $this->_job_step_response; |
|
325 | - } |
|
317 | + /** |
|
318 | + * Gets the job step response which was done during the enqueuing of scripts |
|
319 | + * |
|
320 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
321 | + */ |
|
322 | + public function job_step_response() |
|
323 | + { |
|
324 | + return $this->_job_step_response; |
|
325 | + } |
|
326 | 326 | |
327 | - /** |
|
328 | - * Gets the batch request type indicated in the $_REQUEST |
|
329 | - * |
|
330 | - * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
331 | - */ |
|
332 | - public function batch_request_type() |
|
333 | - { |
|
334 | - if ($this->_batch_request_type === null) { |
|
335 | - if (isset($_GET['batch'])) { |
|
336 | - if ($_GET['batch'] == self::batch_job) { |
|
337 | - $this->_batch_request_type = self::batch_job; |
|
338 | - } elseif ($_GET['batch'] == self::batch_file_job) { |
|
339 | - $this->_batch_request_type = self::batch_file_job; |
|
340 | - } |
|
341 | - } |
|
342 | - // if we didn't find that it was a batch request, indicate it wasn't |
|
343 | - if ($this->_batch_request_type === null) { |
|
344 | - $this->_batch_request_type = self::batch_not_job; |
|
345 | - } |
|
346 | - } |
|
347 | - return $this->_batch_request_type; |
|
348 | - } |
|
327 | + /** |
|
328 | + * Gets the batch request type indicated in the $_REQUEST |
|
329 | + * |
|
330 | + * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
331 | + */ |
|
332 | + public function batch_request_type() |
|
333 | + { |
|
334 | + if ($this->_batch_request_type === null) { |
|
335 | + if (isset($_GET['batch'])) { |
|
336 | + if ($_GET['batch'] == self::batch_job) { |
|
337 | + $this->_batch_request_type = self::batch_job; |
|
338 | + } elseif ($_GET['batch'] == self::batch_file_job) { |
|
339 | + $this->_batch_request_type = self::batch_file_job; |
|
340 | + } |
|
341 | + } |
|
342 | + // if we didn't find that it was a batch request, indicate it wasn't |
|
343 | + if ($this->_batch_request_type === null) { |
|
344 | + $this->_batch_request_type = self::batch_not_job; |
|
345 | + } |
|
346 | + } |
|
347 | + return $this->_batch_request_type; |
|
348 | + } |
|
349 | 349 | |
350 | - /** |
|
351 | - * Unnecessary |
|
352 | - * |
|
353 | - * @param type $WP |
|
354 | - */ |
|
355 | - public function run($WP) |
|
356 | - { |
|
357 | - } |
|
350 | + /** |
|
351 | + * Unnecessary |
|
352 | + * |
|
353 | + * @param type $WP |
|
354 | + */ |
|
355 | + public function run($WP) |
|
356 | + { |
|
357 | + } |
|
358 | 358 | } |
@@ -13,339 +13,339 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @return Messages_Admin_Page |
|
18 | - */ |
|
19 | - public function get_admin_page() |
|
20 | - { |
|
21 | - return $this->_admin_page; |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Setup data object |
|
27 | - */ |
|
28 | - protected function _setup_data() |
|
29 | - { |
|
30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | - $this->_per_page, |
|
32 | - $this->_view, |
|
33 | - false |
|
34 | - ); |
|
35 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
36 | - $this->_per_page, |
|
37 | - $this->_view, |
|
38 | - true, |
|
39 | - true |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Set internal properties |
|
46 | - */ |
|
47 | - protected function _set_properties() |
|
48 | - { |
|
49 | - $this->_wp_list_args = array( |
|
50 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
51 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
52 | - 'ajax' => true, // for now, |
|
53 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
54 | - ); |
|
55 | - $this->_columns = array( |
|
56 | - // 'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
57 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
58 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
59 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
60 | - ); |
|
61 | - |
|
62 | - $this->_sortable_columns = array( |
|
63 | - 'messenger' => array('MTP_messenger' => true), |
|
64 | - ); |
|
65 | - |
|
66 | - $this->_hidden_columns = array(); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
72 | - * message_type or messenger object before generating the row. |
|
73 | - * |
|
74 | - * @param EE_Message_Template_Group $item |
|
75 | - * @return string |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public function single_row($item) |
|
79 | - { |
|
80 | - $message_type = $item->message_type_obj(); |
|
81 | - $messenger = $item->messenger_obj(); |
|
82 | - |
|
83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
84 | - echo ''; |
|
85 | - return; |
|
86 | - } |
|
87 | - |
|
88 | - parent::single_row($item); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return array |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - protected function _get_table_filters() |
|
97 | - { |
|
98 | - $filters = array(); |
|
99 | - |
|
100 | - // get select inputs |
|
101 | - $select_inputs = array( |
|
102 | - $this->_get_messengers_dropdown_filter(), |
|
103 | - $this->_get_message_types_dropdown_filter(), |
|
104 | - ); |
|
105 | - |
|
106 | - // set filters to select inputs if they aren't empty |
|
107 | - foreach ($select_inputs as $select_input) { |
|
108 | - if ($select_input) { |
|
109 | - $filters[] = $select_input; |
|
110 | - } |
|
111 | - } |
|
112 | - return $filters; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * We're just removing the search box for message templates, not needed. |
|
117 | - * |
|
118 | - * @param string $text |
|
119 | - * @param string $input_id |
|
120 | - * @return string ; |
|
121 | - */ |
|
122 | - public function search_box($text, $input_id) |
|
123 | - { |
|
124 | - return ''; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * Add counts to the _views property |
|
130 | - */ |
|
131 | - protected function _add_view_counts() |
|
132 | - { |
|
133 | - foreach ($this->_views as $view => $args) { |
|
134 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
135 | - $this->_per_page, |
|
136 | - $view, |
|
137 | - true, |
|
138 | - true |
|
139 | - ); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param EE_Message_Template_Group $item |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public function column_cb($item) |
|
149 | - { |
|
150 | - return ''; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param EE_Message_Template_Group $item |
|
156 | - * @return string |
|
157 | - * @throws EE_Error |
|
158 | - */ |
|
159 | - public function column_description($item) |
|
160 | - { |
|
161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param EE_Message_Template_Group $item |
|
167 | - * @return string |
|
168 | - * @throws EE_Error |
|
169 | - */ |
|
170 | - public function column_messenger($item) |
|
171 | - { |
|
172 | - // Return the name contents |
|
173 | - return sprintf( |
|
174 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s', |
|
175 | - /* $1%s */ |
|
176 | - ucwords($item->messenger_obj()->label['singular']), |
|
177 | - /* $2%s */ |
|
178 | - $item->GRP_ID(), |
|
179 | - /* %4$s */ |
|
180 | - $this->_get_context_links($item) |
|
181 | - ); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * column_message_type |
|
186 | - * |
|
187 | - * @param EE_Message_Template_Group $item message info for the row |
|
188 | - * @return string message_type name |
|
189 | - * @throws EE_Error |
|
190 | - */ |
|
191 | - public function column_message_type($item) |
|
192 | - { |
|
193 | - return ucwords($item->message_type_obj()->label['singular']); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * Generate dropdown filter select input for messengers |
|
199 | - * |
|
200 | - * @param bool $global |
|
201 | - * @return string |
|
202 | - * @throws EE_Error |
|
203 | - */ |
|
204 | - protected function _get_messengers_dropdown_filter($global = true) |
|
205 | - { |
|
206 | - $messenger_options = array(); |
|
207 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
208 | - array( |
|
209 | - array( |
|
210 | - 'MTP_is_active' => true, |
|
211 | - 'MTP_is_global' => $global, |
|
212 | - ), |
|
213 | - 'group_by' => 'MTP_messenger', |
|
214 | - ) |
|
215 | - ); |
|
216 | - |
|
217 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
218 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
219 | - $messenger = $active_message_template_group->messenger_obj(); |
|
220 | - $messenger_label = $messenger instanceof EE_messenger |
|
221 | - ? $messenger->label['singular'] |
|
222 | - : $active_message_template_group->messenger(); |
|
223 | - $messenger_options[ $active_message_template_group->messenger() ] = ucwords($messenger_label); |
|
224 | - } |
|
225 | - } |
|
226 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Generate dropdown filter select input for message types |
|
232 | - * |
|
233 | - * @param bool $global |
|
234 | - * @return string |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - protected function _get_message_types_dropdown_filter($global = true) |
|
238 | - { |
|
239 | - $message_type_options = array(); |
|
240 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
241 | - array( |
|
242 | - array( |
|
243 | - 'MTP_is_active' => true, |
|
244 | - 'MTP_is_global' => true, |
|
245 | - ), |
|
246 | - 'group_by' => 'MTP_message_type', |
|
247 | - ) |
|
248 | - ); |
|
249 | - |
|
250 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
251 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
252 | - $message_type = $active_message_template_group->message_type_obj(); |
|
253 | - $message_type_label = $message_type instanceof EE_message_type |
|
254 | - ? $message_type->label['singular'] |
|
255 | - : $active_message_template_group->message_type(); |
|
256 | - $message_type_options[ $active_message_template_group->message_type() ] = ucwords($message_type_label); |
|
257 | - } |
|
258 | - } |
|
259 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * Return the edit url for the message template group. |
|
265 | - * |
|
266 | - * @param EE_Message_Template_Group $item |
|
267 | - * @return string |
|
268 | - * @throws EE_Error |
|
269 | - */ |
|
270 | - protected function _get_edit_url(EE_Message_Template_Group $item) |
|
271 | - { |
|
272 | - $edit_url = ''; |
|
273 | - // edit link but only if item isn't trashed. |
|
274 | - if (! $item->get('MTP_deleted') |
|
275 | - && EE_Registry::instance()->CAP->current_user_can( |
|
276 | - 'ee_edit_message', |
|
277 | - 'espresso_messages_edit_message_template', |
|
278 | - $item->ID() |
|
279 | - )) { |
|
280 | - $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
281 | - array( |
|
282 | - 'action' => 'edit_message_template', |
|
283 | - 'id' => $item->GRP_ID(), |
|
284 | - ), |
|
285 | - EE_MSG_ADMIN_URL |
|
286 | - ); |
|
287 | - } |
|
288 | - return $edit_url; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Get the context link string for the messenger column. |
|
294 | - * |
|
295 | - * @param EE_Message_Template_Group $item |
|
296 | - * @return string |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - protected function _get_context_links(EE_Message_Template_Group $item) |
|
300 | - { |
|
301 | - // first check if we even show the context links or not. |
|
302 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
303 | - 'ee_edit_message', |
|
304 | - 'espresso_messages_edit_message_template', |
|
305 | - $item->ID() |
|
306 | - ) |
|
307 | - || $item->get('MTP_deleted') |
|
308 | - ) { |
|
309 | - return ''; |
|
310 | - } |
|
311 | - // we want to display the contexts in here so we need to set them up |
|
312 | - $c_label = $item->context_label(); |
|
313 | - $c_configs = $item->contexts_config(); |
|
314 | - $ctxt = array(); |
|
315 | - $context_templates = $item->context_templates(); |
|
316 | - foreach ($context_templates as $context => $template_fields) { |
|
317 | - $mtp_to = ! empty($context_templates[ $context ]['to']) |
|
318 | - && $context_templates[ $context ]['to'] instanceof EE_Message_Template |
|
319 | - ? $context_templates[ $context ]['to']->get('MTP_content') |
|
320 | - : null; |
|
321 | - $inactive_class = ( |
|
322 | - empty($mtp_to) |
|
323 | - && ! empty($context_templates[ $context ]['to']) |
|
324 | - ) |
|
325 | - || ! $item->is_context_active($context) |
|
326 | - ? ' mtp-inactive' |
|
327 | - : ''; |
|
328 | - $context_title = sprintf( |
|
329 | - /* translators: Placeholder represents the context label. Example "Edit Event Admin" */ |
|
330 | - esc_html__('Edit %1$s', 'event_espresso'), |
|
331 | - ucwords($c_configs[ $context ]['label']) |
|
332 | - ); |
|
333 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
334 | - array( |
|
335 | - 'action' => 'edit_message_template', |
|
336 | - 'id' => $item->GRP_ID(), |
|
337 | - 'context' => $context, |
|
338 | - ), |
|
339 | - EE_MSG_ADMIN_URL |
|
340 | - ); |
|
341 | - $ctxt[] = '<a' |
|
342 | - . ' href="' . $edit_link . '"' |
|
343 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' . $inactive_class . '"' |
|
344 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
345 | - . $context_title |
|
346 | - . '</a>'; |
|
347 | - } |
|
348 | - |
|
349 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
350 | - } |
|
16 | + /** |
|
17 | + * @return Messages_Admin_Page |
|
18 | + */ |
|
19 | + public function get_admin_page() |
|
20 | + { |
|
21 | + return $this->_admin_page; |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Setup data object |
|
27 | + */ |
|
28 | + protected function _setup_data() |
|
29 | + { |
|
30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | + $this->_per_page, |
|
32 | + $this->_view, |
|
33 | + false |
|
34 | + ); |
|
35 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
36 | + $this->_per_page, |
|
37 | + $this->_view, |
|
38 | + true, |
|
39 | + true |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Set internal properties |
|
46 | + */ |
|
47 | + protected function _set_properties() |
|
48 | + { |
|
49 | + $this->_wp_list_args = array( |
|
50 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
51 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
52 | + 'ajax' => true, // for now, |
|
53 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
54 | + ); |
|
55 | + $this->_columns = array( |
|
56 | + // 'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
57 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
58 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
59 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
60 | + ); |
|
61 | + |
|
62 | + $this->_sortable_columns = array( |
|
63 | + 'messenger' => array('MTP_messenger' => true), |
|
64 | + ); |
|
65 | + |
|
66 | + $this->_hidden_columns = array(); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
72 | + * message_type or messenger object before generating the row. |
|
73 | + * |
|
74 | + * @param EE_Message_Template_Group $item |
|
75 | + * @return string |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public function single_row($item) |
|
79 | + { |
|
80 | + $message_type = $item->message_type_obj(); |
|
81 | + $messenger = $item->messenger_obj(); |
|
82 | + |
|
83 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
84 | + echo ''; |
|
85 | + return; |
|
86 | + } |
|
87 | + |
|
88 | + parent::single_row($item); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + protected function _get_table_filters() |
|
97 | + { |
|
98 | + $filters = array(); |
|
99 | + |
|
100 | + // get select inputs |
|
101 | + $select_inputs = array( |
|
102 | + $this->_get_messengers_dropdown_filter(), |
|
103 | + $this->_get_message_types_dropdown_filter(), |
|
104 | + ); |
|
105 | + |
|
106 | + // set filters to select inputs if they aren't empty |
|
107 | + foreach ($select_inputs as $select_input) { |
|
108 | + if ($select_input) { |
|
109 | + $filters[] = $select_input; |
|
110 | + } |
|
111 | + } |
|
112 | + return $filters; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * We're just removing the search box for message templates, not needed. |
|
117 | + * |
|
118 | + * @param string $text |
|
119 | + * @param string $input_id |
|
120 | + * @return string ; |
|
121 | + */ |
|
122 | + public function search_box($text, $input_id) |
|
123 | + { |
|
124 | + return ''; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * Add counts to the _views property |
|
130 | + */ |
|
131 | + protected function _add_view_counts() |
|
132 | + { |
|
133 | + foreach ($this->_views as $view => $args) { |
|
134 | + $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
135 | + $this->_per_page, |
|
136 | + $view, |
|
137 | + true, |
|
138 | + true |
|
139 | + ); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param EE_Message_Template_Group $item |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public function column_cb($item) |
|
149 | + { |
|
150 | + return ''; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param EE_Message_Template_Group $item |
|
156 | + * @return string |
|
157 | + * @throws EE_Error |
|
158 | + */ |
|
159 | + public function column_description($item) |
|
160 | + { |
|
161 | + return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param EE_Message_Template_Group $item |
|
167 | + * @return string |
|
168 | + * @throws EE_Error |
|
169 | + */ |
|
170 | + public function column_messenger($item) |
|
171 | + { |
|
172 | + // Return the name contents |
|
173 | + return sprintf( |
|
174 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s', |
|
175 | + /* $1%s */ |
|
176 | + ucwords($item->messenger_obj()->label['singular']), |
|
177 | + /* $2%s */ |
|
178 | + $item->GRP_ID(), |
|
179 | + /* %4$s */ |
|
180 | + $this->_get_context_links($item) |
|
181 | + ); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * column_message_type |
|
186 | + * |
|
187 | + * @param EE_Message_Template_Group $item message info for the row |
|
188 | + * @return string message_type name |
|
189 | + * @throws EE_Error |
|
190 | + */ |
|
191 | + public function column_message_type($item) |
|
192 | + { |
|
193 | + return ucwords($item->message_type_obj()->label['singular']); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * Generate dropdown filter select input for messengers |
|
199 | + * |
|
200 | + * @param bool $global |
|
201 | + * @return string |
|
202 | + * @throws EE_Error |
|
203 | + */ |
|
204 | + protected function _get_messengers_dropdown_filter($global = true) |
|
205 | + { |
|
206 | + $messenger_options = array(); |
|
207 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
208 | + array( |
|
209 | + array( |
|
210 | + 'MTP_is_active' => true, |
|
211 | + 'MTP_is_global' => $global, |
|
212 | + ), |
|
213 | + 'group_by' => 'MTP_messenger', |
|
214 | + ) |
|
215 | + ); |
|
216 | + |
|
217 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
218 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
219 | + $messenger = $active_message_template_group->messenger_obj(); |
|
220 | + $messenger_label = $messenger instanceof EE_messenger |
|
221 | + ? $messenger->label['singular'] |
|
222 | + : $active_message_template_group->messenger(); |
|
223 | + $messenger_options[ $active_message_template_group->messenger() ] = ucwords($messenger_label); |
|
224 | + } |
|
225 | + } |
|
226 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Generate dropdown filter select input for message types |
|
232 | + * |
|
233 | + * @param bool $global |
|
234 | + * @return string |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + protected function _get_message_types_dropdown_filter($global = true) |
|
238 | + { |
|
239 | + $message_type_options = array(); |
|
240 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
241 | + array( |
|
242 | + array( |
|
243 | + 'MTP_is_active' => true, |
|
244 | + 'MTP_is_global' => true, |
|
245 | + ), |
|
246 | + 'group_by' => 'MTP_message_type', |
|
247 | + ) |
|
248 | + ); |
|
249 | + |
|
250 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
251 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
252 | + $message_type = $active_message_template_group->message_type_obj(); |
|
253 | + $message_type_label = $message_type instanceof EE_message_type |
|
254 | + ? $message_type->label['singular'] |
|
255 | + : $active_message_template_group->message_type(); |
|
256 | + $message_type_options[ $active_message_template_group->message_type() ] = ucwords($message_type_label); |
|
257 | + } |
|
258 | + } |
|
259 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * Return the edit url for the message template group. |
|
265 | + * |
|
266 | + * @param EE_Message_Template_Group $item |
|
267 | + * @return string |
|
268 | + * @throws EE_Error |
|
269 | + */ |
|
270 | + protected function _get_edit_url(EE_Message_Template_Group $item) |
|
271 | + { |
|
272 | + $edit_url = ''; |
|
273 | + // edit link but only if item isn't trashed. |
|
274 | + if (! $item->get('MTP_deleted') |
|
275 | + && EE_Registry::instance()->CAP->current_user_can( |
|
276 | + 'ee_edit_message', |
|
277 | + 'espresso_messages_edit_message_template', |
|
278 | + $item->ID() |
|
279 | + )) { |
|
280 | + $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
281 | + array( |
|
282 | + 'action' => 'edit_message_template', |
|
283 | + 'id' => $item->GRP_ID(), |
|
284 | + ), |
|
285 | + EE_MSG_ADMIN_URL |
|
286 | + ); |
|
287 | + } |
|
288 | + return $edit_url; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Get the context link string for the messenger column. |
|
294 | + * |
|
295 | + * @param EE_Message_Template_Group $item |
|
296 | + * @return string |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + protected function _get_context_links(EE_Message_Template_Group $item) |
|
300 | + { |
|
301 | + // first check if we even show the context links or not. |
|
302 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
303 | + 'ee_edit_message', |
|
304 | + 'espresso_messages_edit_message_template', |
|
305 | + $item->ID() |
|
306 | + ) |
|
307 | + || $item->get('MTP_deleted') |
|
308 | + ) { |
|
309 | + return ''; |
|
310 | + } |
|
311 | + // we want to display the contexts in here so we need to set them up |
|
312 | + $c_label = $item->context_label(); |
|
313 | + $c_configs = $item->contexts_config(); |
|
314 | + $ctxt = array(); |
|
315 | + $context_templates = $item->context_templates(); |
|
316 | + foreach ($context_templates as $context => $template_fields) { |
|
317 | + $mtp_to = ! empty($context_templates[ $context ]['to']) |
|
318 | + && $context_templates[ $context ]['to'] instanceof EE_Message_Template |
|
319 | + ? $context_templates[ $context ]['to']->get('MTP_content') |
|
320 | + : null; |
|
321 | + $inactive_class = ( |
|
322 | + empty($mtp_to) |
|
323 | + && ! empty($context_templates[ $context ]['to']) |
|
324 | + ) |
|
325 | + || ! $item->is_context_active($context) |
|
326 | + ? ' mtp-inactive' |
|
327 | + : ''; |
|
328 | + $context_title = sprintf( |
|
329 | + /* translators: Placeholder represents the context label. Example "Edit Event Admin" */ |
|
330 | + esc_html__('Edit %1$s', 'event_espresso'), |
|
331 | + ucwords($c_configs[ $context ]['label']) |
|
332 | + ); |
|
333 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
334 | + array( |
|
335 | + 'action' => 'edit_message_template', |
|
336 | + 'id' => $item->GRP_ID(), |
|
337 | + 'context' => $context, |
|
338 | + ), |
|
339 | + EE_MSG_ADMIN_URL |
|
340 | + ); |
|
341 | + $ctxt[] = '<a' |
|
342 | + . ' href="' . $edit_link . '"' |
|
343 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link' . $inactive_class . '"' |
|
344 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
345 | + . $context_title |
|
346 | + . '</a>'; |
|
347 | + } |
|
348 | + |
|
349 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
350 | + } |
|
351 | 351 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $message_type = $item->message_type_obj(); |
81 | 81 | $messenger = $item->messenger_obj(); |
82 | 82 | |
83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
83 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
84 | 84 | echo ''; |
85 | 85 | return; |
86 | 86 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | protected function _add_view_counts() |
132 | 132 | { |
133 | 133 | foreach ($this->_views as $view => $args) { |
134 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
134 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
135 | 135 | $this->_per_page, |
136 | 136 | $view, |
137 | 137 | true, |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function column_description($item) |
160 | 160 | { |
161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
161 | + return '<p>'.$item->message_type_obj()->description.'</p>'; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | $messenger_label = $messenger instanceof EE_messenger |
221 | 221 | ? $messenger->label['singular'] |
222 | 222 | : $active_message_template_group->messenger(); |
223 | - $messenger_options[ $active_message_template_group->messenger() ] = ucwords($messenger_label); |
|
223 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | $message_type_label = $message_type instanceof EE_message_type |
254 | 254 | ? $message_type->label['singular'] |
255 | 255 | : $active_message_template_group->message_type(); |
256 | - $message_type_options[ $active_message_template_group->message_type() ] = ucwords($message_type_label); |
|
256 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | { |
272 | 272 | $edit_url = ''; |
273 | 273 | // edit link but only if item isn't trashed. |
274 | - if (! $item->get('MTP_deleted') |
|
274 | + if ( ! $item->get('MTP_deleted') |
|
275 | 275 | && EE_Registry::instance()->CAP->current_user_can( |
276 | 276 | 'ee_edit_message', |
277 | 277 | 'espresso_messages_edit_message_template', |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | protected function _get_context_links(EE_Message_Template_Group $item) |
300 | 300 | { |
301 | 301 | // first check if we even show the context links or not. |
302 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
302 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
303 | 303 | 'ee_edit_message', |
304 | 304 | 'espresso_messages_edit_message_template', |
305 | 305 | $item->ID() |
@@ -314,13 +314,13 @@ discard block |
||
314 | 314 | $ctxt = array(); |
315 | 315 | $context_templates = $item->context_templates(); |
316 | 316 | foreach ($context_templates as $context => $template_fields) { |
317 | - $mtp_to = ! empty($context_templates[ $context ]['to']) |
|
318 | - && $context_templates[ $context ]['to'] instanceof EE_Message_Template |
|
319 | - ? $context_templates[ $context ]['to']->get('MTP_content') |
|
317 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
318 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
319 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
320 | 320 | : null; |
321 | 321 | $inactive_class = ( |
322 | 322 | empty($mtp_to) |
323 | - && ! empty($context_templates[ $context ]['to']) |
|
323 | + && ! empty($context_templates[$context]['to']) |
|
324 | 324 | ) |
325 | 325 | || ! $item->is_context_active($context) |
326 | 326 | ? ' mtp-inactive' |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | $context_title = sprintf( |
329 | 329 | /* translators: Placeholder represents the context label. Example "Edit Event Admin" */ |
330 | 330 | esc_html__('Edit %1$s', 'event_espresso'), |
331 | - ucwords($c_configs[ $context ]['label']) |
|
331 | + ucwords($c_configs[$context]['label']) |
|
332 | 332 | ); |
333 | 333 | $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
334 | 334 | array( |
@@ -339,13 +339,13 @@ discard block |
||
339 | 339 | EE_MSG_ADMIN_URL |
340 | 340 | ); |
341 | 341 | $ctxt[] = '<a' |
342 | - . ' href="' . $edit_link . '"' |
|
343 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' . $inactive_class . '"' |
|
344 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
342 | + . ' href="'.$edit_link.'"' |
|
343 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link'.$inactive_class.'"' |
|
344 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
345 | 345 | . $context_title |
346 | 346 | . '</a>'; |
347 | 347 | } |
348 | 348 | |
349 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
349 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])).implode(' | ', $ctxt); |
|
350 | 350 | } |
351 | 351 | } |