@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | 'getpaid-nonce', |
58 | 58 | 'getpaid-nonce' |
59 | 59 | ); |
60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
60 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
61 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
63 | 63 | |
64 | 64 | } else if( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | 'getpaid-nonce', |
74 | 74 | 'getpaid-nonce' |
75 | 75 | ); |
76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
76 | + $anchor = __( 'Activate', 'invoicing' ); |
|
77 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
79 | 79 | |
80 | 80 | } |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | 'getpaid-nonce' |
92 | 92 | ) |
93 | 93 | ); |
94 | - $anchor = __( 'Delete', 'invoicing' ); |
|
95 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
94 | + $anchor = __( 'Delete', 'invoicing' ); |
|
95 | + $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
96 | 96 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
97 | 97 | |
98 | 98 | $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
@@ -14,70 +14,70 @@ discard block |
||
14 | 14 | class WPInv_Ajax { |
15 | 15 | |
16 | 16 | /** |
17 | - * Hook in ajax handlers. |
|
18 | - */ |
|
19 | - public static function init() { |
|
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | - self::add_ajax_events(); |
|
17 | + * Hook in ajax handlers. |
|
18 | + */ |
|
19 | + public static function init() { |
|
20 | + add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | + add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
22 | + self::add_ajax_events(); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Set GetPaid AJAX constant and headers. |
|
27 | - */ |
|
28 | - public static function define_ajax() { |
|
29 | - |
|
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | - } |
|
36 | - $GLOBALS['wpdb']->hide_errors(); |
|
37 | - } |
|
26 | + * Set GetPaid AJAX constant and headers. |
|
27 | + */ |
|
28 | + public static function define_ajax() { |
|
29 | + |
|
30 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | + getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | + getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | + if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
35 | + } |
|
36 | + $GLOBALS['wpdb']->hide_errors(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Send headers for GetPaid Ajax Requests. |
|
43 | - * |
|
44 | - * @since 1.0.18 |
|
45 | - */ |
|
46 | - private static function wpinv_ajax_headers() { |
|
47 | - if ( ! headers_sent() ) { |
|
48 | - send_origin_headers(); |
|
49 | - send_nosniff_header(); |
|
50 | - nocache_headers(); |
|
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
54 | - } |
|
42 | + * Send headers for GetPaid Ajax Requests. |
|
43 | + * |
|
44 | + * @since 1.0.18 |
|
45 | + */ |
|
46 | + private static function wpinv_ajax_headers() { |
|
47 | + if ( ! headers_sent() ) { |
|
48 | + send_origin_headers(); |
|
49 | + send_nosniff_header(); |
|
50 | + nocache_headers(); |
|
51 | + header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | + header( 'X-Robots-Tag: noindex' ); |
|
53 | + status_header( 200 ); |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | - * Check for GetPaid Ajax request and fire action. |
|
59 | - */ |
|
60 | - public static function do_wpinv_ajax() { |
|
61 | - global $wp_query; |
|
58 | + * Check for GetPaid Ajax request and fire action. |
|
59 | + */ |
|
60 | + public static function do_wpinv_ajax() { |
|
61 | + global $wp_query; |
|
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | - } |
|
63 | + if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | + $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
65 | + } |
|
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get( 'wpinv-ajax' ); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
70 | - self::wpinv_ajax_headers(); |
|
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
73 | - wp_die(); |
|
74 | - } |
|
69 | + if ( $action ) { |
|
70 | + self::wpinv_ajax_headers(); |
|
71 | + $action = sanitize_text_field( $action ); |
|
72 | + do_action( 'wpinv_ajax_' . $action ); |
|
73 | + wp_die(); |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Hook in ajax methods. |
|
80 | - */ |
|
79 | + * Hook in ajax methods. |
|
80 | + */ |
|
81 | 81 | public static function add_ajax_events() { |
82 | 82 | |
83 | 83 | // array( 'event' => is_frontend ) |
@@ -259,24 +259,24 @@ discard block |
||
259 | 259 | check_ajax_referer( 'getpaid_form_nonce' ); |
260 | 260 | |
261 | 261 | // Is the request set up correctly? |
262 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
263 | - echo aui()->alert( |
|
264 | - array( |
|
265 | - 'type' => 'warning', |
|
266 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
267 | - ) |
|
262 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
263 | + echo aui()->alert( |
|
264 | + array( |
|
265 | + 'type' => 'warning', |
|
266 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
267 | + ) |
|
268 | 268 | ); |
269 | 269 | exit; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Payment form or button? |
273 | - if ( ! empty( $_GET['form'] ) ) { |
|
273 | + if ( ! empty( $_GET['form'] ) ) { |
|
274 | 274 | getpaid_display_payment_form( urldecode( $_GET['form'] ) ); |
275 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
276 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
275 | + } else if( ! empty( $_GET['invoice'] ) ) { |
|
276 | + getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
277 | 277 | } else { |
278 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
279 | - getpaid_display_item_payment_form( $items ); |
|
278 | + $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
279 | + getpaid_display_item_payment_form( $items ); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | exit; |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | if ( is_wp_error( $error ) ) { |
598 | 598 | $alert = $error->get_error_message(); |
599 | 599 | wp_send_json_success( compact( 'alert' ) ); |
600 | - } |
|
600 | + } |
|
601 | 601 | |
602 | 602 | // Update totals. |
603 | 603 | $invoice->recalculate_total(); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -319,10 +319,10 @@ discard block |
||
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
322 | - * Output the metabox. |
|
323 | - * |
|
324 | - * @param WP_Post $post |
|
325 | - */ |
|
322 | + * Output the metabox. |
|
323 | + * |
|
324 | + * @param WP_Post $post |
|
325 | + */ |
|
326 | 326 | public static function output2( $post ) { |
327 | 327 | |
328 | 328 | // Prepare the invoice. |
@@ -15,12 +15,12 @@ discard block |
||
15 | 15 | */ |
16 | 16 | |
17 | 17 | if ( ! defined( 'ABSPATH' ) ) { |
18 | - exit; |
|
18 | + exit; |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | if ( ! class_exists( 'AyeCode_Deactivation_Survey' ) ) { |
22 | - // include the class if needed |
|
23 | - include_once( dirname( __FILE__ ) . "/wp-deactivation-survey.php" ); |
|
22 | + // include the class if needed |
|
23 | + include_once( dirname( __FILE__ ) . "/wp-deactivation-survey.php" ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | |
@@ -36,6 +36,6 @@ discard block |
||
36 | 36 | //}); |
37 | 37 | |
38 | 38 | AyeCode_Deactivation_Survey::instance(array( |
39 | - 'slug' => 'ayecode-deactivation-survey-testing', |
|
40 | - 'version' => '1.0.0' |
|
39 | + 'slug' => 'ayecode-deactivation-survey-testing', |
|
40 | + 'version' => '1.0.0' |
|
41 | 41 | )); |
42 | 42 | \ No newline at end of file |
@@ -1,102 +1,102 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; |
|
4 | + exit; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | if ( ! class_exists( 'AyeCode_Deactivation_Survey' ) ) { |
8 | 8 | |
9 | - class AyeCode_Deactivation_Survey { |
|
9 | + class AyeCode_Deactivation_Survey { |
|
10 | 10 | |
11 | - /** |
|
12 | - * AyeCode_Deactivation_Survey instance. |
|
13 | - * |
|
14 | - * @access private |
|
15 | - * @since 1.0.0 |
|
16 | - * @var AyeCode_Deactivation_Survey There can be only one! |
|
17 | - */ |
|
18 | - private static $instance = null; |
|
11 | + /** |
|
12 | + * AyeCode_Deactivation_Survey instance. |
|
13 | + * |
|
14 | + * @access private |
|
15 | + * @since 1.0.0 |
|
16 | + * @var AyeCode_Deactivation_Survey There can be only one! |
|
17 | + */ |
|
18 | + private static $instance = null; |
|
19 | 19 | |
20 | - public static $plugins; |
|
20 | + public static $plugins; |
|
21 | 21 | |
22 | - public $version = "1.0.3"; |
|
22 | + public $version = "1.0.3"; |
|
23 | 23 | |
24 | - public static function instance( $plugin = array() ) { |
|
25 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) { |
|
26 | - self::$instance = new AyeCode_Deactivation_Survey; |
|
27 | - self::$plugins = array(); |
|
24 | + public static function instance( $plugin = array() ) { |
|
25 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) { |
|
26 | + self::$instance = new AyeCode_Deactivation_Survey; |
|
27 | + self::$plugins = array(); |
|
28 | 28 | |
29 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) ); |
|
29 | + add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) ); |
|
30 | 30 | |
31 | - do_action( 'ayecode_deactivation_survey_loaded' ); |
|
32 | - } |
|
31 | + do_action( 'ayecode_deactivation_survey_loaded' ); |
|
32 | + } |
|
33 | 33 | |
34 | - if(!empty($plugin)){ |
|
35 | - self::$plugins[] = (object)$plugin; |
|
36 | - } |
|
34 | + if(!empty($plugin)){ |
|
35 | + self::$plugins[] = (object)$plugin; |
|
36 | + } |
|
37 | 37 | |
38 | - return self::$instance; |
|
39 | - } |
|
38 | + return self::$instance; |
|
39 | + } |
|
40 | 40 | |
41 | - public function scripts() { |
|
42 | - global $pagenow; |
|
41 | + public function scripts() { |
|
42 | + global $pagenow; |
|
43 | 43 | |
44 | - // Bail if we are not on the plugins page |
|
45 | - if ( $pagenow != "plugins.php" ) { |
|
46 | - return; |
|
47 | - } |
|
44 | + // Bail if we are not on the plugins page |
|
45 | + if ( $pagenow != "plugins.php" ) { |
|
46 | + return; |
|
47 | + } |
|
48 | 48 | |
49 | - // Enqueue scripts |
|
50 | - add_thickbox(); |
|
51 | - wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js'); |
|
49 | + // Enqueue scripts |
|
50 | + add_thickbox(); |
|
51 | + wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js'); |
|
52 | 52 | |
53 | - /* |
|
53 | + /* |
|
54 | 54 | * Localized strings. Strings can be localised by plugins using this class. |
55 | 55 | * We deliberately don't add textdomains here so that double textdomain warning is not given in theme review. |
56 | 56 | */ |
57 | - wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array( |
|
58 | - 'quick_feedback' => 'Quick Feedback', |
|
59 | - 'foreword' => 'If you would be kind enough, please tell us why you\'re deactivating?', |
|
60 | - 'better_plugins_name' => 'Please tell us which plugin?', |
|
61 | - 'please_tell_us' => 'Please tell us the reason so we can improve the plugin', |
|
62 | - 'do_not_attach_email' => 'Do not send my e-mail address with this feedback', |
|
63 | - 'brief_description' => 'Please give us any feedback that could help us improve', |
|
64 | - 'cancel' => 'Cancel', |
|
65 | - 'skip_and_deactivate' => 'Skip & Deactivate', |
|
66 | - 'submit_and_deactivate' => 'Submit & Deactivate', |
|
67 | - 'please_wait' => 'Please wait', |
|
68 | - 'get_support' => 'Get Support', |
|
69 | - 'documentation' => 'Documentation', |
|
70 | - 'thank_you' => 'Thank you!', |
|
71 | - )); |
|
72 | - |
|
73 | - // Plugins |
|
74 | - $plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins); |
|
75 | - |
|
76 | - // Reasons |
|
77 | - $defaultReasons = array( |
|
78 | - 'suddenly-stopped-working' => 'The plugin suddenly stopped working', |
|
79 | - 'plugin-broke-site' => 'The plugin broke my site', |
|
80 | - 'plugin-setup-difficult' => 'Too difficult to setup', |
|
81 | - 'no-longer-needed' => 'I don\'t need this plugin any more', |
|
82 | - 'found-better-plugin' => 'I found a better plugin', |
|
83 | - 'temporary-deactivation' => 'It\'s a temporary deactivation, I\'m troubleshooting', |
|
84 | - 'other' => 'Other', |
|
85 | - ); |
|
86 | - |
|
87 | - foreach($plugins as $plugin) |
|
88 | - { |
|
89 | - $plugin->reasons = apply_filters('ayecode_deactivation_survey_reasons', $defaultReasons, $plugin); |
|
90 | - $plugin->url = home_url(); |
|
91 | - $plugin->activated = 0; |
|
92 | - } |
|
93 | - |
|
94 | - // Send plugin data |
|
95 | - wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins); |
|
96 | - |
|
97 | - } |
|
57 | + wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array( |
|
58 | + 'quick_feedback' => 'Quick Feedback', |
|
59 | + 'foreword' => 'If you would be kind enough, please tell us why you\'re deactivating?', |
|
60 | + 'better_plugins_name' => 'Please tell us which plugin?', |
|
61 | + 'please_tell_us' => 'Please tell us the reason so we can improve the plugin', |
|
62 | + 'do_not_attach_email' => 'Do not send my e-mail address with this feedback', |
|
63 | + 'brief_description' => 'Please give us any feedback that could help us improve', |
|
64 | + 'cancel' => 'Cancel', |
|
65 | + 'skip_and_deactivate' => 'Skip & Deactivate', |
|
66 | + 'submit_and_deactivate' => 'Submit & Deactivate', |
|
67 | + 'please_wait' => 'Please wait', |
|
68 | + 'get_support' => 'Get Support', |
|
69 | + 'documentation' => 'Documentation', |
|
70 | + 'thank_you' => 'Thank you!', |
|
71 | + )); |
|
72 | + |
|
73 | + // Plugins |
|
74 | + $plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins); |
|
75 | + |
|
76 | + // Reasons |
|
77 | + $defaultReasons = array( |
|
78 | + 'suddenly-stopped-working' => 'The plugin suddenly stopped working', |
|
79 | + 'plugin-broke-site' => 'The plugin broke my site', |
|
80 | + 'plugin-setup-difficult' => 'Too difficult to setup', |
|
81 | + 'no-longer-needed' => 'I don\'t need this plugin any more', |
|
82 | + 'found-better-plugin' => 'I found a better plugin', |
|
83 | + 'temporary-deactivation' => 'It\'s a temporary deactivation, I\'m troubleshooting', |
|
84 | + 'other' => 'Other', |
|
85 | + ); |
|
86 | + |
|
87 | + foreach($plugins as $plugin) |
|
88 | + { |
|
89 | + $plugin->reasons = apply_filters('ayecode_deactivation_survey_reasons', $defaultReasons, $plugin); |
|
90 | + $plugin->url = home_url(); |
|
91 | + $plugin->activated = 0; |
|
92 | + } |
|
93 | + |
|
94 | + // Send plugin data |
|
95 | + wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins); |
|
96 | + |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | \ No newline at end of file |
@@ -20,228 +20,228 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
52 | - |
|
53 | - if ( empty( $installed ) ) { |
|
54 | - update_option( 'gepaid_installed_on', time() ); |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $method ) ) { |
|
58 | - $this->$method(); |
|
59 | - } |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Do a fresh install. |
|
65 | - * |
|
66 | - */ |
|
67 | - public function upgrade_from_0() { |
|
68 | - $this->create_subscriptions_table(); |
|
69 | - $this->create_invoices_table(); |
|
70 | - $this->create_invoice_items_table(); |
|
71 | - |
|
72 | - // Save default tax rates. |
|
73 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Upgrade to 0.0.5 |
|
78 | - * |
|
79 | - */ |
|
80 | - public function upgrade_from_004() { |
|
81 | - global $wpdb; |
|
82 | - |
|
83 | - // Invoices. |
|
84 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | - if ( ! empty( $results ) ) { |
|
86 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | - |
|
88 | - // Clean post cache |
|
89 | - foreach ( $results as $row ) { |
|
90 | - clean_post_cache( $row->ID ); |
|
91 | - } |
|
92 | - |
|
93 | - } |
|
94 | - |
|
95 | - // Item meta key changes |
|
96 | - $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
97 | - $results = $wpdb->get_results( $query ); |
|
98 | - |
|
99 | - if ( ! empty( $results ) ) { |
|
100 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
101 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
102 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
103 | - |
|
104 | - foreach ( $results as $row ) { |
|
105 | - clean_post_cache( $row->post_id ); |
|
106 | - } |
|
107 | - |
|
108 | - } |
|
109 | - |
|
110 | - $this->upgrade_from_102(); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Upgrade to 1.0.3 |
|
115 | - * |
|
116 | - */ |
|
117 | - public function upgrade_from_102() { |
|
118 | - $this->create_subscriptions_table(); |
|
119 | - $this->upgrade_from_118(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Upgrade to version 2.0.0. |
|
124 | - * |
|
125 | - */ |
|
126 | - public function upgrade_from_118() { |
|
127 | - $this->create_invoices_table(); |
|
128 | - $this->create_invoice_items_table(); |
|
129 | - $this->migrate_old_invoices(); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Upgrade to version 2.0.8. |
|
134 | - * |
|
135 | - */ |
|
136 | - public function upgrade_from_207() { |
|
137 | - global $wpdb; |
|
138 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Give administrators the capability to manage GetPaid. |
|
143 | - * |
|
144 | - */ |
|
145 | - public function add_capabilities() { |
|
146 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Retreives GetPaid pages. |
|
151 | - * |
|
152 | - */ |
|
153 | - public static function get_pages() { |
|
154 | - |
|
155 | - return apply_filters( |
|
156 | - 'wpinv_create_pages', |
|
157 | - array( |
|
158 | - |
|
159 | - // Checkout page. |
|
160 | - 'checkout_page' => array( |
|
161 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
162 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
163 | - 'content' => ' |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + $installed = get_option( 'gepaid_installed_on' ); |
|
52 | + |
|
53 | + if ( empty( $installed ) ) { |
|
54 | + update_option( 'gepaid_installed_on', time() ); |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $method ) ) { |
|
58 | + $this->$method(); |
|
59 | + } |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Do a fresh install. |
|
65 | + * |
|
66 | + */ |
|
67 | + public function upgrade_from_0() { |
|
68 | + $this->create_subscriptions_table(); |
|
69 | + $this->create_invoices_table(); |
|
70 | + $this->create_invoice_items_table(); |
|
71 | + |
|
72 | + // Save default tax rates. |
|
73 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Upgrade to 0.0.5 |
|
78 | + * |
|
79 | + */ |
|
80 | + public function upgrade_from_004() { |
|
81 | + global $wpdb; |
|
82 | + |
|
83 | + // Invoices. |
|
84 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | + if ( ! empty( $results ) ) { |
|
86 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | + |
|
88 | + // Clean post cache |
|
89 | + foreach ( $results as $row ) { |
|
90 | + clean_post_cache( $row->ID ); |
|
91 | + } |
|
92 | + |
|
93 | + } |
|
94 | + |
|
95 | + // Item meta key changes |
|
96 | + $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
97 | + $results = $wpdb->get_results( $query ); |
|
98 | + |
|
99 | + if ( ! empty( $results ) ) { |
|
100 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
101 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
102 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
103 | + |
|
104 | + foreach ( $results as $row ) { |
|
105 | + clean_post_cache( $row->post_id ); |
|
106 | + } |
|
107 | + |
|
108 | + } |
|
109 | + |
|
110 | + $this->upgrade_from_102(); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Upgrade to 1.0.3 |
|
115 | + * |
|
116 | + */ |
|
117 | + public function upgrade_from_102() { |
|
118 | + $this->create_subscriptions_table(); |
|
119 | + $this->upgrade_from_118(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Upgrade to version 2.0.0. |
|
124 | + * |
|
125 | + */ |
|
126 | + public function upgrade_from_118() { |
|
127 | + $this->create_invoices_table(); |
|
128 | + $this->create_invoice_items_table(); |
|
129 | + $this->migrate_old_invoices(); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Upgrade to version 2.0.8. |
|
134 | + * |
|
135 | + */ |
|
136 | + public function upgrade_from_207() { |
|
137 | + global $wpdb; |
|
138 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Give administrators the capability to manage GetPaid. |
|
143 | + * |
|
144 | + */ |
|
145 | + public function add_capabilities() { |
|
146 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Retreives GetPaid pages. |
|
151 | + * |
|
152 | + */ |
|
153 | + public static function get_pages() { |
|
154 | + |
|
155 | + return apply_filters( |
|
156 | + 'wpinv_create_pages', |
|
157 | + array( |
|
158 | + |
|
159 | + // Checkout page. |
|
160 | + 'checkout_page' => array( |
|
161 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
162 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
163 | + 'content' => ' |
|
164 | 164 | <!-- wp:shortcode --> |
165 | 165 | [wpinv_checkout] |
166 | 166 | <!-- /wp:shortcode --> |
167 | 167 | ', |
168 | - 'parent' => '', |
|
169 | - ), |
|
170 | - |
|
171 | - // Invoice history page. |
|
172 | - 'invoice_history_page' => array( |
|
173 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
174 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
175 | - 'content' => ' |
|
168 | + 'parent' => '', |
|
169 | + ), |
|
170 | + |
|
171 | + // Invoice history page. |
|
172 | + 'invoice_history_page' => array( |
|
173 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
174 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
175 | + 'content' => ' |
|
176 | 176 | <!-- wp:shortcode --> |
177 | 177 | [wpinv_history] |
178 | 178 | <!-- /wp:shortcode --> |
179 | 179 | ', |
180 | - 'parent' => '', |
|
181 | - ), |
|
182 | - |
|
183 | - // Success page content. |
|
184 | - 'success_page' => array( |
|
185 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
186 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
187 | - 'content' => ' |
|
180 | + 'parent' => '', |
|
181 | + ), |
|
182 | + |
|
183 | + // Success page content. |
|
184 | + 'success_page' => array( |
|
185 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
186 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
187 | + 'content' => ' |
|
188 | 188 | <!-- wp:shortcode --> |
189 | 189 | [wpinv_receipt] |
190 | 190 | <!-- /wp:shortcode --> |
191 | 191 | ', |
192 | - 'parent' => 'gp-checkout', |
|
193 | - ), |
|
194 | - |
|
195 | - // Failure page content. |
|
196 | - 'failure_page' => array( |
|
197 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
198 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
199 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
200 | - 'parent' => 'gp-checkout', |
|
201 | - ), |
|
202 | - |
|
203 | - // Subscriptions history page. |
|
204 | - 'invoice_subscription_page' => array( |
|
205 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
206 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
207 | - 'content' => ' |
|
192 | + 'parent' => 'gp-checkout', |
|
193 | + ), |
|
194 | + |
|
195 | + // Failure page content. |
|
196 | + 'failure_page' => array( |
|
197 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
198 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
199 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
200 | + 'parent' => 'gp-checkout', |
|
201 | + ), |
|
202 | + |
|
203 | + // Subscriptions history page. |
|
204 | + 'invoice_subscription_page' => array( |
|
205 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
206 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
207 | + 'content' => ' |
|
208 | 208 | <!-- wp:shortcode --> |
209 | 209 | [wpinv_subscriptions] |
210 | 210 | <!-- /wp:shortcode --> |
211 | 211 | ', |
212 | - 'parent' => '', |
|
213 | - ), |
|
212 | + 'parent' => '', |
|
213 | + ), |
|
214 | 214 | |
215 | - ) |
|
216 | - ); |
|
215 | + ) |
|
216 | + ); |
|
217 | 217 | |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * Re-create GetPaid pages. |
|
222 | - * |
|
223 | - */ |
|
224 | - public function create_pages() { |
|
220 | + /** |
|
221 | + * Re-create GetPaid pages. |
|
222 | + * |
|
223 | + */ |
|
224 | + public function create_pages() { |
|
225 | 225 | |
226 | - foreach ( self::get_pages() as $key => $page ) { |
|
227 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
228 | - } |
|
226 | + foreach ( self::get_pages() as $key => $page ) { |
|
227 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
228 | + } |
|
229 | 229 | |
230 | - } |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Create subscriptions table. |
|
234 | - * |
|
235 | - */ |
|
236 | - public function create_subscriptions_table() { |
|
232 | + /** |
|
233 | + * Create subscriptions table. |
|
234 | + * |
|
235 | + */ |
|
236 | + public function create_subscriptions_table() { |
|
237 | 237 | |
238 | - global $wpdb; |
|
238 | + global $wpdb; |
|
239 | 239 | |
240 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
240 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
241 | 241 | |
242 | - // Create tables. |
|
243 | - $charset_collate = $wpdb->get_charset_collate(); |
|
244 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
242 | + // Create tables. |
|
243 | + $charset_collate = $wpdb->get_charset_collate(); |
|
244 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
245 | 245 | id bigint(20) unsigned NOT NULL auto_increment, |
246 | 246 | customer_id bigint(20) NOT NULL, |
247 | 247 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -264,22 +264,22 @@ discard block |
||
264 | 264 | KEY customer_and_status (customer_id, status) |
265 | 265 | ) $charset_collate;"; |
266 | 266 | |
267 | - dbDelta( $sql ); |
|
267 | + dbDelta( $sql ); |
|
268 | 268 | |
269 | - } |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * Create invoices table. |
|
273 | - * |
|
274 | - */ |
|
275 | - public function create_invoices_table() { |
|
276 | - global $wpdb; |
|
271 | + /** |
|
272 | + * Create invoices table. |
|
273 | + * |
|
274 | + */ |
|
275 | + public function create_invoices_table() { |
|
276 | + global $wpdb; |
|
277 | 277 | |
278 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
278 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
279 | 279 | |
280 | - // Create tables. |
|
281 | - $charset_collate = $wpdb->get_charset_collate(); |
|
282 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
280 | + // Create tables. |
|
281 | + $charset_collate = $wpdb->get_charset_collate(); |
|
282 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
283 | 283 | post_id BIGINT(20) NOT NULL, |
284 | 284 | `number` VARCHAR(100), |
285 | 285 | `key` VARCHAR(100), |
@@ -315,22 +315,22 @@ discard block |
||
315 | 315 | KEY `key` (`key`) |
316 | 316 | ) $charset_collate;"; |
317 | 317 | |
318 | - dbDelta( $sql ); |
|
318 | + dbDelta( $sql ); |
|
319 | 319 | |
320 | - } |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Create invoice items table. |
|
324 | - * |
|
325 | - */ |
|
326 | - public function create_invoice_items_table() { |
|
327 | - global $wpdb; |
|
322 | + /** |
|
323 | + * Create invoice items table. |
|
324 | + * |
|
325 | + */ |
|
326 | + public function create_invoice_items_table() { |
|
327 | + global $wpdb; |
|
328 | 328 | |
329 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
329 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
330 | 330 | |
331 | - // Create tables. |
|
332 | - $charset_collate = $wpdb->get_charset_collate(); |
|
333 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
331 | + // Create tables. |
|
332 | + $charset_collate = $wpdb->get_charset_collate(); |
|
333 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
334 | 334 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
335 | 335 | post_id BIGINT(20) NOT NULL, |
336 | 336 | item_id BIGINT(20) NOT NULL, |
@@ -352,159 +352,159 @@ discard block |
||
352 | 352 | KEY post_id (post_id) |
353 | 353 | ) $charset_collate;"; |
354 | 354 | |
355 | - dbDelta( $sql ); |
|
356 | - |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Migrates old invoices to new invoices. |
|
361 | - * |
|
362 | - */ |
|
363 | - public function migrate_old_invoices() { |
|
364 | - global $wpdb; |
|
365 | - |
|
366 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
367 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
368 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
369 | - $invoices = array_unique( |
|
370 | - get_posts( |
|
371 | - array( |
|
372 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
373 | - 'posts_per_page' => -1, |
|
374 | - 'fields' => 'ids', |
|
375 | - 'post_status' => array_keys( get_post_stati() ), |
|
376 | - 'exclude' => (array) $migrated, |
|
377 | - ) |
|
378 | - ) |
|
379 | - ); |
|
380 | - |
|
381 | - // Abort if we do not have any invoices. |
|
382 | - if ( empty( $invoices ) ) { |
|
383 | - return; |
|
384 | - } |
|
385 | - |
|
386 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
387 | - |
|
388 | - $invoice_rows = array(); |
|
389 | - foreach ( $invoices as $invoice ) { |
|
390 | - |
|
391 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
392 | - |
|
393 | - if ( empty( $invoice->ID ) ) { |
|
394 | - return; |
|
395 | - } |
|
396 | - |
|
397 | - $fields = array ( |
|
398 | - 'post_id' => $invoice->ID, |
|
399 | - 'number' => $invoice->get_number(), |
|
400 | - 'key' => $invoice->get_key(), |
|
401 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
402 | - 'mode' => $invoice->mode, |
|
403 | - 'user_ip' => $invoice->get_ip(), |
|
404 | - 'first_name' => $invoice->get_first_name(), |
|
405 | - 'last_name' => $invoice->get_last_name(), |
|
406 | - 'address' => $invoice->get_address(), |
|
407 | - 'city' => $invoice->city, |
|
408 | - 'state' => $invoice->state, |
|
409 | - 'country' => $invoice->country, |
|
410 | - 'zip' => $invoice->zip, |
|
411 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
412 | - 'gateway' => $invoice->get_gateway(), |
|
413 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
414 | - 'currency' => $invoice->get_currency(), |
|
415 | - 'subtotal' => $invoice->get_subtotal(), |
|
416 | - 'tax' => $invoice->get_tax(), |
|
417 | - 'fees_total' => $invoice->get_fees_total(), |
|
418 | - 'total' => $invoice->get_total(), |
|
419 | - 'discount' => $invoice->get_discount(), |
|
420 | - 'discount_code' => $invoice->get_discount_code(), |
|
421 | - 'disable_taxes' => $invoice->disable_taxes, |
|
422 | - 'due_date' => $invoice->get_due_date(), |
|
423 | - 'completed_date' => $invoice->get_completed_date(), |
|
424 | - 'company' => $invoice->company, |
|
425 | - 'vat_number' => $invoice->vat_number, |
|
426 | - 'vat_rate' => $invoice->vat_rate, |
|
427 | - 'custom_meta' => $invoice->payment_meta |
|
428 | - ); |
|
429 | - |
|
430 | - foreach ( $fields as $key => $val ) { |
|
431 | - if ( is_null( $val ) ) { |
|
432 | - $val = ''; |
|
433 | - } |
|
434 | - $val = maybe_serialize( $val ); |
|
435 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
436 | - } |
|
437 | - |
|
438 | - $fields = implode( ', ', $fields ); |
|
439 | - $invoice_rows[] = "($fields)"; |
|
440 | - |
|
441 | - $item_rows = array(); |
|
442 | - $item_columns = array(); |
|
443 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
444 | - $fields = array( |
|
445 | - 'post_id' => $invoice->ID, |
|
446 | - 'item_id' => $details['id'], |
|
447 | - 'item_name' => $details['name'], |
|
448 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
449 | - 'vat_rate' => $details['vat_rate'], |
|
450 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
451 | - 'tax' => $details['tax'], |
|
452 | - 'item_price' => $details['item_price'], |
|
453 | - 'custom_price' => $details['custom_price'], |
|
454 | - 'quantity' => $details['quantity'], |
|
455 | - 'discount' => $details['discount'], |
|
456 | - 'subtotal' => $details['subtotal'], |
|
457 | - 'price' => $details['price'], |
|
458 | - 'meta' => $details['meta'], |
|
459 | - 'fees' => $details['fees'], |
|
460 | - ); |
|
461 | - |
|
462 | - $item_columns = array_keys ( $fields ); |
|
463 | - |
|
464 | - foreach ( $fields as $key => $val ) { |
|
465 | - if ( is_null( $val ) ) { |
|
466 | - $val = ''; |
|
467 | - } |
|
468 | - $val = maybe_serialize( $val ); |
|
469 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
470 | - } |
|
471 | - |
|
472 | - $fields = implode( ', ', $fields ); |
|
473 | - $item_rows[] = "($fields)"; |
|
474 | - } |
|
475 | - |
|
476 | - $item_rows = implode( ', ', $item_rows ); |
|
477 | - $item_columns = implode( ', ', $item_columns ); |
|
478 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
479 | - } |
|
480 | - |
|
481 | - if ( empty( $invoice_rows ) ) { |
|
482 | - return; |
|
483 | - } |
|
484 | - |
|
485 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
486 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
487 | - |
|
488 | - } |
|
489 | - |
|
490 | - /** |
|
491 | - * Migrates old invoices to new invoices. |
|
492 | - * |
|
493 | - */ |
|
494 | - public static function rename_gateways_label() { |
|
495 | - global $wpdb; |
|
496 | - |
|
497 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
498 | - |
|
499 | - $wpdb->update( |
|
500 | - $wpdb->prefix . 'getpaid_invoices', |
|
501 | - array( 'gateway' => $gateway ), |
|
502 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
503 | - '%s', |
|
504 | - '%s' |
|
505 | - ); |
|
506 | - |
|
507 | - } |
|
508 | - } |
|
355 | + dbDelta( $sql ); |
|
356 | + |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Migrates old invoices to new invoices. |
|
361 | + * |
|
362 | + */ |
|
363 | + public function migrate_old_invoices() { |
|
364 | + global $wpdb; |
|
365 | + |
|
366 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
367 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
368 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
369 | + $invoices = array_unique( |
|
370 | + get_posts( |
|
371 | + array( |
|
372 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
373 | + 'posts_per_page' => -1, |
|
374 | + 'fields' => 'ids', |
|
375 | + 'post_status' => array_keys( get_post_stati() ), |
|
376 | + 'exclude' => (array) $migrated, |
|
377 | + ) |
|
378 | + ) |
|
379 | + ); |
|
380 | + |
|
381 | + // Abort if we do not have any invoices. |
|
382 | + if ( empty( $invoices ) ) { |
|
383 | + return; |
|
384 | + } |
|
385 | + |
|
386 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
387 | + |
|
388 | + $invoice_rows = array(); |
|
389 | + foreach ( $invoices as $invoice ) { |
|
390 | + |
|
391 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
392 | + |
|
393 | + if ( empty( $invoice->ID ) ) { |
|
394 | + return; |
|
395 | + } |
|
396 | + |
|
397 | + $fields = array ( |
|
398 | + 'post_id' => $invoice->ID, |
|
399 | + 'number' => $invoice->get_number(), |
|
400 | + 'key' => $invoice->get_key(), |
|
401 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
402 | + 'mode' => $invoice->mode, |
|
403 | + 'user_ip' => $invoice->get_ip(), |
|
404 | + 'first_name' => $invoice->get_first_name(), |
|
405 | + 'last_name' => $invoice->get_last_name(), |
|
406 | + 'address' => $invoice->get_address(), |
|
407 | + 'city' => $invoice->city, |
|
408 | + 'state' => $invoice->state, |
|
409 | + 'country' => $invoice->country, |
|
410 | + 'zip' => $invoice->zip, |
|
411 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
412 | + 'gateway' => $invoice->get_gateway(), |
|
413 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
414 | + 'currency' => $invoice->get_currency(), |
|
415 | + 'subtotal' => $invoice->get_subtotal(), |
|
416 | + 'tax' => $invoice->get_tax(), |
|
417 | + 'fees_total' => $invoice->get_fees_total(), |
|
418 | + 'total' => $invoice->get_total(), |
|
419 | + 'discount' => $invoice->get_discount(), |
|
420 | + 'discount_code' => $invoice->get_discount_code(), |
|
421 | + 'disable_taxes' => $invoice->disable_taxes, |
|
422 | + 'due_date' => $invoice->get_due_date(), |
|
423 | + 'completed_date' => $invoice->get_completed_date(), |
|
424 | + 'company' => $invoice->company, |
|
425 | + 'vat_number' => $invoice->vat_number, |
|
426 | + 'vat_rate' => $invoice->vat_rate, |
|
427 | + 'custom_meta' => $invoice->payment_meta |
|
428 | + ); |
|
429 | + |
|
430 | + foreach ( $fields as $key => $val ) { |
|
431 | + if ( is_null( $val ) ) { |
|
432 | + $val = ''; |
|
433 | + } |
|
434 | + $val = maybe_serialize( $val ); |
|
435 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
436 | + } |
|
437 | + |
|
438 | + $fields = implode( ', ', $fields ); |
|
439 | + $invoice_rows[] = "($fields)"; |
|
440 | + |
|
441 | + $item_rows = array(); |
|
442 | + $item_columns = array(); |
|
443 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
444 | + $fields = array( |
|
445 | + 'post_id' => $invoice->ID, |
|
446 | + 'item_id' => $details['id'], |
|
447 | + 'item_name' => $details['name'], |
|
448 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
449 | + 'vat_rate' => $details['vat_rate'], |
|
450 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
451 | + 'tax' => $details['tax'], |
|
452 | + 'item_price' => $details['item_price'], |
|
453 | + 'custom_price' => $details['custom_price'], |
|
454 | + 'quantity' => $details['quantity'], |
|
455 | + 'discount' => $details['discount'], |
|
456 | + 'subtotal' => $details['subtotal'], |
|
457 | + 'price' => $details['price'], |
|
458 | + 'meta' => $details['meta'], |
|
459 | + 'fees' => $details['fees'], |
|
460 | + ); |
|
461 | + |
|
462 | + $item_columns = array_keys ( $fields ); |
|
463 | + |
|
464 | + foreach ( $fields as $key => $val ) { |
|
465 | + if ( is_null( $val ) ) { |
|
466 | + $val = ''; |
|
467 | + } |
|
468 | + $val = maybe_serialize( $val ); |
|
469 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
470 | + } |
|
471 | + |
|
472 | + $fields = implode( ', ', $fields ); |
|
473 | + $item_rows[] = "($fields)"; |
|
474 | + } |
|
475 | + |
|
476 | + $item_rows = implode( ', ', $item_rows ); |
|
477 | + $item_columns = implode( ', ', $item_columns ); |
|
478 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
479 | + } |
|
480 | + |
|
481 | + if ( empty( $invoice_rows ) ) { |
|
482 | + return; |
|
483 | + } |
|
484 | + |
|
485 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
486 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
487 | + |
|
488 | + } |
|
489 | + |
|
490 | + /** |
|
491 | + * Migrates old invoices to new invoices. |
|
492 | + * |
|
493 | + */ |
|
494 | + public static function rename_gateways_label() { |
|
495 | + global $wpdb; |
|
496 | + |
|
497 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
498 | + |
|
499 | + $wpdb->update( |
|
500 | + $wpdb->prefix . 'getpaid_invoices', |
|
501 | + array( 'gateway' => $gateway ), |
|
502 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
503 | + '%s', |
|
504 | + '%s' |
|
505 | + ); |
|
506 | + |
|
507 | + } |
|
508 | + } |
|
509 | 509 | |
510 | 510 | } |
@@ -12,180 +12,180 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Checkout { |
14 | 14 | |
15 | - /** |
|
16 | - * @var GetPaid_Payment_Form_Submission |
|
17 | - */ |
|
18 | - protected $payment_form_submission; |
|
19 | - |
|
20 | - /** |
|
21 | - * Class constructor. |
|
22 | - * |
|
23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
24 | - */ |
|
25 | - public function __construct( $submission ) { |
|
26 | - $this->payment_form_submission = $submission; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Processes the checkout. |
|
31 | - * |
|
32 | - */ |
|
33 | - public function process_checkout() { |
|
34 | - |
|
35 | - // Validate the submission. |
|
36 | - $this->validate_submission(); |
|
37 | - |
|
38 | - // Prepare the invoice. |
|
39 | - $items = $this->get_submission_items(); |
|
40 | - $invoice = $this->get_submission_invoice(); |
|
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | - |
|
44 | - $this->prepare_billing_info( $invoice ); |
|
45 | - |
|
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | - |
|
48 | - // Save the invoice. |
|
49 | - $invoice->set_is_viewed( true ); |
|
50 | - $invoice->recalculate_total(); |
|
15 | + /** |
|
16 | + * @var GetPaid_Payment_Form_Submission |
|
17 | + */ |
|
18 | + protected $payment_form_submission; |
|
19 | + |
|
20 | + /** |
|
21 | + * Class constructor. |
|
22 | + * |
|
23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
24 | + */ |
|
25 | + public function __construct( $submission ) { |
|
26 | + $this->payment_form_submission = $submission; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Processes the checkout. |
|
31 | + * |
|
32 | + */ |
|
33 | + public function process_checkout() { |
|
34 | + |
|
35 | + // Validate the submission. |
|
36 | + $this->validate_submission(); |
|
37 | + |
|
38 | + // Prepare the invoice. |
|
39 | + $items = $this->get_submission_items(); |
|
40 | + $invoice = $this->get_submission_invoice(); |
|
41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
43 | + |
|
44 | + $this->prepare_billing_info( $invoice ); |
|
45 | + |
|
46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
47 | + |
|
48 | + // Save the invoice. |
|
49 | + $invoice->set_is_viewed( true ); |
|
50 | + $invoice->recalculate_total(); |
|
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
54 | 54 | |
55 | - // Send to the gateway. |
|
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | - } |
|
55 | + // Send to the gateway. |
|
56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Validates the submission. |
|
61 | - * |
|
62 | - */ |
|
63 | - protected function validate_submission() { |
|
59 | + /** |
|
60 | + * Validates the submission. |
|
61 | + * |
|
62 | + */ |
|
63 | + protected function validate_submission() { |
|
64 | 64 | |
65 | - $submission = $this->payment_form_submission; |
|
66 | - $data = $submission->get_data(); |
|
65 | + $submission = $this->payment_form_submission; |
|
66 | + $data = $submission->get_data(); |
|
67 | 67 | |
68 | - // Do we have an error? |
|
68 | + // Do we have an error? |
|
69 | 69 | if ( ! empty( $submission->last_error ) ) { |
70 | - wp_send_json_error( $submission->last_error ); |
|
70 | + wp_send_json_error( $submission->last_error ); |
|
71 | 71 | } |
72 | 72 | |
73 | - // We need a billing email. |
|
73 | + // We need a billing email. |
|
74 | 74 | if ( ! $submission->has_billing_email() ) { |
75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | - } |
|
78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
81 | + } |
|
82 | 82 | |
83 | - // Ensure the gateway is active. |
|
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | - } |
|
83 | + // Ensure the gateway is active. |
|
84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
86 | + } |
|
87 | 87 | |
88 | - // Clear any existing errors. |
|
89 | - wpinv_clear_errors(); |
|
88 | + // Clear any existing errors. |
|
89 | + wpinv_clear_errors(); |
|
90 | 90 | |
91 | - // Allow themes and plugins to hook to errors |
|
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
91 | + // Allow themes and plugins to hook to errors |
|
92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
93 | 93 | |
94 | - // Do we have any errors? |
|
94 | + // Do we have any errors? |
|
95 | 95 | if ( wpinv_get_errors() ) { |
96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Retrieves submission items. |
|
103 | - * |
|
104 | - * @return GetPaid_Form_Item[] |
|
105 | - */ |
|
106 | - protected function get_submission_items() { |
|
101 | + /** |
|
102 | + * Retrieves submission items. |
|
103 | + * |
|
104 | + * @return GetPaid_Form_Item[] |
|
105 | + */ |
|
106 | + protected function get_submission_items() { |
|
107 | 107 | |
108 | - $items = $this->payment_form_submission->get_items(); |
|
108 | + $items = $this->payment_form_submission->get_items(); |
|
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
113 | - } |
|
114 | - |
|
115 | - return $items; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieves submission invoice. |
|
120 | - * |
|
121 | - * @return WPInv_Invoice |
|
122 | - */ |
|
123 | - protected function get_submission_invoice() { |
|
124 | - $submission = $this->payment_form_submission; |
|
125 | - |
|
126 | - if ( ! $submission->has_invoice() ) { |
|
127 | - $invoice = new WPInv_Invoice(); |
|
128 | - $invoice->set_created_via( 'payment_form' ); |
|
129 | - return $invoice; |
|
130 | 113 | } |
131 | 114 | |
132 | - $invoice = $submission->get_invoice(); |
|
115 | + return $items; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Retrieves submission invoice. |
|
120 | + * |
|
121 | + * @return WPInv_Invoice |
|
122 | + */ |
|
123 | + protected function get_submission_invoice() { |
|
124 | + $submission = $this->payment_form_submission; |
|
125 | + |
|
126 | + if ( ! $submission->has_invoice() ) { |
|
127 | + $invoice = new WPInv_Invoice(); |
|
128 | + $invoice->set_created_via( 'payment_form' ); |
|
129 | + return $invoice; |
|
130 | + } |
|
131 | + |
|
132 | + $invoice = $submission->get_invoice(); |
|
133 | 133 | |
134 | - // Make sure that it is neither paid or refunded. |
|
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | - } |
|
134 | + // Make sure that it is neither paid or refunded. |
|
135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
137 | + } |
|
138 | 138 | |
139 | - return $invoice; |
|
140 | - } |
|
139 | + return $invoice; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Processes the submission invoice. |
|
144 | - * |
|
145 | - * @param WPInv_Invoice $invoice |
|
146 | - * @param GetPaid_Form_Item[] $items |
|
147 | - * @return WPInv_Invoice |
|
148 | - */ |
|
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
142 | + /** |
|
143 | + * Processes the submission invoice. |
|
144 | + * |
|
145 | + * @param WPInv_Invoice $invoice |
|
146 | + * @param GetPaid_Form_Item[] $items |
|
147 | + * @return WPInv_Invoice |
|
148 | + */ |
|
149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
150 | 150 | |
151 | - $submission = $this->payment_form_submission; |
|
152 | - $data = $submission->get_data(); |
|
151 | + $submission = $this->payment_form_submission; |
|
152 | + $data = $submission->get_data(); |
|
153 | 153 | |
154 | - // Set-up the invoice details. |
|
155 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
154 | + // Set-up the invoice details. |
|
155 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
156 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
157 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
158 | 158 | $invoice->set_items( $items ); |
159 | 159 | $invoice->set_fees( $submission->get_fees() ); |
160 | 160 | $invoice->set_taxes( $submission->get_taxes() ); |
161 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
161 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
162 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
163 | 163 | |
164 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
164 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
165 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
166 | 166 | |
167 | - if ( $submission->has_discount_code() ) { |
|
167 | + if ( $submission->has_discount_code() ) { |
|
168 | 168 | $invoice->set_discount_code( $submission->get_discount_code() ); |
169 | - } |
|
170 | - |
|
171 | - getpaid_maybe_add_default_address( $invoice ); |
|
172 | - return $invoice; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Retrieves the submission's customer. |
|
177 | - * |
|
178 | - * @return int The customer id. |
|
179 | - */ |
|
180 | - protected function get_submission_customer() { |
|
181 | - $submission = $this->payment_form_submission; |
|
182 | - |
|
183 | - // If this is an existing invoice... |
|
184 | - if ( $submission->has_invoice() ) { |
|
185 | - return $submission->get_invoice()->get_user_id(); |
|
186 | - } |
|
187 | - |
|
188 | - // (Maybe) create the user. |
|
169 | + } |
|
170 | + |
|
171 | + getpaid_maybe_add_default_address( $invoice ); |
|
172 | + return $invoice; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Retrieves the submission's customer. |
|
177 | + * |
|
178 | + * @return int The customer id. |
|
179 | + */ |
|
180 | + protected function get_submission_customer() { |
|
181 | + $submission = $this->payment_form_submission; |
|
182 | + |
|
183 | + // If this is an existing invoice... |
|
184 | + if ( $submission->has_invoice() ) { |
|
185 | + return $submission->get_invoice()->get_user_id(); |
|
186 | + } |
|
187 | + |
|
188 | + // (Maybe) create the user. |
|
189 | 189 | $user = get_current_user_id(); |
190 | 190 | |
191 | 191 | if ( empty( $user ) ) { |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | if ( empty( $user ) ) { |
196 | 196 | $user = wpinv_create_user( $submission->get_billing_email() ); |
197 | 197 | |
198 | - // (Maybe) send new user notification. |
|
199 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
200 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
201 | - wp_send_new_user_notifications( $user, 'user' ); |
|
202 | - } |
|
198 | + // (Maybe) send new user notification. |
|
199 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
200 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
201 | + wp_send_new_user_notifications( $user, 'user' ); |
|
202 | + } |
|
203 | 203 | |
204 | 204 | } |
205 | 205 | |
@@ -209,34 +209,34 @@ discard block |
||
209 | 209 | |
210 | 210 | if ( is_numeric( $user ) ) { |
211 | 211 | return $user; |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - return $user->ID; |
|
214 | + return $user->ID; |
|
215 | 215 | |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
218 | + /** |
|
219 | 219 | * Prepares submission data for saving to the database. |
220 | 220 | * |
221 | - * @return array |
|
221 | + * @return array |
|
222 | 222 | */ |
223 | 223 | public function prepare_submission_data_for_saving() { |
224 | 224 | |
225 | - $submission = $this->payment_form_submission; |
|
225 | + $submission = $this->payment_form_submission; |
|
226 | 226 | |
227 | - // Prepared submission details. |
|
227 | + // Prepared submission details. |
|
228 | 228 | $prepared = array( |
229 | - 'all' => array(), |
|
230 | - 'meta' => array(), |
|
231 | - ); |
|
229 | + 'all' => array(), |
|
230 | + 'meta' => array(), |
|
231 | + ); |
|
232 | 232 | |
233 | 233 | // Raw submission details. |
234 | - $data = $submission->get_data(); |
|
234 | + $data = $submission->get_data(); |
|
235 | 235 | |
236 | - // Loop through the submitted details. |
|
236 | + // Loop through the submitted details. |
|
237 | 237 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
238 | 238 | |
239 | - // Skip premade fields. |
|
239 | + // Skip premade fields. |
|
240 | 240 | if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) { |
241 | 241 | continue; |
242 | 242 | } |
@@ -249,11 +249,11 @@ discard block |
||
249 | 249 | // Handle misc fields. |
250 | 250 | if ( isset( $data[ $field['id'] ] ) ) { |
251 | 251 | |
252 | - if ( $field['type'] == 'checkbox' ) { |
|
253 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
254 | - } else { |
|
255 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
256 | - } |
|
252 | + if ( $field['type'] == 'checkbox' ) { |
|
253 | + $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
254 | + } else { |
|
255 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
256 | + } |
|
257 | 257 | |
258 | 258 | $label = $field['id']; |
259 | 259 | |
@@ -261,189 +261,189 @@ discard block |
||
261 | 261 | $label = $field['label']; |
262 | 262 | } |
263 | 263 | |
264 | - if ( ! empty( $field['add_meta'] ) ) { |
|
265 | - $prepared['meta'][ wpinv_clean( $label ) ] = $value; |
|
266 | - } |
|
267 | - $prepared['all'][ wpinv_clean( $label ) ] = $value; |
|
264 | + if ( ! empty( $field['add_meta'] ) ) { |
|
265 | + $prepared['meta'][ wpinv_clean( $label ) ] = $value; |
|
266 | + } |
|
267 | + $prepared['all'][ wpinv_clean( $label ) ] = $value; |
|
268 | 268 | |
269 | 269 | } |
270 | 270 | |
271 | - } |
|
271 | + } |
|
272 | 272 | |
273 | - return $prepared; |
|
273 | + return $prepared; |
|
274 | 274 | |
275 | - } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
277 | + /** |
|
278 | 278 | * Retrieves address details. |
279 | 279 | * |
280 | - * @return array |
|
281 | - * @param WPInv_Invoice $invoice |
|
282 | - * @param string $type |
|
280 | + * @return array |
|
281 | + * @param WPInv_Invoice $invoice |
|
282 | + * @param string $type |
|
283 | 283 | */ |
284 | 284 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
285 | 285 | |
286 | - $data = $this->payment_form_submission->get_data(); |
|
287 | - $type = sanitize_key( $type ); |
|
288 | - $address = array(); |
|
289 | - $prepared = array(); |
|
286 | + $data = $this->payment_form_submission->get_data(); |
|
287 | + $type = sanitize_key( $type ); |
|
288 | + $address = array(); |
|
289 | + $prepared = array(); |
|
290 | 290 | |
291 | - if ( ! empty( $data[ $type ] ) ) { |
|
292 | - $address = $data[ $type ]; |
|
293 | - } |
|
291 | + if ( ! empty( $data[ $type ] ) ) { |
|
292 | + $address = $data[ $type ]; |
|
293 | + } |
|
294 | 294 | |
295 | - // Clean address details. |
|
296 | - foreach ( $address as $key => $value ) { |
|
297 | - $key = sanitize_key( $key ); |
|
298 | - $key = str_replace( 'wpinv_', '', $key ); |
|
299 | - $value = wpinv_clean( $value ); |
|
300 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
301 | - } |
|
295 | + // Clean address details. |
|
296 | + foreach ( $address as $key => $value ) { |
|
297 | + $key = sanitize_key( $key ); |
|
298 | + $key = str_replace( 'wpinv_', '', $key ); |
|
299 | + $value = wpinv_clean( $value ); |
|
300 | + $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
301 | + } |
|
302 | 302 | |
303 | - // Filter address details. |
|
304 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
303 | + // Filter address details. |
|
304 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
305 | 305 | |
306 | - // Remove non-whitelisted values. |
|
307 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
306 | + // Remove non-whitelisted values. |
|
307 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
308 | 308 | |
309 | - } |
|
309 | + } |
|
310 | 310 | |
311 | - /** |
|
311 | + /** |
|
312 | 312 | * Prepares the billing details. |
313 | 313 | * |
314 | - * @return array |
|
315 | - * @param WPInv_Invoice $invoice |
|
314 | + * @return array |
|
315 | + * @param WPInv_Invoice $invoice |
|
316 | 316 | */ |
317 | 317 | protected function prepare_billing_info( &$invoice ) { |
318 | 318 | |
319 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
319 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
320 | 320 | |
321 | - // Update the invoice with the billing details. |
|
322 | - $invoice->set_props( $billing_address ); |
|
321 | + // Update the invoice with the billing details. |
|
322 | + $invoice->set_props( $billing_address ); |
|
323 | 323 | |
324 | - } |
|
324 | + } |
|
325 | 325 | |
326 | - /** |
|
326 | + /** |
|
327 | 327 | * Prepares the shipping details. |
328 | 328 | * |
329 | - * @return array |
|
330 | - * @param WPInv_Invoice $invoice |
|
329 | + * @return array |
|
330 | + * @param WPInv_Invoice $invoice |
|
331 | 331 | */ |
332 | 332 | protected function prepare_shipping_info( $invoice ) { |
333 | 333 | |
334 | - $data = $this->payment_form_submission->get_data(); |
|
334 | + $data = $this->payment_form_submission->get_data(); |
|
335 | 335 | |
336 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
337 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
338 | - } |
|
336 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
337 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
338 | + } |
|
339 | 339 | |
340 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
340 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
341 | 341 | |
342 | - } |
|
342 | + } |
|
343 | 343 | |
344 | - /** |
|
345 | - * Confirms the submission is valid and send users to the gateway. |
|
346 | - * |
|
347 | - * @param WPInv_Invoice $invoice |
|
348 | - * @param array $prepared_payment_form_data |
|
349 | - * @param array $shipping |
|
350 | - */ |
|
351 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
344 | + /** |
|
345 | + * Confirms the submission is valid and send users to the gateway. |
|
346 | + * |
|
347 | + * @param WPInv_Invoice $invoice |
|
348 | + * @param array $prepared_payment_form_data |
|
349 | + * @param array $shipping |
|
350 | + */ |
|
351 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
352 | 352 | |
353 | - // Ensure the invoice exists. |
|
353 | + // Ensure the invoice exists. |
|
354 | 354 | if ( ! $invoice->exists() ) { |
355 | 355 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
356 | 356 | } |
357 | 357 | |
358 | - // Save payment form data. |
|
359 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
358 | + // Save payment form data. |
|
359 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
360 | 360 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
361 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
362 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
361 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
362 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
363 | 363 | |
364 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
365 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
366 | - } |
|
364 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
365 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
366 | + } |
|
367 | 367 | |
368 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
369 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
370 | - } |
|
368 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
369 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
370 | + } |
|
371 | 371 | |
372 | - } |
|
372 | + } |
|
373 | 373 | |
374 | - // Save payment form data. |
|
374 | + // Save payment form data. |
|
375 | 375 | if ( ! empty( $shipping ) ) { |
376 | 376 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
377 | - } |
|
377 | + } |
|
378 | 378 | |
379 | - // Backwards compatibility. |
|
379 | + // Backwards compatibility. |
|
380 | 380 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
381 | 381 | |
382 | - $this->process_payment( $invoice ); |
|
382 | + $this->process_payment( $invoice ); |
|
383 | 383 | |
384 | 384 | // If we are here, there was an error. |
385 | - wpinv_send_back_to_checkout( $invoice ); |
|
385 | + wpinv_send_back_to_checkout( $invoice ); |
|
386 | 386 | |
387 | - } |
|
387 | + } |
|
388 | 388 | |
389 | - /** |
|
390 | - * Processes the actual payment. |
|
391 | - * |
|
392 | - * @param WPInv_Invoice $invoice |
|
393 | - */ |
|
394 | - protected function process_payment( $invoice ) { |
|
389 | + /** |
|
390 | + * Processes the actual payment. |
|
391 | + * |
|
392 | + * @param WPInv_Invoice $invoice |
|
393 | + */ |
|
394 | + protected function process_payment( $invoice ) { |
|
395 | 395 | |
396 | - // Clear any checkout errors. |
|
397 | - wpinv_clear_errors(); |
|
396 | + // Clear any checkout errors. |
|
397 | + wpinv_clear_errors(); |
|
398 | 398 | |
399 | - // No need to send free invoices to the gateway. |
|
400 | - if ( $invoice->is_free() ) { |
|
401 | - $this->process_free_payment( $invoice ); |
|
402 | - } |
|
399 | + // No need to send free invoices to the gateway. |
|
400 | + if ( $invoice->is_free() ) { |
|
401 | + $this->process_free_payment( $invoice ); |
|
402 | + } |
|
403 | 403 | |
404 | - $submission = $this->payment_form_submission; |
|
404 | + $submission = $this->payment_form_submission; |
|
405 | 405 | |
406 | - // Fires before sending to the gateway. |
|
407 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
406 | + // Fires before sending to the gateway. |
|
407 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
408 | 408 | |
409 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
410 | - $submission_data = $submission->get_data(); |
|
411 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
412 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
409 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
410 | + $submission_data = $submission->get_data(); |
|
411 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
412 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
413 | 413 | |
414 | - // Validate the currency. |
|
415 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
416 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
417 | - } |
|
414 | + // Validate the currency. |
|
415 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
416 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
417 | + } |
|
418 | 418 | |
419 | - // Check to see if we have any errors. |
|
420 | - if ( wpinv_get_errors() ) { |
|
421 | - wpinv_send_back_to_checkout( $invoice ); |
|
422 | - } |
|
419 | + // Check to see if we have any errors. |
|
420 | + if ( wpinv_get_errors() ) { |
|
421 | + wpinv_send_back_to_checkout( $invoice ); |
|
422 | + } |
|
423 | 423 | |
424 | - // Send info to the gateway for payment processing |
|
425 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
424 | + // Send info to the gateway for payment processing |
|
425 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
426 | 426 | |
427 | - // Backwards compatibility. |
|
428 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
427 | + // Backwards compatibility. |
|
428 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
429 | 429 | |
430 | - } |
|
430 | + } |
|
431 | 431 | |
432 | - /** |
|
433 | - * Marks the invoice as paid in case the checkout is free. |
|
434 | - * |
|
435 | - * @param WPInv_Invoice $invoice |
|
436 | - */ |
|
437 | - protected function process_free_payment( $invoice ) { |
|
432 | + /** |
|
433 | + * Marks the invoice as paid in case the checkout is free. |
|
434 | + * |
|
435 | + * @param WPInv_Invoice $invoice |
|
436 | + */ |
|
437 | + protected function process_free_payment( $invoice ) { |
|
438 | 438 | |
439 | - $invoice->set_gateway( 'none' ); |
|
440 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
441 | - $invoice->mark_paid(); |
|
442 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
439 | + $invoice->set_gateway( 'none' ); |
|
440 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
441 | + $invoice->mark_paid(); |
|
442 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
443 | 443 | |
444 | - } |
|
444 | + } |
|
445 | 445 | |
446 | - /** |
|
446 | + /** |
|
447 | 447 | * Sends a redrect response to payment details. |
448 | 448 | * |
449 | 449 | */ |
@@ -12,492 +12,492 @@ |
||
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, $hook ); |
|
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 | - $merge_tags = 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}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
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( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
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 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | - |
|
152 | - if ( is_array( $payment_form_data ) ) { |
|
153 | - |
|
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
155 | - |
|
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | - |
|
159 | - if ( is_scalar ( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Helper function to send an email. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice |
|
174 | - * @param GetPaid_Notification_Email $email |
|
175 | - * @param string $type |
|
176 | - * @param string|array $recipients |
|
177 | - * @param array $extra_args Extra template args. |
|
178 | - */ |
|
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | - |
|
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | - |
|
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | - return; |
|
186 | - } |
|
187 | - |
|
188 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | - $merge_tags = $email->get_merge_tags(); |
|
190 | - |
|
191 | - $result = $mailer->send( |
|
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
195 | - $email->get_attachments() |
|
196 | - ); |
|
197 | - |
|
198 | - // Maybe send a copy to the admin. |
|
199 | - if ( $email->include_admin_bcc() ) { |
|
200 | - $mailer->send( |
|
201 | - wpinv_get_admin_email(), |
|
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
204 | - $email->get_attachments() |
|
205 | - ); |
|
206 | - } |
|
207 | - |
|
208 | - if ( $result ) { |
|
209 | - $invoice->add_system_note( |
|
210 | - sprintf( |
|
211 | - __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
212 | - sanitize_key( $type ), |
|
213 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
214 | - ) |
|
215 | - ); |
|
216 | - } else { |
|
217 | - $invoice->add_system_note( |
|
218 | - sprintf( |
|
219 | - __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - |
|
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | - |
|
228 | - return $result; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Also send emails to any cc users. |
|
233 | - * |
|
234 | - * @param array $recipients |
|
235 | - * @param GetPaid_Notification_Email $email |
|
236 | - */ |
|
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
238 | - |
|
239 | - if ( ! $email->is_admin_email() ) { |
|
240 | - $cc = $email->object->get_email_cc(); |
|
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | - |
|
243 | - if ( ! empty( $cc ) ) { |
|
244 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | - } |
|
247 | - |
|
248 | - if ( ! empty( $cc_2 ) ) { |
|
249 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | - } |
|
252 | - |
|
253 | - } |
|
254 | - |
|
255 | - return $recipients; |
|
256 | - |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Sends a new invoice notification. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice |
|
263 | - */ |
|
264 | - public function new_invoice( $invoice ) { |
|
265 | - |
|
266 | - // Only send this email for invoices created via the admin page. |
|
267 | - if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | - return; |
|
269 | - } |
|
270 | - |
|
271 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | - $recipient = wpinv_get_admin_email(); |
|
273 | - |
|
274 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | - |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Sends a cancelled invoice notification. |
|
280 | - * |
|
281 | - * @param WPInv_Invoice $invoice |
|
282 | - */ |
|
283 | - public function cancelled_invoice( $invoice ) { |
|
284 | - |
|
285 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | - $recipient = wpinv_get_admin_email(); |
|
287 | - |
|
288 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | - |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Sends a failed invoice notification. |
|
294 | - * |
|
295 | - * @param WPInv_Invoice $invoice |
|
296 | - */ |
|
297 | - public function failed_invoice( $invoice ) { |
|
298 | - |
|
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | - $recipient = wpinv_get_admin_email(); |
|
301 | - |
|
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Sends a notification whenever an invoice is put on hold. |
|
308 | - * |
|
309 | - * @param WPInv_Invoice $invoice |
|
310 | - */ |
|
311 | - public function onhold_invoice( $invoice ) { |
|
312 | - |
|
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
314 | - $recipient = $invoice->get_email(); |
|
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, $hook ); |
|
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 | + $merge_tags = 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}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
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( strtolower( $invoice->get_label() ) ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
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 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | + |
|
152 | + if ( is_array( $payment_form_data ) ) { |
|
153 | + |
|
154 | + foreach ( $payment_form_data as $label => $value ) { |
|
155 | + |
|
156 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | + |
|
159 | + if ( is_scalar ( $value ) ) { |
|
160 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Helper function to send an email. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice |
|
174 | + * @param GetPaid_Notification_Email $email |
|
175 | + * @param string $type |
|
176 | + * @param string|array $recipients |
|
177 | + * @param array $extra_args Extra template args. |
|
178 | + */ |
|
179 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | + |
|
181 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | + |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | + return; |
|
186 | + } |
|
187 | + |
|
188 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | + $merge_tags = $email->get_merge_tags(); |
|
190 | + |
|
191 | + $result = $mailer->send( |
|
192 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | + $email->get_content( $merge_tags, $extra_args ), |
|
195 | + $email->get_attachments() |
|
196 | + ); |
|
197 | + |
|
198 | + // Maybe send a copy to the admin. |
|
199 | + if ( $email->include_admin_bcc() ) { |
|
200 | + $mailer->send( |
|
201 | + wpinv_get_admin_email(), |
|
202 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | + $email->get_content( $merge_tags ), |
|
204 | + $email->get_attachments() |
|
205 | + ); |
|
206 | + } |
|
207 | + |
|
208 | + if ( $result ) { |
|
209 | + $invoice->add_system_note( |
|
210 | + sprintf( |
|
211 | + __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
212 | + sanitize_key( $type ), |
|
213 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
214 | + ) |
|
215 | + ); |
|
216 | + } else { |
|
217 | + $invoice->add_system_note( |
|
218 | + sprintf( |
|
219 | + __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
220 | + sanitize_key( $type ), |
|
221 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + |
|
226 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | + |
|
228 | + return $result; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Also send emails to any cc users. |
|
233 | + * |
|
234 | + * @param array $recipients |
|
235 | + * @param GetPaid_Notification_Email $email |
|
236 | + */ |
|
237 | + public function filter_email_recipients( $recipients, $email ) { |
|
238 | + |
|
239 | + if ( ! $email->is_admin_email() ) { |
|
240 | + $cc = $email->object->get_email_cc(); |
|
241 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | + |
|
243 | + if ( ! empty( $cc ) ) { |
|
244 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | + } |
|
247 | + |
|
248 | + if ( ! empty( $cc_2 ) ) { |
|
249 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | + } |
|
252 | + |
|
253 | + } |
|
254 | + |
|
255 | + return $recipients; |
|
256 | + |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Sends a new invoice notification. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice |
|
263 | + */ |
|
264 | + public function new_invoice( $invoice ) { |
|
265 | + |
|
266 | + // Only send this email for invoices created via the admin page. |
|
267 | + if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | + return; |
|
269 | + } |
|
270 | + |
|
271 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | + $recipient = wpinv_get_admin_email(); |
|
273 | + |
|
274 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | + |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Sends a cancelled invoice notification. |
|
280 | + * |
|
281 | + * @param WPInv_Invoice $invoice |
|
282 | + */ |
|
283 | + public function cancelled_invoice( $invoice ) { |
|
284 | + |
|
285 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | + $recipient = wpinv_get_admin_email(); |
|
287 | + |
|
288 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | + |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Sends a failed invoice notification. |
|
294 | + * |
|
295 | + * @param WPInv_Invoice $invoice |
|
296 | + */ |
|
297 | + public function failed_invoice( $invoice ) { |
|
298 | + |
|
299 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | + $recipient = wpinv_get_admin_email(); |
|
301 | + |
|
302 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Sends a notification whenever an invoice is put on hold. |
|
308 | + * |
|
309 | + * @param WPInv_Invoice $invoice |
|
310 | + */ |
|
311 | + public function onhold_invoice( $invoice ) { |
|
312 | + |
|
313 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
314 | + $recipient = $invoice->get_email(); |
|
315 | 315 | |
316 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
317 | 317 | |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | - * |
|
323 | - * @param WPInv_Invoice $invoice |
|
324 | - */ |
|
325 | - public function processing_invoice( $invoice ) { |
|
320 | + /** |
|
321 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | + * |
|
323 | + * @param WPInv_Invoice $invoice |
|
324 | + */ |
|
325 | + public function processing_invoice( $invoice ) { |
|
326 | 326 | |
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | - $recipient = $invoice->get_email(); |
|
327 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | + $recipient = $invoice->get_email(); |
|
329 | 329 | |
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | - |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Sends a notification whenever an invoice is paid. |
|
336 | - * |
|
337 | - * @param WPInv_Invoice $invoice |
|
338 | - */ |
|
339 | - public function completed_invoice( $invoice ) { |
|
330 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | + |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Sends a notification whenever an invoice is paid. |
|
336 | + * |
|
337 | + * @param WPInv_Invoice $invoice |
|
338 | + */ |
|
339 | + public function completed_invoice( $invoice ) { |
|
340 | 340 | |
341 | - // (Maybe) abort if it is a renewal invoice. |
|
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | - return; |
|
344 | - } |
|
341 | + // (Maybe) abort if it is a renewal invoice. |
|
342 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | + return; |
|
344 | + } |
|
345 | 345 | |
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
347 | - $recipient = $invoice->get_email(); |
|
346 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
347 | + $recipient = $invoice->get_email(); |
|
348 | 348 | |
349 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
350 | 350 | |
351 | - } |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Sends a notification whenever an invoice is refunded. |
|
355 | - * |
|
356 | - * @param WPInv_Invoice $invoice |
|
357 | - */ |
|
358 | - public function refunded_invoice( $invoice ) { |
|
353 | + /** |
|
354 | + * Sends a notification whenever an invoice is refunded. |
|
355 | + * |
|
356 | + * @param WPInv_Invoice $invoice |
|
357 | + */ |
|
358 | + public function refunded_invoice( $invoice ) { |
|
359 | 359 | |
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | - $recipient = $invoice->get_email(); |
|
360 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | + $recipient = $invoice->get_email(); |
|
362 | 362 | |
363 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
364 | 364 | |
365 | - } |
|
365 | + } |
|
366 | 366 | |
367 | - /** |
|
368 | - * Notifies a user about new invoices |
|
369 | - * |
|
370 | - * @param WPInv_Invoice $invoice |
|
371 | - * @param bool $force |
|
372 | - */ |
|
373 | - public function user_invoice( $invoice, $force = false ) { |
|
367 | + /** |
|
368 | + * Notifies a user about new invoices |
|
369 | + * |
|
370 | + * @param WPInv_Invoice $invoice |
|
371 | + * @param bool $force |
|
372 | + */ |
|
373 | + public function user_invoice( $invoice, $force = false ) { |
|
374 | 374 | |
375 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | - return; |
|
377 | - } |
|
378 | - |
|
379 | - // Only send this email for invoices created via the admin page. |
|
380 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
381 | - return; |
|
382 | - } |
|
375 | + if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | + return; |
|
377 | + } |
|
378 | + |
|
379 | + // Only send this email for invoices created via the admin page. |
|
380 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | 383 | |
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
385 | - $recipient = $invoice->get_email(); |
|
384 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
385 | + $recipient = $invoice->get_email(); |
|
386 | 386 | |
387 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
388 | 388 | |
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Checks if an invoice is a payment form invoice. |
|
393 | - * |
|
394 | - * @param int $invoice |
|
395 | - * @return bool |
|
396 | - */ |
|
397 | - public function is_payment_form_invoice( $invoice ) { |
|
398 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
399 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
400 | - } |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Checks if an invoice is a payment form invoice. |
|
393 | + * |
|
394 | + * @param int $invoice |
|
395 | + * @return bool |
|
396 | + */ |
|
397 | + public function is_payment_form_invoice( $invoice ) { |
|
398 | + $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
399 | + return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Notifies admin about new invoice notes |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice |
|
406 | - * @param string $note |
|
407 | - */ |
|
408 | - public function user_note( $invoice, $note ) { |
|
409 | - |
|
410 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
411 | - $recipient = $invoice->get_email(); |
|
402 | + /** |
|
403 | + * Notifies admin about new invoice notes |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice |
|
406 | + * @param string $note |
|
407 | + */ |
|
408 | + public function user_note( $invoice, $note ) { |
|
409 | + |
|
410 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
411 | + $recipient = $invoice->get_email(); |
|
412 | 412 | |
413 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
414 | - |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * (Force) Sends overdue notices. |
|
419 | - * |
|
420 | - * @param WPInv_Invoice $invoice |
|
421 | - */ |
|
422 | - public function force_send_overdue_notice( $invoice ) { |
|
423 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
424 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Sends overdue notices. |
|
429 | - * |
|
430 | - * @TODO: Create an invoices query class. |
|
431 | - */ |
|
432 | - public function overdue() { |
|
433 | - global $wpdb; |
|
434 | - |
|
435 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
436 | - |
|
437 | - // Fetch reminder days. |
|
438 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
439 | - |
|
440 | - // Abort if non is set. |
|
441 | - if ( empty( $reminder_days ) ) { |
|
442 | - return; |
|
443 | - } |
|
444 | - |
|
445 | - // Retrieve date query. |
|
446 | - $date_query = $this->get_date_query( $reminder_days ); |
|
447 | - |
|
448 | - // Invoices table. |
|
449 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
450 | - |
|
451 | - // Fetch invoices. |
|
452 | - $invoices = $wpdb->get_col( |
|
453 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
413 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
414 | + |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * (Force) Sends overdue notices. |
|
419 | + * |
|
420 | + * @param WPInv_Invoice $invoice |
|
421 | + */ |
|
422 | + public function force_send_overdue_notice( $invoice ) { |
|
423 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
424 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Sends overdue notices. |
|
429 | + * |
|
430 | + * @TODO: Create an invoices query class. |
|
431 | + */ |
|
432 | + public function overdue() { |
|
433 | + global $wpdb; |
|
434 | + |
|
435 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
436 | + |
|
437 | + // Fetch reminder days. |
|
438 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
439 | + |
|
440 | + // Abort if non is set. |
|
441 | + if ( empty( $reminder_days ) ) { |
|
442 | + return; |
|
443 | + } |
|
444 | + |
|
445 | + // Retrieve date query. |
|
446 | + $date_query = $this->get_date_query( $reminder_days ); |
|
447 | + |
|
448 | + // Invoices table. |
|
449 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
450 | + |
|
451 | + // Fetch invoices. |
|
452 | + $invoices = $wpdb->get_col( |
|
453 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
454 | 454 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
455 | 455 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
456 | 456 | |
457 | - foreach ( $invoices as $invoice ) { |
|
457 | + foreach ( $invoices as $invoice ) { |
|
458 | 458 | |
459 | - // Only send this email for invoices created via the admin page. |
|
460 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
461 | - $invoice = new WPInv_Invoice( $invoice ); |
|
462 | - $email->object = $invoice; |
|
459 | + // Only send this email for invoices created via the admin page. |
|
460 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
461 | + $invoice = new WPInv_Invoice( $invoice ); |
|
462 | + $email->object = $invoice; |
|
463 | 463 | |
464 | - if ( $invoice->needs_payment() ) { |
|
465 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
466 | - } |
|
464 | + if ( $invoice->needs_payment() ) { |
|
465 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
466 | + } |
|
467 | 467 | |
468 | - } |
|
468 | + } |
|
469 | 469 | |
470 | - } |
|
470 | + } |
|
471 | 471 | |
472 | - } |
|
472 | + } |
|
473 | 473 | |
474 | - /** |
|
475 | - * Calculates the date query for an invoices query |
|
476 | - * |
|
477 | - * @param array $reminder_days |
|
478 | - * @return string |
|
479 | - */ |
|
480 | - public function get_date_query( $reminder_days ) { |
|
474 | + /** |
|
475 | + * Calculates the date query for an invoices query |
|
476 | + * |
|
477 | + * @param array $reminder_days |
|
478 | + * @return string |
|
479 | + */ |
|
480 | + public function get_date_query( $reminder_days ) { |
|
481 | 481 | |
482 | - $date_query = array( |
|
483 | - 'relation' => 'OR' |
|
484 | - ); |
|
482 | + $date_query = array( |
|
483 | + 'relation' => 'OR' |
|
484 | + ); |
|
485 | 485 | |
486 | - foreach ( $reminder_days as $days ) { |
|
487 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
486 | + foreach ( $reminder_days as $days ) { |
|
487 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
488 | 488 | |
489 | - $date_query[] = array( |
|
490 | - 'year' => $date['year'], |
|
491 | - 'month' => $date['month'], |
|
492 | - 'day' => $date['day'], |
|
493 | - ); |
|
489 | + $date_query[] = array( |
|
490 | + 'year' => $date['year'], |
|
491 | + 'month' => $date['month'], |
|
492 | + 'day' => $date['day'], |
|
493 | + ); |
|
494 | 494 | |
495 | - } |
|
495 | + } |
|
496 | 496 | |
497 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
497 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
498 | 498 | |
499 | - return $date_query->get_sql(); |
|
499 | + return $date_query->get_sql(); |
|
500 | 500 | |
501 | - } |
|
501 | + } |
|
502 | 502 | |
503 | 503 | } |
@@ -24,64 +24,64 @@ discard block |
||
24 | 24 | |
25 | 25 | <?php |
26 | 26 | |
27 | - // Fires before printing a line item column. |
|
28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
27 | + // Fires before printing a line item column. |
|
28 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
29 | 29 | |
30 | - // Item name. |
|
31 | - if ( 'name' == $key ) { |
|
30 | + // Item name. |
|
31 | + if ( 'name' == $key ) { |
|
32 | 32 | |
33 | - // Display the name. |
|
34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
33 | + // Display the name. |
|
34 | + echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
35 | 35 | |
36 | - // And an optional description. |
|
36 | + // And an optional description. |
|
37 | 37 | $description = $item->get_description(); |
38 | 38 | |
39 | 39 | if ( ! empty( $description ) ) { |
40 | 40 | $description = wp_kses_post( $description ); |
41 | 41 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - // Price help text. |
|
44 | + // Price help text. |
|
45 | 45 | $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
46 | 46 | if ( $description ) { |
47 | 47 | echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>"; |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - // Item price. |
|
53 | - if ( 'price' == $key ) { |
|
52 | + // Item price. |
|
53 | + if ( 'price' == $key ) { |
|
54 | 54 | |
55 | - // Set the currency position. |
|
56 | - $position = wpinv_currency_position(); |
|
55 | + // Set the currency position. |
|
56 | + $position = wpinv_currency_position(); |
|
57 | 57 | |
58 | - if ( $position == 'left_space' ) { |
|
59 | - $position = 'left'; |
|
60 | - } |
|
58 | + if ( $position == 'left_space' ) { |
|
59 | + $position = 'left'; |
|
60 | + } |
|
61 | 61 | |
62 | - if ( $position == 'right_space' ) { |
|
63 | - $position = 'right'; |
|
64 | - } |
|
62 | + if ( $position == 'right_space' ) { |
|
63 | + $position = 'right'; |
|
64 | + } |
|
65 | 65 | |
66 | - if ( $item->user_can_set_their_price() ) { |
|
67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
68 | - $minimum = (float) $item->get_minimum_price(); |
|
69 | - $validate_minimum = ''; |
|
70 | - $class = ''; |
|
71 | - $data_minimum = ''; |
|
66 | + if ( $item->user_can_set_their_price() ) { |
|
67 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
68 | + $minimum = (float) $item->get_minimum_price(); |
|
69 | + $validate_minimum = ''; |
|
70 | + $class = ''; |
|
71 | + $data_minimum = ''; |
|
72 | 72 | |
73 | - if ( $minimum > 0 ) { |
|
74 | - $validate_minimum = sprintf( |
|
75 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
76 | - sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
77 | - ); |
|
73 | + if ( $minimum > 0 ) { |
|
74 | + $validate_minimum = sprintf( |
|
75 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
76 | + sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
77 | + ); |
|
78 | 78 | |
79 | - $class = 'getpaid-validate-minimum-amount'; |
|
79 | + $class = 'getpaid-validate-minimum-amount'; |
|
80 | 80 | |
81 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
82 | - } |
|
81 | + $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
82 | + } |
|
83 | 83 | |
84 | - ?> |
|
84 | + ?> |
|
85 | 85 | <div class="input-group input-group-sm"> |
86 | 86 | <?php if( 'left' == $position ) : ?> |
87 | 87 | <div class="input-group-prepend"> |
@@ -105,37 +105,37 @@ discard block |
||
105 | 105 | </div> |
106 | 106 | |
107 | 107 | <?php |
108 | - } else { |
|
109 | - echo wpinv_price( $item->get_price(), $currency ); |
|
110 | - ?> |
|
108 | + } else { |
|
109 | + echo wpinv_price( $item->get_price(), $currency ); |
|
110 | + ?> |
|
111 | 111 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
112 | 112 | <?php |
113 | - } |
|
114 | - } |
|
113 | + } |
|
114 | + } |
|
115 | 115 | |
116 | - // Item quantity. |
|
117 | - if ( 'quantity' == $key ) { |
|
116 | + // Item quantity. |
|
117 | + if ( 'quantity' == $key ) { |
|
118 | 118 | |
119 | - if ( $item->allows_quantities() ) { |
|
120 | - ?> |
|
119 | + if ( $item->allows_quantities() ) { |
|
120 | + ?> |
|
121 | 121 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required> |
122 | 122 | <?php |
123 | - } else { |
|
124 | - echo (float) $item->get_quantity(); |
|
125 | - echo ' '; |
|
126 | - ?> |
|
123 | + } else { |
|
124 | + echo (float) $item->get_quantity(); |
|
125 | + echo ' '; |
|
126 | + ?> |
|
127 | 127 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
128 | 128 | <?php |
129 | - } |
|
130 | - } |
|
129 | + } |
|
130 | + } |
|
131 | 131 | |
132 | - // Item sub total. |
|
133 | - if ( 'subtotal' == $key ) { |
|
134 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
135 | - } |
|
132 | + // Item sub total. |
|
133 | + if ( 'subtotal' == $key ) { |
|
134 | + echo wpinv_price( $item->get_sub_total(), $currency ); |
|
135 | + } |
|
136 | 136 | |
137 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
138 | - ?> |
|
137 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
138 | + ?> |
|
139 | 139 | |
140 | 140 | </div> |
141 | 141 |