@@ -63,8 +63,8 @@ |
||
63 | 63 | */ |
64 | 64 | public function generate_new_settings_form() |
65 | 65 | { |
66 | - require_once($this->file_folder() . 'EE_Paypal_Standard_Form.form.php'); |
|
67 | - $form = new EE_Paypal_Standard_Form($this); |
|
66 | + require_once($this->file_folder().'EE_Paypal_Standard_Form.form.php'); |
|
67 | + $form = new EE_Paypal_Standard_Form($this); |
|
68 | 68 | $form->get_input('PMD_debug_mode')->set_html_label_text( |
69 | 69 | sprintf(__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link()) |
70 | 70 | ); |
@@ -13,105 +13,105 @@ |
||
13 | 13 | class EE_PMT_Paypal_Standard extends EE_PMT_Base |
14 | 14 | { |
15 | 15 | |
16 | - const shipping_info_none = 1; |
|
17 | - const shipping_info_optional = 0; |
|
18 | - const shipping_info_required = 2; |
|
19 | - |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * @param null $pm_instance |
|
24 | - * @return \EE_PMT_Paypal_Standard |
|
25 | - * @throws \EE_Error |
|
26 | - */ |
|
27 | - public function __construct($pm_instance = null) |
|
28 | - { |
|
29 | - require_once($this->file_folder().'EEG_Paypal_Standard.gateway.php'); |
|
30 | - $this->_gateway = new EEG_Paypal_Standard(); |
|
31 | - $this->_pretty_name = __("PayPal Standard", 'event_espresso'); |
|
32 | - $this->_default_description = sprintf( |
|
33 | - __( |
|
34 | - 'Upon submitting this form, you will be forwarded to PayPal to make your payment. %1$sMake sure you return to this site in order to properly finalize your registration.%2$s', |
|
35 | - 'event_espresso' |
|
36 | - ), |
|
37 | - '<strong>', |
|
38 | - '</strong>' |
|
39 | - ); |
|
40 | - parent::__construct($pm_instance); |
|
41 | - $this->_default_button_url = $this->file_url().'lib/paypal-logo.png'; |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Creates the billing form for this payment method type |
|
48 | - * @param \EE_Transaction $transaction |
|
49 | - * @return NULL |
|
50 | - */ |
|
51 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
52 | - { |
|
53 | - return null; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * Gets the form for all the settings related to this payment method type |
|
60 | - * |
|
61 | - * @return EE_Payment_Method_Form |
|
62 | - * @throws \EE_Error |
|
63 | - */ |
|
64 | - public function generate_new_settings_form() |
|
65 | - { |
|
66 | - require_once($this->file_folder() . 'EE_Paypal_Standard_Form.form.php'); |
|
67 | - $form = new EE_Paypal_Standard_Form($this); |
|
68 | - $form->get_input('PMD_debug_mode')->set_html_label_text( |
|
69 | - sprintf(__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link()) |
|
70 | - ); |
|
71 | - $form->get_input('shipping_details')->set_html_label_text( |
|
72 | - sprintf(__("Shipping Address Options %s", "event_espresso"), $this->get_help_tab_link()) |
|
73 | - ); |
|
74 | - return $form; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Adds the help tab |
|
81 | - * @see EE_PMT_Base::help_tabs_config() |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function help_tabs_config() |
|
85 | - { |
|
86 | - return array( |
|
87 | - $this->get_help_tab_name() => array( |
|
88 | - 'title'=> __("PayPal Standard Settings", 'event_espresso'), |
|
89 | - 'filename'=>'payment_methods_overview_paypalstandard' |
|
90 | - ) |
|
91 | - ); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Logic to be accomplished when the payment attempt is complete. |
|
98 | - * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
99 | - * (Mijireh was an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
100 | - * Mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
101 | - * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
102 | - * |
|
103 | - * @param EE_Transaction $transaction |
|
104 | - * @return EE_Payment |
|
105 | - * @throws \EE_Error |
|
106 | - */ |
|
107 | - public function finalize_payment_for($transaction) |
|
108 | - { |
|
109 | - // PayPal standard actually sends the IPN info along with the user when they return to our site |
|
110 | - // so in case the IPN is arriving later, let's try to process an IPN! |
|
111 | - if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
112 | - return $this->handle_ipn($_POST, $transaction); |
|
113 | - } else { |
|
114 | - return parent::finalize_payment_for($transaction); |
|
115 | - } |
|
116 | - } |
|
16 | + const shipping_info_none = 1; |
|
17 | + const shipping_info_optional = 0; |
|
18 | + const shipping_info_required = 2; |
|
19 | + |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * @param null $pm_instance |
|
24 | + * @return \EE_PMT_Paypal_Standard |
|
25 | + * @throws \EE_Error |
|
26 | + */ |
|
27 | + public function __construct($pm_instance = null) |
|
28 | + { |
|
29 | + require_once($this->file_folder().'EEG_Paypal_Standard.gateway.php'); |
|
30 | + $this->_gateway = new EEG_Paypal_Standard(); |
|
31 | + $this->_pretty_name = __("PayPal Standard", 'event_espresso'); |
|
32 | + $this->_default_description = sprintf( |
|
33 | + __( |
|
34 | + 'Upon submitting this form, you will be forwarded to PayPal to make your payment. %1$sMake sure you return to this site in order to properly finalize your registration.%2$s', |
|
35 | + 'event_espresso' |
|
36 | + ), |
|
37 | + '<strong>', |
|
38 | + '</strong>' |
|
39 | + ); |
|
40 | + parent::__construct($pm_instance); |
|
41 | + $this->_default_button_url = $this->file_url().'lib/paypal-logo.png'; |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Creates the billing form for this payment method type |
|
48 | + * @param \EE_Transaction $transaction |
|
49 | + * @return NULL |
|
50 | + */ |
|
51 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
52 | + { |
|
53 | + return null; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * Gets the form for all the settings related to this payment method type |
|
60 | + * |
|
61 | + * @return EE_Payment_Method_Form |
|
62 | + * @throws \EE_Error |
|
63 | + */ |
|
64 | + public function generate_new_settings_form() |
|
65 | + { |
|
66 | + require_once($this->file_folder() . 'EE_Paypal_Standard_Form.form.php'); |
|
67 | + $form = new EE_Paypal_Standard_Form($this); |
|
68 | + $form->get_input('PMD_debug_mode')->set_html_label_text( |
|
69 | + sprintf(__("Use PayPal Sandbox %s", 'event_espresso'), $this->get_help_tab_link()) |
|
70 | + ); |
|
71 | + $form->get_input('shipping_details')->set_html_label_text( |
|
72 | + sprintf(__("Shipping Address Options %s", "event_espresso"), $this->get_help_tab_link()) |
|
73 | + ); |
|
74 | + return $form; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Adds the help tab |
|
81 | + * @see EE_PMT_Base::help_tabs_config() |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function help_tabs_config() |
|
85 | + { |
|
86 | + return array( |
|
87 | + $this->get_help_tab_name() => array( |
|
88 | + 'title'=> __("PayPal Standard Settings", 'event_espresso'), |
|
89 | + 'filename'=>'payment_methods_overview_paypalstandard' |
|
90 | + ) |
|
91 | + ); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Logic to be accomplished when the payment attempt is complete. |
|
98 | + * Most payment methods don't need to do anything at this point; but some, like Mijireh, do. |
|
99 | + * (Mijireh was an offsite gateway which doesn't send an IPN. So when the user returns to EE from |
|
100 | + * Mijireh, this method needs to be called so the Mijireh PM can ping Mijireh to know the status |
|
101 | + * of the payment). Fed a transaction because it's always assumed to be the last payment that |
|
102 | + * |
|
103 | + * @param EE_Transaction $transaction |
|
104 | + * @return EE_Payment |
|
105 | + * @throws \EE_Error |
|
106 | + */ |
|
107 | + public function finalize_payment_for($transaction) |
|
108 | + { |
|
109 | + // PayPal standard actually sends the IPN info along with the user when they return to our site |
|
110 | + // so in case the IPN is arriving later, let's try to process an IPN! |
|
111 | + if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
|
112 | + return $this->handle_ipn($_POST, $transaction); |
|
113 | + } else { |
|
114 | + return parent::finalize_payment_for($transaction); |
|
115 | + } |
|
116 | + } |
|
117 | 117 | } |
@@ -19,605 +19,605 @@ |
||
19 | 19 | class EEG_Paypal_Standard extends EE_Offsite_Gateway |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Name for the wp option used to save the itemized payment |
|
24 | - */ |
|
25 | - const itemized_payment_option_name = '_itemized_payment'; |
|
26 | - |
|
27 | - protected $_paypal_id; |
|
28 | - |
|
29 | - protected $_image_url; |
|
30 | - |
|
31 | - protected $_shipping_details; |
|
32 | - |
|
33 | - protected $_paypal_shipping; |
|
34 | - |
|
35 | - protected $_paypal_taxes; |
|
36 | - |
|
37 | - protected $_gateway_url; |
|
38 | - |
|
39 | - protected $_currencies_supported = array( |
|
40 | - 'USD', |
|
41 | - 'GBP', |
|
42 | - 'CAD', |
|
43 | - 'AUD', |
|
44 | - 'BRL', |
|
45 | - 'CHF', |
|
46 | - 'CZK', |
|
47 | - 'DKK', |
|
48 | - 'EUR', |
|
49 | - 'HKD', |
|
50 | - 'HUF', |
|
51 | - 'ILS', |
|
52 | - 'JPY', |
|
53 | - 'MXN', |
|
54 | - 'MYR', |
|
55 | - 'NOK', |
|
56 | - 'NZD', |
|
57 | - 'PHP', |
|
58 | - 'PLN', |
|
59 | - 'SEK', |
|
60 | - 'SGD', |
|
61 | - 'THB', |
|
62 | - 'TRY', |
|
63 | - 'TWD', |
|
64 | - 'RUB' |
|
65 | - ); |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * EEG_Paypal_Standard constructor. |
|
70 | - * |
|
71 | - * @return EEG_Paypal_Standard |
|
72 | - */ |
|
73 | - public function __construct() |
|
74 | - { |
|
75 | - $this->set_uses_separate_IPN_request(true); |
|
76 | - parent::__construct(); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
82 | - * |
|
83 | - * @param array $settings_array |
|
84 | - */ |
|
85 | - public function set_settings($settings_array) |
|
86 | - { |
|
87 | - parent::set_settings($settings_array); |
|
88 | - $this->_gateway_url = $this->_debug_mode |
|
89 | - ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
90 | - : 'https://www.paypal.com/cgi-bin/webscr'; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @param EEI_Payment $payment the payment to process |
|
96 | - * @param array $billing_info but should be empty for this gateway |
|
97 | - * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
98 | - * @param string $notify_url URL to send the instant payment notification |
|
99 | - * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
100 | - * on the payment provider's website |
|
101 | - * @return EEI_Payment |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public function set_redirection_info( |
|
105 | - $payment, |
|
106 | - $billing_info = array(), |
|
107 | - $return_url = null, |
|
108 | - $notify_url = null, |
|
109 | - $cancel_url = null |
|
110 | - ) { |
|
111 | - $redirect_args = array(); |
|
112 | - $transaction = $payment->transaction(); |
|
113 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
114 | - $item_num = 1; |
|
115 | - /** @type EE_Line_Item $total_line_item */ |
|
116 | - $total_line_item = $transaction->total_line_item(); |
|
117 | - |
|
118 | - $total_discounts_to_cart_total = $transaction->paid(); |
|
119 | - // only itemize the order if we're paying for the rest of the order's amount |
|
120 | - if (EEH_Money::compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
121 | - $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
122 | - // this payment is for the remaining transaction amount, |
|
123 | - // keep track of exactly how much the itemized order amount equals |
|
124 | - $itemized_sum = 0; |
|
125 | - $shipping_previously_added = 0; |
|
126 | - // so let's show all the line items |
|
127 | - foreach ($total_line_item->get_items() as $line_item) { |
|
128 | - if ($line_item instanceof EE_Line_Item) { |
|
129 | - // it's some kind of discount |
|
130 | - if ($line_item->total() < 0) { |
|
131 | - $total_discounts_to_cart_total += abs($line_item->total()); |
|
132 | - $itemized_sum += $line_item->total(); |
|
133 | - continue; |
|
134 | - } |
|
135 | - // dont include shipping again. |
|
136 | - if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
137 | - $shipping_previously_added = $line_item->total(); |
|
138 | - continue; |
|
139 | - } |
|
140 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
141 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
142 | - 0, |
|
143 | - 127 |
|
144 | - ); |
|
145 | - $redirect_args[ 'amount_' . $item_num ] = $line_item->unit_price(); |
|
146 | - $redirect_args[ 'quantity_' . $item_num ] = $line_item->quantity(); |
|
147 | - // if we're not letting PayPal calculate shipping, tell them its 0 |
|
148 | - if (! $this->_paypal_shipping) { |
|
149 | - $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
150 | - $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
151 | - } |
|
152 | - $item_num++; |
|
153 | - $itemized_sum += $line_item->total(); |
|
154 | - } |
|
155 | - } |
|
156 | - $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
157 | - // ideally itemized sum equals the transaction total. but if not (which is weird) |
|
158 | - // and the itemized sum is LESS than the transaction total |
|
159 | - // add another line item |
|
160 | - // if the itemized sum is MORE than the transaction total, |
|
161 | - // add the difference it to the discounts |
|
162 | - $itemized_sum_diff_from_txn_total = round( |
|
163 | - $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
|
164 | - 2 |
|
165 | - ); |
|
166 | - if ($itemized_sum_diff_from_txn_total < 0) { |
|
167 | - // itemized sum is too big |
|
168 | - $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
169 | - } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
170 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
171 | - __('Other charges', 'event_espresso'), |
|
172 | - 0, |
|
173 | - 127 |
|
174 | - ); |
|
175 | - $redirect_args[ 'amount_' . $item_num ] = $gateway_formatter->formatCurrency( |
|
176 | - $itemized_sum_diff_from_txn_total |
|
177 | - ); |
|
178 | - $redirect_args[ 'quantity_' . $item_num ] = 1; |
|
179 | - $item_num++; |
|
180 | - } |
|
181 | - if ($total_discounts_to_cart_total > 0) { |
|
182 | - $redirect_args['discount_amount_cart'] = $gateway_formatter->formatCurrency( |
|
183 | - $total_discounts_to_cart_total |
|
184 | - ); |
|
185 | - } |
|
186 | - // add our taxes to the order if we're NOT using PayPal's |
|
187 | - if (! $this->_paypal_taxes) { |
|
188 | - $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
|
189 | - } |
|
190 | - } else { |
|
191 | - $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
192 | - // partial payment that's not for the remaining amount, so we can't send an itemized list |
|
193 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
194 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
195 | - 0, |
|
196 | - 127 |
|
197 | - ); |
|
198 | - $redirect_args[ 'amount_' . $item_num ] = $payment->amount(); |
|
199 | - $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
200 | - $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
201 | - $redirect_args['tax_cart'] = '0'; |
|
202 | - $item_num++; |
|
203 | - } |
|
204 | - |
|
205 | - if ($this->_debug_mode) { |
|
206 | - $redirect_args[ 'item_name_' . $item_num ] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
207 | - $redirect_args[ 'amount_' . $item_num ] = 0; |
|
208 | - $redirect_args[ 'on0_'.$item_num ] = 'NOTIFY URL'; |
|
209 | - $redirect_args[ 'os0_' . $item_num ] = $notify_url; |
|
210 | - $redirect_args[ 'on1_'.$item_num ] = 'RETURN URL'; |
|
211 | - $redirect_args[ 'os1_' . $item_num ] = $return_url; |
|
22 | + /** |
|
23 | + * Name for the wp option used to save the itemized payment |
|
24 | + */ |
|
25 | + const itemized_payment_option_name = '_itemized_payment'; |
|
26 | + |
|
27 | + protected $_paypal_id; |
|
28 | + |
|
29 | + protected $_image_url; |
|
30 | + |
|
31 | + protected $_shipping_details; |
|
32 | + |
|
33 | + protected $_paypal_shipping; |
|
34 | + |
|
35 | + protected $_paypal_taxes; |
|
36 | + |
|
37 | + protected $_gateway_url; |
|
38 | + |
|
39 | + protected $_currencies_supported = array( |
|
40 | + 'USD', |
|
41 | + 'GBP', |
|
42 | + 'CAD', |
|
43 | + 'AUD', |
|
44 | + 'BRL', |
|
45 | + 'CHF', |
|
46 | + 'CZK', |
|
47 | + 'DKK', |
|
48 | + 'EUR', |
|
49 | + 'HKD', |
|
50 | + 'HUF', |
|
51 | + 'ILS', |
|
52 | + 'JPY', |
|
53 | + 'MXN', |
|
54 | + 'MYR', |
|
55 | + 'NOK', |
|
56 | + 'NZD', |
|
57 | + 'PHP', |
|
58 | + 'PLN', |
|
59 | + 'SEK', |
|
60 | + 'SGD', |
|
61 | + 'THB', |
|
62 | + 'TRY', |
|
63 | + 'TWD', |
|
64 | + 'RUB' |
|
65 | + ); |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * EEG_Paypal_Standard constructor. |
|
70 | + * |
|
71 | + * @return EEG_Paypal_Standard |
|
72 | + */ |
|
73 | + public function __construct() |
|
74 | + { |
|
75 | + $this->set_uses_separate_IPN_request(true); |
|
76 | + parent::__construct(); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
82 | + * |
|
83 | + * @param array $settings_array |
|
84 | + */ |
|
85 | + public function set_settings($settings_array) |
|
86 | + { |
|
87 | + parent::set_settings($settings_array); |
|
88 | + $this->_gateway_url = $this->_debug_mode |
|
89 | + ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
90 | + : 'https://www.paypal.com/cgi-bin/webscr'; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @param EEI_Payment $payment the payment to process |
|
96 | + * @param array $billing_info but should be empty for this gateway |
|
97 | + * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
98 | + * @param string $notify_url URL to send the instant payment notification |
|
99 | + * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
100 | + * on the payment provider's website |
|
101 | + * @return EEI_Payment |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public function set_redirection_info( |
|
105 | + $payment, |
|
106 | + $billing_info = array(), |
|
107 | + $return_url = null, |
|
108 | + $notify_url = null, |
|
109 | + $cancel_url = null |
|
110 | + ) { |
|
111 | + $redirect_args = array(); |
|
112 | + $transaction = $payment->transaction(); |
|
113 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
114 | + $item_num = 1; |
|
115 | + /** @type EE_Line_Item $total_line_item */ |
|
116 | + $total_line_item = $transaction->total_line_item(); |
|
117 | + |
|
118 | + $total_discounts_to_cart_total = $transaction->paid(); |
|
119 | + // only itemize the order if we're paying for the rest of the order's amount |
|
120 | + if (EEH_Money::compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
121 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
122 | + // this payment is for the remaining transaction amount, |
|
123 | + // keep track of exactly how much the itemized order amount equals |
|
124 | + $itemized_sum = 0; |
|
125 | + $shipping_previously_added = 0; |
|
126 | + // so let's show all the line items |
|
127 | + foreach ($total_line_item->get_items() as $line_item) { |
|
128 | + if ($line_item instanceof EE_Line_Item) { |
|
129 | + // it's some kind of discount |
|
130 | + if ($line_item->total() < 0) { |
|
131 | + $total_discounts_to_cart_total += abs($line_item->total()); |
|
132 | + $itemized_sum += $line_item->total(); |
|
133 | + continue; |
|
134 | + } |
|
135 | + // dont include shipping again. |
|
136 | + if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
137 | + $shipping_previously_added = $line_item->total(); |
|
138 | + continue; |
|
139 | + } |
|
140 | + $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
141 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
142 | + 0, |
|
143 | + 127 |
|
144 | + ); |
|
145 | + $redirect_args[ 'amount_' . $item_num ] = $line_item->unit_price(); |
|
146 | + $redirect_args[ 'quantity_' . $item_num ] = $line_item->quantity(); |
|
147 | + // if we're not letting PayPal calculate shipping, tell them its 0 |
|
148 | + if (! $this->_paypal_shipping) { |
|
149 | + $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
150 | + $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
151 | + } |
|
152 | + $item_num++; |
|
153 | + $itemized_sum += $line_item->total(); |
|
154 | + } |
|
155 | + } |
|
156 | + $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
157 | + // ideally itemized sum equals the transaction total. but if not (which is weird) |
|
158 | + // and the itemized sum is LESS than the transaction total |
|
159 | + // add another line item |
|
160 | + // if the itemized sum is MORE than the transaction total, |
|
161 | + // add the difference it to the discounts |
|
162 | + $itemized_sum_diff_from_txn_total = round( |
|
163 | + $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
|
164 | + 2 |
|
165 | + ); |
|
166 | + if ($itemized_sum_diff_from_txn_total < 0) { |
|
167 | + // itemized sum is too big |
|
168 | + $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
169 | + } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
170 | + $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
171 | + __('Other charges', 'event_espresso'), |
|
172 | + 0, |
|
173 | + 127 |
|
174 | + ); |
|
175 | + $redirect_args[ 'amount_' . $item_num ] = $gateway_formatter->formatCurrency( |
|
176 | + $itemized_sum_diff_from_txn_total |
|
177 | + ); |
|
178 | + $redirect_args[ 'quantity_' . $item_num ] = 1; |
|
179 | + $item_num++; |
|
180 | + } |
|
181 | + if ($total_discounts_to_cart_total > 0) { |
|
182 | + $redirect_args['discount_amount_cart'] = $gateway_formatter->formatCurrency( |
|
183 | + $total_discounts_to_cart_total |
|
184 | + ); |
|
185 | + } |
|
186 | + // add our taxes to the order if we're NOT using PayPal's |
|
187 | + if (! $this->_paypal_taxes) { |
|
188 | + $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
|
189 | + } |
|
190 | + } else { |
|
191 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
192 | + // partial payment that's not for the remaining amount, so we can't send an itemized list |
|
193 | + $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
194 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
195 | + 0, |
|
196 | + 127 |
|
197 | + ); |
|
198 | + $redirect_args[ 'amount_' . $item_num ] = $payment->amount(); |
|
199 | + $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
200 | + $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
201 | + $redirect_args['tax_cart'] = '0'; |
|
202 | + $item_num++; |
|
203 | + } |
|
204 | + |
|
205 | + if ($this->_debug_mode) { |
|
206 | + $redirect_args[ 'item_name_' . $item_num ] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
207 | + $redirect_args[ 'amount_' . $item_num ] = 0; |
|
208 | + $redirect_args[ 'on0_'.$item_num ] = 'NOTIFY URL'; |
|
209 | + $redirect_args[ 'os0_' . $item_num ] = $notify_url; |
|
210 | + $redirect_args[ 'on1_'.$item_num ] = 'RETURN URL'; |
|
211 | + $redirect_args[ 'os1_' . $item_num ] = $return_url; |
|
212 | 212 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
213 | - $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
214 | - $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
215 | - } |
|
216 | - |
|
217 | - $redirect_args['business'] = $this->_paypal_id; |
|
218 | - $redirect_args['return'] = $return_url; |
|
219 | - $redirect_args['cancel_return'] = $cancel_url; |
|
220 | - $redirect_args['notify_url'] = $notify_url; |
|
221 | - $redirect_args['cmd'] = '_cart'; |
|
222 | - $redirect_args['upload'] = 1; |
|
223 | - $redirect_args['currency_code'] = $payment->currency_code(); |
|
224 | - $redirect_args['rm'] = 2;// makes the user return with method=POST |
|
225 | - if ($this->_image_url) { |
|
226 | - $redirect_args['image_url'] = $this->_image_url; |
|
227 | - } |
|
228 | - $redirect_args['no_shipping'] = $this->_shipping_details; |
|
229 | - $redirect_args['bn'] = 'EventEspresso_SP';// EE will blow up if you change this |
|
230 | - |
|
231 | - $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
232 | - |
|
233 | - $payment->set_redirect_url($this->_gateway_url); |
|
234 | - $payment->set_redirect_args($redirect_args); |
|
235 | - // log the results |
|
236 | - $this->log( |
|
237 | - array( |
|
238 | - 'message' => sprintf( |
|
239 | - __('PayPal payment request initiated.', 'event_espresso') |
|
240 | - ), |
|
241 | - 'transaction' => $transaction->model_field_array(), |
|
242 | - ), |
|
243 | - $payment |
|
244 | - ); |
|
245 | - return $payment; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * Often used for IPNs. But applies the info in $update_info to the payment. |
|
251 | - * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
252 | - * the payment method passes in. |
|
253 | - * |
|
254 | - * @param array $update_info like $_POST |
|
255 | - * @param EEI_Transaction $transaction |
|
256 | - * @return \EEI_Payment updated |
|
257 | - * @throws \EE_Error, IpnException |
|
258 | - */ |
|
259 | - public function handle_payment_update($update_info, $transaction) |
|
260 | - { |
|
261 | - // verify there's payment data that's been sent |
|
262 | - if (empty($update_info['payment_status']) || empty($update_info['txn_id'])) { |
|
263 | - // log the results |
|
264 | - $this->log( |
|
265 | - array( |
|
266 | - 'message' => sprintf( |
|
267 | - // @codingStandardsIgnoreStart |
|
268 | - __('PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso') |
|
269 | - // @codingStandardsIgnoreEnd |
|
270 | - ), |
|
271 | - 'update_info' => $update_info, |
|
272 | - ), |
|
273 | - $transaction |
|
274 | - ); |
|
275 | - // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
276 | - // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
277 | - if (isset($update_info['tx'])) { |
|
278 | - return $transaction->last_payment(); |
|
279 | - } else { |
|
280 | - return null; |
|
281 | - } |
|
282 | - } |
|
283 | - $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
284 | - if (! $payment instanceof EEI_Payment) { |
|
285 | - $payment = $transaction->last_payment(); |
|
286 | - } |
|
287 | - // ok, then validate the IPN. Even if we've already processed this payment, |
|
288 | - // let PayPal know we don't want to hear from them anymore! |
|
289 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
290 | - return $payment; |
|
291 | - } |
|
292 | - // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
293 | - // registrations, ticket counts, etc) |
|
294 | - if (( |
|
295 | - $update_info['payment_status'] === 'Refunded' |
|
296 | - || $update_info['payment_status'] === 'Partially_Refunded' |
|
297 | - ) |
|
298 | - && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
299 | - ) { |
|
300 | - throw new EventEspresso\core\exceptions\IpnException( |
|
301 | - sprintf( |
|
302 | - esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
303 | - $update_info['payment_status'] |
|
304 | - ), |
|
305 | - EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
306 | - null, |
|
307 | - $payment, |
|
308 | - $update_info |
|
309 | - ); |
|
310 | - } |
|
311 | - // ok, well let's process this payment then! |
|
312 | - switch ($update_info['payment_status']) { |
|
313 | - case 'Completed': |
|
314 | - $status = $this->_pay_model->approved_status(); |
|
315 | - $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
316 | - break; |
|
317 | - |
|
318 | - case 'Pending': |
|
319 | - $status = $this->_pay_model->pending_status(); |
|
320 | - $gateway_response = esc_html__( |
|
321 | - 'The payment is in progress. Another message will be sent when payment is approved.', |
|
322 | - 'event_espresso' |
|
323 | - ); |
|
324 | - break; |
|
325 | - |
|
326 | - case 'Denied': |
|
327 | - $status = $this->_pay_model->declined_status(); |
|
328 | - $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
329 | - break; |
|
330 | - |
|
331 | - case 'Expired': |
|
332 | - case 'Failed': |
|
333 | - $status = $this->_pay_model->failed_status(); |
|
334 | - $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
335 | - break; |
|
336 | - |
|
337 | - case 'Refunded': |
|
338 | - case 'Partially_Refunded': |
|
339 | - // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
340 | - $status = $this->_pay_model->approved_status(); |
|
341 | - $gateway_response = esc_html__( |
|
342 | - 'The payment has been refunded. Please update registrations accordingly.', |
|
343 | - 'event_espresso' |
|
344 | - ); |
|
345 | - break; |
|
346 | - |
|
347 | - case 'Voided': |
|
348 | - case 'Reversed': |
|
349 | - case 'Canceled_Reversal': |
|
350 | - default: |
|
351 | - $status = $this->_pay_model->cancelled_status(); |
|
352 | - $gateway_response = esc_html__( |
|
353 | - 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
354 | - 'event_espresso' |
|
355 | - ); |
|
356 | - break; |
|
357 | - } |
|
358 | - |
|
359 | - // check if we've already processed this payment |
|
360 | - if ($payment instanceof EEI_Payment) { |
|
361 | - // payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
362 | - if ($payment->status() === $status && (float) $payment->amount() === (float) $update_info['mc_gross']) { |
|
363 | - // DUPLICATED IPN! don't bother updating transaction |
|
364 | - throw new IpnException( |
|
365 | - sprintf( |
|
366 | - esc_html__( |
|
367 | - 'It appears we have received a duplicate IPN from PayPal for payment %d', |
|
368 | - 'event_espresso' |
|
369 | - ), |
|
370 | - $payment->ID() |
|
371 | - ), |
|
372 | - IpnException::DUPLICATE, |
|
373 | - null, |
|
374 | - $payment, |
|
375 | - $update_info |
|
376 | - ); |
|
377 | - } else { |
|
378 | - // new payment yippee !!! |
|
379 | - $payment->set_status($status); |
|
380 | - $payment->set_amount((float) $update_info['mc_gross']); |
|
381 | - $payment->set_gateway_response($gateway_response); |
|
382 | - $payment->set_details($update_info); |
|
383 | - $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
384 | - $this->log( |
|
385 | - array( |
|
386 | - 'message' => esc_html__( |
|
387 | - 'Updated payment either from IPN or as part of POST from PayPal', |
|
388 | - 'event_espresso' |
|
389 | - ), |
|
390 | - 'url' => $this->_process_response_url(), |
|
391 | - 'payment' => $payment->model_field_array(), |
|
392 | - 'IPN_data' => $update_info |
|
393 | - ), |
|
394 | - $payment |
|
395 | - ); |
|
396 | - } |
|
397 | - } |
|
398 | - do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
399 | - return $payment; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * Validate the IPN notification. |
|
405 | - * |
|
406 | - * @param array $update_info like $_REQUEST |
|
407 | - * @param EE_Payment|EEI_Payment $payment |
|
408 | - * @return boolean |
|
409 | - * @throws \EE_Error |
|
410 | - */ |
|
411 | - public function validate_ipn($update_info, $payment) |
|
412 | - { |
|
413 | - // allow us to skip validating IPNs with PayPal (useful for testing) |
|
414 | - if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
415 | - return true; |
|
416 | - } |
|
417 | - // ...otherwise, we actually don't care what the $update_info is, we need to look |
|
418 | - // at the request directly because we can't use $update_info because it has issues with quotes |
|
419 | - // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
420 | - // Instead, read raw POST data from the input stream. |
|
421 | - // @see https://gist.github.com/xcommerce-gists/3440401 |
|
422 | - $raw_post_data = file_get_contents('php://input'); |
|
423 | - $raw_post_array = explode('&', $raw_post_data); |
|
424 | - $update_info = array(); |
|
425 | - foreach ($raw_post_array as $keyval) { |
|
426 | - $keyval = explode('=', $keyval); |
|
427 | - if (count($keyval) === 2) { |
|
428 | - $update_info[ $keyval[0] ] = urldecode($keyval[1]); |
|
429 | - } |
|
430 | - } |
|
431 | - // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
432 | - $req = 'cmd=_notify-validate'; |
|
433 | - $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 |
|
434 | - ? true |
|
435 | - : false; |
|
436 | - foreach ($update_info as $key => $value) { |
|
437 | - $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
438 | - $req .= "&$key=$value"; |
|
439 | - } |
|
440 | - // HTTP POST the complete, unaltered IPN back to PayPal |
|
441 | - $response = wp_remote_post( |
|
442 | - $this->_gateway_url, |
|
443 | - array( |
|
444 | - 'body' => $req, |
|
445 | - 'sslverify' => false, |
|
446 | - 'timeout' => 60, |
|
447 | - // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
448 | - // plz see: https://github.com/websharks/s2member/issues/610 |
|
449 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
450 | - 'httpversion' => '1.1' |
|
451 | - ) |
|
452 | - ); |
|
453 | - // then check the response |
|
454 | - if (array_key_exists('body', $response) |
|
455 | - && ! is_wp_error($response) |
|
456 | - && strcmp($response['body'], "VERIFIED") === 0 |
|
457 | - ) { |
|
458 | - return true; |
|
459 | - } |
|
460 | - // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
461 | - // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
462 | - if ($response instanceof WP_Error) { |
|
463 | - $error_msg = sprintf( |
|
464 | - esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
465 | - $response->get_error_code(), |
|
466 | - $response->get_error_message(), |
|
467 | - print_r($response->get_error_data(), true) |
|
468 | - ); |
|
469 | - } elseif (is_array($response) && isset($response['body'])) { |
|
470 | - $error_msg = $response['body']; |
|
471 | - } else { |
|
472 | - $error_msg = print_r($response, true); |
|
473 | - } |
|
474 | - $payment->set_gateway_response( |
|
475 | - sprintf( |
|
476 | - esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
477 | - $error_msg |
|
478 | - ) |
|
479 | - ); |
|
480 | - $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
481 | - $payment->set_status(EEM_Payment::status_id_failed); |
|
482 | - // log the results |
|
483 | - $this->log( |
|
484 | - array( |
|
485 | - 'url' => $this->_process_response_url(), |
|
486 | - 'message' => $payment->gateway_response(), |
|
487 | - 'details' => $payment->details(), |
|
488 | - ), |
|
489 | - $payment |
|
490 | - ); |
|
491 | - return false; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * _process_response_url |
|
497 | - * @return string |
|
498 | - */ |
|
499 | - protected function _process_response_url() |
|
500 | - { |
|
501 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
502 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
503 | - $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
504 | - $url .= EEH_URL::filter_input_server_url(); |
|
505 | - } else { |
|
506 | - $url = 'unknown'; |
|
507 | - } |
|
508 | - return $url; |
|
509 | - } |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
514 | - * like the taxes or shipping |
|
515 | - * |
|
516 | - * @param EEI_Payment $payment |
|
517 | - * @throws \EE_Error |
|
518 | - */ |
|
519 | - public function update_txn_based_on_payment($payment) |
|
520 | - { |
|
521 | - $update_info = $payment->details(); |
|
522 | - /** @var EE_Transaction $transaction */ |
|
523 | - $transaction = $payment->transaction(); |
|
524 | - $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
525 | - if (! $transaction) { |
|
526 | - $this->log( |
|
527 | - esc_html__( |
|
528 | - // @codingStandardsIgnoreStart |
|
529 | - 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
530 | - // @codingStandardsIgnoreEnd |
|
531 | - 'event_espresso' |
|
532 | - ), |
|
533 | - $payment |
|
534 | - ); |
|
535 | - return; |
|
536 | - } |
|
537 | - if (! is_array($update_info) |
|
538 | - || ! isset($update_info['mc_shipping']) |
|
539 | - || ! isset($update_info['tax']) |
|
540 | - ) { |
|
541 | - $this->log( |
|
542 | - array( |
|
543 | - 'message' => esc_html__( |
|
544 | - // @codingStandardsIgnoreStart |
|
545 | - 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
546 | - // @codingStandardsIgnoreEnd |
|
547 | - 'event_espresso' |
|
548 | - ), |
|
549 | - 'url' => $this->_process_response_url(), |
|
550 | - 'payment' => $payment->model_field_array() |
|
551 | - ), |
|
552 | - $payment |
|
553 | - ); |
|
554 | - return; |
|
555 | - } |
|
556 | - if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
557 | - $this->log( |
|
558 | - array( |
|
559 | - 'message' => esc_html__( |
|
560 | - 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
561 | - 'event_espresso' |
|
562 | - ), |
|
563 | - 'url' => $this->_process_response_url(), |
|
564 | - 'payment' => $payment->model_field_array() |
|
565 | - ), |
|
566 | - $payment |
|
567 | - ); |
|
568 | - return; |
|
569 | - } |
|
570 | - $grand_total_needs_resaving = false; |
|
571 | - /** @var EE_Line_Item $transaction_total_line_item */ |
|
572 | - $transaction_total_line_item = $transaction->total_line_item(); |
|
573 | - |
|
574 | - // might paypal have changed the taxes? |
|
575 | - if ($this->_paypal_taxes && $payment_was_itemized) { |
|
576 | - // note that we're doing this BEFORE adding shipping; |
|
577 | - // we actually want PayPal's shipping to remain non-taxable |
|
578 | - $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
579 | - $this->_line_item->set_total_tax_to( |
|
580 | - $transaction_total_line_item, |
|
581 | - (float) $update_info['tax'], |
|
582 | - esc_html__('Taxes', 'event_espresso'), |
|
583 | - esc_html__('Calculated by Paypal', 'event_espresso'), |
|
584 | - 'paypal_tax' |
|
585 | - ); |
|
586 | - $grand_total_needs_resaving = true; |
|
587 | - } |
|
588 | - |
|
589 | - $shipping_amount = (float) $update_info['mc_shipping']; |
|
590 | - // might paypal have added shipping? |
|
591 | - if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
592 | - $this->_line_item->add_unrelated_item( |
|
593 | - $transaction_total_line_item, |
|
594 | - sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
595 | - $shipping_amount, |
|
596 | - esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
597 | - 1, |
|
598 | - false, |
|
599 | - 'paypal_shipping_' . $transaction->ID() |
|
600 | - ); |
|
601 | - $grand_total_needs_resaving = true; |
|
602 | - } |
|
603 | - |
|
604 | - if ($grand_total_needs_resaving) { |
|
605 | - $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
606 | - /** @var EE_Registration_Processor $registration_processor */ |
|
607 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
608 | - $registration_processor->update_registration_final_prices($transaction); |
|
609 | - } |
|
610 | - $this->log( |
|
611 | - array( |
|
612 | - 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
613 | - 'url' => $this->_process_response_url(), |
|
614 | - 'transaction (updated)' => $transaction->model_field_array(), |
|
615 | - 'payment (updated)' => $payment->model_field_array(), |
|
616 | - 'use_paypal_shipping' => $this->_paypal_shipping, |
|
617 | - 'use_paypal_tax' => $this->_paypal_taxes, |
|
618 | - 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
619 | - ), |
|
620 | - $payment |
|
621 | - ); |
|
622 | - } |
|
213 | + $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
214 | + $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
215 | + } |
|
216 | + |
|
217 | + $redirect_args['business'] = $this->_paypal_id; |
|
218 | + $redirect_args['return'] = $return_url; |
|
219 | + $redirect_args['cancel_return'] = $cancel_url; |
|
220 | + $redirect_args['notify_url'] = $notify_url; |
|
221 | + $redirect_args['cmd'] = '_cart'; |
|
222 | + $redirect_args['upload'] = 1; |
|
223 | + $redirect_args['currency_code'] = $payment->currency_code(); |
|
224 | + $redirect_args['rm'] = 2;// makes the user return with method=POST |
|
225 | + if ($this->_image_url) { |
|
226 | + $redirect_args['image_url'] = $this->_image_url; |
|
227 | + } |
|
228 | + $redirect_args['no_shipping'] = $this->_shipping_details; |
|
229 | + $redirect_args['bn'] = 'EventEspresso_SP';// EE will blow up if you change this |
|
230 | + |
|
231 | + $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
232 | + |
|
233 | + $payment->set_redirect_url($this->_gateway_url); |
|
234 | + $payment->set_redirect_args($redirect_args); |
|
235 | + // log the results |
|
236 | + $this->log( |
|
237 | + array( |
|
238 | + 'message' => sprintf( |
|
239 | + __('PayPal payment request initiated.', 'event_espresso') |
|
240 | + ), |
|
241 | + 'transaction' => $transaction->model_field_array(), |
|
242 | + ), |
|
243 | + $payment |
|
244 | + ); |
|
245 | + return $payment; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * Often used for IPNs. But applies the info in $update_info to the payment. |
|
251 | + * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
252 | + * the payment method passes in. |
|
253 | + * |
|
254 | + * @param array $update_info like $_POST |
|
255 | + * @param EEI_Transaction $transaction |
|
256 | + * @return \EEI_Payment updated |
|
257 | + * @throws \EE_Error, IpnException |
|
258 | + */ |
|
259 | + public function handle_payment_update($update_info, $transaction) |
|
260 | + { |
|
261 | + // verify there's payment data that's been sent |
|
262 | + if (empty($update_info['payment_status']) || empty($update_info['txn_id'])) { |
|
263 | + // log the results |
|
264 | + $this->log( |
|
265 | + array( |
|
266 | + 'message' => sprintf( |
|
267 | + // @codingStandardsIgnoreStart |
|
268 | + __('PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso') |
|
269 | + // @codingStandardsIgnoreEnd |
|
270 | + ), |
|
271 | + 'update_info' => $update_info, |
|
272 | + ), |
|
273 | + $transaction |
|
274 | + ); |
|
275 | + // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
276 | + // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
277 | + if (isset($update_info['tx'])) { |
|
278 | + return $transaction->last_payment(); |
|
279 | + } else { |
|
280 | + return null; |
|
281 | + } |
|
282 | + } |
|
283 | + $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
284 | + if (! $payment instanceof EEI_Payment) { |
|
285 | + $payment = $transaction->last_payment(); |
|
286 | + } |
|
287 | + // ok, then validate the IPN. Even if we've already processed this payment, |
|
288 | + // let PayPal know we don't want to hear from them anymore! |
|
289 | + if (! $this->validate_ipn($update_info, $payment)) { |
|
290 | + return $payment; |
|
291 | + } |
|
292 | + // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
293 | + // registrations, ticket counts, etc) |
|
294 | + if (( |
|
295 | + $update_info['payment_status'] === 'Refunded' |
|
296 | + || $update_info['payment_status'] === 'Partially_Refunded' |
|
297 | + ) |
|
298 | + && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
299 | + ) { |
|
300 | + throw new EventEspresso\core\exceptions\IpnException( |
|
301 | + sprintf( |
|
302 | + esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
303 | + $update_info['payment_status'] |
|
304 | + ), |
|
305 | + EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
306 | + null, |
|
307 | + $payment, |
|
308 | + $update_info |
|
309 | + ); |
|
310 | + } |
|
311 | + // ok, well let's process this payment then! |
|
312 | + switch ($update_info['payment_status']) { |
|
313 | + case 'Completed': |
|
314 | + $status = $this->_pay_model->approved_status(); |
|
315 | + $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
316 | + break; |
|
317 | + |
|
318 | + case 'Pending': |
|
319 | + $status = $this->_pay_model->pending_status(); |
|
320 | + $gateway_response = esc_html__( |
|
321 | + 'The payment is in progress. Another message will be sent when payment is approved.', |
|
322 | + 'event_espresso' |
|
323 | + ); |
|
324 | + break; |
|
325 | + |
|
326 | + case 'Denied': |
|
327 | + $status = $this->_pay_model->declined_status(); |
|
328 | + $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
329 | + break; |
|
330 | + |
|
331 | + case 'Expired': |
|
332 | + case 'Failed': |
|
333 | + $status = $this->_pay_model->failed_status(); |
|
334 | + $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
335 | + break; |
|
336 | + |
|
337 | + case 'Refunded': |
|
338 | + case 'Partially_Refunded': |
|
339 | + // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
340 | + $status = $this->_pay_model->approved_status(); |
|
341 | + $gateway_response = esc_html__( |
|
342 | + 'The payment has been refunded. Please update registrations accordingly.', |
|
343 | + 'event_espresso' |
|
344 | + ); |
|
345 | + break; |
|
346 | + |
|
347 | + case 'Voided': |
|
348 | + case 'Reversed': |
|
349 | + case 'Canceled_Reversal': |
|
350 | + default: |
|
351 | + $status = $this->_pay_model->cancelled_status(); |
|
352 | + $gateway_response = esc_html__( |
|
353 | + 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
354 | + 'event_espresso' |
|
355 | + ); |
|
356 | + break; |
|
357 | + } |
|
358 | + |
|
359 | + // check if we've already processed this payment |
|
360 | + if ($payment instanceof EEI_Payment) { |
|
361 | + // payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
362 | + if ($payment->status() === $status && (float) $payment->amount() === (float) $update_info['mc_gross']) { |
|
363 | + // DUPLICATED IPN! don't bother updating transaction |
|
364 | + throw new IpnException( |
|
365 | + sprintf( |
|
366 | + esc_html__( |
|
367 | + 'It appears we have received a duplicate IPN from PayPal for payment %d', |
|
368 | + 'event_espresso' |
|
369 | + ), |
|
370 | + $payment->ID() |
|
371 | + ), |
|
372 | + IpnException::DUPLICATE, |
|
373 | + null, |
|
374 | + $payment, |
|
375 | + $update_info |
|
376 | + ); |
|
377 | + } else { |
|
378 | + // new payment yippee !!! |
|
379 | + $payment->set_status($status); |
|
380 | + $payment->set_amount((float) $update_info['mc_gross']); |
|
381 | + $payment->set_gateway_response($gateway_response); |
|
382 | + $payment->set_details($update_info); |
|
383 | + $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
384 | + $this->log( |
|
385 | + array( |
|
386 | + 'message' => esc_html__( |
|
387 | + 'Updated payment either from IPN or as part of POST from PayPal', |
|
388 | + 'event_espresso' |
|
389 | + ), |
|
390 | + 'url' => $this->_process_response_url(), |
|
391 | + 'payment' => $payment->model_field_array(), |
|
392 | + 'IPN_data' => $update_info |
|
393 | + ), |
|
394 | + $payment |
|
395 | + ); |
|
396 | + } |
|
397 | + } |
|
398 | + do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
399 | + return $payment; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * Validate the IPN notification. |
|
405 | + * |
|
406 | + * @param array $update_info like $_REQUEST |
|
407 | + * @param EE_Payment|EEI_Payment $payment |
|
408 | + * @return boolean |
|
409 | + * @throws \EE_Error |
|
410 | + */ |
|
411 | + public function validate_ipn($update_info, $payment) |
|
412 | + { |
|
413 | + // allow us to skip validating IPNs with PayPal (useful for testing) |
|
414 | + if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
415 | + return true; |
|
416 | + } |
|
417 | + // ...otherwise, we actually don't care what the $update_info is, we need to look |
|
418 | + // at the request directly because we can't use $update_info because it has issues with quotes |
|
419 | + // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
420 | + // Instead, read raw POST data from the input stream. |
|
421 | + // @see https://gist.github.com/xcommerce-gists/3440401 |
|
422 | + $raw_post_data = file_get_contents('php://input'); |
|
423 | + $raw_post_array = explode('&', $raw_post_data); |
|
424 | + $update_info = array(); |
|
425 | + foreach ($raw_post_array as $keyval) { |
|
426 | + $keyval = explode('=', $keyval); |
|
427 | + if (count($keyval) === 2) { |
|
428 | + $update_info[ $keyval[0] ] = urldecode($keyval[1]); |
|
429 | + } |
|
430 | + } |
|
431 | + // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
432 | + $req = 'cmd=_notify-validate'; |
|
433 | + $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 |
|
434 | + ? true |
|
435 | + : false; |
|
436 | + foreach ($update_info as $key => $value) { |
|
437 | + $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
438 | + $req .= "&$key=$value"; |
|
439 | + } |
|
440 | + // HTTP POST the complete, unaltered IPN back to PayPal |
|
441 | + $response = wp_remote_post( |
|
442 | + $this->_gateway_url, |
|
443 | + array( |
|
444 | + 'body' => $req, |
|
445 | + 'sslverify' => false, |
|
446 | + 'timeout' => 60, |
|
447 | + // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
448 | + // plz see: https://github.com/websharks/s2member/issues/610 |
|
449 | + 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
450 | + 'httpversion' => '1.1' |
|
451 | + ) |
|
452 | + ); |
|
453 | + // then check the response |
|
454 | + if (array_key_exists('body', $response) |
|
455 | + && ! is_wp_error($response) |
|
456 | + && strcmp($response['body'], "VERIFIED") === 0 |
|
457 | + ) { |
|
458 | + return true; |
|
459 | + } |
|
460 | + // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
461 | + // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
462 | + if ($response instanceof WP_Error) { |
|
463 | + $error_msg = sprintf( |
|
464 | + esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
465 | + $response->get_error_code(), |
|
466 | + $response->get_error_message(), |
|
467 | + print_r($response->get_error_data(), true) |
|
468 | + ); |
|
469 | + } elseif (is_array($response) && isset($response['body'])) { |
|
470 | + $error_msg = $response['body']; |
|
471 | + } else { |
|
472 | + $error_msg = print_r($response, true); |
|
473 | + } |
|
474 | + $payment->set_gateway_response( |
|
475 | + sprintf( |
|
476 | + esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
477 | + $error_msg |
|
478 | + ) |
|
479 | + ); |
|
480 | + $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
481 | + $payment->set_status(EEM_Payment::status_id_failed); |
|
482 | + // log the results |
|
483 | + $this->log( |
|
484 | + array( |
|
485 | + 'url' => $this->_process_response_url(), |
|
486 | + 'message' => $payment->gateway_response(), |
|
487 | + 'details' => $payment->details(), |
|
488 | + ), |
|
489 | + $payment |
|
490 | + ); |
|
491 | + return false; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * _process_response_url |
|
497 | + * @return string |
|
498 | + */ |
|
499 | + protected function _process_response_url() |
|
500 | + { |
|
501 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
502 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
503 | + $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
504 | + $url .= EEH_URL::filter_input_server_url(); |
|
505 | + } else { |
|
506 | + $url = 'unknown'; |
|
507 | + } |
|
508 | + return $url; |
|
509 | + } |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
514 | + * like the taxes or shipping |
|
515 | + * |
|
516 | + * @param EEI_Payment $payment |
|
517 | + * @throws \EE_Error |
|
518 | + */ |
|
519 | + public function update_txn_based_on_payment($payment) |
|
520 | + { |
|
521 | + $update_info = $payment->details(); |
|
522 | + /** @var EE_Transaction $transaction */ |
|
523 | + $transaction = $payment->transaction(); |
|
524 | + $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
525 | + if (! $transaction) { |
|
526 | + $this->log( |
|
527 | + esc_html__( |
|
528 | + // @codingStandardsIgnoreStart |
|
529 | + 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
530 | + // @codingStandardsIgnoreEnd |
|
531 | + 'event_espresso' |
|
532 | + ), |
|
533 | + $payment |
|
534 | + ); |
|
535 | + return; |
|
536 | + } |
|
537 | + if (! is_array($update_info) |
|
538 | + || ! isset($update_info['mc_shipping']) |
|
539 | + || ! isset($update_info['tax']) |
|
540 | + ) { |
|
541 | + $this->log( |
|
542 | + array( |
|
543 | + 'message' => esc_html__( |
|
544 | + // @codingStandardsIgnoreStart |
|
545 | + 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
546 | + // @codingStandardsIgnoreEnd |
|
547 | + 'event_espresso' |
|
548 | + ), |
|
549 | + 'url' => $this->_process_response_url(), |
|
550 | + 'payment' => $payment->model_field_array() |
|
551 | + ), |
|
552 | + $payment |
|
553 | + ); |
|
554 | + return; |
|
555 | + } |
|
556 | + if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
557 | + $this->log( |
|
558 | + array( |
|
559 | + 'message' => esc_html__( |
|
560 | + 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
561 | + 'event_espresso' |
|
562 | + ), |
|
563 | + 'url' => $this->_process_response_url(), |
|
564 | + 'payment' => $payment->model_field_array() |
|
565 | + ), |
|
566 | + $payment |
|
567 | + ); |
|
568 | + return; |
|
569 | + } |
|
570 | + $grand_total_needs_resaving = false; |
|
571 | + /** @var EE_Line_Item $transaction_total_line_item */ |
|
572 | + $transaction_total_line_item = $transaction->total_line_item(); |
|
573 | + |
|
574 | + // might paypal have changed the taxes? |
|
575 | + if ($this->_paypal_taxes && $payment_was_itemized) { |
|
576 | + // note that we're doing this BEFORE adding shipping; |
|
577 | + // we actually want PayPal's shipping to remain non-taxable |
|
578 | + $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
579 | + $this->_line_item->set_total_tax_to( |
|
580 | + $transaction_total_line_item, |
|
581 | + (float) $update_info['tax'], |
|
582 | + esc_html__('Taxes', 'event_espresso'), |
|
583 | + esc_html__('Calculated by Paypal', 'event_espresso'), |
|
584 | + 'paypal_tax' |
|
585 | + ); |
|
586 | + $grand_total_needs_resaving = true; |
|
587 | + } |
|
588 | + |
|
589 | + $shipping_amount = (float) $update_info['mc_shipping']; |
|
590 | + // might paypal have added shipping? |
|
591 | + if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
592 | + $this->_line_item->add_unrelated_item( |
|
593 | + $transaction_total_line_item, |
|
594 | + sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
595 | + $shipping_amount, |
|
596 | + esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
597 | + 1, |
|
598 | + false, |
|
599 | + 'paypal_shipping_' . $transaction->ID() |
|
600 | + ); |
|
601 | + $grand_total_needs_resaving = true; |
|
602 | + } |
|
603 | + |
|
604 | + if ($grand_total_needs_resaving) { |
|
605 | + $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
606 | + /** @var EE_Registration_Processor $registration_processor */ |
|
607 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
608 | + $registration_processor->update_registration_final_prices($transaction); |
|
609 | + } |
|
610 | + $this->log( |
|
611 | + array( |
|
612 | + 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
613 | + 'url' => $this->_process_response_url(), |
|
614 | + 'transaction (updated)' => $transaction->model_field_array(), |
|
615 | + 'payment (updated)' => $payment->model_field_array(), |
|
616 | + 'use_paypal_shipping' => $this->_paypal_shipping, |
|
617 | + 'use_paypal_tax' => $this->_paypal_taxes, |
|
618 | + 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
619 | + ), |
|
620 | + $payment |
|
621 | + ); |
|
622 | + } |
|
623 | 623 | } |
@@ -137,17 +137,17 @@ discard block |
||
137 | 137 | $shipping_previously_added = $line_item->total(); |
138 | 138 | continue; |
139 | 139 | } |
140 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
140 | + $redirect_args['item_name_'.$item_num] = substr( |
|
141 | 141 | $gateway_formatter->formatLineItemName($line_item, $payment), |
142 | 142 | 0, |
143 | 143 | 127 |
144 | 144 | ); |
145 | - $redirect_args[ 'amount_' . $item_num ] = $line_item->unit_price(); |
|
146 | - $redirect_args[ 'quantity_' . $item_num ] = $line_item->quantity(); |
|
145 | + $redirect_args['amount_'.$item_num] = $line_item->unit_price(); |
|
146 | + $redirect_args['quantity_'.$item_num] = $line_item->quantity(); |
|
147 | 147 | // if we're not letting PayPal calculate shipping, tell them its 0 |
148 | - if (! $this->_paypal_shipping) { |
|
149 | - $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
150 | - $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
148 | + if ( ! $this->_paypal_shipping) { |
|
149 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
150 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
151 | 151 | } |
152 | 152 | $item_num++; |
153 | 153 | $itemized_sum += $line_item->total(); |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | // itemized sum is too big |
168 | 168 | $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
169 | 169 | } elseif ($itemized_sum_diff_from_txn_total > 0) { |
170 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
170 | + $redirect_args['item_name_'.$item_num] = substr( |
|
171 | 171 | __('Other charges', 'event_espresso'), |
172 | 172 | 0, |
173 | 173 | 127 |
174 | 174 | ); |
175 | - $redirect_args[ 'amount_' . $item_num ] = $gateway_formatter->formatCurrency( |
|
175 | + $redirect_args['amount_'.$item_num] = $gateway_formatter->formatCurrency( |
|
176 | 176 | $itemized_sum_diff_from_txn_total |
177 | 177 | ); |
178 | - $redirect_args[ 'quantity_' . $item_num ] = 1; |
|
178 | + $redirect_args['quantity_'.$item_num] = 1; |
|
179 | 179 | $item_num++; |
180 | 180 | } |
181 | 181 | if ($total_discounts_to_cart_total > 0) { |
@@ -184,34 +184,34 @@ discard block |
||
184 | 184 | ); |
185 | 185 | } |
186 | 186 | // add our taxes to the order if we're NOT using PayPal's |
187 | - if (! $this->_paypal_taxes) { |
|
187 | + if ( ! $this->_paypal_taxes) { |
|
188 | 188 | $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
189 | 189 | } |
190 | 190 | } else { |
191 | 191 | $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
192 | 192 | // partial payment that's not for the remaining amount, so we can't send an itemized list |
193 | - $redirect_args[ 'item_name_' . $item_num ] = substr( |
|
193 | + $redirect_args['item_name_'.$item_num] = substr( |
|
194 | 194 | $gateway_formatter->formatPartialPaymentLineItemName($payment), |
195 | 195 | 0, |
196 | 196 | 127 |
197 | 197 | ); |
198 | - $redirect_args[ 'amount_' . $item_num ] = $payment->amount(); |
|
199 | - $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
200 | - $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
198 | + $redirect_args['amount_'.$item_num] = $payment->amount(); |
|
199 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
200 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
201 | 201 | $redirect_args['tax_cart'] = '0'; |
202 | 202 | $item_num++; |
203 | 203 | } |
204 | 204 | |
205 | 205 | if ($this->_debug_mode) { |
206 | - $redirect_args[ 'item_name_' . $item_num ] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
207 | - $redirect_args[ 'amount_' . $item_num ] = 0; |
|
208 | - $redirect_args[ 'on0_'.$item_num ] = 'NOTIFY URL'; |
|
209 | - $redirect_args[ 'os0_' . $item_num ] = $notify_url; |
|
210 | - $redirect_args[ 'on1_'.$item_num ] = 'RETURN URL'; |
|
211 | - $redirect_args[ 'os1_' . $item_num ] = $return_url; |
|
206 | + $redirect_args['item_name_'.$item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
207 | + $redirect_args['amount_'.$item_num] = 0; |
|
208 | + $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
|
209 | + $redirect_args['os0_'.$item_num] = $notify_url; |
|
210 | + $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
|
211 | + $redirect_args['os1_'.$item_num] = $return_url; |
|
212 | 212 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
213 | - $redirect_args[ 'shipping_' . $item_num ] = '0'; |
|
214 | - $redirect_args[ 'shipping2_' . $item_num ] = '0'; |
|
213 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
214 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | $redirect_args['business'] = $this->_paypal_id; |
@@ -221,12 +221,12 @@ discard block |
||
221 | 221 | $redirect_args['cmd'] = '_cart'; |
222 | 222 | $redirect_args['upload'] = 1; |
223 | 223 | $redirect_args['currency_code'] = $payment->currency_code(); |
224 | - $redirect_args['rm'] = 2;// makes the user return with method=POST |
|
224 | + $redirect_args['rm'] = 2; // makes the user return with method=POST |
|
225 | 225 | if ($this->_image_url) { |
226 | 226 | $redirect_args['image_url'] = $this->_image_url; |
227 | 227 | } |
228 | 228 | $redirect_args['no_shipping'] = $this->_shipping_details; |
229 | - $redirect_args['bn'] = 'EventEspresso_SP';// EE will blow up if you change this |
|
229 | + $redirect_args['bn'] = 'EventEspresso_SP'; // EE will blow up if you change this |
|
230 | 230 | |
231 | 231 | $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
232 | 232 | |
@@ -281,12 +281,12 @@ discard block |
||
281 | 281 | } |
282 | 282 | } |
283 | 283 | $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
284 | - if (! $payment instanceof EEI_Payment) { |
|
284 | + if ( ! $payment instanceof EEI_Payment) { |
|
285 | 285 | $payment = $transaction->last_payment(); |
286 | 286 | } |
287 | 287 | // ok, then validate the IPN. Even if we've already processed this payment, |
288 | 288 | // let PayPal know we don't want to hear from them anymore! |
289 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
289 | + if ( ! $this->validate_ipn($update_info, $payment)) { |
|
290 | 290 | return $payment; |
291 | 291 | } |
292 | 292 | // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | foreach ($raw_post_array as $keyval) { |
426 | 426 | $keyval = explode('=', $keyval); |
427 | 427 | if (count($keyval) === 2) { |
428 | - $update_info[ $keyval[0] ] = urldecode($keyval[1]); |
|
428 | + $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | 'timeout' => 60, |
447 | 447 | // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
448 | 448 | // plz see: https://github.com/websharks/s2member/issues/610 |
449 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
449 | + 'user-agent' => 'Event Espresso v'.EVENT_ESPRESSO_VERSION.'; '.home_url(), |
|
450 | 450 | 'httpversion' => '1.1' |
451 | 451 | ) |
452 | 452 | ); |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | /** @var EE_Transaction $transaction */ |
523 | 523 | $transaction = $payment->transaction(); |
524 | 524 | $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
525 | - if (! $transaction) { |
|
525 | + if ( ! $transaction) { |
|
526 | 526 | $this->log( |
527 | 527 | esc_html__( |
528 | 528 | // @codingStandardsIgnoreStart |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | ); |
535 | 535 | return; |
536 | 536 | } |
537 | - if (! is_array($update_info) |
|
537 | + if ( ! is_array($update_info) |
|
538 | 538 | || ! isset($update_info['mc_shipping']) |
539 | 539 | || ! isset($update_info['tax']) |
540 | 540 | ) { |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
597 | 597 | 1, |
598 | 598 | false, |
599 | - 'paypal_shipping_' . $transaction->ID() |
|
599 | + 'paypal_shipping_'.$transaction->ID() |
|
600 | 600 | ); |
601 | 601 | $grand_total_needs_resaving = true; |
602 | 602 | } |
@@ -3,13 +3,13 @@ |
||
3 | 3 | // if this is decaf, which is put on WordPress.org, we need to inform users that |
4 | 4 | // we just put an affiliate link there. See https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/ section 12 |
5 | 5 | if (apply_filters('FHEE__ee_show_affiliate_links', true)) { |
6 | - $closing_tag .= esc_html__(' (affiliate link)', 'event_espresso'); |
|
6 | + $closing_tag .= esc_html__(' (affiliate link)', 'event_espresso'); |
|
7 | 7 | } |
8 | 8 | printf( |
9 | - esc_html__( |
|
10 | - 'PayPal Standard (PayPal Payments Standard) is an off-site payment method and is available to event organizers in many countries. A PayPal premier or business account is needed to accept payments. Need a PayPal account? Call 1-855-456-1338 or %1$sclick here to sign up for a merchant account%2$s.', |
|
11 | - 'event_espresso' |
|
12 | - ), |
|
13 | - '<a href="https://eventespresso.com/go/paypalstandard/" target="_blank">', |
|
14 | - $closing_tag |
|
9 | + esc_html__( |
|
10 | + 'PayPal Standard (PayPal Payments Standard) is an off-site payment method and is available to event organizers in many countries. A PayPal premier or business account is needed to accept payments. Need a PayPal account? Call 1-855-456-1338 or %1$sclick here to sign up for a merchant account%2$s.', |
|
11 | + 'event_espresso' |
|
12 | + ), |
|
13 | + '<a href="https://eventespresso.com/go/paypalstandard/" target="_blank">', |
|
14 | + $closing_tag |
|
15 | 15 | ); |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php esc_html_e( |
2 | - 'Check is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay with a check.', |
|
3 | - 'event_espresso' |
|
2 | + 'Check is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay with a check.', |
|
3 | + 'event_espresso' |
|
4 | 4 | ); |
@@ -16,38 +16,38 @@ |
||
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * |
|
21 | - * @param EE_Payment_Method $pm_instance |
|
22 | - * @return EE_PMT_Admin_Only |
|
23 | - */ |
|
24 | - public function __construct($pm_instance = null) |
|
25 | - { |
|
26 | - $this->_pretty_name = __("Admin Only", 'event_espresso'); |
|
27 | - $this->_default_button_url = ''; |
|
28 | - parent::__construct($pm_instance); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Creates the billing form for this payment method type |
|
35 | - * @param \EE_Transaction $transaction |
|
36 | - * @return NULL |
|
37 | - */ |
|
38 | - public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
39 | - { |
|
40 | - return null; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Gets the form for all the settings related to this payment method type |
|
47 | - * @return EE_Payment_Method_Form |
|
48 | - */ |
|
49 | - public function generate_new_settings_form() |
|
50 | - { |
|
51 | - return new EE_Payment_Method_Form(); |
|
52 | - } |
|
19 | + /** |
|
20 | + * |
|
21 | + * @param EE_Payment_Method $pm_instance |
|
22 | + * @return EE_PMT_Admin_Only |
|
23 | + */ |
|
24 | + public function __construct($pm_instance = null) |
|
25 | + { |
|
26 | + $this->_pretty_name = __("Admin Only", 'event_espresso'); |
|
27 | + $this->_default_button_url = ''; |
|
28 | + parent::__construct($pm_instance); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Creates the billing form for this payment method type |
|
35 | + * @param \EE_Transaction $transaction |
|
36 | + * @return NULL |
|
37 | + */ |
|
38 | + public function generate_new_billing_form(EE_Transaction $transaction = null) |
|
39 | + { |
|
40 | + return null; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Gets the form for all the settings related to this payment method type |
|
47 | + * @return EE_Payment_Method_Form |
|
48 | + */ |
|
49 | + public function generate_new_settings_form() |
|
50 | + { |
|
51 | + return new EE_Payment_Method_Form(); |
|
52 | + } |
|
53 | 53 | } |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php esc_html_e( |
2 | - 'Bank is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay with a bank transfer.', |
|
3 | - 'event_espresso' |
|
2 | + 'Bank is an offline payment method for accepting payments. Payments are processed manually by providing your registrants/attendees with information on how to pay with a bank transfer.', |
|
3 | + 'event_espresso' |
|
4 | 4 | ); |
@@ -12,1420 +12,1420 @@ |
||
12 | 12 | class Pricing_Admin_Page extends EE_Admin_Page |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * constructor |
|
17 | - * |
|
18 | - * @Constructor |
|
19 | - * @access public |
|
20 | - * @param bool $routing |
|
21 | - * @return Pricing_Admin_Page |
|
22 | - */ |
|
23 | - public function __construct($routing = true) |
|
24 | - { |
|
25 | - parent::__construct($routing); |
|
26 | - } |
|
27 | - |
|
28 | - |
|
29 | - protected function _init_page_props() |
|
30 | - { |
|
31 | - $this->page_slug = PRICING_PG_SLUG; |
|
32 | - $this->page_label = PRICING_LABEL; |
|
33 | - $this->_admin_base_url = PRICING_ADMIN_URL; |
|
34 | - $this->_admin_base_path = PRICING_ADMIN; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - protected function _ajax_hooks() |
|
39 | - { |
|
40 | - add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order')); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - protected function _define_page_props() |
|
45 | - { |
|
46 | - $this->_admin_page_title = PRICING_LABEL; |
|
47 | - $this->_labels = array( |
|
48 | - 'buttons' => array( |
|
49 | - 'add' => __('Add New Default Price', 'event_espresso'), |
|
50 | - 'edit' => __('Edit Default Price', 'event_espresso'), |
|
51 | - 'delete' => __('Delete Default Price', 'event_espresso'), |
|
52 | - 'add_type' => __('Add New Default Price Type', 'event_espresso'), |
|
53 | - 'edit_type' => __('Edit Price Type', 'event_espresso'), |
|
54 | - 'delete_type' => __('Delete Price Type', 'event_espresso'), |
|
55 | - ), |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * an array for storing request actions and their corresponding methods |
|
62 | - * |
|
63 | - * @access private |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - protected function _set_page_routes() |
|
67 | - { |
|
68 | - $prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID']) |
|
69 | - ? $this->_req_data['PRC_ID'] : 0; |
|
70 | - $prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID']) |
|
71 | - ? $this->_req_data['PRT_ID'] : 0; |
|
72 | - $this->_page_routes = array( |
|
73 | - 'default' => array( |
|
74 | - 'func' => '_price_overview_list_table', |
|
75 | - 'capability' => 'ee_read_default_prices', |
|
76 | - ), |
|
77 | - 'add_new_price' => array( |
|
78 | - 'func' => '_edit_price_details', |
|
79 | - 'args' => array('new_price' => true), |
|
80 | - 'capability' => 'ee_edit_default_prices', |
|
81 | - ), |
|
82 | - 'edit_price' => array( |
|
83 | - 'func' => '_edit_price_details', |
|
84 | - 'args' => array('new_price' => false), |
|
85 | - 'capability' => 'ee_edit_default_price', |
|
86 | - 'obj_id' => $prc_id, |
|
87 | - ), |
|
88 | - 'insert_price' => array( |
|
89 | - 'func' => '_insert_or_update_price', |
|
90 | - 'args' => array('new_price' => true), |
|
91 | - 'noheader' => true, |
|
92 | - 'capability' => 'ee_edit_default_prices', |
|
93 | - ), |
|
94 | - 'update_price' => array( |
|
95 | - 'func' => '_insert_or_update_price', |
|
96 | - 'args' => array('new_price' => false), |
|
97 | - 'noheader' => true, |
|
98 | - 'capability' => 'ee_edit_default_price', |
|
99 | - 'obj_id' => $prc_id, |
|
100 | - ), |
|
101 | - 'trash_price' => array( |
|
102 | - 'func' => '_trash_or_restore_price', |
|
103 | - 'args' => array('trash' => true), |
|
104 | - 'noheader' => true, |
|
105 | - 'capability' => 'ee_delete_default_price', |
|
106 | - 'obj_id' => $prc_id, |
|
107 | - ), |
|
108 | - 'restore_price' => array( |
|
109 | - 'func' => '_trash_or_restore_price', |
|
110 | - 'args' => array('trash' => false), |
|
111 | - 'noheader' => true, |
|
112 | - 'capability' => 'ee_delete_default_price', |
|
113 | - 'obj_id' => $prc_id, |
|
114 | - ), |
|
115 | - 'delete_price' => array( |
|
116 | - 'func' => '_delete_price', |
|
117 | - 'noheader' => true, |
|
118 | - 'capability' => 'ee_delete_default_price', |
|
119 | - 'obj_id' => $prc_id, |
|
120 | - ), |
|
121 | - 'espresso_update_price_order' => array( |
|
122 | - 'func' => 'update_price_order', |
|
123 | - 'noheader' => true, |
|
124 | - 'capability' => 'ee_edit_default_prices', |
|
125 | - ), |
|
126 | - // price types |
|
127 | - 'price_types' => array( |
|
128 | - 'func' => '_price_types_overview_list_table', |
|
129 | - 'capability' => 'ee_read_default_price_types', |
|
130 | - ), |
|
131 | - 'add_new_price_type' => array( |
|
132 | - 'func' => '_edit_price_type_details', |
|
133 | - 'capability' => 'ee_edit_default_price_types', |
|
134 | - ), |
|
135 | - 'edit_price_type' => array( |
|
136 | - 'func' => '_edit_price_type_details', |
|
137 | - 'capability' => 'ee_edit_default_price_type', |
|
138 | - 'obj_id' => $prt_id, |
|
139 | - ), |
|
140 | - 'insert_price_type' => array( |
|
141 | - 'func' => '_insert_or_update_price_type', |
|
142 | - 'args' => array('new_price_type' => true), |
|
143 | - 'noheader' => true, |
|
144 | - 'capability' => 'ee_edit_default_price_types', |
|
145 | - ), |
|
146 | - 'update_price_type' => array( |
|
147 | - 'func' => '_insert_or_update_price_type', |
|
148 | - 'args' => array('new_price_type' => false), |
|
149 | - 'noheader' => true, |
|
150 | - 'capability' => 'ee_edit_default_price_type', |
|
151 | - 'obj_id' => $prt_id, |
|
152 | - ), |
|
153 | - 'trash_price_type' => array( |
|
154 | - 'func' => '_trash_or_restore_price_type', |
|
155 | - 'args' => array('trash' => true), |
|
156 | - 'noheader' => true, |
|
157 | - 'capability' => 'ee_delete_default_price_type', |
|
158 | - 'obj_id' => $prt_id, |
|
159 | - ), |
|
160 | - 'restore_price_type' => array( |
|
161 | - 'func' => '_trash_or_restore_price_type', |
|
162 | - 'args' => array('trash' => false), |
|
163 | - 'noheader' => true, |
|
164 | - 'capability' => 'ee_delete_default_price_type', |
|
165 | - 'obj_id' => $prt_id, |
|
166 | - ), |
|
167 | - 'delete_price_type' => array( |
|
168 | - 'func' => '_delete_price_type', |
|
169 | - 'noheader' => true, |
|
170 | - 'capability' => 'ee_delete_default_price_type', |
|
171 | - 'obj_id' => $prt_id, |
|
172 | - ), |
|
173 | - 'tax_settings' => array( |
|
174 | - 'func' => '_tax_settings', |
|
175 | - 'capability' => 'manage_options', |
|
176 | - ), |
|
177 | - 'update_tax_settings' => array( |
|
178 | - 'func' => '_update_tax_settings', |
|
179 | - 'capability' => 'manage_options', |
|
180 | - 'noheader' => true, |
|
181 | - ), |
|
182 | - ); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - protected function _set_page_config() |
|
187 | - { |
|
188 | - |
|
189 | - $this->_page_config = array( |
|
190 | - 'default' => array( |
|
191 | - 'nav' => array( |
|
192 | - 'label' => __('Default Pricing', 'event_espresso'), |
|
193 | - 'order' => 10, |
|
194 | - ), |
|
195 | - 'list_table' => 'Prices_List_Table', |
|
196 | - 'help_tabs' => array( |
|
197 | - 'pricing_default_pricing_help_tab' => array( |
|
198 | - 'title' => __('Default Pricing', 'event_espresso'), |
|
199 | - 'filename' => 'pricing_default_pricing', |
|
200 | - ), |
|
201 | - 'pricing_default_pricing_table_column_headings_help_tab' => array( |
|
202 | - 'title' => __('Default Pricing Table Column Headings', 'event_espresso'), |
|
203 | - 'filename' => 'pricing_default_pricing_table_column_headings', |
|
204 | - ), |
|
205 | - 'pricing_default_pricing_views_bulk_actions_search_help_tab' => array( |
|
206 | - 'title' => __('Default Pricing Views & Bulk Actions & Search', 'event_espresso'), |
|
207 | - 'filename' => 'pricing_default_pricing_views_bulk_actions_search', |
|
208 | - ), |
|
209 | - ), |
|
210 | - 'help_tour' => array('Pricing_Default_Prices_Help_Tour'), |
|
211 | - 'require_nonce' => false, |
|
212 | - ), |
|
213 | - 'add_new_price' => array( |
|
214 | - 'nav' => array( |
|
215 | - 'label' => __('Add New Default Price', 'event_espresso'), |
|
216 | - 'order' => 20, |
|
217 | - 'persistent' => false, |
|
218 | - ), |
|
219 | - 'help_tabs' => array( |
|
220 | - 'add_new_default_price_help_tab' => array( |
|
221 | - 'title' => __('Add New Default Price', 'event_espresso'), |
|
222 | - 'filename' => 'pricing_add_new_default_price', |
|
223 | - ), |
|
224 | - ), |
|
225 | - 'help_tour' => array('Pricing_Add_New_Default_Price_Help_Tour'), |
|
226 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
227 | - 'require_nonce' => false, |
|
228 | - ), |
|
229 | - 'edit_price' => array( |
|
230 | - 'nav' => array( |
|
231 | - 'label' => __('Edit Default Price', 'event_espresso'), |
|
232 | - 'order' => 20, |
|
233 | - 'url' => isset($this->_req_data['id']) ? add_query_arg( |
|
234 | - array('id' => $this->_req_data['id']), |
|
235 | - $this->_current_page_view_url |
|
236 | - ) : $this->_admin_base_url, |
|
237 | - 'persistent' => false, |
|
238 | - ), |
|
239 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
240 | - 'help_tabs' => array( |
|
241 | - 'edit_default_price_help_tab' => array( |
|
242 | - 'title' => __('Edit Default Price', 'event_espresso'), |
|
243 | - 'filename' => 'pricing_edit_default_price', |
|
244 | - ), |
|
245 | - ), |
|
246 | - 'help_tour' => array('Pricing_Edit_Default_Price_Help_Tour'), |
|
247 | - 'require_nonce' => false, |
|
248 | - ), |
|
249 | - 'price_types' => array( |
|
250 | - 'nav' => array( |
|
251 | - 'label' => __('Price Types', 'event_espresso'), |
|
252 | - 'order' => 30, |
|
253 | - ), |
|
254 | - 'list_table' => 'Price_Types_List_Table', |
|
255 | - 'help_tabs' => array( |
|
256 | - 'pricing_price_types_help_tab' => array( |
|
257 | - 'title' => __('Price Types', 'event_espresso'), |
|
258 | - 'filename' => 'pricing_price_types', |
|
259 | - ), |
|
260 | - 'pricing_price_types_table_column_headings_help_tab' => array( |
|
261 | - 'title' => __('Price Types Table Column Headings', 'event_espresso'), |
|
262 | - 'filename' => 'pricing_price_types_table_column_headings', |
|
263 | - ), |
|
264 | - 'pricing_price_types_views_bulk_actions_search_help_tab' => array( |
|
265 | - 'title' => __('Price Types Views & Bulk Actions & Search', 'event_espresso'), |
|
266 | - 'filename' => 'pricing_price_types_views_bulk_actions_search', |
|
267 | - ), |
|
268 | - ), |
|
269 | - 'help_tour' => array('Pricing_Price_Types_Default_Help_Tour'), |
|
270 | - 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
271 | - 'require_nonce' => false, |
|
272 | - ), |
|
273 | - 'add_new_price_type' => array( |
|
274 | - 'nav' => array( |
|
275 | - 'label' => __('Add New Price Type', 'event_espresso'), |
|
276 | - 'order' => 40, |
|
277 | - 'persistent' => false, |
|
278 | - ), |
|
279 | - 'help_tabs' => array( |
|
280 | - 'add_new_price_type_help_tab' => array( |
|
281 | - 'title' => __('Add New Price Type', 'event_espresso'), |
|
282 | - 'filename' => 'pricing_add_new_price_type', |
|
283 | - ), |
|
284 | - ), |
|
285 | - 'help_tour' => array('Pricing_Add_New_Price_Type_Help_Tour'), |
|
286 | - 'metaboxes' => array( |
|
287 | - '_publish_post_box', |
|
288 | - '_espresso_news_post_box', |
|
289 | - '_price_type_details_meta_boxes', |
|
290 | - ), |
|
291 | - 'require_nonce' => false, |
|
292 | - ), |
|
293 | - 'edit_price_type' => array( |
|
294 | - 'nav' => array( |
|
295 | - 'label' => __('Edit Price Type', 'event_espresso'), |
|
296 | - 'order' => 40, |
|
297 | - 'persistent' => false, |
|
298 | - ), |
|
299 | - 'help_tabs' => array( |
|
300 | - 'edit_price_type_help_tab' => array( |
|
301 | - 'title' => __('Edit Price Type', 'event_espresso'), |
|
302 | - 'filename' => 'pricing_edit_price_type', |
|
303 | - ), |
|
304 | - ), |
|
305 | - 'help_tour' => array('Pricing_Edit_Price_Type_Help_Tour'), |
|
306 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'), |
|
307 | - |
|
308 | - 'require_nonce' => false, |
|
309 | - ), |
|
310 | - 'tax_settings' => array( |
|
311 | - 'nav' => array( |
|
312 | - 'label' => esc_html__('Tax Settings', 'event_espresso'), |
|
313 | - 'order' => 40, |
|
314 | - ), |
|
315 | - 'labels' => array( |
|
316 | - 'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'), |
|
317 | - ), |
|
318 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
319 | - // 'help_tabs' => array( |
|
320 | - // 'registration_form_reg_form_settings_help_tab' => array( |
|
321 | - // 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
322 | - // 'filename' => 'registration_form_reg_form_settings' |
|
323 | - // ), |
|
324 | - // ), |
|
325 | - // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
326 | - 'require_nonce' => true, |
|
327 | - ), |
|
328 | - ); |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - protected function _add_screen_options() |
|
333 | - { |
|
334 | - // todo |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - protected function _add_screen_options_default() |
|
339 | - { |
|
340 | - $this->_per_page_screen_option(); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - protected function _add_screen_options_price_types() |
|
345 | - { |
|
346 | - $page_title = $this->_admin_page_title; |
|
347 | - $this->_admin_page_title = __('Price Types', 'event_espresso'); |
|
348 | - $this->_per_page_screen_option(); |
|
349 | - $this->_admin_page_title = $page_title; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - protected function _add_feature_pointers() |
|
354 | - { |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - public function load_scripts_styles() |
|
359 | - { |
|
360 | - // styles |
|
361 | - wp_enqueue_style('espresso-ui-theme'); |
|
362 | - wp_register_style( |
|
363 | - 'espresso_PRICING', |
|
364 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.css', |
|
365 | - array(), |
|
366 | - EVENT_ESPRESSO_VERSION |
|
367 | - ); |
|
368 | - wp_enqueue_style('espresso_PRICING'); |
|
369 | - |
|
370 | - // scripts |
|
371 | - wp_enqueue_script('ee_admin_js'); |
|
372 | - wp_enqueue_script('jquery-ui-position'); |
|
373 | - wp_enqueue_script('jquery-ui-widget'); |
|
374 | - // wp_enqueue_script('jquery-ui-dialog'); |
|
375 | - // wp_enqueue_script('jquery-ui-draggable'); |
|
376 | - // wp_enqueue_script('jquery-ui-datepicker'); |
|
377 | - wp_register_script( |
|
378 | - 'espresso_PRICING', |
|
379 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.js', |
|
380 | - array('jquery'), |
|
381 | - EVENT_ESPRESSO_VERSION, |
|
382 | - true |
|
383 | - ); |
|
384 | - wp_enqueue_script('espresso_PRICING'); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - public function load_scripts_styles_default() |
|
389 | - { |
|
390 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - public function admin_footer_scripts() |
|
395 | - { |
|
396 | - } |
|
397 | - |
|
398 | - public function admin_init() |
|
399 | - { |
|
400 | - } |
|
401 | - |
|
402 | - public function admin_notices() |
|
403 | - { |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - protected function _set_list_table_views_default() |
|
408 | - { |
|
409 | - $this->_views = array( |
|
410 | - 'all' => array( |
|
411 | - 'slug' => 'all', |
|
412 | - 'label' => __('View All Default Pricing', 'event_espresso'), |
|
413 | - 'count' => 0, |
|
414 | - 'bulk_action' => array( |
|
415 | - 'trash_price' => __('Move to Trash', 'event_espresso'), |
|
416 | - ), |
|
417 | - ), |
|
418 | - ); |
|
419 | - |
|
420 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
421 | - $this->_views['trashed'] = array( |
|
422 | - 'slug' => 'trashed', |
|
423 | - 'label' => __('Trash', 'event_espresso'), |
|
424 | - 'count' => 0, |
|
425 | - 'bulk_action' => array( |
|
426 | - 'restore_price' => __('Restore from Trash', 'event_espresso'), |
|
427 | - 'delete_price' => __('Delete Permanently', 'event_espresso'), |
|
428 | - ), |
|
429 | - ); |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - protected function _set_list_table_views_price_types() |
|
435 | - { |
|
436 | - $this->_views = array( |
|
437 | - 'all' => array( |
|
438 | - 'slug' => 'all', |
|
439 | - 'label' => __('All', 'event_espresso'), |
|
440 | - 'count' => 0, |
|
441 | - 'bulk_action' => array( |
|
442 | - 'trash_price_type' => __('Move to Trash', 'event_espresso'), |
|
443 | - ), |
|
444 | - ), |
|
445 | - ); |
|
446 | - |
|
447 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
448 | - 'ee_delete_default_price_types', |
|
449 | - 'pricing_trash_price_type' |
|
450 | - )) { |
|
451 | - $this->_views['trashed'] = array( |
|
452 | - 'slug' => 'trashed', |
|
453 | - 'label' => __('Trash', 'event_espresso'), |
|
454 | - 'count' => 0, |
|
455 | - 'bulk_action' => array( |
|
456 | - 'restore_price_type' => __('Restore from Trash', 'event_espresso'), |
|
457 | - 'delete_price_type' => __('Delete Permanently', 'event_espresso'), |
|
458 | - ), |
|
459 | - ); |
|
460 | - } |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * generates HTML for main Prices Admin page |
|
466 | - * |
|
467 | - * @access protected |
|
468 | - * @return void |
|
469 | - */ |
|
470 | - protected function _price_overview_list_table() |
|
471 | - { |
|
472 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
473 | - 'add_new_price', |
|
474 | - 'add', |
|
475 | - array(), |
|
476 | - 'add-new-h2' |
|
477 | - ); |
|
478 | - $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
479 | - $this->_search_btn_label = __('Default Prices', 'event_espresso'); |
|
480 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - /** |
|
485 | - * retrieve data for Prices List table |
|
486 | - * |
|
487 | - * @access public |
|
488 | - * @param int $per_page how many prices displayed per page |
|
489 | - * @param boolean $count return the count or objects |
|
490 | - * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
491 | - * @return mixed (int|array) int = count || array of price objects |
|
492 | - */ |
|
493 | - public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false) |
|
494 | - { |
|
495 | - |
|
496 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
497 | - // start with an empty array |
|
498 | - $event_pricing = array(); |
|
499 | - |
|
500 | - require_once(PRICING_ADMIN . 'Prices_List_Table.class.php'); |
|
501 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
502 | - // $PRC = EEM_Price::instance(); |
|
503 | - |
|
504 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
505 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
506 | - : 'ASC'; |
|
507 | - |
|
508 | - switch ($this->_req_data['orderby']) { |
|
509 | - case 'name': |
|
510 | - $orderby = array('PRC_name' => $order); |
|
511 | - break; |
|
512 | - case 'type': |
|
513 | - $orderby = array('Price_Type.PRT_name' => $order); |
|
514 | - break; |
|
515 | - case 'amount': |
|
516 | - $orderby = array('PRC_amount' => $order); |
|
517 | - break; |
|
518 | - default: |
|
519 | - $orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order); |
|
520 | - } |
|
521 | - |
|
522 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
523 | - ? $this->_req_data['paged'] : 1; |
|
524 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
525 | - ? $this->_req_data['perpage'] : $per_page; |
|
526 | - |
|
527 | - $_where = array( |
|
528 | - 'PRC_is_default' => 1, |
|
529 | - 'PRC_deleted' => $trashed, |
|
530 | - ); |
|
531 | - |
|
532 | - $offset = ($current_page - 1) * $per_page; |
|
533 | - $limit = array($offset, $per_page); |
|
534 | - |
|
535 | - if (isset($this->_req_data['s'])) { |
|
536 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
537 | - $_where['OR'] = array( |
|
538 | - 'PRC_name' => array('LIKE', $sstr), |
|
539 | - 'PRC_desc' => array('LIKE', $sstr), |
|
540 | - 'PRC_amount' => array('LIKE', $sstr), |
|
541 | - 'Price_Type.PRT_name' => array('LIKE', $sstr), |
|
542 | - ); |
|
543 | - } |
|
544 | - |
|
545 | - $query_params = array( |
|
546 | - $_where, |
|
547 | - 'order_by' => $orderby, |
|
548 | - 'limit' => $limit, |
|
549 | - 'group_by' => 'PRC_ID', |
|
550 | - ); |
|
551 | - |
|
552 | - if ($count) { |
|
553 | - return $trashed ? EEM_Price::instance()->count(array($_where)) |
|
554 | - : EEM_Price::instance()->count_deleted_and_undeleted(array($_where)); |
|
555 | - } else { |
|
556 | - return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params); |
|
557 | - } |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * _price_details |
|
563 | - * |
|
564 | - * @access protected |
|
565 | - * @return void |
|
566 | - */ |
|
567 | - protected function _edit_price_details() |
|
568 | - { |
|
569 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
570 | - // grab price ID |
|
571 | - $PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
572 | - : false; |
|
573 | - // change page title based on request action |
|
574 | - switch ($this->_req_action) { |
|
575 | - case 'add_new_price': |
|
576 | - $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso'); |
|
577 | - break; |
|
578 | - case 'edit_price': |
|
579 | - $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso'); |
|
580 | - break; |
|
581 | - default: |
|
582 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
583 | - } |
|
584 | - // add PRC_ID to title if editing |
|
585 | - $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title; |
|
586 | - |
|
587 | - // get prices |
|
588 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
589 | - $PRC = EEM_Price::instance(); |
|
590 | - |
|
591 | - if ($PRC_ID) { |
|
592 | - $price = $PRC->get_one_by_ID($PRC_ID); |
|
593 | - $additional_hidden_fields = array( |
|
594 | - 'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID), |
|
595 | - ); |
|
596 | - $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields); |
|
597 | - } else { |
|
598 | - $price = $PRC->get_new_price(); |
|
599 | - $this->_set_add_edit_form_tags('insert_price'); |
|
600 | - } |
|
601 | - |
|
602 | - $this->_template_args['PRC_ID'] = $PRC_ID; |
|
603 | - $this->_template_args['price'] = $price; |
|
604 | - |
|
605 | - // get price types |
|
606 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
607 | - $PRT = EEM_Price_Type::instance(); |
|
608 | - $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1)))); |
|
609 | - $price_type_names = array(); |
|
610 | - if (empty($price_types)) { |
|
611 | - $msg = __( |
|
612 | - 'You have no price types defined. Please add a price type before adding a price.', |
|
613 | - 'event_espresso' |
|
614 | - ); |
|
615 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
616 | - exit(); |
|
617 | - } else { |
|
618 | - foreach ($price_types as $type) { |
|
619 | - // if ($type->is_global()) { |
|
620 | - $price_type_names[] = array('id' => $type->ID(), 'text' => $type->name()); |
|
621 | - // } |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - $this->_template_args['price_types'] = $price_type_names; |
|
626 | - $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
627 | - |
|
628 | - $this->_set_publish_post_box_vars('id', $PRC_ID); |
|
629 | - // the details template wrapper |
|
630 | - $this->display_admin_page_with_sidebar(); |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - /** |
|
635 | - * declare price details page metaboxes |
|
636 | - * |
|
637 | - * @access protected |
|
638 | - * @return void |
|
639 | - */ |
|
640 | - protected function _price_details_meta_boxes() |
|
641 | - { |
|
642 | - add_meta_box( |
|
643 | - 'edit-price-details-mbox', |
|
644 | - __('Default Price Details', 'event_espresso'), |
|
645 | - array($this, '_edit_price_details_meta_box'), |
|
646 | - $this->wp_page_slug, |
|
647 | - 'normal', |
|
648 | - 'high' |
|
649 | - ); |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * _edit_price_details_meta_box |
|
655 | - * |
|
656 | - * @access public |
|
657 | - * @return void |
|
658 | - */ |
|
659 | - public function _edit_price_details_meta_box() |
|
660 | - { |
|
661 | - echo EEH_Template::display_template( |
|
662 | - PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', |
|
663 | - $this->_template_args, |
|
664 | - true |
|
665 | - ); |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * set_price_column_values |
|
671 | - * |
|
672 | - * @access protected |
|
673 | - * @return array |
|
674 | - */ |
|
675 | - protected function set_price_column_values() |
|
676 | - { |
|
677 | - |
|
678 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
679 | - |
|
680 | - $set_column_values = array( |
|
681 | - 'PRT_ID' => absint($this->_req_data['PRT_ID']), |
|
682 | - 'PRC_amount' => $this->_req_data['PRC_amount'], |
|
683 | - 'PRC_name' => $this->_req_data['PRC_name'], |
|
684 | - 'PRC_desc' => $this->_req_data['PRC_desc'], |
|
685 | - 'PRC_is_default' => 1, |
|
686 | - 'PRC_overrides' => null, |
|
687 | - 'PRC_order' => 0, |
|
688 | - 'PRC_deleted' => 0, |
|
689 | - 'PRC_parent' => 0, |
|
690 | - ); |
|
691 | - return $set_column_values; |
|
692 | - } |
|
693 | - |
|
694 | - |
|
695 | - /** |
|
696 | - * insert_or_update_price |
|
697 | - * |
|
698 | - * @param boolean $insert - whether to insert or update |
|
699 | - * @access protected |
|
700 | - * @return void |
|
701 | - */ |
|
702 | - protected function _insert_or_update_price($insert = false) |
|
703 | - { |
|
704 | - |
|
705 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
706 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
707 | - |
|
708 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
709 | - $PRC = EEM_Price::instance(); |
|
710 | - |
|
711 | - // why be so pessimistic ??? : ( |
|
712 | - $success = 0; |
|
713 | - |
|
714 | - $set_column_values = $this->set_price_column_values(); |
|
715 | - // is this a new Price ? |
|
716 | - if ($insert) { |
|
717 | - // run the insert |
|
718 | - if ($PRC_ID = $PRC->insert($set_column_values)) { |
|
719 | - // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type |
|
720 | - $PR = EEM_price::instance()->get_one_by_ID($PRC_ID); |
|
721 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
722 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
723 | - $ticket->_add_relation_to($PR, 'Price'); |
|
724 | - $ticket->save(); |
|
725 | - } |
|
726 | - $success = 1; |
|
727 | - } else { |
|
728 | - $PRC_ID = false; |
|
729 | - $success = 0; |
|
730 | - } |
|
731 | - $action_desc = 'created'; |
|
732 | - } else { |
|
733 | - $PRC_ID = absint($this->_req_data['PRC_ID']); |
|
734 | - // run the update |
|
735 | - $where_cols_n_values = array('PRC_ID' => $PRC_ID); |
|
736 | - if ($PRC->update($set_column_values, array($where_cols_n_values))) { |
|
737 | - $success = 1; |
|
738 | - } |
|
739 | - |
|
740 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
741 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
742 | - // if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated. |
|
743 | - if ($PRC_ID === 1) { |
|
744 | - $ticket = $PR->get_first_related('Ticket'); |
|
745 | - if ($ticket) { |
|
746 | - $ticket->set('TKT_price', $PR->get('PRC_amount')); |
|
747 | - $ticket->set('TKT_name', $PR->get('PRC_name')); |
|
748 | - $ticket->set('TKT_description', $PR->get('PRC_desc')); |
|
749 | - $ticket->save(); |
|
750 | - } |
|
751 | - } else { |
|
752 | - // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type. |
|
753 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
754 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
755 | - $ticket->save(); |
|
756 | - } |
|
757 | - } |
|
758 | - |
|
759 | - $action_desc = 'updated'; |
|
760 | - } |
|
761 | - |
|
762 | - $query_args = array('action' => 'edit_price', 'id' => $PRC_ID); |
|
763 | - |
|
764 | - $this->_redirect_after_action($success, 'Prices', $action_desc, $query_args); |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * _trash_or_restore_price |
|
770 | - * |
|
771 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
772 | - * @access protected |
|
773 | - * @return void |
|
774 | - */ |
|
775 | - protected function _trash_or_restore_price($trash = true) |
|
776 | - { |
|
777 | - |
|
778 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
779 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
780 | - |
|
781 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
782 | - $PRC = EEM_Price::instance(); |
|
783 | - |
|
784 | - $success = 1; |
|
785 | - $PRC_deleted = $trash ? true : false; |
|
786 | - |
|
787 | - // get base ticket for updating |
|
788 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
789 | - // Checkboxes |
|
790 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
791 | - // if array has more than one element than success message should be plural |
|
792 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
793 | - // cycle thru checkboxes |
|
794 | - while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
795 | - if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
796 | - $success = 0; |
|
797 | - } else { |
|
798 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
799 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
800 | - // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
801 | - if ($PRC_deleted) { |
|
802 | - $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
803 | - } else { |
|
804 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
805 | - } |
|
806 | - $ticket->save(); |
|
807 | - } |
|
808 | - } |
|
809 | - } |
|
810 | - } else { |
|
811 | - // grab single id and delete |
|
812 | - $PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
813 | - if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) { |
|
814 | - $success = 0; |
|
815 | - } else { |
|
816 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
817 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
818 | - // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
819 | - if ($PRC_deleted) { |
|
820 | - $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
821 | - } else { |
|
822 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
823 | - } |
|
824 | - $ticket->save(); |
|
825 | - } |
|
826 | - } |
|
827 | - } |
|
828 | - $query_args = array( |
|
829 | - 'action' => 'default', |
|
830 | - ); |
|
831 | - |
|
832 | - if ($success) { |
|
833 | - if ($trash) { |
|
834 | - $msg = $success == 2 |
|
835 | - ? __('The Prices have been trashed.', 'event_espresso') |
|
836 | - : __( |
|
837 | - 'The Price has been trashed.', |
|
838 | - 'event_espresso' |
|
839 | - ); |
|
840 | - } else { |
|
841 | - $msg = $success == 2 |
|
842 | - ? __('The Prices have been restored.', 'event_espresso') |
|
843 | - : __( |
|
844 | - 'The Price has been restored.', |
|
845 | - 'event_espresso' |
|
846 | - ); |
|
847 | - } |
|
848 | - |
|
849 | - EE_Error::add_success($msg); |
|
850 | - } |
|
851 | - |
|
852 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
853 | - } |
|
854 | - |
|
855 | - |
|
856 | - /** |
|
857 | - * _delete_price |
|
858 | - * |
|
859 | - * @access protected |
|
860 | - * @return void |
|
861 | - */ |
|
862 | - protected function _delete_price() |
|
863 | - { |
|
864 | - |
|
865 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
866 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
867 | - |
|
868 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
869 | - $PRC = EEM_Price::instance(); |
|
870 | - |
|
871 | - $success = 1; |
|
872 | - // Checkboxes |
|
873 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
874 | - // if array has more than one element than success message should be plural |
|
875 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
876 | - // cycle thru bulk action checkboxes |
|
877 | - while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
878 | - if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
879 | - $success = 0; |
|
880 | - } |
|
881 | - } |
|
882 | - } else { |
|
883 | - // grab single id and delete |
|
884 | - $PRC_ID = absint($this->_req_data['id']); |
|
885 | - if (! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
886 | - $success = 0; |
|
887 | - } |
|
888 | - } |
|
889 | - |
|
890 | - $this->_redirect_after_action($success, 'Prices', 'deleted', array()); |
|
891 | - } |
|
892 | - |
|
893 | - |
|
894 | - public function update_price_order() |
|
895 | - { |
|
896 | - $success = __('Price order was updated successfully.', 'event_espresso'); |
|
897 | - |
|
898 | - // grab our row IDs |
|
899 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode( |
|
900 | - ',', |
|
901 | - rtrim( |
|
902 | - $this->_req_data['row_ids'], |
|
903 | - ',' |
|
904 | - ) |
|
905 | - ) : false; |
|
906 | - |
|
907 | - if (is_array($row_ids)) { |
|
908 | - for ($i = 0; $i < count($row_ids); $i++) { |
|
909 | - // Update the prices when re-ordering |
|
910 | - $id = absint($row_ids[ $i ]); |
|
911 | - if (EEM_Price::instance()->update( |
|
912 | - array('PRC_order' => $i + 1), |
|
913 | - array(array('PRC_ID' => $id)) |
|
914 | - ) === false) { |
|
915 | - $success = false; |
|
916 | - } |
|
917 | - } |
|
918 | - } else { |
|
919 | - $success = false; |
|
920 | - } |
|
921 | - |
|
922 | - $errors = ! $success ? __('An error occurred. The price order was not updated.', 'event_espresso') : false; |
|
923 | - |
|
924 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
925 | - die(); |
|
926 | - } |
|
927 | - |
|
928 | - |
|
929 | - |
|
930 | - |
|
931 | - |
|
932 | - |
|
933 | - /************************************************************************************************************************************************************** |
|
15 | + /** |
|
16 | + * constructor |
|
17 | + * |
|
18 | + * @Constructor |
|
19 | + * @access public |
|
20 | + * @param bool $routing |
|
21 | + * @return Pricing_Admin_Page |
|
22 | + */ |
|
23 | + public function __construct($routing = true) |
|
24 | + { |
|
25 | + parent::__construct($routing); |
|
26 | + } |
|
27 | + |
|
28 | + |
|
29 | + protected function _init_page_props() |
|
30 | + { |
|
31 | + $this->page_slug = PRICING_PG_SLUG; |
|
32 | + $this->page_label = PRICING_LABEL; |
|
33 | + $this->_admin_base_url = PRICING_ADMIN_URL; |
|
34 | + $this->_admin_base_path = PRICING_ADMIN; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + protected function _ajax_hooks() |
|
39 | + { |
|
40 | + add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order')); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + protected function _define_page_props() |
|
45 | + { |
|
46 | + $this->_admin_page_title = PRICING_LABEL; |
|
47 | + $this->_labels = array( |
|
48 | + 'buttons' => array( |
|
49 | + 'add' => __('Add New Default Price', 'event_espresso'), |
|
50 | + 'edit' => __('Edit Default Price', 'event_espresso'), |
|
51 | + 'delete' => __('Delete Default Price', 'event_espresso'), |
|
52 | + 'add_type' => __('Add New Default Price Type', 'event_espresso'), |
|
53 | + 'edit_type' => __('Edit Price Type', 'event_espresso'), |
|
54 | + 'delete_type' => __('Delete Price Type', 'event_espresso'), |
|
55 | + ), |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * an array for storing request actions and their corresponding methods |
|
62 | + * |
|
63 | + * @access private |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + protected function _set_page_routes() |
|
67 | + { |
|
68 | + $prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID']) |
|
69 | + ? $this->_req_data['PRC_ID'] : 0; |
|
70 | + $prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID']) |
|
71 | + ? $this->_req_data['PRT_ID'] : 0; |
|
72 | + $this->_page_routes = array( |
|
73 | + 'default' => array( |
|
74 | + 'func' => '_price_overview_list_table', |
|
75 | + 'capability' => 'ee_read_default_prices', |
|
76 | + ), |
|
77 | + 'add_new_price' => array( |
|
78 | + 'func' => '_edit_price_details', |
|
79 | + 'args' => array('new_price' => true), |
|
80 | + 'capability' => 'ee_edit_default_prices', |
|
81 | + ), |
|
82 | + 'edit_price' => array( |
|
83 | + 'func' => '_edit_price_details', |
|
84 | + 'args' => array('new_price' => false), |
|
85 | + 'capability' => 'ee_edit_default_price', |
|
86 | + 'obj_id' => $prc_id, |
|
87 | + ), |
|
88 | + 'insert_price' => array( |
|
89 | + 'func' => '_insert_or_update_price', |
|
90 | + 'args' => array('new_price' => true), |
|
91 | + 'noheader' => true, |
|
92 | + 'capability' => 'ee_edit_default_prices', |
|
93 | + ), |
|
94 | + 'update_price' => array( |
|
95 | + 'func' => '_insert_or_update_price', |
|
96 | + 'args' => array('new_price' => false), |
|
97 | + 'noheader' => true, |
|
98 | + 'capability' => 'ee_edit_default_price', |
|
99 | + 'obj_id' => $prc_id, |
|
100 | + ), |
|
101 | + 'trash_price' => array( |
|
102 | + 'func' => '_trash_or_restore_price', |
|
103 | + 'args' => array('trash' => true), |
|
104 | + 'noheader' => true, |
|
105 | + 'capability' => 'ee_delete_default_price', |
|
106 | + 'obj_id' => $prc_id, |
|
107 | + ), |
|
108 | + 'restore_price' => array( |
|
109 | + 'func' => '_trash_or_restore_price', |
|
110 | + 'args' => array('trash' => false), |
|
111 | + 'noheader' => true, |
|
112 | + 'capability' => 'ee_delete_default_price', |
|
113 | + 'obj_id' => $prc_id, |
|
114 | + ), |
|
115 | + 'delete_price' => array( |
|
116 | + 'func' => '_delete_price', |
|
117 | + 'noheader' => true, |
|
118 | + 'capability' => 'ee_delete_default_price', |
|
119 | + 'obj_id' => $prc_id, |
|
120 | + ), |
|
121 | + 'espresso_update_price_order' => array( |
|
122 | + 'func' => 'update_price_order', |
|
123 | + 'noheader' => true, |
|
124 | + 'capability' => 'ee_edit_default_prices', |
|
125 | + ), |
|
126 | + // price types |
|
127 | + 'price_types' => array( |
|
128 | + 'func' => '_price_types_overview_list_table', |
|
129 | + 'capability' => 'ee_read_default_price_types', |
|
130 | + ), |
|
131 | + 'add_new_price_type' => array( |
|
132 | + 'func' => '_edit_price_type_details', |
|
133 | + 'capability' => 'ee_edit_default_price_types', |
|
134 | + ), |
|
135 | + 'edit_price_type' => array( |
|
136 | + 'func' => '_edit_price_type_details', |
|
137 | + 'capability' => 'ee_edit_default_price_type', |
|
138 | + 'obj_id' => $prt_id, |
|
139 | + ), |
|
140 | + 'insert_price_type' => array( |
|
141 | + 'func' => '_insert_or_update_price_type', |
|
142 | + 'args' => array('new_price_type' => true), |
|
143 | + 'noheader' => true, |
|
144 | + 'capability' => 'ee_edit_default_price_types', |
|
145 | + ), |
|
146 | + 'update_price_type' => array( |
|
147 | + 'func' => '_insert_or_update_price_type', |
|
148 | + 'args' => array('new_price_type' => false), |
|
149 | + 'noheader' => true, |
|
150 | + 'capability' => 'ee_edit_default_price_type', |
|
151 | + 'obj_id' => $prt_id, |
|
152 | + ), |
|
153 | + 'trash_price_type' => array( |
|
154 | + 'func' => '_trash_or_restore_price_type', |
|
155 | + 'args' => array('trash' => true), |
|
156 | + 'noheader' => true, |
|
157 | + 'capability' => 'ee_delete_default_price_type', |
|
158 | + 'obj_id' => $prt_id, |
|
159 | + ), |
|
160 | + 'restore_price_type' => array( |
|
161 | + 'func' => '_trash_or_restore_price_type', |
|
162 | + 'args' => array('trash' => false), |
|
163 | + 'noheader' => true, |
|
164 | + 'capability' => 'ee_delete_default_price_type', |
|
165 | + 'obj_id' => $prt_id, |
|
166 | + ), |
|
167 | + 'delete_price_type' => array( |
|
168 | + 'func' => '_delete_price_type', |
|
169 | + 'noheader' => true, |
|
170 | + 'capability' => 'ee_delete_default_price_type', |
|
171 | + 'obj_id' => $prt_id, |
|
172 | + ), |
|
173 | + 'tax_settings' => array( |
|
174 | + 'func' => '_tax_settings', |
|
175 | + 'capability' => 'manage_options', |
|
176 | + ), |
|
177 | + 'update_tax_settings' => array( |
|
178 | + 'func' => '_update_tax_settings', |
|
179 | + 'capability' => 'manage_options', |
|
180 | + 'noheader' => true, |
|
181 | + ), |
|
182 | + ); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + protected function _set_page_config() |
|
187 | + { |
|
188 | + |
|
189 | + $this->_page_config = array( |
|
190 | + 'default' => array( |
|
191 | + 'nav' => array( |
|
192 | + 'label' => __('Default Pricing', 'event_espresso'), |
|
193 | + 'order' => 10, |
|
194 | + ), |
|
195 | + 'list_table' => 'Prices_List_Table', |
|
196 | + 'help_tabs' => array( |
|
197 | + 'pricing_default_pricing_help_tab' => array( |
|
198 | + 'title' => __('Default Pricing', 'event_espresso'), |
|
199 | + 'filename' => 'pricing_default_pricing', |
|
200 | + ), |
|
201 | + 'pricing_default_pricing_table_column_headings_help_tab' => array( |
|
202 | + 'title' => __('Default Pricing Table Column Headings', 'event_espresso'), |
|
203 | + 'filename' => 'pricing_default_pricing_table_column_headings', |
|
204 | + ), |
|
205 | + 'pricing_default_pricing_views_bulk_actions_search_help_tab' => array( |
|
206 | + 'title' => __('Default Pricing Views & Bulk Actions & Search', 'event_espresso'), |
|
207 | + 'filename' => 'pricing_default_pricing_views_bulk_actions_search', |
|
208 | + ), |
|
209 | + ), |
|
210 | + 'help_tour' => array('Pricing_Default_Prices_Help_Tour'), |
|
211 | + 'require_nonce' => false, |
|
212 | + ), |
|
213 | + 'add_new_price' => array( |
|
214 | + 'nav' => array( |
|
215 | + 'label' => __('Add New Default Price', 'event_espresso'), |
|
216 | + 'order' => 20, |
|
217 | + 'persistent' => false, |
|
218 | + ), |
|
219 | + 'help_tabs' => array( |
|
220 | + 'add_new_default_price_help_tab' => array( |
|
221 | + 'title' => __('Add New Default Price', 'event_espresso'), |
|
222 | + 'filename' => 'pricing_add_new_default_price', |
|
223 | + ), |
|
224 | + ), |
|
225 | + 'help_tour' => array('Pricing_Add_New_Default_Price_Help_Tour'), |
|
226 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
227 | + 'require_nonce' => false, |
|
228 | + ), |
|
229 | + 'edit_price' => array( |
|
230 | + 'nav' => array( |
|
231 | + 'label' => __('Edit Default Price', 'event_espresso'), |
|
232 | + 'order' => 20, |
|
233 | + 'url' => isset($this->_req_data['id']) ? add_query_arg( |
|
234 | + array('id' => $this->_req_data['id']), |
|
235 | + $this->_current_page_view_url |
|
236 | + ) : $this->_admin_base_url, |
|
237 | + 'persistent' => false, |
|
238 | + ), |
|
239 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
240 | + 'help_tabs' => array( |
|
241 | + 'edit_default_price_help_tab' => array( |
|
242 | + 'title' => __('Edit Default Price', 'event_espresso'), |
|
243 | + 'filename' => 'pricing_edit_default_price', |
|
244 | + ), |
|
245 | + ), |
|
246 | + 'help_tour' => array('Pricing_Edit_Default_Price_Help_Tour'), |
|
247 | + 'require_nonce' => false, |
|
248 | + ), |
|
249 | + 'price_types' => array( |
|
250 | + 'nav' => array( |
|
251 | + 'label' => __('Price Types', 'event_espresso'), |
|
252 | + 'order' => 30, |
|
253 | + ), |
|
254 | + 'list_table' => 'Price_Types_List_Table', |
|
255 | + 'help_tabs' => array( |
|
256 | + 'pricing_price_types_help_tab' => array( |
|
257 | + 'title' => __('Price Types', 'event_espresso'), |
|
258 | + 'filename' => 'pricing_price_types', |
|
259 | + ), |
|
260 | + 'pricing_price_types_table_column_headings_help_tab' => array( |
|
261 | + 'title' => __('Price Types Table Column Headings', 'event_espresso'), |
|
262 | + 'filename' => 'pricing_price_types_table_column_headings', |
|
263 | + ), |
|
264 | + 'pricing_price_types_views_bulk_actions_search_help_tab' => array( |
|
265 | + 'title' => __('Price Types Views & Bulk Actions & Search', 'event_espresso'), |
|
266 | + 'filename' => 'pricing_price_types_views_bulk_actions_search', |
|
267 | + ), |
|
268 | + ), |
|
269 | + 'help_tour' => array('Pricing_Price_Types_Default_Help_Tour'), |
|
270 | + 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
271 | + 'require_nonce' => false, |
|
272 | + ), |
|
273 | + 'add_new_price_type' => array( |
|
274 | + 'nav' => array( |
|
275 | + 'label' => __('Add New Price Type', 'event_espresso'), |
|
276 | + 'order' => 40, |
|
277 | + 'persistent' => false, |
|
278 | + ), |
|
279 | + 'help_tabs' => array( |
|
280 | + 'add_new_price_type_help_tab' => array( |
|
281 | + 'title' => __('Add New Price Type', 'event_espresso'), |
|
282 | + 'filename' => 'pricing_add_new_price_type', |
|
283 | + ), |
|
284 | + ), |
|
285 | + 'help_tour' => array('Pricing_Add_New_Price_Type_Help_Tour'), |
|
286 | + 'metaboxes' => array( |
|
287 | + '_publish_post_box', |
|
288 | + '_espresso_news_post_box', |
|
289 | + '_price_type_details_meta_boxes', |
|
290 | + ), |
|
291 | + 'require_nonce' => false, |
|
292 | + ), |
|
293 | + 'edit_price_type' => array( |
|
294 | + 'nav' => array( |
|
295 | + 'label' => __('Edit Price Type', 'event_espresso'), |
|
296 | + 'order' => 40, |
|
297 | + 'persistent' => false, |
|
298 | + ), |
|
299 | + 'help_tabs' => array( |
|
300 | + 'edit_price_type_help_tab' => array( |
|
301 | + 'title' => __('Edit Price Type', 'event_espresso'), |
|
302 | + 'filename' => 'pricing_edit_price_type', |
|
303 | + ), |
|
304 | + ), |
|
305 | + 'help_tour' => array('Pricing_Edit_Price_Type_Help_Tour'), |
|
306 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'), |
|
307 | + |
|
308 | + 'require_nonce' => false, |
|
309 | + ), |
|
310 | + 'tax_settings' => array( |
|
311 | + 'nav' => array( |
|
312 | + 'label' => esc_html__('Tax Settings', 'event_espresso'), |
|
313 | + 'order' => 40, |
|
314 | + ), |
|
315 | + 'labels' => array( |
|
316 | + 'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'), |
|
317 | + ), |
|
318 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
319 | + // 'help_tabs' => array( |
|
320 | + // 'registration_form_reg_form_settings_help_tab' => array( |
|
321 | + // 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
322 | + // 'filename' => 'registration_form_reg_form_settings' |
|
323 | + // ), |
|
324 | + // ), |
|
325 | + // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
326 | + 'require_nonce' => true, |
|
327 | + ), |
|
328 | + ); |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + protected function _add_screen_options() |
|
333 | + { |
|
334 | + // todo |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + protected function _add_screen_options_default() |
|
339 | + { |
|
340 | + $this->_per_page_screen_option(); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + protected function _add_screen_options_price_types() |
|
345 | + { |
|
346 | + $page_title = $this->_admin_page_title; |
|
347 | + $this->_admin_page_title = __('Price Types', 'event_espresso'); |
|
348 | + $this->_per_page_screen_option(); |
|
349 | + $this->_admin_page_title = $page_title; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + protected function _add_feature_pointers() |
|
354 | + { |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + public function load_scripts_styles() |
|
359 | + { |
|
360 | + // styles |
|
361 | + wp_enqueue_style('espresso-ui-theme'); |
|
362 | + wp_register_style( |
|
363 | + 'espresso_PRICING', |
|
364 | + PRICING_ASSETS_URL . 'espresso_pricing_admin.css', |
|
365 | + array(), |
|
366 | + EVENT_ESPRESSO_VERSION |
|
367 | + ); |
|
368 | + wp_enqueue_style('espresso_PRICING'); |
|
369 | + |
|
370 | + // scripts |
|
371 | + wp_enqueue_script('ee_admin_js'); |
|
372 | + wp_enqueue_script('jquery-ui-position'); |
|
373 | + wp_enqueue_script('jquery-ui-widget'); |
|
374 | + // wp_enqueue_script('jquery-ui-dialog'); |
|
375 | + // wp_enqueue_script('jquery-ui-draggable'); |
|
376 | + // wp_enqueue_script('jquery-ui-datepicker'); |
|
377 | + wp_register_script( |
|
378 | + 'espresso_PRICING', |
|
379 | + PRICING_ASSETS_URL . 'espresso_pricing_admin.js', |
|
380 | + array('jquery'), |
|
381 | + EVENT_ESPRESSO_VERSION, |
|
382 | + true |
|
383 | + ); |
|
384 | + wp_enqueue_script('espresso_PRICING'); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + public function load_scripts_styles_default() |
|
389 | + { |
|
390 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + public function admin_footer_scripts() |
|
395 | + { |
|
396 | + } |
|
397 | + |
|
398 | + public function admin_init() |
|
399 | + { |
|
400 | + } |
|
401 | + |
|
402 | + public function admin_notices() |
|
403 | + { |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + protected function _set_list_table_views_default() |
|
408 | + { |
|
409 | + $this->_views = array( |
|
410 | + 'all' => array( |
|
411 | + 'slug' => 'all', |
|
412 | + 'label' => __('View All Default Pricing', 'event_espresso'), |
|
413 | + 'count' => 0, |
|
414 | + 'bulk_action' => array( |
|
415 | + 'trash_price' => __('Move to Trash', 'event_espresso'), |
|
416 | + ), |
|
417 | + ), |
|
418 | + ); |
|
419 | + |
|
420 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
421 | + $this->_views['trashed'] = array( |
|
422 | + 'slug' => 'trashed', |
|
423 | + 'label' => __('Trash', 'event_espresso'), |
|
424 | + 'count' => 0, |
|
425 | + 'bulk_action' => array( |
|
426 | + 'restore_price' => __('Restore from Trash', 'event_espresso'), |
|
427 | + 'delete_price' => __('Delete Permanently', 'event_espresso'), |
|
428 | + ), |
|
429 | + ); |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + protected function _set_list_table_views_price_types() |
|
435 | + { |
|
436 | + $this->_views = array( |
|
437 | + 'all' => array( |
|
438 | + 'slug' => 'all', |
|
439 | + 'label' => __('All', 'event_espresso'), |
|
440 | + 'count' => 0, |
|
441 | + 'bulk_action' => array( |
|
442 | + 'trash_price_type' => __('Move to Trash', 'event_espresso'), |
|
443 | + ), |
|
444 | + ), |
|
445 | + ); |
|
446 | + |
|
447 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
448 | + 'ee_delete_default_price_types', |
|
449 | + 'pricing_trash_price_type' |
|
450 | + )) { |
|
451 | + $this->_views['trashed'] = array( |
|
452 | + 'slug' => 'trashed', |
|
453 | + 'label' => __('Trash', 'event_espresso'), |
|
454 | + 'count' => 0, |
|
455 | + 'bulk_action' => array( |
|
456 | + 'restore_price_type' => __('Restore from Trash', 'event_espresso'), |
|
457 | + 'delete_price_type' => __('Delete Permanently', 'event_espresso'), |
|
458 | + ), |
|
459 | + ); |
|
460 | + } |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * generates HTML for main Prices Admin page |
|
466 | + * |
|
467 | + * @access protected |
|
468 | + * @return void |
|
469 | + */ |
|
470 | + protected function _price_overview_list_table() |
|
471 | + { |
|
472 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
473 | + 'add_new_price', |
|
474 | + 'add', |
|
475 | + array(), |
|
476 | + 'add-new-h2' |
|
477 | + ); |
|
478 | + $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
479 | + $this->_search_btn_label = __('Default Prices', 'event_espresso'); |
|
480 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
481 | + } |
|
482 | + |
|
483 | + |
|
484 | + /** |
|
485 | + * retrieve data for Prices List table |
|
486 | + * |
|
487 | + * @access public |
|
488 | + * @param int $per_page how many prices displayed per page |
|
489 | + * @param boolean $count return the count or objects |
|
490 | + * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
491 | + * @return mixed (int|array) int = count || array of price objects |
|
492 | + */ |
|
493 | + public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false) |
|
494 | + { |
|
495 | + |
|
496 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
497 | + // start with an empty array |
|
498 | + $event_pricing = array(); |
|
499 | + |
|
500 | + require_once(PRICING_ADMIN . 'Prices_List_Table.class.php'); |
|
501 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
502 | + // $PRC = EEM_Price::instance(); |
|
503 | + |
|
504 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
505 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
506 | + : 'ASC'; |
|
507 | + |
|
508 | + switch ($this->_req_data['orderby']) { |
|
509 | + case 'name': |
|
510 | + $orderby = array('PRC_name' => $order); |
|
511 | + break; |
|
512 | + case 'type': |
|
513 | + $orderby = array('Price_Type.PRT_name' => $order); |
|
514 | + break; |
|
515 | + case 'amount': |
|
516 | + $orderby = array('PRC_amount' => $order); |
|
517 | + break; |
|
518 | + default: |
|
519 | + $orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order); |
|
520 | + } |
|
521 | + |
|
522 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
523 | + ? $this->_req_data['paged'] : 1; |
|
524 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
525 | + ? $this->_req_data['perpage'] : $per_page; |
|
526 | + |
|
527 | + $_where = array( |
|
528 | + 'PRC_is_default' => 1, |
|
529 | + 'PRC_deleted' => $trashed, |
|
530 | + ); |
|
531 | + |
|
532 | + $offset = ($current_page - 1) * $per_page; |
|
533 | + $limit = array($offset, $per_page); |
|
534 | + |
|
535 | + if (isset($this->_req_data['s'])) { |
|
536 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
537 | + $_where['OR'] = array( |
|
538 | + 'PRC_name' => array('LIKE', $sstr), |
|
539 | + 'PRC_desc' => array('LIKE', $sstr), |
|
540 | + 'PRC_amount' => array('LIKE', $sstr), |
|
541 | + 'Price_Type.PRT_name' => array('LIKE', $sstr), |
|
542 | + ); |
|
543 | + } |
|
544 | + |
|
545 | + $query_params = array( |
|
546 | + $_where, |
|
547 | + 'order_by' => $orderby, |
|
548 | + 'limit' => $limit, |
|
549 | + 'group_by' => 'PRC_ID', |
|
550 | + ); |
|
551 | + |
|
552 | + if ($count) { |
|
553 | + return $trashed ? EEM_Price::instance()->count(array($_where)) |
|
554 | + : EEM_Price::instance()->count_deleted_and_undeleted(array($_where)); |
|
555 | + } else { |
|
556 | + return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params); |
|
557 | + } |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * _price_details |
|
563 | + * |
|
564 | + * @access protected |
|
565 | + * @return void |
|
566 | + */ |
|
567 | + protected function _edit_price_details() |
|
568 | + { |
|
569 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
570 | + // grab price ID |
|
571 | + $PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
572 | + : false; |
|
573 | + // change page title based on request action |
|
574 | + switch ($this->_req_action) { |
|
575 | + case 'add_new_price': |
|
576 | + $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso'); |
|
577 | + break; |
|
578 | + case 'edit_price': |
|
579 | + $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso'); |
|
580 | + break; |
|
581 | + default: |
|
582 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
583 | + } |
|
584 | + // add PRC_ID to title if editing |
|
585 | + $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title; |
|
586 | + |
|
587 | + // get prices |
|
588 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
589 | + $PRC = EEM_Price::instance(); |
|
590 | + |
|
591 | + if ($PRC_ID) { |
|
592 | + $price = $PRC->get_one_by_ID($PRC_ID); |
|
593 | + $additional_hidden_fields = array( |
|
594 | + 'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID), |
|
595 | + ); |
|
596 | + $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields); |
|
597 | + } else { |
|
598 | + $price = $PRC->get_new_price(); |
|
599 | + $this->_set_add_edit_form_tags('insert_price'); |
|
600 | + } |
|
601 | + |
|
602 | + $this->_template_args['PRC_ID'] = $PRC_ID; |
|
603 | + $this->_template_args['price'] = $price; |
|
604 | + |
|
605 | + // get price types |
|
606 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
607 | + $PRT = EEM_Price_Type::instance(); |
|
608 | + $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1)))); |
|
609 | + $price_type_names = array(); |
|
610 | + if (empty($price_types)) { |
|
611 | + $msg = __( |
|
612 | + 'You have no price types defined. Please add a price type before adding a price.', |
|
613 | + 'event_espresso' |
|
614 | + ); |
|
615 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
616 | + exit(); |
|
617 | + } else { |
|
618 | + foreach ($price_types as $type) { |
|
619 | + // if ($type->is_global()) { |
|
620 | + $price_type_names[] = array('id' => $type->ID(), 'text' => $type->name()); |
|
621 | + // } |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + $this->_template_args['price_types'] = $price_type_names; |
|
626 | + $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
627 | + |
|
628 | + $this->_set_publish_post_box_vars('id', $PRC_ID); |
|
629 | + // the details template wrapper |
|
630 | + $this->display_admin_page_with_sidebar(); |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + /** |
|
635 | + * declare price details page metaboxes |
|
636 | + * |
|
637 | + * @access protected |
|
638 | + * @return void |
|
639 | + */ |
|
640 | + protected function _price_details_meta_boxes() |
|
641 | + { |
|
642 | + add_meta_box( |
|
643 | + 'edit-price-details-mbox', |
|
644 | + __('Default Price Details', 'event_espresso'), |
|
645 | + array($this, '_edit_price_details_meta_box'), |
|
646 | + $this->wp_page_slug, |
|
647 | + 'normal', |
|
648 | + 'high' |
|
649 | + ); |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * _edit_price_details_meta_box |
|
655 | + * |
|
656 | + * @access public |
|
657 | + * @return void |
|
658 | + */ |
|
659 | + public function _edit_price_details_meta_box() |
|
660 | + { |
|
661 | + echo EEH_Template::display_template( |
|
662 | + PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', |
|
663 | + $this->_template_args, |
|
664 | + true |
|
665 | + ); |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * set_price_column_values |
|
671 | + * |
|
672 | + * @access protected |
|
673 | + * @return array |
|
674 | + */ |
|
675 | + protected function set_price_column_values() |
|
676 | + { |
|
677 | + |
|
678 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
679 | + |
|
680 | + $set_column_values = array( |
|
681 | + 'PRT_ID' => absint($this->_req_data['PRT_ID']), |
|
682 | + 'PRC_amount' => $this->_req_data['PRC_amount'], |
|
683 | + 'PRC_name' => $this->_req_data['PRC_name'], |
|
684 | + 'PRC_desc' => $this->_req_data['PRC_desc'], |
|
685 | + 'PRC_is_default' => 1, |
|
686 | + 'PRC_overrides' => null, |
|
687 | + 'PRC_order' => 0, |
|
688 | + 'PRC_deleted' => 0, |
|
689 | + 'PRC_parent' => 0, |
|
690 | + ); |
|
691 | + return $set_column_values; |
|
692 | + } |
|
693 | + |
|
694 | + |
|
695 | + /** |
|
696 | + * insert_or_update_price |
|
697 | + * |
|
698 | + * @param boolean $insert - whether to insert or update |
|
699 | + * @access protected |
|
700 | + * @return void |
|
701 | + */ |
|
702 | + protected function _insert_or_update_price($insert = false) |
|
703 | + { |
|
704 | + |
|
705 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
706 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
707 | + |
|
708 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
709 | + $PRC = EEM_Price::instance(); |
|
710 | + |
|
711 | + // why be so pessimistic ??? : ( |
|
712 | + $success = 0; |
|
713 | + |
|
714 | + $set_column_values = $this->set_price_column_values(); |
|
715 | + // is this a new Price ? |
|
716 | + if ($insert) { |
|
717 | + // run the insert |
|
718 | + if ($PRC_ID = $PRC->insert($set_column_values)) { |
|
719 | + // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type |
|
720 | + $PR = EEM_price::instance()->get_one_by_ID($PRC_ID); |
|
721 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
722 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
723 | + $ticket->_add_relation_to($PR, 'Price'); |
|
724 | + $ticket->save(); |
|
725 | + } |
|
726 | + $success = 1; |
|
727 | + } else { |
|
728 | + $PRC_ID = false; |
|
729 | + $success = 0; |
|
730 | + } |
|
731 | + $action_desc = 'created'; |
|
732 | + } else { |
|
733 | + $PRC_ID = absint($this->_req_data['PRC_ID']); |
|
734 | + // run the update |
|
735 | + $where_cols_n_values = array('PRC_ID' => $PRC_ID); |
|
736 | + if ($PRC->update($set_column_values, array($where_cols_n_values))) { |
|
737 | + $success = 1; |
|
738 | + } |
|
739 | + |
|
740 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
741 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
742 | + // if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated. |
|
743 | + if ($PRC_ID === 1) { |
|
744 | + $ticket = $PR->get_first_related('Ticket'); |
|
745 | + if ($ticket) { |
|
746 | + $ticket->set('TKT_price', $PR->get('PRC_amount')); |
|
747 | + $ticket->set('TKT_name', $PR->get('PRC_name')); |
|
748 | + $ticket->set('TKT_description', $PR->get('PRC_desc')); |
|
749 | + $ticket->save(); |
|
750 | + } |
|
751 | + } else { |
|
752 | + // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type. |
|
753 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
754 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
755 | + $ticket->save(); |
|
756 | + } |
|
757 | + } |
|
758 | + |
|
759 | + $action_desc = 'updated'; |
|
760 | + } |
|
761 | + |
|
762 | + $query_args = array('action' => 'edit_price', 'id' => $PRC_ID); |
|
763 | + |
|
764 | + $this->_redirect_after_action($success, 'Prices', $action_desc, $query_args); |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * _trash_or_restore_price |
|
770 | + * |
|
771 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
772 | + * @access protected |
|
773 | + * @return void |
|
774 | + */ |
|
775 | + protected function _trash_or_restore_price($trash = true) |
|
776 | + { |
|
777 | + |
|
778 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
779 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
780 | + |
|
781 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
782 | + $PRC = EEM_Price::instance(); |
|
783 | + |
|
784 | + $success = 1; |
|
785 | + $PRC_deleted = $trash ? true : false; |
|
786 | + |
|
787 | + // get base ticket for updating |
|
788 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
789 | + // Checkboxes |
|
790 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
791 | + // if array has more than one element than success message should be plural |
|
792 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
793 | + // cycle thru checkboxes |
|
794 | + while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
795 | + if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
796 | + $success = 0; |
|
797 | + } else { |
|
798 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
799 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
800 | + // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
801 | + if ($PRC_deleted) { |
|
802 | + $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
803 | + } else { |
|
804 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
805 | + } |
|
806 | + $ticket->save(); |
|
807 | + } |
|
808 | + } |
|
809 | + } |
|
810 | + } else { |
|
811 | + // grab single id and delete |
|
812 | + $PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
813 | + if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) { |
|
814 | + $success = 0; |
|
815 | + } else { |
|
816 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
817 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
818 | + // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
819 | + if ($PRC_deleted) { |
|
820 | + $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
821 | + } else { |
|
822 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
823 | + } |
|
824 | + $ticket->save(); |
|
825 | + } |
|
826 | + } |
|
827 | + } |
|
828 | + $query_args = array( |
|
829 | + 'action' => 'default', |
|
830 | + ); |
|
831 | + |
|
832 | + if ($success) { |
|
833 | + if ($trash) { |
|
834 | + $msg = $success == 2 |
|
835 | + ? __('The Prices have been trashed.', 'event_espresso') |
|
836 | + : __( |
|
837 | + 'The Price has been trashed.', |
|
838 | + 'event_espresso' |
|
839 | + ); |
|
840 | + } else { |
|
841 | + $msg = $success == 2 |
|
842 | + ? __('The Prices have been restored.', 'event_espresso') |
|
843 | + : __( |
|
844 | + 'The Price has been restored.', |
|
845 | + 'event_espresso' |
|
846 | + ); |
|
847 | + } |
|
848 | + |
|
849 | + EE_Error::add_success($msg); |
|
850 | + } |
|
851 | + |
|
852 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
853 | + } |
|
854 | + |
|
855 | + |
|
856 | + /** |
|
857 | + * _delete_price |
|
858 | + * |
|
859 | + * @access protected |
|
860 | + * @return void |
|
861 | + */ |
|
862 | + protected function _delete_price() |
|
863 | + { |
|
864 | + |
|
865 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
866 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
867 | + |
|
868 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
869 | + $PRC = EEM_Price::instance(); |
|
870 | + |
|
871 | + $success = 1; |
|
872 | + // Checkboxes |
|
873 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
874 | + // if array has more than one element than success message should be plural |
|
875 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
876 | + // cycle thru bulk action checkboxes |
|
877 | + while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
878 | + if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
879 | + $success = 0; |
|
880 | + } |
|
881 | + } |
|
882 | + } else { |
|
883 | + // grab single id and delete |
|
884 | + $PRC_ID = absint($this->_req_data['id']); |
|
885 | + if (! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
886 | + $success = 0; |
|
887 | + } |
|
888 | + } |
|
889 | + |
|
890 | + $this->_redirect_after_action($success, 'Prices', 'deleted', array()); |
|
891 | + } |
|
892 | + |
|
893 | + |
|
894 | + public function update_price_order() |
|
895 | + { |
|
896 | + $success = __('Price order was updated successfully.', 'event_espresso'); |
|
897 | + |
|
898 | + // grab our row IDs |
|
899 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode( |
|
900 | + ',', |
|
901 | + rtrim( |
|
902 | + $this->_req_data['row_ids'], |
|
903 | + ',' |
|
904 | + ) |
|
905 | + ) : false; |
|
906 | + |
|
907 | + if (is_array($row_ids)) { |
|
908 | + for ($i = 0; $i < count($row_ids); $i++) { |
|
909 | + // Update the prices when re-ordering |
|
910 | + $id = absint($row_ids[ $i ]); |
|
911 | + if (EEM_Price::instance()->update( |
|
912 | + array('PRC_order' => $i + 1), |
|
913 | + array(array('PRC_ID' => $id)) |
|
914 | + ) === false) { |
|
915 | + $success = false; |
|
916 | + } |
|
917 | + } |
|
918 | + } else { |
|
919 | + $success = false; |
|
920 | + } |
|
921 | + |
|
922 | + $errors = ! $success ? __('An error occurred. The price order was not updated.', 'event_espresso') : false; |
|
923 | + |
|
924 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
925 | + die(); |
|
926 | + } |
|
927 | + |
|
928 | + |
|
929 | + |
|
930 | + |
|
931 | + |
|
932 | + |
|
933 | + /************************************************************************************************************************************************************** |
|
934 | 934 | ******************************************************************** TICKET PRICE TYPES ****************************************************************** |
935 | 935 | **************************************************************************************************************************************************************/ |
936 | 936 | |
937 | 937 | |
938 | - /** |
|
939 | - * generates HTML for main Prices Admin page |
|
940 | - * |
|
941 | - * @access protected |
|
942 | - * @return void |
|
943 | - */ |
|
944 | - protected function _price_types_overview_list_table() |
|
945 | - { |
|
946 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
947 | - 'add_new_price_type', |
|
948 | - 'add_type', |
|
949 | - array(), |
|
950 | - 'add-new-h2' |
|
951 | - ); |
|
952 | - $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
953 | - $this->_search_btn_label = __('Price Types', 'event_espresso'); |
|
954 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
955 | - } |
|
956 | - |
|
957 | - |
|
958 | - /** |
|
959 | - * retrieve data for Price Types List table |
|
960 | - * |
|
961 | - * @access public |
|
962 | - * @param int $per_page how many prices displayed per page |
|
963 | - * @param boolean $count return the count or objects |
|
964 | - * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
965 | - * @return mixed (int|array) int = count || array of price objects |
|
966 | - */ |
|
967 | - public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false) |
|
968 | - { |
|
969 | - |
|
970 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
971 | - // start with an empty array |
|
972 | - |
|
973 | - require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php'); |
|
974 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
975 | - |
|
976 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
977 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
978 | - : 'ASC'; |
|
979 | - switch ($this->_req_data['orderby']) { |
|
980 | - case 'name': |
|
981 | - $orderby = array('PRT_name' => $order); |
|
982 | - break; |
|
983 | - default: |
|
984 | - $orderby = array('PRT_order' => $order); |
|
985 | - } |
|
986 | - |
|
987 | - |
|
988 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
989 | - ? $this->_req_data['paged'] : 1; |
|
990 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
991 | - ? $this->_req_data['perpage'] : $per_page; |
|
992 | - |
|
993 | - $offset = ($current_page - 1) * $per_page; |
|
994 | - $limit = array($offset, $per_page); |
|
995 | - |
|
996 | - $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1)); |
|
997 | - |
|
998 | - if (isset($this->_req_data['s'])) { |
|
999 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1000 | - $_where['OR'] = array( |
|
1001 | - 'PRT_name' => array('LIKE', $sstr), |
|
1002 | - ); |
|
1003 | - } |
|
1004 | - $query_params = array( |
|
1005 | - $_where, |
|
1006 | - 'order_by' => $orderby, |
|
1007 | - 'limit' => $limit, |
|
1008 | - ); |
|
1009 | - if ($count) { |
|
1010 | - return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params); |
|
1011 | - } else { |
|
1012 | - return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params); |
|
1013 | - } |
|
1014 | - |
|
1015 | - // EEH_Debug_Tools::printr( $price_types, '$price_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
1016 | - } |
|
1017 | - |
|
1018 | - |
|
1019 | - /** |
|
1020 | - * _edit_price_type_details |
|
1021 | - * |
|
1022 | - * @access protected |
|
1023 | - * @return void |
|
1024 | - */ |
|
1025 | - protected function _edit_price_type_details() |
|
1026 | - { |
|
1027 | - |
|
1028 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1029 | - |
|
1030 | - |
|
1031 | - // grab price type ID |
|
1032 | - $PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
1033 | - : false; |
|
1034 | - // change page title based on request action |
|
1035 | - switch ($this->_req_action) { |
|
1036 | - case 'add_new_price_type': |
|
1037 | - $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso'); |
|
1038 | - break; |
|
1039 | - case 'edit_price_type': |
|
1040 | - $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso'); |
|
1041 | - break; |
|
1042 | - default: |
|
1043 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
1044 | - } |
|
1045 | - // add PRT_ID to title if editing |
|
1046 | - $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title; |
|
1047 | - |
|
1048 | - if ($PRT_ID) { |
|
1049 | - $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID); |
|
1050 | - $additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID)); |
|
1051 | - $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields); |
|
1052 | - } else { |
|
1053 | - $price_type = EEM_Price_Type::instance()->get_new_price_type(); |
|
1054 | - $this->_set_add_edit_form_tags('insert_price_type'); |
|
1055 | - } |
|
1056 | - |
|
1057 | - $this->_template_args['PRT_ID'] = $PRT_ID; |
|
1058 | - $this->_template_args['price_type'] = $price_type; |
|
1059 | - |
|
1060 | - |
|
1061 | - $base_types = EEM_Price_Type::instance()->get_base_types(); |
|
1062 | - $select_values = array(); |
|
1063 | - foreach ($base_types as $ref => $text) { |
|
1064 | - if ($ref == EEM_Price_Type::base_type_base_price) { |
|
1065 | - // do not allow creation of base_type_base_prices because that's a system only base type. |
|
1066 | - continue; |
|
1067 | - } |
|
1068 | - $values[] = array('id' => $ref, 'text' => $text); |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input( |
|
1073 | - 'base_type', |
|
1074 | - $values, |
|
1075 | - $price_type->base_type(), |
|
1076 | - 'id="price-type-base-type-slct"' |
|
1077 | - ); |
|
1078 | - $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
1079 | - $redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url); |
|
1080 | - $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL); |
|
1081 | - // the details template wrapper |
|
1082 | - $this->display_admin_page_with_sidebar(); |
|
1083 | - } |
|
1084 | - |
|
1085 | - |
|
1086 | - /** |
|
1087 | - * declare price type details page metaboxes |
|
1088 | - * |
|
1089 | - * @access protected |
|
1090 | - * @return void |
|
1091 | - */ |
|
1092 | - protected function _price_type_details_meta_boxes() |
|
1093 | - { |
|
1094 | - add_meta_box( |
|
1095 | - 'edit-price-details-mbox', |
|
1096 | - __('Price Type Details', 'event_espresso'), |
|
1097 | - array($this, '_edit_price_type_details_meta_box'), |
|
1098 | - $this->wp_page_slug, |
|
1099 | - 'normal', |
|
1100 | - 'high' |
|
1101 | - ); |
|
1102 | - } |
|
1103 | - |
|
1104 | - |
|
1105 | - /** |
|
1106 | - * _edit_price_type_details_meta_box |
|
1107 | - * |
|
1108 | - * @access public |
|
1109 | - * @return void |
|
1110 | - */ |
|
1111 | - public function _edit_price_type_details_meta_box() |
|
1112 | - { |
|
1113 | - echo EEH_Template::display_template( |
|
1114 | - PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', |
|
1115 | - $this->_template_args, |
|
1116 | - true |
|
1117 | - ); |
|
1118 | - } |
|
1119 | - |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * set_price_type_column_values |
|
1123 | - * |
|
1124 | - * @access protected |
|
1125 | - * @return void |
|
1126 | - */ |
|
1127 | - protected function set_price_type_column_values() |
|
1128 | - { |
|
1129 | - |
|
1130 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1131 | - |
|
1132 | - $base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type'] |
|
1133 | - : EEM_Price_Type::base_type_base_price; |
|
1134 | - |
|
1135 | - switch ($base_type) { |
|
1136 | - case EEM_Price_Type::base_type_base_price: |
|
1137 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price; |
|
1138 | - $this->_req_data['PRT_is_percent'] = 0; |
|
1139 | - $this->_req_data['PRT_order'] = 0; |
|
1140 | - break; |
|
1141 | - |
|
1142 | - case EEM_Price_Type::base_type_discount: |
|
1143 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount; |
|
1144 | - break; |
|
1145 | - |
|
1146 | - case EEM_Price_Type::base_type_surcharge: |
|
1147 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge; |
|
1148 | - break; |
|
1149 | - |
|
1150 | - case EEM_Price_Type::base_type_tax: |
|
1151 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax; |
|
1152 | - $this->_req_data['PRT_is_percent'] = 1; |
|
1153 | - break; |
|
1154 | - }/**/ |
|
1155 | - |
|
1156 | - $set_column_values = array( |
|
1157 | - 'PRT_name' => $this->_req_data['PRT_name'], |
|
1158 | - 'PBT_ID' => absint($this->_req_data['PBT_ID']), |
|
1159 | - 'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']), |
|
1160 | - 'PRT_order' => absint($this->_req_data['PRT_order']), |
|
1161 | - 'PRT_deleted' => 0, |
|
1162 | - ); |
|
1163 | - |
|
1164 | - return $set_column_values; |
|
1165 | - } |
|
1166 | - |
|
1167 | - |
|
1168 | - /** |
|
1169 | - * _insert_or_update_price_type |
|
1170 | - * |
|
1171 | - * @param boolean $new_price_type - whether to insert or update |
|
1172 | - * @access protected |
|
1173 | - * @return void |
|
1174 | - */ |
|
1175 | - protected function _insert_or_update_price_type($new_price_type = false) |
|
1176 | - { |
|
1177 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1178 | - |
|
1179 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1180 | - $PRT = EEM_Price_Type::instance(); |
|
1181 | - |
|
1182 | - // why be so pessimistic ??? : ( |
|
1183 | - $success = 0; |
|
1184 | - |
|
1185 | - $set_column_values = $this->set_price_type_column_values(); |
|
1186 | - // is this a new Price ? |
|
1187 | - if ($new_price_type) { |
|
1188 | - // run the insert |
|
1189 | - if ($PRT_ID = $PRT->insert($set_column_values)) { |
|
1190 | - $success = 1; |
|
1191 | - } |
|
1192 | - $action_desc = 'created'; |
|
1193 | - } else { |
|
1194 | - $PRT_ID = absint($this->_req_data['PRT_ID']); |
|
1195 | - // run the update |
|
1196 | - $where_cols_n_values = array('PRT_ID' => $PRT_ID); |
|
1197 | - if ($PRT->update($set_column_values, array($where_cols_n_values))) { |
|
1198 | - $success = 1; |
|
1199 | - } |
|
1200 | - $action_desc = 'updated'; |
|
1201 | - } |
|
1202 | - |
|
1203 | - $query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID); |
|
1204 | - $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args); |
|
1205 | - } |
|
1206 | - |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * _trash_or_restore_price_type |
|
1210 | - * |
|
1211 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
1212 | - * @access protected |
|
1213 | - * @return void |
|
1214 | - */ |
|
1215 | - protected function _trash_or_restore_price_type($trash = true) |
|
1216 | - { |
|
1217 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1218 | - |
|
1219 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1220 | - $PRT = EEM_Price_Type::instance(); |
|
1221 | - |
|
1222 | - $success = 1; |
|
1223 | - $PRT_deleted = $trash ? true : false; |
|
1224 | - // Checkboxes |
|
1225 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1226 | - // if array has more than one element than success message should be plural |
|
1227 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1228 | - $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type'; |
|
1229 | - // cycle thru checkboxes |
|
1230 | - while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1231 | - if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1232 | - $success = 0; |
|
1233 | - } |
|
1234 | - } |
|
1235 | - } else { |
|
1236 | - // grab single id and delete |
|
1237 | - $PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
1238 | - if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1239 | - $success = 0; |
|
1240 | - } |
|
1241 | - $what = 'Price Type'; |
|
1242 | - } |
|
1243 | - |
|
1244 | - $query_args = array('action' => 'price_types'); |
|
1245 | - if ($success) { |
|
1246 | - if ($trash) { |
|
1247 | - $msg = $success > 1 |
|
1248 | - ? __('The Price Types have been trashed.', 'event_espresso') |
|
1249 | - : __( |
|
1250 | - 'The Price Type has been trashed.', |
|
1251 | - 'event_espresso' |
|
1252 | - ); |
|
1253 | - } else { |
|
1254 | - $msg = $success > 1 |
|
1255 | - ? __('The Price Types have been restored.', 'event_espresso') |
|
1256 | - : __( |
|
1257 | - 'The Price Type has been restored.', |
|
1258 | - 'event_espresso' |
|
1259 | - ); |
|
1260 | - } |
|
1261 | - EE_Error::add_success($msg); |
|
1262 | - } |
|
1263 | - |
|
1264 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1265 | - } |
|
1266 | - |
|
1267 | - |
|
1268 | - /** |
|
1269 | - * _delete_price_type |
|
1270 | - * |
|
1271 | - * @access protected |
|
1272 | - * @return void |
|
1273 | - */ |
|
1274 | - protected function _delete_price_type() |
|
1275 | - { |
|
1276 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1277 | - |
|
1278 | - $PRT = EEM_Price_Type::instance(); |
|
1279 | - |
|
1280 | - $success = 1; |
|
1281 | - // Checkboxes |
|
1282 | - if (! empty($this->_req_data['checkbox'])) { |
|
1283 | - // if array has more than one element than success message should be plural |
|
1284 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1285 | - $what = $PRT->item_name($success); |
|
1286 | - // cycle thru bulk action checkboxes |
|
1287 | - while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1288 | - if (! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
1289 | - $success = 0; |
|
1290 | - } |
|
1291 | - } |
|
1292 | - } |
|
1293 | - |
|
1294 | - |
|
1295 | - $query_args = array('action' => 'price_types'); |
|
1296 | - $this->_redirect_after_action($success, $what, 'deleted', $query_args); |
|
1297 | - } |
|
1298 | - |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * _learn_more_about_pricing_link |
|
1302 | - * |
|
1303 | - * @access protected |
|
1304 | - * @return string |
|
1305 | - */ |
|
1306 | - protected function _learn_more_about_pricing_link() |
|
1307 | - { |
|
1308 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __( |
|
1309 | - 'learn more about how pricing works', |
|
1310 | - 'event_espresso' |
|
1311 | - ) . '</a>'; |
|
1312 | - } |
|
1313 | - |
|
1314 | - |
|
1315 | - protected function _tax_settings() |
|
1316 | - { |
|
1317 | - $this->_set_add_edit_form_tags('update_tax_settings'); |
|
1318 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1319 | - $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html(); |
|
1320 | - $this->display_admin_page_with_sidebar(); |
|
1321 | - } |
|
1322 | - |
|
1323 | - |
|
1324 | - /** |
|
1325 | - * @return \EE_Form_Section_Proper |
|
1326 | - * @throws \EE_Error |
|
1327 | - */ |
|
1328 | - protected function tax_settings_form() |
|
1329 | - { |
|
1330 | - return new EE_Form_Section_Proper( |
|
1331 | - array( |
|
1332 | - 'name' => 'tax_settings_form', |
|
1333 | - 'html_id' => 'tax_settings_form', |
|
1334 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1335 | - 'subsections' => apply_filters( |
|
1336 | - 'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections', |
|
1337 | - array( |
|
1338 | - 'tax_settings' => new EE_Form_Section_Proper( |
|
1339 | - array( |
|
1340 | - 'name' => 'tax_settings_tbl', |
|
1341 | - 'html_id' => 'tax_settings_tbl', |
|
1342 | - 'html_class' => 'form-table', |
|
1343 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1344 | - 'subsections' => array( |
|
1345 | - 'prices_displayed_including_taxes' => new EE_Yes_No_Input( |
|
1346 | - array( |
|
1347 | - 'html_label_text' => __( |
|
1348 | - "Show Prices With Taxes Included?", |
|
1349 | - 'event_espresso' |
|
1350 | - ), |
|
1351 | - 'html_help_text' => __( |
|
1352 | - 'Indicates whether or not to display prices with the taxes included', |
|
1353 | - 'event_espresso' |
|
1354 | - ), |
|
1355 | - 'default' => isset( |
|
1356 | - EE_Registry::instance() |
|
1357 | - ->CFG |
|
1358 | - ->tax_settings |
|
1359 | - ->prices_displayed_including_taxes |
|
1360 | - ) |
|
1361 | - ? EE_Registry::instance() |
|
1362 | - ->CFG |
|
1363 | - ->tax_settings |
|
1364 | - ->prices_displayed_including_taxes |
|
1365 | - : true, |
|
1366 | - 'display_html_label_text' => false, |
|
1367 | - ) |
|
1368 | - ), |
|
1369 | - ), |
|
1370 | - ) |
|
1371 | - ), |
|
1372 | - ) |
|
1373 | - ), |
|
1374 | - ) |
|
1375 | - ); |
|
1376 | - } |
|
1377 | - |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * _update_tax_settings |
|
1381 | - * |
|
1382 | - * @since 4.9.13 |
|
1383 | - * @return void |
|
1384 | - */ |
|
1385 | - public function _update_tax_settings() |
|
1386 | - { |
|
1387 | - if (! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
1388 | - EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config(); |
|
1389 | - } |
|
1390 | - try { |
|
1391 | - $tax_form = $this->tax_settings_form(); |
|
1392 | - // check for form submission |
|
1393 | - if ($tax_form->was_submitted()) { |
|
1394 | - // capture form data |
|
1395 | - $tax_form->receive_form_submission(); |
|
1396 | - // validate form data |
|
1397 | - if ($tax_form->is_valid()) { |
|
1398 | - // grab validated data from form |
|
1399 | - $valid_data = $tax_form->valid_data(); |
|
1400 | - // set data on config |
|
1401 | - EE_Registry::instance() |
|
1402 | - ->CFG |
|
1403 | - ->tax_settings |
|
1404 | - ->prices_displayed_including_taxes |
|
1405 | - = $valid_data['tax_settings']['prices_displayed_including_taxes']; |
|
1406 | - } else { |
|
1407 | - if ($tax_form->submission_error_message() !== '') { |
|
1408 | - EE_Error::add_error( |
|
1409 | - $tax_form->submission_error_message(), |
|
1410 | - __FILE__, |
|
1411 | - __FUNCTION__, |
|
1412 | - __LINE__ |
|
1413 | - ); |
|
1414 | - } |
|
1415 | - } |
|
1416 | - } |
|
1417 | - } catch (EE_Error $e) { |
|
1418 | - EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__); |
|
1419 | - } |
|
1420 | - |
|
1421 | - $what = 'Tax Settings'; |
|
1422 | - $success = $this->_update_espresso_configuration( |
|
1423 | - $what, |
|
1424 | - EE_Registry::instance()->CFG->tax_settings, |
|
1425 | - __FILE__, |
|
1426 | - __FUNCTION__, |
|
1427 | - __LINE__ |
|
1428 | - ); |
|
1429 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings')); |
|
1430 | - } |
|
938 | + /** |
|
939 | + * generates HTML for main Prices Admin page |
|
940 | + * |
|
941 | + * @access protected |
|
942 | + * @return void |
|
943 | + */ |
|
944 | + protected function _price_types_overview_list_table() |
|
945 | + { |
|
946 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
947 | + 'add_new_price_type', |
|
948 | + 'add_type', |
|
949 | + array(), |
|
950 | + 'add-new-h2' |
|
951 | + ); |
|
952 | + $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
953 | + $this->_search_btn_label = __('Price Types', 'event_espresso'); |
|
954 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
955 | + } |
|
956 | + |
|
957 | + |
|
958 | + /** |
|
959 | + * retrieve data for Price Types List table |
|
960 | + * |
|
961 | + * @access public |
|
962 | + * @param int $per_page how many prices displayed per page |
|
963 | + * @param boolean $count return the count or objects |
|
964 | + * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
965 | + * @return mixed (int|array) int = count || array of price objects |
|
966 | + */ |
|
967 | + public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false) |
|
968 | + { |
|
969 | + |
|
970 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
971 | + // start with an empty array |
|
972 | + |
|
973 | + require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php'); |
|
974 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
975 | + |
|
976 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
977 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
978 | + : 'ASC'; |
|
979 | + switch ($this->_req_data['orderby']) { |
|
980 | + case 'name': |
|
981 | + $orderby = array('PRT_name' => $order); |
|
982 | + break; |
|
983 | + default: |
|
984 | + $orderby = array('PRT_order' => $order); |
|
985 | + } |
|
986 | + |
|
987 | + |
|
988 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
989 | + ? $this->_req_data['paged'] : 1; |
|
990 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
991 | + ? $this->_req_data['perpage'] : $per_page; |
|
992 | + |
|
993 | + $offset = ($current_page - 1) * $per_page; |
|
994 | + $limit = array($offset, $per_page); |
|
995 | + |
|
996 | + $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1)); |
|
997 | + |
|
998 | + if (isset($this->_req_data['s'])) { |
|
999 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1000 | + $_where['OR'] = array( |
|
1001 | + 'PRT_name' => array('LIKE', $sstr), |
|
1002 | + ); |
|
1003 | + } |
|
1004 | + $query_params = array( |
|
1005 | + $_where, |
|
1006 | + 'order_by' => $orderby, |
|
1007 | + 'limit' => $limit, |
|
1008 | + ); |
|
1009 | + if ($count) { |
|
1010 | + return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params); |
|
1011 | + } else { |
|
1012 | + return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params); |
|
1013 | + } |
|
1014 | + |
|
1015 | + // EEH_Debug_Tools::printr( $price_types, '$price_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
1016 | + } |
|
1017 | + |
|
1018 | + |
|
1019 | + /** |
|
1020 | + * _edit_price_type_details |
|
1021 | + * |
|
1022 | + * @access protected |
|
1023 | + * @return void |
|
1024 | + */ |
|
1025 | + protected function _edit_price_type_details() |
|
1026 | + { |
|
1027 | + |
|
1028 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1029 | + |
|
1030 | + |
|
1031 | + // grab price type ID |
|
1032 | + $PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
1033 | + : false; |
|
1034 | + // change page title based on request action |
|
1035 | + switch ($this->_req_action) { |
|
1036 | + case 'add_new_price_type': |
|
1037 | + $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso'); |
|
1038 | + break; |
|
1039 | + case 'edit_price_type': |
|
1040 | + $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso'); |
|
1041 | + break; |
|
1042 | + default: |
|
1043 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
1044 | + } |
|
1045 | + // add PRT_ID to title if editing |
|
1046 | + $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title; |
|
1047 | + |
|
1048 | + if ($PRT_ID) { |
|
1049 | + $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID); |
|
1050 | + $additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID)); |
|
1051 | + $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields); |
|
1052 | + } else { |
|
1053 | + $price_type = EEM_Price_Type::instance()->get_new_price_type(); |
|
1054 | + $this->_set_add_edit_form_tags('insert_price_type'); |
|
1055 | + } |
|
1056 | + |
|
1057 | + $this->_template_args['PRT_ID'] = $PRT_ID; |
|
1058 | + $this->_template_args['price_type'] = $price_type; |
|
1059 | + |
|
1060 | + |
|
1061 | + $base_types = EEM_Price_Type::instance()->get_base_types(); |
|
1062 | + $select_values = array(); |
|
1063 | + foreach ($base_types as $ref => $text) { |
|
1064 | + if ($ref == EEM_Price_Type::base_type_base_price) { |
|
1065 | + // do not allow creation of base_type_base_prices because that's a system only base type. |
|
1066 | + continue; |
|
1067 | + } |
|
1068 | + $values[] = array('id' => $ref, 'text' => $text); |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input( |
|
1073 | + 'base_type', |
|
1074 | + $values, |
|
1075 | + $price_type->base_type(), |
|
1076 | + 'id="price-type-base-type-slct"' |
|
1077 | + ); |
|
1078 | + $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
1079 | + $redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url); |
|
1080 | + $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL); |
|
1081 | + // the details template wrapper |
|
1082 | + $this->display_admin_page_with_sidebar(); |
|
1083 | + } |
|
1084 | + |
|
1085 | + |
|
1086 | + /** |
|
1087 | + * declare price type details page metaboxes |
|
1088 | + * |
|
1089 | + * @access protected |
|
1090 | + * @return void |
|
1091 | + */ |
|
1092 | + protected function _price_type_details_meta_boxes() |
|
1093 | + { |
|
1094 | + add_meta_box( |
|
1095 | + 'edit-price-details-mbox', |
|
1096 | + __('Price Type Details', 'event_espresso'), |
|
1097 | + array($this, '_edit_price_type_details_meta_box'), |
|
1098 | + $this->wp_page_slug, |
|
1099 | + 'normal', |
|
1100 | + 'high' |
|
1101 | + ); |
|
1102 | + } |
|
1103 | + |
|
1104 | + |
|
1105 | + /** |
|
1106 | + * _edit_price_type_details_meta_box |
|
1107 | + * |
|
1108 | + * @access public |
|
1109 | + * @return void |
|
1110 | + */ |
|
1111 | + public function _edit_price_type_details_meta_box() |
|
1112 | + { |
|
1113 | + echo EEH_Template::display_template( |
|
1114 | + PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', |
|
1115 | + $this->_template_args, |
|
1116 | + true |
|
1117 | + ); |
|
1118 | + } |
|
1119 | + |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * set_price_type_column_values |
|
1123 | + * |
|
1124 | + * @access protected |
|
1125 | + * @return void |
|
1126 | + */ |
|
1127 | + protected function set_price_type_column_values() |
|
1128 | + { |
|
1129 | + |
|
1130 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1131 | + |
|
1132 | + $base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type'] |
|
1133 | + : EEM_Price_Type::base_type_base_price; |
|
1134 | + |
|
1135 | + switch ($base_type) { |
|
1136 | + case EEM_Price_Type::base_type_base_price: |
|
1137 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price; |
|
1138 | + $this->_req_data['PRT_is_percent'] = 0; |
|
1139 | + $this->_req_data['PRT_order'] = 0; |
|
1140 | + break; |
|
1141 | + |
|
1142 | + case EEM_Price_Type::base_type_discount: |
|
1143 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount; |
|
1144 | + break; |
|
1145 | + |
|
1146 | + case EEM_Price_Type::base_type_surcharge: |
|
1147 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge; |
|
1148 | + break; |
|
1149 | + |
|
1150 | + case EEM_Price_Type::base_type_tax: |
|
1151 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax; |
|
1152 | + $this->_req_data['PRT_is_percent'] = 1; |
|
1153 | + break; |
|
1154 | + }/**/ |
|
1155 | + |
|
1156 | + $set_column_values = array( |
|
1157 | + 'PRT_name' => $this->_req_data['PRT_name'], |
|
1158 | + 'PBT_ID' => absint($this->_req_data['PBT_ID']), |
|
1159 | + 'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']), |
|
1160 | + 'PRT_order' => absint($this->_req_data['PRT_order']), |
|
1161 | + 'PRT_deleted' => 0, |
|
1162 | + ); |
|
1163 | + |
|
1164 | + return $set_column_values; |
|
1165 | + } |
|
1166 | + |
|
1167 | + |
|
1168 | + /** |
|
1169 | + * _insert_or_update_price_type |
|
1170 | + * |
|
1171 | + * @param boolean $new_price_type - whether to insert or update |
|
1172 | + * @access protected |
|
1173 | + * @return void |
|
1174 | + */ |
|
1175 | + protected function _insert_or_update_price_type($new_price_type = false) |
|
1176 | + { |
|
1177 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1178 | + |
|
1179 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1180 | + $PRT = EEM_Price_Type::instance(); |
|
1181 | + |
|
1182 | + // why be so pessimistic ??? : ( |
|
1183 | + $success = 0; |
|
1184 | + |
|
1185 | + $set_column_values = $this->set_price_type_column_values(); |
|
1186 | + // is this a new Price ? |
|
1187 | + if ($new_price_type) { |
|
1188 | + // run the insert |
|
1189 | + if ($PRT_ID = $PRT->insert($set_column_values)) { |
|
1190 | + $success = 1; |
|
1191 | + } |
|
1192 | + $action_desc = 'created'; |
|
1193 | + } else { |
|
1194 | + $PRT_ID = absint($this->_req_data['PRT_ID']); |
|
1195 | + // run the update |
|
1196 | + $where_cols_n_values = array('PRT_ID' => $PRT_ID); |
|
1197 | + if ($PRT->update($set_column_values, array($where_cols_n_values))) { |
|
1198 | + $success = 1; |
|
1199 | + } |
|
1200 | + $action_desc = 'updated'; |
|
1201 | + } |
|
1202 | + |
|
1203 | + $query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID); |
|
1204 | + $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args); |
|
1205 | + } |
|
1206 | + |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * _trash_or_restore_price_type |
|
1210 | + * |
|
1211 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
1212 | + * @access protected |
|
1213 | + * @return void |
|
1214 | + */ |
|
1215 | + protected function _trash_or_restore_price_type($trash = true) |
|
1216 | + { |
|
1217 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1218 | + |
|
1219 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1220 | + $PRT = EEM_Price_Type::instance(); |
|
1221 | + |
|
1222 | + $success = 1; |
|
1223 | + $PRT_deleted = $trash ? true : false; |
|
1224 | + // Checkboxes |
|
1225 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1226 | + // if array has more than one element than success message should be plural |
|
1227 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1228 | + $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type'; |
|
1229 | + // cycle thru checkboxes |
|
1230 | + while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1231 | + if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1232 | + $success = 0; |
|
1233 | + } |
|
1234 | + } |
|
1235 | + } else { |
|
1236 | + // grab single id and delete |
|
1237 | + $PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
1238 | + if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1239 | + $success = 0; |
|
1240 | + } |
|
1241 | + $what = 'Price Type'; |
|
1242 | + } |
|
1243 | + |
|
1244 | + $query_args = array('action' => 'price_types'); |
|
1245 | + if ($success) { |
|
1246 | + if ($trash) { |
|
1247 | + $msg = $success > 1 |
|
1248 | + ? __('The Price Types have been trashed.', 'event_espresso') |
|
1249 | + : __( |
|
1250 | + 'The Price Type has been trashed.', |
|
1251 | + 'event_espresso' |
|
1252 | + ); |
|
1253 | + } else { |
|
1254 | + $msg = $success > 1 |
|
1255 | + ? __('The Price Types have been restored.', 'event_espresso') |
|
1256 | + : __( |
|
1257 | + 'The Price Type has been restored.', |
|
1258 | + 'event_espresso' |
|
1259 | + ); |
|
1260 | + } |
|
1261 | + EE_Error::add_success($msg); |
|
1262 | + } |
|
1263 | + |
|
1264 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1265 | + } |
|
1266 | + |
|
1267 | + |
|
1268 | + /** |
|
1269 | + * _delete_price_type |
|
1270 | + * |
|
1271 | + * @access protected |
|
1272 | + * @return void |
|
1273 | + */ |
|
1274 | + protected function _delete_price_type() |
|
1275 | + { |
|
1276 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1277 | + |
|
1278 | + $PRT = EEM_Price_Type::instance(); |
|
1279 | + |
|
1280 | + $success = 1; |
|
1281 | + // Checkboxes |
|
1282 | + if (! empty($this->_req_data['checkbox'])) { |
|
1283 | + // if array has more than one element than success message should be plural |
|
1284 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1285 | + $what = $PRT->item_name($success); |
|
1286 | + // cycle thru bulk action checkboxes |
|
1287 | + while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1288 | + if (! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
1289 | + $success = 0; |
|
1290 | + } |
|
1291 | + } |
|
1292 | + } |
|
1293 | + |
|
1294 | + |
|
1295 | + $query_args = array('action' => 'price_types'); |
|
1296 | + $this->_redirect_after_action($success, $what, 'deleted', $query_args); |
|
1297 | + } |
|
1298 | + |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * _learn_more_about_pricing_link |
|
1302 | + * |
|
1303 | + * @access protected |
|
1304 | + * @return string |
|
1305 | + */ |
|
1306 | + protected function _learn_more_about_pricing_link() |
|
1307 | + { |
|
1308 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __( |
|
1309 | + 'learn more about how pricing works', |
|
1310 | + 'event_espresso' |
|
1311 | + ) . '</a>'; |
|
1312 | + } |
|
1313 | + |
|
1314 | + |
|
1315 | + protected function _tax_settings() |
|
1316 | + { |
|
1317 | + $this->_set_add_edit_form_tags('update_tax_settings'); |
|
1318 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1319 | + $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html(); |
|
1320 | + $this->display_admin_page_with_sidebar(); |
|
1321 | + } |
|
1322 | + |
|
1323 | + |
|
1324 | + /** |
|
1325 | + * @return \EE_Form_Section_Proper |
|
1326 | + * @throws \EE_Error |
|
1327 | + */ |
|
1328 | + protected function tax_settings_form() |
|
1329 | + { |
|
1330 | + return new EE_Form_Section_Proper( |
|
1331 | + array( |
|
1332 | + 'name' => 'tax_settings_form', |
|
1333 | + 'html_id' => 'tax_settings_form', |
|
1334 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
1335 | + 'subsections' => apply_filters( |
|
1336 | + 'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections', |
|
1337 | + array( |
|
1338 | + 'tax_settings' => new EE_Form_Section_Proper( |
|
1339 | + array( |
|
1340 | + 'name' => 'tax_settings_tbl', |
|
1341 | + 'html_id' => 'tax_settings_tbl', |
|
1342 | + 'html_class' => 'form-table', |
|
1343 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
1344 | + 'subsections' => array( |
|
1345 | + 'prices_displayed_including_taxes' => new EE_Yes_No_Input( |
|
1346 | + array( |
|
1347 | + 'html_label_text' => __( |
|
1348 | + "Show Prices With Taxes Included?", |
|
1349 | + 'event_espresso' |
|
1350 | + ), |
|
1351 | + 'html_help_text' => __( |
|
1352 | + 'Indicates whether or not to display prices with the taxes included', |
|
1353 | + 'event_espresso' |
|
1354 | + ), |
|
1355 | + 'default' => isset( |
|
1356 | + EE_Registry::instance() |
|
1357 | + ->CFG |
|
1358 | + ->tax_settings |
|
1359 | + ->prices_displayed_including_taxes |
|
1360 | + ) |
|
1361 | + ? EE_Registry::instance() |
|
1362 | + ->CFG |
|
1363 | + ->tax_settings |
|
1364 | + ->prices_displayed_including_taxes |
|
1365 | + : true, |
|
1366 | + 'display_html_label_text' => false, |
|
1367 | + ) |
|
1368 | + ), |
|
1369 | + ), |
|
1370 | + ) |
|
1371 | + ), |
|
1372 | + ) |
|
1373 | + ), |
|
1374 | + ) |
|
1375 | + ); |
|
1376 | + } |
|
1377 | + |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * _update_tax_settings |
|
1381 | + * |
|
1382 | + * @since 4.9.13 |
|
1383 | + * @return void |
|
1384 | + */ |
|
1385 | + public function _update_tax_settings() |
|
1386 | + { |
|
1387 | + if (! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
1388 | + EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config(); |
|
1389 | + } |
|
1390 | + try { |
|
1391 | + $tax_form = $this->tax_settings_form(); |
|
1392 | + // check for form submission |
|
1393 | + if ($tax_form->was_submitted()) { |
|
1394 | + // capture form data |
|
1395 | + $tax_form->receive_form_submission(); |
|
1396 | + // validate form data |
|
1397 | + if ($tax_form->is_valid()) { |
|
1398 | + // grab validated data from form |
|
1399 | + $valid_data = $tax_form->valid_data(); |
|
1400 | + // set data on config |
|
1401 | + EE_Registry::instance() |
|
1402 | + ->CFG |
|
1403 | + ->tax_settings |
|
1404 | + ->prices_displayed_including_taxes |
|
1405 | + = $valid_data['tax_settings']['prices_displayed_including_taxes']; |
|
1406 | + } else { |
|
1407 | + if ($tax_form->submission_error_message() !== '') { |
|
1408 | + EE_Error::add_error( |
|
1409 | + $tax_form->submission_error_message(), |
|
1410 | + __FILE__, |
|
1411 | + __FUNCTION__, |
|
1412 | + __LINE__ |
|
1413 | + ); |
|
1414 | + } |
|
1415 | + } |
|
1416 | + } |
|
1417 | + } catch (EE_Error $e) { |
|
1418 | + EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__); |
|
1419 | + } |
|
1420 | + |
|
1421 | + $what = 'Tax Settings'; |
|
1422 | + $success = $this->_update_espresso_configuration( |
|
1423 | + $what, |
|
1424 | + EE_Registry::instance()->CFG->tax_settings, |
|
1425 | + __FILE__, |
|
1426 | + __FUNCTION__, |
|
1427 | + __LINE__ |
|
1428 | + ); |
|
1429 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings')); |
|
1430 | + } |
|
1431 | 1431 | } |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | wp_enqueue_style('espresso-ui-theme'); |
362 | 362 | wp_register_style( |
363 | 363 | 'espresso_PRICING', |
364 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.css', |
|
364 | + PRICING_ASSETS_URL.'espresso_pricing_admin.css', |
|
365 | 365 | array(), |
366 | 366 | EVENT_ESPRESSO_VERSION |
367 | 367 | ); |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | // wp_enqueue_script('jquery-ui-datepicker'); |
377 | 377 | wp_register_script( |
378 | 378 | 'espresso_PRICING', |
379 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.js', |
|
379 | + PRICING_ASSETS_URL.'espresso_pricing_admin.js', |
|
380 | 380 | array('jquery'), |
381 | 381 | EVENT_ESPRESSO_VERSION, |
382 | 382 | true |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | */ |
470 | 470 | protected function _price_overview_list_table() |
471 | 471 | { |
472 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
472 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
473 | 473 | 'add_new_price', |
474 | 474 | 'add', |
475 | 475 | array(), |
@@ -497,8 +497,8 @@ discard block |
||
497 | 497 | // start with an empty array |
498 | 498 | $event_pricing = array(); |
499 | 499 | |
500 | - require_once(PRICING_ADMIN . 'Prices_List_Table.class.php'); |
|
501 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
500 | + require_once(PRICING_ADMIN.'Prices_List_Table.class.php'); |
|
501 | + require_once(EE_MODELS.'EEM_Price.model.php'); |
|
502 | 502 | // $PRC = EEM_Price::instance(); |
503 | 503 | |
504 | 504 | $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
@@ -533,7 +533,7 @@ discard block |
||
533 | 533 | $limit = array($offset, $per_page); |
534 | 534 | |
535 | 535 | if (isset($this->_req_data['s'])) { |
536 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
536 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
537 | 537 | $_where['OR'] = array( |
538 | 538 | 'PRC_name' => array('LIKE', $sstr), |
539 | 539 | 'PRC_desc' => array('LIKE', $sstr), |
@@ -582,10 +582,10 @@ discard block |
||
582 | 582 | $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
583 | 583 | } |
584 | 584 | // add PRC_ID to title if editing |
585 | - $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title; |
|
585 | + $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title.' # '.$PRC_ID : $this->_admin_page_title; |
|
586 | 586 | |
587 | 587 | // get prices |
588 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
588 | + require_once(EE_MODELS.'EEM_Price.model.php'); |
|
589 | 589 | $PRC = EEM_Price::instance(); |
590 | 590 | |
591 | 591 | if ($PRC_ID) { |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | $this->_template_args['price'] = $price; |
604 | 604 | |
605 | 605 | // get price types |
606 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
606 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
607 | 607 | $PRT = EEM_Price_Type::instance(); |
608 | 608 | $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1)))); |
609 | 609 | $price_type_names = array(); |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | public function _edit_price_details_meta_box() |
660 | 660 | { |
661 | 661 | echo EEH_Template::display_template( |
662 | - PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', |
|
662 | + PRICING_TEMPLATE_PATH.'pricing_details_main_meta_box.template.php', |
|
663 | 663 | $this->_template_args, |
664 | 664 | true |
665 | 665 | ); |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
706 | 706 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
707 | 707 | |
708 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
708 | + require_once(EE_MODELS.'EEM_Price.model.php'); |
|
709 | 709 | $PRC = EEM_Price::instance(); |
710 | 710 | |
711 | 711 | // why be so pessimistic ??? : ( |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
779 | 779 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
780 | 780 | |
781 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
781 | + require_once(EE_MODELS.'EEM_Price.model.php'); |
|
782 | 782 | $PRC = EEM_Price::instance(); |
783 | 783 | |
784 | 784 | $success = 1; |
@@ -787,12 +787,12 @@ discard block |
||
787 | 787 | // get base ticket for updating |
788 | 788 | $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
789 | 789 | // Checkboxes |
790 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
790 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
791 | 791 | // if array has more than one element than success message should be plural |
792 | 792 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
793 | 793 | // cycle thru checkboxes |
794 | 794 | while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
795 | - if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
795 | + if ( ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
796 | 796 | $success = 0; |
797 | 797 | } else { |
798 | 798 | $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
@@ -865,24 +865,24 @@ discard block |
||
865 | 865 | // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
866 | 866 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
867 | 867 | |
868 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
868 | + require_once(EE_MODELS.'EEM_Price.model.php'); |
|
869 | 869 | $PRC = EEM_Price::instance(); |
870 | 870 | |
871 | 871 | $success = 1; |
872 | 872 | // Checkboxes |
873 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
873 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
874 | 874 | // if array has more than one element than success message should be plural |
875 | 875 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
876 | 876 | // cycle thru bulk action checkboxes |
877 | 877 | while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
878 | - if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
878 | + if ( ! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
879 | 879 | $success = 0; |
880 | 880 | } |
881 | 881 | } |
882 | 882 | } else { |
883 | 883 | // grab single id and delete |
884 | 884 | $PRC_ID = absint($this->_req_data['id']); |
885 | - if (! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
885 | + if ( ! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
886 | 886 | $success = 0; |
887 | 887 | } |
888 | 888 | } |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | if (is_array($row_ids)) { |
908 | 908 | for ($i = 0; $i < count($row_ids); $i++) { |
909 | 909 | // Update the prices when re-ordering |
910 | - $id = absint($row_ids[ $i ]); |
|
910 | + $id = absint($row_ids[$i]); |
|
911 | 911 | if (EEM_Price::instance()->update( |
912 | 912 | array('PRC_order' => $i + 1), |
913 | 913 | array(array('PRC_ID' => $id)) |
@@ -943,7 +943,7 @@ discard block |
||
943 | 943 | */ |
944 | 944 | protected function _price_types_overview_list_table() |
945 | 945 | { |
946 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
946 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
947 | 947 | 'add_new_price_type', |
948 | 948 | 'add_type', |
949 | 949 | array(), |
@@ -970,8 +970,8 @@ discard block |
||
970 | 970 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
971 | 971 | // start with an empty array |
972 | 972 | |
973 | - require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php'); |
|
974 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
973 | + require_once(PRICING_ADMIN.'Price_Types_List_Table.class.php'); |
|
974 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
975 | 975 | |
976 | 976 | $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
977 | 977 | $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
@@ -996,7 +996,7 @@ discard block |
||
996 | 996 | $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1)); |
997 | 997 | |
998 | 998 | if (isset($this->_req_data['s'])) { |
999 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
999 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
1000 | 1000 | $_where['OR'] = array( |
1001 | 1001 | 'PRT_name' => array('LIKE', $sstr), |
1002 | 1002 | ); |
@@ -1043,7 +1043,7 @@ discard block |
||
1043 | 1043 | $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
1044 | 1044 | } |
1045 | 1045 | // add PRT_ID to title if editing |
1046 | - $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title; |
|
1046 | + $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title.' # '.$PRT_ID : $this->_admin_page_title; |
|
1047 | 1047 | |
1048 | 1048 | if ($PRT_ID) { |
1049 | 1049 | $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID); |
@@ -1111,7 +1111,7 @@ discard block |
||
1111 | 1111 | public function _edit_price_type_details_meta_box() |
1112 | 1112 | { |
1113 | 1113 | echo EEH_Template::display_template( |
1114 | - PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', |
|
1114 | + PRICING_TEMPLATE_PATH.'pricing_type_details_main_meta_box.template.php', |
|
1115 | 1115 | $this->_template_args, |
1116 | 1116 | true |
1117 | 1117 | ); |
@@ -1176,7 +1176,7 @@ discard block |
||
1176 | 1176 | { |
1177 | 1177 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
1178 | 1178 | |
1179 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1179 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
1180 | 1180 | $PRT = EEM_Price_Type::instance(); |
1181 | 1181 | |
1182 | 1182 | // why be so pessimistic ??? : ( |
@@ -1216,19 +1216,19 @@ discard block |
||
1216 | 1216 | { |
1217 | 1217 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
1218 | 1218 | |
1219 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
1219 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
1220 | 1220 | $PRT = EEM_Price_Type::instance(); |
1221 | 1221 | |
1222 | 1222 | $success = 1; |
1223 | 1223 | $PRT_deleted = $trash ? true : false; |
1224 | 1224 | // Checkboxes |
1225 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1225 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1226 | 1226 | // if array has more than one element than success message should be plural |
1227 | 1227 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
1228 | 1228 | $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type'; |
1229 | 1229 | // cycle thru checkboxes |
1230 | 1230 | while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
1231 | - if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1231 | + if ( ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
1232 | 1232 | $success = 0; |
1233 | 1233 | } |
1234 | 1234 | } |
@@ -1279,13 +1279,13 @@ discard block |
||
1279 | 1279 | |
1280 | 1280 | $success = 1; |
1281 | 1281 | // Checkboxes |
1282 | - if (! empty($this->_req_data['checkbox'])) { |
|
1282 | + if ( ! empty($this->_req_data['checkbox'])) { |
|
1283 | 1283 | // if array has more than one element than success message should be plural |
1284 | 1284 | $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
1285 | 1285 | $what = $PRT->item_name($success); |
1286 | 1286 | // cycle thru bulk action checkboxes |
1287 | 1287 | while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
1288 | - if (! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
1288 | + if ( ! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
1289 | 1289 | $success = 0; |
1290 | 1290 | } |
1291 | 1291 | } |
@@ -1305,10 +1305,10 @@ discard block |
||
1305 | 1305 | */ |
1306 | 1306 | protected function _learn_more_about_pricing_link() |
1307 | 1307 | { |
1308 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __( |
|
1308 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'.__( |
|
1309 | 1309 | 'learn more about how pricing works', |
1310 | 1310 | 'event_espresso' |
1311 | - ) . '</a>'; |
|
1311 | + ).'</a>'; |
|
1312 | 1312 | } |
1313 | 1313 | |
1314 | 1314 | |
@@ -1384,7 +1384,7 @@ discard block |
||
1384 | 1384 | */ |
1385 | 1385 | public function _update_tax_settings() |
1386 | 1386 | { |
1387 | - if (! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
1387 | + if ( ! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
1388 | 1388 | EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config(); |
1389 | 1389 | } |
1390 | 1390 | try { |
@@ -33,9 +33,12 @@ discard block |
||
33 | 33 | <input type="text" size="1" class="edit-price-PRC_amount ee-numeric" |
34 | 34 | name="prices_archive[<?php echo $tkt_row; ?>][<?php echo $PRC_order; ?>][PRC_amount]" |
35 | 35 | value="<?php echo $PRC_amount; ?>" disabled> |
36 | - <?php else : ?> |
|
36 | + <?php else { |
|
37 | + : ?> |
|
37 | 38 | <input type="text" size="1" class="edit-price-PRC_amount ee-numeric" |
38 | - name="<?php echo $edit_prices_name; ?>[<?php echo $tkt_row; ?>][<?php echo $PRC_order; ?>][PRC_amount]" |
|
39 | + name="<?php echo $edit_prices_name; |
|
40 | +} |
|
41 | +?>[<?php echo $tkt_row; ?>][<?php echo $PRC_order; ?>][PRC_amount]" |
|
39 | 42 | value="<?php echo $PRC_amount; ?>"> |
40 | 43 | <?php endif; ?> |
41 | 44 | </td> |
@@ -46,8 +49,11 @@ discard block |
||
46 | 49 | <td> |
47 | 50 | <?php if ($disabled) : ?> |
48 | 51 | <span class="ee-lock-icon"></span> |
49 | - <?php else : ?> |
|
50 | - <!-- <span class="gear-icon dashicons dashicons-admin-generic clickable" data-ticket-row="<?php echo $tkt_row; ?>" data-context="price" data-price-row="<?php echo $PRC_order; ?>"></span> --> |
|
52 | + <?php else { |
|
53 | + : ?> |
|
54 | + <!-- <span class="gear-icon dashicons dashicons-admin-generic clickable" data-ticket-row="<?php echo $tkt_row; |
|
55 | +} |
|
56 | +?>" data-context="price" data-price-row="<?php echo $PRC_order; ?>"></span> --> |
|
51 | 57 | <span class="trash-icon dashicons dashicons-post-trash clickable" data-ticket-row="<?php echo $tkt_row; ?>" |
52 | 58 | data-context="price" data-price-row="<?php echo $PRC_order; ?>"<?php echo $show_trash_icon; ?>></span> |
53 | 59 | <button data-ticket-row="<?php echo $tkt_row; ?>" data-price-row="<?php echo $PRC_order; ?>" |
@@ -10,10 +10,10 @@ discard block |
||
10 | 10 | <td> |
11 | 11 | <?php echo $base_type_select; ?><br/> |
12 | 12 | <p class="description"><?php |
13 | - _e( |
|
14 | - 'Choosing a basic type allows us to quickly configure a bunch of other options for you.<br/>All events need to have at least one Base Price type option.<br/>Discounts reduce the price of an event, Surcharges increase the price.<br/>Taxes are applied to the final total.', |
|
15 | - 'event_espresso' |
|
16 | - ); ?></p> |
|
13 | + _e( |
|
14 | + 'Choosing a basic type allows us to quickly configure a bunch of other options for you.<br/>All events need to have at least one Base Price type option.<br/>Discounts reduce the price of an event, Surcharges increase the price.<br/>Taxes are applied to the final total.', |
|
15 | + 'event_espresso' |
|
16 | + ); ?></p> |
|
17 | 17 | </td> |
18 | 18 | </tr> |
19 | 19 | |
@@ -44,20 +44,20 @@ discard block |
||
44 | 44 | <?php _e('Fixed', 'event_espresso'); ?> |
45 | 45 | </label> |
46 | 46 | <p class="description"><?php |
47 | - _e( |
|
48 | - 'Whether this Price Type will be applied as a percentage or applied as a set fixed amount.', |
|
49 | - 'event_espresso' |
|
50 | - ); ?></p> |
|
47 | + _e( |
|
48 | + 'Whether this Price Type will be applied as a percentage or applied as a set fixed amount.', |
|
49 | + 'event_espresso' |
|
50 | + ); ?></p> |
|
51 | 51 | <?php if ($price_type->base_type() == EEM_Price_Type::base_type_tax) : |
52 | - // base type is tax so let's just let the user know that taxes are always percentage. |
|
53 | - ?> |
|
52 | + // base type is tax so let's just let the user know that taxes are always percentage. |
|
53 | + ?> |
|
54 | 54 | <p class="description" style="color:#E44064"> |
55 | 55 | <?php |
56 | - _e( |
|
57 | - 'The selected base type for this price type is "Tax". Taxes are always assumed to be a percentage. If you want to use a fixed value for a tax then please change the base type to a surcharge.', |
|
58 | - 'event_espresso' |
|
59 | - ); |
|
60 | - ?></p> |
|
56 | + _e( |
|
57 | + 'The selected base type for this price type is "Tax". Taxes are always assumed to be a percentage. If you want to use a fixed value for a tax then please change the base type to a surcharge.', |
|
58 | + 'event_espresso' |
|
59 | + ); |
|
60 | + ?></p> |
|
61 | 61 | <?php endif; ?> |
62 | 62 | </td> |
63 | 63 | </tr> |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | <p class="description"> |
72 | 72 | <?php _e('The order that Price Types are applied.', 'event_espresso'); ?></p> |
73 | 73 | <p class="description"><?php |
74 | - _e( |
|
75 | - 'Price types are applied sequentially according to their Order, where higher ordered Price Types will affect lower ordered Price Types.<br/>Price types with equal Orders will be applied in parallel to whatever total precedes them and will not affect each other. Actual Prices will be set to "0" so that they are processed first. Taxes will be always be applied last but their order will still determine if they are applied in parallel or as compound taxes (one tax on top of the other).', |
|
76 | - 'event_espresso' |
|
77 | - ); ?></p> |
|
74 | + _e( |
|
75 | + 'Price types are applied sequentially according to their Order, where higher ordered Price Types will affect lower ordered Price Types.<br/>Price types with equal Orders will be applied in parallel to whatever total precedes them and will not affect each other. Actual Prices will be set to "0" so that they are processed first. Taxes will be always be applied last but their order will still determine if they are applied in parallel or as compound taxes (one tax on top of the other).', |
|
76 | + 'event_espresso' |
|
77 | + ); ?></p> |
|
78 | 78 | </td> |
79 | 79 | </tr> |
80 | 80 |