@@ -13,72 +13,72 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
@@ -92,15 +92,15 @@ discard block |
||
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | - * Process Payment. |
|
96 | - * |
|
97 | - * |
|
98 | - * @param WPInv_Invoice $invoice Invoice. |
|
99 | - * @param array $submission_data Posted checkout fields. |
|
100 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
95 | + * Process Payment. |
|
96 | + * |
|
97 | + * |
|
98 | + * @param WPInv_Invoice $invoice Invoice. |
|
99 | + * @param array $submission_data Posted checkout fields. |
|
100 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | 106 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Get the PayPal request URL for an invoice. |
|
127 | - * |
|
128 | - * @param WPInv_Invoice $invoice Invoice object. |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function get_request_url( $invoice ) { |
|
126 | + * Get the PayPal request URL for an invoice. |
|
127 | + * |
|
128 | + * @param WPInv_Invoice $invoice Invoice object. |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function get_request_url( $invoice ) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | 137 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -144,44 +144,44 @@ discard block |
||
144 | 144 | |
145 | 145 | return add_query_arg( $paypal_args, $this->endpoint ); |
146 | 146 | |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | 149 | /** |
150 | - * Get PayPal Args for passing to PP. |
|
151 | - * |
|
152 | - * @param WPInv_Invoice $invoice Invoice object. |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - protected function get_paypal_args( $invoice ) { |
|
150 | + * Get PayPal Args for passing to PP. |
|
151 | + * |
|
152 | + * @param WPInv_Invoice $invoice Invoice object. |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + protected function get_paypal_args( $invoice ) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | - |
|
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | - $force_one_line_item = true; |
|
162 | - } |
|
163 | - |
|
164 | - $paypal_args = apply_filters( |
|
165 | - 'getpaid_paypal_args', |
|
166 | - array_merge( |
|
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | - ), |
|
170 | - $invoice |
|
171 | - ); |
|
172 | - |
|
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
158 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | + |
|
160 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | + $force_one_line_item = true; |
|
162 | + } |
|
163 | + |
|
164 | + $paypal_args = apply_filters( |
|
165 | + 'getpaid_paypal_args', |
|
166 | + array_merge( |
|
167 | + $this->get_transaction_args( $invoice ), |
|
168 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | + ), |
|
170 | + $invoice |
|
171 | + ); |
|
172 | + |
|
173 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Get transaction args for paypal request. |
|
178 | - * |
|
179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function get_transaction_args( $invoice ) { |
|
177 | + * Get transaction args for paypal request. |
|
178 | + * |
|
179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function get_transaction_args( $invoice ) { |
|
183 | 183 | |
184 | - return array( |
|
184 | + return array( |
|
185 | 185 | 'cmd' => '_cart', |
186 | 186 | 'business' => wpinv_get_option( 'paypal_email', false ), |
187 | 187 | 'no_shipping' => '1', |
@@ -206,16 +206,16 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
209 | - * Get line item args for paypal request. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
209 | + * Get line item args for paypal request. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
218 | + if ( $force_one_line_item ) { |
|
219 | 219 | return $this->get_line_item_args_single_item( $invoice ); |
220 | 220 | } |
221 | 221 | |
@@ -235,129 +235,129 @@ discard block |
||
235 | 235 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Get line item args for paypal request as a single line item. |
|
244 | - * |
|
245 | - * @param WPInv_Invoice $invoice Invoice object. |
|
246 | - * @return array |
|
247 | - */ |
|
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
249 | - $this->delete_line_items(); |
|
243 | + * Get line item args for paypal request as a single line item. |
|
244 | + * |
|
245 | + * @param WPInv_Invoice $invoice Invoice object. |
|
246 | + * @return array |
|
247 | + */ |
|
248 | + protected function get_line_item_args_single_item( $invoice ) { |
|
249 | + $this->delete_line_items(); |
|
250 | 250 | |
251 | 251 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
252 | + $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
253 | 253 | |
254 | - return $this->get_line_items(); |
|
254 | + return $this->get_line_items(); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | - * Return all line items. |
|
259 | - */ |
|
260 | - protected function get_line_items() { |
|
261 | - return $this->line_items; |
|
262 | - } |
|
258 | + * Return all line items. |
|
259 | + */ |
|
260 | + protected function get_line_items() { |
|
261 | + return $this->line_items; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | /** |
265 | - * Remove all line items. |
|
266 | - */ |
|
267 | - protected function delete_line_items() { |
|
268 | - $this->line_items = array(); |
|
265 | + * Remove all line items. |
|
266 | + */ |
|
267 | + protected function delete_line_items() { |
|
268 | + $this->line_items = array(); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | - * Prepare line items to send to paypal. |
|
273 | - * |
|
274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
275 | - */ |
|
276 | - protected function prepare_line_items( $invoice ) { |
|
277 | - $this->delete_line_items(); |
|
278 | - |
|
279 | - // Items. |
|
280 | - foreach ( $invoice->get_items() as $item ) { |
|
281 | - $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
272 | + * Prepare line items to send to paypal. |
|
273 | + * |
|
274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
275 | + */ |
|
276 | + protected function prepare_line_items( $invoice ) { |
|
277 | + $this->delete_line_items(); |
|
278 | + |
|
279 | + // Items. |
|
280 | + foreach ( $invoice->get_items() as $item ) { |
|
281 | + $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
287 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | 288 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | - * Add PayPal Line Item. |
|
295 | - * |
|
296 | - * @param string $item_name Item name. |
|
297 | - * @param int $quantity Item quantity. |
|
298 | - * @param float $amount Amount. |
|
299 | - * @param string $item_number Item number. |
|
300 | - */ |
|
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | - |
|
304 | - $item = apply_filters( |
|
305 | - 'getpaid_paypal_line_item', |
|
306 | - array( |
|
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | - 'quantity' => (int) $quantity, |
|
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | - 'item_number' => $item_number, |
|
311 | - ), |
|
312 | - $item_name, |
|
313 | - $quantity, |
|
314 | - $amount, |
|
315 | - $item_number |
|
316 | - ); |
|
317 | - |
|
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
294 | + * Add PayPal Line Item. |
|
295 | + * |
|
296 | + * @param string $item_name Item name. |
|
297 | + * @param int $quantity Item quantity. |
|
298 | + * @param float $amount Amount. |
|
299 | + * @param string $item_number Item number. |
|
300 | + */ |
|
301 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | + |
|
304 | + $item = apply_filters( |
|
305 | + 'getpaid_paypal_line_item', |
|
306 | + array( |
|
307 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | + 'quantity' => (int) $quantity, |
|
309 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | + 'item_number' => $item_number, |
|
311 | + ), |
|
312 | + $item_name, |
|
313 | + $quantity, |
|
314 | + $amount, |
|
315 | + $item_number |
|
316 | + ); |
|
317 | + |
|
318 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | 319 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | - * |
|
329 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | - * |
|
331 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | - $max_paypal_length = 2083; |
|
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | - |
|
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | - return $paypal_args; |
|
341 | - } |
|
342 | - |
|
343 | - return apply_filters( |
|
344 | - 'getpaid_paypal_args', |
|
345 | - array_merge( |
|
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
348 | - ), |
|
349 | - $invoice |
|
350 | - ); |
|
327 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | + * |
|
329 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | + * |
|
331 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | + $max_paypal_length = 2083; |
|
337 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | + |
|
339 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | + return $paypal_args; |
|
341 | + } |
|
342 | + |
|
343 | + return apply_filters( |
|
344 | + 'getpaid_paypal_args', |
|
345 | + array_merge( |
|
346 | + $this->get_transaction_args( $invoice ), |
|
347 | + $this->get_line_item_args( $invoice, true ) |
|
348 | + ), |
|
349 | + $invoice |
|
350 | + ); |
|
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
355 | - * Processes recurring invoices. |
|
356 | - * |
|
357 | - * @param array $paypal_args PayPal args. |
|
358 | - * @param WPInv_Invoice $invoice Invoice object. |
|
359 | - */ |
|
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
355 | + * Processes recurring invoices. |
|
356 | + * |
|
357 | + * @param array $paypal_args PayPal args. |
|
358 | + * @param WPInv_Invoice $invoice Invoice object. |
|
359 | + */ |
|
360 | + public function process_subscription( $paypal_args, $invoice ) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | 363 | if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
385 | - // Trial period length. |
|
386 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
385 | + // Trial period length. |
|
386 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
387 | 387 | |
388 | - // Trial period. |
|
389 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
388 | + // Trial period. |
|
389 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
390 | 390 | |
391 | 391 | } else if ( $initial_amount != $recurring_amount ) { |
392 | 392 | |
@@ -409,40 +409,40 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
413 | 413 | |
414 | - // Subscription price |
|
415 | - $paypal_args['a3'] = $recurring_amount; |
|
414 | + // Subscription price |
|
415 | + $paypal_args['a3'] = $recurring_amount; |
|
416 | 416 | |
417 | - // Subscription duration |
|
418 | - $paypal_args['p3'] = $interval; |
|
417 | + // Subscription duration |
|
418 | + $paypal_args['p3'] = $interval; |
|
419 | 419 | |
420 | - // Subscription period |
|
421 | - $paypal_args['t3'] = $period; |
|
420 | + // Subscription period |
|
421 | + $paypal_args['t3'] = $period; |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
427 | 427 | |
428 | - // Non-recurring payments |
|
429 | - $paypal_args['src'] = 0; |
|
428 | + // Non-recurring payments |
|
429 | + $paypal_args['src'] = 0; |
|
430 | 430 | |
431 | - } else { |
|
431 | + } else { |
|
432 | 432 | |
433 | - $paypal_args['src'] = 1; |
|
433 | + $paypal_args['src'] = 1; |
|
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ( $bill_times > 0 ) { |
|
436 | 436 | |
437 | - // An initial period is being used to charge a sign-up fee |
|
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | - $bill_times--; |
|
440 | - } |
|
437 | + // An initial period is being used to charge a sign-up fee |
|
438 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | + $bill_times--; |
|
440 | + } |
|
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | 443 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | // Force return URL so that order description & instructions display |
@@ -458,24 +458,24 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | return apply_filters( |
461 | - 'getpaid_paypal_subscription_args', |
|
462 | - $paypal_args, |
|
463 | - $invoice |
|
461 | + 'getpaid_paypal_subscription_args', |
|
462 | + $paypal_args, |
|
463 | + $invoice |
|
464 | 464 | ); |
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
469 | - * Processes ipns and marks payments as complete. |
|
470 | - * |
|
471 | - * @return void |
|
472 | - */ |
|
473 | - public function verify_ipn() { |
|
469 | + * Processes ipns and marks payments as complete. |
|
470 | + * |
|
471 | + * @return void |
|
472 | + */ |
|
473 | + public function verify_ipn() { |
|
474 | 474 | |
475 | 475 | // Validate the IPN. |
476 | 476 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
477 | - wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) ); |
|
478 | - } |
|
477 | + wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) ); |
|
478 | + } |
|
479 | 479 | |
480 | 480 | // Process the IPN. |
481 | 481 | $posted = wp_unslash( $_POST ); |
@@ -489,8 +489,8 @@ discard block |
||
489 | 489 | wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
490 | 490 | wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
491 | 491 | |
492 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
493 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
492 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
493 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
494 | 494 | } else { |
495 | 495 | wpinv_error_log( 'Aborting, Invalid type:' . $posted['txn_type'] ); |
496 | 496 | } |
@@ -502,33 +502,33 @@ discard block |
||
502 | 502 | } |
503 | 503 | |
504 | 504 | /** |
505 | - * Check PayPal IPN validity. |
|
506 | - */ |
|
507 | - public function validate_ipn() { |
|
508 | - |
|
509 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
510 | - |
|
511 | - // Get received values from post data. |
|
512 | - $validate_ipn = wp_unslash( $_POST ); |
|
513 | - $validate_ipn['cmd'] = '_notify-validate'; |
|
514 | - |
|
515 | - // Send back post vars to paypal. |
|
516 | - $params = array( |
|
517 | - 'body' => $validate_ipn, |
|
518 | - 'timeout' => 60, |
|
519 | - 'httpversion' => '1.1', |
|
520 | - 'compress' => false, |
|
521 | - 'decompress' => false, |
|
522 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
523 | - ); |
|
505 | + * Check PayPal IPN validity. |
|
506 | + */ |
|
507 | + public function validate_ipn() { |
|
508 | + |
|
509 | + wpinv_error_log( 'Validating PayPal IPN response' ); |
|
510 | + |
|
511 | + // Get received values from post data. |
|
512 | + $validate_ipn = wp_unslash( $_POST ); |
|
513 | + $validate_ipn['cmd'] = '_notify-validate'; |
|
514 | + |
|
515 | + // Send back post vars to paypal. |
|
516 | + $params = array( |
|
517 | + 'body' => $validate_ipn, |
|
518 | + 'timeout' => 60, |
|
519 | + 'httpversion' => '1.1', |
|
520 | + 'compress' => false, |
|
521 | + 'decompress' => false, |
|
522 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
523 | + ); |
|
524 | 524 | |
525 | - // Post back to get a response. |
|
526 | - $response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
525 | + // Post back to get a response. |
|
526 | + $response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
527 | 527 | |
528 | 528 | // Check to see if the request was valid. |
529 | - if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
529 | + if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
530 | 530 | wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
531 | - return true; |
|
531 | + return true; |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | if ( is_wp_error( $response ) ) { |
@@ -542,63 +542,63 @@ discard block |
||
542 | 542 | } |
543 | 543 | |
544 | 544 | /** |
545 | - * Check currency from IPN matches the invoice. |
|
546 | - * |
|
547 | - * @param WPInv_Invoice $invoice Invoice object. |
|
548 | - * @param string $currency currency to validate. |
|
549 | - */ |
|
550 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
551 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
545 | + * Check currency from IPN matches the invoice. |
|
546 | + * |
|
547 | + * @param WPInv_Invoice $invoice Invoice object. |
|
548 | + * @param string $currency currency to validate. |
|
549 | + */ |
|
550 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
551 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
552 | 552 | wpinv_record_gateway_error( 'IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}" ); |
553 | 553 | |
554 | - /* translators: %s: currency code. */ |
|
555 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
556 | - exit; |
|
557 | - } |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Check payment amount from IPN matches the invoice. |
|
562 | - * |
|
563 | - * @param WPInv_Invoice $invoice Invoice object. |
|
564 | - * @param float $amount amount to validate. |
|
565 | - */ |
|
566 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
567 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
554 | + /* translators: %s: currency code. */ |
|
555 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
556 | + exit; |
|
557 | + } |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Check payment amount from IPN matches the invoice. |
|
562 | + * |
|
563 | + * @param WPInv_Invoice $invoice Invoice object. |
|
564 | + * @param float $amount amount to validate. |
|
565 | + */ |
|
566 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
567 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
568 | 568 | wpinv_record_gateway_error( 'IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}" ); |
569 | 569 | |
570 | - /* translators: %s: Amount. */ |
|
571 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
572 | - exit; |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * Verify receiver email from PayPal. |
|
578 | - * |
|
579 | - * @param WPInv_Invoice $invoice Invoice object. |
|
580 | - * @param string $receiver_email Email to validate. |
|
581 | - */ |
|
582 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
570 | + /* translators: %s: Amount. */ |
|
571 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
572 | + exit; |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * Verify receiver email from PayPal. |
|
578 | + * |
|
579 | + * @param WPInv_Invoice $invoice Invoice object. |
|
580 | + * @param string $receiver_email Email to validate. |
|
581 | + */ |
|
582 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
583 | 583 | $paypal_email = wpinv_get_option( 'paypal_email' ); |
584 | 584 | |
585 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
585 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
586 | 586 | wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
587 | 587 | |
588 | - /* translators: %s: email address . */ |
|
589 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
590 | - exit; |
|
588 | + /* translators: %s: email address . */ |
|
589 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
590 | + exit; |
|
591 | 591 | } |
592 | 592 | |
593 | - } |
|
593 | + } |
|
594 | 594 | |
595 | 595 | /** |
596 | - * Handles one time payments. |
|
597 | - * |
|
598 | - * @param WPInv_Invoice $invoice Invoice object. |
|
599 | - * @param array $posted Posted data. |
|
600 | - */ |
|
601 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
596 | + * Handles one time payments. |
|
597 | + * |
|
598 | + * @param WPInv_Invoice $invoice Invoice object. |
|
599 | + * @param array $posted Posted data. |
|
600 | + */ |
|
601 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
602 | 602 | |
603 | 603 | // Collect payment details |
604 | 604 | $payment_status = strtolower( $posted['payment_status'] ); |
@@ -659,27 +659,27 @@ discard block |
||
659 | 659 | // Process failures. |
660 | 660 | |
661 | 661 | /* translators: %s: payment status. */ |
662 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) ); |
|
663 | - |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * Handles one time payments. |
|
668 | - * |
|
669 | - * @param WPInv_Invoice $invoice Invoice object. |
|
670 | - * @param array $posted Posted data. |
|
671 | - */ |
|
672 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
673 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
662 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) ); |
|
663 | + |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * Handles one time payments. |
|
668 | + * |
|
669 | + * @param WPInv_Invoice $invoice Invoice object. |
|
670 | + * @param array $posted Posted data. |
|
671 | + */ |
|
672 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
673 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | /** |
677 | - * Handles subscription sign ups. |
|
678 | - * |
|
679 | - * @param WPInv_Invoice $invoice Invoice object. |
|
680 | - * @param array $posted Posted data. |
|
681 | - */ |
|
682 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
677 | + * Handles subscription sign ups. |
|
678 | + * |
|
679 | + * @param WPInv_Invoice $invoice Invoice object. |
|
680 | + * @param array $posted Posted data. |
|
681 | + */ |
|
682 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
683 | 683 | |
684 | 684 | // Make sure the invoice has a subscription. |
685 | 685 | $subscription = wpinv_get_subscription( $invoice ); |
@@ -718,12 +718,12 @@ discard block |
||
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
721 | - * Handles subscription renewals. |
|
722 | - * |
|
723 | - * @param WPInv_Invoice $invoice Invoice object. |
|
724 | - * @param array $posted Posted data. |
|
725 | - */ |
|
726 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
721 | + * Handles subscription renewals. |
|
722 | + * |
|
723 | + * @param WPInv_Invoice $invoice Invoice object. |
|
724 | + * @param array $posted Posted data. |
|
725 | + */ |
|
726 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
727 | 727 | |
728 | 728 | // Make sure the invoice has a subscription. |
729 | 729 | $subscription = wpinv_get_subscription( $invoice ); |
@@ -766,12 +766,12 @@ discard block |
||
766 | 766 | } |
767 | 767 | |
768 | 768 | /** |
769 | - * Handles subscription cancelations. |
|
770 | - * |
|
771 | - * @param WPInv_Invoice $invoice Invoice object. |
|
772 | - * @param array $posted Posted data. |
|
773 | - */ |
|
774 | - protected function ipn_txn_subscr_cancel( $invoice, $posted ) { |
|
769 | + * Handles subscription cancelations. |
|
770 | + * |
|
771 | + * @param WPInv_Invoice $invoice Invoice object. |
|
772 | + * @param array $posted Posted data. |
|
773 | + */ |
|
774 | + protected function ipn_txn_subscr_cancel( $invoice, $posted ) { |
|
775 | 775 | |
776 | 776 | if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
777 | 777 | $subscription->cancel(); |
@@ -780,12 +780,12 @@ discard block |
||
780 | 780 | } |
781 | 781 | |
782 | 782 | /** |
783 | - * Handles subscription completions. |
|
784 | - * |
|
785 | - * @param WPInv_Invoice $invoice Invoice object. |
|
786 | - * @param array $posted Posted data. |
|
787 | - */ |
|
788 | - protected function ipn_txn_subscr_eot( $invoice, $posted ) { |
|
783 | + * Handles subscription completions. |
|
784 | + * |
|
785 | + * @param WPInv_Invoice $invoice Invoice object. |
|
786 | + * @param array $posted Posted data. |
|
787 | + */ |
|
788 | + protected function ipn_txn_subscr_eot( $invoice, $posted ) { |
|
789 | 789 | |
790 | 790 | if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
791 | 791 | $subscription->complete(); |
@@ -794,12 +794,12 @@ discard block |
||
794 | 794 | } |
795 | 795 | |
796 | 796 | /** |
797 | - * Handles subscription fails. |
|
798 | - * |
|
799 | - * @param WPInv_Invoice $invoice Invoice object. |
|
800 | - * @param array $posted Posted data. |
|
801 | - */ |
|
802 | - protected function ipn_txn_subscr_failed( $invoice, $posted ) { |
|
797 | + * Handles subscription fails. |
|
798 | + * |
|
799 | + * @param WPInv_Invoice $invoice Invoice object. |
|
800 | + * @param array $posted Posted data. |
|
801 | + */ |
|
802 | + protected function ipn_txn_subscr_failed( $invoice, $posted ) { |
|
803 | 803 | |
804 | 804 | if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
805 | 805 | $subscription->failing(); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox' ); |
|
27 | + protected $supports = array('subscription', 'sandbox'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | 82 | |
83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
89 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
90 | 90 | |
91 | 91 | parent::__construct(); |
92 | 92 | } |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
101 | 101 | * @return array |
102 | 102 | */ |
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
103 | + public function process_payment($invoice, $submission_data, $submission) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
106 | + $paypal_redirect = $this->get_request_url($invoice); |
|
107 | 107 | |
108 | 108 | // Add a note about the request url. |
109 | 109 | $invoice->add_note( |
110 | 110 | sprintf( |
111 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
112 | - esc_url( $paypal_redirect ) |
|
111 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
112 | + esc_url($paypal_redirect) |
|
113 | 113 | ), |
114 | 114 | false, |
115 | 115 | false, |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ); |
118 | 118 | |
119 | 119 | // Redirect to PayPal |
120 | - wp_redirect( $paypal_redirect ); |
|
120 | + wp_redirect($paypal_redirect); |
|
121 | 121 | exit; |
122 | 122 | |
123 | 123 | } |
@@ -128,21 +128,21 @@ discard block |
||
128 | 128 | * @param WPInv_Invoice $invoice Invoice object. |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public function get_request_url( $invoice ) { |
|
131 | + public function get_request_url($invoice) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
137 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
138 | 138 | |
139 | - if ( $invoice->is_recurring() ) { |
|
139 | + if ($invoice->is_recurring()) { |
|
140 | 140 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
141 | 141 | } else { |
142 | 142 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
143 | 143 | } |
144 | 144 | |
145 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
145 | + return add_query_arg($paypal_args, $this->endpoint); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
@@ -152,25 +152,25 @@ discard block |
||
152 | 152 | * @param WPInv_Invoice $invoice Invoice object. |
153 | 153 | * @return array |
154 | 154 | */ |
155 | - protected function get_paypal_args( $invoice ) { |
|
155 | + protected function get_paypal_args($invoice) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
158 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', false, $invoice); |
|
159 | 159 | |
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
160 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
161 | 161 | $force_one_line_item = true; |
162 | 162 | } |
163 | 163 | |
164 | 164 | $paypal_args = apply_filters( |
165 | 165 | 'getpaid_paypal_args', |
166 | 166 | array_merge( |
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
167 | + $this->get_transaction_args($invoice), |
|
168 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
169 | 169 | ), |
170 | 170 | $invoice |
171 | 171 | ); |
172 | 172 | |
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
173 | + return $this->fix_request_length($invoice, $paypal_args); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | * @param WPInv_Invoice $invoice Invoice object. |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - protected function get_transaction_args( $invoice ) { |
|
182 | + protected function get_transaction_args($invoice) { |
|
183 | 183 | |
184 | 184 | return array( |
185 | 185 | 'cmd' => '_cart', |
186 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
186 | + 'business' => wpinv_get_option('paypal_email', false), |
|
187 | 187 | 'no_shipping' => '1', |
188 | 188 | 'shipping' => '0', |
189 | 189 | 'no_note' => '1', |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | 'rm' => is_ssl() ? 2 : 1, |
192 | 192 | 'upload' => 1, |
193 | 193 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
194 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
195 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
196 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
197 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
194 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
195 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
196 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
197 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
198 | 198 | 'custom' => $invoice->get_id(), |
199 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
200 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
201 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
202 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
203 | - 'cbt' => get_bloginfo( 'name' ) |
|
199 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
200 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
201 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
202 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
203 | + 'cbt' => get_bloginfo('name') |
|
204 | 204 | ); |
205 | 205 | |
206 | 206 | } |
@@ -212,30 +212,30 @@ discard block |
||
212 | 212 | * @param bool $force_one_line_item Create only one item for this invoice. |
213 | 213 | * @return array |
214 | 214 | */ |
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
215 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
219 | - return $this->get_line_item_args_single_item( $invoice ); |
|
218 | + if ($force_one_line_item) { |
|
219 | + return $this->get_line_item_args_single_item($invoice); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // Send each line item individually. |
223 | 223 | $line_item_args = array(); |
224 | 224 | |
225 | 225 | // Prepare line items. |
226 | - $this->prepare_line_items( $invoice ); |
|
226 | + $this->prepare_line_items($invoice); |
|
227 | 227 | |
228 | 228 | // Add taxes to the cart |
229 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
230 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
229 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
230 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Add discount. |
234 | - if ( $invoice->get_total_discount() > 0 ) { |
|
235 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
234 | + if ($invoice->get_total_discount() > 0) { |
|
235 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge($line_item_args, $this->get_line_items()); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | * @param WPInv_Invoice $invoice Invoice object. |
246 | 246 | * @return array |
247 | 247 | */ |
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
248 | + protected function get_line_item_args_single_item($invoice) { |
|
249 | 249 | $this->delete_line_items(); |
250 | 250 | |
251 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
251 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
252 | + $this->add_line_item($item_name, 1, wpinv_sanitize_amount((float) $invoice->get_total(), 2), $invoice->get_id()); |
|
253 | 253 | |
254 | 254 | return $this->get_line_items(); |
255 | 255 | } |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @param WPInv_Invoice $invoice Invoice object. |
275 | 275 | */ |
276 | - protected function prepare_line_items( $invoice ) { |
|
276 | + protected function prepare_line_items($invoice) { |
|
277 | 277 | $this->delete_line_items(); |
278 | 278 | |
279 | 279 | // Items. |
280 | - foreach ( $invoice->get_items() as $item ) { |
|
280 | + foreach ($invoice->get_items() as $item) { |
|
281 | 281 | $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
282 | 282 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
283 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
287 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
288 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
@@ -298,15 +298,15 @@ discard block |
||
298 | 298 | * @param float $amount Amount. |
299 | 299 | * @param string $item_number Item number. |
300 | 300 | */ |
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
301 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
302 | + $index = (count($this->line_items) / 4) + 1; |
|
303 | 303 | |
304 | 304 | $item = apply_filters( |
305 | 305 | 'getpaid_paypal_line_item', |
306 | 306 | array( |
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
307 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
308 | 308 | 'quantity' => (int) $quantity, |
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
309 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
310 | 310 | 'item_number' => $item_number, |
311 | 311 | ), |
312 | 312 | $item_name, |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | $item_number |
316 | 316 | ); |
317 | 317 | |
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
318 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
319 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items['amount_' . $index] = $item['amount']; |
|
323 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -332,19 +332,19 @@ discard block |
||
332 | 332 | * @param array $paypal_args Arguments sent to Paypal in the request. |
333 | 333 | * @return array |
334 | 334 | */ |
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
335 | + protected function fix_request_length($invoice, $paypal_args) { |
|
336 | 336 | $max_paypal_length = 2083; |
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
337 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
338 | 338 | |
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
339 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
340 | 340 | return $paypal_args; |
341 | 341 | } |
342 | 342 | |
343 | 343 | return apply_filters( |
344 | 344 | 'getpaid_paypal_args', |
345 | 345 | array_merge( |
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
346 | + $this->get_transaction_args($invoice), |
|
347 | + $this->get_line_item_args($invoice, true) |
|
348 | 348 | ), |
349 | 349 | $invoice |
350 | 350 | ); |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | * @param array $paypal_args PayPal args. |
358 | 358 | * @param WPInv_Invoice $invoice Invoice object. |
359 | 359 | */ |
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
360 | + public function process_subscription($paypal_args, $invoice) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | - if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
|
363 | + if (!$invoice->is_recurring() || !$subscription = wpinv_get_subscription($invoice)) { |
|
364 | 364 | return $paypal_args; |
365 | 365 | } |
366 | 366 | |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
369 | 369 | |
370 | 370 | // Subscription name. |
371 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
371 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
372 | 372 | |
373 | 373 | // Get subscription args. |
374 | - $period = strtoupper( substr( $subscription->period, 0, 1) ); |
|
374 | + $period = strtoupper(substr($subscription->period, 0, 1)); |
|
375 | 375 | $interval = (int) $subscription->frequency; |
376 | 376 | $bill_times = (int) $subscription->bill_times; |
377 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
378 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
379 | - $subscription_item = $invoice->get_recurring( true ); |
|
377 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
378 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
379 | + $subscription_item = $invoice->get_recurring(true); |
|
380 | 380 | |
381 | - if ( $subscription_item->has_free_trial() ) { |
|
381 | + if ($subscription_item->has_free_trial()) { |
|
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
@@ -388,28 +388,28 @@ discard block |
||
388 | 388 | // Trial period. |
389 | 389 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
390 | 390 | |
391 | - } else if ( $initial_amount != $recurring_amount ) { |
|
391 | + } else if ($initial_amount != $recurring_amount) { |
|
392 | 392 | |
393 | 393 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
394 | 394 | |
395 | - if ( 1 == $bill_times ) { |
|
395 | + if (1 == $bill_times) { |
|
396 | 396 | $param_number = 3; |
397 | 397 | } else { |
398 | 398 | $param_number = 1; |
399 | 399 | } |
400 | 400 | |
401 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? 0 : $initial_amount; |
|
401 | + $paypal_args['a' . $param_number] = $initial_amount ? 0 : $initial_amount; |
|
402 | 402 | |
403 | 403 | // Sign Up interval |
404 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
404 | + $paypal_args['p' . $param_number] = $interval; |
|
405 | 405 | |
406 | 406 | // Sign Up unit of duration |
407 | - $paypal_args[ 't' . $param_number ] = $period; |
|
407 | + $paypal_args['t' . $param_number] = $period; |
|
408 | 408 | |
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if (!isset($param_number) || 1 == $param_number) { |
|
413 | 413 | |
414 | 414 | // Subscription price |
415 | 415 | $paypal_args['a3'] = $recurring_amount; |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
427 | 427 | |
428 | 428 | // Non-recurring payments |
429 | 429 | $paypal_args['src'] = 0; |
@@ -432,15 +432,15 @@ discard block |
||
432 | 432 | |
433 | 433 | $paypal_args['src'] = 1; |
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ($bill_times > 0) { |
|
436 | 436 | |
437 | 437 | // An initial period is being used to charge a sign-up fee |
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
438 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
439 | 439 | $bill_times--; |
440 | 440 | } |
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
443 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
444 | 444 | |
445 | 445 | } |
446 | 446 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | $paypal_args['rm'] = 2; |
450 | 450 | |
451 | 451 | // Get rid of redudant items. |
452 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
452 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
453 | 453 | |
454 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
455 | - unset( $paypal_args[ $arg ] ); |
|
454 | + if (isset($paypal_args[$arg])) { |
|
455 | + unset($paypal_args[$arg]); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | } |
@@ -473,26 +473,26 @@ discard block |
||
473 | 473 | public function verify_ipn() { |
474 | 474 | |
475 | 475 | // Validate the IPN. |
476 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
477 | - wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) ); |
|
476 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
477 | + wp_die('PayPal IPN Request Failure', 'PayPal IPN', array('response' => 500)); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | // Process the IPN. |
481 | - $posted = wp_unslash( $_POST ); |
|
482 | - $invoice = wpinv_get_invoice( $posted['custom'] ); |
|
481 | + $posted = wp_unslash($_POST); |
|
482 | + $invoice = wpinv_get_invoice($posted['custom']); |
|
483 | 483 | |
484 | - if ( $invoice && $this->id == $invoice->get_gateway() ) { |
|
484 | + if ($invoice && $this->id == $invoice->get_gateway()) { |
|
485 | 485 | |
486 | - $posted['payment_status'] = sanitize_key( strtolower( $posted['payment_status'] ) ); |
|
487 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
486 | + $posted['payment_status'] = sanitize_key(strtolower($posted['payment_status'])); |
|
487 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
488 | 488 | |
489 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
490 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
489 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
490 | + wpinv_error_log('Payment status:' . $posted['payment_status']); |
|
491 | 491 | |
492 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
493 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
492 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
493 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
494 | 494 | } else { |
495 | - wpinv_error_log( 'Aborting, Invalid type:' . $posted['txn_type'] ); |
|
495 | + wpinv_error_log('Aborting, Invalid type:' . $posted['txn_type']); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | } |
@@ -506,10 +506,10 @@ discard block |
||
506 | 506 | */ |
507 | 507 | public function validate_ipn() { |
508 | 508 | |
509 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
509 | + wpinv_error_log('Validating PayPal IPN response'); |
|
510 | 510 | |
511 | 511 | // Get received values from post data. |
512 | - $validate_ipn = wp_unslash( $_POST ); |
|
512 | + $validate_ipn = wp_unslash($_POST); |
|
513 | 513 | $validate_ipn['cmd'] = '_notify-validate'; |
514 | 514 | |
515 | 515 | // Send back post vars to paypal. |
@@ -523,18 +523,18 @@ discard block |
||
523 | 523 | ); |
524 | 524 | |
525 | 525 | // Post back to get a response. |
526 | - $response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
526 | + $response = wp_safe_remote_post($this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
527 | 527 | |
528 | 528 | // Check to see if the request was valid. |
529 | - if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
530 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
529 | + if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
530 | + wpinv_error_log($response['body'], 'Received valid response from PayPal IPN'); |
|
531 | 531 | return true; |
532 | 532 | } |
533 | 533 | |
534 | - if ( is_wp_error( $response ) ) { |
|
535 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
534 | + if (is_wp_error($response)) { |
|
535 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
536 | 536 | } else { |
537 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
537 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
538 | 538 | } |
539 | 539 | |
540 | 540 | return false; |
@@ -547,12 +547,12 @@ discard block |
||
547 | 547 | * @param WPInv_Invoice $invoice Invoice object. |
548 | 548 | * @param string $currency currency to validate. |
549 | 549 | */ |
550 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
551 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
552 | - wpinv_record_gateway_error( 'IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}" ); |
|
550 | + protected function validate_ipn_currency($invoice, $currency) { |
|
551 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
552 | + wpinv_record_gateway_error('IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}"); |
|
553 | 553 | |
554 | 554 | /* translators: %s: currency code. */ |
555 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
555 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
556 | 556 | exit; |
557 | 557 | } |
558 | 558 | } |
@@ -563,12 +563,12 @@ discard block |
||
563 | 563 | * @param WPInv_Invoice $invoice Invoice object. |
564 | 564 | * @param float $amount amount to validate. |
565 | 565 | */ |
566 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
567 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
568 | - wpinv_record_gateway_error( 'IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}" ); |
|
566 | + protected function validate_ipn_amount($invoice, $amount) { |
|
567 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
568 | + wpinv_record_gateway_error('IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}"); |
|
569 | 569 | |
570 | 570 | /* translators: %s: Amount. */ |
571 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
571 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
572 | 572 | exit; |
573 | 573 | } |
574 | 574 | } |
@@ -579,14 +579,14 @@ discard block |
||
579 | 579 | * @param WPInv_Invoice $invoice Invoice object. |
580 | 580 | * @param string $receiver_email Email to validate. |
581 | 581 | */ |
582 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
583 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
582 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
583 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
584 | 584 | |
585 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
586 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
585 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
586 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
587 | 587 | |
588 | 588 | /* translators: %s: email address . */ |
589 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
589 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
590 | 590 | exit; |
591 | 591 | } |
592 | 592 | |
@@ -598,57 +598,57 @@ discard block |
||
598 | 598 | * @param WPInv_Invoice $invoice Invoice object. |
599 | 599 | * @param array $posted Posted data. |
600 | 600 | */ |
601 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
601 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
602 | 602 | |
603 | 603 | // Collect payment details |
604 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
605 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
604 | + $payment_status = strtolower($posted['payment_status']); |
|
605 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
606 | 606 | |
607 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
608 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
607 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
608 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
609 | 609 | |
610 | 610 | // Update the transaction id. |
611 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
612 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
611 | + if (!empty($posted['txn_id'])) { |
|
612 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
613 | 613 | $invoice->save(); |
614 | 614 | } |
615 | 615 | |
616 | 616 | // Process a refund. |
617 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
617 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
618 | 618 | |
619 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
619 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
620 | 620 | |
621 | - if ( ! $invoice->is_refunded() ) { |
|
622 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
621 | + if (!$invoice->is_refunded()) { |
|
622 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | exit; |
626 | 626 | } |
627 | 627 | |
628 | 628 | // Process payments. |
629 | - if ( $payment_status == 'completed' ) { |
|
629 | + if ($payment_status == 'completed') { |
|
630 | 630 | |
631 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
632 | - wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already complete.' ); |
|
631 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
632 | + wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already complete.'); |
|
633 | 633 | exit; |
634 | 634 | } |
635 | 635 | |
636 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
636 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
637 | 637 | |
638 | - if ( 'completed' === $payment_status || 'pending' === $payment_status ) { |
|
638 | + if ('completed' === $payment_status || 'pending' === $payment_status) { |
|
639 | 639 | |
640 | 640 | $note = ''; |
641 | 641 | |
642 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
643 | - $note = sprintf( __( 'PayPal Transaction Fee %s', 'invoicing' ), wpinv_clean( $posted['mc_fee'] ) ); |
|
642 | + if (!empty($posted['mc_fee'])) { |
|
643 | + $note = sprintf(__('PayPal Transaction Fee %s', 'invoicing'), wpinv_clean($posted['mc_fee'])); |
|
644 | 644 | } |
645 | 645 | |
646 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? wpinv_clean( $posted['txn_id'] ) : '' ), $note ); |
|
646 | + $invoice->mark_paid((!empty($posted['txn_id']) ? wpinv_clean($posted['txn_id']) : ''), $note); |
|
647 | 647 | |
648 | 648 | } else { |
649 | 649 | |
650 | 650 | /* translators: %s: pending reason. */ |
651 | - $invoice->update_status( 'wpi_processing', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
651 | + $invoice->update_status('wpi_processing', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
652 | 652 | |
653 | 653 | } |
654 | 654 | |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | // Process failures. |
660 | 660 | |
661 | 661 | /* translators: %s: payment status. */ |
662 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) ); |
|
662 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), wpinv_clean($posted['payment_status']))); |
|
663 | 663 | |
664 | 664 | } |
665 | 665 | |
@@ -669,8 +669,8 @@ discard block |
||
669 | 669 | * @param WPInv_Invoice $invoice Invoice object. |
670 | 670 | * @param array $posted Posted data. |
671 | 671 | */ |
672 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
673 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
672 | + protected function ipn_txn_cart($invoice, $posted) { |
|
673 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | /** |
@@ -679,39 +679,39 @@ discard block |
||
679 | 679 | * @param WPInv_Invoice $invoice Invoice object. |
680 | 680 | * @param array $posted Posted data. |
681 | 681 | */ |
682 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
682 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
683 | 683 | |
684 | 684 | // Make sure the invoice has a subscription. |
685 | - $subscription = wpinv_get_subscription( $invoice ); |
|
685 | + $subscription = wpinv_get_subscription($invoice); |
|
686 | 686 | |
687 | - if ( empty( $subscription ) ) { |
|
688 | - wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
687 | + if (empty($subscription)) { |
|
688 | + wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | // Update the subscription ids. |
692 | 692 | $subscription->update( |
693 | 693 | array( |
694 | - 'profile_id' => sanitize_text_field( $posted['subscr_id'] ), |
|
694 | + 'profile_id' => sanitize_text_field($posted['subscr_id']), |
|
695 | 695 | ) |
696 | 696 | ); |
697 | 697 | |
698 | 698 | // Set the transaction id. |
699 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
700 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
699 | + if (!empty($posted['txn_id'])) { |
|
700 | + $invoice->set_transaction_id($posted['txn_id']); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | // Update the payment status. |
704 | 704 | $invoice->mark_paid(); |
705 | 705 | |
706 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
706 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
707 | 707 | |
708 | 708 | // Update the subscription duration. |
709 | - $duration = strtotime( $subscription->expiration ) - strtotime( $subscription->created ); |
|
709 | + $duration = strtotime($subscription->expiration) - strtotime($subscription->created); |
|
710 | 710 | $subscription->update( |
711 | 711 | array( |
712 | 712 | 'status' => 'trialling' == $subscription->status ? 'trialling' : 'active', |
713 | - 'created' => current_time( 'mysql' ), |
|
714 | - 'expiration' => date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ), |
|
713 | + 'created' => current_time('mysql'), |
|
714 | + 'expiration' => date('Y-m-d H:i:s', (current_time('timestamp') + $duration)), |
|
715 | 715 | ) |
716 | 716 | ); |
717 | 717 | |
@@ -723,25 +723,25 @@ discard block |
||
723 | 723 | * @param WPInv_Invoice $invoice Invoice object. |
724 | 724 | * @param array $posted Posted data. |
725 | 725 | */ |
726 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
726 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
727 | 727 | |
728 | 728 | // Make sure the invoice has a subscription. |
729 | - $subscription = wpinv_get_subscription( $invoice ); |
|
729 | + $subscription = wpinv_get_subscription($invoice); |
|
730 | 730 | |
731 | - if ( empty( $subscription ) ) { |
|
732 | - wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
731 | + if (empty($subscription)) { |
|
732 | + wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
733 | 733 | } |
734 | 734 | |
735 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
735 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
736 | 736 | |
737 | 737 | // Abort if the payment is already recorded. |
738 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
738 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
739 | 739 | return; |
740 | 740 | } |
741 | 741 | |
742 | 742 | // Abort if this is the first payment. |
743 | - if ( date( 'Ynd', $subscription->created ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
744 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
743 | + if (date('Ynd', $subscription->created) == date('Ynd', strtotime($posted['payment_date']))) { |
|
744 | + $invoice->set_transaction_id($posted['txn_id']); |
|
745 | 745 | $invoice->save(); |
746 | 746 | return; |
747 | 747 | } |
@@ -752,14 +752,14 @@ discard block |
||
752 | 752 | 'gateway' => $this->id, |
753 | 753 | ); |
754 | 754 | |
755 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
755 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
756 | 756 | |
757 | - if ( empty( $invoice ) ) { |
|
757 | + if (empty($invoice)) { |
|
758 | 758 | return; |
759 | 759 | } |
760 | 760 | |
761 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
762 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
761 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
762 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
763 | 763 | |
764 | 764 | $subscription->renew(); |
765 | 765 | |
@@ -771,9 +771,9 @@ discard block |
||
771 | 771 | * @param WPInv_Invoice $invoice Invoice object. |
772 | 772 | * @param array $posted Posted data. |
773 | 773 | */ |
774 | - protected function ipn_txn_subscr_cancel( $invoice, $posted ) { |
|
774 | + protected function ipn_txn_subscr_cancel($invoice, $posted) { |
|
775 | 775 | |
776 | - if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
|
776 | + if ($subscription = wpinv_get_subscription($invoice)) { |
|
777 | 777 | $subscription->cancel(); |
778 | 778 | } |
779 | 779 | |
@@ -785,9 +785,9 @@ discard block |
||
785 | 785 | * @param WPInv_Invoice $invoice Invoice object. |
786 | 786 | * @param array $posted Posted data. |
787 | 787 | */ |
788 | - protected function ipn_txn_subscr_eot( $invoice, $posted ) { |
|
788 | + protected function ipn_txn_subscr_eot($invoice, $posted) { |
|
789 | 789 | |
790 | - if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
|
790 | + if ($subscription = wpinv_get_subscription($invoice)) { |
|
791 | 791 | $subscription->complete(); |
792 | 792 | } |
793 | 793 | |
@@ -799,9 +799,9 @@ discard block |
||
799 | 799 | * @param WPInv_Invoice $invoice Invoice object. |
800 | 800 | * @param array $posted Posted data. |
801 | 801 | */ |
802 | - protected function ipn_txn_subscr_failed( $invoice, $posted ) { |
|
802 | + protected function ipn_txn_subscr_failed($invoice, $posted) { |
|
803 | 803 | |
804 | - if ( $subscription = wpinv_get_subscription( $invoice ) ) { |
|
804 | + if ($subscription = wpinv_get_subscription($invoice)) { |
|
805 | 805 | $subscription->failing(); |
806 | 806 | } |
807 | 807 | |
@@ -810,10 +810,10 @@ discard block |
||
810 | 810 | /** |
811 | 811 | * Displays a notice on the checkout page if sandbox is enabled. |
812 | 812 | */ |
813 | - public function sandbox_notice( $description, $gateway ) { |
|
814 | - if ( 'paypal' == $gateway && wpinv_is_test_mode( 'paypal' ) ) { |
|
813 | + public function sandbox_notice($description, $gateway) { |
|
814 | + if ('paypal' == $gateway && wpinv_is_test_mode('paypal')) { |
|
815 | 815 | $description .= '<br> <br>' . sprintf( |
816 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
816 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
817 | 817 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
818 | 818 | '</a>' |
819 | 819 | ); |
@@ -12,443 +12,443 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
52 | - |
|
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
129 | - return array( |
|
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | - ); |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Helper function to send an email. |
|
154 | - * |
|
155 | - * @param WPInv_Invoice $invoice |
|
156 | - * @param GetPaid_Notification_Email $email |
|
157 | - * @param string $type |
|
158 | - * @param string|array $recipients |
|
159 | - * @param array $extra_args Extra template args. |
|
160 | - */ |
|
161 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
162 | - |
|
163 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
164 | - |
|
165 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
166 | - $merge_tags = $email->get_merge_tags(); |
|
167 | - |
|
168 | - $result = $mailer->send( |
|
169 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
170 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
171 | - $email->get_content( $merge_tags, $extra_args ), |
|
172 | - $email->get_attachments() |
|
173 | - ); |
|
174 | - |
|
175 | - // Maybe send a copy to the admin. |
|
176 | - if ( $email->include_admin_bcc() ) { |
|
177 | - $mailer->send( |
|
178 | - wpinv_get_admin_email(), |
|
179 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
180 | - $email->get_content( $merge_tags ), |
|
181 | - $email->get_attachments() |
|
182 | - ); |
|
183 | - } |
|
184 | - |
|
185 | - if ( ! $result ) { |
|
186 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
187 | - } |
|
188 | - |
|
189 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
190 | - |
|
191 | - return $result; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Also send emails to any cc users. |
|
196 | - * |
|
197 | - * @param array $recipients |
|
198 | - * @param GetPaid_Notification_Email $email |
|
199 | - */ |
|
200 | - public function filter_email_recipients( $recipients, $email ) { |
|
201 | - |
|
202 | - if ( ! $email->is_admin_email() ) { |
|
203 | - $cc = $email->object->get_email_cc(); |
|
204 | - |
|
205 | - if ( ! empty( $cc ) ) { |
|
206 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
207 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
208 | - } |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - return $recipients; |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Sends a new invoice notification. |
|
218 | - * |
|
219 | - * @param WPInv_Invoice $invoice |
|
220 | - */ |
|
221 | - public function new_invoice( $invoice ) { |
|
222 | - |
|
223 | - // Only send this email for invoices created via the admin page. |
|
224 | - if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
225 | - return; |
|
226 | - } |
|
227 | - |
|
228 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
229 | - $recipient = wpinv_get_admin_email(); |
|
230 | - |
|
231 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
232 | - |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Sends a cancelled invoice notification. |
|
237 | - * |
|
238 | - * @param WPInv_Invoice $invoice |
|
239 | - */ |
|
240 | - public function cancelled_invoice( $invoice ) { |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
52 | + |
|
53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
129 | + return array( |
|
130 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | + '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
138 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | + '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | + '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
145 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | + ); |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Helper function to send an email. |
|
154 | + * |
|
155 | + * @param WPInv_Invoice $invoice |
|
156 | + * @param GetPaid_Notification_Email $email |
|
157 | + * @param string $type |
|
158 | + * @param string|array $recipients |
|
159 | + * @param array $extra_args Extra template args. |
|
160 | + */ |
|
161 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
162 | + |
|
163 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
164 | + |
|
165 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
166 | + $merge_tags = $email->get_merge_tags(); |
|
167 | + |
|
168 | + $result = $mailer->send( |
|
169 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
170 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
171 | + $email->get_content( $merge_tags, $extra_args ), |
|
172 | + $email->get_attachments() |
|
173 | + ); |
|
174 | + |
|
175 | + // Maybe send a copy to the admin. |
|
176 | + if ( $email->include_admin_bcc() ) { |
|
177 | + $mailer->send( |
|
178 | + wpinv_get_admin_email(), |
|
179 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
180 | + $email->get_content( $merge_tags ), |
|
181 | + $email->get_attachments() |
|
182 | + ); |
|
183 | + } |
|
184 | + |
|
185 | + if ( ! $result ) { |
|
186 | + $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
187 | + } |
|
188 | + |
|
189 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
190 | + |
|
191 | + return $result; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Also send emails to any cc users. |
|
196 | + * |
|
197 | + * @param array $recipients |
|
198 | + * @param GetPaid_Notification_Email $email |
|
199 | + */ |
|
200 | + public function filter_email_recipients( $recipients, $email ) { |
|
201 | + |
|
202 | + if ( ! $email->is_admin_email() ) { |
|
203 | + $cc = $email->object->get_email_cc(); |
|
204 | + |
|
205 | + if ( ! empty( $cc ) ) { |
|
206 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
207 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
208 | + } |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + return $recipients; |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Sends a new invoice notification. |
|
218 | + * |
|
219 | + * @param WPInv_Invoice $invoice |
|
220 | + */ |
|
221 | + public function new_invoice( $invoice ) { |
|
222 | + |
|
223 | + // Only send this email for invoices created via the admin page. |
|
224 | + if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | + |
|
228 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
229 | + $recipient = wpinv_get_admin_email(); |
|
230 | + |
|
231 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
232 | + |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Sends a cancelled invoice notification. |
|
237 | + * |
|
238 | + * @param WPInv_Invoice $invoice |
|
239 | + */ |
|
240 | + public function cancelled_invoice( $invoice ) { |
|
241 | 241 | |
242 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
243 | - $recipient = wpinv_get_admin_email(); |
|
242 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
243 | + $recipient = wpinv_get_admin_email(); |
|
244 | 244 | |
245 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
245 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Sends a failed invoice notification. |
|
251 | - * |
|
252 | - * @param WPInv_Invoice $invoice |
|
253 | - */ |
|
254 | - public function failed_invoice( $invoice ) { |
|
249 | + /** |
|
250 | + * Sends a failed invoice notification. |
|
251 | + * |
|
252 | + * @param WPInv_Invoice $invoice |
|
253 | + */ |
|
254 | + public function failed_invoice( $invoice ) { |
|
255 | 255 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
257 | - $recipient = wpinv_get_admin_email(); |
|
256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
257 | + $recipient = wpinv_get_admin_email(); |
|
258 | 258 | |
259 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
259 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
260 | 260 | |
261 | - } |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * Sends a notification whenever an invoice is put on hold. |
|
265 | - * |
|
266 | - * @param WPInv_Invoice $invoice |
|
267 | - */ |
|
268 | - public function onhold_invoice( $invoice ) { |
|
263 | + /** |
|
264 | + * Sends a notification whenever an invoice is put on hold. |
|
265 | + * |
|
266 | + * @param WPInv_Invoice $invoice |
|
267 | + */ |
|
268 | + public function onhold_invoice( $invoice ) { |
|
269 | 269 | |
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | - $recipient = $invoice->get_email(); |
|
270 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $recipient = $invoice->get_email(); |
|
272 | 272 | |
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
273 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | 274 | |
275 | - } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
279 | - * |
|
280 | - * @param WPInv_Invoice $invoice |
|
281 | - */ |
|
282 | - public function processing_invoice( $invoice ) { |
|
277 | + /** |
|
278 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
279 | + * |
|
280 | + * @param WPInv_Invoice $invoice |
|
281 | + */ |
|
282 | + public function processing_invoice( $invoice ) { |
|
283 | 283 | |
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | - $recipient = $invoice->get_email(); |
|
284 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $recipient = $invoice->get_email(); |
|
286 | 286 | |
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
287 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | 288 | |
289 | - } |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Sends a notification whenever an invoice is paid. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice |
|
295 | - */ |
|
296 | - public function completed_invoice( $invoice ) { |
|
291 | + /** |
|
292 | + * Sends a notification whenever an invoice is paid. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice |
|
295 | + */ |
|
296 | + public function completed_invoice( $invoice ) { |
|
297 | 297 | |
298 | - // (Maybe) abort if it is a renewal invoice. |
|
299 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
300 | - return; |
|
301 | - } |
|
298 | + // (Maybe) abort if it is a renewal invoice. |
|
299 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
300 | + return; |
|
301 | + } |
|
302 | 302 | |
303 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
304 | - $recipient = $invoice->get_email(); |
|
303 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
304 | + $recipient = $invoice->get_email(); |
|
305 | 305 | |
306 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
306 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
307 | 307 | |
308 | - } |
|
308 | + } |
|
309 | 309 | |
310 | - /** |
|
311 | - * Sends a notification whenever an invoice is refunded. |
|
312 | - * |
|
313 | - * @param WPInv_Invoice $invoice |
|
314 | - */ |
|
315 | - public function refunded_invoice( $invoice ) { |
|
310 | + /** |
|
311 | + * Sends a notification whenever an invoice is refunded. |
|
312 | + * |
|
313 | + * @param WPInv_Invoice $invoice |
|
314 | + */ |
|
315 | + public function refunded_invoice( $invoice ) { |
|
316 | 316 | |
317 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
318 | - $recipient = $invoice->get_email(); |
|
317 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
318 | + $recipient = $invoice->get_email(); |
|
319 | 319 | |
320 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
320 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
321 | 321 | |
322 | - } |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * Notifies a user about new invoices |
|
326 | - * |
|
327 | - * @param WPInv_Invoice $invoice |
|
328 | - */ |
|
329 | - public function user_invoice( $invoice ) { |
|
324 | + /** |
|
325 | + * Notifies a user about new invoices |
|
326 | + * |
|
327 | + * @param WPInv_Invoice $invoice |
|
328 | + */ |
|
329 | + public function user_invoice( $invoice ) { |
|
330 | 330 | |
331 | - // Only send this email for invoices created via the admin page. |
|
332 | - if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
333 | - return; |
|
334 | - } |
|
331 | + // Only send this email for invoices created via the admin page. |
|
332 | + if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
333 | + return; |
|
334 | + } |
|
335 | 335 | |
336 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
337 | - $recipient = $invoice->get_email(); |
|
336 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
337 | + $recipient = $invoice->get_email(); |
|
338 | 338 | |
339 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
339 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
340 | 340 | |
341 | - } |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * Checks if an invoice is a payment form invoice. |
|
345 | - * |
|
346 | - * @param int $invoice |
|
347 | - * @return bool |
|
348 | - */ |
|
349 | - public function is_payment_form_invoice( $invoice ) { |
|
350 | - return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
351 | - } |
|
343 | + /** |
|
344 | + * Checks if an invoice is a payment form invoice. |
|
345 | + * |
|
346 | + * @param int $invoice |
|
347 | + * @return bool |
|
348 | + */ |
|
349 | + public function is_payment_form_invoice( $invoice ) { |
|
350 | + return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Notifies admin about new invoice notes |
|
355 | - * |
|
356 | - * @param WPInv_Invoice $invoice |
|
357 | - * @param string $note |
|
358 | - */ |
|
359 | - public function user_note( $invoice, $note ) { |
|
353 | + /** |
|
354 | + * Notifies admin about new invoice notes |
|
355 | + * |
|
356 | + * @param WPInv_Invoice $invoice |
|
357 | + * @param string $note |
|
358 | + */ |
|
359 | + public function user_note( $invoice, $note ) { |
|
360 | 360 | |
361 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
362 | - $recipient = $invoice->get_email(); |
|
363 | - |
|
364 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
365 | - |
|
366 | - } |
|
361 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
362 | + $recipient = $invoice->get_email(); |
|
363 | + |
|
364 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
365 | + |
|
366 | + } |
|
367 | 367 | |
368 | - /** |
|
369 | - * (Force) Sends overdue notices. |
|
370 | - * |
|
371 | - * @param WPInv_Invoice $invoice |
|
372 | - */ |
|
373 | - public function force_send_overdue_notice( $invoice ) { |
|
374 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
375 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Sends overdue notices. |
|
380 | - * |
|
381 | - * @TODO: Create an invoices query class. |
|
382 | - */ |
|
383 | - public function overdue() { |
|
384 | - global $wpdb; |
|
385 | - |
|
386 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
387 | - |
|
388 | - // Fetch reminder days. |
|
389 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
390 | - |
|
391 | - // Abort if non is set. |
|
392 | - if ( empty( $reminder_days ) ) { |
|
393 | - return; |
|
394 | - } |
|
395 | - |
|
396 | - // Retrieve date query. |
|
397 | - $date_query = $this->get_date_query( $reminder_days ); |
|
398 | - |
|
399 | - // Invoices table. |
|
400 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
401 | - |
|
402 | - // Fetch invoices. |
|
403 | - $invoices = $wpdb->get_col( |
|
404 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
368 | + /** |
|
369 | + * (Force) Sends overdue notices. |
|
370 | + * |
|
371 | + * @param WPInv_Invoice $invoice |
|
372 | + */ |
|
373 | + public function force_send_overdue_notice( $invoice ) { |
|
374 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
375 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Sends overdue notices. |
|
380 | + * |
|
381 | + * @TODO: Create an invoices query class. |
|
382 | + */ |
|
383 | + public function overdue() { |
|
384 | + global $wpdb; |
|
385 | + |
|
386 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
387 | + |
|
388 | + // Fetch reminder days. |
|
389 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
390 | + |
|
391 | + // Abort if non is set. |
|
392 | + if ( empty( $reminder_days ) ) { |
|
393 | + return; |
|
394 | + } |
|
395 | + |
|
396 | + // Retrieve date query. |
|
397 | + $date_query = $this->get_date_query( $reminder_days ); |
|
398 | + |
|
399 | + // Invoices table. |
|
400 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
401 | + |
|
402 | + // Fetch invoices. |
|
403 | + $invoices = $wpdb->get_col( |
|
404 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
405 | 405 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
406 | 406 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
407 | 407 | |
408 | - foreach ( $invoices as $invoice ) { |
|
408 | + foreach ( $invoices as $invoice ) { |
|
409 | 409 | |
410 | - // Only send this email for invoices created via the admin page. |
|
411 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
412 | - $invoice = new WPInv_Invoice( $invoice ); |
|
413 | - $email->object = $invoice; |
|
410 | + // Only send this email for invoices created via the admin page. |
|
411 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
412 | + $invoice = new WPInv_Invoice( $invoice ); |
|
413 | + $email->object = $invoice; |
|
414 | 414 | |
415 | - if ( $invoice->needs_payment() ) { |
|
416 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
417 | - } |
|
415 | + if ( $invoice->needs_payment() ) { |
|
416 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
417 | + } |
|
418 | 418 | |
419 | - } |
|
419 | + } |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Calculates the date query for an invoices query |
|
427 | - * |
|
428 | - * @param array $reminder_days |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public function get_date_query( $reminder_days ) { |
|
425 | + /** |
|
426 | + * Calculates the date query for an invoices query |
|
427 | + * |
|
428 | + * @param array $reminder_days |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public function get_date_query( $reminder_days ) { |
|
432 | 432 | |
433 | - $date_query = array( |
|
434 | - 'relation' => 'OR' |
|
435 | - ); |
|
433 | + $date_query = array( |
|
434 | + 'relation' => 'OR' |
|
435 | + ); |
|
436 | 436 | |
437 | - foreach ( $reminder_days as $days ) { |
|
438 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
437 | + foreach ( $reminder_days as $days ) { |
|
438 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
439 | 439 | |
440 | - $date_query[] = array( |
|
441 | - 'year' => $date['year'], |
|
442 | - 'month' => $date['month'], |
|
443 | - 'day' => $date['day'], |
|
444 | - ); |
|
440 | + $date_query[] = array( |
|
441 | + 'year' => $date['year'], |
|
442 | + 'month' => $date['month'], |
|
443 | + 'day' => $date['day'], |
|
444 | + ); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
448 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
449 | 449 | |
450 | - return $date_query->get_sql(); |
|
450 | + return $date_query->get_sql(); |
|
451 | 451 | |
452 | - } |
|
452 | + } |
|
453 | 453 | |
454 | 454 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class handles invoice notificaiton emails. |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $this->invoice_actions = apply_filters( |
29 | 29 | 'getpaid_notification_email_invoice_triggers', |
30 | 30 | array( |
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
31 | + 'getpaid_new_invoice' => array('new_invoice', 'user_invoice'), |
|
32 | 32 | 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
33 | 33 | 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
34 | 34 | 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function init_hooks() { |
52 | 52 | |
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
53 | + add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2); |
|
54 | + add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2); |
|
55 | 55 | |
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
56 | + foreach ($this->invoice_actions as $hook => $email_type) { |
|
57 | + $this->init_email_type_hook($hook, $email_type); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -64,25 +64,25 @@ discard block |
||
64 | 64 | * @param string $hook |
65 | 65 | * @param string|array $email_type |
66 | 66 | */ |
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
67 | + public function init_email_type_hook($hook, $email_type) { |
|
68 | 68 | |
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
69 | + $email_type = wpinv_parse_list($email_type); |
|
70 | 70 | |
71 | - foreach ( $email_type as $type ) { |
|
71 | + foreach ($email_type as $type) { |
|
72 | 72 | |
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
73 | + $email = new GetPaid_Notification_Email($type); |
|
74 | 74 | |
75 | 75 | // Abort if it is not active. |
76 | - if ( ! $email->is_active() ) { |
|
76 | + if (!$email->is_active()) { |
|
77 | 77 | continue; |
78 | 78 | } |
79 | 79 | |
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
80 | + if (method_exists($this, $type)) { |
|
81 | + add_action($hook, array($this, $type), 100, 2); |
|
82 | 82 | continue; |
83 | 83 | } |
84 | 84 | |
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type ); |
|
85 | + do_action('getpaid_invoice_init_email_type_hook', $type); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | } |
@@ -93,19 +93,19 @@ discard block |
||
93 | 93 | * @param array $merge_tags |
94 | 94 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
95 | 95 | */ |
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | + public function invoice_merge_tags($merge_tags, $object) { |
|
97 | 97 | |
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | + if (is_a($object, 'WPInv_Invoice')) { |
|
99 | 99 | return array_merge( |
100 | 100 | $merge_tags, |
101 | - $this->get_invoice_merge_tags( $object ) |
|
101 | + $this->get_invoice_merge_tags($object) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | + if (is_a($object, 'WPInv_Subscription')) { |
|
106 | 106 | return array_merge( |
107 | 107 | $merge_tags, |
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | + $this->get_invoice_merge_tags($object->get_parent_payment()) |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
@@ -119,32 +119,32 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return array |
121 | 121 | */ |
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
122 | + public function get_invoice_merge_tags($invoice) { |
|
123 | 123 | |
124 | 124 | // Abort if it does not exist. |
125 | - if ( ! $invoice->get_id() ) { |
|
125 | + if (!$invoice->get_id()) { |
|
126 | 126 | return array(); |
127 | 127 | } |
128 | 128 | |
129 | 129 | return array( |
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
130 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
131 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
132 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
133 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
134 | + '{email}' => sanitize_email($invoice->get_email()), |
|
135 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
136 | + '{invoice_currency}' => sanitize_text_field($invoice->get_currency()), |
|
137 | + '{invoice_total}' => wpinv_price(wpinv_format_amount($invoice->get_total())), |
|
138 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
139 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
140 | + '{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()), |
|
141 | + '{invoice_date}' => getpaid_format_date_value($invoice->get_date_created()), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')), |
|
143 | + '{invoice_quote}' => sanitize_text_field($invoice->get_type()), |
|
144 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_type())), |
|
145 | + '{invoice_description}' => wp_kses_post($invoice->get_description()), |
|
146 | + '{subscription_name}' => wp_kses_post($invoice->get_subscription_name()), |
|
147 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | |
150 | 150 | } |
@@ -158,35 +158,35 @@ discard block |
||
158 | 158 | * @param string|array $recipients |
159 | 159 | * @param array $extra_args Extra template args. |
160 | 160 | */ |
161 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
161 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
162 | 162 | |
163 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
163 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
164 | 164 | |
165 | 165 | $mailer = new GetPaid_Notification_Email_Sender(); |
166 | 166 | $merge_tags = $email->get_merge_tags(); |
167 | 167 | |
168 | 168 | $result = $mailer->send( |
169 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
170 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
171 | - $email->get_content( $merge_tags, $extra_args ), |
|
169 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
170 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
171 | + $email->get_content($merge_tags, $extra_args), |
|
172 | 172 | $email->get_attachments() |
173 | 173 | ); |
174 | 174 | |
175 | 175 | // Maybe send a copy to the admin. |
176 | - if ( $email->include_admin_bcc() ) { |
|
176 | + if ($email->include_admin_bcc()) { |
|
177 | 177 | $mailer->send( |
178 | 178 | wpinv_get_admin_email(), |
179 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
180 | - $email->get_content( $merge_tags ), |
|
179 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
180 | + $email->get_content($merge_tags), |
|
181 | 181 | $email->get_attachments() |
182 | 182 | ); |
183 | 183 | } |
184 | 184 | |
185 | - if ( ! $result ) { |
|
186 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
185 | + if (!$result) { |
|
186 | + $invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true); |
|
187 | 187 | } |
188 | 188 | |
189 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
189 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
190 | 190 | |
191 | 191 | return $result; |
192 | 192 | } |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | * @param array $recipients |
198 | 198 | * @param GetPaid_Notification_Email $email |
199 | 199 | */ |
200 | - public function filter_email_recipients( $recipients, $email ) { |
|
200 | + public function filter_email_recipients($recipients, $email) { |
|
201 | 201 | |
202 | - if ( ! $email->is_admin_email() ) { |
|
202 | + if (!$email->is_admin_email()) { |
|
203 | 203 | $cc = $email->object->get_email_cc(); |
204 | 204 | |
205 | - if ( ! empty( $cc ) ) { |
|
206 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
207 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
205 | + if (!empty($cc)) { |
|
206 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
207 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | } |
@@ -218,17 +218,17 @@ discard block |
||
218 | 218 | * |
219 | 219 | * @param WPInv_Invoice $invoice |
220 | 220 | */ |
221 | - public function new_invoice( $invoice ) { |
|
221 | + public function new_invoice($invoice) { |
|
222 | 222 | |
223 | 223 | // Only send this email for invoices created via the admin page. |
224 | - if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
224 | + if ($this->is_payment_form_invoice($invoice->get_id())) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
228 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
229 | 229 | $recipient = wpinv_get_admin_email(); |
230 | 230 | |
231 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
231 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
232 | 232 | |
233 | 233 | } |
234 | 234 | |
@@ -237,12 +237,12 @@ discard block |
||
237 | 237 | * |
238 | 238 | * @param WPInv_Invoice $invoice |
239 | 239 | */ |
240 | - public function cancelled_invoice( $invoice ) { |
|
240 | + public function cancelled_invoice($invoice) { |
|
241 | 241 | |
242 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
242 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
243 | 243 | $recipient = wpinv_get_admin_email(); |
244 | 244 | |
245 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
245 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
246 | 246 | |
247 | 247 | } |
248 | 248 | |
@@ -251,12 +251,12 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param WPInv_Invoice $invoice |
253 | 253 | */ |
254 | - public function failed_invoice( $invoice ) { |
|
254 | + public function failed_invoice($invoice) { |
|
255 | 255 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
256 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
257 | 257 | $recipient = wpinv_get_admin_email(); |
258 | 258 | |
259 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
259 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
260 | 260 | |
261 | 261 | } |
262 | 262 | |
@@ -265,12 +265,12 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @param WPInv_Invoice $invoice |
267 | 267 | */ |
268 | - public function onhold_invoice( $invoice ) { |
|
268 | + public function onhold_invoice($invoice) { |
|
269 | 269 | |
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
270 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
271 | 271 | $recipient = $invoice->get_email(); |
272 | 272 | |
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
273 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
274 | 274 | |
275 | 275 | } |
276 | 276 | |
@@ -279,12 +279,12 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @param WPInv_Invoice $invoice |
281 | 281 | */ |
282 | - public function processing_invoice( $invoice ) { |
|
282 | + public function processing_invoice($invoice) { |
|
283 | 283 | |
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
284 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
285 | 285 | $recipient = $invoice->get_email(); |
286 | 286 | |
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
287 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
288 | 288 | |
289 | 289 | } |
290 | 290 | |
@@ -293,17 +293,17 @@ discard block |
||
293 | 293 | * |
294 | 294 | * @param WPInv_Invoice $invoice |
295 | 295 | */ |
296 | - public function completed_invoice( $invoice ) { |
|
296 | + public function completed_invoice($invoice) { |
|
297 | 297 | |
298 | 298 | // (Maybe) abort if it is a renewal invoice. |
299 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
299 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
300 | 300 | return; |
301 | 301 | } |
302 | 302 | |
303 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
303 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
304 | 304 | $recipient = $invoice->get_email(); |
305 | 305 | |
306 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
306 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
307 | 307 | |
308 | 308 | } |
309 | 309 | |
@@ -312,12 +312,12 @@ discard block |
||
312 | 312 | * |
313 | 313 | * @param WPInv_Invoice $invoice |
314 | 314 | */ |
315 | - public function refunded_invoice( $invoice ) { |
|
315 | + public function refunded_invoice($invoice) { |
|
316 | 316 | |
317 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
317 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
318 | 318 | $recipient = $invoice->get_email(); |
319 | 319 | |
320 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
320 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
321 | 321 | |
322 | 322 | } |
323 | 323 | |
@@ -326,17 +326,17 @@ discard block |
||
326 | 326 | * |
327 | 327 | * @param WPInv_Invoice $invoice |
328 | 328 | */ |
329 | - public function user_invoice( $invoice ) { |
|
329 | + public function user_invoice($invoice) { |
|
330 | 330 | |
331 | 331 | // Only send this email for invoices created via the admin page. |
332 | - if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
332 | + if ($this->is_payment_form_invoice($invoice->get_id())) { |
|
333 | 333 | return; |
334 | 334 | } |
335 | 335 | |
336 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
336 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
337 | 337 | $recipient = $invoice->get_email(); |
338 | 338 | |
339 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
339 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
340 | 340 | |
341 | 341 | } |
342 | 342 | |
@@ -346,8 +346,8 @@ discard block |
||
346 | 346 | * @param int $invoice |
347 | 347 | * @return bool |
348 | 348 | */ |
349 | - public function is_payment_form_invoice( $invoice ) { |
|
350 | - return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
349 | + public function is_payment_form_invoice($invoice) { |
|
350 | + return empty($_GET['getpaid-admin-action']) && 'payment_form' == get_post_meta($invoice, 'wpinv_created_via', true); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | /** |
@@ -356,12 +356,12 @@ discard block |
||
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | * @param string $note |
358 | 358 | */ |
359 | - public function user_note( $invoice, $note ) { |
|
359 | + public function user_note($invoice, $note) { |
|
360 | 360 | |
361 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
362 | 362 | $recipient = $invoice->get_email(); |
363 | 363 | |
364 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
364 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
365 | 365 | |
366 | 366 | } |
367 | 367 | |
@@ -370,9 +370,9 @@ discard block |
||
370 | 370 | * |
371 | 371 | * @param WPInv_Invoice $invoice |
372 | 372 | */ |
373 | - public function force_send_overdue_notice( $invoice ) { |
|
374 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
375 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
373 | + public function force_send_overdue_notice($invoice) { |
|
374 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
375 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
@@ -383,37 +383,37 @@ discard block |
||
383 | 383 | public function overdue() { |
384 | 384 | global $wpdb; |
385 | 385 | |
386 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
386 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
387 | 387 | |
388 | 388 | // Fetch reminder days. |
389 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
389 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
390 | 390 | |
391 | 391 | // Abort if non is set. |
392 | - if ( empty( $reminder_days ) ) { |
|
392 | + if (empty($reminder_days)) { |
|
393 | 393 | return; |
394 | 394 | } |
395 | 395 | |
396 | 396 | // Retrieve date query. |
397 | - $date_query = $this->get_date_query( $reminder_days ); |
|
397 | + $date_query = $this->get_date_query($reminder_days); |
|
398 | 398 | |
399 | 399 | // Invoices table. |
400 | 400 | $table = $wpdb->prefix . 'getpaid_invoices'; |
401 | 401 | |
402 | 402 | // Fetch invoices. |
403 | - $invoices = $wpdb->get_col( |
|
403 | + $invoices = $wpdb->get_col( |
|
404 | 404 | "SELECT posts.ID FROM $wpdb->posts as posts |
405 | 405 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
406 | 406 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
407 | 407 | |
408 | - foreach ( $invoices as $invoice ) { |
|
408 | + foreach ($invoices as $invoice) { |
|
409 | 409 | |
410 | 410 | // Only send this email for invoices created via the admin page. |
411 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
412 | - $invoice = new WPInv_Invoice( $invoice ); |
|
411 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
412 | + $invoice = new WPInv_Invoice($invoice); |
|
413 | 413 | $email->object = $invoice; |
414 | 414 | |
415 | - if ( $invoice->needs_payment() ) { |
|
416 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
415 | + if ($invoice->needs_payment()) { |
|
416 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | } |
@@ -428,14 +428,14 @@ discard block |
||
428 | 428 | * @param array $reminder_days |
429 | 429 | * @return string |
430 | 430 | */ |
431 | - public function get_date_query( $reminder_days ) { |
|
431 | + public function get_date_query($reminder_days) { |
|
432 | 432 | |
433 | 433 | $date_query = array( |
434 | 434 | 'relation' => 'OR' |
435 | 435 | ); |
436 | 436 | |
437 | - foreach ( $reminder_days as $days ) { |
|
438 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
437 | + foreach ($reminder_days as $days) { |
|
438 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
439 | 439 | |
440 | 440 | $date_query[] = array( |
441 | 441 | 'year' => $date['year'], |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | |
446 | 446 | } |
447 | 447 | |
448 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
448 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
449 | 449 | |
450 | 450 | return $date_query->get_sql(); |
451 | 451 |
@@ -13,17 +13,17 @@ discard block |
||
13 | 13 | class GetPaid_Notification_Email_Sender { |
14 | 14 | |
15 | 15 | /** |
16 | - * Whether or not we should inline CSS into the email. |
|
17 | - */ |
|
18 | - public $inline_css = true; |
|
16 | + * Whether or not we should inline CSS into the email. |
|
17 | + */ |
|
18 | + public $inline_css = true; |
|
19 | 19 | |
20 | 20 | /** |
21 | - * The wp_mail() data. |
|
22 | - */ |
|
21 | + * The wp_mail() data. |
|
22 | + */ |
|
23 | 23 | public $wp_mail_data = null; |
24 | 24 | |
25 | 25 | /** |
26 | - * Sends a new email. |
|
26 | + * Sends a new email. |
|
27 | 27 | * |
28 | 28 | * @param string|array $to The recipients email or an array of recipient emails. |
29 | 29 | * @param string $subject The email's subject. |
@@ -31,49 +31,49 @@ discard block |
||
31 | 31 | * @param array $attachments The email attachments. |
32 | 32 | * |
33 | 33 | * @return bool |
34 | - */ |
|
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
34 | + */ |
|
35 | + public function send( $to, $subject, $email, $attachments = array() ) { |
|
36 | 36 | |
37 | - /* |
|
37 | + /* |
|
38 | 38 | * Allow to filter data on per-email basis. |
39 | 39 | */ |
40 | - $data = apply_filters( |
|
41 | - 'getpaid_email_data', |
|
42 | - array( |
|
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ), |
|
45 | - 'email' => $email, |
|
46 | - 'headers' => $this->get_headers(), |
|
47 | - 'attachments' => $attachments, |
|
48 | - ), |
|
49 | - $this |
|
50 | - ); |
|
40 | + $data = apply_filters( |
|
41 | + 'getpaid_email_data', |
|
42 | + array( |
|
43 | + 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | + 'subject' => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ), |
|
45 | + 'email' => $email, |
|
46 | + 'headers' => $this->get_headers(), |
|
47 | + 'attachments' => $attachments, |
|
48 | + ), |
|
49 | + $this |
|
50 | + ); |
|
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | 53 | $data = (array) wp_unslash( $data ); |
54 | 54 | |
55 | 55 | // Cache it. |
56 | - $this->wp_mail_data = $data; |
|
56 | + $this->wp_mail_data = $data; |
|
57 | 57 | |
58 | - // Attach our own hooks. |
|
59 | - $this->before_sending(); |
|
58 | + // Attach our own hooks. |
|
59 | + $this->before_sending(); |
|
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | 63 | foreach ( $this->wp_mail_data['to'] as $to ) { |
64 | - $result = $this->_send( $to, $data ); |
|
64 | + $result = $this->_send( $to, $data ); |
|
65 | 65 | } |
66 | 66 | |
67 | - // Remove our hooks. |
|
68 | - $this->after_sending(); |
|
67 | + // Remove our hooks. |
|
68 | + $this->after_sending(); |
|
69 | 69 | |
70 | - $this->wp_mail_data = null; |
|
70 | + $this->wp_mail_data = null; |
|
71 | 71 | |
72 | - return $result; |
|
73 | - } |
|
72 | + return $result; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Does the actual sending. |
|
75 | + /** |
|
76 | + * Does the actual sending. |
|
77 | 77 | * |
78 | 78 | * @param string $to The recipient's email. |
79 | 79 | * @param array $data The email's data. |
@@ -81,81 +81,81 @@ discard block |
||
81 | 81 | * @param array $attachments The email attachments. |
82 | 82 | * |
83 | 83 | * @return bool |
84 | - */ |
|
85 | - protected function _send( $to, $data ) { |
|
86 | - |
|
87 | - // Prepare the sending function. |
|
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | - |
|
90 | - // Send the actual email. |
|
91 | - $result = call_user_func( |
|
92 | - $sending_function, |
|
93 | - $to, |
|
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | - $data['email'], |
|
96 | - $data['headers'], |
|
97 | - $data['attachments'] |
|
98 | - ); |
|
99 | - |
|
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | - } |
|
104 | - |
|
105 | - return $result; |
|
106 | - } |
|
84 | + */ |
|
85 | + protected function _send( $to, $data ) { |
|
86 | + |
|
87 | + // Prepare the sending function. |
|
88 | + $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
89 | + |
|
90 | + // Send the actual email. |
|
91 | + $result = call_user_func( |
|
92 | + $sending_function, |
|
93 | + $to, |
|
94 | + html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
95 | + $data['email'], |
|
96 | + $data['headers'], |
|
97 | + $data['attachments'] |
|
98 | + ); |
|
99 | + |
|
100 | + if ( ! $result ) { |
|
101 | + $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | + wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
103 | + } |
|
104 | + |
|
105 | + return $result; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | /** |
109 | - * Retrieves email headers. |
|
110 | - */ |
|
111 | - public function get_headers() { |
|
109 | + * Retrieves email headers. |
|
110 | + */ |
|
111 | + public function get_headers() { |
|
112 | 112 | |
113 | - $name = $this->get_from_name(); |
|
114 | - $reply_to = $this->get_reply_to(); |
|
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
113 | + $name = $this->get_from_name(); |
|
114 | + $reply_to = $this->get_reply_to(); |
|
115 | + $headers = array( "Reply-To:$name <$reply_to>" ); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
118 | 118 | |
119 | - } |
|
119 | + } |
|
120 | 120 | |
121 | 121 | /** |
122 | - * Fires before an email is sent |
|
123 | - * |
|
124 | - * @since 1.0.0 |
|
125 | - */ |
|
126 | - public function before_sending() { |
|
122 | + * Fires before an email is sent |
|
123 | + * |
|
124 | + * @since 1.0.0 |
|
125 | + */ |
|
126 | + public function before_sending() { |
|
127 | 127 | |
128 | 128 | do_action( 'getpaid_before_send_email', $this ); |
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
129 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | + add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | + add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
133 | 133 | |
134 | - } |
|
134 | + } |
|
135 | 135 | |
136 | 136 | /** |
137 | - * Returns the from name. |
|
138 | - */ |
|
139 | - public function get_from_name() { |
|
137 | + * Returns the from name. |
|
138 | + */ |
|
139 | + public function get_from_name() { |
|
140 | 140 | |
141 | 141 | $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if ( empty( $from_name ) ) { |
|
144 | + $from_name = get_bloginfo( 'name' ); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | - * Returns the from email. |
|
152 | - */ |
|
153 | - public function get_from_address() { |
|
151 | + * Returns the from email. |
|
152 | + */ |
|
153 | + public function get_from_address() { |
|
154 | 154 | |
155 | 155 | $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
158 | - $from_address = $this->default_from_address(); |
|
157 | + if ( ! is_email( $from_address ) ) { |
|
158 | + $from_address = $this->default_from_address(); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return $from_address; |
@@ -163,75 +163,75 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | - * The default emails from address. |
|
167 | - * |
|
168 | - * Defaults to wordpress@$sitename |
|
169 | - * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | - * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | - * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | - * |
|
173 | - */ |
|
174 | - public function default_from_address() { |
|
175 | - |
|
176 | - // Get the site domain and get rid of www. |
|
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
180 | - } |
|
181 | - |
|
182 | - $from_email = 'wordpress@' . $sitename; |
|
183 | - |
|
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
166 | + * The default emails from address. |
|
167 | + * |
|
168 | + * Defaults to wordpress@$sitename |
|
169 | + * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
170 | + * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
171 | + * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
172 | + * |
|
173 | + */ |
|
174 | + public function default_from_address() { |
|
175 | + |
|
176 | + // Get the site domain and get rid of www. |
|
177 | + $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | + if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | + $sitename = substr( $sitename, 4 ); |
|
180 | + } |
|
181 | + |
|
182 | + $from_email = 'wordpress@' . $sitename; |
|
183 | + |
|
184 | + return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | - * Get the email reply-to. |
|
190 | - * |
|
191 | - * |
|
192 | - * @return string The email reply-to address. |
|
193 | - */ |
|
194 | - public function get_reply_to() { |
|
189 | + * Get the email reply-to. |
|
190 | + * |
|
191 | + * |
|
192 | + * @return string The email reply-to address. |
|
193 | + */ |
|
194 | + public function get_reply_to() { |
|
195 | 195 | |
196 | - $reply_to = wpinv_get_admin_email(); |
|
196 | + $reply_to = wpinv_get_admin_email(); |
|
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
200 | - } |
|
198 | + if ( ! is_email( $reply_to ) ) { |
|
199 | + $reply_to = get_option( 'admin_email' ); |
|
200 | + } |
|
201 | 201 | |
202 | - return $reply_to; |
|
202 | + return $reply_to; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | - * Get the email content type. |
|
207 | - * |
|
208 | - */ |
|
209 | - public function get_content_type() { |
|
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
206 | + * Get the email content type. |
|
207 | + * |
|
208 | + */ |
|
209 | + public function get_content_type() { |
|
210 | + return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
214 | - * Ensures that our email messages are not messed up by template plugins. |
|
215 | - * |
|
216 | - * @return array wp_mail_data. |
|
217 | - */ |
|
218 | - public function ensure_email_content( $args ) { |
|
219 | - $args['message'] = $this->wp_mail_data['email']; |
|
220 | - return $args; |
|
214 | + * Ensures that our email messages are not messed up by template plugins. |
|
215 | + * |
|
216 | + * @return array wp_mail_data. |
|
217 | + */ |
|
218 | + public function ensure_email_content( $args ) { |
|
219 | + $args['message'] = $this->wp_mail_data['email']; |
|
220 | + return $args; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | /** |
224 | - * A little house keeping after an email is sent. |
|
225 | - * |
|
226 | - */ |
|
227 | - public function after_sending() { |
|
224 | + * A little house keeping after an email is sent. |
|
225 | + * |
|
226 | + */ |
|
227 | + public function after_sending() { |
|
228 | 228 | |
229 | 229 | do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
230 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | + remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | + remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
234 | 234 | |
235 | - } |
|
235 | + } |
|
236 | 236 | |
237 | 237 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This function is responsible for sending emails. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return bool |
34 | 34 | */ |
35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
35 | + public function send($to, $subject, $email, $attachments = array()) { |
|
36 | 36 | |
37 | 37 | /* |
38 | 38 | * Allow to filter data on per-email basis. |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | $data = apply_filters( |
41 | 41 | 'getpaid_email_data', |
42 | 42 | array( |
43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
44 | - 'subject' => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ), |
|
43 | + 'to' => array_filter(array_unique(wpinv_parse_list($to))), |
|
44 | + 'subject' => htmlspecialchars_decode(strip_tags($subject), ENT_QUOTES), |
|
45 | 45 | 'email' => $email, |
46 | 46 | 'headers' => $this->get_headers(), |
47 | 47 | 'attachments' => $attachments, |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | ); |
51 | 51 | |
52 | 52 | // Remove slashes. |
53 | - $data = (array) wp_unslash( $data ); |
|
53 | + $data = (array) wp_unslash($data); |
|
54 | 54 | |
55 | 55 | // Cache it. |
56 | 56 | $this->wp_mail_data = $data; |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | |
61 | 61 | $result = false; |
62 | 62 | |
63 | - foreach ( $this->wp_mail_data['to'] as $to ) { |
|
64 | - $result = $this->_send( $to, $data ); |
|
63 | + foreach ($this->wp_mail_data['to'] as $to) { |
|
64 | + $result = $this->_send($to, $data); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Remove our hooks. |
@@ -82,24 +82,24 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - protected function _send( $to, $data ) { |
|
85 | + protected function _send($to, $data) { |
|
86 | 86 | |
87 | 87 | // Prepare the sending function. |
88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
88 | + $sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail'); |
|
89 | 89 | |
90 | 90 | // Send the actual email. |
91 | 91 | $result = call_user_func( |
92 | 92 | $sending_function, |
93 | 93 | $to, |
94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
94 | + html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')), |
|
95 | 95 | $data['email'], |
96 | 96 | $data['headers'], |
97 | 97 | $data['attachments'] |
98 | 98 | ); |
99 | 99 | |
100 | - if ( ! $result ) { |
|
101 | - $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
100 | + if (!$result) { |
|
101 | + $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']); |
|
102 | + wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | return $result; |
@@ -112,9 +112,9 @@ discard block |
||
112 | 112 | |
113 | 113 | $name = $this->get_from_name(); |
114 | 114 | $reply_to = $this->get_reply_to(); |
115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
115 | + $headers = array("Reply-To:$name <$reply_to>"); |
|
116 | 116 | |
117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
117 | + return apply_filters('getpaid_email_headers', $headers, $this); |
|
118 | 118 | |
119 | 119 | } |
120 | 120 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public function before_sending() { |
127 | 127 | |
128 | - do_action( 'getpaid_before_send_email', $this ); |
|
129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
128 | + do_action('getpaid_before_send_email', $this); |
|
129 | + add_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
130 | + add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
131 | + add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
132 | + add_filter('wp_mail', array($this, 'ensure_email_content'), 1000000); |
|
133 | 133 | |
134 | 134 | } |
135 | 135 | |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function get_from_name() { |
140 | 140 | |
141 | - $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
|
141 | + $from_name = wpinv_get_option('email_from_name', get_bloginfo('name')); |
|
142 | 142 | |
143 | - if ( empty( $from_name ) ) { |
|
144 | - $from_name = get_bloginfo( 'name' ); |
|
143 | + if (empty($from_name)) { |
|
144 | + $from_name = get_bloginfo('name'); |
|
145 | 145 | } |
146 | 146 | |
147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
147 | + return wp_specialchars_decode($from_name, ENT_QUOTES); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function get_from_address() { |
154 | 154 | |
155 | - $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
|
155 | + $from_address = wpinv_get_option('email_from', $this->default_from_address()); |
|
156 | 156 | |
157 | - if ( ! is_email( $from_address ) ) { |
|
158 | - $from_address = $this->default_from_address(); |
|
157 | + if (!is_email($from_address)) { |
|
158 | + $from_address = $this->default_from_address(); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | return $from_address; |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | public function default_from_address() { |
175 | 175 | |
176 | 176 | // Get the site domain and get rid of www. |
177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
179 | - $sitename = substr( $sitename, 4 ); |
|
177 | + $sitename = strtolower($_SERVER['SERVER_NAME']); |
|
178 | + if (substr($sitename, 0, 4) == 'www.') { |
|
179 | + $sitename = substr($sitename, 4); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | $from_email = 'wordpress@' . $sitename; |
183 | 183 | |
184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
184 | + return apply_filters('getpaid_default_from_address', $from_email); |
|
185 | 185 | |
186 | 186 | } |
187 | 187 | |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | |
196 | 196 | $reply_to = wpinv_get_admin_email(); |
197 | 197 | |
198 | - if ( ! is_email( $reply_to ) ) { |
|
199 | - $reply_to = get_option( 'admin_email' ); |
|
198 | + if (!is_email($reply_to)) { |
|
199 | + $reply_to = get_option('admin_email'); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return $reply_to; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | */ |
209 | 209 | public function get_content_type() { |
210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
210 | + return apply_filters('getpaid_email_content_type', 'text/html', $this); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return array wp_mail_data. |
217 | 217 | */ |
218 | - public function ensure_email_content( $args ) { |
|
218 | + public function ensure_email_content($args) { |
|
219 | 219 | $args['message'] = $this->wp_mail_data['email']; |
220 | 220 | return $args; |
221 | 221 | } |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function after_sending() { |
228 | 228 | |
229 | - do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
|
230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000000 ); |
|
229 | + do_action('getpaid_after_send_email', $this->wp_mail_data); |
|
230 | + remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000); |
|
231 | + remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000); |
|
232 | + remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000); |
|
233 | + remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000000); |
|
234 | 234 | |
235 | 235 | } |
236 | 236 |
@@ -7,23 +7,23 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | 13 | |
14 | -if ( ! empty( $required ) ) { |
|
14 | +if (!empty($required)) { |
|
15 | 15 | $label .= "<span class='text-danger'> *</span>"; |
16 | 16 | } |
17 | 17 | |
18 | 18 | echo aui()->input( |
19 | 19 | array( |
20 | - 'name' => esc_attr( $id ), |
|
21 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
22 | - 'placeholder'=> empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
23 | - 'required' => ! empty( $required ), |
|
20 | + 'name' => esc_attr($id), |
|
21 | + 'id' => esc_attr($id) . uniqid('_'), |
|
22 | + 'placeholder'=> empty($placeholder) ? '' : esc_attr($placeholder), |
|
23 | + 'required' => !empty($required), |
|
24 | 24 | 'label' => $label, |
25 | 25 | 'label_type' => 'vertical', |
26 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
26 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
27 | 27 | 'type' => 'datepicker', |
28 | 28 | ) |
29 | 29 | ); |
@@ -7,23 +7,23 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | 13 | |
14 | -if ( ! empty( $required ) ) { |
|
14 | +if (!empty($required)) { |
|
15 | 15 | $label .= "<span class='text-danger'> *</span>"; |
16 | 16 | } |
17 | 17 | |
18 | 18 | echo aui()->input( |
19 | 19 | array( |
20 | - 'name' => esc_attr( $id ), |
|
21 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
22 | - 'placeholder'=> empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
23 | - 'required' => ! empty( $required ), |
|
20 | + 'name' => esc_attr($id), |
|
21 | + 'id' => esc_attr($id) . uniqid('_'), |
|
22 | + 'placeholder'=> empty($placeholder) ? '' : esc_attr($placeholder), |
|
23 | + 'required' => !empty($required), |
|
24 | 24 | 'label' => $label, |
25 | 25 | 'label_type' => 'vertical', |
26 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
26 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
27 | 27 | 'type' => 'number', |
28 | 28 | ) |
29 | 29 | ); |
@@ -7,23 +7,23 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | 13 | |
14 | -if ( ! empty( $required ) ) { |
|
14 | +if (!empty($required)) { |
|
15 | 15 | $label .= "<span class='text-danger'> *</span>"; |
16 | 16 | } |
17 | 17 | |
18 | 18 | echo aui()->radio( |
19 | 19 | array( |
20 | - 'name' => esc_attr( $id ), |
|
21 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
22 | - 'required' => ! empty( $required ), |
|
20 | + 'name' => esc_attr($id), |
|
21 | + 'id' => esc_attr($id) . uniqid('_'), |
|
22 | + 'required' => !empty($required), |
|
23 | 23 | 'label' => $label, |
24 | 24 | 'label_type' => 'vertical', |
25 | 25 | 'inline' => false, |
26 | - 'options' => empty( $options ) ? array() : array_combine( $options, $options ), |
|
27 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
26 | + 'options' => empty($options) ? array() : array_combine($options, $options), |
|
27 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
28 | 28 | ) |
29 | 29 | ); |
@@ -7,35 +7,35 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Ensure that we have options. |
13 | -if ( empty( $options ) ) { |
|
13 | +if (empty($options)) { |
|
14 | 14 | return; |
15 | 15 | } |
16 | 16 | |
17 | 17 | // Prepare price options. |
18 | -$options = getpaid_convert_price_string_to_options( $options ); |
|
19 | -$keys = array_keys( $options ); |
|
20 | -$value = empty( $options ) ? '' : $keys[0]; |
|
18 | +$options = getpaid_convert_price_string_to_options($options); |
|
19 | +$keys = array_keys($options); |
|
20 | +$value = empty($options) ? '' : $keys[0]; |
|
21 | 21 | |
22 | 22 | // Prepare id. |
23 | -$id = esc_attr( $id ); |
|
23 | +$id = esc_attr($id); |
|
24 | 24 | |
25 | -$select_type = empty( $select_type ) ? 'select' : $select_type; |
|
25 | +$select_type = empty($select_type) ? 'select' : $select_type; |
|
26 | 26 | |
27 | 27 | // Item select; |
28 | -if ( $select_type == 'select' ) { |
|
28 | +if ($select_type == 'select') { |
|
29 | 29 | echo aui()->select( |
30 | 30 | array( |
31 | 31 | 'name' => $id, |
32 | - 'id' => $id . uniqid( '_' ), |
|
33 | - 'placeholder'=> empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
32 | + 'id' => $id . uniqid('_'), |
|
33 | + 'placeholder'=> empty($placeholder) ? '' : esc_attr($placeholder), |
|
34 | 34 | 'value' => $value, |
35 | - 'label' => empty( $label ) ? '' : sanitize_text_field( $label ), |
|
35 | + 'label' => empty($label) ? '' : sanitize_text_field($label), |
|
36 | 36 | 'label_type' => 'vertical', |
37 | 37 | 'class' => 'getpaid-price-select-dropdown getpaid-refresh-on-change', |
38 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
38 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
39 | 39 | 'options' => $options, |
40 | 40 | ) |
41 | 41 | ); |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | // Item radios; |
46 | -if ( $select_type == 'radios' ) { |
|
46 | +if ($select_type == 'radios') { |
|
47 | 47 | echo aui()->radio( |
48 | 48 | array( |
49 | - 'name' => esc_attr( $id ), |
|
50 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
51 | - 'label' => empty( $label ) ? '' : sanitize_text_field( $label ), |
|
49 | + 'name' => esc_attr($id), |
|
50 | + 'id' => esc_attr($id) . uniqid('_'), |
|
51 | + 'label' => empty($label) ? '' : sanitize_text_field($label), |
|
52 | 52 | 'label_type' => 'vertical', |
53 | 53 | 'class' => 'getpaid-price-select-radio getpaid-refresh-on-change', |
54 | 54 | 'value' => $value, |
55 | 55 | 'inline' => false, |
56 | 56 | 'options' => $options, |
57 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
57 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
58 | 58 | ) |
59 | 59 | ); |
60 | 60 | return; |
@@ -62,30 +62,30 @@ discard block |
||
62 | 62 | |
63 | 63 | |
64 | 64 | // Display the label. |
65 | -if ( ! empty( $label ) ) { |
|
66 | - $label = sanitize_text_field( $label ); |
|
65 | +if (!empty($label)) { |
|
66 | + $label = sanitize_text_field($label); |
|
67 | 67 | echo "<label>$label</label>"; |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Item buttons; |
71 | -if ( $select_type == 'buttons' || $select_type == 'circles' ) { |
|
71 | +if ($select_type == 'buttons' || $select_type == 'circles') { |
|
72 | 72 | |
73 | 73 | $class = 'getpaid-price-buttons'; |
74 | 74 | |
75 | - if ( $select_type == 'circles' ) { |
|
75 | + if ($select_type == 'circles') { |
|
76 | 76 | $class .= ' getpaid-price-circles'; |
77 | 77 | } |
78 | 78 | echo "<div class='$class'>"; |
79 | 79 | |
80 | - foreach ( $options as $price => $label ) { |
|
81 | - $label = sanitize_text_field( $label ); |
|
82 | - $price = esc_attr( $price ); |
|
83 | - $_id = $id . uniqid( '_' ); |
|
84 | - $checked = checked( $price, $value, false ); |
|
80 | + foreach ($options as $price => $label) { |
|
81 | + $label = sanitize_text_field($label); |
|
82 | + $price = esc_attr($price); |
|
83 | + $_id = $id . uniqid('_'); |
|
84 | + $checked = checked($price, $value, false); |
|
85 | 85 | |
86 | 86 | $class = 'rounded'; |
87 | 87 | |
88 | - if ( $select_type == 'circles' ) { |
|
88 | + if ($select_type == 'circles') { |
|
89 | 89 | $class = ''; |
90 | 90 | } |
91 | 91 | echo " |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | } |
102 | 102 | |
103 | 103 | // Item checkboxes; |
104 | -if ( $select_type == 'checkboxes' ) { |
|
104 | +if ($select_type == 'checkboxes') { |
|
105 | 105 | echo '<div class="form-group">'; |
106 | 106 | |
107 | - foreach ( $options as $price => $label ) { |
|
108 | - $label = sanitize_text_field( $label ); |
|
109 | - $price = esc_attr( $price ); |
|
110 | - $checked = checked( $price, $value, false ); |
|
107 | + foreach ($options as $price => $label) { |
|
108 | + $label = sanitize_text_field($label); |
|
109 | + $price = esc_attr($price); |
|
110 | + $checked = checked($price, $value, false); |
|
111 | 111 | echo " |
112 | 112 | <label class='d-block'> |
113 | 113 | <input type='checkbox' class='getpaid-price-select-checkbox getpaid-refresh-on-change' name='{$id}[]' value='$price' $checked /> |
@@ -120,6 +120,6 @@ discard block |
||
120 | 120 | |
121 | 121 | } |
122 | 122 | |
123 | -if ( ! empty( $description ) ) { |
|
123 | +if (!empty($description)) { |
|
124 | 124 | echo "<small class='form-text text-muted'>$description</small>"; |
125 | 125 | } |
@@ -7,23 +7,23 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | 13 | |
14 | -if ( ! empty( $required ) ) { |
|
14 | +if (!empty($required)) { |
|
15 | 15 | $label .= "<span class='text-danger'> *</span>"; |
16 | 16 | } |
17 | 17 | |
18 | 18 | echo aui()->select( |
19 | 19 | array( |
20 | - 'name' => esc_attr( $id ), |
|
21 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
22 | - 'placeholder'=> empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
23 | - 'required' => ! empty( $required ), |
|
20 | + 'name' => esc_attr($id), |
|
21 | + 'id' => esc_attr($id) . uniqid('_'), |
|
22 | + 'placeholder'=> empty($placeholder) ? '' : esc_attr($placeholder), |
|
23 | + 'required' => !empty($required), |
|
24 | 24 | 'label' => $label, |
25 | 25 | 'label_type' => 'vertical', |
26 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
27 | - 'options' => empty( $options ) ? array() : array_combine( $options, $options ), |
|
26 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
27 | + 'options' => empty($options) ? array() : array_combine($options, $options), |
|
28 | 28 | ) |
29 | 29 | ); |
@@ -7,23 +7,23 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -$label = empty( $label ) ? '' : wp_kses_post( $label ); |
|
12 | +$label = empty($label) ? '' : wp_kses_post($label); |
|
13 | 13 | |
14 | -if ( ! empty( $required ) ) { |
|
14 | +if (!empty($required)) { |
|
15 | 15 | $label .= "<span class='text-danger'> *</span>"; |
16 | 16 | } |
17 | 17 | |
18 | 18 | echo aui()->input( |
19 | 19 | array( |
20 | - 'name' => esc_attr( $id ), |
|
21 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
22 | - 'placeholder'=> empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
23 | - 'required' => ! empty( $required ), |
|
20 | + 'name' => esc_attr($id), |
|
21 | + 'id' => esc_attr($id) . uniqid('_'), |
|
22 | + 'placeholder'=> empty($placeholder) ? '' : esc_attr($placeholder), |
|
23 | + 'required' => !empty($required), |
|
24 | 24 | 'label' => $label, |
25 | 25 | 'label_type' => 'vertical', |
26 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
26 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
27 | 27 | 'type' => 'url', |
28 | 28 | ) |
29 | 29 | ); |