@@ -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 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.76.rc.024'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.76.rc.024'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -18,332 +18,332 @@ |
||
18 | 18 | class EED_Recaptcha_Invisible extends EED_Module |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Registration_Config $config |
|
23 | - */ |
|
24 | - private static $config; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * @return EED_Module|EED_Recaptcha |
|
29 | - */ |
|
30 | - public static function instance() |
|
31 | - { |
|
32 | - return parent::get_instance(__CLASS__); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @return void |
|
38 | - * @throws InvalidInterfaceException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidArgumentException |
|
41 | - */ |
|
42 | - public static function set_hooks() |
|
43 | - { |
|
44 | - EED_Recaptcha_Invisible::setProperties(); |
|
45 | - if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
46 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
47 | - // ticket selection |
|
48 | - add_filter( |
|
49 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
50 | - array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
51 | - 10, |
|
52 | - 3 |
|
53 | - ); |
|
54 | - add_action( |
|
55 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
56 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
57 | - ); |
|
58 | - } |
|
59 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
60 | - // checkout |
|
61 | - add_action( |
|
62 | - 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
63 | - array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
64 | - ); |
|
65 | - add_filter( |
|
66 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
67 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
68 | - 10, |
|
69 | - 2 |
|
70 | - ); |
|
71 | - } |
|
72 | - add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return void |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - * @throws InvalidArgumentException |
|
82 | - */ |
|
83 | - public static function set_hooks_admin() |
|
84 | - { |
|
85 | - EED_Recaptcha_Invisible::setProperties(); |
|
86 | - if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
87 | - add_action( |
|
88 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
89 | - array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
90 | - ); |
|
91 | - } |
|
92 | - if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
93 | - add_filter( |
|
94 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
95 | - array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
96 | - 10, |
|
97 | - 2 |
|
98 | - ); |
|
99 | - } |
|
100 | - // admin settings |
|
101 | - add_action( |
|
102 | - 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | - array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | - ); |
|
105 | - add_filter( |
|
106 | - 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | - array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return void |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws InvalidArgumentException |
|
117 | - */ |
|
118 | - public static function setProperties() |
|
119 | - { |
|
120 | - |
|
121 | - EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return boolean |
|
127 | - */ |
|
128 | - public static function useInvisibleRecaptcha() |
|
129 | - { |
|
130 | - return EED_Recaptcha_Invisible::$config->use_captcha |
|
131 | - && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param string $form |
|
137 | - * @return boolean |
|
138 | - */ |
|
139 | - public static function protectForm($form) |
|
140 | - { |
|
141 | - return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
142 | - && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return void |
|
148 | - * @throws InvalidInterfaceException |
|
149 | - * @throws InvalidDataTypeException |
|
150 | - * @throws InvalidArgumentException |
|
151 | - */ |
|
152 | - public static function localizeScriptVars() |
|
153 | - { |
|
154 | - /** @var \EventEspresso\core\services\request\Request $request */ |
|
155 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
156 | - // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
157 | - // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
158 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
159 | - return; |
|
160 | - } |
|
161 | - wp_localize_script( |
|
162 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
163 | - 'eeRecaptcha', |
|
164 | - RecaptchaFactory::create()->getLocalizedVars() |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return string |
|
171 | - */ |
|
172 | - public static function assetsUrl() |
|
173 | - { |
|
174 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param \WP $WP |
|
180 | - */ |
|
181 | - public function run($WP) |
|
182 | - { |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param RequestInterface $request |
|
188 | - * @return bool |
|
189 | - * @throws InvalidArgumentException |
|
190 | - * @throws InvalidDataTypeException |
|
191 | - * @throws InvalidInterfaceException |
|
192 | - * @throws RuntimeException |
|
193 | - */ |
|
194 | - public static function verifyToken(RequestInterface $request) |
|
195 | - { |
|
196 | - return RecaptchaFactory::create()->verifyToken($request); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param EE_Form_Section_Proper $reg_form |
|
202 | - * @return void |
|
203 | - * @throws EE_Error |
|
204 | - * @throws InvalidArgumentException |
|
205 | - * @throws InvalidDataTypeException |
|
206 | - * @throws InvalidInterfaceException |
|
207 | - * @throws DomainException |
|
208 | - */ |
|
209 | - public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
210 | - { |
|
211 | - // do nothing if form isn't for a reg step or test has already been passed |
|
212 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
213 | - return; |
|
214 | - } |
|
215 | - $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
216 | - if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
217 | - $invisible_recaptcha = RecaptchaFactory::create(); |
|
218 | - $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * @param EE_Form_Section_Proper $reg_form |
|
225 | - * @return bool |
|
226 | - * @throws InvalidDataTypeException |
|
227 | - * @throws InvalidInterfaceException |
|
228 | - * @throws EE_Error |
|
229 | - * @throws InvalidArgumentException |
|
230 | - */ |
|
231 | - public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
232 | - { |
|
233 | - return strpos($reg_form->name(), 'reg-step-form') !== false |
|
234 | - && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param array|null $req_data |
|
240 | - * @param EE_Form_Section_Proper $reg_form |
|
241 | - * @return array |
|
242 | - * @throws EE_Error |
|
243 | - * @throws InvalidArgumentException |
|
244 | - * @throws InvalidDataTypeException |
|
245 | - * @throws InvalidInterfaceException |
|
246 | - * @throws RuntimeException |
|
247 | - */ |
|
248 | - public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
249 | - { |
|
250 | - // do nothing if form isn't for a reg step or test has already been passed |
|
251 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
252 | - return $req_data; |
|
253 | - } |
|
254 | - /** @var RequestInterface $request */ |
|
255 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
256 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
257 | - if ($request->isAjax()) { |
|
258 | - $json_response = new EE_SPCO_JSON_Response(); |
|
259 | - $json_response->echoAndExit(); |
|
260 | - } |
|
261 | - EEH_URL::safeRedirectAndExit( |
|
262 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
263 | - ); |
|
264 | - } |
|
265 | - return $req_data; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @param string $html |
|
271 | - * @param EE_Event $event |
|
272 | - * @param bool $iframe |
|
273 | - * @return string |
|
274 | - * @throws EE_Error |
|
275 | - * @throws InvalidArgumentException |
|
276 | - * @throws InvalidDataTypeException |
|
277 | - * @throws InvalidInterfaceException |
|
278 | - * @throws ReflectionException |
|
279 | - * @throws DomainException |
|
280 | - */ |
|
281 | - public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
282 | - { |
|
283 | - $recaptcha = RecaptchaFactory::create(); |
|
284 | - // do nothing if test has already been passed |
|
285 | - if ($recaptcha->recaptchaPassed()) { |
|
286 | - return $html; |
|
287 | - } |
|
288 | - $html .= $recaptcha->getInputHtml( |
|
289 | - array( |
|
290 | - 'recaptcha_id' => $event->ID(), |
|
291 | - 'iframe' => $iframe, |
|
292 | - 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
293 | - ) |
|
294 | - ); |
|
295 | - return $html; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @return void |
|
301 | - * @throws InvalidArgumentException |
|
302 | - * @throws InvalidInterfaceException |
|
303 | - * @throws InvalidDataTypeException |
|
304 | - * @throws RuntimeException |
|
305 | - */ |
|
306 | - public static function processTicketSelectorForm() |
|
307 | - { |
|
308 | - // do nothing if test has already been passed |
|
309 | - if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
310 | - return; |
|
311 | - } |
|
312 | - /** @var RequestInterface $request */ |
|
313 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
314 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | - $event_id = $request->getRequestParam('tkt-slctr-event-id'); |
|
316 | - $return_url = $request->requestParamIsSet("tkt-slctr-return-url-{$event_id}") |
|
317 | - ? $request->getRequestParam("tkt-slctr-return-url-{$event_id}") |
|
318 | - : get_permalink($event_id); |
|
319 | - EEH_URL::safeRedirectAndExit($return_url); |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * @throws EE_Error |
|
326 | - * @throws InvalidArgumentException |
|
327 | - * @throws InvalidDataTypeException |
|
328 | - * @throws InvalidInterfaceException |
|
329 | - */ |
|
330 | - public static function adminSettings() |
|
331 | - { |
|
332 | - RecaptchaFactory::getAdminModule()->adminSettings(); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @param EE_Registration_Config $EE_Registration_Config |
|
338 | - * @return EE_Registration_Config |
|
339 | - * @throws EE_Error |
|
340 | - * @throws InvalidArgumentException |
|
341 | - * @throws InvalidDataTypeException |
|
342 | - * @throws InvalidInterfaceException |
|
343 | - * @throws ReflectionException |
|
344 | - */ |
|
345 | - public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
346 | - { |
|
347 | - return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
348 | - } |
|
21 | + /** |
|
22 | + * @var EE_Registration_Config $config |
|
23 | + */ |
|
24 | + private static $config; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * @return EED_Module|EED_Recaptcha |
|
29 | + */ |
|
30 | + public static function instance() |
|
31 | + { |
|
32 | + return parent::get_instance(__CLASS__); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + * @throws InvalidInterfaceException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidArgumentException |
|
41 | + */ |
|
42 | + public static function set_hooks() |
|
43 | + { |
|
44 | + EED_Recaptcha_Invisible::setProperties(); |
|
45 | + if (EED_Recaptcha_Invisible::useInvisibleRecaptcha()) { |
|
46 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
47 | + // ticket selection |
|
48 | + add_filter( |
|
49 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
50 | + array('EED_Recaptcha_Invisible', 'ticketSelectorForm'), |
|
51 | + 10, |
|
52 | + 3 |
|
53 | + ); |
|
54 | + add_action( |
|
55 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
56 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
57 | + ); |
|
58 | + } |
|
59 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
60 | + // checkout |
|
61 | + add_action( |
|
62 | + 'AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', |
|
63 | + array('EED_Recaptcha_Invisible', 'spcoRegStepForm') |
|
64 | + ); |
|
65 | + add_filter( |
|
66 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
67 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
68 | + 10, |
|
69 | + 2 |
|
70 | + ); |
|
71 | + } |
|
72 | + add_action('loop_end', array('EED_Recaptcha_Invisible', 'localizeScriptVars')); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + * @throws InvalidArgumentException |
|
82 | + */ |
|
83 | + public static function set_hooks_admin() |
|
84 | + { |
|
85 | + EED_Recaptcha_Invisible::setProperties(); |
|
86 | + if (EED_Recaptcha_Invisible::protectForm('ticket_selector')) { |
|
87 | + add_action( |
|
88 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
89 | + array('EED_Recaptcha_Invisible', 'processTicketSelectorForm') |
|
90 | + ); |
|
91 | + } |
|
92 | + if (EED_Recaptcha_Invisible::protectForm('registration_form')) { |
|
93 | + add_filter( |
|
94 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', |
|
95 | + array('EED_Recaptcha_Invisible', 'receiveSpcoRegStepForm'), |
|
96 | + 10, |
|
97 | + 2 |
|
98 | + ); |
|
99 | + } |
|
100 | + // admin settings |
|
101 | + add_action( |
|
102 | + 'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template', |
|
103 | + array('EED_Recaptcha_Invisible', 'adminSettings') |
|
104 | + ); |
|
105 | + add_filter( |
|
106 | + 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', |
|
107 | + array('EED_Recaptcha_Invisible', 'updateAdminSettings') |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws InvalidArgumentException |
|
117 | + */ |
|
118 | + public static function setProperties() |
|
119 | + { |
|
120 | + |
|
121 | + EED_Recaptcha_Invisible::$config = EE_Registry::instance()->CFG->registration; |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return boolean |
|
127 | + */ |
|
128 | + public static function useInvisibleRecaptcha() |
|
129 | + { |
|
130 | + return EED_Recaptcha_Invisible::$config->use_captcha |
|
131 | + && EED_Recaptcha_Invisible::$config->recaptcha_theme === 'invisible'; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param string $form |
|
137 | + * @return boolean |
|
138 | + */ |
|
139 | + public static function protectForm($form) |
|
140 | + { |
|
141 | + return is_array(EED_Recaptcha_Invisible::$config->recaptcha_protected_forms) |
|
142 | + && in_array($form, EED_Recaptcha_Invisible::$config->recaptcha_protected_forms, true); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return void |
|
148 | + * @throws InvalidInterfaceException |
|
149 | + * @throws InvalidDataTypeException |
|
150 | + * @throws InvalidArgumentException |
|
151 | + */ |
|
152 | + public static function localizeScriptVars() |
|
153 | + { |
|
154 | + /** @var \EventEspresso\core\services\request\Request $request */ |
|
155 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
156 | + // Invisible Recaptcha is ONLY ever required for the frontend and admin |
|
157 | + // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
|
158 | + if (! ($request->isAdmin() || $request->isFrontend())) { |
|
159 | + return; |
|
160 | + } |
|
161 | + wp_localize_script( |
|
162 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
163 | + 'eeRecaptcha', |
|
164 | + RecaptchaFactory::create()->getLocalizedVars() |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return string |
|
171 | + */ |
|
172 | + public static function assetsUrl() |
|
173 | + { |
|
174 | + return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param \WP $WP |
|
180 | + */ |
|
181 | + public function run($WP) |
|
182 | + { |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param RequestInterface $request |
|
188 | + * @return bool |
|
189 | + * @throws InvalidArgumentException |
|
190 | + * @throws InvalidDataTypeException |
|
191 | + * @throws InvalidInterfaceException |
|
192 | + * @throws RuntimeException |
|
193 | + */ |
|
194 | + public static function verifyToken(RequestInterface $request) |
|
195 | + { |
|
196 | + return RecaptchaFactory::create()->verifyToken($request); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param EE_Form_Section_Proper $reg_form |
|
202 | + * @return void |
|
203 | + * @throws EE_Error |
|
204 | + * @throws InvalidArgumentException |
|
205 | + * @throws InvalidDataTypeException |
|
206 | + * @throws InvalidInterfaceException |
|
207 | + * @throws DomainException |
|
208 | + */ |
|
209 | + public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
210 | + { |
|
211 | + // do nothing if form isn't for a reg step or test has already been passed |
|
212 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
213 | + return; |
|
214 | + } |
|
215 | + $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
|
216 | + if ($default_hidden_inputs instanceof EE_Form_Section_Proper) { |
|
217 | + $invisible_recaptcha = RecaptchaFactory::create(); |
|
218 | + $invisible_recaptcha->addToFormSection($default_hidden_inputs); |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * @param EE_Form_Section_Proper $reg_form |
|
225 | + * @return bool |
|
226 | + * @throws InvalidDataTypeException |
|
227 | + * @throws InvalidInterfaceException |
|
228 | + * @throws EE_Error |
|
229 | + * @throws InvalidArgumentException |
|
230 | + */ |
|
231 | + public static function processSpcoRegStepForm(EE_Form_Section_Proper $reg_form) |
|
232 | + { |
|
233 | + return strpos($reg_form->name(), 'reg-step-form') !== false |
|
234 | + && ! RecaptchaFactory::create()->recaptchaPassed(); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param array|null $req_data |
|
240 | + * @param EE_Form_Section_Proper $reg_form |
|
241 | + * @return array |
|
242 | + * @throws EE_Error |
|
243 | + * @throws InvalidArgumentException |
|
244 | + * @throws InvalidDataTypeException |
|
245 | + * @throws InvalidInterfaceException |
|
246 | + * @throws RuntimeException |
|
247 | + */ |
|
248 | + public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
|
249 | + { |
|
250 | + // do nothing if form isn't for a reg step or test has already been passed |
|
251 | + if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
252 | + return $req_data; |
|
253 | + } |
|
254 | + /** @var RequestInterface $request */ |
|
255 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
256 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
257 | + if ($request->isAjax()) { |
|
258 | + $json_response = new EE_SPCO_JSON_Response(); |
|
259 | + $json_response->echoAndExit(); |
|
260 | + } |
|
261 | + EEH_URL::safeRedirectAndExit( |
|
262 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
263 | + ); |
|
264 | + } |
|
265 | + return $req_data; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @param string $html |
|
271 | + * @param EE_Event $event |
|
272 | + * @param bool $iframe |
|
273 | + * @return string |
|
274 | + * @throws EE_Error |
|
275 | + * @throws InvalidArgumentException |
|
276 | + * @throws InvalidDataTypeException |
|
277 | + * @throws InvalidInterfaceException |
|
278 | + * @throws ReflectionException |
|
279 | + * @throws DomainException |
|
280 | + */ |
|
281 | + public static function ticketSelectorForm($html = '', EE_Event $event, $iframe = false) |
|
282 | + { |
|
283 | + $recaptcha = RecaptchaFactory::create(); |
|
284 | + // do nothing if test has already been passed |
|
285 | + if ($recaptcha->recaptchaPassed()) { |
|
286 | + return $html; |
|
287 | + } |
|
288 | + $html .= $recaptcha->getInputHtml( |
|
289 | + array( |
|
290 | + 'recaptcha_id' => $event->ID(), |
|
291 | + 'iframe' => $iframe, |
|
292 | + 'localized_vars' => $recaptcha->getLocalizedVars(), |
|
293 | + ) |
|
294 | + ); |
|
295 | + return $html; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @return void |
|
301 | + * @throws InvalidArgumentException |
|
302 | + * @throws InvalidInterfaceException |
|
303 | + * @throws InvalidDataTypeException |
|
304 | + * @throws RuntimeException |
|
305 | + */ |
|
306 | + public static function processTicketSelectorForm() |
|
307 | + { |
|
308 | + // do nothing if test has already been passed |
|
309 | + if (RecaptchaFactory::create()->recaptchaPassed()) { |
|
310 | + return; |
|
311 | + } |
|
312 | + /** @var RequestInterface $request */ |
|
313 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
314 | + if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | + $event_id = $request->getRequestParam('tkt-slctr-event-id'); |
|
316 | + $return_url = $request->requestParamIsSet("tkt-slctr-return-url-{$event_id}") |
|
317 | + ? $request->getRequestParam("tkt-slctr-return-url-{$event_id}") |
|
318 | + : get_permalink($event_id); |
|
319 | + EEH_URL::safeRedirectAndExit($return_url); |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * @throws EE_Error |
|
326 | + * @throws InvalidArgumentException |
|
327 | + * @throws InvalidDataTypeException |
|
328 | + * @throws InvalidInterfaceException |
|
329 | + */ |
|
330 | + public static function adminSettings() |
|
331 | + { |
|
332 | + RecaptchaFactory::getAdminModule()->adminSettings(); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @param EE_Registration_Config $EE_Registration_Config |
|
338 | + * @return EE_Registration_Config |
|
339 | + * @throws EE_Error |
|
340 | + * @throws InvalidArgumentException |
|
341 | + * @throws InvalidDataTypeException |
|
342 | + * @throws InvalidInterfaceException |
|
343 | + * @throws ReflectionException |
|
344 | + */ |
|
345 | + public static function updateAdminSettings(EE_Registration_Config $EE_Registration_Config) |
|
346 | + { |
|
347 | + return RecaptchaFactory::getAdminModule()->updateAdminSettings($EE_Registration_Config); |
|
348 | + } |
|
349 | 349 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
156 | 156 | // Invisible Recaptcha is ONLY ever required for the frontend and admin |
157 | 157 | // so we don't need to load any JS assets for other types of requests (like AJAX or API). |
158 | - if (! ($request->isAdmin() || $request->isFrontend())) { |
|
158 | + if ( ! ($request->isAdmin() || $request->isFrontend())) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | 161 | wp_localize_script( |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public static function assetsUrl() |
173 | 173 | { |
174 | - return plugin_dir_url(__FILE__) . 'assets' . DS; |
|
174 | + return plugin_dir_url(__FILE__).'assets'.DS; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | public static function spcoRegStepForm(EE_Form_Section_Proper $reg_form) |
210 | 210 | { |
211 | 211 | // do nothing if form isn't for a reg step or test has already been passed |
212 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
212 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | $default_hidden_inputs = $reg_form->get_subsection('default_hidden_inputs'); |
@@ -248,12 +248,12 @@ discard block |
||
248 | 248 | public static function receiveSpcoRegStepForm($req_data = array(), EE_Form_Section_Proper $reg_form) |
249 | 249 | { |
250 | 250 | // do nothing if form isn't for a reg step or test has already been passed |
251 | - if (! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
251 | + if ( ! EED_Recaptcha_Invisible::processSpcoRegStepForm($reg_form)) { |
|
252 | 252 | return $req_data; |
253 | 253 | } |
254 | 254 | /** @var RequestInterface $request */ |
255 | 255 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
256 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
256 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
257 | 257 | if ($request->isAjax()) { |
258 | 258 | $json_response = new EE_SPCO_JSON_Response(); |
259 | 259 | $json_response->echoAndExit(); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | } |
312 | 312 | /** @var RequestInterface $request */ |
313 | 313 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
314 | - if (! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
314 | + if ( ! EED_Recaptcha_Invisible::verifyToken($request)) { |
|
315 | 315 | $event_id = $request->getRequestParam('tkt-slctr-event-id'); |
316 | 316 | $return_url = $request->requestParamIsSet("tkt-slctr-return-url-{$event_id}") |
317 | 317 | ? $request->getRequestParam("tkt-slctr-return-url-{$event_id}") |