@@ -14,62 +14,62 @@ discard block |
||
| 14 | 14 | class GetPaid_Admin { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Local path to this plugins admin directory |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $admin_path; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Web path to this plugins admin directory |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 17 | + * Local path to this plugins admin directory |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $admin_path; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Web path to this plugins admin directory |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | 28 | public $admin_url; |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | - * Class constructor. |
|
| 32 | - */ |
|
| 33 | - public function __construct(){ |
|
| 31 | + * Class constructor. |
|
| 32 | + */ |
|
| 33 | + public function __construct(){ |
|
| 34 | 34 | |
| 35 | 35 | $this->admin_path = plugin_dir_path( __FILE__ ); |
| 36 | 36 | $this->admin_url = plugins_url( '/', __FILE__ ); |
| 37 | 37 | |
| 38 | 38 | if ( is_admin() ) { |
| 39 | - $this->init_admin_hooks(); |
|
| 39 | + $this->init_admin_hooks(); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | - * Init action and filter hooks |
|
| 46 | - * |
|
| 47 | - */ |
|
| 48 | - private function init_admin_hooks() { |
|
| 45 | + * Init action and filter hooks |
|
| 46 | + * |
|
| 47 | + */ |
|
| 48 | + private function init_admin_hooks() { |
|
| 49 | 49 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) ); |
| 50 | 50 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 51 | 51 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
| 52 | 52 | add_action( 'admin_init', array( $this, 'activation_redirect') ); |
| 53 | 53 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action') ); |
| 54 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 55 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 56 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 57 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 54 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 55 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 56 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 57 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 58 | 58 | |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | - * Register admin scripts |
|
| 63 | - * |
|
| 64 | - */ |
|
| 65 | - public function enqeue_scripts() { |
|
| 62 | + * Register admin scripts |
|
| 63 | + * |
|
| 64 | + */ |
|
| 65 | + public function enqeue_scripts() { |
|
| 66 | 66 | global $current_screen, $pagenow; |
| 67 | 67 | |
| 68 | - $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 69 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 68 | + $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
|
| 69 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 70 | 70 | |
| 71 | 71 | if ( ! empty( $current_screen->post_type ) ) { |
| 72 | - $page = $current_screen->post_type; |
|
| 72 | + $page = $current_screen->post_type; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // General styles. |
@@ -93,30 +93,30 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // Payment form scripts. |
| 96 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 96 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 97 | 97 | $this->load_payment_form_scripts(); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | if ( $page == 'wpinv-subscriptions' ) { |
| 101 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
| 102 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
| 103 | - } |
|
| 101 | + wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
| 102 | + wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - if ( $page == 'wpinv-reports' ) { |
|
| 106 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
| 107 | - } |
|
| 105 | + if ( $page == 'wpinv-reports' ) { |
|
| 106 | + wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 110 | - wp_enqueue_script( 'postbox' ); |
|
| 111 | - } |
|
| 109 | + if ( $page == 'wpinv-subscriptions' ) { |
|
| 110 | + wp_enqueue_script( 'postbox' ); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | - * Returns admin js translations. |
|
| 117 | - * |
|
| 118 | - */ |
|
| 119 | - protected function get_admin_i18() { |
|
| 116 | + * Returns admin js translations. |
|
| 117 | + * |
|
| 118 | + */ |
|
| 119 | + protected function get_admin_i18() { |
|
| 120 | 120 | global $post; |
| 121 | 121 | |
| 122 | 122 | return array( |
@@ -157,32 +157,32 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | - * Loads payment form js. |
|
| 161 | - * |
|
| 162 | - */ |
|
| 163 | - protected function load_payment_form_scripts() { |
|
| 160 | + * Loads payment form js. |
|
| 161 | + * |
|
| 162 | + */ |
|
| 163 | + protected function load_payment_form_scripts() { |
|
| 164 | 164 | global $post; |
| 165 | 165 | |
| 166 | 166 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
| 167 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 168 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 167 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 168 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 169 | 169 | |
| 170 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 171 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 170 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 171 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
| 172 | 172 | |
| 173 | - wp_localize_script( |
|
| 173 | + wp_localize_script( |
|
| 174 | 174 | 'wpinv-admin-payment-form-script', |
| 175 | 175 | 'wpinvPaymentFormAdmin', |
| 176 | 176 | array( |
| 177 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 178 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 179 | - 'currency' => wpinv_currency_symbol(), |
|
| 180 | - 'position' => wpinv_currency_position(), |
|
| 181 | - 'decimals' => (int) wpinv_decimals(), |
|
| 182 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
| 183 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
| 184 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 185 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 177 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 178 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 179 | + 'currency' => wpinv_currency_symbol(), |
|
| 180 | + 'position' => wpinv_currency_position(), |
|
| 181 | + 'decimals' => (int) wpinv_decimals(), |
|
| 182 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
| 183 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
| 184 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 185 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 186 | 186 | ) |
| 187 | 187 | ); |
| 188 | 188 | |
@@ -191,20 +191,20 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
| 194 | - * Add our classes to admin pages. |
|
| 194 | + * Add our classes to admin pages. |
|
| 195 | 195 | * |
| 196 | 196 | * @param string $classes |
| 197 | 197 | * @return string |
| 198 | - * |
|
| 199 | - */ |
|
| 198 | + * |
|
| 199 | + */ |
|
| 200 | 200 | public function admin_body_class( $classes ) { |
| 201 | - global $pagenow, $post, $current_screen; |
|
| 201 | + global $pagenow, $post, $current_screen; |
|
| 202 | 202 | |
| 203 | 203 | |
| 204 | 204 | $page = isset( $_GET['page'] ) ? $_GET['page'] : ''; |
| 205 | 205 | |
| 206 | 206 | if ( ! empty( $current_screen->post_type ) ) { |
| 207 | - $page = $current_screen->post_type; |
|
| 207 | + $page = $current_screen->post_type; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -215,27 +215,27 @@ discard block |
||
| 215 | 215 | $classes .= ' wpinv-cpt wpinv'; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
| 219 | - $classes .= ' wpi-editable-n'; |
|
| 220 | - } |
|
| 218 | + if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) { |
|
| 219 | + $classes .= ' wpi-editable-n'; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - return $classes; |
|
| 222 | + return $classes; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | /** |
| 226 | - * Maybe show the AyeCode Connect Notice. |
|
| 227 | - */ |
|
| 228 | - public function init_ayecode_connect_helper(){ |
|
| 226 | + * Maybe show the AyeCode Connect Notice. |
|
| 227 | + */ |
|
| 228 | + public function init_ayecode_connect_helper(){ |
|
| 229 | 229 | |
| 230 | 230 | new AyeCode_Connect_Helper( |
| 231 | 231 | array( |
| 232 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 233 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 234 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 235 | - 'connect_button' => __("Connect Site","invoicing"), |
|
| 236 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
| 237 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 238 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 232 | + 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
| 233 | + 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
| 234 | + 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
| 235 | + 'connect_button' => __("Connect Site","invoicing"), |
|
| 236 | + 'connecting_button' => __("Connecting...","invoicing"), |
|
| 237 | + 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
| 238 | + 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
| 239 | 239 | ), |
| 240 | 240 | array( 'wpi-addons' ) |
| 241 | 241 | ); |
@@ -247,21 +247,21 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | public function activation_redirect() { |
| 249 | 249 | |
| 250 | - // Bail if no activation redirect. |
|
| 251 | - if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
| 252 | - return; |
|
| 253 | - } |
|
| 250 | + // Bail if no activation redirect. |
|
| 251 | + if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) { |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // Delete the redirect transient. |
|
| 256 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 255 | + // Delete the redirect transient. |
|
| 256 | + delete_transient( '_wpinv_activation_redirect' ); |
|
| 257 | 257 | |
| 258 | - // Bail if activating from network, or bulk |
|
| 259 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 260 | - return; |
|
| 261 | - } |
|
| 258 | + // Bail if activating from network, or bulk |
|
| 259 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 260 | + return; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 264 | - exit; |
|
| 263 | + wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 264 | + exit; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -276,150 +276,150 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - /** |
|
| 279 | + /** |
|
| 280 | 280 | * Sends a payment reminder to a customer. |
| 281 | - * |
|
| 282 | - * @param array $args |
|
| 281 | + * |
|
| 282 | + * @param array $args |
|
| 283 | 283 | */ |
| 284 | 284 | public function send_customer_invoice( $args ) { |
| 285 | - $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 285 | + $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 286 | 286 | |
| 287 | - if ( $sent ) { |
|
| 288 | - $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
| 289 | - } else { |
|
| 290 | - $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
| 291 | - } |
|
| 287 | + if ( $sent ) { |
|
| 288 | + $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) ); |
|
| 289 | + } else { |
|
| 290 | + $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) ); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 294 | - exit; |
|
| 295 | - } |
|
| 293 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 294 | + exit; |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - /** |
|
| 297 | + /** |
|
| 298 | 298 | * Sends a payment reminder to a customer. |
| 299 | - * |
|
| 300 | - * @param array $args |
|
| 299 | + * |
|
| 300 | + * @param array $args |
|
| 301 | 301 | */ |
| 302 | 302 | public function send_customer_payment_reminder( $args ) { |
| 303 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 303 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 304 | 304 | |
| 305 | - if ( $sent ) { |
|
| 306 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 307 | - } else { |
|
| 308 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 309 | - } |
|
| 305 | + if ( $sent ) { |
|
| 306 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 307 | + } else { |
|
| 308 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 312 | - exit; |
|
| 313 | - } |
|
| 311 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 312 | + exit; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | /** |
| 316 | - * Returns an array of admin notices. |
|
| 317 | - * |
|
| 318 | - * @since 1.0.19 |
|
| 316 | + * Returns an array of admin notices. |
|
| 317 | + * |
|
| 318 | + * @since 1.0.19 |
|
| 319 | 319 | * @return array |
| 320 | - */ |
|
| 321 | - public function get_notices() { |
|
| 322 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
| 320 | + */ |
|
| 321 | + public function get_notices() { |
|
| 322 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
| 323 | 323 | return is_array( $notices ) ? $notices : array(); |
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Clears all admin notices |
|
| 328 | - * |
|
| 329 | - * @access public |
|
| 330 | - * @since 1.0.19 |
|
| 331 | - */ |
|
| 332 | - public function clear_notices() { |
|
| 333 | - delete_option( 'wpinv_admin_notices' ); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Saves a new admin notice |
|
| 338 | - * |
|
| 339 | - * @access public |
|
| 340 | - * @since 1.0.19 |
|
| 341 | - */ |
|
| 342 | - public function save_notice( $type, $message ) { |
|
| 343 | - $notices = $this->get_notices(); |
|
| 344 | - |
|
| 345 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 346 | - $notices[ $type ] = array(); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - $notices[ $type ][] = $message; |
|
| 350 | - |
|
| 351 | - update_option( 'wpinv_admin_notices', $notices ); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Displays a success notice |
|
| 356 | - * |
|
| 357 | - * @param string $msg The message to qeue. |
|
| 358 | - * @access public |
|
| 359 | - * @since 1.0.19 |
|
| 360 | - */ |
|
| 361 | - public function show_success( $msg ) { |
|
| 362 | - $this->save_notice( 'success', $msg ); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Displays a error notice |
|
| 367 | - * |
|
| 368 | - * @access public |
|
| 369 | - * @param string $msg The message to qeue. |
|
| 370 | - * @since 1.0.19 |
|
| 371 | - */ |
|
| 372 | - public function show_error( $msg ) { |
|
| 373 | - $this->save_notice( 'error', $msg ); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Displays a warning notice |
|
| 378 | - * |
|
| 379 | - * @access public |
|
| 380 | - * @param string $msg The message to qeue. |
|
| 381 | - * @since 1.0.19 |
|
| 382 | - */ |
|
| 383 | - public function show_warning( $msg ) { |
|
| 384 | - $this->save_notice( 'warning', $msg ); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Displays a info notice |
|
| 389 | - * |
|
| 390 | - * @access public |
|
| 391 | - * @param string $msg The message to qeue. |
|
| 392 | - * @since 1.0.19 |
|
| 393 | - */ |
|
| 394 | - public function show_info( $msg ) { |
|
| 395 | - $this->save_notice( 'info', $msg ); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Show notices |
|
| 400 | - * |
|
| 401 | - * @access public |
|
| 402 | - * @since 1.0.19 |
|
| 403 | - */ |
|
| 404 | - public function show_notices() { |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Clears all admin notices |
|
| 328 | + * |
|
| 329 | + * @access public |
|
| 330 | + * @since 1.0.19 |
|
| 331 | + */ |
|
| 332 | + public function clear_notices() { |
|
| 333 | + delete_option( 'wpinv_admin_notices' ); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Saves a new admin notice |
|
| 338 | + * |
|
| 339 | + * @access public |
|
| 340 | + * @since 1.0.19 |
|
| 341 | + */ |
|
| 342 | + public function save_notice( $type, $message ) { |
|
| 343 | + $notices = $this->get_notices(); |
|
| 344 | + |
|
| 345 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) { |
|
| 346 | + $notices[ $type ] = array(); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + $notices[ $type ][] = $message; |
|
| 350 | + |
|
| 351 | + update_option( 'wpinv_admin_notices', $notices ); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Displays a success notice |
|
| 356 | + * |
|
| 357 | + * @param string $msg The message to qeue. |
|
| 358 | + * @access public |
|
| 359 | + * @since 1.0.19 |
|
| 360 | + */ |
|
| 361 | + public function show_success( $msg ) { |
|
| 362 | + $this->save_notice( 'success', $msg ); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Displays a error notice |
|
| 367 | + * |
|
| 368 | + * @access public |
|
| 369 | + * @param string $msg The message to qeue. |
|
| 370 | + * @since 1.0.19 |
|
| 371 | + */ |
|
| 372 | + public function show_error( $msg ) { |
|
| 373 | + $this->save_notice( 'error', $msg ); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Displays a warning notice |
|
| 378 | + * |
|
| 379 | + * @access public |
|
| 380 | + * @param string $msg The message to qeue. |
|
| 381 | + * @since 1.0.19 |
|
| 382 | + */ |
|
| 383 | + public function show_warning( $msg ) { |
|
| 384 | + $this->save_notice( 'warning', $msg ); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Displays a info notice |
|
| 389 | + * |
|
| 390 | + * @access public |
|
| 391 | + * @param string $msg The message to qeue. |
|
| 392 | + * @since 1.0.19 |
|
| 393 | + */ |
|
| 394 | + public function show_info( $msg ) { |
|
| 395 | + $this->save_notice( 'info', $msg ); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Show notices |
|
| 400 | + * |
|
| 401 | + * @access public |
|
| 402 | + * @since 1.0.19 |
|
| 403 | + */ |
|
| 404 | + public function show_notices() { |
|
| 405 | 405 | |
| 406 | 406 | $notices = $this->get_notices(); |
| 407 | 407 | $this->clear_notices(); |
| 408 | 408 | |
| 409 | - foreach ( $notices as $type => $messages ) { |
|
| 409 | + foreach ( $notices as $type => $messages ) { |
|
| 410 | 410 | |
| 411 | - if ( ! is_array( $messages ) ) { |
|
| 412 | - continue; |
|
| 413 | - } |
|
| 411 | + if ( ! is_array( $messages ) ) { |
|
| 412 | + continue; |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | 415 | $type = sanitize_key( $type ); |
| 416 | - foreach ( $messages as $message ) { |
|
| 416 | + foreach ( $messages as $message ) { |
|
| 417 | 417 | $message = wp_kses_post( $message ); |
| 418 | - echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 418 | + echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>"; |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | - } |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | 425 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
| 141 | 141 | */ |
| 142 | 142 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
| 143 | + return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @return string |
| 159 | 159 | */ |
| 160 | 160 | function wpinv_get_theme_template_dir_name() { |
| 161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
| 161 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -175,122 +175,122 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
| 178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 178 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 179 | 179 | |
| 180 | - // Setup possible parts |
|
| 181 | - $templates = array(); |
|
| 182 | - if ( isset( $name ) ) |
|
| 183 | - $templates[] = $slug . '-' . $name . '.php'; |
|
| 184 | - $templates[] = $slug . '.php'; |
|
| 180 | + // Setup possible parts |
|
| 181 | + $templates = array(); |
|
| 182 | + if ( isset( $name ) ) |
|
| 183 | + $templates[] = $slug . '-' . $name . '.php'; |
|
| 184 | + $templates[] = $slug . '.php'; |
|
| 185 | 185 | |
| 186 | - // Allow template parts to be filtered |
|
| 187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 186 | + // Allow template parts to be filtered |
|
| 187 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 188 | 188 | |
| 189 | - // Return the part that is found |
|
| 190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 189 | + // Return the part that is found |
|
| 190 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
| 194 | - // No file found yet |
|
| 195 | - $located = false; |
|
| 194 | + // No file found yet |
|
| 195 | + $located = false; |
|
| 196 | 196 | |
| 197 | - // Try to find a template file |
|
| 198 | - foreach ( (array)$template_names as $template_name ) { |
|
| 197 | + // Try to find a template file |
|
| 198 | + foreach ( (array)$template_names as $template_name ) { |
|
| 199 | 199 | |
| 200 | - // Continue if template is empty |
|
| 201 | - if ( empty( $template_name ) ) |
|
| 202 | - continue; |
|
| 200 | + // Continue if template is empty |
|
| 201 | + if ( empty( $template_name ) ) |
|
| 202 | + continue; |
|
| 203 | 203 | |
| 204 | - // Trim off any slashes from the template name |
|
| 205 | - $template_name = ltrim( $template_name, '/' ); |
|
| 204 | + // Trim off any slashes from the template name |
|
| 205 | + $template_name = ltrim( $template_name, '/' ); |
|
| 206 | 206 | |
| 207 | - // try locating this template file by looping through the template paths |
|
| 208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 207 | + // try locating this template file by looping through the template paths |
|
| 208 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 209 | 209 | |
| 210 | - if( file_exists( $template_path . $template_name ) ) { |
|
| 211 | - $located = $template_path . $template_name; |
|
| 212 | - break; |
|
| 213 | - } |
|
| 214 | - } |
|
| 210 | + if( file_exists( $template_path . $template_name ) ) { |
|
| 211 | + $located = $template_path . $template_name; |
|
| 212 | + break; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - if( !empty( $located ) ) { |
|
| 217 | - break; |
|
| 218 | - } |
|
| 219 | - } |
|
| 216 | + if( !empty( $located ) ) { |
|
| 217 | + break; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
| 222 | - load_template( $located, $require_once ); |
|
| 221 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
| 222 | + load_template( $located, $require_once ); |
|
| 223 | 223 | |
| 224 | - return $located; |
|
| 224 | + return $located; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | function wpinv_get_theme_template_paths() { |
| 228 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
| 228 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
| 229 | 229 | |
| 230 | - $file_paths = array( |
|
| 231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 233 | - 100 => wpinv_get_templates_dir() |
|
| 234 | - ); |
|
| 230 | + $file_paths = array( |
|
| 231 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 232 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 233 | + 100 => wpinv_get_templates_dir() |
|
| 234 | + ); |
|
| 235 | 235 | |
| 236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 236 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 237 | 237 | |
| 238 | - // sort the file paths based on priority |
|
| 239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
| 238 | + // sort the file paths based on priority |
|
| 239 | + ksort( $file_paths, SORT_NUMERIC ); |
|
| 240 | 240 | |
| 241 | - return array_map( 'trailingslashit', $file_paths ); |
|
| 241 | + return array_map( 'trailingslashit', $file_paths ); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | function wpinv_checkout_meta_tags() { |
| 245 | 245 | |
| 246 | - $pages = array(); |
|
| 247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
| 248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
| 246 | + $pages = array(); |
|
| 247 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
| 248 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 249 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 250 | + $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
| 251 | 251 | |
| 252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 253 | - return; |
|
| 254 | - } |
|
| 252 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
| 256 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
| 257 | 257 | } |
| 258 | 258 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
| 259 | 259 | |
| 260 | 260 | function wpinv_add_body_classes( $class ) { |
| 261 | - $classes = (array)$class; |
|
| 261 | + $classes = (array)$class; |
|
| 262 | 262 | |
| 263 | - if( wpinv_is_checkout() ) { |
|
| 264 | - $classes[] = 'wpinv-checkout'; |
|
| 265 | - $classes[] = 'wpinv-page'; |
|
| 266 | - } |
|
| 263 | + if( wpinv_is_checkout() ) { |
|
| 264 | + $classes[] = 'wpinv-checkout'; |
|
| 265 | + $classes[] = 'wpinv-page'; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - if( wpinv_is_success_page() ) { |
|
| 269 | - $classes[] = 'wpinv-success'; |
|
| 270 | - $classes[] = 'wpinv-page'; |
|
| 271 | - } |
|
| 268 | + if( wpinv_is_success_page() ) { |
|
| 269 | + $classes[] = 'wpinv-success'; |
|
| 270 | + $classes[] = 'wpinv-page'; |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - if( wpinv_is_failed_transaction_page() ) { |
|
| 274 | - $classes[] = 'wpinv-failed-transaction'; |
|
| 275 | - $classes[] = 'wpinv-page'; |
|
| 276 | - } |
|
| 273 | + if( wpinv_is_failed_transaction_page() ) { |
|
| 274 | + $classes[] = 'wpinv-failed-transaction'; |
|
| 275 | + $classes[] = 'wpinv-page'; |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - if( wpinv_is_invoice_history_page() ) { |
|
| 279 | - $classes[] = 'wpinv-history'; |
|
| 280 | - $classes[] = 'wpinv-page'; |
|
| 281 | - } |
|
| 278 | + if( wpinv_is_invoice_history_page() ) { |
|
| 279 | + $classes[] = 'wpinv-history'; |
|
| 280 | + $classes[] = 'wpinv-page'; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
| 284 | - $classes[] = 'wpinv-subscription'; |
|
| 285 | - $classes[] = 'wpinv-page'; |
|
| 286 | - } |
|
| 283 | + if( wpinv_is_subscriptions_history_page() ) { |
|
| 284 | + $classes[] = 'wpinv-subscription'; |
|
| 285 | + $classes[] = 'wpinv-page'; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - if( wpinv_is_test_mode() ) { |
|
| 289 | - $classes[] = 'wpinv-test-mode'; |
|
| 290 | - $classes[] = 'wpinv-page'; |
|
| 291 | - } |
|
| 288 | + if( wpinv_is_test_mode() ) { |
|
| 289 | + $classes[] = 'wpinv-test-mode'; |
|
| 290 | + $classes[] = 'wpinv-page'; |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - return array_unique( $classes ); |
|
| 293 | + return array_unique( $classes ); |
|
| 294 | 294 | } |
| 295 | 295 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
| 296 | 296 | |
@@ -992,21 +992,21 @@ discard block |
||
| 992 | 992 | |
| 993 | 993 | $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
| 994 | 994 | |
| 995 | - // Remove unavailable tags. |
|
| 995 | + // Remove unavailable tags. |
|
| 996 | 996 | $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
| 997 | 997 | |
| 998 | 998 | // Clean up white space. |
| 999 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
| 999 | + $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
| 1000 | 1000 | $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
| 1001 | 1001 | |
| 1002 | 1002 | // Break newlines apart and remove empty lines/trim commas and white space. |
| 1003 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
| 1003 | + $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
| 1004 | 1004 | |
| 1005 | 1005 | // Add html breaks. |
| 1006 | - $formatted_address = implode( $separator, $formatted_address ); |
|
| 1006 | + $formatted_address = implode( $separator, $formatted_address ); |
|
| 1007 | 1007 | |
| 1008 | - // We're done! |
|
| 1009 | - return $formatted_address; |
|
| 1008 | + // We're done! |
|
| 1009 | + return $formatted_address; |
|
| 1010 | 1010 | |
| 1011 | 1011 | } |
| 1012 | 1012 | |
@@ -1208,7 +1208,7 @@ discard block |
||
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | function wpinv_empty_cart_message() { |
| 1211 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1211 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | 1214 | /** |
@@ -1498,10 +1498,10 @@ discard block |
||
| 1498 | 1498 | |
| 1499 | 1499 | if ( 0 == count( $form->get_items() ) ) { |
| 1500 | 1500 | echo aui()->alert( |
| 1501 | - array( |
|
| 1502 | - 'type' => 'warning', |
|
| 1503 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
| 1504 | - ) |
|
| 1501 | + array( |
|
| 1502 | + 'type' => 'warning', |
|
| 1503 | + 'content' => __( 'No published items found', 'invoicing' ), |
|
| 1504 | + ) |
|
| 1505 | 1505 | ); |
| 1506 | 1506 | return; |
| 1507 | 1507 | } |
@@ -1517,21 +1517,21 @@ discard block |
||
| 1517 | 1517 | $invoice = wpinv_get_invoice( $invoice_id ); |
| 1518 | 1518 | |
| 1519 | 1519 | if ( empty( $invoice ) ) { |
| 1520 | - echo aui()->alert( |
|
| 1521 | - array( |
|
| 1522 | - 'type' => 'warning', |
|
| 1523 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
| 1524 | - ) |
|
| 1520 | + echo aui()->alert( |
|
| 1521 | + array( |
|
| 1522 | + 'type' => 'warning', |
|
| 1523 | + 'content' => __( 'Invoice not found', 'invoicing' ), |
|
| 1524 | + ) |
|
| 1525 | 1525 | ); |
| 1526 | 1526 | return; |
| 1527 | 1527 | } |
| 1528 | 1528 | |
| 1529 | 1529 | if ( $invoice->is_paid() ) { |
| 1530 | - echo aui()->alert( |
|
| 1531 | - array( |
|
| 1532 | - 'type' => 'warning', |
|
| 1533 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
| 1534 | - ) |
|
| 1530 | + echo aui()->alert( |
|
| 1531 | + array( |
|
| 1532 | + 'type' => 'warning', |
|
| 1533 | + 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
| 1534 | + ) |
|
| 1535 | 1535 | ); |
| 1536 | 1536 | return; |
| 1537 | 1537 | } |
@@ -1594,7 +1594,7 @@ discard block |
||
| 1594 | 1594 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; |
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | - if ( ! empty( $items ) ) { |
|
| 1597 | + if ( ! empty( $items ) ) { |
|
| 1598 | 1598 | $items = esc_attr( $items ); |
| 1599 | 1599 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; |
| 1600 | 1600 | } |
@@ -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 ) |
@@ -260,24 +260,24 @@ discard block |
||
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | // Is the request set up correctly? |
| 263 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
| 264 | - echo aui()->alert( |
|
| 265 | - array( |
|
| 266 | - 'type' => 'warning', |
|
| 267 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
| 268 | - ) |
|
| 263 | + if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
| 264 | + echo aui()->alert( |
|
| 265 | + array( |
|
| 266 | + 'type' => 'warning', |
|
| 267 | + 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
| 268 | + ) |
|
| 269 | 269 | ); |
| 270 | 270 | exit; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // Payment form or button? |
| 274 | - if ( ! empty( $_GET['form'] ) ) { |
|
| 274 | + if ( ! empty( $_GET['form'] ) ) { |
|
| 275 | 275 | getpaid_display_payment_form( $_GET['form'] ); |
| 276 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
| 277 | - getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
| 276 | + } else if( ! empty( $_GET['invoice'] ) ) { |
|
| 277 | + getpaid_display_invoice_payment_form( $_GET['invoice'] ); |
|
| 278 | 278 | } else { |
| 279 | - $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
| 280 | - getpaid_display_item_payment_form( $items ); |
|
| 279 | + $items = getpaid_convert_items_to_array( $_GET['item'] ); |
|
| 280 | + getpaid_display_item_payment_form( $items ); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | exit; |
@@ -13,128 +13,128 @@ |
||
| 13 | 13 | class GetPaid_Payment_Forms { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Class constructor |
|
| 17 | - * |
|
| 18 | - */ |
|
| 19 | - public function __construct() { |
|
| 20 | - |
|
| 21 | - // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
| 22 | - add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
| 23 | - add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
| 24 | - |
|
| 25 | - // Sync form amount whenever invoice statuses change. |
|
| 26 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
| 27 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
| 28 | - add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
| 29 | - |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Increments a form's revenue whenever there is a payment. |
|
| 34 | - * |
|
| 35 | - * @param WPInv_Invoice $invoice |
|
| 36 | - */ |
|
| 37 | - public function increment_form_revenue( $invoice ) { |
|
| 38 | - |
|
| 39 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 40 | - if ( $form->get_id() ) { |
|
| 41 | - $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
| 42 | - $form->save(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Decreases form revenue whenever invoice payment changes. |
|
| 49 | - * |
|
| 50 | - * @param WPInv_Invoice $invoice |
|
| 51 | - */ |
|
| 52 | - public function decrease_form_revenue( $invoice ) { |
|
| 53 | - |
|
| 54 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 55 | - if ( $form->get_id() ) { |
|
| 56 | - $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
| 57 | - $form->save(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Updates a form's failed amount. |
|
| 64 | - * |
|
| 65 | - * @param WPInv_Invoice $invoice |
|
| 66 | - * @param string $from |
|
| 67 | - * @param string $to |
|
| 68 | - */ |
|
| 69 | - public function update_form_failed_amount( $invoice, $from, $to ) { |
|
| 70 | - |
|
| 71 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 72 | - if ( $form->get_id() ) { |
|
| 73 | - return; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ( 'wpi-failed' == $from ) { |
|
| 77 | - $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
| 78 | - $form->save(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if ( 'wpi-failed' == $to ) { |
|
| 82 | - $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
| 83 | - $form->save(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Updates a form's refunded amount. |
|
| 90 | - * |
|
| 91 | - * @param WPInv_Invoice $invoice |
|
| 92 | - * @param string $from |
|
| 93 | - * @param string $to |
|
| 94 | - */ |
|
| 95 | - public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
| 96 | - |
|
| 97 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 98 | - if ( $form->get_id() ) { |
|
| 99 | - return; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ( 'wpi-refunded' == $from ) { |
|
| 103 | - $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
| 104 | - $form->save(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ( 'wpi-refunded' == $to ) { |
|
| 108 | - $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
| 109 | - $form->save(); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Updates a form's cancelled amount. |
|
| 116 | - * |
|
| 117 | - * @param WPInv_Invoice $invoice |
|
| 118 | - * @param string $from |
|
| 119 | - * @param string $to |
|
| 120 | - */ |
|
| 121 | - public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
| 122 | - |
|
| 123 | - $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 124 | - if ( $form->get_id() ) { |
|
| 125 | - return; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ( 'wpi-cancelled' == $from ) { |
|
| 129 | - $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
| 130 | - $form->save(); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if ( 'wpi-cancelled' == $to ) { |
|
| 134 | - $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
| 135 | - $form->save(); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - } |
|
| 16 | + * Class constructor |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | + public function __construct() { |
|
| 20 | + |
|
| 21 | + // Update a payment form's revenue whenever an invoice is paid for or refunded. |
|
| 22 | + add_action( 'getpaid_invoice_payment_status_changed', array( $this, 'increment_form_revenue' ) ); |
|
| 23 | + add_action( 'getpaid_invoice_payment_status_reversed', array( $this, 'decrease_form_revenue' ) ); |
|
| 24 | + |
|
| 25 | + // Sync form amount whenever invoice statuses change. |
|
| 26 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_failed_amount' ), 10, 3 ); |
|
| 27 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_refunded_amount' ), 10, 3 ); |
|
| 28 | + add_action( 'getpaid_invoice_status_changed', array( $this, 'update_form_cancelled_amount' ), 10, 3 ); |
|
| 29 | + |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Increments a form's revenue whenever there is a payment. |
|
| 34 | + * |
|
| 35 | + * @param WPInv_Invoice $invoice |
|
| 36 | + */ |
|
| 37 | + public function increment_form_revenue( $invoice ) { |
|
| 38 | + |
|
| 39 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 40 | + if ( $form->get_id() ) { |
|
| 41 | + $form->set_earned( $form->get_earned() + $invoice->get_total() ); |
|
| 42 | + $form->save(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Decreases form revenue whenever invoice payment changes. |
|
| 49 | + * |
|
| 50 | + * @param WPInv_Invoice $invoice |
|
| 51 | + */ |
|
| 52 | + public function decrease_form_revenue( $invoice ) { |
|
| 53 | + |
|
| 54 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 55 | + if ( $form->get_id() ) { |
|
| 56 | + $form->set_earned( $form->get_earned() - $invoice->get_total() ); |
|
| 57 | + $form->save(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Updates a form's failed amount. |
|
| 64 | + * |
|
| 65 | + * @param WPInv_Invoice $invoice |
|
| 66 | + * @param string $from |
|
| 67 | + * @param string $to |
|
| 68 | + */ |
|
| 69 | + public function update_form_failed_amount( $invoice, $from, $to ) { |
|
| 70 | + |
|
| 71 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 72 | + if ( $form->get_id() ) { |
|
| 73 | + return; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ( 'wpi-failed' == $from ) { |
|
| 77 | + $form->set_failed( $form->get_failed() - $invoice->get_total() ); |
|
| 78 | + $form->save(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if ( 'wpi-failed' == $to ) { |
|
| 82 | + $form->set_failed( $form->get_failed() + $invoice->get_total() ); |
|
| 83 | + $form->save(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Updates a form's refunded amount. |
|
| 90 | + * |
|
| 91 | + * @param WPInv_Invoice $invoice |
|
| 92 | + * @param string $from |
|
| 93 | + * @param string $to |
|
| 94 | + */ |
|
| 95 | + public function update_form_refunded_amount( $invoice, $from, $to ) { |
|
| 96 | + |
|
| 97 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 98 | + if ( $form->get_id() ) { |
|
| 99 | + return; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ( 'wpi-refunded' == $from ) { |
|
| 103 | + $form->set_refunded( $form->get_refunded() - $invoice->get_total() ); |
|
| 104 | + $form->save(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ( 'wpi-refunded' == $to ) { |
|
| 108 | + $form->set_refunded( $form->get_refunded() + $invoice->get_total() ); |
|
| 109 | + $form->save(); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Updates a form's cancelled amount. |
|
| 116 | + * |
|
| 117 | + * @param WPInv_Invoice $invoice |
|
| 118 | + * @param string $from |
|
| 119 | + * @param string $to |
|
| 120 | + */ |
|
| 121 | + public function update_form_cancelled_amount( $invoice, $from, $to ) { |
|
| 122 | + |
|
| 123 | + $form = new GetPaid_Payment_Form( $invoice->get_payment_form() ); |
|
| 124 | + if ( $form->get_id() ) { |
|
| 125 | + return; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ( 'wpi-cancelled' == $from ) { |
|
| 129 | + $form->set_cancelled( $form->get_cancelled() - $invoice->get_total() ); |
|
| 130 | + $form->save(); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if ( 'wpi-cancelled' == $to ) { |
|
| 134 | + $form->set_cancelled( $form->get_cancelled() + $invoice->get_total() ); |
|
| 135 | + $form->save(); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; // Exit if accessed directly |
|
| 10 | + exit; // Exit if accessed directly |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -16,10 +16,10 @@ discard block |
||
| 16 | 16 | class GetPaid_Meta_Box_Payment_Form { |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | - * Output the metabox. |
|
| 20 | - * |
|
| 21 | - * @param WP_Post $post |
|
| 22 | - */ |
|
| 19 | + * Output the metabox. |
|
| 20 | + * |
|
| 21 | + * @param WP_Post $post |
|
| 22 | + */ |
|
| 23 | 23 | public static function output( $post ) { |
| 24 | 24 | ?> |
| 25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | - * Save meta box data. |
|
| 90 | - * |
|
| 91 | - * @param int $post_id |
|
| 92 | - */ |
|
| 93 | - public static function save( $post_id ) { |
|
| 89 | + * Save meta box data. |
|
| 90 | + * |
|
| 91 | + * @param int $post_id |
|
| 92 | + */ |
|
| 93 | + public static function save( $post_id ) { |
|
| 94 | 94 | |
| 95 | 95 | // Prepare the form. |
| 96 | 96 | $form = new GetPaid_Payment_Form( $post_id ); |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | - * Converts an array fo form items to objects. |
|
| 125 | - * |
|
| 126 | - * @param array $items |
|
| 127 | - */ |
|
| 128 | - public static function item_to_objects( $items ) { |
|
| 124 | + * Converts an array fo form items to objects. |
|
| 125 | + * |
|
| 126 | + * @param array $items |
|
| 127 | + */ |
|
| 128 | + public static function item_to_objects( $items ) { |
|
| 129 | 129 | |
| 130 | 130 | $objects = array(); |
| 131 | 131 | |
@@ -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 | /** |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Output the metabox. |
|
| 21 | - * |
|
| 22 | - * @param WP_Post $post |
|
| 23 | - */ |
|
| 20 | + * Output the metabox. |
|
| 21 | + * |
|
| 22 | + * @param WP_Post $post |
|
| 23 | + */ |
|
| 24 | 24 | public static function output( $post ) { |
| 25 | 25 | |
| 26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
| 371 | - * Save meta box data. |
|
| 372 | - * |
|
| 373 | - * @param int $post_id |
|
| 374 | - */ |
|
| 375 | - public static function save( $post_id ) { |
|
| 371 | + * Save meta box data. |
|
| 372 | + * |
|
| 373 | + * @param int $post_id |
|
| 374 | + */ |
|
| 375 | + public static function save( $post_id ) { |
|
| 376 | 376 | |
| 377 | 377 | // Prepare the discount. |
| 378 | 378 | $discount = new WPInv_Discount( $post_id ); |
| 379 | 379 | |
| 380 | 380 | // Load new data. |
| 381 | 381 | $discount->set_props( |
| 382 | - array( |
|
| 383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
| 384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
| 385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
| 386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
| 387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
| 382 | + array( |
|
| 383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
| 384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
| 385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
| 386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
| 387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
| 388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
| 389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
| 390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
| 391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
| 392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
| 393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
| 394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
| 395 | - ) |
|
| 389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
| 390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
| 391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
| 392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
| 393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
| 394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
| 395 | + ) |
|
| 396 | 396 | ); |
| 397 | 397 | |
| 398 | - $discount->save(); |
|
| 399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
| 400 | - } |
|
| 398 | + $discount->save(); |
|
| 399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
| 400 | + } |
|
| 401 | 401 | } |
@@ -12,108 +12,108 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * The fee validation error. |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - public $fee_error; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Submission fees. |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $fees = array(); |
|
| 15 | + /** |
|
| 16 | + * The fee validation error. |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + public $fee_error; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Submission fees. |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $fees = array(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Process any existing invoice fees. |
|
| 35 | + if ( $submission->has_invoice() ) { |
|
| 36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Process price fields. |
|
| 40 | + $data = $submission->get_data(); |
|
| 41 | + $payment_form = $submission->get_payment_form(); |
|
| 42 | + |
|
| 43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | + |
|
| 45 | + if ( 'price_input' == $element['type'] ) { |
|
| 46 | + $this->process_price_input( $element, $data ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ( 'price_select' == $element['type'] ) { |
|
| 50 | + $this->process_price_select( $element, $data ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Process a price input field. |
|
| 59 | + * |
|
| 60 | + * @param array $element |
|
| 61 | + * @param array $data |
|
| 62 | + */ |
|
| 63 | + public function process_price_input( $element, $data ) { |
|
| 64 | + |
|
| 65 | + // Abort if not passed. |
|
| 66 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 67 | + return; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 72 | + |
|
| 73 | + if ( $amount < $minimum ) { |
|
| 74 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $this->fees[ $element['label'] ] = array( |
|
| 78 | + 'name' => $element['label'], |
|
| 79 | + 'initial_fee' => $amount, |
|
| 80 | + 'recurring_fee' => 0, |
|
| 81 | + ); |
|
| 82 | + |
|
| 83 | + } |
|
| 26 | 84 | |
| 27 | 85 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Process any existing invoice fees. |
|
| 35 | - if ( $submission->has_invoice() ) { |
|
| 36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Process price fields. |
|
| 40 | - $data = $submission->get_data(); |
|
| 41 | - $payment_form = $submission->get_payment_form(); |
|
| 42 | - |
|
| 43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | - |
|
| 45 | - if ( 'price_input' == $element['type'] ) { |
|
| 46 | - $this->process_price_input( $element, $data ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ( 'price_select' == $element['type'] ) { |
|
| 50 | - $this->process_price_select( $element, $data ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Process a price input field. |
|
| 59 | - * |
|
| 60 | - * @param array $element |
|
| 61 | - * @param array $data |
|
| 62 | - */ |
|
| 63 | - public function process_price_input( $element, $data ) { |
|
| 64 | - |
|
| 65 | - // Abort if not passed. |
|
| 66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 67 | - return; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 72 | - |
|
| 73 | - if ( $amount < $minimum ) { |
|
| 74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $this->fees[ $element['label'] ] = array( |
|
| 78 | - 'name' => $element['label'], |
|
| 79 | - 'initial_fee' => $amount, |
|
| 80 | - 'recurring_fee' => 0, |
|
| 81 | - ); |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Process a price select field. |
|
| 87 | - * |
|
| 88 | - * @param array $element |
|
| 89 | - * @param array $data |
|
| 90 | - */ |
|
| 91 | - public function process_price_select( $element, $data ) { |
|
| 92 | - |
|
| 93 | - // Abort if not passed. |
|
| 94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
| 100 | - $total = 0; |
|
| 101 | - |
|
| 102 | - foreach ( $selected as $price ) { |
|
| 103 | - |
|
| 104 | - if ( ! isset( $options[ $price ] ) ) { |
|
| 105 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $total += (float) wpinv_sanitize_amount( $price ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $this->fees[ $element['label'] ] = array( |
|
| 112 | - 'name' => $element['label'], |
|
| 113 | - 'initial_fee' => $total, |
|
| 114 | - 'recurring_fee' => 0, |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - } |
|
| 86 | + * Process a price select field. |
|
| 87 | + * |
|
| 88 | + * @param array $element |
|
| 89 | + * @param array $data |
|
| 90 | + */ |
|
| 91 | + public function process_price_select( $element, $data ) { |
|
| 92 | + |
|
| 93 | + // Abort if not passed. |
|
| 94 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | + $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
| 100 | + $total = 0; |
|
| 101 | + |
|
| 102 | + foreach ( $selected as $price ) { |
|
| 103 | + |
|
| 104 | + if ( ! isset( $options[ $price ] ) ) { |
|
| 105 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $total += (float) wpinv_sanitize_amount( $price ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $this->fees[ $element['label'] ] = array( |
|
| 112 | + 'name' => $element['label'], |
|
| 113 | + 'initial_fee' => $total, |
|
| 114 | + 'recurring_fee' => 0, |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } |
@@ -12,231 +12,231 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission taxes. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $taxes = array(); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Initial tax. |
|
| 23 | - * @var float |
|
| 24 | - */ |
|
| 25 | - protected $initial_tax = 0; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Recurring tax. |
|
| 29 | - * @var float |
|
| 30 | - */ |
|
| 31 | - protected $recurring_tax = 0; |
|
| 15 | + /** |
|
| 16 | + * Submission taxes. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $taxes = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Initial tax. |
|
| 23 | + * @var float |
|
| 24 | + */ |
|
| 25 | + protected $initial_tax = 0; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Recurring tax. |
|
| 29 | + * @var float |
|
| 30 | + */ |
|
| 31 | + protected $recurring_tax = 0; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Class constructor |
|
| 35 | + * |
|
| 36 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 37 | + */ |
|
| 38 | + public function __construct( $submission ) { |
|
| 39 | + |
|
| 40 | + // Validate VAT number. |
|
| 41 | + $this->validate_vat( $submission ); |
|
| 42 | + |
|
| 43 | + foreach ( $submission->get_items() as $item ) { |
|
| 44 | + $this->process_item_tax( $item, $submission ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Process any existing invoice taxes. |
|
| 48 | + if ( $submission->has_invoice() ) { |
|
| 49 | + $this->taxes = $submission->get_invoice()->get_taxes(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + // Add VAT. |
|
| 53 | + $this->taxes['vat'] = array( |
|
| 54 | + 'name' => 'vat', |
|
| 55 | + 'initial_tax' => $this->initial_tax, |
|
| 56 | + 'recurring_tax' => $this->recurring_tax, |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Maybe process tax. |
|
| 63 | + * |
|
| 64 | + * @since 1.0.19 |
|
| 65 | + * @param GetPaid_Form_Item $item |
|
| 66 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 67 | + */ |
|
| 68 | + public function process_item_tax( $item, $submission ) { |
|
| 69 | + |
|
| 70 | + $rate = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() ); |
|
| 71 | + $price = $item->get_sub_total(); |
|
| 72 | + $item_tax = $price * $rate * 0.01; |
|
| 73 | + |
|
| 74 | + if ( wpinv_prices_include_tax() ) { |
|
| 75 | + $item_tax = $price - ( $price - $price * $rate * 0.01 ); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $this->initial_tax += $item_tax; |
|
| 79 | + |
|
| 80 | + if ( $item->is_recurring() ) { |
|
| 81 | + $this->recurring_tax += $item_tax; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Checks if the submission has a digital item. |
|
| 88 | + * |
|
| 89 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 90 | + * @since 1.0.19 |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + public function has_digital_item( $submission ) { |
|
| 94 | + |
|
| 95 | + foreach ( $submission->get_items() as $item ) { |
|
| 96 | + |
|
| 97 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
| 98 | + return true; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Checks if this is an eu store. |
|
| 108 | + * |
|
| 109 | + * @since 1.0.19 |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function is_eu_store() { |
|
| 113 | + return $this->is_eu_country( wpinv_get_default_country() ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Checks if this is an eu country. |
|
| 118 | + * |
|
| 119 | + * @param string $country |
|
| 120 | + * @since 1.0.19 |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + public function is_eu_country( $country ) { |
|
| 124 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Checks if this is an eu purchase. |
|
| 129 | + * |
|
| 130 | + * @param string $customer_country |
|
| 131 | + * @since 1.0.19 |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function is_eu_transaction( $customer_country ) { |
|
| 135 | + return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Retrieves the vat number. |
|
| 140 | + * |
|
| 141 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 142 | + * @since 1.0.19 |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function get_vat_number( $submission ) { |
|
| 146 | + |
|
| 147 | + // Retrieve from the posted number. |
|
| 148 | + $vat_number = $submission->get_field( 'wpinv_vat_number' ); |
|
| 149 | + if ( ! empty( $vat_number ) ) { |
|
| 150 | + return wpinv_clean( $vat_number ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Retrieve from the invoice. |
|
| 154 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Retrieves the company. |
|
| 159 | + * |
|
| 160 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 161 | + * @since 1.0.19 |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public function get_company( $submission ) { |
|
| 165 | + |
|
| 166 | + // Retrieve from the posted data. |
|
| 167 | + $company = $submission->get_field( 'wpinv_company' ); |
|
| 168 | + if ( ! empty( $company ) ) { |
|
| 169 | + return wpinv_clean( $company ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // Retrieve from the invoice. |
|
| 173 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Checks if we requires a VAT number. |
|
| 178 | + * |
|
| 179 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 180 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 181 | + * @since 1.0.19 |
|
| 182 | + * @return string |
|
| 183 | + */ |
|
| 184 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 185 | + |
|
| 186 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 187 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 188 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
| 189 | + |
|
| 190 | + return $prevent_b2c && $is_eu; |
|
| 191 | + } |
|
| 32 | 192 | |
| 33 | 193 | /** |
| 34 | - * Class constructor |
|
| 35 | - * |
|
| 36 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 37 | - */ |
|
| 38 | - public function __construct( $submission ) { |
|
| 39 | - |
|
| 40 | - // Validate VAT number. |
|
| 41 | - $this->validate_vat( $submission ); |
|
| 42 | - |
|
| 43 | - foreach ( $submission->get_items() as $item ) { |
|
| 44 | - $this->process_item_tax( $item, $submission ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Process any existing invoice taxes. |
|
| 48 | - if ( $submission->has_invoice() ) { |
|
| 49 | - $this->taxes = $submission->get_invoice()->get_taxes(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - // Add VAT. |
|
| 53 | - $this->taxes['vat'] = array( |
|
| 54 | - 'name' => 'vat', |
|
| 55 | - 'initial_tax' => $this->initial_tax, |
|
| 56 | - 'recurring_tax' => $this->recurring_tax, |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Maybe process tax. |
|
| 63 | - * |
|
| 64 | - * @since 1.0.19 |
|
| 65 | - * @param GetPaid_Form_Item $item |
|
| 66 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 67 | - */ |
|
| 68 | - public function process_item_tax( $item, $submission ) { |
|
| 69 | - |
|
| 70 | - $rate = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() ); |
|
| 71 | - $price = $item->get_sub_total(); |
|
| 72 | - $item_tax = $price * $rate * 0.01; |
|
| 73 | - |
|
| 74 | - if ( wpinv_prices_include_tax() ) { |
|
| 75 | - $item_tax = $price - ( $price - $price * $rate * 0.01 ); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $this->initial_tax += $item_tax; |
|
| 79 | - |
|
| 80 | - if ( $item->is_recurring() ) { |
|
| 81 | - $this->recurring_tax += $item_tax; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Checks if the submission has a digital item. |
|
| 88 | - * |
|
| 89 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 90 | - * @since 1.0.19 |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - public function has_digital_item( $submission ) { |
|
| 94 | - |
|
| 95 | - foreach ( $submission->get_items() as $item ) { |
|
| 96 | - |
|
| 97 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 98 | - return true; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Checks if this is an eu store. |
|
| 108 | - * |
|
| 109 | - * @since 1.0.19 |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function is_eu_store() { |
|
| 113 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Checks if this is an eu country. |
|
| 118 | - * |
|
| 119 | - * @param string $country |
|
| 120 | - * @since 1.0.19 |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - public function is_eu_country( $country ) { |
|
| 124 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Checks if this is an eu purchase. |
|
| 129 | - * |
|
| 130 | - * @param string $customer_country |
|
| 131 | - * @since 1.0.19 |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function is_eu_transaction( $customer_country ) { |
|
| 135 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Retrieves the vat number. |
|
| 140 | - * |
|
| 141 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 142 | - * @since 1.0.19 |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function get_vat_number( $submission ) { |
|
| 146 | - |
|
| 147 | - // Retrieve from the posted number. |
|
| 148 | - $vat_number = $submission->get_field( 'wpinv_vat_number' ); |
|
| 149 | - if ( ! empty( $vat_number ) ) { |
|
| 150 | - return wpinv_clean( $vat_number ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Retrieve from the invoice. |
|
| 154 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Retrieves the company. |
|
| 159 | - * |
|
| 160 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 161 | - * @since 1.0.19 |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function get_company( $submission ) { |
|
| 165 | - |
|
| 166 | - // Retrieve from the posted data. |
|
| 167 | - $company = $submission->get_field( 'wpinv_company' ); |
|
| 168 | - if ( ! empty( $company ) ) { |
|
| 169 | - return wpinv_clean( $company ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // Retrieve from the invoice. |
|
| 173 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Checks if we requires a VAT number. |
|
| 178 | - * |
|
| 179 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 180 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 181 | - * @since 1.0.19 |
|
| 182 | - * @return string |
|
| 183 | - */ |
|
| 184 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 185 | - |
|
| 186 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 187 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 188 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
| 189 | - |
|
| 190 | - return $prevent_b2c && $is_eu; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Validate VAT data. |
|
| 195 | - * |
|
| 196 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 197 | - * @since 1.0.19 |
|
| 198 | - */ |
|
| 199 | - public function validate_vat( $submission ) { |
|
| 200 | - |
|
| 201 | - $has_digital = $this->has_digital_item( $submission ); |
|
| 202 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 203 | - |
|
| 204 | - // Abort if we are not validating vat numbers. |
|
| 205 | - if ( ! $has_digital && ! $in_eu ) { |
|
| 194 | + * Validate VAT data. |
|
| 195 | + * |
|
| 196 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 197 | + * @since 1.0.19 |
|
| 198 | + */ |
|
| 199 | + public function validate_vat( $submission ) { |
|
| 200 | + |
|
| 201 | + $has_digital = $this->has_digital_item( $submission ); |
|
| 202 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 203 | + |
|
| 204 | + // Abort if we are not validating vat numbers. |
|
| 205 | + if ( ! $has_digital && ! $in_eu ) { |
|
| 206 | 206 | return; |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - // Prepare variables. |
|
| 210 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 211 | - $company = $this->get_company( $submission ); |
|
| 212 | - $ip_country = WPInv_EUVat::get_country_by_ip(); |
|
| 209 | + // Prepare variables. |
|
| 210 | + $vat_number = $this->get_vat_number( $submission ); |
|
| 211 | + $company = $this->get_company( $submission ); |
|
| 212 | + $ip_country = WPInv_EUVat::get_country_by_ip(); |
|
| 213 | 213 | $is_eu = $this->is_eu_country( $submission->country ); |
| 214 | 214 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
| 215 | 215 | |
| 216 | - // If we're preventing business to consumer purchases, ensure |
|
| 217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 216 | + // If we're preventing business to consumer purchases, ensure |
|
| 217 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 218 | 218 | |
| 219 | - // Ensure that a vat number has been specified. |
|
| 220 | - throw new Exception( |
|
| 221 | - wp_sprintf( |
|
| 222 | - __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
| 223 | - getpaid_vat_name() |
|
| 224 | - ) |
|
| 225 | - ); |
|
| 219 | + // Ensure that a vat number has been specified. |
|
| 220 | + throw new Exception( |
|
| 221 | + wp_sprintf( |
|
| 222 | + __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
| 223 | + getpaid_vat_name() |
|
| 224 | + ) |
|
| 225 | + ); |
|
| 226 | 226 | |
| 227 | - } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
|
| 230 | - if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) { |
|
| 229 | + // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
|
| 230 | + if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) { |
|
| 231 | 231 | return; |
| 232 | - } |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country ); |
|
| 234 | + $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country ); |
|
| 235 | 235 | |
| 236 | - if ( is_string( $is_valid ) ) { |
|
| 237 | - throw new Exception( $is_valid ); |
|
| 238 | - } |
|
| 236 | + if ( is_string( $is_valid ) ) { |
|
| 237 | + throw new Exception( $is_valid ); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | 242 | } |
@@ -12,77 +12,77 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission items. |
|
| 17 | - * @var GetPaid_Form_Item[] |
|
| 18 | - */ |
|
| 19 | - public $items = array(); |
|
| 15 | + /** |
|
| 16 | + * Submission items. |
|
| 17 | + * @var GetPaid_Form_Item[] |
|
| 18 | + */ |
|
| 19 | + public $items = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | 27 | |
| 28 | - $data = $submission->get_data(); |
|
| 29 | - $payment_form = $submission->get_payment_form(); |
|
| 28 | + $data = $submission->get_data(); |
|
| 29 | + $payment_form = $submission->get_payment_form(); |
|
| 30 | 30 | |
| 31 | - // Prepare the selected items. |
|
| 32 | - $selected_items = array(); |
|
| 33 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | - } |
|
| 31 | + // Prepare the selected items. |
|
| 32 | + $selected_items = array(); |
|
| 33 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 34 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // For default forms, ensure that an item has been set. |
|
| 38 | - if ( $payment_form->is_default() && ! $submission->has_invoice() ) { |
|
| 39 | - $payment_form->set_items( $selected_items ); |
|
| 40 | - } |
|
| 37 | + // For default forms, ensure that an item has been set. |
|
| 38 | + if ( $payment_form->is_default() && ! $submission->has_invoice() ) { |
|
| 39 | + $payment_form->set_items( $selected_items ); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - // Process each individual item. |
|
| 43 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 44 | - $this->process_item( $item, $selected_items ); |
|
| 45 | - } |
|
| 42 | + // Process each individual item. |
|
| 43 | + foreach ( $payment_form->get_items() as $item ) { |
|
| 44 | + $this->process_item( $item, $selected_items ); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Process a single item. |
|
| 51 | - * |
|
| 52 | - * @param GetPaid_Form_Item $item |
|
| 53 | - * @param array $selected_items |
|
| 54 | - */ |
|
| 55 | - public function process_item( $item, $selected_items ) { |
|
| 49 | + /** |
|
| 50 | + * Process a single item. |
|
| 51 | + * |
|
| 52 | + * @param GetPaid_Form_Item $item |
|
| 53 | + * @param array $selected_items |
|
| 54 | + */ |
|
| 55 | + public function process_item( $item, $selected_items ) { |
|
| 56 | 56 | |
| 57 | - // Abort if this is an optional item and it has not been selected. |
|
| 58 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 59 | - return; |
|
| 60 | - } |
|
| 57 | + // Abort if this is an optional item and it has not been selected. |
|
| 58 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - // (maybe) let customers change the quantities and prices. |
|
| 63 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 62 | + // (maybe) let customers change the quantities and prices. |
|
| 63 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 64 | 64 | |
| 65 | - // Maybe change the quantities. |
|
| 66 | - if ( $item->allows_quantities() ) { |
|
| 67 | - $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 68 | - } |
|
| 65 | + // Maybe change the quantities. |
|
| 66 | + if ( $item->allows_quantities() ) { |
|
| 67 | + $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - // Maybe change the price. |
|
| 71 | - if ( $item->user_can_set_their_price() ) { |
|
| 72 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 70 | + // Maybe change the price. |
|
| 71 | + if ( $item->user_can_set_their_price() ) { |
|
| 72 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 73 | 73 | |
| 74 | - // But don't get lower than the minimum price. |
|
| 75 | - $price = max( $price, $item->get_minimum_price() ); |
|
| 74 | + // But don't get lower than the minimum price. |
|
| 75 | + $price = max( $price, $item->get_minimum_price() ); |
|
| 76 | 76 | |
| 77 | - $item->set_price( $price ); |
|
| 77 | + $item->set_price( $price ); |
|
| 78 | 78 | |
| 79 | - } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - // Save the item. |
|
| 84 | - $this->items[] = $item; |
|
| 83 | + // Save the item. |
|
| 84 | + $this->items[] = $item; |
|
| 85 | 85 | |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | } |