@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | $name = isset( $option['name'] ) ? $option['name'] : ''; |
193 | 193 | $cb = "wpinv_{$option['type']}_callback"; |
194 | 194 | $section = "wpinv_settings_{$tab}_$section"; |
195 | - $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
195 | + $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
196 | 196 | |
197 | - if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
198 | - $tip = wpinv_clean( $option['desc'] ); |
|
199 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
200 | - unset( $option['desc'] ); |
|
201 | - } |
|
197 | + if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
198 | + $tip = wpinv_clean( $option['desc'] ); |
|
199 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
200 | + unset( $option['desc'] ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | // Loop through all tabs. |
204 | 204 | add_settings_field( |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
226 | 226 | 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
227 | 227 | 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
228 | - 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
229 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
230 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
228 | + 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
229 | + 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
230 | + 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
231 | 231 | 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
232 | 232 | 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
233 | 233 | ) |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @return array |
242 | 242 | */ |
243 | 243 | function wpinv_get_registered_settings() { |
244 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
244 | + return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -260,18 +260,18 @@ discard block |
||
260 | 260 | */ |
261 | 261 | function wpinv_settings_sanitize( $input = array() ) { |
262 | 262 | |
263 | - $wpinv_options = wpinv_get_options(); |
|
264 | - $raw_referrer = wp_get_raw_referer(); |
|
263 | + $wpinv_options = wpinv_get_options(); |
|
264 | + $raw_referrer = wp_get_raw_referer(); |
|
265 | 265 | |
266 | 266 | if ( empty( $raw_referrer ) ) { |
267 | - return array_merge( $wpinv_options, $input ); |
|
267 | + return array_merge( $wpinv_options, $input ); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | wp_parse_str( $raw_referrer, $referrer ); |
271 | 271 | |
272 | - if ( in_array( 'gp-setup', $referrer ) ) { |
|
273 | - return array_merge( $wpinv_options, $input ); |
|
274 | - } |
|
272 | + if ( in_array( 'gp-setup', $referrer ) ) { |
|
273 | + return array_merge( $wpinv_options, $input ); |
|
274 | + } |
|
275 | 275 | |
276 | 276 | $settings = wpinv_get_registered_settings(); |
277 | 277 | $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
@@ -293,10 +293,10 @@ discard block |
||
293 | 293 | } |
294 | 294 | |
295 | 295 | // General filter |
296 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
296 | + $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
297 | 297 | |
298 | - // Key specific filter. |
|
299 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
298 | + // Key specific filter. |
|
299 | + $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | // Loop through the whitelist and unset any that are empty for the tab being saved |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | |
340 | 340 | foreach ( $new_rates as $rate ) { |
341 | 341 | |
342 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
343 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
344 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
345 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
346 | - $rate['global'] = empty( $rate['state'] ); |
|
347 | - $tax_rates[] = $rate; |
|
342 | + $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
343 | + $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
344 | + $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
345 | + $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
346 | + $rate['global'] = empty( $rate['state'] ); |
|
347 | + $tax_rates[] = $rate; |
|
348 | 348 | |
349 | - } |
|
349 | + } |
|
350 | 350 | |
351 | 351 | update_option( 'wpinv_tax_rates', $tax_rates ); |
352 | 352 | |
@@ -359,11 +359,11 @@ discard block |
||
359 | 359 | $tabs['general'] = __( 'General', 'invoicing' ); |
360 | 360 | $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
361 | 361 | $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
362 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
362 | + $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
363 | 363 | |
364 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
365 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
366 | - } |
|
364 | + if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
365 | + $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
366 | + } |
|
367 | 367 | |
368 | 368 | $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
369 | 369 | $tabs['misc'] = __( 'Misc', 'invoicing' ); |
@@ -394,52 +394,52 @@ discard block |
||
394 | 394 | 'general' => apply_filters( |
395 | 395 | 'wpinv_settings_sections_general', |
396 | 396 | array( |
397 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
398 | - 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
399 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
400 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
397 | + 'main' => __( 'General Settings', 'invoicing' ), |
|
398 | + 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
399 | + 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
400 | + 'labels' => __( 'Label Texts', 'invoicing' ), |
|
401 | 401 | ) |
402 | 402 | ), |
403 | 403 | 'gateways' => apply_filters( |
404 | 404 | 'wpinv_settings_sections_gateways', |
405 | 405 | array( |
406 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
406 | + 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
407 | 407 | ) |
408 | 408 | ), |
409 | 409 | 'taxes' => apply_filters( |
410 | 410 | 'wpinv_settings_sections_taxes', |
411 | 411 | array( |
412 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
413 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
414 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ), |
|
412 | + 'main' => __( 'Tax Settings', 'invoicing' ), |
|
413 | + 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
414 | + 'vat' => __( 'EU VAT Settings', 'invoicing' ), |
|
415 | 415 | ) |
416 | 416 | ), |
417 | 417 | 'emails' => apply_filters( |
418 | 418 | 'wpinv_settings_sections_emails', |
419 | 419 | array( |
420 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
420 | + 'main' => __( 'Email Settings', 'invoicing' ), |
|
421 | 421 | ) |
422 | 422 | ), |
423 | 423 | |
424 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
424 | + 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
425 | 425 | |
426 | 426 | 'privacy' => apply_filters( |
427 | 427 | 'wpinv_settings_sections_privacy', |
428 | 428 | array( |
429 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
429 | + 'main' => __( 'Privacy policy', 'invoicing' ), |
|
430 | 430 | ) |
431 | 431 | ), |
432 | 432 | 'misc' => apply_filters( |
433 | 433 | 'wpinv_settings_sections_misc', |
434 | 434 | array( |
435 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
436 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
435 | + 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
436 | + 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
437 | 437 | ) |
438 | 438 | ), |
439 | 439 | 'tools' => apply_filters( |
440 | 440 | 'wpinv_settings_sections_tools', |
441 | 441 | array( |
442 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
442 | + 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
443 | 443 | ) |
444 | 444 | ), |
445 | 445 | ); |
@@ -450,46 +450,46 @@ discard block |
||
450 | 450 | } |
451 | 451 | |
452 | 452 | function wpinv_get_pages( $with_slug = false, $default_label = null ) { |
453 | - $pages_options = array(); |
|
453 | + $pages_options = array(); |
|
454 | 454 | |
455 | - if ( $default_label !== null && $default_label !== false ) { |
|
456 | - $pages_options = array( '' => $default_label ); // Blank option |
|
457 | - } |
|
455 | + if ( $default_label !== null && $default_label !== false ) { |
|
456 | + $pages_options = array( '' => $default_label ); // Blank option |
|
457 | + } |
|
458 | 458 | |
459 | - $pages = get_pages(); |
|
460 | - if ( $pages ) { |
|
461 | - foreach ( $pages as $page ) { |
|
462 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
459 | + $pages = get_pages(); |
|
460 | + if ( $pages ) { |
|
461 | + foreach ( $pages as $page ) { |
|
462 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
463 | 463 | $pages_options[ $page->ID ] = $title; |
464 | - } |
|
465 | - } |
|
464 | + } |
|
465 | + } |
|
466 | 466 | |
467 | - return $pages_options; |
|
467 | + return $pages_options; |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | function wpinv_header_callback( $args ) { |
471 | - if ( ! empty( $args['desc'] ) ) { |
|
471 | + if ( ! empty( $args['desc'] ) ) { |
|
472 | 472 | echo wp_kses_post( $args['desc'] ); |
473 | 473 | } |
474 | 474 | } |
475 | 475 | |
476 | 476 | function wpinv_hidden_callback( $args ) { |
477 | 477 | |
478 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
479 | - $value = wpinv_get_option( $args['id'], $std ); |
|
478 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
479 | + $value = wpinv_get_option( $args['id'], $std ); |
|
480 | 480 | |
481 | - if ( isset( $args['set_value'] ) ) { |
|
482 | - $value = $args['set_value']; |
|
483 | - } |
|
481 | + if ( isset( $args['set_value'] ) ) { |
|
482 | + $value = $args['set_value']; |
|
483 | + } |
|
484 | 484 | |
485 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
486 | - $args['readonly'] = true; |
|
487 | - $name = ''; |
|
488 | - } else { |
|
489 | - $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']'; |
|
490 | - } |
|
485 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
486 | + $args['readonly'] = true; |
|
487 | + $name = ''; |
|
488 | + } else { |
|
489 | + $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']'; |
|
490 | + } |
|
491 | 491 | |
492 | - echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
492 | + echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
493 | 493 | |
494 | 494 | } |
495 | 495 | |
@@ -498,12 +498,12 @@ discard block |
||
498 | 498 | */ |
499 | 499 | function wpinv_checkbox_callback( $args ) { |
500 | 500 | |
501 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
502 | - $std = wpinv_get_option( $args['id'], $std ); |
|
503 | - $id = esc_attr( $args['id'] ); |
|
501 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
502 | + $std = wpinv_get_option( $args['id'], $std ); |
|
503 | + $id = esc_attr( $args['id'] ); |
|
504 | 504 | |
505 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
506 | - ?> |
|
505 | + getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
506 | + ?> |
|
507 | 507 | <fieldset> |
508 | 508 | <label> |
509 | 509 | <input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox"> |
@@ -515,75 +515,75 @@ discard block |
||
515 | 515 | |
516 | 516 | function wpinv_multicheck_callback( $args ) { |
517 | 517 | |
518 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
519 | - $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
518 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
519 | + $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
520 | 520 | |
521 | - if ( ! empty( $args['options'] ) ) { |
|
521 | + if ( ! empty( $args['options'] ) ) { |
|
522 | 522 | |
523 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
524 | - $value = wpinv_get_option( $args['id'], $std ); |
|
523 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
524 | + $value = wpinv_get_option( $args['id'], $std ); |
|
525 | 525 | |
526 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">'; |
|
526 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">'; |
|
527 | 527 | foreach ( $args['options'] as $key => $option ) : |
528 | - $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) ); |
|
529 | - if ( in_array( $sanitize_key, $value ) ) { |
|
530 | - $enabled = $sanitize_key; |
|
531 | - } else { |
|
532 | - $enabled = null; |
|
533 | - } |
|
534 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
535 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
536 | - endforeach; |
|
537 | - echo '</div>'; |
|
538 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
539 | - } |
|
528 | + $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) ); |
|
529 | + if ( in_array( $sanitize_key, $value ) ) { |
|
530 | + $enabled = $sanitize_key; |
|
531 | + } else { |
|
532 | + $enabled = null; |
|
533 | + } |
|
534 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
535 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
536 | + endforeach; |
|
537 | + echo '</div>'; |
|
538 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
539 | + } |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | function wpinv_payment_icons_callback( $args ) { |
543 | 543 | |
544 | 544 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
545 | - $value = wpinv_get_option( $args['id'], false ); |
|
545 | + $value = wpinv_get_option( $args['id'], false ); |
|
546 | 546 | |
547 | - if ( ! empty( $args['options'] ) ) { |
|
548 | - foreach ( $args['options'] as $key => $option ) { |
|
547 | + if ( ! empty( $args['options'] ) ) { |
|
548 | + foreach ( $args['options'] as $key => $option ) { |
|
549 | 549 | $sanitize_key = wpinv_sanitize_key( $key ); |
550 | 550 | |
551 | - if ( empty( $value ) ) { |
|
552 | - $enabled = $option; |
|
553 | - } else { |
|
554 | - $enabled = null; |
|
555 | - } |
|
556 | - |
|
557 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
558 | - |
|
559 | - echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
560 | - |
|
561 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
562 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
563 | - } else { |
|
564 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
565 | - |
|
566 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
567 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
568 | - } else { |
|
569 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
570 | - $content_dir = WP_CONTENT_DIR; |
|
571 | - |
|
572 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
573 | - // Replaces backslashes with forward slashes for Windows systems |
|
574 | - $image = wp_normalize_path( $image ); |
|
575 | - $content_dir = wp_normalize_path( $content_dir ); |
|
576 | - } |
|
577 | - |
|
578 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
579 | - } |
|
580 | - |
|
581 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
582 | - } |
|
583 | - echo wp_kses_post( $option ) . '</label>'; |
|
584 | - } |
|
585 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
586 | - } |
|
551 | + if ( empty( $value ) ) { |
|
552 | + $enabled = $option; |
|
553 | + } else { |
|
554 | + $enabled = null; |
|
555 | + } |
|
556 | + |
|
557 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
558 | + |
|
559 | + echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
560 | + |
|
561 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
562 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
563 | + } else { |
|
564 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
565 | + |
|
566 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
567 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
568 | + } else { |
|
569 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
570 | + $content_dir = WP_CONTENT_DIR; |
|
571 | + |
|
572 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
573 | + // Replaces backslashes with forward slashes for Windows systems |
|
574 | + $image = wp_normalize_path( $image ); |
|
575 | + $content_dir = wp_normalize_path( $content_dir ); |
|
576 | + } |
|
577 | + |
|
578 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
579 | + } |
|
580 | + |
|
581 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
582 | + } |
|
583 | + echo wp_kses_post( $option ) . '</label>'; |
|
584 | + } |
|
585 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
586 | + } |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | /** |
@@ -591,9 +591,9 @@ discard block |
||
591 | 591 | */ |
592 | 592 | function wpinv_radio_callback( $args ) { |
593 | 593 | |
594 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
595 | - $std = wpinv_get_option( $args['id'], $std ); |
|
596 | - ?> |
|
594 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
595 | + $std = wpinv_get_option( $args['id'], $std ); |
|
596 | + ?> |
|
597 | 597 | <fieldset> |
598 | 598 | <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
599 | 599 | <?php foreach ( $args['options'] as $key => $option ) : ?> |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | </ul> |
608 | 608 | </fieldset> |
609 | 609 | <?php |
610 | - getpaid_settings_description_callback( $args ); |
|
610 | + getpaid_settings_description_callback( $args ); |
|
611 | 611 | } |
612 | 612 | |
613 | 613 | /** |
@@ -615,10 +615,10 @@ discard block |
||
615 | 615 | */ |
616 | 616 | function getpaid_settings_description_callback( $args ) { |
617 | 617 | |
618 | - if ( ! empty( $args['desc'] ) ) { |
|
619 | - $description = $args['desc']; |
|
620 | - echo wp_kses_post( "<p class='description'>$description</p>" ); |
|
621 | - } |
|
618 | + if ( ! empty( $args['desc'] ) ) { |
|
619 | + $description = $args['desc']; |
|
620 | + echo wp_kses_post( "<p class='description'>$description</p>" ); |
|
621 | + } |
|
622 | 622 | |
623 | 623 | } |
624 | 624 | |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | */ |
628 | 628 | function wpinv_gateways_callback() { |
629 | 629 | |
630 | - ?> |
|
630 | + ?> |
|
631 | 631 | </td> |
632 | 632 | </tr> |
633 | 633 | <tr class="bsui"> |
@@ -641,26 +641,26 @@ discard block |
||
641 | 641 | |
642 | 642 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
643 | 643 | $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
644 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
645 | - $value = wpinv_get_option( $args['id'], $std ); |
|
644 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
645 | + $value = wpinv_get_option( $args['id'], $std ); |
|
646 | 646 | |
647 | - echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >'; |
|
647 | + echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >'; |
|
648 | 648 | |
649 | - foreach ( $args['options'] as $key => $option ) : |
|
649 | + foreach ( $args['options'] as $key => $option ) : |
|
650 | 650 | |
651 | - echo '<option value="' . esc_attr( $key ) . '" '; |
|
651 | + echo '<option value="' . esc_attr( $key ) . '" '; |
|
652 | 652 | |
653 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
653 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
654 | 654 | selected( $key, $args['selected'] ); |
655 | 655 | } else { |
656 | 656 | selected( $key, $value ); |
657 | 657 | } |
658 | 658 | |
659 | - echo '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
660 | - endforeach; |
|
659 | + echo '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
660 | + endforeach; |
|
661 | 661 | |
662 | - echo '</select>'; |
|
663 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
662 | + echo '</select>'; |
|
663 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
664 | 664 | } |
665 | 665 | |
666 | 666 | /** |
@@ -671,38 +671,38 @@ discard block |
||
671 | 671 | */ |
672 | 672 | function wpinv_settings_attrs_helper( $args ) { |
673 | 673 | |
674 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
675 | - $id = esc_attr( $args['id'] ); |
|
676 | - $value = is_scalar( $value ) ? $value : ''; |
|
677 | - |
|
678 | - $attrs = array( |
|
679 | - 'name' => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]", |
|
680 | - 'readonly' => ! empty( $args['faux'] ), |
|
681 | - 'value' => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ), |
|
682 | - 'id' => 'wpinv-settings-' . $args['id'], |
|
683 | - 'style' => $args['style'], |
|
684 | - 'class' => $args['class'], |
|
685 | - 'placeholder' => $args['placeholder'], |
|
686 | - 'data-placeholder' => $args['placeholder'], |
|
687 | - ); |
|
674 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
675 | + $id = esc_attr( $args['id'] ); |
|
676 | + $value = is_scalar( $value ) ? $value : ''; |
|
677 | + |
|
678 | + $attrs = array( |
|
679 | + 'name' => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]", |
|
680 | + 'readonly' => ! empty( $args['faux'] ), |
|
681 | + 'value' => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ), |
|
682 | + 'id' => 'wpinv-settings-' . $args['id'], |
|
683 | + 'style' => $args['style'], |
|
684 | + 'class' => $args['class'], |
|
685 | + 'placeholder' => $args['placeholder'], |
|
686 | + 'data-placeholder' => $args['placeholder'], |
|
687 | + ); |
|
688 | 688 | |
689 | - if ( ! empty( $args['onchange'] ) ) { |
|
690 | - $attrs['onchange'] = $args['onchange']; |
|
691 | - } |
|
689 | + if ( ! empty( $args['onchange'] ) ) { |
|
690 | + $attrs['onchange'] = $args['onchange']; |
|
691 | + } |
|
692 | 692 | |
693 | - foreach ( $attrs as $key => $value ) { |
|
693 | + foreach ( $attrs as $key => $value ) { |
|
694 | 694 | |
695 | - if ( false === $value ) { |
|
696 | - continue; |
|
697 | - } |
|
695 | + if ( false === $value ) { |
|
696 | + continue; |
|
697 | + } |
|
698 | 698 | |
699 | - if ( true === $value ) { |
|
700 | - echo ' ' . esc_attr( $key ); |
|
701 | - } else { |
|
702 | - echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
703 | - } |
|
699 | + if ( true === $value ) { |
|
700 | + echo ' ' . esc_attr( $key ); |
|
701 | + } else { |
|
702 | + echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
703 | + } |
|
704 | 704 | |
705 | - } |
|
705 | + } |
|
706 | 706 | |
707 | 707 | } |
708 | 708 | |
@@ -711,9 +711,9 @@ discard block |
||
711 | 711 | */ |
712 | 712 | function wpinv_text_callback( $args ) { |
713 | 713 | |
714 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
714 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
715 | 715 | |
716 | - ?> |
|
716 | + ?> |
|
717 | 717 | <label style="width: 100%;"> |
718 | 718 | <input type="text" <?php wpinv_settings_attrs_helper( $args ); ?>> |
719 | 719 | <?php echo wp_kses_post( $desc ); ?> |
@@ -727,9 +727,9 @@ discard block |
||
727 | 727 | */ |
728 | 728 | function wpinv_number_callback( $args ) { |
729 | 729 | |
730 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
730 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
731 | 731 | |
732 | - ?> |
|
732 | + ?> |
|
733 | 733 | <label style="width: 100%;"> |
734 | 734 | <input type="number" step="<?php echo floatval( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php wpinv_settings_attrs_helper( $args ); ?>> |
735 | 735 | <?php echo wp_kses_post( $desc ); ?> |
@@ -741,34 +741,34 @@ discard block |
||
741 | 741 | function wpinv_textarea_callback( $args ) { |
742 | 742 | |
743 | 743 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
744 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
745 | - $value = wpinv_get_option( $args['id'], $std ); |
|
744 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
745 | + $value = wpinv_get_option( $args['id'], $std ); |
|
746 | 746 | |
747 | 747 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
748 | 748 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
749 | 749 | |
750 | - echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
751 | - echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
750 | + echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
751 | + echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
752 | 752 | |
753 | 753 | } |
754 | 754 | |
755 | 755 | function wpinv_password_callback( $args ) { |
756 | 756 | |
757 | 757 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
758 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
759 | - $value = wpinv_get_option( $args['id'], $std ); |
|
758 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
759 | + $value = wpinv_get_option( $args['id'], $std ); |
|
760 | 760 | |
761 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
762 | - echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
763 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
761 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
762 | + echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
763 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
764 | 764 | |
765 | 765 | } |
766 | 766 | |
767 | 767 | function wpinv_missing_callback( $args ) { |
768 | - printf( |
|
769 | - esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
770 | - '<strong>' . esc_html( $args['id'] ) . '</strong>' |
|
771 | - ); |
|
768 | + printf( |
|
769 | + esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
770 | + '<strong>' . esc_html( $args['id'] ) . '</strong>' |
|
771 | + ); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | /** |
@@ -776,13 +776,13 @@ discard block |
||
776 | 776 | */ |
777 | 777 | function wpinv_select_callback( $args ) { |
778 | 778 | |
779 | - $desc = wp_kses_post( $args['desc'] ); |
|
780 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
781 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
782 | - $value = wpinv_get_option( $args['id'], $value ); |
|
783 | - $rand = uniqid( 'random_id' ); |
|
779 | + $desc = wp_kses_post( $args['desc'] ); |
|
780 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
781 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
782 | + $value = wpinv_get_option( $args['id'], $value ); |
|
783 | + $rand = uniqid( 'random_id' ); |
|
784 | 784 | |
785 | - ?> |
|
785 | + ?> |
|
786 | 786 | <label style="width: 100%;"> |
787 | 787 | <select <?php wpinv_settings_attrs_helper( $args ); ?> data-allow-clear="true"> |
788 | 788 | <?php foreach ( $args['options'] as $option => $name ) : ?> |
@@ -815,50 +815,50 @@ discard block |
||
815 | 815 | function wpinv_color_select_callback( $args ) { |
816 | 816 | |
817 | 817 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
818 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
819 | - $value = wpinv_get_option( $args['id'], $std ); |
|
818 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
819 | + $value = wpinv_get_option( $args['id'], $std ); |
|
820 | 820 | |
821 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
821 | + echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
822 | 822 | |
823 | - foreach ( $args['options'] as $option => $color ) { |
|
824 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>'; |
|
825 | - } |
|
823 | + foreach ( $args['options'] as $option => $color ) { |
|
824 | + echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>'; |
|
825 | + } |
|
826 | 826 | |
827 | - echo '</select>'; |
|
828 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
827 | + echo '</select>'; |
|
828 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
829 | 829 | |
830 | 830 | } |
831 | 831 | |
832 | 832 | function wpinv_rich_editor_callback( $args ) { |
833 | - global $wp_version; |
|
833 | + global $wp_version; |
|
834 | 834 | |
835 | 835 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
836 | 836 | |
837 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
838 | - $value = wpinv_get_option( $args['id'], $std ); |
|
837 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
838 | + $value = wpinv_get_option( $args['id'], $std ); |
|
839 | 839 | |
840 | - if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
841 | - $value = $std; |
|
842 | - } |
|
840 | + if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
841 | + $value = $std; |
|
842 | + } |
|
843 | 843 | |
844 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
844 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
845 | 845 | |
846 | - echo '<div class="getpaid-settings-editor-input">'; |
|
847 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
848 | - wp_editor( |
|
846 | + echo '<div class="getpaid-settings-editor-input">'; |
|
847 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
848 | + wp_editor( |
|
849 | 849 | stripslashes( $value ), |
850 | 850 | 'wpinv_settings_' . esc_attr( $args['id'] ), |
851 | 851 | array( |
852 | - 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', |
|
853 | - 'textarea_rows' => absint( $rows ), |
|
854 | - 'media_buttons' => false, |
|
852 | + 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', |
|
853 | + 'textarea_rows' => absint( $rows ), |
|
854 | + 'media_buttons' => false, |
|
855 | 855 | ) |
856 | 856 | ); |
857 | - } else { |
|
858 | - echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
859 | - } |
|
857 | + } else { |
|
858 | + echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
859 | + } |
|
860 | 860 | |
861 | - echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
861 | + echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
862 | 862 | |
863 | 863 | } |
864 | 864 | |
@@ -866,51 +866,51 @@ discard block |
||
866 | 866 | |
867 | 867 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
868 | 868 | |
869 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
870 | - $value = wpinv_get_option( $args['id'], $std ); |
|
869 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
870 | + $value = wpinv_get_option( $args['id'], $std ); |
|
871 | 871 | |
872 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
873 | - echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
874 | - echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
875 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
872 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
873 | + echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
874 | + echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
875 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
876 | 876 | |
877 | 877 | } |
878 | 878 | |
879 | 879 | function wpinv_color_callback( $args ) { |
880 | 880 | |
881 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
882 | - $value = wpinv_get_option( $args['id'], $std ); |
|
881 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
882 | + $value = wpinv_get_option( $args['id'], $std ); |
|
883 | 883 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
884 | 884 | |
885 | - echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
886 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
885 | + echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
886 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
887 | 887 | |
888 | 888 | } |
889 | 889 | |
890 | 890 | function wpinv_country_states_callback( $args ) { |
891 | 891 | |
892 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
893 | - $value = wpinv_get_option( $args['id'], $std ); |
|
892 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
893 | + $value = wpinv_get_option( $args['id'], $std ); |
|
894 | 894 | |
895 | 895 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
896 | 896 | |
897 | - if ( isset( $args['placeholder'] ) ) { |
|
898 | - $placeholder = $args['placeholder']; |
|
899 | - } else { |
|
900 | - $placeholder = ''; |
|
901 | - } |
|
897 | + if ( isset( $args['placeholder'] ) ) { |
|
898 | + $placeholder = $args['placeholder']; |
|
899 | + } else { |
|
900 | + $placeholder = ''; |
|
901 | + } |
|
902 | 902 | |
903 | - $states = wpinv_get_country_states(); |
|
903 | + $states = wpinv_get_country_states(); |
|
904 | 904 | |
905 | - $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2'; |
|
906 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
905 | + $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2'; |
|
906 | + echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
907 | 907 | |
908 | - foreach ( $states as $option => $name ) { |
|
909 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>'; |
|
910 | - } |
|
908 | + foreach ( $states as $option => $name ) { |
|
909 | + echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>'; |
|
910 | + } |
|
911 | 911 | |
912 | - echo '</select>'; |
|
913 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
912 | + echo '</select>'; |
|
913 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
914 | 914 | |
915 | 915 | } |
916 | 916 | |
@@ -919,7 +919,7 @@ discard block |
||
919 | 919 | */ |
920 | 920 | function wpinv_tax_rates_callback() { |
921 | 921 | |
922 | - ?> |
|
922 | + ?> |
|
923 | 923 | </td> |
924 | 924 | </tr> |
925 | 925 | <tr class="bsui"> |
@@ -935,9 +935,9 @@ discard block |
||
935 | 935 | */ |
936 | 936 | function wpinv_tax_rate_callback( $tax_rate, $key ) { |
937 | 937 | |
938 | - $key = sanitize_key( $key ); |
|
939 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
940 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
938 | + $key = sanitize_key( $key ); |
|
939 | + $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
940 | + include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
941 | 941 | |
942 | 942 | } |
943 | 943 | |
@@ -969,14 +969,14 @@ discard block |
||
969 | 969 | <td> |
970 | 970 | <a href=" |
971 | 971 | <?php |
972 | - echo esc_url( |
|
973 | - wp_nonce_url( |
|
974 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
975 | - 'getpaid-nonce', |
|
976 | - 'getpaid-nonce' |
|
977 | - ) |
|
978 | - ); |
|
979 | - ?> |
|
972 | + echo esc_url( |
|
973 | + wp_nonce_url( |
|
974 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
975 | + 'getpaid-nonce', |
|
976 | + 'getpaid-nonce' |
|
977 | + ) |
|
978 | + ); |
|
979 | + ?> |
|
980 | 980 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
981 | 981 | </td> |
982 | 982 | </tr> |
@@ -988,14 +988,14 @@ discard block |
||
988 | 988 | <td> |
989 | 989 | <a href=" |
990 | 990 | <?php |
991 | - echo esc_url( |
|
992 | - wp_nonce_url( |
|
993 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
994 | - 'getpaid-nonce', |
|
995 | - 'getpaid-nonce' |
|
996 | - ) |
|
997 | - ); |
|
998 | - ?> |
|
991 | + echo esc_url( |
|
992 | + wp_nonce_url( |
|
993 | + add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
994 | + 'getpaid-nonce', |
|
995 | + 'getpaid-nonce' |
|
996 | + ) |
|
997 | + ); |
|
998 | + ?> |
|
999 | 999 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1000 | 1000 | </td> |
1001 | 1001 | </tr> |
@@ -1007,14 +1007,14 @@ discard block |
||
1007 | 1007 | <td> |
1008 | 1008 | <a href=" |
1009 | 1009 | <?php |
1010 | - echo esc_url( |
|
1011 | - wp_nonce_url( |
|
1012 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1013 | - 'getpaid-nonce', |
|
1014 | - 'getpaid-nonce' |
|
1015 | - ) |
|
1016 | - ); |
|
1017 | - ?> |
|
1010 | + echo esc_url( |
|
1011 | + wp_nonce_url( |
|
1012 | + add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
1013 | + 'getpaid-nonce', |
|
1014 | + 'getpaid-nonce' |
|
1015 | + ) |
|
1016 | + ); |
|
1017 | + ?> |
|
1018 | 1018 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1019 | 1019 | </td> |
1020 | 1020 | </tr> |
@@ -1027,14 +1027,14 @@ discard block |
||
1027 | 1027 | <td> |
1028 | 1028 | <a href=" |
1029 | 1029 | <?php |
1030 | - echo esc_url( |
|
1031 | - wp_nonce_url( |
|
1032 | - add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1033 | - 'getpaid-nonce', |
|
1034 | - 'getpaid-nonce' |
|
1035 | - ) |
|
1036 | - ); |
|
1037 | - ?> |
|
1030 | + echo esc_url( |
|
1031 | + wp_nonce_url( |
|
1032 | + add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
1033 | + 'getpaid-nonce', |
|
1034 | + 'getpaid-nonce' |
|
1035 | + ) |
|
1036 | + ); |
|
1037 | + ?> |
|
1038 | 1038 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
1039 | 1039 | </td> |
1040 | 1040 | </tr> |
@@ -1047,8 +1047,8 @@ discard block |
||
1047 | 1047 | <td> |
1048 | 1048 | <a href=" |
1049 | 1049 | <?php |
1050 | - echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1051 | - ?> |
|
1050 | + echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
1051 | + ?> |
|
1052 | 1052 | " class="button button-primary"><?php esc_html_e( 'Launch', 'invoicing' ); ?></a> |
1053 | 1053 | </td> |
1054 | 1054 | </tr> |
@@ -1062,19 +1062,19 @@ discard block |
||
1062 | 1062 | |
1063 | 1063 | |
1064 | 1064 | function wpinv_descriptive_text_callback( $args ) { |
1065 | - echo wp_kses_post( $args['desc'] ); |
|
1065 | + echo wp_kses_post( $args['desc'] ); |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | 1068 | function wpinv_raw_html_callback( $args ) { |
1069 | - echo wp_kses( $args['desc'], getpaid_allowed_html() ); |
|
1069 | + echo wp_kses( $args['desc'], getpaid_allowed_html() ); |
|
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | function wpinv_hook_callback( $args ) { |
1073 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1073 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | function wpinv_set_settings_cap() { |
1077 | - return wpinv_get_capability(); |
|
1077 | + return wpinv_get_capability(); |
|
1078 | 1078 | } |
1079 | 1079 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
1080 | 1080 | |
@@ -1098,15 +1098,15 @@ discard block |
||
1098 | 1098 | */ |
1099 | 1099 | function wpinv_get_merge_tags_help_text( $subscription = false ) { |
1100 | 1100 | |
1101 | - $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
|
1102 | - $link = sprintf( |
|
1103 | - '<strong><a href="%s" target="_blank">%s</a></strong>', |
|
1104 | - $url, |
|
1105 | - esc_html__( 'View available merge tags.', 'wpinv-quotes' ) |
|
1106 | - ); |
|
1101 | + $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
|
1102 | + $link = sprintf( |
|
1103 | + '<strong><a href="%s" target="_blank">%s</a></strong>', |
|
1104 | + $url, |
|
1105 | + esc_html__( 'View available merge tags.', 'wpinv-quotes' ) |
|
1106 | + ); |
|
1107 | 1107 | |
1108 | - $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1108 | + $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
1109 | 1109 | |
1110 | - return "$description $link"; |
|
1110 | + return "$description $link"; |
|
1111 | 1111 | |
1112 | 1112 | } |
@@ -13,96 +13,96 @@ 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', 'single_subscription_group' ); |
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; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
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' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
92 | - add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
93 | - parent::__construct(); |
|
90 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
92 | + add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
93 | + parent::__construct(); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | - * Process Payment. |
|
98 | - * |
|
99 | - * |
|
100 | - * @param WPInv_Invoice $invoice Invoice. |
|
101 | - * @param array $submission_data Posted checkout fields. |
|
102 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
97 | + * Process Payment. |
|
98 | + * |
|
99 | + * |
|
100 | + * @param WPInv_Invoice $invoice Invoice. |
|
101 | + * @param array $submission_data Posted checkout fields. |
|
102 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
106 | 106 | |
107 | 107 | // Get redirect url. |
108 | 108 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get the PayPal request URL for an invoice. |
|
129 | - * |
|
130 | - * @param WPInv_Invoice $invoice Invoice object. |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function get_request_url( $invoice ) { |
|
128 | + * Get the PayPal request URL for an invoice. |
|
129 | + * |
|
130 | + * @param WPInv_Invoice $invoice Invoice object. |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function get_request_url( $invoice ) { |
|
134 | 134 | |
135 | 135 | // Endpoint for this request |
136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
136 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | 137 | |
138 | 138 | // Retrieve paypal args. |
139 | 139 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -146,45 +146,45 @@ discard block |
||
146 | 146 | |
147 | 147 | return add_query_arg( $paypal_args, $this->endpoint ); |
148 | 148 | |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | 151 | /** |
152 | - * Get PayPal Args for passing to PP. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - protected function get_paypal_args( $invoice ) { |
|
152 | + * Get PayPal Args for passing to PP. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + protected function get_paypal_args( $invoice ) { |
|
158 | 158 | |
159 | 159 | // Whether or not to send the line items as one item. |
160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | - |
|
162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | - $force_one_line_item = true; |
|
164 | - } |
|
165 | - |
|
166 | - $paypal_args = apply_filters( |
|
167 | - 'getpaid_paypal_args', |
|
168 | - array_merge( |
|
169 | - $this->get_transaction_args( $invoice ), |
|
170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | - ), |
|
172 | - $invoice |
|
173 | - ); |
|
174 | - |
|
175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
160 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | + |
|
162 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | + $force_one_line_item = true; |
|
164 | + } |
|
165 | + |
|
166 | + $paypal_args = apply_filters( |
|
167 | + 'getpaid_paypal_args', |
|
168 | + array_merge( |
|
169 | + $this->get_transaction_args( $invoice ), |
|
170 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | + ), |
|
172 | + $invoice |
|
173 | + ); |
|
174 | + |
|
175 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Get transaction args for paypal request. |
|
180 | - * |
|
181 | - * @param WPInv_Invoice $invoice Invoice object. |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - protected function get_transaction_args( $invoice ) { |
|
185 | - |
|
186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | - return array( |
|
179 | + * Get transaction args for paypal request. |
|
180 | + * |
|
181 | + * @param WPInv_Invoice $invoice Invoice object. |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + protected function get_transaction_args( $invoice ) { |
|
185 | + |
|
186 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | + return array( |
|
188 | 188 | 'cmd' => '_cart', |
189 | 189 | 'business' => $email, |
190 | 190 | 'no_shipping' => '1', |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get line item args for paypal request. |
|
213 | - * |
|
214 | - * @param WPInv_Invoice $invoice Invoice object. |
|
215 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | - * @return array |
|
217 | - */ |
|
218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
212 | + * Get line item args for paypal request. |
|
213 | + * |
|
214 | + * @param WPInv_Invoice $invoice Invoice object. |
|
215 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | + * @return array |
|
217 | + */ |
|
218 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | 219 | |
220 | 220 | // Maybe send invoice as a single item. |
221 | - if ( $force_one_line_item ) { |
|
221 | + if ( $force_one_line_item ) { |
|
222 | 222 | return $this->get_line_item_args_single_item( $invoice ); |
223 | 223 | } |
224 | 224 | |
@@ -238,129 +238,129 @@ discard block |
||
238 | 238 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
239 | 239 | } |
240 | 240 | |
241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
241 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | - * Get line item args for paypal request as a single line item. |
|
247 | - * |
|
248 | - * @param WPInv_Invoice $invoice Invoice object. |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
252 | - $this->delete_line_items(); |
|
246 | + * Get line item args for paypal request as a single line item. |
|
247 | + * |
|
248 | + * @param WPInv_Invoice $invoice Invoice object. |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function get_line_item_args_single_item( $invoice ) { |
|
252 | + $this->delete_line_items(); |
|
253 | 253 | |
254 | 254 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
255 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
256 | 256 | |
257 | - return $this->get_line_items(); |
|
257 | + return $this->get_line_items(); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Return all line items. |
|
262 | - */ |
|
263 | - protected function get_line_items() { |
|
264 | - return $this->line_items; |
|
265 | - } |
|
261 | + * Return all line items. |
|
262 | + */ |
|
263 | + protected function get_line_items() { |
|
264 | + return $this->line_items; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | - * Remove all line items. |
|
269 | - */ |
|
270 | - protected function delete_line_items() { |
|
271 | - $this->line_items = array(); |
|
268 | + * Remove all line items. |
|
269 | + */ |
|
270 | + protected function delete_line_items() { |
|
271 | + $this->line_items = array(); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Prepare line items to send to paypal. |
|
276 | - * |
|
277 | - * @param WPInv_Invoice $invoice Invoice object. |
|
278 | - */ |
|
279 | - protected function prepare_line_items( $invoice ) { |
|
280 | - $this->delete_line_items(); |
|
281 | - |
|
282 | - // Items. |
|
283 | - foreach ( $invoice->get_items() as $item ) { |
|
284 | - $amount = $item->get_price(); |
|
285 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
275 | + * Prepare line items to send to paypal. |
|
276 | + * |
|
277 | + * @param WPInv_Invoice $invoice Invoice object. |
|
278 | + */ |
|
279 | + protected function prepare_line_items( $invoice ) { |
|
280 | + $this->delete_line_items(); |
|
281 | + |
|
282 | + // Items. |
|
283 | + foreach ( $invoice->get_items() as $item ) { |
|
284 | + $amount = $item->get_price(); |
|
285 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fees. |
290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
290 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
291 | 291 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Add PayPal Line Item. |
|
298 | - * |
|
299 | - * @param string $item_name Item name. |
|
300 | - * @param float $quantity Item quantity. |
|
301 | - * @param float $amount Amount. |
|
302 | - * @param string $item_number Item number. |
|
303 | - */ |
|
304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | - |
|
307 | - $item = apply_filters( |
|
308 | - 'getpaid_paypal_line_item', |
|
309 | - array( |
|
310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | - 'quantity' => (float) $quantity, |
|
312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | - 'item_number' => $item_number, |
|
314 | - ), |
|
315 | - $item_name, |
|
316 | - $quantity, |
|
317 | - $amount, |
|
318 | - $item_number |
|
319 | - ); |
|
320 | - |
|
321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
297 | + * Add PayPal Line Item. |
|
298 | + * |
|
299 | + * @param string $item_name Item name. |
|
300 | + * @param float $quantity Item quantity. |
|
301 | + * @param float $amount Amount. |
|
302 | + * @param string $item_number Item number. |
|
303 | + */ |
|
304 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | + |
|
307 | + $item = apply_filters( |
|
308 | + 'getpaid_paypal_line_item', |
|
309 | + array( |
|
310 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | + 'quantity' => (float) $quantity, |
|
312 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | + 'item_number' => $item_number, |
|
314 | + ), |
|
315 | + $item_name, |
|
316 | + $quantity, |
|
317 | + $amount, |
|
318 | + $item_number |
|
319 | + ); |
|
320 | + |
|
321 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
322 | 322 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
323 | 323 | |
324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
325 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | - * |
|
332 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | - * |
|
334 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | - * @return array |
|
337 | - */ |
|
338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | - $max_paypal_length = 2083; |
|
340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | - |
|
342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | - return $paypal_args; |
|
344 | - } |
|
345 | - |
|
346 | - return apply_filters( |
|
347 | - 'getpaid_paypal_args', |
|
348 | - array_merge( |
|
349 | - $this->get_transaction_args( $invoice ), |
|
350 | - $this->get_line_item_args( $invoice, true ) |
|
351 | - ), |
|
352 | - $invoice |
|
353 | - ); |
|
330 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | + * |
|
332 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | + * |
|
334 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | + * @return array |
|
337 | + */ |
|
338 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | + $max_paypal_length = 2083; |
|
340 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | + |
|
342 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | + return $paypal_args; |
|
344 | + } |
|
345 | + |
|
346 | + return apply_filters( |
|
347 | + 'getpaid_paypal_args', |
|
348 | + array_merge( |
|
349 | + $this->get_transaction_args( $invoice ), |
|
350 | + $this->get_line_item_args( $invoice, true ) |
|
351 | + ), |
|
352 | + $invoice |
|
353 | + ); |
|
354 | 354 | |
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Processes recurring invoices. |
|
359 | - * |
|
360 | - * @param array $paypal_args PayPal args. |
|
361 | - * @param WPInv_Invoice $invoice Invoice object. |
|
362 | - */ |
|
363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
358 | + * Processes recurring invoices. |
|
359 | + * |
|
360 | + * @param array $paypal_args PayPal args. |
|
361 | + * @param WPInv_Invoice $invoice Invoice object. |
|
362 | + */ |
|
363 | + public function process_subscription( $paypal_args, $invoice ) { |
|
364 | 364 | |
365 | 365 | // Make sure this is a subscription. |
366 | 366 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -381,21 +381,21 @@ discard block |
||
381 | 381 | $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
382 | 382 | $subscription_item = $invoice->get_recurring( true ); |
383 | 383 | |
384 | - // Convert 365 days to 1 year. |
|
385 | - if ( 'D' == $period && 365 == $interval ) { |
|
386 | - $period = 'Y'; |
|
387 | - $interval = 1; |
|
388 | - } |
|
384 | + // Convert 365 days to 1 year. |
|
385 | + if ( 'D' == $period && 365 == $interval ) { |
|
386 | + $period = 'Y'; |
|
387 | + $interval = 1; |
|
388 | + } |
|
389 | 389 | |
390 | 390 | if ( $subscription_item->has_free_trial() ) { |
391 | 391 | |
392 | 392 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
393 | 393 | |
394 | - // Trial period length. |
|
395 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
394 | + // Trial period length. |
|
395 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
396 | 396 | |
397 | - // Trial period. |
|
398 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
397 | + // Trial period. |
|
398 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
399 | 399 | |
400 | 400 | } elseif ( $initial_amount != $recurring_amount ) { |
401 | 401 | |
@@ -418,40 +418,40 @@ discard block |
||
418 | 418 | } |
419 | 419 | |
420 | 420 | // We have a recurring payment |
421 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
421 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
422 | 422 | |
423 | - // Subscription price |
|
424 | - $paypal_args['a3'] = $recurring_amount; |
|
423 | + // Subscription price |
|
424 | + $paypal_args['a3'] = $recurring_amount; |
|
425 | 425 | |
426 | - // Subscription duration |
|
427 | - $paypal_args['p3'] = $interval; |
|
426 | + // Subscription duration |
|
427 | + $paypal_args['p3'] = $interval; |
|
428 | 428 | |
429 | - // Subscription period |
|
430 | - $paypal_args['t3'] = $period; |
|
429 | + // Subscription period |
|
430 | + $paypal_args['t3'] = $period; |
|
431 | 431 | |
432 | 432 | } |
433 | 433 | |
434 | 434 | // Recurring payments |
435 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
435 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
436 | 436 | |
437 | - // Non-recurring payments |
|
438 | - $paypal_args['src'] = 0; |
|
437 | + // Non-recurring payments |
|
438 | + $paypal_args['src'] = 0; |
|
439 | 439 | |
440 | - } else { |
|
440 | + } else { |
|
441 | 441 | |
442 | - $paypal_args['src'] = 1; |
|
442 | + $paypal_args['src'] = 1; |
|
443 | 443 | |
444 | - if ( $bill_times > 0 ) { |
|
444 | + if ( $bill_times > 0 ) { |
|
445 | 445 | |
446 | - // An initial period is being used to charge a sign-up fee |
|
447 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
448 | - $bill_times--; |
|
449 | - } |
|
446 | + // An initial period is being used to charge a sign-up fee |
|
447 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
448 | + $bill_times--; |
|
449 | + } |
|
450 | 450 | |
451 | 451 | // Make sure it's not over the max of 52 |
452 | 452 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
453 | 453 | |
454 | - } |
|
454 | + } |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | // Force return URL so that order description & instructions display |
@@ -466,19 +466,19 @@ discard block |
||
466 | 466 | } |
467 | 467 | |
468 | 468 | return apply_filters( |
469 | - 'getpaid_paypal_subscription_args', |
|
470 | - $paypal_args, |
|
471 | - $invoice |
|
469 | + 'getpaid_paypal_subscription_args', |
|
470 | + $paypal_args, |
|
471 | + $invoice |
|
472 | 472 | ); |
473 | 473 | |
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
477 | - * Processes ipns and marks payments as complete. |
|
478 | - * |
|
479 | - * @return void |
|
480 | - */ |
|
481 | - public function verify_ipn() { |
|
477 | + * Processes ipns and marks payments as complete. |
|
478 | + * |
|
479 | + * @return void |
|
480 | + */ |
|
481 | + public function verify_ipn() { |
|
482 | 482 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
483 | 483 | } |
484 | 484 | |
@@ -488,19 +488,19 @@ discard block |
||
488 | 488 | public function sandbox_notice() { |
489 | 489 | |
490 | 490 | return sprintf( |
491 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
492 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
493 | - '</a>' |
|
494 | - ); |
|
491 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
492 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
493 | + '</a>' |
|
494 | + ); |
|
495 | 495 | |
496 | 496 | } |
497 | 497 | |
498 | - /** |
|
499 | - * Filters the gateway settings. |
|
500 | - * |
|
501 | - * @param array $admin_settings |
|
502 | - */ |
|
503 | - public function admin_settings( $admin_settings ) { |
|
498 | + /** |
|
499 | + * Filters the gateway settings. |
|
500 | + * |
|
501 | + * @param array $admin_settings |
|
502 | + */ |
|
503 | + public function admin_settings( $admin_settings ) { |
|
504 | 504 | |
505 | 505 | $currencies = sprintf( |
506 | 506 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -510,31 +510,31 @@ discard block |
||
510 | 510 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
511 | 511 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
512 | 512 | |
513 | - // Access tokens. |
|
514 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
515 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
513 | + // Access tokens. |
|
514 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
515 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
516 | 516 | |
517 | - $admin_settings['paypal_connect'] = array( |
|
518 | - 'type' => 'hook', |
|
519 | - 'id' => 'paypal_connect', |
|
520 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
521 | - ); |
|
517 | + $admin_settings['paypal_connect'] = array( |
|
518 | + 'type' => 'hook', |
|
519 | + 'id' => 'paypal_connect', |
|
520 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
521 | + ); |
|
522 | 522 | |
523 | 523 | $admin_settings['paypal_email'] = array( |
524 | 524 | 'type' => 'text', |
525 | - 'class' => 'live-auth-data', |
|
525 | + 'class' => 'live-auth-data', |
|
526 | 526 | 'id' => 'paypal_email', |
527 | 527 | 'name' => __( 'Live Email Address', 'invoicing' ), |
528 | 528 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
529 | 529 | ); |
530 | 530 | |
531 | - $admin_settings['paypal_sandbox_email'] = array( |
|
531 | + $admin_settings['paypal_sandbox_email'] = array( |
|
532 | 532 | 'type' => 'text', |
533 | - 'class' => 'sandbox-auth-data', |
|
533 | + 'class' => 'sandbox-auth-data', |
|
534 | 534 | 'id' => 'paypal_sandbox_email', |
535 | 535 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
536 | 536 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
537 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
537 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
538 | 538 | ); |
539 | 539 | |
540 | 540 | $admin_settings['paypal_ipn_url'] = array( |
@@ -546,29 +546,29 @@ discard block |
||
546 | 546 | 'readonly' => true, |
547 | 547 | ); |
548 | 548 | |
549 | - return $admin_settings; |
|
550 | - } |
|
549 | + return $admin_settings; |
|
550 | + } |
|
551 | 551 | |
552 | - /** |
|
553 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
554 | - * |
|
555 | - * |
|
552 | + /** |
|
553 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
554 | + * |
|
555 | + * |
|
556 | 556 | * @param array $data |
557 | 557 | * @return string |
558 | - */ |
|
559 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
560 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Retrieves the PayPal connect URL. |
|
565 | - * |
|
566 | - * |
|
558 | + */ |
|
559 | + public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
560 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Retrieves the PayPal connect URL. |
|
565 | + * |
|
566 | + * |
|
567 | 567 | * @param bool $is_sandbox |
568 | - * @param string $redirect |
|
568 | + * @param string $redirect |
|
569 | 569 | * @return string |
570 | - */ |
|
571 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
570 | + */ |
|
571 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
572 | 572 | |
573 | 573 | $redirect_url = add_query_arg( |
574 | 574 | array( |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | 'tab' => 'gateways', |
579 | 579 | 'section' => 'paypal', |
580 | 580 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
581 | - 'redirect' => urlencode( $redirect ), |
|
581 | + 'redirect' => urlencode( $redirect ), |
|
582 | 582 | ), |
583 | 583 | admin_url( 'admin.php' ) |
584 | 584 | ); |
@@ -593,12 +593,12 @@ discard block |
||
593 | 593 | |
594 | 594 | } |
595 | 595 | |
596 | - /** |
|
597 | - * Generates settings page js. |
|
598 | - * |
|
596 | + /** |
|
597 | + * Generates settings page js. |
|
598 | + * |
|
599 | 599 | * @return void |
600 | - */ |
|
601 | - public static function display_connect_buttons() { |
|
600 | + */ |
|
601 | + public static function display_connect_buttons() { |
|
602 | 602 | |
603 | 603 | ?> |
604 | 604 | <div class="wpinv-paypal-connect-live"> |
@@ -640,70 +640,70 @@ discard block |
||
640 | 640 | <?php |
641 | 641 | } |
642 | 642 | |
643 | - /** |
|
644 | - * Connects to PayPal. |
|
645 | - * |
|
646 | - * @param array $data Connection data. |
|
647 | - * @return void |
|
648 | - */ |
|
649 | - public function connect_paypal( $data ) { |
|
650 | - |
|
651 | - $sandbox = $this->is_sandbox(); |
|
652 | - $data = wp_unslash( $data ); |
|
653 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
654 | - |
|
655 | - if ( isset( $data['live_mode'] ) ) { |
|
656 | - $sandbox = empty( $data['live_mode'] ); |
|
657 | - } |
|
658 | - |
|
659 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
660 | - wpinv_update_option( 'paypal_active', 1 ); |
|
661 | - |
|
662 | - if ( ! empty( $data['error_description'] ) ) { |
|
663 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
664 | - } else { |
|
665 | - |
|
666 | - // Retrieve the user info. |
|
667 | - $user_info = wp_remote_get( |
|
668 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
669 | - array( |
|
670 | - |
|
671 | - 'headers' => array( |
|
672 | - 'Authorization' => 'Bearer ' . $access_token, |
|
673 | - 'Content-type' => 'application/json', |
|
674 | - ), |
|
675 | - |
|
676 | - ) |
|
677 | - ); |
|
678 | - |
|
679 | - if ( is_wp_error( $user_info ) ) { |
|
680 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
681 | - } else { |
|
682 | - |
|
683 | - // Create application. |
|
684 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
685 | - |
|
686 | - if ( $sandbox ) { |
|
687 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
688 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
689 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
690 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
691 | - } else { |
|
692 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
693 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
694 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
695 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
696 | - } |
|
643 | + /** |
|
644 | + * Connects to PayPal. |
|
645 | + * |
|
646 | + * @param array $data Connection data. |
|
647 | + * @return void |
|
648 | + */ |
|
649 | + public function connect_paypal( $data ) { |
|
650 | + |
|
651 | + $sandbox = $this->is_sandbox(); |
|
652 | + $data = wp_unslash( $data ); |
|
653 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
654 | + |
|
655 | + if ( isset( $data['live_mode'] ) ) { |
|
656 | + $sandbox = empty( $data['live_mode'] ); |
|
657 | + } |
|
658 | + |
|
659 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
660 | + wpinv_update_option( 'paypal_active', 1 ); |
|
661 | + |
|
662 | + if ( ! empty( $data['error_description'] ) ) { |
|
663 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
664 | + } else { |
|
665 | + |
|
666 | + // Retrieve the user info. |
|
667 | + $user_info = wp_remote_get( |
|
668 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
669 | + array( |
|
670 | + |
|
671 | + 'headers' => array( |
|
672 | + 'Authorization' => 'Bearer ' . $access_token, |
|
673 | + 'Content-type' => 'application/json', |
|
674 | + ), |
|
675 | + |
|
676 | + ) |
|
677 | + ); |
|
678 | + |
|
679 | + if ( is_wp_error( $user_info ) ) { |
|
680 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
681 | + } else { |
|
682 | + |
|
683 | + // Create application. |
|
684 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
685 | + |
|
686 | + if ( $sandbox ) { |
|
687 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
688 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
689 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
690 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
691 | + } else { |
|
692 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
693 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
694 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
695 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
696 | + } |
|
697 | 697 | } |
698 | 698 | } |
699 | 699 | |
700 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
700 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
701 | 701 | |
702 | - if ( isset( $data['step'] ) ) { |
|
703 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
704 | - } |
|
705 | - wp_redirect( $redirect ); |
|
706 | - exit; |
|
707 | - } |
|
702 | + if ( isset( $data['step'] ) ) { |
|
703 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
704 | + } |
|
705 | + wp_redirect( $redirect ); |
|
706 | + exit; |
|
707 | + } |
|
708 | 708 | |
709 | 709 | } |