@@ -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_Invoice_Payment_Meta { |
| 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 invoice. |
@@ -42,167 +42,167 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | if ( $invoice->is_draft() ) { |
| 44 | 44 | |
| 45 | - // Set gateway. |
|
| 46 | - aui()->select( |
|
| 47 | - array( |
|
| 48 | - 'id' => 'wpinv_gateway', |
|
| 49 | - 'name' => 'wpinv_gateway', |
|
| 50 | - 'label' => __( 'Gateway:', 'invoicing' ), |
|
| 51 | - 'label_type' => 'vertical', |
|
| 52 | - 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
| 53 | - 'value' => wpinv_get_default_gateway(), |
|
| 54 | - 'select2' => true, |
|
| 55 | - 'data-allow-clear' => 'false', |
|
| 56 | - 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
| 57 | - ), |
|
| 58 | - true |
|
| 59 | - ); |
|
| 45 | + // Set gateway. |
|
| 46 | + aui()->select( |
|
| 47 | + array( |
|
| 48 | + 'id' => 'wpinv_gateway', |
|
| 49 | + 'name' => 'wpinv_gateway', |
|
| 50 | + 'label' => __( 'Gateway:', 'invoicing' ), |
|
| 51 | + 'label_type' => 'vertical', |
|
| 52 | + 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
| 53 | + 'value' => wpinv_get_default_gateway(), |
|
| 54 | + 'select2' => true, |
|
| 55 | + 'data-allow-clear' => 'false', |
|
| 56 | + 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
| 57 | + ), |
|
| 58 | + true |
|
| 59 | + ); |
|
| 60 | 60 | |
| 61 | 61 | } else { |
| 62 | 62 | |
| 63 | - // Invoice key. |
|
| 64 | - aui()->input( |
|
| 65 | - array( |
|
| 66 | - 'type' => 'text', |
|
| 67 | - 'id' => 'wpinv_key', |
|
| 68 | - 'name' => 'wpinv_key', |
|
| 69 | - 'label' => sprintf( |
|
| 70 | - // translators: %s: Invoice type. |
|
| 71 | - __( '%s Key:', 'invoicing' ), |
|
| 72 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 73 | - ), |
|
| 74 | - 'label_type' => 'vertical', |
|
| 75 | - 'class' => 'form-control-sm', |
|
| 76 | - 'value' => $invoice->get_key( 'edit' ), |
|
| 77 | - 'extra_attributes' => array( |
|
| 78 | - 'onclick' => 'this.select();', |
|
| 79 | - 'readonly' => 'true', |
|
| 80 | - ), |
|
| 81 | - ), |
|
| 82 | - true |
|
| 83 | - ); |
|
| 84 | - |
|
| 85 | - // View URL. |
|
| 86 | - aui()->input( |
|
| 87 | - array( |
|
| 88 | - 'type' => 'text', |
|
| 89 | - 'id' => 'wpinv_view_url', |
|
| 90 | - 'name' => 'wpinv_view_url', |
|
| 91 | - 'label' => sprintf( |
|
| 92 | - // translators: %s: Invoice type. |
|
| 93 | - __( '%s URL:', 'invoicing' ), |
|
| 94 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 95 | - ) . ' <a href="' . esc_url_raw( $invoice->get_view_url() ) . '" title="' . __( 'View invoice', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>', |
|
| 96 | - 'label_type' => 'vertical', |
|
| 97 | - 'class' => 'form-control-sm', |
|
| 98 | - 'value' => $invoice->get_view_url(), |
|
| 99 | - 'extra_attributes' => array( |
|
| 100 | - 'onclick' => 'this.select();', |
|
| 101 | - 'readonly' => 'true', |
|
| 102 | - ), |
|
| 103 | - ), |
|
| 104 | - true |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - // If the invoice is paid... |
|
| 108 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 109 | - |
|
| 110 | - // Gateway. |
|
| 111 | - aui()->input( |
|
| 112 | - array( |
|
| 113 | - 'type' => 'text', |
|
| 114 | - 'id' => 'wpinv_gateway', |
|
| 115 | - 'name' => '', |
|
| 116 | - 'label' => __( 'Gateway:', 'invoicing' ), |
|
| 117 | - 'label_type' => 'vertical', |
|
| 118 | - 'class' => 'form-control-sm', |
|
| 119 | - 'value' => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ), |
|
| 120 | - 'extra_attributes' => array( |
|
| 121 | - 'onclick' => 'this.select();', |
|
| 122 | - 'readonly' => 'true', |
|
| 123 | - ), |
|
| 124 | - ), |
|
| 125 | - true |
|
| 126 | - ); |
|
| 127 | - |
|
| 128 | - // Transaction ID. |
|
| 129 | - $transaction_url = $invoice->get_transaction_url(); |
|
| 130 | - aui()->input( |
|
| 131 | - array( |
|
| 132 | - 'type' => 'text', |
|
| 133 | - 'id' => 'wpinv_transaction_id', |
|
| 134 | - 'name' => 'wpinv_transaction_id', |
|
| 135 | - 'label' => __( 'Transaction ID:', 'invoicing' ) . ( $transaction_url ? ' <a href="' . esc_url( $transaction_url ) . '" title="' . __( 'View details', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>' : '' ), |
|
| 136 | - 'label_type' => 'vertical', |
|
| 137 | - 'class' => 'form-control-sm', |
|
| 138 | - 'value' => $invoice->get_transaction_id( 'edit' ), |
|
| 139 | - 'help_text' => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), '', $invoice->get_transaction_id(), $invoice ), |
|
| 140 | - 'extra_attributes' => array( |
|
| 141 | - 'onclick' => 'this.select();', |
|
| 142 | - 'readonly' => 'true', |
|
| 143 | - ), |
|
| 144 | - ), |
|
| 145 | - true |
|
| 146 | - ); |
|
| 147 | - |
|
| 148 | - // Currency. |
|
| 149 | - aui()->input( |
|
| 150 | - array( |
|
| 151 | - 'type' => 'text', |
|
| 152 | - 'id' => 'wpinv_currency', |
|
| 153 | - 'name' => 'wpinv_currency', |
|
| 154 | - 'label' => __( 'Currency:', 'invoicing' ), |
|
| 155 | - 'label_type' => 'vertical', |
|
| 156 | - 'class' => 'form-control-sm', |
|
| 157 | - 'value' => $invoice->get_currency( 'edit' ), |
|
| 158 | - 'extra_attributes' => array( |
|
| 159 | - 'onclick' => 'this.select();', |
|
| 160 | - 'readonly' => 'true', |
|
| 161 | - ), |
|
| 162 | - ), |
|
| 163 | - true |
|
| 164 | - ); |
|
| 165 | - |
|
| 166 | - } else { |
|
| 167 | - |
|
| 168 | - if ( 'wpi_invoice' === $invoice->get_post_type() ) { |
|
| 169 | - |
|
| 170 | - // Payment URL. |
|
| 171 | - aui()->input( |
|
| 172 | - array( |
|
| 173 | - 'type' => 'text', |
|
| 174 | - 'id' => 'wpinv_payment_url', |
|
| 175 | - 'name' => 'wpinv_payment_url', |
|
| 176 | - 'label' => __( 'Payment URL:', 'invoicing' ), |
|
| 177 | - 'label_type' => 'vertical', |
|
| 178 | - 'class' => 'form-control-sm', |
|
| 179 | - 'value' => $invoice->get_checkout_payment_url(), |
|
| 180 | - 'extra_attributes' => array( |
|
| 181 | - 'onclick' => 'this.select();', |
|
| 182 | - 'readonly' => 'true', |
|
| 183 | - ), |
|
| 184 | - ), |
|
| 185 | - true |
|
| 186 | - ); |
|
| 187 | - |
|
| 188 | - // Set gateway. |
|
| 189 | - aui()->select( |
|
| 190 | - array( |
|
| 191 | - 'id' => 'wpinv_gateway', |
|
| 192 | - 'name' => 'wpinv_gateway', |
|
| 193 | - 'label' => __( 'Gateway:', 'invoicing' ), |
|
| 194 | - 'label_type' => 'vertical', |
|
| 195 | - 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
| 196 | - 'value' => $invoice->get_gateway( 'edit' ), |
|
| 197 | - 'select2' => true, |
|
| 198 | - 'data-allow-clear' => 'false', |
|
| 199 | - 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
| 200 | - ), |
|
| 201 | - true |
|
| 202 | - ); |
|
| 203 | - |
|
| 204 | - } |
|
| 205 | - } |
|
| 63 | + // Invoice key. |
|
| 64 | + aui()->input( |
|
| 65 | + array( |
|
| 66 | + 'type' => 'text', |
|
| 67 | + 'id' => 'wpinv_key', |
|
| 68 | + 'name' => 'wpinv_key', |
|
| 69 | + 'label' => sprintf( |
|
| 70 | + // translators: %s: Invoice type. |
|
| 71 | + __( '%s Key:', 'invoicing' ), |
|
| 72 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 73 | + ), |
|
| 74 | + 'label_type' => 'vertical', |
|
| 75 | + 'class' => 'form-control-sm', |
|
| 76 | + 'value' => $invoice->get_key( 'edit' ), |
|
| 77 | + 'extra_attributes' => array( |
|
| 78 | + 'onclick' => 'this.select();', |
|
| 79 | + 'readonly' => 'true', |
|
| 80 | + ), |
|
| 81 | + ), |
|
| 82 | + true |
|
| 83 | + ); |
|
| 84 | + |
|
| 85 | + // View URL. |
|
| 86 | + aui()->input( |
|
| 87 | + array( |
|
| 88 | + 'type' => 'text', |
|
| 89 | + 'id' => 'wpinv_view_url', |
|
| 90 | + 'name' => 'wpinv_view_url', |
|
| 91 | + 'label' => sprintf( |
|
| 92 | + // translators: %s: Invoice type. |
|
| 93 | + __( '%s URL:', 'invoicing' ), |
|
| 94 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 95 | + ) . ' <a href="' . esc_url_raw( $invoice->get_view_url() ) . '" title="' . __( 'View invoice', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>', |
|
| 96 | + 'label_type' => 'vertical', |
|
| 97 | + 'class' => 'form-control-sm', |
|
| 98 | + 'value' => $invoice->get_view_url(), |
|
| 99 | + 'extra_attributes' => array( |
|
| 100 | + 'onclick' => 'this.select();', |
|
| 101 | + 'readonly' => 'true', |
|
| 102 | + ), |
|
| 103 | + ), |
|
| 104 | + true |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + // If the invoice is paid... |
|
| 108 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 109 | + |
|
| 110 | + // Gateway. |
|
| 111 | + aui()->input( |
|
| 112 | + array( |
|
| 113 | + 'type' => 'text', |
|
| 114 | + 'id' => 'wpinv_gateway', |
|
| 115 | + 'name' => '', |
|
| 116 | + 'label' => __( 'Gateway:', 'invoicing' ), |
|
| 117 | + 'label_type' => 'vertical', |
|
| 118 | + 'class' => 'form-control-sm', |
|
| 119 | + 'value' => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ), |
|
| 120 | + 'extra_attributes' => array( |
|
| 121 | + 'onclick' => 'this.select();', |
|
| 122 | + 'readonly' => 'true', |
|
| 123 | + ), |
|
| 124 | + ), |
|
| 125 | + true |
|
| 126 | + ); |
|
| 127 | + |
|
| 128 | + // Transaction ID. |
|
| 129 | + $transaction_url = $invoice->get_transaction_url(); |
|
| 130 | + aui()->input( |
|
| 131 | + array( |
|
| 132 | + 'type' => 'text', |
|
| 133 | + 'id' => 'wpinv_transaction_id', |
|
| 134 | + 'name' => 'wpinv_transaction_id', |
|
| 135 | + 'label' => __( 'Transaction ID:', 'invoicing' ) . ( $transaction_url ? ' <a href="' . esc_url( $transaction_url ) . '" title="' . __( 'View details', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-fw"></i></a>' : '' ), |
|
| 136 | + 'label_type' => 'vertical', |
|
| 137 | + 'class' => 'form-control-sm', |
|
| 138 | + 'value' => $invoice->get_transaction_id( 'edit' ), |
|
| 139 | + 'help_text' => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), '', $invoice->get_transaction_id(), $invoice ), |
|
| 140 | + 'extra_attributes' => array( |
|
| 141 | + 'onclick' => 'this.select();', |
|
| 142 | + 'readonly' => 'true', |
|
| 143 | + ), |
|
| 144 | + ), |
|
| 145 | + true |
|
| 146 | + ); |
|
| 147 | + |
|
| 148 | + // Currency. |
|
| 149 | + aui()->input( |
|
| 150 | + array( |
|
| 151 | + 'type' => 'text', |
|
| 152 | + 'id' => 'wpinv_currency', |
|
| 153 | + 'name' => 'wpinv_currency', |
|
| 154 | + 'label' => __( 'Currency:', 'invoicing' ), |
|
| 155 | + 'label_type' => 'vertical', |
|
| 156 | + 'class' => 'form-control-sm', |
|
| 157 | + 'value' => $invoice->get_currency( 'edit' ), |
|
| 158 | + 'extra_attributes' => array( |
|
| 159 | + 'onclick' => 'this.select();', |
|
| 160 | + 'readonly' => 'true', |
|
| 161 | + ), |
|
| 162 | + ), |
|
| 163 | + true |
|
| 164 | + ); |
|
| 165 | + |
|
| 166 | + } else { |
|
| 167 | + |
|
| 168 | + if ( 'wpi_invoice' === $invoice->get_post_type() ) { |
|
| 169 | + |
|
| 170 | + // Payment URL. |
|
| 171 | + aui()->input( |
|
| 172 | + array( |
|
| 173 | + 'type' => 'text', |
|
| 174 | + 'id' => 'wpinv_payment_url', |
|
| 175 | + 'name' => 'wpinv_payment_url', |
|
| 176 | + 'label' => __( 'Payment URL:', 'invoicing' ), |
|
| 177 | + 'label_type' => 'vertical', |
|
| 178 | + 'class' => 'form-control-sm', |
|
| 179 | + 'value' => $invoice->get_checkout_payment_url(), |
|
| 180 | + 'extra_attributes' => array( |
|
| 181 | + 'onclick' => 'this.select();', |
|
| 182 | + 'readonly' => 'true', |
|
| 183 | + ), |
|
| 184 | + ), |
|
| 185 | + true |
|
| 186 | + ); |
|
| 187 | + |
|
| 188 | + // Set gateway. |
|
| 189 | + aui()->select( |
|
| 190 | + array( |
|
| 191 | + 'id' => 'wpinv_gateway', |
|
| 192 | + 'name' => 'wpinv_gateway', |
|
| 193 | + 'label' => __( 'Gateway:', 'invoicing' ), |
|
| 194 | + 'label_type' => 'vertical', |
|
| 195 | + 'placeholder' => __( 'Select Gateway', 'invoicing' ), |
|
| 196 | + 'value' => $invoice->get_gateway( 'edit' ), |
|
| 197 | + 'select2' => true, |
|
| 198 | + 'data-allow-clear' => 'false', |
|
| 199 | + 'options' => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ), |
|
| 200 | + ), |
|
| 201 | + true |
|
| 202 | + ); |
|
| 203 | + |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | } |
| 207 | 207 | ?> |
| 208 | 208 | </div> |
@@ -14,91 +14,91 @@ 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 | - */ |
|
| 28 | - public $admin_url; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Reports components. |
|
| 32 | - * |
|
| 33 | - * @var GetPaid_Reports |
|
| 34 | - */ |
|
| 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 | + public $admin_url; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Reports components. |
|
| 32 | + * |
|
| 33 | + * @var GetPaid_Reports |
|
| 34 | + */ |
|
| 35 | 35 | public $reports; |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * Class constructor. |
|
| 39 | - */ |
|
| 40 | - public function __construct() { |
|
| 38 | + * Class constructor. |
|
| 39 | + */ |
|
| 40 | + public function __construct() { |
|
| 41 | 41 | |
| 42 | 42 | $this->admin_path = plugin_dir_path( __FILE__ ); |
| 43 | - $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | - $this->reports = new GetPaid_Reports(); |
|
| 43 | + $this->admin_url = plugins_url( '/', __FILE__ ); |
|
| 44 | + $this->reports = new GetPaid_Reports(); |
|
| 45 | 45 | |
| 46 | 46 | if ( is_admin() ) { |
| 47 | - $this->init_admin_hooks(); |
|
| 47 | + $this->init_admin_hooks(); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * Init action and filter hooks |
|
| 54 | - * |
|
| 55 | - */ |
|
| 56 | - private function init_admin_hooks() { |
|
| 53 | + * Init action and filter hooks |
|
| 54 | + * |
|
| 55 | + */ |
|
| 56 | + private function init_admin_hooks() { |
|
| 57 | 57 | add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ), 9 ); |
| 58 | 58 | add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 59 | 59 | add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) ); |
| 60 | 60 | add_action( 'admin_init', array( $this, 'activation_redirect' ) ); |
| 61 | 61 | add_action( 'admin_init', array( $this, 'maybe_do_admin_action' ) ); |
| 62 | - add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | - add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | - add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
| 65 | - add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
| 66 | - add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 67 | - add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 62 | + add_action( 'admin_notices', array( $this, 'show_notices' ) ); |
|
| 63 | + add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) ); |
|
| 64 | + add_action( 'getpaid_authenticated_admin_action_duplicate_form', array( $this, 'duplicate_payment_form' ) ); |
|
| 65 | + add_action( 'getpaid_authenticated_admin_action_duplicate_invoice', array( $this, 'duplicate_invoice' ) ); |
|
| 66 | + add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) ); |
|
| 67 | + add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) ); |
|
| 68 | 68 | add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) ); |
| 69 | - add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 70 | - add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 71 | - add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 72 | - add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
| 73 | - add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 74 | - add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
| 75 | - add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
| 76 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 77 | - do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 78 | - |
|
| 79 | - // Setup/welcome |
|
| 80 | - if ( ! empty( $_GET['page'] ) ) { |
|
| 81 | - switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
| 82 | - case 'gp-setup': |
|
| 83 | - include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
| 84 | - break; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Register admin scripts |
|
| 92 | - * |
|
| 93 | - */ |
|
| 94 | - public function enqeue_scripts() { |
|
| 69 | + add_action( 'getpaid_authenticated_admin_action_create_missing_pages', array( $this, 'admin_create_missing_pages' ) ); |
|
| 70 | + add_action( 'getpaid_authenticated_admin_action_create_missing_tables', array( $this, 'admin_create_missing_tables' ) ); |
|
| 71 | + add_action( 'getpaid_authenticated_admin_action_migrate_old_invoices', array( $this, 'admin_migrate_old_invoices' ) ); |
|
| 72 | + add_action( 'getpaid_authenticated_admin_action_download_customers', array( $this, 'admin_download_customers' ) ); |
|
| 73 | + add_action( 'getpaid_authenticated_admin_action_recalculate_discounts', array( $this, 'admin_recalculate_discounts' ) ); |
|
| 74 | + add_action( 'getpaid_authenticated_admin_action_install_plugin', array( $this, 'admin_install_plugin' ) ); |
|
| 75 | + add_action( 'getpaid_authenticated_admin_action_connect_gateway', array( $this, 'admin_connect_gateway' ) ); |
|
| 76 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
|
| 77 | + do_action( 'getpaid_init_admin_hooks', $this ); |
|
| 78 | + |
|
| 79 | + // Setup/welcome |
|
| 80 | + if ( ! empty( $_GET['page'] ) ) { |
|
| 81 | + switch ( sanitize_text_field( $_GET['page'] ) ) { |
|
| 82 | + case 'gp-setup': |
|
| 83 | + include_once dirname( __FILE__ ) . '/class-getpaid-admin-setup-wizard.php'; |
|
| 84 | + break; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Register admin scripts |
|
| 92 | + * |
|
| 93 | + */ |
|
| 94 | + public function enqeue_scripts() { |
|
| 95 | 95 | global $current_screen, $pagenow; |
| 96 | 96 | |
| 97 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 98 | - $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 97 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 98 | + $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php'; |
|
| 99 | 99 | |
| 100 | 100 | if ( ! empty( $current_screen->post_type ) ) { |
| 101 | - $page = $current_screen->post_type; |
|
| 101 | + $page = $current_screen->post_type; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // General styles. |
@@ -119,53 +119,53 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // Payment form scripts. |
| 122 | - if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 122 | + if ( 'wpi_payment_form' == $page && $editing ) { |
|
| 123 | 123 | $this->load_payment_form_scripts(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 127 | - wp_enqueue_script( 'postbox' ); |
|
| 128 | - } |
|
| 126 | + if ( $page == 'wpinv-subscriptions' ) { |
|
| 127 | + wp_enqueue_script( 'postbox' ); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | - * Returns admin js translations. |
|
| 134 | - * |
|
| 135 | - */ |
|
| 136 | - protected function get_admin_i18() { |
|
| 133 | + * Returns admin js translations. |
|
| 134 | + * |
|
| 135 | + */ |
|
| 136 | + protected function get_admin_i18() { |
|
| 137 | 137 | global $post; |
| 138 | 138 | |
| 139 | - $date_range = array( |
|
| 140 | - 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
| 141 | - ); |
|
| 139 | + $date_range = array( |
|
| 140 | + 'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days', |
|
| 141 | + ); |
|
| 142 | 142 | |
| 143 | - if ( $date_range['period'] == 'custom' ) { |
|
| 143 | + if ( $date_range['period'] == 'custom' ) { |
|
| 144 | 144 | |
| 145 | - if ( isset( $_GET['from'] ) ) { |
|
| 146 | - $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 147 | - } |
|
| 145 | + if ( isset( $_GET['from'] ) ) { |
|
| 146 | + $date_range['after'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS ); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - if ( isset( $_GET['to'] ) ) { |
|
| 150 | - $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 151 | - } |
|
| 149 | + if ( isset( $_GET['to'] ) ) { |
|
| 150 | + $date_range['before'] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS ); |
|
| 151 | + } |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | $i18n = array( |
| 155 | 155 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 156 | 156 | 'post_ID' => isset( $post->ID ) ? $post->ID : '', |
| 157 | - 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 158 | - 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 159 | - 'rest_root' => esc_url_raw( rest_url() ), |
|
| 160 | - 'date_range' => $date_range, |
|
| 157 | + 'wpinv_nonce' => wp_create_nonce( 'wpinv-nonce' ), |
|
| 158 | + 'rest_nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 159 | + 'rest_root' => esc_url_raw( rest_url() ), |
|
| 160 | + 'date_range' => $date_range, |
|
| 161 | 161 | 'add_invoice_note_nonce' => wp_create_nonce( 'add-invoice-note' ), |
| 162 | 162 | 'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ), |
| 163 | 163 | 'invoice_item_nonce' => wp_create_nonce( 'invoice-item' ), |
| 164 | 164 | 'billing_details_nonce' => wp_create_nonce( 'get-billing-details' ), |
| 165 | 165 | 'tax' => wpinv_tax_amount(), |
| 166 | 166 | 'discount' => 0, |
| 167 | - 'currency_symbol' => wpinv_currency_symbol(), |
|
| 168 | - 'currency' => wpinv_get_currency(), |
|
| 167 | + 'currency_symbol' => wpinv_currency_symbol(), |
|
| 168 | + 'currency' => wpinv_get_currency(), |
|
| 169 | 169 | 'currency_pos' => wpinv_currency_position(), |
| 170 | 170 | 'thousand_sep' => wpinv_thousands_separator(), |
| 171 | 171 | 'decimal_sep' => wpinv_decimal_separator(), |
@@ -185,118 +185,118 @@ discard block |
||
| 185 | 185 | 'item_description' => __( 'Item Description', 'invoicing' ), |
| 186 | 186 | 'invoice_description' => __( 'Invoice Description', 'invoicing' ), |
| 187 | 187 | 'discount_description' => __( 'Discount Description', 'invoicing' ), |
| 188 | - 'searching' => __( 'Searching', 'invoicing' ), |
|
| 189 | - 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 190 | - 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 191 | - 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
| 192 | - 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
| 188 | + 'searching' => __( 'Searching', 'invoicing' ), |
|
| 189 | + 'loading' => __( 'Loading...', 'invoicing' ), |
|
| 190 | + 'search_customers' => __( 'Enter customer name or email', 'invoicing' ), |
|
| 191 | + 'search_items' => __( 'Enter item name', 'invoicing' ), |
|
| 192 | + 'graphs' => array_merge( array( 'refunded_fees', 'refunded_items', 'refunded_subtotal', 'refunded_tax' ), array_keys( wpinv_get_report_graphs() ) ), |
|
| 193 | 193 | ); |
| 194 | 194 | |
| 195 | - if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 195 | + if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) { |
|
| 196 | 196 | |
| 197 | - $invoice = new WPInv_Invoice( $post ); |
|
| 198 | - $i18n['save_invoice'] = sprintf( |
|
| 199 | - __( 'Save %s', 'invoicing' ), |
|
| 200 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 201 | - ); |
|
| 197 | + $invoice = new WPInv_Invoice( $post ); |
|
| 198 | + $i18n['save_invoice'] = sprintf( |
|
| 199 | + __( 'Save %s', 'invoicing' ), |
|
| 200 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 201 | + ); |
|
| 202 | 202 | |
| 203 | - $i18n['invoice_description'] = sprintf( |
|
| 204 | - __( '%s Description', 'invoicing' ), |
|
| 205 | - ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 206 | - ); |
|
| 203 | + $i18n['invoice_description'] = sprintf( |
|
| 204 | + __( '%s Description', 'invoicing' ), |
|
| 205 | + ucfirst( $invoice->get_invoice_quote_type() ) |
|
| 206 | + ); |
|
| 207 | 207 | |
| 208 | - } |
|
| 209 | - return $i18n; |
|
| 210 | - } |
|
| 208 | + } |
|
| 209 | + return $i18n; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Change the admin footer text on GetPaid admin pages. |
|
| 214 | - * |
|
| 215 | - * @since 2.0.0 |
|
| 216 | - * @param string $footer_text |
|
| 217 | - * @return string |
|
| 218 | - */ |
|
| 219 | - public function admin_footer_text( $footer_text ) { |
|
| 220 | - global $current_screen; |
|
| 212 | + /** |
|
| 213 | + * Change the admin footer text on GetPaid admin pages. |
|
| 214 | + * |
|
| 215 | + * @since 2.0.0 |
|
| 216 | + * @param string $footer_text |
|
| 217 | + * @return string |
|
| 218 | + */ |
|
| 219 | + public function admin_footer_text( $footer_text ) { |
|
| 220 | + global $current_screen; |
|
| 221 | 221 | |
| 222 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 222 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
|
| 223 | 223 | |
| 224 | 224 | if ( ! empty( $current_screen->post_type ) ) { |
| 225 | - $page = $current_screen->post_type; |
|
| 225 | + $page = $current_screen->post_type; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // General styles. |
| 229 | 229 | if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) { |
| 230 | 230 | |
| 231 | - // Change the footer text |
|
| 232 | - if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 231 | + // Change the footer text |
|
| 232 | + if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) { |
|
| 233 | 233 | |
| 234 | - $rating_url = esc_url( |
|
| 235 | - wp_nonce_url( |
|
| 236 | - admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 237 | - 'getpaid-nonce', |
|
| 238 | - 'getpaid-nonce' |
|
| 234 | + $rating_url = esc_url( |
|
| 235 | + wp_nonce_url( |
|
| 236 | + admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ), |
|
| 237 | + 'getpaid-nonce', |
|
| 238 | + 'getpaid-nonce' |
|
| 239 | 239 | ) |
| 240 | - ); |
|
| 240 | + ); |
|
| 241 | 241 | |
| 242 | - $footer_text = sprintf( |
|
| 243 | - /* translators: %s: five stars */ |
|
| 244 | - __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 245 | - "<a href='$rating_url'>★★★★★</a>" |
|
| 246 | - ); |
|
| 242 | + $footer_text = sprintf( |
|
| 243 | + /* translators: %s: five stars */ |
|
| 244 | + __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ), |
|
| 245 | + "<a href='$rating_url'>★★★★★</a>" |
|
| 246 | + ); |
|
| 247 | 247 | |
| 248 | - } else { |
|
| 248 | + } else { |
|
| 249 | 249 | |
| 250 | - $footer_text = sprintf( |
|
| 251 | - /* translators: %s: GetPaid */ |
|
| 252 | - __( 'Thank you for using %s!', 'invoicing' ), |
|
| 253 | - "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 254 | - ); |
|
| 250 | + $footer_text = sprintf( |
|
| 251 | + /* translators: %s: GetPaid */ |
|
| 252 | + __( 'Thank you for using %s!', 'invoicing' ), |
|
| 253 | + "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>" |
|
| 254 | + ); |
|
| 255 | 255 | |
| 256 | - } |
|
| 256 | + } |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - return $footer_text; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Redirects to wp.org to rate the plugin. |
|
| 264 | - * |
|
| 265 | - * @since 2.0.0 |
|
| 266 | - */ |
|
| 267 | - public function redirect_to_wordpress_rating_page() { |
|
| 268 | - update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 269 | - wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 270 | - exit; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Loads payment form js. |
|
| 275 | - * |
|
| 276 | - */ |
|
| 277 | - protected function load_payment_form_scripts() { |
|
| 259 | + return $footer_text; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Redirects to wp.org to rate the plugin. |
|
| 264 | + * |
|
| 265 | + * @since 2.0.0 |
|
| 266 | + */ |
|
| 267 | + public function redirect_to_wordpress_rating_page() { |
|
| 268 | + update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 ); |
|
| 269 | + wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' ); |
|
| 270 | + exit; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Loads payment form js. |
|
| 275 | + * |
|
| 276 | + */ |
|
| 277 | + protected function load_payment_form_scripts() { |
|
| 278 | 278 | global $post; |
| 279 | 279 | |
| 280 | 280 | wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.min.js', array(), WPINV_VERSION ); |
| 281 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 282 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 281 | + wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
| 282 | + wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
| 283 | 283 | |
| 284 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 285 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
| 284 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
| 285 | + wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable', 'wp-hooks' ), $version ); |
|
| 286 | 286 | |
| 287 | - wp_localize_script( |
|
| 287 | + wp_localize_script( |
|
| 288 | 288 | 'wpinv-admin-payment-form-script', |
| 289 | 289 | 'wpinvPaymentFormAdmin', |
| 290 | 290 | array( |
| 291 | - 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 292 | - 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 293 | - 'currency' => wpinv_currency_symbol(), |
|
| 294 | - 'position' => wpinv_currency_position(), |
|
| 295 | - 'decimals' => (int) wpinv_decimals(), |
|
| 296 | - 'thousands_sep' => wpinv_thousands_separator(), |
|
| 297 | - 'decimals_sep' => wpinv_decimal_separator(), |
|
| 298 | - 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 299 | - 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 291 | + 'elements' => wpinv_get_data( 'payment-form-elements' ), |
|
| 292 | + 'form_elements' => getpaid_get_payment_form_elements( $post->ID ), |
|
| 293 | + 'currency' => wpinv_currency_symbol(), |
|
| 294 | + 'position' => wpinv_currency_position(), |
|
| 295 | + 'decimals' => (int) wpinv_decimals(), |
|
| 296 | + 'thousands_sep' => wpinv_thousands_separator(), |
|
| 297 | + 'decimals_sep' => wpinv_decimal_separator(), |
|
| 298 | + 'form_items' => gepaid_get_form_items( $post->ID ), |
|
| 299 | + 'is_default' => $post->ID == wpinv_get_default_payment_form(), |
|
| 300 | 300 | ) |
| 301 | 301 | ); |
| 302 | 302 | |
@@ -305,19 +305,19 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | - * Add our classes to admin pages. |
|
| 308 | + * Add our classes to admin pages. |
|
| 309 | 309 | * |
| 310 | 310 | * @param string $classes |
| 311 | 311 | * @return string |
| 312 | - * |
|
| 313 | - */ |
|
| 312 | + * |
|
| 313 | + */ |
|
| 314 | 314 | public function admin_body_class( $classes ) { |
| 315 | - global $pagenow, $post, $current_screen; |
|
| 315 | + global $pagenow, $post, $current_screen; |
|
| 316 | 316 | |
| 317 | 317 | $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : ''; |
| 318 | 318 | |
| 319 | 319 | if ( ! empty( $current_screen->post_type ) ) { |
| 320 | - $page = $current_screen->post_type; |
|
| 320 | + $page = $current_screen->post_type; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | if ( false !== stripos( $page, 'wpi' ) ) { |
@@ -326,70 +326,70 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) { |
| 328 | 328 | $classes .= ' wpinv-cpt wpinv'; |
| 329 | - } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 331 | + if ( getpaid_is_invoice_post_type( $page ) ) { |
|
| 332 | 332 | $classes .= ' getpaid-is-invoice-cpt'; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - return $classes; |
|
| 335 | + return $classes; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
| 339 | - * Maybe show the AyeCode Connect Notice. |
|
| 340 | - */ |
|
| 341 | - public function init_ayecode_connect_helper() { |
|
| 339 | + * Maybe show the AyeCode Connect Notice. |
|
| 340 | + */ |
|
| 341 | + public function init_ayecode_connect_helper() { |
|
| 342 | 342 | |
| 343 | - // Register with the deactivation survey class. |
|
| 344 | - AyeCode_Deactivation_Survey::instance( |
|
| 343 | + // Register with the deactivation survey class. |
|
| 344 | + AyeCode_Deactivation_Survey::instance( |
|
| 345 | 345 | array( |
| 346 | - 'slug' => 'invoicing', |
|
| 347 | - 'version' => WPINV_VERSION, |
|
| 348 | - 'support_url' => 'https://wpgetpaid.com/support/', |
|
| 349 | - 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
| 350 | - 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
| 346 | + 'slug' => 'invoicing', |
|
| 347 | + 'version' => WPINV_VERSION, |
|
| 348 | + 'support_url' => 'https://wpgetpaid.com/support/', |
|
| 349 | + 'documentation_url' => 'https://docs.wpgetpaid.com/', |
|
| 350 | + 'activated' => (int) get_option( 'gepaid_installed_on' ), |
|
| 351 | 351 | ) |
| 352 | 352 | ); |
| 353 | 353 | |
| 354 | 354 | new AyeCode_Connect_Helper( |
| 355 | 355 | array( |
| 356 | - 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
| 357 | - 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
| 358 | - 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
| 359 | - 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
| 360 | - 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
| 361 | - 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
| 362 | - 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
| 356 | + 'connect_title' => __( 'WP Invoicing - an AyeCode product!', 'invoicing' ), |
|
| 357 | + 'connect_external' => __( 'Please confirm you wish to connect your site?', 'invoicing' ), |
|
| 358 | + 'connect' => sprintf( __( '<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %1$slearn more%2$s', 'invoicing' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", '</a>' ), |
|
| 359 | + 'connect_button' => __( 'Connect Site', 'invoicing' ), |
|
| 360 | + 'connecting_button' => __( 'Connecting...', 'invoicing' ), |
|
| 361 | + 'error_localhost' => __( 'This service will only work with a live domain, not a localhost.', 'invoicing' ), |
|
| 362 | + 'error' => __( 'Something went wrong, please refresh and try again.', 'invoicing' ), |
|
| 363 | 363 | ), |
| 364 | 364 | array( 'wpi-addons' ) |
| 365 | 365 | ); |
| 366 | 366 | |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - /** |
|
| 370 | - * Redirect users to settings on activation. |
|
| 371 | - * |
|
| 372 | - * @return void |
|
| 373 | - */ |
|
| 374 | - public function activation_redirect() { |
|
| 369 | + /** |
|
| 370 | + * Redirect users to settings on activation. |
|
| 371 | + * |
|
| 372 | + * @return void |
|
| 373 | + */ |
|
| 374 | + public function activation_redirect() { |
|
| 375 | 375 | |
| 376 | - $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 376 | + $redirected = get_option( 'wpinv_redirected_to_settings' ); |
|
| 377 | 377 | |
| 378 | - if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 379 | - return; |
|
| 380 | - } |
|
| 378 | + if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) { |
|
| 379 | + return; |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | - // Bail if activating from network, or bulk |
|
| 383 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 384 | - return; |
|
| 385 | - } |
|
| 382 | + // Bail if activating from network, or bulk |
|
| 383 | + if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 384 | + return; |
|
| 385 | + } |
|
| 386 | 386 | |
| 387 | - update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 387 | + update_option( 'wpinv_redirected_to_settings', 1 ); |
|
| 388 | 388 | |
| 389 | 389 | wp_safe_redirect( admin_url( 'index.php?page=gp-setup' ) ); |
| 390 | 390 | exit; |
| 391 | 391 | |
| 392 | - } |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | 394 | /** |
| 395 | 395 | * Fires an admin action after verifying that a user can fire them. |
@@ -403,525 +403,525 @@ discard block |
||
| 403 | 403 | |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - /** |
|
| 406 | + /** |
|
| 407 | 407 | * Duplicate invoice. |
| 408 | - * |
|
| 409 | - * @param array $args |
|
| 408 | + * |
|
| 409 | + * @param array $args |
|
| 410 | 410 | */ |
| 411 | 411 | public function duplicate_invoice( $args ) { |
| 412 | 412 | |
| 413 | - if ( empty( $args['invoice_id'] ) ) { |
|
| 414 | - return; |
|
| 415 | - } |
|
| 413 | + if ( empty( $args['invoice_id'] ) ) { |
|
| 414 | + return; |
|
| 415 | + } |
|
| 416 | 416 | |
| 417 | - $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
| 417 | + $invoice = new WPInv_Invoice( (int) $args['invoice_id'] ); |
|
| 418 | 418 | |
| 419 | - if ( ! $invoice->exists() ) { |
|
| 420 | - return; |
|
| 421 | - } |
|
| 419 | + if ( ! $invoice->exists() ) { |
|
| 420 | + return; |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | - $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
| 424 | - $new_invoice->save(); |
|
| 423 | + $new_invoice = getpaid_duplicate_invoice( $invoice ); |
|
| 424 | + $new_invoice->save(); |
|
| 425 | 425 | |
| 426 | - if ( $new_invoice->exists() ) { |
|
| 426 | + if ( $new_invoice->exists() ) { |
|
| 427 | 427 | |
| 428 | - getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
| 428 | + getpaid_admin()->show_success( __( 'Invoice duplicated successfully.', 'newsletter-optin-box' ) ); |
|
| 429 | 429 | |
| 430 | - wp_safe_redirect( |
|
| 431 | - add_query_arg( |
|
| 432 | - array( |
|
| 433 | - 'action' => 'edit', |
|
| 434 | - 'post' => $new_invoice->get_id(), |
|
| 435 | - ), |
|
| 436 | - admin_url( 'post.php' ) |
|
| 437 | - ) |
|
| 438 | - ); |
|
| 439 | - exit; |
|
| 430 | + wp_safe_redirect( |
|
| 431 | + add_query_arg( |
|
| 432 | + array( |
|
| 433 | + 'action' => 'edit', |
|
| 434 | + 'post' => $new_invoice->get_id(), |
|
| 435 | + ), |
|
| 436 | + admin_url( 'post.php' ) |
|
| 437 | + ) |
|
| 438 | + ); |
|
| 439 | + exit; |
|
| 440 | 440 | |
| 441 | - } |
|
| 441 | + } |
|
| 442 | 442 | |
| 443 | - getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
| 443 | + getpaid_admin()->show_error( __( 'There was an error duplicating this invoice. Please try again.', 'newsletter-optin-box' ) ); |
|
| 444 | 444 | |
| 445 | - } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - /** |
|
| 447 | + /** |
|
| 448 | 448 | * Sends a payment reminder to a customer. |
| 449 | - * |
|
| 450 | - * @param array $args |
|
| 449 | + * |
|
| 450 | + * @param array $args |
|
| 451 | 451 | */ |
| 452 | 452 | public function duplicate_payment_form( $args ) { |
| 453 | 453 | |
| 454 | - if ( empty( $args['form_id'] ) ) { |
|
| 455 | - return; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 454 | + if ( empty( $args['form_id'] ) ) { |
|
| 455 | + return; |
|
| 456 | + } |
|
| 459 | 457 | |
| 460 | - if ( ! $form->exists() ) { |
|
| 461 | - return; |
|
| 462 | - } |
|
| 458 | + $form = new GetPaid_Payment_Form( (int) $args['form_id'] ); |
|
| 463 | 459 | |
| 464 | - $new_form = new GetPaid_Payment_Form(); |
|
| 465 | - $new_form->set_author( $form->get_author( 'edit' ) ); |
|
| 466 | - $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
| 467 | - $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
| 468 | - $new_form->set_items( $form->get_items( 'edit' ) ); |
|
| 469 | - $new_form->save(); |
|
| 460 | + if ( ! $form->exists() ) { |
|
| 461 | + return; |
|
| 462 | + } |
|
| 470 | 463 | |
| 471 | - if ( $new_form->exists() ) { |
|
| 472 | - $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
| 473 | - $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
| 474 | - } else { |
|
| 475 | - $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
| 476 | - $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
| 477 | - } |
|
| 464 | + $new_form = new GetPaid_Payment_Form(); |
|
| 465 | + $new_form->set_author( $form->get_author( 'edit' ) ); |
|
| 466 | + $new_form->set_name( $form->get_name( 'edit' ) . __( '(copy)', 'invoicing' ) ); |
|
| 467 | + $new_form->set_elements( $form->get_elements( 'edit' ) ); |
|
| 468 | + $new_form->set_items( $form->get_items( 'edit' ) ); |
|
| 469 | + $new_form->save(); |
|
| 470 | + |
|
| 471 | + if ( $new_form->exists() ) { |
|
| 472 | + $this->show_success( __( 'Form duplicated successfully', 'invoicing' ) ); |
|
| 473 | + $url = get_edit_post_link( $new_form->get_id(), 'edit' ); |
|
| 474 | + } else { |
|
| 475 | + $this->show_error( __( 'Unable to duplicate form', 'invoicing' ) ); |
|
| 476 | + $url = remove_query_arg( array( 'getpaid-admin-action', 'form_id', 'getpaid-nonce' ) ); |
|
| 477 | + } |
|
| 478 | 478 | |
| 479 | - wp_redirect( $url ); |
|
| 480 | - exit; |
|
| 481 | - } |
|
| 479 | + wp_redirect( $url ); |
|
| 480 | + exit; |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - /** |
|
| 483 | + /** |
|
| 484 | 484 | * Sends a payment reminder to a customer. |
| 485 | - * |
|
| 486 | - * @param array $args |
|
| 485 | + * |
|
| 486 | + * @param array $args |
|
| 487 | 487 | */ |
| 488 | 488 | public function send_customer_invoice( $args ) { |
| 489 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
| 490 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 491 | - exit; |
|
| 492 | - } |
|
| 489 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ), true ); |
|
| 490 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 491 | + exit; |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | - /** |
|
| 494 | + /** |
|
| 495 | 495 | * Sends a payment reminder to a customer. |
| 496 | - * |
|
| 497 | - * @param array $args |
|
| 496 | + * |
|
| 497 | + * @param array $args |
|
| 498 | 498 | */ |
| 499 | 499 | public function send_customer_payment_reminder( $args ) { |
| 500 | - $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 500 | + $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) ); |
|
| 501 | 501 | |
| 502 | - if ( $sent ) { |
|
| 503 | - $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 504 | - } else { |
|
| 505 | - $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 506 | - } |
|
| 502 | + if ( $sent ) { |
|
| 503 | + $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) ); |
|
| 504 | + } else { |
|
| 505 | + $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) ); |
|
| 506 | + } |
|
| 507 | 507 | |
| 508 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 509 | - exit; |
|
| 510 | - } |
|
| 508 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) ); |
|
| 509 | + exit; |
|
| 510 | + } |
|
| 511 | 511 | |
| 512 | - /** |
|
| 512 | + /** |
|
| 513 | 513 | * Resets tax rates. |
| 514 | - * |
|
| 514 | + * |
|
| 515 | 515 | */ |
| 516 | 516 | public function admin_reset_tax_rates() { |
| 517 | 517 | |
| 518 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 519 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 520 | - exit; |
|
| 518 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
| 519 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 520 | + exit; |
|
| 521 | 521 | |
| 522 | - } |
|
| 522 | + } |
|
| 523 | 523 | |
| 524 | - /** |
|
| 524 | + /** |
|
| 525 | 525 | * Resets admin pages. |
| 526 | - * |
|
| 526 | + * |
|
| 527 | 527 | */ |
| 528 | 528 | public function admin_create_missing_pages() { |
| 529 | - $installer = new GetPaid_Installer(); |
|
| 530 | - $installer->create_pages(); |
|
| 531 | - $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 532 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 533 | - exit; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 529 | + $installer = new GetPaid_Installer(); |
|
| 530 | + $installer->create_pages(); |
|
| 531 | + $this->show_success( __( 'GetPaid pages updated.', 'invoicing' ) ); |
|
| 532 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 533 | + exit; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | 537 | * Creates an missing admin tables. |
| 538 | - * |
|
| 538 | + * |
|
| 539 | 539 | */ |
| 540 | 540 | public function admin_create_missing_tables() { |
| 541 | - global $wpdb; |
|
| 542 | - $installer = new GetPaid_Installer(); |
|
| 541 | + global $wpdb; |
|
| 542 | + $installer = new GetPaid_Installer(); |
|
| 543 | 543 | |
| 544 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 545 | - $installer->create_subscriptions_table(); |
|
| 544 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpinv_subscriptions'" ) != $wpdb->prefix . 'wpinv_subscriptions' ) { |
|
| 545 | + $installer->create_subscriptions_table(); |
|
| 546 | 546 | |
| 547 | - if ( $wpdb->last_error !== '' ) { |
|
| 548 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 549 | - } |
|
| 550 | - } |
|
| 547 | + if ( $wpdb->last_error !== '' ) { |
|
| 548 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | 551 | |
| 552 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 553 | - $installer->create_invoices_table(); |
|
| 552 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) != $wpdb->prefix . 'getpaid_invoices' ) { |
|
| 553 | + $installer->create_invoices_table(); |
|
| 554 | 554 | |
| 555 | - if ( '' !== $wpdb->last_error ) { |
|
| 556 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 557 | - } |
|
| 558 | - } |
|
| 555 | + if ( '' !== $wpdb->last_error ) { |
|
| 556 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | 559 | |
| 560 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 561 | - $installer->create_invoice_items_table(); |
|
| 560 | + if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoice_items'" ) != $wpdb->prefix . 'getpaid_invoice_items' ) { |
|
| 561 | + $installer->create_invoice_items_table(); |
|
| 562 | 562 | |
| 563 | - if ( '' !== $wpdb->last_error ) { |
|
| 564 | - $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 565 | - } |
|
| 566 | - } |
|
| 563 | + if ( '' !== $wpdb->last_error ) { |
|
| 564 | + $this->show_error( __( 'Your GetPaid tables have been updated:', 'invoicing' ) . ' ' . $wpdb->last_error ); |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | 567 | |
| 568 | - if ( ! $this->has_notices() ) { |
|
| 569 | - $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 570 | - } |
|
| 568 | + if ( ! $this->has_notices() ) { |
|
| 569 | + $this->show_success( __( 'Your GetPaid tables have been updated.', 'invoicing' ) ); |
|
| 570 | + } |
|
| 571 | 571 | |
| 572 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 573 | - exit; |
|
| 574 | - } |
|
| 572 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 573 | + exit; |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | - /** |
|
| 576 | + /** |
|
| 577 | 577 | * Migrates old invoices to the new database tables. |
| 578 | - * |
|
| 578 | + * |
|
| 579 | 579 | */ |
| 580 | 580 | public function admin_migrate_old_invoices() { |
| 581 | 581 | |
| 582 | - // Migrate the invoices. |
|
| 583 | - $installer = new GetPaid_Installer(); |
|
| 584 | - $installer->migrate_old_invoices(); |
|
| 582 | + // Migrate the invoices. |
|
| 583 | + $installer = new GetPaid_Installer(); |
|
| 584 | + $installer->migrate_old_invoices(); |
|
| 585 | 585 | |
| 586 | - // Show an admin message. |
|
| 587 | - $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 586 | + // Show an admin message. |
|
| 587 | + $this->show_success( __( 'Your invoices have been migrated.', 'invoicing' ) ); |
|
| 588 | 588 | |
| 589 | - // Redirect the admin. |
|
| 590 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 591 | - exit; |
|
| 589 | + // Redirect the admin. |
|
| 590 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 591 | + exit; |
|
| 592 | 592 | |
| 593 | - } |
|
| 593 | + } |
|
| 594 | 594 | |
| 595 | - /** |
|
| 595 | + /** |
|
| 596 | 596 | * Download customers. |
| 597 | - * |
|
| 597 | + * |
|
| 598 | 598 | */ |
| 599 | 599 | public function admin_download_customers() { |
| 600 | - global $wpdb; |
|
| 601 | - |
|
| 602 | - $output = fopen( 'php://output', 'w' ); |
|
| 603 | - |
|
| 604 | - if ( false === $output ) { |
|
| 605 | - wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 606 | - } |
|
| 600 | + global $wpdb; |
|
| 607 | 601 | |
| 608 | - header( 'Content-Type:text/csv' ); |
|
| 609 | - header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
| 602 | + $output = fopen( 'php://output', 'w' ); |
|
| 610 | 603 | |
| 611 | - $post_types = ''; |
|
| 604 | + if ( false === $output ) { |
|
| 605 | + wp_die( esc_html__( 'Unsupported server', 'invoicing' ), 500 ); |
|
| 606 | + } |
|
| 612 | 607 | |
| 613 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 614 | - $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
| 615 | - } |
|
| 608 | + header( 'Content-Type:text/csv' ); |
|
| 609 | + header( 'Content-Disposition:attachment;filename=customers.csv' ); |
|
| 616 | 610 | |
| 617 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 611 | + $post_types = ''; |
|
| 618 | 612 | |
| 619 | - $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 613 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 614 | + $post_types .= $wpdb->prepare( 'post_type=%s OR ', $post_type ); |
|
| 615 | + } |
|
| 620 | 616 | |
| 621 | - $columns = array( |
|
| 622 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 623 | - 'email' => __( 'Email', 'invoicing' ), |
|
| 624 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 625 | - 'state' => __( 'State', 'invoicing' ), |
|
| 626 | - 'city' => __( 'City', 'invoicing' ), |
|
| 627 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 628 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 629 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 630 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 631 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
| 632 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 633 | - 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
| 634 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 635 | - ); |
|
| 617 | + $post_types = rtrim( $post_types, ' OR' ); |
|
| 618 | + |
|
| 619 | + $customers = $wpdb->get_col( "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 620 | + |
|
| 621 | + $columns = array( |
|
| 622 | + 'name' => __( 'Name', 'invoicing' ), |
|
| 623 | + 'email' => __( 'Email', 'invoicing' ), |
|
| 624 | + 'country' => __( 'Country', 'invoicing' ), |
|
| 625 | + 'state' => __( 'State', 'invoicing' ), |
|
| 626 | + 'city' => __( 'City', 'invoicing' ), |
|
| 627 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 628 | + 'address' => __( 'Address', 'invoicing' ), |
|
| 629 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
| 630 | + 'company' => __( 'Company', 'invoicing' ), |
|
| 631 | + 'company_id' => __( 'Company ID', 'invoicing' ), |
|
| 632 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 633 | + 'total_raw' => __( 'Total Spend', 'invoicing' ), |
|
| 634 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
| 635 | + ); |
|
| 636 | 636 | |
| 637 | - // Output the csv column headers. |
|
| 638 | - fputcsv( $output, array_values( $columns ) ); |
|
| 637 | + // Output the csv column headers. |
|
| 638 | + fputcsv( $output, array_values( $columns ) ); |
|
| 639 | 639 | |
| 640 | - // Loop through |
|
| 641 | - $table = new WPInv_Customers_Table(); |
|
| 642 | - foreach ( $customers as $customer_id ) { |
|
| 640 | + // Loop through |
|
| 641 | + $table = new WPInv_Customers_Table(); |
|
| 642 | + foreach ( $customers as $customer_id ) { |
|
| 643 | 643 | |
| 644 | - $user = get_user_by( 'id', $customer_id ); |
|
| 645 | - $row = array(); |
|
| 646 | - if ( empty( $user ) ) { |
|
| 647 | - continue; |
|
| 648 | - } |
|
| 644 | + $user = get_user_by( 'id', $customer_id ); |
|
| 645 | + $row = array(); |
|
| 646 | + if ( empty( $user ) ) { |
|
| 647 | + continue; |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - foreach ( array_keys( $columns ) as $column ) { |
|
| 650 | + foreach ( array_keys( $columns ) as $column ) { |
|
| 651 | 651 | |
| 652 | - $method = 'column_' . $column; |
|
| 652 | + $method = 'column_' . $column; |
|
| 653 | 653 | |
| 654 | - if ( 'name' == $column ) { |
|
| 655 | - $value = esc_html( $user->display_name ); |
|
| 656 | - } elseif ( 'email' == $column ) { |
|
| 657 | - $value = sanitize_email( $user->user_email ); |
|
| 658 | - } elseif ( is_callable( array( $table, $method ) ) ) { |
|
| 659 | - $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
| 660 | - } |
|
| 654 | + if ( 'name' == $column ) { |
|
| 655 | + $value = esc_html( $user->display_name ); |
|
| 656 | + } elseif ( 'email' == $column ) { |
|
| 657 | + $value = sanitize_email( $user->user_email ); |
|
| 658 | + } elseif ( is_callable( array( $table, $method ) ) ) { |
|
| 659 | + $value = wp_strip_all_tags( $table->$method( $user ) ); |
|
| 660 | + } |
|
| 661 | 661 | |
| 662 | - if ( empty( $value ) ) { |
|
| 663 | - $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
| 664 | - } |
|
| 662 | + if ( empty( $value ) ) { |
|
| 663 | + $value = esc_html( get_user_meta( $user->ID, '_wpinv_' . $column, true ) ); |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | - $row[] = $value; |
|
| 666 | + $row[] = $value; |
|
| 667 | 667 | |
| 668 | - } |
|
| 668 | + } |
|
| 669 | 669 | |
| 670 | - fputcsv( $output, $row ); |
|
| 671 | - } |
|
| 670 | + fputcsv( $output, $row ); |
|
| 671 | + } |
|
| 672 | 672 | |
| 673 | - fclose( $output ); |
|
| 674 | - exit; |
|
| 673 | + fclose( $output ); |
|
| 674 | + exit; |
|
| 675 | 675 | |
| 676 | - } |
|
| 676 | + } |
|
| 677 | 677 | |
| 678 | - /** |
|
| 678 | + /** |
|
| 679 | 679 | * Installs a plugin. |
| 680 | - * |
|
| 681 | - * @param array $data |
|
| 680 | + * |
|
| 681 | + * @param array $data |
|
| 682 | 682 | */ |
| 683 | 683 | public function admin_install_plugin( $data ) { |
| 684 | 684 | |
| 685 | - if ( ! empty( $data['plugins'] ) ) { |
|
| 686 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 687 | - wp_cache_flush(); |
|
| 685 | + if ( ! empty( $data['plugins'] ) ) { |
|
| 686 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 687 | + wp_cache_flush(); |
|
| 688 | 688 | |
| 689 | - foreach ( $data['plugins'] as $slug => $file ) { |
|
| 690 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
| 691 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 692 | - $installed = $upgrader->install( $plugin_zip ); |
|
| 689 | + foreach ( $data['plugins'] as $slug => $file ) { |
|
| 690 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/' . $slug . '.latest-stable.zip' ); |
|
| 691 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 692 | + $installed = $upgrader->install( $plugin_zip ); |
|
| 693 | 693 | |
| 694 | - if ( ! is_wp_error( $installed ) && $installed ) { |
|
| 695 | - activate_plugin( $file, '', false, true ); |
|
| 696 | - } else { |
|
| 697 | - wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
| 698 | - } |
|
| 694 | + if ( ! is_wp_error( $installed ) && $installed ) { |
|
| 695 | + activate_plugin( $file, '', false, true ); |
|
| 696 | + } else { |
|
| 697 | + wpinv_error_log( $upgrader->skin->get_upgrade_messages(), false ); |
|
| 698 | + } |
|
| 699 | 699 | } |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
| 703 | - wp_safe_redirect( $redirect ); |
|
| 704 | - exit; |
|
| 702 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( $data['redirect'] ) : admin_url( 'plugins.php' ); |
|
| 703 | + wp_safe_redirect( $redirect ); |
|
| 704 | + exit; |
|
| 705 | 705 | |
| 706 | - } |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | - /** |
|
| 708 | + /** |
|
| 709 | 709 | * Connects a gateway. |
| 710 | - * |
|
| 711 | - * @param array $data |
|
| 710 | + * |
|
| 711 | + * @param array $data |
|
| 712 | 712 | */ |
| 713 | 713 | public function admin_connect_gateway( $data ) { |
| 714 | 714 | |
| 715 | - if ( ! empty( $data['plugin'] ) ) { |
|
| 715 | + if ( ! empty( $data['plugin'] ) ) { |
|
| 716 | 716 | |
| 717 | - $gateway = sanitize_key( $data['plugin'] ); |
|
| 718 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 717 | + $gateway = sanitize_key( $data['plugin'] ); |
|
| 718 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 719 | 719 | |
| 720 | - if ( ! empty( $connect_url ) ) { |
|
| 721 | - wp_redirect( $connect_url ); |
|
| 722 | - exit; |
|
| 723 | - } |
|
| 720 | + if ( ! empty( $connect_url ) ) { |
|
| 721 | + wp_redirect( $connect_url ); |
|
| 722 | + exit; |
|
| 723 | + } |
|
| 724 | 724 | |
| 725 | - if ( 'stripe' == $data['plugin'] ) { |
|
| 726 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 727 | - include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 728 | - wp_cache_flush(); |
|
| 725 | + if ( 'stripe' == $data['plugin'] ) { |
|
| 726 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 727 | + include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
| 728 | + wp_cache_flush(); |
|
| 729 | 729 | |
| 730 | - if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
| 731 | - $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
| 732 | - $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 733 | - $upgrader->install( $plugin_zip ); |
|
| 734 | - } |
|
| 730 | + if ( ! array_key_exists( 'getpaid-stripe-payments/getpaid-stripe-payments.php', get_plugins() ) ) { |
|
| 731 | + $plugin_zip = esc_url( 'https://downloads.wordpress.org/plugin/getpaid-stripe-payments.latest-stable.zip' ); |
|
| 732 | + $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); |
|
| 733 | + $upgrader->install( $plugin_zip ); |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | - activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
| 737 | - } |
|
| 736 | + activate_plugin( 'getpaid-stripe-payments/getpaid-stripe-payments.php', '', false, true ); |
|
| 737 | + } |
|
| 738 | 738 | |
| 739 | - $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 740 | - if ( ! empty( $connect_url ) ) { |
|
| 741 | - wp_redirect( $connect_url ); |
|
| 742 | - exit; |
|
| 743 | - } |
|
| 739 | + $connect_url = apply_filters( "getpaid_get_{$gateway}_connect_url", false, $data ); |
|
| 740 | + if ( ! empty( $connect_url ) ) { |
|
| 741 | + wp_redirect( $connect_url ); |
|
| 742 | + exit; |
|
| 743 | + } |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | - $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
| 747 | - wp_safe_redirect( $redirect ); |
|
| 748 | - exit; |
|
| 746 | + $redirect = isset( $data['redirect'] ) ? esc_url_raw( urldecode( $data['redirect'] ) ) : admin_url( 'admin.php?page=wpinv-settings&tab=gateways' ); |
|
| 747 | + wp_safe_redirect( $redirect ); |
|
| 748 | + exit; |
|
| 749 | 749 | |
| 750 | - } |
|
| 750 | + } |
|
| 751 | 751 | |
| 752 | - /** |
|
| 752 | + /** |
|
| 753 | 753 | * Recalculates discounts. |
| 754 | - * |
|
| 754 | + * |
|
| 755 | 755 | */ |
| 756 | 756 | public function admin_recalculate_discounts() { |
| 757 | - global $wpdb; |
|
| 757 | + global $wpdb; |
|
| 758 | 758 | |
| 759 | - // Fetch all invoices that have discount codes. |
|
| 760 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 761 | - $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 759 | + // Fetch all invoices that have discount codes. |
|
| 760 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 761 | + $invoices = $wpdb->get_col( "SELECT `post_id` FROM `$table` WHERE `discount` = 0 && `discount_code` <> ''" ); |
|
| 762 | 762 | |
| 763 | - foreach ( $invoices as $invoice ) { |
|
| 763 | + foreach ( $invoices as $invoice ) { |
|
| 764 | 764 | |
| 765 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 765 | + $invoice = new WPInv_Invoice( $invoice ); |
|
| 766 | 766 | |
| 767 | - if ( ! $invoice->exists() ) { |
|
| 768 | - continue; |
|
| 769 | - } |
|
| 767 | + if ( ! $invoice->exists() ) { |
|
| 768 | + continue; |
|
| 769 | + } |
|
| 770 | 770 | |
| 771 | - // Abort if the discount does not exist or does not apply here. |
|
| 772 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 773 | - if ( ! $discount->exists() ) { |
|
| 774 | - continue; |
|
| 775 | - } |
|
| 771 | + // Abort if the discount does not exist or does not apply here. |
|
| 772 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 773 | + if ( ! $discount->exists() ) { |
|
| 774 | + continue; |
|
| 775 | + } |
|
| 776 | 776 | |
| 777 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 778 | - $invoice->recalculate_total(); |
|
| 777 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 778 | + $invoice->recalculate_total(); |
|
| 779 | 779 | |
| 780 | - if ( $invoice->get_total_discount() > 0 ) { |
|
| 781 | - $invoice->save(); |
|
| 782 | - } |
|
| 780 | + if ( $invoice->get_total_discount() > 0 ) { |
|
| 781 | + $invoice->save(); |
|
| 782 | + } |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | - // Show an admin message. |
|
| 786 | - $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 785 | + // Show an admin message. |
|
| 786 | + $this->show_success( __( 'Discounts have been recalculated.', 'invoicing' ) ); |
|
| 787 | 787 | |
| 788 | - // Redirect the admin. |
|
| 789 | - wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 790 | - exit; |
|
| 788 | + // Redirect the admin. |
|
| 789 | + wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) ); |
|
| 790 | + exit; |
|
| 791 | 791 | |
| 792 | - } |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | 794 | /** |
| 795 | - * Returns an array of admin notices. |
|
| 796 | - * |
|
| 797 | - * @since 1.0.19 |
|
| 795 | + * Returns an array of admin notices. |
|
| 796 | + * |
|
| 797 | + * @since 1.0.19 |
|
| 798 | 798 | * @return array |
| 799 | - */ |
|
| 800 | - public function get_notices() { |
|
| 801 | - $notices = get_option( 'wpinv_admin_notices' ); |
|
| 799 | + */ |
|
| 800 | + public function get_notices() { |
|
| 801 | + $notices = get_option( 'wpinv_admin_notices' ); |
|
| 802 | 802 | return is_array( $notices ) ? $notices : array(); |
| 803 | - } |
|
| 803 | + } |
|
| 804 | 804 | |
| 805 | - /** |
|
| 806 | - * Checks if we have any admin notices. |
|
| 807 | - * |
|
| 808 | - * @since 2.0.4 |
|
| 805 | + /** |
|
| 806 | + * Checks if we have any admin notices. |
|
| 807 | + * |
|
| 808 | + * @since 2.0.4 |
|
| 809 | 809 | * @return array |
| 810 | - */ |
|
| 811 | - public function has_notices() { |
|
| 812 | - return count( $this->get_notices() ) > 0; |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * Clears all admin notices |
|
| 817 | - * |
|
| 818 | - * @access public |
|
| 819 | - * @since 1.0.19 |
|
| 820 | - */ |
|
| 821 | - public function clear_notices() { |
|
| 822 | - delete_option( 'wpinv_admin_notices' ); |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * Saves a new admin notice |
|
| 827 | - * |
|
| 828 | - * @access public |
|
| 829 | - * @since 1.0.19 |
|
| 830 | - */ |
|
| 831 | - public function save_notice( $type, $message ) { |
|
| 832 | - $notices = $this->get_notices(); |
|
| 833 | - |
|
| 834 | - if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
| 835 | - $notices[ $type ] = array(); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - $notices[ $type ][] = $message; |
|
| 839 | - |
|
| 840 | - update_option( 'wpinv_admin_notices', $notices ); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - /** |
|
| 844 | - * Displays a success notice |
|
| 845 | - * |
|
| 846 | - * @param string $msg The message to qeue. |
|
| 847 | - * @access public |
|
| 848 | - * @since 1.0.19 |
|
| 849 | - */ |
|
| 850 | - public function show_success( $msg ) { |
|
| 851 | - $this->save_notice( 'success', $msg ); |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * Displays a error notice |
|
| 856 | - * |
|
| 857 | - * @access public |
|
| 858 | - * @param string $msg The message to qeue. |
|
| 859 | - * @since 1.0.19 |
|
| 860 | - */ |
|
| 861 | - public function show_error( $msg ) { |
|
| 862 | - $this->save_notice( 'error', $msg ); |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - /** |
|
| 866 | - * Displays a warning notice |
|
| 867 | - * |
|
| 868 | - * @access public |
|
| 869 | - * @param string $msg The message to qeue. |
|
| 870 | - * @since 1.0.19 |
|
| 871 | - */ |
|
| 872 | - public function show_warning( $msg ) { |
|
| 873 | - $this->save_notice( 'warning', $msg ); |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - /** |
|
| 877 | - * Displays a info notice |
|
| 878 | - * |
|
| 879 | - * @access public |
|
| 880 | - * @param string $msg The message to qeue. |
|
| 881 | - * @since 1.0.19 |
|
| 882 | - */ |
|
| 883 | - public function show_info( $msg ) { |
|
| 884 | - $this->save_notice( 'info', $msg ); |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - /** |
|
| 888 | - * Show notices |
|
| 889 | - * |
|
| 890 | - * @access public |
|
| 891 | - * @since 1.0.19 |
|
| 892 | - */ |
|
| 893 | - public function show_notices() { |
|
| 810 | + */ |
|
| 811 | + public function has_notices() { |
|
| 812 | + return count( $this->get_notices() ) > 0; |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * Clears all admin notices |
|
| 817 | + * |
|
| 818 | + * @access public |
|
| 819 | + * @since 1.0.19 |
|
| 820 | + */ |
|
| 821 | + public function clear_notices() { |
|
| 822 | + delete_option( 'wpinv_admin_notices' ); |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * Saves a new admin notice |
|
| 827 | + * |
|
| 828 | + * @access public |
|
| 829 | + * @since 1.0.19 |
|
| 830 | + */ |
|
| 831 | + public function save_notice( $type, $message ) { |
|
| 832 | + $notices = $this->get_notices(); |
|
| 833 | + |
|
| 834 | + if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ] ) ) { |
|
| 835 | + $notices[ $type ] = array(); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + $notices[ $type ][] = $message; |
|
| 839 | + |
|
| 840 | + update_option( 'wpinv_admin_notices', $notices ); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + /** |
|
| 844 | + * Displays a success notice |
|
| 845 | + * |
|
| 846 | + * @param string $msg The message to qeue. |
|
| 847 | + * @access public |
|
| 848 | + * @since 1.0.19 |
|
| 849 | + */ |
|
| 850 | + public function show_success( $msg ) { |
|
| 851 | + $this->save_notice( 'success', $msg ); |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * Displays a error notice |
|
| 856 | + * |
|
| 857 | + * @access public |
|
| 858 | + * @param string $msg The message to qeue. |
|
| 859 | + * @since 1.0.19 |
|
| 860 | + */ |
|
| 861 | + public function show_error( $msg ) { |
|
| 862 | + $this->save_notice( 'error', $msg ); |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | + * Displays a warning notice |
|
| 867 | + * |
|
| 868 | + * @access public |
|
| 869 | + * @param string $msg The message to qeue. |
|
| 870 | + * @since 1.0.19 |
|
| 871 | + */ |
|
| 872 | + public function show_warning( $msg ) { |
|
| 873 | + $this->save_notice( 'warning', $msg ); |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + /** |
|
| 877 | + * Displays a info notice |
|
| 878 | + * |
|
| 879 | + * @access public |
|
| 880 | + * @param string $msg The message to qeue. |
|
| 881 | + * @since 1.0.19 |
|
| 882 | + */ |
|
| 883 | + public function show_info( $msg ) { |
|
| 884 | + $this->save_notice( 'info', $msg ); |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + /** |
|
| 888 | + * Show notices |
|
| 889 | + * |
|
| 890 | + * @access public |
|
| 891 | + * @since 1.0.19 |
|
| 892 | + */ |
|
| 893 | + public function show_notices() { |
|
| 894 | 894 | |
| 895 | 895 | $notices = $this->get_notices(); |
| 896 | 896 | $this->clear_notices(); |
| 897 | 897 | |
| 898 | - foreach ( $notices as $type => $messages ) { |
|
| 898 | + foreach ( $notices as $type => $messages ) { |
|
| 899 | 899 | |
| 900 | - if ( ! is_array( $messages ) ) { |
|
| 901 | - continue; |
|
| 902 | - } |
|
| 900 | + if ( ! is_array( $messages ) ) { |
|
| 901 | + continue; |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | 904 | $type = esc_attr( $type ); |
| 905 | - foreach ( $messages as $message ) { |
|
| 906 | - echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
| 905 | + foreach ( $messages as $message ) { |
|
| 906 | + echo wp_kses_post( "<div class='notice notice-$type is-dismissible'><p>$message</p></div>" ); |
|
| 907 | 907 | } |
| 908 | 908 | } |
| 909 | 909 | |
| 910 | - foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 911 | - |
|
| 912 | - if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 913 | - $url = wp_nonce_url( |
|
| 914 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 915 | - 'getpaid-nonce', |
|
| 916 | - 'getpaid-nonce' |
|
| 917 | - ); |
|
| 918 | - $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 919 | - $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 920 | - echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
| 921 | - break; |
|
| 922 | - } |
|
| 910 | + foreach ( array( 'checkout_page', 'invoice_history_page', 'success_page', 'failure_page', 'invoice_subscription_page' ) as $page ) { |
|
| 911 | + |
|
| 912 | + if ( ! is_numeric( wpinv_get_option( $page, false ) ) ) { |
|
| 913 | + $url = wp_nonce_url( |
|
| 914 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 915 | + 'getpaid-nonce', |
|
| 916 | + 'getpaid-nonce' |
|
| 917 | + ); |
|
| 918 | + $message = __( 'Some GetPaid pages are missing. To use GetPaid without any issues, click the button below to generate the missing pages.', 'invoicing' ); |
|
| 919 | + $message2 = __( 'Generate Pages', 'invoicing' ); |
|
| 920 | + echo wp_kses_post( "<div class='notice notice-warning is-dismissible'><p>$message<br><br><a href='$url' class='button button-primary'>$message2</a></p></div>" ); |
|
| 921 | + break; |
|
| 922 | + } |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | - } |
|
| 925 | + } |
|
| 926 | 926 | |
| 927 | 927 | } |
@@ -13,30 +13,30 @@ discard block |
||
| 13 | 13 | class GetPaid_Bank_Transfer_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'bank_transfer'; |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
| 22 | + /** |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 34 | - public $order = 8; |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | + public $order = 8; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Class constructor. |
|
| 38 | - */ |
|
| 39 | - public function __construct() { |
|
| 37 | + * Class constructor. |
|
| 38 | + */ |
|
| 39 | + public function __construct() { |
|
| 40 | 40 | parent::__construct(); |
| 41 | 41 | |
| 42 | 42 | $this->title = __( 'Direct bank transfer', 'invoicing' ); |
@@ -44,24 +44,24 @@ discard block |
||
| 44 | 44 | $this->checkout_button_text = __( 'Proceed', 'invoicing' ); |
| 45 | 45 | $this->instructions = apply_filters( 'wpinv_bank_instructions', $this->get_option( 'info' ) ); |
| 46 | 46 | |
| 47 | - add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
| 48 | - add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
| 49 | - add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
| 50 | - add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
| 51 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
| 52 | - add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
| 47 | + add_action( 'wpinv_receipt_end', array( $this, 'thankyou_page' ) ); |
|
| 48 | + add_action( 'getpaid_invoice_line_items', array( $this, 'thankyou_page' ), 40 ); |
|
| 49 | + add_action( 'wpinv_pdf_content_billing', array( $this, 'thankyou_page' ), 11 ); |
|
| 50 | + add_action( 'wpinv_email_invoice_details', array( $this, 'email_instructions' ), 10, 3 ); |
|
| 51 | + add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
| 52 | + add_action( 'getpaid_invoice_status_publish', array( $this, 'invoice_paid' ), 20 ); |
|
| 53 | 53 | |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | - * Process Payment. |
|
| 58 | - * |
|
| 59 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 60 | - * @param array $submission_data Posted checkout fields. |
|
| 61 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 62 | - * @return array |
|
| 63 | - */ |
|
| 64 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 57 | + * Process Payment. |
|
| 58 | + * |
|
| 59 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 60 | + * @param array $submission_data Posted checkout fields. |
|
| 61 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 62 | + * @return array |
|
| 63 | + */ |
|
| 64 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 65 | 65 | |
| 66 | 66 | // Add a transaction id. |
| 67 | 67 | $invoice->set_transaction_id( $invoice->generate_key( 'bt_' ) ); |
@@ -82,66 +82,66 @@ discard block |
||
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | - * Output for the order received page. |
|
| 86 | - * |
|
| 87 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 88 | - */ |
|
| 89 | - public function thankyou_page( $invoice ) { |
|
| 85 | + * Output for the order received page. |
|
| 86 | + * |
|
| 87 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 88 | + */ |
|
| 89 | + public function thankyou_page( $invoice ) { |
|
| 90 | 90 | |
| 91 | 91 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
| 92 | 92 | |
| 93 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
| 93 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
| 94 | 94 | |
| 95 | 95 | if ( ! empty( $this->instructions ) ) { |
| 96 | 96 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - $this->bank_details( $invoice ); |
|
| 99 | + $this->bank_details( $invoice ); |
|
| 100 | 100 | |
| 101 | - echo '</div>'; |
|
| 101 | + echo '</div>'; |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | - * Add content to the WPI emails. |
|
| 109 | - * |
|
| 110 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 111 | - * @param string $email_type Email format: plain text or HTML. |
|
| 112 | - * @param bool $sent_to_admin Sent to admin. |
|
| 113 | - */ |
|
| 114 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
| 108 | + * Add content to the WPI emails. |
|
| 109 | + * |
|
| 110 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 111 | + * @param string $email_type Email format: plain text or HTML. |
|
| 112 | + * @param bool $sent_to_admin Sent to admin. |
|
| 113 | + */ |
|
| 114 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
| 115 | 115 | |
| 116 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
| 116 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
| 117 | 117 | |
| 118 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
| 118 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
| 119 | 119 | |
| 120 | - if ( $this->instructions ) { |
|
| 121 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
| 120 | + if ( $this->instructions ) { |
|
| 121 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - $this->bank_details( $invoice ); |
|
| 124 | + $this->bank_details( $invoice ); |
|
| 125 | 125 | |
| 126 | - echo '</div>'; |
|
| 126 | + echo '</div>'; |
|
| 127 | 127 | |
| 128 | - } |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | - * Get bank details and place into a list format. |
|
| 134 | - * |
|
| 135 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 136 | - */ |
|
| 137 | - protected function bank_details( $invoice ) { |
|
| 133 | + * Get bank details and place into a list format. |
|
| 134 | + * |
|
| 135 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 136 | + */ |
|
| 137 | + protected function bank_details( $invoice ) { |
|
| 138 | 138 | |
| 139 | - // Get the invoice country and country $locale. |
|
| 140 | - $country = $invoice->get_country(); |
|
| 141 | - $locale = $this->get_country_locale(); |
|
| 139 | + // Get the invoice country and country $locale. |
|
| 140 | + $country = $invoice->get_country(); |
|
| 141 | + $locale = $this->get_country_locale(); |
|
| 142 | 142 | |
| 143 | - // Get sortcode label in the $locale array and use appropriate one. |
|
| 144 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
| 143 | + // Get sortcode label in the $locale array and use appropriate one. |
|
| 144 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
| 145 | 145 | |
| 146 | 146 | $bank_fields = array( |
| 147 | 147 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -160,11 +160,11 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | if ( ! empty( $value ) ) { |
| 162 | 162 | $bank_info[ $field ] = array( |
| 163 | - 'label' => $label, |
|
| 164 | - 'value' => $value, |
|
| 165 | - ); |
|
| 163 | + 'label' => $label, |
|
| 164 | + 'value' => $value, |
|
| 165 | + ); |
|
| 166 | 166 | } |
| 167 | - } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | 169 | $bank_info = apply_filters( 'wpinv_bank_info', $bank_info, $invoice ); |
| 170 | 170 | |
@@ -172,139 +172,139 @@ discard block |
||
| 172 | 172 | return; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
| 175 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . esc_html( apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ), $invoice ) ) . '</h3>' . PHP_EOL; |
|
| 176 | + |
|
| 177 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
| 178 | + |
|
| 179 | + foreach ( $bank_info as $key => $data ) { |
|
| 180 | + echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + echo '</table>'; |
|
| 176 | 184 | |
| 177 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
| 185 | + } |
|
| 178 | 186 | |
| 179 | - foreach ( $bank_info as $key => $data ) { |
|
| 180 | - echo "<tr class='getpaid-bank-transfer-" . esc_attr( $key ) . "'><th class='font-weight-bold'>" . wp_kses_post( $data['label'] ) . "</th><td class='w-75'>" . wp_kses_post( wptexturize( $data['value'] ) ) . '</td></tr>' . PHP_EOL; |
|
| 181 | - } |
|
| 187 | + /** |
|
| 188 | + * Get country locale if localized. |
|
| 189 | + * |
|
| 190 | + * @return array |
|
| 191 | + */ |
|
| 192 | + public function get_country_locale() { |
|
| 193 | + |
|
| 194 | + if ( empty( $this->locale ) ) { |
|
| 195 | + |
|
| 196 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
| 197 | + $this->locale = apply_filters( |
|
| 198 | + 'getpaid_get_bank_transfer_locale', |
|
| 199 | + array( |
|
| 200 | + 'AU' => array( |
|
| 201 | + 'sortcode' => array( |
|
| 202 | + 'label' => __( 'BSB', 'invoicing' ), |
|
| 203 | + ), |
|
| 204 | + ), |
|
| 205 | + 'CA' => array( |
|
| 206 | + 'sortcode' => array( |
|
| 207 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
| 208 | + ), |
|
| 209 | + ), |
|
| 210 | + 'IN' => array( |
|
| 211 | + 'sortcode' => array( |
|
| 212 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
| 213 | + ), |
|
| 214 | + ), |
|
| 215 | + 'IT' => array( |
|
| 216 | + 'sortcode' => array( |
|
| 217 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
| 218 | + ), |
|
| 219 | + ), |
|
| 220 | + 'NZ' => array( |
|
| 221 | + 'sortcode' => array( |
|
| 222 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
| 223 | + ), |
|
| 224 | + ), |
|
| 225 | + 'SE' => array( |
|
| 226 | + 'sortcode' => array( |
|
| 227 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
| 228 | + ), |
|
| 229 | + ), |
|
| 230 | + 'US' => array( |
|
| 231 | + 'sortcode' => array( |
|
| 232 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
| 233 | + ), |
|
| 234 | + ), |
|
| 235 | + 'ZA' => array( |
|
| 236 | + 'sortcode' => array( |
|
| 237 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
| 238 | + ), |
|
| 239 | + ), |
|
| 240 | + ) |
|
| 241 | + ); |
|
| 182 | 242 | |
| 183 | - echo '</table>'; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return $this->locale; |
|
| 184 | 246 | |
| 185 | 247 | } |
| 186 | 248 | |
| 187 | 249 | /** |
| 188 | - * Get country locale if localized. |
|
| 189 | - * |
|
| 190 | - * @return array |
|
| 191 | - */ |
|
| 192 | - public function get_country_locale() { |
|
| 193 | - |
|
| 194 | - if ( empty( $this->locale ) ) { |
|
| 195 | - |
|
| 196 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
| 197 | - $this->locale = apply_filters( |
|
| 198 | - 'getpaid_get_bank_transfer_locale', |
|
| 199 | - array( |
|
| 200 | - 'AU' => array( |
|
| 201 | - 'sortcode' => array( |
|
| 202 | - 'label' => __( 'BSB', 'invoicing' ), |
|
| 203 | - ), |
|
| 204 | - ), |
|
| 205 | - 'CA' => array( |
|
| 206 | - 'sortcode' => array( |
|
| 207 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
| 208 | - ), |
|
| 209 | - ), |
|
| 210 | - 'IN' => array( |
|
| 211 | - 'sortcode' => array( |
|
| 212 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
| 213 | - ), |
|
| 214 | - ), |
|
| 215 | - 'IT' => array( |
|
| 216 | - 'sortcode' => array( |
|
| 217 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
| 218 | - ), |
|
| 219 | - ), |
|
| 220 | - 'NZ' => array( |
|
| 221 | - 'sortcode' => array( |
|
| 222 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
| 223 | - ), |
|
| 224 | - ), |
|
| 225 | - 'SE' => array( |
|
| 226 | - 'sortcode' => array( |
|
| 227 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
| 228 | - ), |
|
| 229 | - ), |
|
| 230 | - 'US' => array( |
|
| 231 | - 'sortcode' => array( |
|
| 232 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
| 233 | - ), |
|
| 234 | - ), |
|
| 235 | - 'ZA' => array( |
|
| 236 | - 'sortcode' => array( |
|
| 237 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
| 238 | - ), |
|
| 239 | - ), |
|
| 240 | - ) |
|
| 241 | - ); |
|
| 242 | - |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return $this->locale; |
|
| 246 | - |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Filters the gateway settings. |
|
| 251 | - * |
|
| 252 | - * @param array $admin_settings |
|
| 253 | - */ |
|
| 254 | - public function admin_settings( $admin_settings ) { |
|
| 250 | + * Filters the gateway settings. |
|
| 251 | + * |
|
| 252 | + * @param array $admin_settings |
|
| 253 | + */ |
|
| 254 | + public function admin_settings( $admin_settings ) { |
|
| 255 | 255 | |
| 256 | 256 | $admin_settings['bank_transfer_desc']['std'] = __( "Make your payment directly into our bank account. Please use your Invoice Number as the payment reference. Your invoice won't be processed until the funds have cleared in our account.", 'invoicing' ); |
| 257 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
| 257 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
| 258 | 258 | |
| 259 | - $locale = $this->get_country_locale(); |
|
| 259 | + $locale = $this->get_country_locale(); |
|
| 260 | 260 | |
| 261 | - // Get sortcode label in the $locale array and use appropriate one. |
|
| 262 | - $country = wpinv_default_billing_country(); |
|
| 263 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
| 261 | + // Get sortcode label in the $locale array and use appropriate one. |
|
| 262 | + $country = wpinv_default_billing_country(); |
|
| 263 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
| 264 | 264 | |
| 265 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
| 265 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
| 266 | 266 | 'type' => 'text', |
| 267 | 267 | 'id' => 'bank_transfer_ac_name', |
| 268 | 268 | 'name' => __( 'Account Name', 'invoicing' ), |
| 269 | - ); |
|
| 269 | + ); |
|
| 270 | 270 | |
| 271 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
| 271 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
| 272 | 272 | 'type' => 'text', |
| 273 | 273 | 'id' => 'bank_transfer_ac_no', |
| 274 | 274 | 'name' => __( 'Account Number', 'invoicing' ), |
| 275 | - ); |
|
| 275 | + ); |
|
| 276 | 276 | |
| 277 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
| 277 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
| 278 | 278 | 'type' => 'text', |
| 279 | 279 | 'id' => 'bank_transfer_bank_name', |
| 280 | 280 | 'name' => __( 'Bank Name', 'invoicing' ), |
| 281 | - ); |
|
| 281 | + ); |
|
| 282 | 282 | |
| 283 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
| 283 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
| 284 | 284 | 'type' => 'text', |
| 285 | 285 | 'id' => 'bank_transfer_ifsc', |
| 286 | 286 | 'name' => __( 'IFSC Code', 'invoicing' ), |
| 287 | - ); |
|
| 287 | + ); |
|
| 288 | 288 | |
| 289 | - $admin_settings['bank_transfer_iban'] = array( |
|
| 289 | + $admin_settings['bank_transfer_iban'] = array( |
|
| 290 | 290 | 'type' => 'text', |
| 291 | 291 | 'id' => 'bank_transfer_iban', |
| 292 | 292 | 'name' => __( 'IBAN', 'invoicing' ), |
| 293 | - ); |
|
| 293 | + ); |
|
| 294 | 294 | |
| 295 | - $admin_settings['bank_transfer_bic'] = array( |
|
| 295 | + $admin_settings['bank_transfer_bic'] = array( |
|
| 296 | 296 | 'type' => 'text', |
| 297 | 297 | 'id' => 'bank_transfer_bic', |
| 298 | 298 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
| 299 | - ); |
|
| 299 | + ); |
|
| 300 | 300 | |
| 301 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
| 302 | - 'type' => 'text', |
|
| 303 | - 'id' => 'bank_transfer_sort_code', |
|
| 304 | - 'name' => $sortcode, |
|
| 305 | - ); |
|
| 301 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
| 302 | + 'type' => 'text', |
|
| 303 | + 'id' => 'bank_transfer_sort_code', |
|
| 304 | + 'name' => $sortcode, |
|
| 305 | + ); |
|
| 306 | 306 | |
| 307 | - $admin_settings['bank_transfer_info'] = array( |
|
| 307 | + $admin_settings['bank_transfer_info'] = array( |
|
| 308 | 308 | 'id' => 'bank_transfer_info', |
| 309 | 309 | 'name' => __( 'Instructions', 'invoicing' ), |
| 310 | 310 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -314,17 +314,17 @@ discard block |
||
| 314 | 314 | 'rows' => 5, |
| 315 | 315 | ); |
| 316 | 316 | |
| 317 | - return $admin_settings; |
|
| 318 | - } |
|
| 317 | + return $admin_settings; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * Processes invoice addons. |
|
| 322 | - * |
|
| 323 | - * @param WPInv_Invoice $invoice |
|
| 324 | - * @param GetPaid_Form_Item[] $items |
|
| 325 | - * @return WPInv_Invoice |
|
| 326 | - */ |
|
| 327 | - public function process_addons( $invoice, $items ) { |
|
| 320 | + /** |
|
| 321 | + * Processes invoice addons. |
|
| 322 | + * |
|
| 323 | + * @param WPInv_Invoice $invoice |
|
| 324 | + * @param GetPaid_Form_Item[] $items |
|
| 325 | + * @return WPInv_Invoice |
|
| 326 | + */ |
|
| 327 | + public function process_addons( $invoice, $items ) { |
|
| 328 | 328 | |
| 329 | 329 | foreach ( $items as $item ) { |
| 330 | 330 | $invoice->add_item( $item ); |
@@ -332,66 +332,66 @@ discard block |
||
| 332 | 332 | |
| 333 | 333 | $invoice->recalculate_total(); |
| 334 | 334 | $invoice->save(); |
| 335 | - } |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - /** |
|
| 338 | - * (Maybe) renews a bank transfer subscription profile. |
|
| 339 | - * |
|
| 340 | - * |
|
| 337 | + /** |
|
| 338 | + * (Maybe) renews a bank transfer subscription profile. |
|
| 339 | + * |
|
| 340 | + * |
|
| 341 | 341 | * @param WPInv_Subscription $subscription |
| 342 | - */ |
|
| 343 | - public function maybe_renew_subscription( $subscription ) { |
|
| 342 | + */ |
|
| 343 | + public function maybe_renew_subscription( $subscription ) { |
|
| 344 | 344 | |
| 345 | 345 | // Ensure its our subscription && it's active. |
| 346 | 346 | if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
| 347 | - $subscription->create_payment(); |
|
| 347 | + $subscription->create_payment(); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - /** |
|
| 353 | - * Process a bank transfer payment. |
|
| 354 | - * |
|
| 355 | - * |
|
| 352 | + /** |
|
| 353 | + * Process a bank transfer payment. |
|
| 354 | + * |
|
| 355 | + * |
|
| 356 | 356 | * @param WPInv_Invoice $invoice |
| 357 | - */ |
|
| 358 | - public function invoice_paid( $invoice ) { |
|
| 359 | - |
|
| 360 | - // Abort if not paid by bank transfer. |
|
| 361 | - if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
| 362 | - return; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - // Is it a parent payment? |
|
| 366 | - if ( 0 == $invoice->get_parent_id() ) { |
|
| 367 | - |
|
| 368 | - // (Maybe) activate subscriptions. |
|
| 369 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 370 | - |
|
| 371 | - if ( ! empty( $subscriptions ) ) { |
|
| 372 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
| 373 | - |
|
| 374 | - foreach ( $subscriptions as $subscription ) { |
|
| 375 | - if ( $subscription->exists() ) { |
|
| 376 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 377 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
| 378 | - |
|
| 379 | - $subscription->set_next_renewal_date( $expiry ); |
|
| 380 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 381 | - $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
| 382 | - $subscription->activate(); |
|
| 383 | - } |
|
| 384 | - } |
|
| 357 | + */ |
|
| 358 | + public function invoice_paid( $invoice ) { |
|
| 359 | + |
|
| 360 | + // Abort if not paid by bank transfer. |
|
| 361 | + if ( $this->id !== $invoice->get_gateway() || ! $invoice->is_recurring() ) { |
|
| 362 | + return; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + // Is it a parent payment? |
|
| 366 | + if ( 0 == $invoice->get_parent_id() ) { |
|
| 367 | + |
|
| 368 | + // (Maybe) activate subscriptions. |
|
| 369 | + $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 370 | + |
|
| 371 | + if ( ! empty( $subscriptions ) ) { |
|
| 372 | + $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
| 373 | + |
|
| 374 | + foreach ( $subscriptions as $subscription ) { |
|
| 375 | + if ( $subscription->exists() ) { |
|
| 376 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 377 | + $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
| 378 | + |
|
| 379 | + $subscription->set_next_renewal_date( $expiry ); |
|
| 380 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 381 | + $subscription->set_profile_id( 'bt_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ); |
|
| 382 | + $subscription->activate(); |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | 385 | } |
| 386 | 386 | } else { |
| 387 | 387 | |
| 388 | - $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
| 388 | + $subscription = getpaid_get_subscription( $invoice->get_subscription_id() ); |
|
| 389 | 389 | |
| 390 | - // Renew the subscription. |
|
| 391 | - if ( $subscription && $subscription->exists() ) { |
|
| 392 | - $subscription->add_payment( array(), $invoice ); |
|
| 393 | - $subscription->renew(); |
|
| 394 | - } |
|
| 390 | + // Renew the subscription. |
|
| 391 | + if ( $subscription && $subscription->exists() ) { |
|
| 392 | + $subscription->add_payment( array(), $invoice ); |
|
| 393 | + $subscription->renew(); |
|
| 394 | + } |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | } |
@@ -14,143 +14,143 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Register the widget with WordPress. |
|
| 19 | - * |
|
| 20 | - */ |
|
| 21 | - public function __construct() { |
|
| 22 | - |
|
| 23 | - $options = array( |
|
| 24 | - 'textdomain' => 'invoicing', |
|
| 25 | - 'block-icon' => 'controls-repeat', |
|
| 26 | - 'block-category' => 'widgets', |
|
| 27 | - 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | - 'class_name' => __CLASS__, |
|
| 29 | - 'base_id' => 'wpinv_subscriptions', |
|
| 30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | - 'widget_ops' => array( |
|
| 32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | - ), |
|
| 35 | - 'arguments' => array( |
|
| 36 | - 'title' => array( |
|
| 37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | - 'type' => 'text', |
|
| 40 | - 'desc_tip' => true, |
|
| 41 | - 'default' => '', |
|
| 42 | - 'advanced' => false, |
|
| 43 | - ), |
|
| 44 | - ), |
|
| 45 | - |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - parent::__construct( $options ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Retrieves current user's subscriptions. |
|
| 53 | - * |
|
| 54 | - * @return GetPaid_Subscriptions_Query |
|
| 55 | - */ |
|
| 56 | - public function get_subscriptions() { |
|
| 57 | - |
|
| 58 | - // Prepare license args. |
|
| 59 | - $args = array( |
|
| 60 | - 'customer_in' => get_current_user_id(), |
|
| 61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The Super block output function. |
|
| 70 | - * |
|
| 71 | - * @param array $args |
|
| 72 | - * @param array $widget_args |
|
| 73 | - * @param string $content |
|
| 74 | - * |
|
| 75 | - * @return mixed|string|bool |
|
| 76 | - */ |
|
| 77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 78 | - |
|
| 79 | - // Ensure that the user is logged in. |
|
| 80 | - if ( ! is_user_logged_in() ) { |
|
| 81 | - |
|
| 82 | - return aui()->alert( |
|
| 83 | - array( |
|
| 84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 85 | - 'type' => 'error', |
|
| 86 | - ) |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Are we displaying a single subscription? |
|
| 92 | - if ( isset( $_GET['subscription'] ) ) { |
|
| 93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Retrieve the user's subscriptions. |
|
| 97 | - $subscriptions = $this->get_subscriptions(); |
|
| 98 | - |
|
| 99 | - // Start the output buffer. |
|
| 100 | - ob_start(); |
|
| 101 | - |
|
| 102 | - // Backwards compatibility. |
|
| 103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 104 | - |
|
| 105 | - // Display errors and notices. |
|
| 106 | - wpinv_print_errors(); |
|
| 107 | - |
|
| 108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 109 | - |
|
| 110 | - // Print the table header. |
|
| 111 | - $this->print_table_header(); |
|
| 112 | - |
|
| 113 | - // Print table body. |
|
| 114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
| 115 | - |
|
| 116 | - // Print table footer. |
|
| 117 | - $this->print_table_footer(); |
|
| 118 | - |
|
| 119 | - // Print the navigation. |
|
| 120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
| 121 | - |
|
| 122 | - // Backwards compatibility. |
|
| 123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 124 | - |
|
| 125 | - // Return the output. |
|
| 126 | - return ob_get_clean(); |
|
| 127 | - |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Retrieves the subscription columns. |
|
| 132 | - * |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - public function get_subscriptions_table_columns() { |
|
| 17 | + /** |
|
| 18 | + * Register the widget with WordPress. |
|
| 19 | + * |
|
| 20 | + */ |
|
| 21 | + public function __construct() { |
|
| 22 | + |
|
| 23 | + $options = array( |
|
| 24 | + 'textdomain' => 'invoicing', |
|
| 25 | + 'block-icon' => 'controls-repeat', |
|
| 26 | + 'block-category' => 'widgets', |
|
| 27 | + 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | + 'class_name' => __CLASS__, |
|
| 29 | + 'base_id' => 'wpinv_subscriptions', |
|
| 30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | + 'widget_ops' => array( |
|
| 32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | + ), |
|
| 35 | + 'arguments' => array( |
|
| 36 | + 'title' => array( |
|
| 37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | + 'type' => 'text', |
|
| 40 | + 'desc_tip' => true, |
|
| 41 | + 'default' => '', |
|
| 42 | + 'advanced' => false, |
|
| 43 | + ), |
|
| 44 | + ), |
|
| 45 | + |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + parent::__construct( $options ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Retrieves current user's subscriptions. |
|
| 53 | + * |
|
| 54 | + * @return GetPaid_Subscriptions_Query |
|
| 55 | + */ |
|
| 56 | + public function get_subscriptions() { |
|
| 57 | + |
|
| 58 | + // Prepare license args. |
|
| 59 | + $args = array( |
|
| 60 | + 'customer_in' => get_current_user_id(), |
|
| 61 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + return new GetPaid_Subscriptions_Query( $args ); |
|
| 65 | + |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The Super block output function. |
|
| 70 | + * |
|
| 71 | + * @param array $args |
|
| 72 | + * @param array $widget_args |
|
| 73 | + * @param string $content |
|
| 74 | + * |
|
| 75 | + * @return mixed|string|bool |
|
| 76 | + */ |
|
| 77 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 78 | + |
|
| 79 | + // Ensure that the user is logged in. |
|
| 80 | + if ( ! is_user_logged_in() ) { |
|
| 81 | + |
|
| 82 | + return aui()->alert( |
|
| 83 | + array( |
|
| 84 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 85 | + 'type' => 'error', |
|
| 86 | + ) |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Are we displaying a single subscription? |
|
| 92 | + if ( isset( $_GET['subscription'] ) ) { |
|
| 93 | + return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Retrieve the user's subscriptions. |
|
| 97 | + $subscriptions = $this->get_subscriptions(); |
|
| 98 | + |
|
| 99 | + // Start the output buffer. |
|
| 100 | + ob_start(); |
|
| 101 | + |
|
| 102 | + // Backwards compatibility. |
|
| 103 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
| 104 | + |
|
| 105 | + // Display errors and notices. |
|
| 106 | + wpinv_print_errors(); |
|
| 107 | + |
|
| 108 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 109 | + |
|
| 110 | + // Print the table header. |
|
| 111 | + $this->print_table_header(); |
|
| 112 | + |
|
| 113 | + // Print table body. |
|
| 114 | + $this->print_table_body( $subscriptions->get_results() ); |
|
| 115 | + |
|
| 116 | + // Print table footer. |
|
| 117 | + $this->print_table_footer(); |
|
| 118 | + |
|
| 119 | + // Print the navigation. |
|
| 120 | + $this->print_navigation( $subscriptions->get_total() ); |
|
| 121 | + |
|
| 122 | + // Backwards compatibility. |
|
| 123 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
| 124 | + |
|
| 125 | + // Return the output. |
|
| 126 | + return ob_get_clean(); |
|
| 127 | + |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Retrieves the subscription columns. |
|
| 132 | + * |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + public function get_subscriptions_table_columns() { |
|
| 136 | 136 | |
| 137 | - $columns = array( |
|
| 138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 141 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 142 | - ); |
|
| 137 | + $columns = array( |
|
| 138 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 139 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 140 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 141 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 142 | + ); |
|
| 143 | 143 | |
| 144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 145 | - } |
|
| 144 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Displays the table header. |
|
| 149 | - * |
|
| 150 | - */ |
|
| 151 | - public function print_table_header() { |
|
| 147 | + /** |
|
| 148 | + * Displays the table header. |
|
| 149 | + * |
|
| 150 | + */ |
|
| 151 | + public function print_table_header() { |
|
| 152 | 152 | |
| 153 | - ?> |
|
| 153 | + ?> |
|
| 154 | 154 | |
| 155 | 155 | <table class="table table-bordered table-striped"> |
| 156 | 156 | |
@@ -166,122 +166,122 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | <?php |
| 168 | 168 | |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Displays the table body. |
|
| 173 | - * |
|
| 174 | - * @param WPInv_Subscription[] $subscriptions |
|
| 175 | - */ |
|
| 176 | - public function print_table_body( $subscriptions ) { |
|
| 171 | + /** |
|
| 172 | + * Displays the table body. |
|
| 173 | + * |
|
| 174 | + * @param WPInv_Subscription[] $subscriptions |
|
| 175 | + */ |
|
| 176 | + public function print_table_body( $subscriptions ) { |
|
| 177 | 177 | |
| 178 | - if ( empty( $subscriptions ) ) { |
|
| 179 | - $this->print_table_body_no_subscriptions(); |
|
| 180 | - } else { |
|
| 181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
| 182 | - } |
|
| 178 | + if ( empty( $subscriptions ) ) { |
|
| 179 | + $this->print_table_body_no_subscriptions(); |
|
| 180 | + } else { |
|
| 181 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Displays the table body if no subscriptions were found. |
|
| 188 | - * |
|
| 189 | - */ |
|
| 190 | - public function print_table_body_no_subscriptions() { |
|
| 186 | + /** |
|
| 187 | + * Displays the table body if no subscriptions were found. |
|
| 188 | + * |
|
| 189 | + */ |
|
| 190 | + public function print_table_body_no_subscriptions() { |
|
| 191 | 191 | |
| 192 | - ?> |
|
| 192 | + ?> |
|
| 193 | 193 | <tbody> |
| 194 | 194 | |
| 195 | 195 | <tr> |
| 196 | 196 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
| 197 | 197 | |
| 198 | 198 | <?php |
| 199 | - aui()->alert( |
|
| 200 | - array( |
|
| 201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 202 | - 'type' => 'warning', |
|
| 203 | - ), |
|
| 199 | + aui()->alert( |
|
| 200 | + array( |
|
| 201 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 202 | + 'type' => 'warning', |
|
| 203 | + ), |
|
| 204 | 204 | true |
| 205 | - ); |
|
| 206 | - ?> |
|
| 205 | + ); |
|
| 206 | + ?> |
|
| 207 | 207 | |
| 208 | 208 | </td> |
| 209 | 209 | </tr> |
| 210 | 210 | |
| 211 | 211 | </tbody> |
| 212 | 212 | <?php |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Displays the table body if subscriptions were found. |
|
| 217 | - * |
|
| 218 | - * @param WPInv_Subscription[] $subscriptions |
|
| 219 | - */ |
|
| 220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
| 215 | + /** |
|
| 216 | + * Displays the table body if subscriptions were found. |
|
| 217 | + * |
|
| 218 | + * @param WPInv_Subscription[] $subscriptions |
|
| 219 | + */ |
|
| 220 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
| 221 | 221 | |
| 222 | - ?> |
|
| 222 | + ?> |
|
| 223 | 223 | <tbody> |
| 224 | 224 | |
| 225 | 225 | <?php foreach ( $subscriptions as $subscription ) : ?> |
| 226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
| 227 | 227 | <?php |
| 228 | - wpinv_get_template( |
|
| 229 | - 'subscriptions/subscriptions-table-row.php', |
|
| 230 | - array( |
|
| 231 | - 'subscription' => $subscription, |
|
| 232 | - 'widget' => $this, |
|
| 233 | - ) |
|
| 234 | - ); |
|
| 235 | - ?> |
|
| 228 | + wpinv_get_template( |
|
| 229 | + 'subscriptions/subscriptions-table-row.php', |
|
| 230 | + array( |
|
| 231 | + 'subscription' => $subscription, |
|
| 232 | + 'widget' => $this, |
|
| 233 | + ) |
|
| 234 | + ); |
|
| 235 | + ?> |
|
| 236 | 236 | </tr> |
| 237 | 237 | <?php endforeach; ?> |
| 238 | 238 | |
| 239 | 239 | </tbody> |
| 240 | 240 | <?php |
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Adds row actions to a column |
|
| 245 | - * |
|
| 246 | - * @param string $content column content |
|
| 247 | - * @param WPInv_Subscription $subscription |
|
| 248 | - * @since 1.0.0 |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function add_row_actions( $content, $subscription ) { |
|
| 252 | - |
|
| 253 | - // Prepare row actions. |
|
| 254 | - $actions = array(); |
|
| 255 | - |
|
| 256 | - // View subscription action. |
|
| 257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | - |
|
| 261 | - // Filter the actions. |
|
| 262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | - |
|
| 264 | - $sanitized = array(); |
|
| 265 | - foreach ( $actions as $key => $action ) { |
|
| 266 | - $key = sanitize_html_class( $key ); |
|
| 267 | - $action = wp_kses_post( $action ); |
|
| 268 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | - $row_actions .= '</small>'; |
|
| 274 | - |
|
| 275 | - return $content . $row_actions; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Displays the table footer. |
|
| 280 | - * |
|
| 281 | - */ |
|
| 282 | - public function print_table_footer() { |
|
| 283 | - |
|
| 284 | - ?> |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Adds row actions to a column |
|
| 245 | + * |
|
| 246 | + * @param string $content column content |
|
| 247 | + * @param WPInv_Subscription $subscription |
|
| 248 | + * @since 1.0.0 |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function add_row_actions( $content, $subscription ) { |
|
| 252 | + |
|
| 253 | + // Prepare row actions. |
|
| 254 | + $actions = array(); |
|
| 255 | + |
|
| 256 | + // View subscription action. |
|
| 257 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | + |
|
| 261 | + // Filter the actions. |
|
| 262 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | + |
|
| 264 | + $sanitized = array(); |
|
| 265 | + foreach ( $actions as $key => $action ) { |
|
| 266 | + $key = sanitize_html_class( $key ); |
|
| 267 | + $action = wp_kses_post( $action ); |
|
| 268 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | + $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | + $row_actions .= '</small>'; |
|
| 274 | + |
|
| 275 | + return $content . $row_actions; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Displays the table footer. |
|
| 280 | + * |
|
| 281 | + */ |
|
| 282 | + public function print_table_footer() { |
|
| 283 | + |
|
| 284 | + ?> |
|
| 285 | 285 | |
| 286 | 286 | <tfoot> |
| 287 | 287 | <tr> |
@@ -296,145 +296,145 @@ discard block |
||
| 296 | 296 | </table> |
| 297 | 297 | <?php |
| 298 | 298 | |
| 299 | - } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Displays the navigation. |
|
| 303 | - * |
|
| 304 | - * @param int $total |
|
| 305 | - */ |
|
| 306 | - public function print_navigation( $total ) { |
|
| 301 | + /** |
|
| 302 | + * Displays the navigation. |
|
| 303 | + * |
|
| 304 | + * @param int $total |
|
| 305 | + */ |
|
| 306 | + public function print_navigation( $total ) { |
|
| 307 | 307 | |
| 308 | - if ( $total < 1 ) { |
|
| 308 | + if ( $total < 1 ) { |
|
| 309 | 309 | |
| 310 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | - $args = array( |
|
| 312 | - 'customer_in' => get_current_user_id(), |
|
| 313 | - 'fields' => 'id', |
|
| 314 | - ); |
|
| 310 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | + $args = array( |
|
| 312 | + 'customer_in' => get_current_user_id(), |
|
| 313 | + 'fields' => 'id', |
|
| 314 | + ); |
|
| 315 | 315 | |
| 316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | - $total = $count_query->get_total(); |
|
| 318 | - } |
|
| 316 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | + $total = $count_query->get_total(); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - // Abort if we do not have pages. |
|
| 321 | - if ( 2 > $total ) { |
|
| 322 | - return; |
|
| 323 | - } |
|
| 320 | + // Abort if we do not have pages. |
|
| 321 | + if ( 2 > $total ) { |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - ?> |
|
| 325 | + ?> |
|
| 326 | 326 | |
| 327 | 327 | <div class="getpaid-subscriptions-pagination"> |
| 328 | 328 | <?php |
| 329 | - $big = 999999; |
|
| 330 | - |
|
| 331 | - echo wp_kses_post( |
|
| 332 | - getpaid_paginate_links( |
|
| 333 | - array( |
|
| 334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 335 | - 'format' => '?paged=%#%', |
|
| 336 | - 'total' => (int) ceil( $total / 10 ), |
|
| 337 | - ) |
|
| 338 | - ) |
|
| 339 | - ); |
|
| 340 | - ?> |
|
| 329 | + $big = 999999; |
|
| 330 | + |
|
| 331 | + echo wp_kses_post( |
|
| 332 | + getpaid_paginate_links( |
|
| 333 | + array( |
|
| 334 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 335 | + 'format' => '?paged=%#%', |
|
| 336 | + 'total' => (int) ceil( $total / 10 ), |
|
| 337 | + ) |
|
| 338 | + ) |
|
| 339 | + ); |
|
| 340 | + ?> |
|
| 341 | 341 | </div> |
| 342 | 342 | |
| 343 | 343 | <?php |
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Returns a single subscription's columns. |
|
| 348 | - * |
|
| 349 | - * @param WPInv_Subscription $subscription |
|
| 350 | - * |
|
| 351 | - * @return array |
|
| 352 | - */ |
|
| 353 | - public function get_single_subscription_columns( $subscription ) { |
|
| 354 | - |
|
| 355 | - // Prepare subscription detail columns. |
|
| 356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
| 357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 358 | - $fields = apply_filters( |
|
| 359 | - 'getpaid_single_subscription_details_fields', |
|
| 360 | - array( |
|
| 361 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
| 367 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
| 368 | - ), |
|
| 369 | - $subscription, |
|
| 370 | - $items_count |
|
| 371 | - ); |
|
| 372 | - |
|
| 373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
| 374 | - |
|
| 375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if ( 'pending' === $subscription->get_status() ) { |
|
| 380 | - unset( $fields['expiry_date'] ); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
| 385 | - unset( $fields['start_date'] ); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
| 389 | - unset( $fields['initial_amount'] ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $fields; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Displays a single subscription. |
|
| 397 | - * |
|
| 398 | - * @param string $subscription |
|
| 399 | - * |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function display_single_subscription( $subscription ) { |
|
| 403 | - |
|
| 404 | - // Fetch the subscription. |
|
| 405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 406 | - |
|
| 407 | - if ( ! $subscription->exists() ) { |
|
| 408 | - |
|
| 409 | - return aui()->alert( |
|
| 410 | - array( |
|
| 411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 412 | - 'type' => 'error', |
|
| 413 | - ) |
|
| 414 | - ); |
|
| 415 | - |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // Ensure that the user owns this subscription key. |
|
| 419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 420 | - |
|
| 421 | - return aui()->alert( |
|
| 422 | - array( |
|
| 423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 424 | - 'type' => 'error', |
|
| 425 | - ) |
|
| 426 | - ); |
|
| 427 | - |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return wpinv_get_template_html( |
|
| 431 | - 'subscriptions/subscription-details.php', |
|
| 432 | - array( |
|
| 433 | - 'subscription' => $subscription, |
|
| 434 | - 'widget' => $this, |
|
| 435 | - ) |
|
| 436 | - ); |
|
| 437 | - |
|
| 438 | - } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Returns a single subscription's columns. |
|
| 348 | + * |
|
| 349 | + * @param WPInv_Subscription $subscription |
|
| 350 | + * |
|
| 351 | + * @return array |
|
| 352 | + */ |
|
| 353 | + public function get_single_subscription_columns( $subscription ) { |
|
| 354 | + |
|
| 355 | + // Prepare subscription detail columns. |
|
| 356 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
| 357 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 358 | + $fields = apply_filters( |
|
| 359 | + 'getpaid_single_subscription_details_fields', |
|
| 360 | + array( |
|
| 361 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 362 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 363 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 364 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 365 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 366 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
| 367 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
| 368 | + ), |
|
| 369 | + $subscription, |
|
| 370 | + $items_count |
|
| 371 | + ); |
|
| 372 | + |
|
| 373 | + if ( isset( $fields['expiry_date'] ) ) { |
|
| 374 | + |
|
| 375 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 376 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if ( 'pending' === $subscription->get_status() ) { |
|
| 380 | + unset( $fields['expiry_date'] ); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
| 385 | + unset( $fields['start_date'] ); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
| 389 | + unset( $fields['initial_amount'] ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $fields; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Displays a single subscription. |
|
| 397 | + * |
|
| 398 | + * @param string $subscription |
|
| 399 | + * |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function display_single_subscription( $subscription ) { |
|
| 403 | + |
|
| 404 | + // Fetch the subscription. |
|
| 405 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 406 | + |
|
| 407 | + if ( ! $subscription->exists() ) { |
|
| 408 | + |
|
| 409 | + return aui()->alert( |
|
| 410 | + array( |
|
| 411 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 412 | + 'type' => 'error', |
|
| 413 | + ) |
|
| 414 | + ); |
|
| 415 | + |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // Ensure that the user owns this subscription key. |
|
| 419 | + if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 420 | + |
|
| 421 | + return aui()->alert( |
|
| 422 | + array( |
|
| 423 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 424 | + 'type' => 'error', |
|
| 425 | + ) |
|
| 426 | + ); |
|
| 427 | + |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return wpinv_get_template_html( |
|
| 431 | + 'subscriptions/subscription-details.php', |
|
| 432 | + array( |
|
| 433 | + 'subscription' => $subscription, |
|
| 434 | + 'widget' => $this, |
|
| 435 | + ) |
|
| 436 | + ); |
|
| 437 | + |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | 440 | } |
@@ -12,489 +12,489 @@ |
||
| 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 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Helper function to send an email. |
|
| 170 | - * |
|
| 171 | - * @param WPInv_Invoice $invoice |
|
| 172 | - * @param GetPaid_Notification_Email $email |
|
| 173 | - * @param string $type |
|
| 174 | - * @param string|array $recipients |
|
| 175 | - * @param array $extra_args Extra template args. |
|
| 176 | - */ |
|
| 177 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
| 178 | - |
|
| 179 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
| 180 | - |
|
| 181 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
| 182 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
| 183 | - return; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 187 | - $merge_tags = $email->get_merge_tags(); |
|
| 188 | - |
|
| 189 | - $result = $mailer->send( |
|
| 190 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 191 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
| 192 | - $email->get_content( $merge_tags, $extra_args ), |
|
| 193 | - $email->get_attachments() |
|
| 194 | - ); |
|
| 195 | - |
|
| 196 | - // Maybe send a copy to the admin. |
|
| 197 | - if ( $email->include_admin_bcc() ) { |
|
| 198 | - $mailer->send( |
|
| 199 | - wpinv_get_admin_email(), |
|
| 200 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
| 201 | - $email->get_content( $merge_tags ), |
|
| 202 | - $email->get_attachments() |
|
| 203 | - ); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ( $result ) { |
|
| 207 | - $invoice->add_system_note( |
|
| 208 | - sprintf( |
|
| 209 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
| 210 | - __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
| 211 | - sanitize_key( $type ), |
|
| 212 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
| 213 | - ) |
|
| 214 | - ); |
|
| 215 | - } else { |
|
| 216 | - $invoice->add_system_note( |
|
| 217 | - sprintf( |
|
| 218 | - // translators: %1 is the email type, %2 is the invoice recipient. |
|
| 219 | - __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
| 220 | - sanitize_key( $type ), |
|
| 221 | - $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
| 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 | - return $recipients; |
|
| 255 | - |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Sends a new invoice notification. |
|
| 260 | - * |
|
| 261 | - * @param WPInv_Invoice $invoice |
|
| 262 | - */ |
|
| 263 | - public function new_invoice( $invoice ) { |
|
| 264 | - |
|
| 265 | - // Only send this email for invoices created via the admin page. |
|
| 266 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
| 267 | - return; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 271 | - $recipient = wpinv_get_admin_email(); |
|
| 272 | - |
|
| 273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 274 | - |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Sends a cancelled invoice notification. |
|
| 279 | - * |
|
| 280 | - * @param WPInv_Invoice $invoice |
|
| 281 | - */ |
|
| 282 | - public function cancelled_invoice( $invoice ) { |
|
| 283 | - |
|
| 284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 285 | - $recipient = $invoice->get_email(); |
|
| 286 | - |
|
| 287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Sends a failed invoice notification. |
|
| 292 | - * |
|
| 293 | - * @param WPInv_Invoice $invoice |
|
| 294 | - */ |
|
| 295 | - public function failed_invoice( $invoice ) { |
|
| 296 | - |
|
| 297 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 298 | - $recipient = wpinv_get_admin_email(); |
|
| 299 | - |
|
| 300 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 301 | - |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Sends a notification whenever an invoice is put on hold. |
|
| 306 | - * |
|
| 307 | - * @param WPInv_Invoice $invoice |
|
| 308 | - */ |
|
| 309 | - public function onhold_invoice( $invoice ) { |
|
| 310 | - |
|
| 311 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 312 | - $recipient = $invoice->get_email(); |
|
| 313 | - |
|
| 314 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 315 | - |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
| 320 | - * |
|
| 321 | - * @param WPInv_Invoice $invoice |
|
| 322 | - */ |
|
| 323 | - public function processing_invoice( $invoice ) { |
|
| 15 | + /** |
|
| 16 | + * The array of invoice email actions. |
|
| 17 | + * |
|
| 18 | + * @param array |
|
| 19 | + */ |
|
| 20 | + public $invoice_actions; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Class constructor |
|
| 24 | + * |
|
| 25 | + */ |
|
| 26 | + public function __construct() { |
|
| 27 | + |
|
| 28 | + $this->invoice_actions = apply_filters( |
|
| 29 | + 'getpaid_notification_email_invoice_triggers', |
|
| 30 | + array( |
|
| 31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
| 32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
| 33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
| 34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
| 35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
| 36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
| 37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
| 38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
| 39 | + 'getpaid_new_customer_note' => 'user_note', |
|
| 40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
| 41 | + ) |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + $this->init_hooks(); |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Registers email hooks. |
|
| 50 | + */ |
|
| 51 | + public function init_hooks() { |
|
| 52 | + |
|
| 53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
| 54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
| 55 | + |
|
| 56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
| 57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Registers an email hook for an invoice action. |
|
| 63 | + * |
|
| 64 | + * @param string $hook |
|
| 65 | + * @param string|array $email_type |
|
| 66 | + */ |
|
| 67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
| 68 | + |
|
| 69 | + $email_type = wpinv_parse_list( $email_type ); |
|
| 70 | + |
|
| 71 | + foreach ( $email_type as $type ) { |
|
| 72 | + |
|
| 73 | + $email = new GetPaid_Notification_Email( $type ); |
|
| 74 | + |
|
| 75 | + // Abort if it is not active. |
|
| 76 | + if ( ! $email->is_active() ) { |
|
| 77 | + continue; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if ( method_exists( $this, $type ) ) { |
|
| 81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type, $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 ) ) { |
|
| 324 | 153 | |
| 325 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 326 | - $recipient = $invoice->get_email(); |
|
| 327 | - |
|
| 328 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 329 | - |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Sends a notification whenever an invoice is paid. |
|
| 334 | - * |
|
| 335 | - * @param WPInv_Invoice $invoice |
|
| 336 | - */ |
|
| 337 | - public function completed_invoice( $invoice ) { |
|
| 154 | + foreach ( $payment_form_data as $label => $value ) { |
|
| 338 | 155 | |
| 339 | - // (Maybe) abort if it is a renewal invoice. |
|
| 340 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
| 341 | - return; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 345 | - $recipient = $invoice->get_email(); |
|
| 156 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
| 157 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
| 346 | 158 | |
| 347 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 159 | + if ( is_scalar( $value ) ) { |
|
| 160 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 348 | 164 | |
| 349 | - } |
|
| 165 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
| 166 | + } |
|
| 350 | 167 | |
| 351 | - /** |
|
| 352 | - * Sends a notification whenever an invoice is refunded. |
|
| 353 | - * |
|
| 354 | - * @param WPInv_Invoice $invoice |
|
| 355 | - */ |
|
| 356 | - public function refunded_invoice( $invoice ) { |
|
| 168 | + /** |
|
| 169 | + * Helper function to send an email. |
|
| 170 | + * |
|
| 171 | + * @param WPInv_Invoice $invoice |
|
| 172 | + * @param GetPaid_Notification_Email $email |
|
| 173 | + * @param string $type |
|
| 174 | + * @param string|array $recipients |
|
| 175 | + * @param array $extra_args Extra template args. |
|
| 176 | + */ |
|
| 177 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
| 357 | 178 | |
| 358 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 359 | - $recipient = $invoice->get_email(); |
|
| 360 | - |
|
| 361 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 179 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
| 180 | + |
|
| 181 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
| 182 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
| 183 | + return; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
| 187 | + $merge_tags = $email->get_merge_tags(); |
|
| 188 | + |
|
| 189 | + $result = $mailer->send( |
|
| 190 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
| 191 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
| 192 | + $email->get_content( $merge_tags, $extra_args ), |
|
| 193 | + $email->get_attachments() |
|
| 194 | + ); |
|
| 362 | 195 | |
| 363 | - } |
|
| 196 | + // Maybe send a copy to the admin. |
|
| 197 | + if ( $email->include_admin_bcc() ) { |
|
| 198 | + $mailer->send( |
|
| 199 | + wpinv_get_admin_email(), |
|
| 200 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
| 201 | + $email->get_content( $merge_tags ), |
|
| 202 | + $email->get_attachments() |
|
| 203 | + ); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ( $result ) { |
|
| 207 | + $invoice->add_system_note( |
|
| 208 | + sprintf( |
|
| 209 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
| 210 | + __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ), |
|
| 211 | + sanitize_key( $type ), |
|
| 212 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
| 213 | + ) |
|
| 214 | + ); |
|
| 215 | + } else { |
|
| 216 | + $invoice->add_system_note( |
|
| 217 | + sprintf( |
|
| 218 | + // translators: %1 is the email type, %2 is the invoice recipient. |
|
| 219 | + __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ), |
|
| 220 | + sanitize_key( $type ), |
|
| 221 | + $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' ) |
|
| 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 | + return $recipients; |
|
| 255 | + |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Sends a new invoice notification. |
|
| 260 | + * |
|
| 261 | + * @param WPInv_Invoice $invoice |
|
| 262 | + */ |
|
| 263 | + public function new_invoice( $invoice ) { |
|
| 264 | + |
|
| 265 | + // Only send this email for invoices created via the admin page. |
|
| 266 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
| 267 | + return; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 271 | + $recipient = wpinv_get_admin_email(); |
|
| 272 | + |
|
| 273 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 274 | + |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Sends a cancelled invoice notification. |
|
| 279 | + * |
|
| 280 | + * @param WPInv_Invoice $invoice |
|
| 281 | + */ |
|
| 282 | + public function cancelled_invoice( $invoice ) { |
|
| 283 | + |
|
| 284 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 285 | + $recipient = $invoice->get_email(); |
|
| 286 | + |
|
| 287 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Sends a failed invoice notification. |
|
| 292 | + * |
|
| 293 | + * @param WPInv_Invoice $invoice |
|
| 294 | + */ |
|
| 295 | + public function failed_invoice( $invoice ) { |
|
| 296 | + |
|
| 297 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 298 | + $recipient = wpinv_get_admin_email(); |
|
| 299 | + |
|
| 300 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 301 | + |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Sends a notification whenever an invoice is put on hold. |
|
| 306 | + * |
|
| 307 | + * @param WPInv_Invoice $invoice |
|
| 308 | + */ |
|
| 309 | + public function onhold_invoice( $invoice ) { |
|
| 310 | + |
|
| 311 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 312 | + $recipient = $invoice->get_email(); |
|
| 313 | + |
|
| 314 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 315 | + |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
| 320 | + * |
|
| 321 | + * @param WPInv_Invoice $invoice |
|
| 322 | + */ |
|
| 323 | + public function processing_invoice( $invoice ) { |
|
| 364 | 324 | |
| 365 | - /** |
|
| 366 | - * Notifies a user about new invoices |
|
| 367 | - * |
|
| 368 | - * @param WPInv_Invoice $invoice |
|
| 369 | - * @param bool $force |
|
| 370 | - */ |
|
| 371 | - public function user_invoice( $invoice, $force = false ) { |
|
| 325 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 326 | + $recipient = $invoice->get_email(); |
|
| 327 | + |
|
| 328 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 329 | + |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Sends a notification whenever an invoice is paid. |
|
| 334 | + * |
|
| 335 | + * @param WPInv_Invoice $invoice |
|
| 336 | + */ |
|
| 337 | + public function completed_invoice( $invoice ) { |
|
| 372 | 338 | |
| 373 | - if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
| 374 | - return; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - // Only send this email for invoices created via the admin page. |
|
| 378 | - if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
| 379 | - return; |
|
| 380 | - } |
|
| 339 | + // (Maybe) abort if it is a renewal invoice. |
|
| 340 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
| 341 | + return; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 345 | + $recipient = $invoice->get_email(); |
|
| 381 | 346 | |
| 382 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 383 | - $recipient = $invoice->get_email(); |
|
| 384 | - |
|
| 385 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 347 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 386 | 348 | |
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Checks if an invoice is a payment form invoice. |
|
| 391 | - * |
|
| 392 | - * @param int $invoice |
|
| 393 | - * @return bool |
|
| 394 | - */ |
|
| 395 | - public function is_payment_form_invoice( $invoice ) { |
|
| 396 | - $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 ) ); |
|
| 397 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
| 398 | - } |
|
| 349 | + } |
|
| 399 | 350 | |
| 400 | - /** |
|
| 401 | - * Notifies admin about new invoice notes |
|
| 402 | - * |
|
| 403 | - * @param WPInv_Invoice $invoice |
|
| 404 | - * @param string $note |
|
| 405 | - */ |
|
| 406 | - public function user_note( $invoice, $note ) { |
|
| 407 | - |
|
| 408 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 409 | - $recipient = $invoice->get_email(); |
|
| 351 | + /** |
|
| 352 | + * Sends a notification whenever an invoice is refunded. |
|
| 353 | + * |
|
| 354 | + * @param WPInv_Invoice $invoice |
|
| 355 | + */ |
|
| 356 | + public function refunded_invoice( $invoice ) { |
|
| 410 | 357 | |
| 411 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
| 412 | - |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * (Force) Sends overdue notices. |
|
| 417 | - * |
|
| 418 | - * @param WPInv_Invoice $invoice |
|
| 419 | - */ |
|
| 420 | - public function force_send_overdue_notice( $invoice ) { |
|
| 421 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
| 422 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Sends overdue notices. |
|
| 427 | - * |
|
| 428 | - * @TODO: Create an invoices query class. |
|
| 429 | - */ |
|
| 430 | - public function overdue() { |
|
| 431 | - global $wpdb; |
|
| 432 | - |
|
| 433 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 434 | - |
|
| 435 | - // Fetch reminder days. |
|
| 436 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 437 | - |
|
| 438 | - // Abort if non is set. |
|
| 439 | - if ( empty( $reminder_days ) ) { |
|
| 440 | - return; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - // Retrieve date query. |
|
| 444 | - $date_query = $this->get_date_query( $reminder_days ); |
|
| 445 | - |
|
| 446 | - // Invoices table. |
|
| 447 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 448 | - |
|
| 449 | - // Fetch invoices. |
|
| 450 | - $invoices = $wpdb->get_col( |
|
| 451 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
| 358 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 359 | + $recipient = $invoice->get_email(); |
|
| 360 | + |
|
| 361 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 362 | + |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Notifies a user about new invoices |
|
| 367 | + * |
|
| 368 | + * @param WPInv_Invoice $invoice |
|
| 369 | + * @param bool $force |
|
| 370 | + */ |
|
| 371 | + public function user_invoice( $invoice, $force = false ) { |
|
| 372 | + |
|
| 373 | + if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
| 374 | + return; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + // Only send this email for invoices created via the admin page. |
|
| 378 | + if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
| 379 | + return; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 383 | + $recipient = $invoice->get_email(); |
|
| 384 | + |
|
| 385 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
| 386 | + |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Checks if an invoice is a payment form invoice. |
|
| 391 | + * |
|
| 392 | + * @param int $invoice |
|
| 393 | + * @return bool |
|
| 394 | + */ |
|
| 395 | + public function is_payment_form_invoice( $invoice ) { |
|
| 396 | + $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 ) ); |
|
| 397 | + return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * Notifies admin about new invoice notes |
|
| 402 | + * |
|
| 403 | + * @param WPInv_Invoice $invoice |
|
| 404 | + * @param string $note |
|
| 405 | + */ |
|
| 406 | + public function user_note( $invoice, $note ) { |
|
| 407 | + |
|
| 408 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
| 409 | + $recipient = $invoice->get_email(); |
|
| 410 | + |
|
| 411 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
| 412 | + |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * (Force) Sends overdue notices. |
|
| 417 | + * |
|
| 418 | + * @param WPInv_Invoice $invoice |
|
| 419 | + */ |
|
| 420 | + public function force_send_overdue_notice( $invoice ) { |
|
| 421 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
| 422 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Sends overdue notices. |
|
| 427 | + * |
|
| 428 | + * @TODO: Create an invoices query class. |
|
| 429 | + */ |
|
| 430 | + public function overdue() { |
|
| 431 | + global $wpdb; |
|
| 432 | + |
|
| 433 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
| 434 | + |
|
| 435 | + // Fetch reminder days. |
|
| 436 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
| 437 | + |
|
| 438 | + // Abort if non is set. |
|
| 439 | + if ( empty( $reminder_days ) ) { |
|
| 440 | + return; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + // Retrieve date query. |
|
| 444 | + $date_query = $this->get_date_query( $reminder_days ); |
|
| 445 | + |
|
| 446 | + // Invoices table. |
|
| 447 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
| 448 | + |
|
| 449 | + // Fetch invoices. |
|
| 450 | + $invoices = $wpdb->get_col( |
|
| 451 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
| 452 | 452 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
| 453 | 453 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query" |
| 454 | 454 | ); |
| 455 | 455 | |
| 456 | - foreach ( $invoices as $invoice ) { |
|
| 456 | + foreach ( $invoices as $invoice ) { |
|
| 457 | 457 | |
| 458 | - // Only send this email for invoices created via the admin page. |
|
| 459 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
| 460 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 461 | - $email->object = $invoice; |
|
| 458 | + // Only send this email for invoices created via the admin page. |
|
| 459 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
| 460 | + $invoice = new WPInv_Invoice( $invoice ); |
|
| 461 | + $email->object = $invoice; |
|
| 462 | 462 | |
| 463 | - if ( $invoice->needs_payment() ) { |
|
| 464 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
| 465 | - } |
|
| 463 | + if ( $invoice->needs_payment() ) { |
|
| 464 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - } |
|
| 469 | + } |
|
| 470 | 470 | |
| 471 | - /** |
|
| 472 | - * Calculates the date query for an invoices query |
|
| 473 | - * |
|
| 474 | - * @param array $reminder_days |
|
| 475 | - * @return string |
|
| 476 | - */ |
|
| 477 | - public function get_date_query( $reminder_days ) { |
|
| 471 | + /** |
|
| 472 | + * Calculates the date query for an invoices query |
|
| 473 | + * |
|
| 474 | + * @param array $reminder_days |
|
| 475 | + * @return string |
|
| 476 | + */ |
|
| 477 | + public function get_date_query( $reminder_days ) { |
|
| 478 | 478 | |
| 479 | - $date_query = array( |
|
| 480 | - 'relation' => 'OR', |
|
| 481 | - ); |
|
| 479 | + $date_query = array( |
|
| 480 | + 'relation' => 'OR', |
|
| 481 | + ); |
|
| 482 | 482 | |
| 483 | - foreach ( $reminder_days as $days ) { |
|
| 484 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
| 483 | + foreach ( $reminder_days as $days ) { |
|
| 484 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
| 485 | 485 | |
| 486 | - $date_query[] = array( |
|
| 487 | - 'year' => $date['year'], |
|
| 488 | - 'month' => $date['month'], |
|
| 489 | - 'day' => $date['day'], |
|
| 490 | - ); |
|
| 486 | + $date_query[] = array( |
|
| 487 | + 'year' => $date['year'], |
|
| 488 | + 'month' => $date['month'], |
|
| 489 | + 'day' => $date['day'], |
|
| 490 | + ); |
|
| 491 | 491 | |
| 492 | - } |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
| 494 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
| 495 | 495 | |
| 496 | - return $date_query->get_sql(); |
|
| 496 | + return $date_query->get_sql(); |
|
| 497 | 497 | |
| 498 | - } |
|
| 498 | + } |
|
| 499 | 499 | |
| 500 | 500 | } |
@@ -12,47 +12,47 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Reports_Export { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Displays the reports tab. |
|
| 17 | - * |
|
| 18 | - */ |
|
| 19 | - public function display() { |
|
| 20 | - |
|
| 21 | - echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
| 22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 23 | - $this->display_post_type_export( $post_type ); |
|
| 24 | - } |
|
| 25 | - $this->display_subscription_export(); |
|
| 26 | - echo '</div>'; |
|
| 27 | - |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Retrieves the download url. |
|
| 32 | - * |
|
| 33 | - */ |
|
| 34 | - public function get_download_url( $post_type ) { |
|
| 35 | - |
|
| 36 | - return wp_nonce_url( |
|
| 37 | - add_query_arg( |
|
| 38 | - array( |
|
| 39 | - 'getpaid-admin-action' => 'export_invoices', |
|
| 40 | - 'post_type' => urlencode( $post_type ), |
|
| 41 | - ) |
|
| 42 | - ), |
|
| 43 | - 'getpaid-nonce', |
|
| 44 | - 'getpaid-nonce' |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Displays a single post type export card. |
|
| 51 | - * |
|
| 52 | - */ |
|
| 53 | - public function display_post_type_export( $post_type ) { |
|
| 54 | - |
|
| 55 | - ?> |
|
| 15 | + /** |
|
| 16 | + * Displays the reports tab. |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | + public function display() { |
|
| 20 | + |
|
| 21 | + echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
| 22 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 23 | + $this->display_post_type_export( $post_type ); |
|
| 24 | + } |
|
| 25 | + $this->display_subscription_export(); |
|
| 26 | + echo '</div>'; |
|
| 27 | + |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Retrieves the download url. |
|
| 32 | + * |
|
| 33 | + */ |
|
| 34 | + public function get_download_url( $post_type ) { |
|
| 35 | + |
|
| 36 | + return wp_nonce_url( |
|
| 37 | + add_query_arg( |
|
| 38 | + array( |
|
| 39 | + 'getpaid-admin-action' => 'export_invoices', |
|
| 40 | + 'post_type' => urlencode( $post_type ), |
|
| 41 | + ) |
|
| 42 | + ), |
|
| 43 | + 'getpaid-nonce', |
|
| 44 | + 'getpaid-nonce' |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Displays a single post type export card. |
|
| 51 | + * |
|
| 52 | + */ |
|
| 53 | + public function display_post_type_export( $post_type ) { |
|
| 54 | + |
|
| 55 | + ?> |
|
| 56 | 56 | |
| 57 | 57 | <div class="col-12 col-md-6"> |
| 58 | 58 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | <div class="card-header"> |
| 61 | 61 | <strong> |
| 62 | 62 | <?php |
| 63 | - printf( |
|
| 64 | - esc_html__( 'Export %s', 'invoicing' ), |
|
| 65 | - esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
| 66 | - ); |
|
| 67 | - ?> |
|
| 63 | + printf( |
|
| 64 | + esc_html__( 'Export %s', 'invoicing' ), |
|
| 65 | + esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
| 66 | + ); |
|
| 67 | + ?> |
|
| 68 | 68 | </strong> |
| 69 | 69 | </div> |
| 70 | 70 | |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
| 74 | 74 | |
| 75 | 75 | <?php |
| 76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
| 77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
| 78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
| 79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
| 80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
| 81 | - ?> |
|
| 76 | + $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
| 77 | + $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
| 78 | + $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
| 79 | + $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
| 80 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
| 81 | + ?> |
|
| 82 | 82 | |
| 83 | 83 | </form> |
| 84 | 84 | |
@@ -89,128 +89,128 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | <?php |
| 91 | 91 | |
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Generates the from date input field. |
|
| 96 | - * |
|
| 97 | - */ |
|
| 98 | - public function generate_from_date( $post_type ) { |
|
| 99 | - |
|
| 100 | - return aui()->input( |
|
| 101 | - array( |
|
| 102 | - 'type' => 'datepicker', |
|
| 103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
| 104 | - 'name' => 'from_date', |
|
| 105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
| 106 | - 'placeholder' => 'YYYY-MM-DD', |
|
| 107 | - 'extra_attributes' => array( |
|
| 108 | - 'data-enable-time' => 'false', |
|
| 109 | - 'data-allow-input' => 'true', |
|
| 110 | - ), |
|
| 111 | - ), |
|
| 112 | - false |
|
| 113 | - ); |
|
| 114 | - |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Generates the to date input field. |
|
| 119 | - * |
|
| 120 | - */ |
|
| 121 | - public function generate_to_date( $post_type ) { |
|
| 122 | - |
|
| 123 | - return aui()->input( |
|
| 124 | - array( |
|
| 125 | - 'name' => 'to_date', |
|
| 126 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
| 127 | - 'placeholder' => 'yy-mm-dd', |
|
| 128 | - 'label' => __( 'To Date', 'invoicing' ), |
|
| 129 | - 'label_type' => 'vertical', |
|
| 130 | - 'label_class' => 'd-block', |
|
| 131 | - 'type' => 'datepicker', |
|
| 132 | - ) |
|
| 133 | - ); |
|
| 134 | - |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Generates the to post status select field. |
|
| 139 | - * |
|
| 140 | - */ |
|
| 141 | - public function generate_post_status_select( $post_type ) { |
|
| 142 | - |
|
| 143 | - if ( 'subscriptions' === $post_type ) { |
|
| 144 | - $options = getpaid_get_subscription_statuses(); |
|
| 145 | - } else { |
|
| 146 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return aui()->select( |
|
| 150 | - array( |
|
| 151 | - 'name' => 'status', |
|
| 152 | - 'id' => esc_attr( "$post_type-status" ), |
|
| 153 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
| 154 | - 'label' => __( 'Status', 'invoicing' ), |
|
| 155 | - 'label_type' => 'vertical', |
|
| 156 | - 'label_class' => 'd-block', |
|
| 157 | - 'options' => $options, |
|
| 158 | - ) |
|
| 159 | - ); |
|
| 160 | - |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Generates the to file type select field. |
|
| 165 | - * |
|
| 166 | - */ |
|
| 167 | - public function generate_file_type_select( $post_type ) { |
|
| 168 | - |
|
| 169 | - return aui()->select( |
|
| 170 | - array( |
|
| 171 | - 'name' => 'file_type', |
|
| 172 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
| 173 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
| 174 | - 'label' => __( 'Export File', 'invoicing' ), |
|
| 175 | - 'label_type' => 'vertical', |
|
| 176 | - 'label_class' => 'd-block', |
|
| 177 | - 'options' => array( |
|
| 178 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
| 179 | - 'xml' => __( 'XML', 'invoicing' ), |
|
| 180 | - 'json' => __( 'JSON', 'invoicing' ), |
|
| 181 | - ), |
|
| 182 | - ) |
|
| 183 | - ); |
|
| 184 | - |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Displays a field's markup. |
|
| 189 | - * |
|
| 190 | - */ |
|
| 191 | - public function display_markup( $markup ) { |
|
| 192 | - |
|
| 193 | - echo wp_kses( |
|
| 194 | - str_replace( |
|
| 195 | - array( |
|
| 196 | - 'form-control', |
|
| 197 | - 'custom-select', |
|
| 198 | - ), |
|
| 199 | - 'regular-text', |
|
| 200 | - $markup |
|
| 201 | - ), |
|
| 202 | - getpaid_allowed_html() |
|
| 203 | - ); |
|
| 204 | - |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Displays a subscription export card. |
|
| 209 | - * |
|
| 210 | - */ |
|
| 211 | - public function display_subscription_export() { |
|
| 212 | - |
|
| 213 | - ?> |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Generates the from date input field. |
|
| 96 | + * |
|
| 97 | + */ |
|
| 98 | + public function generate_from_date( $post_type ) { |
|
| 99 | + |
|
| 100 | + return aui()->input( |
|
| 101 | + array( |
|
| 102 | + 'type' => 'datepicker', |
|
| 103 | + 'id' => esc_attr( "$post_type-from_date" ), |
|
| 104 | + 'name' => 'from_date', |
|
| 105 | + 'label' => __( 'From Date', 'invoicing' ), |
|
| 106 | + 'placeholder' => 'YYYY-MM-DD', |
|
| 107 | + 'extra_attributes' => array( |
|
| 108 | + 'data-enable-time' => 'false', |
|
| 109 | + 'data-allow-input' => 'true', |
|
| 110 | + ), |
|
| 111 | + ), |
|
| 112 | + false |
|
| 113 | + ); |
|
| 114 | + |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Generates the to date input field. |
|
| 119 | + * |
|
| 120 | + */ |
|
| 121 | + public function generate_to_date( $post_type ) { |
|
| 122 | + |
|
| 123 | + return aui()->input( |
|
| 124 | + array( |
|
| 125 | + 'name' => 'to_date', |
|
| 126 | + 'id' => esc_attr( "$post_type-to_date" ), |
|
| 127 | + 'placeholder' => 'yy-mm-dd', |
|
| 128 | + 'label' => __( 'To Date', 'invoicing' ), |
|
| 129 | + 'label_type' => 'vertical', |
|
| 130 | + 'label_class' => 'd-block', |
|
| 131 | + 'type' => 'datepicker', |
|
| 132 | + ) |
|
| 133 | + ); |
|
| 134 | + |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Generates the to post status select field. |
|
| 139 | + * |
|
| 140 | + */ |
|
| 141 | + public function generate_post_status_select( $post_type ) { |
|
| 142 | + |
|
| 143 | + if ( 'subscriptions' === $post_type ) { |
|
| 144 | + $options = getpaid_get_subscription_statuses(); |
|
| 145 | + } else { |
|
| 146 | + $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return aui()->select( |
|
| 150 | + array( |
|
| 151 | + 'name' => 'status', |
|
| 152 | + 'id' => esc_attr( "$post_type-status" ), |
|
| 153 | + 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
| 154 | + 'label' => __( 'Status', 'invoicing' ), |
|
| 155 | + 'label_type' => 'vertical', |
|
| 156 | + 'label_class' => 'd-block', |
|
| 157 | + 'options' => $options, |
|
| 158 | + ) |
|
| 159 | + ); |
|
| 160 | + |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Generates the to file type select field. |
|
| 165 | + * |
|
| 166 | + */ |
|
| 167 | + public function generate_file_type_select( $post_type ) { |
|
| 168 | + |
|
| 169 | + return aui()->select( |
|
| 170 | + array( |
|
| 171 | + 'name' => 'file_type', |
|
| 172 | + 'id' => esc_attr( "$post_type-file_type" ), |
|
| 173 | + 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
| 174 | + 'label' => __( 'Export File', 'invoicing' ), |
|
| 175 | + 'label_type' => 'vertical', |
|
| 176 | + 'label_class' => 'd-block', |
|
| 177 | + 'options' => array( |
|
| 178 | + 'csv' => __( 'CSV', 'invoicing' ), |
|
| 179 | + 'xml' => __( 'XML', 'invoicing' ), |
|
| 180 | + 'json' => __( 'JSON', 'invoicing' ), |
|
| 181 | + ), |
|
| 182 | + ) |
|
| 183 | + ); |
|
| 184 | + |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Displays a field's markup. |
|
| 189 | + * |
|
| 190 | + */ |
|
| 191 | + public function display_markup( $markup ) { |
|
| 192 | + |
|
| 193 | + echo wp_kses( |
|
| 194 | + str_replace( |
|
| 195 | + array( |
|
| 196 | + 'form-control', |
|
| 197 | + 'custom-select', |
|
| 198 | + ), |
|
| 199 | + 'regular-text', |
|
| 200 | + $markup |
|
| 201 | + ), |
|
| 202 | + getpaid_allowed_html() |
|
| 203 | + ); |
|
| 204 | + |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Displays a subscription export card. |
|
| 209 | + * |
|
| 210 | + */ |
|
| 211 | + public function display_subscription_export() { |
|
| 212 | + |
|
| 213 | + ?> |
|
| 214 | 214 | |
| 215 | 215 | <div class="col-12 col-md-6"> |
| 216 | 216 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -226,12 +226,12 @@ discard block |
||
| 226 | 226 | <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
| 227 | 227 | |
| 228 | 228 | <?php |
| 229 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
| 230 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
| 231 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
| 232 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
| 233 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
| 234 | - ?> |
|
| 229 | + $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
| 230 | + $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
| 231 | + $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
| 232 | + $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
| 233 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
| 234 | + ?> |
|
| 235 | 235 | |
| 236 | 236 | </form> |
| 237 | 237 | |
@@ -242,6 +242,6 @@ discard block |
||
| 242 | 242 | |
| 243 | 243 | <?php |
| 244 | 244 | |
| 245 | - } |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | 247 | } |
@@ -13,17 +13,17 @@ discard block |
||
| 13 | 13 | class GetPaid_Notification_Email_Sender { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Whether or not we should inline CSS into the email. |
|
| 17 | - */ |
|
| 18 | - public $inline_css = true; |
|
| 16 | + * Whether or not we should inline CSS into the email. |
|
| 17 | + */ |
|
| 18 | + public $inline_css = true; |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | - * The wp_mail() data. |
|
| 22 | - */ |
|
| 21 | + * The wp_mail() data. |
|
| 22 | + */ |
|
| 23 | 23 | public $wp_mail_data = null; |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * Sends a new email. |
|
| 26 | + * Sends a new email. |
|
| 27 | 27 | * |
| 28 | 28 | * @param string|array $to The recipients email or an array of recipient emails. |
| 29 | 29 | * @param string $subject The email's subject. |
@@ -31,49 +31,49 @@ discard block |
||
| 31 | 31 | * @param array $attachments The email attachments. |
| 32 | 32 | * |
| 33 | 33 | * @return bool |
| 34 | - */ |
|
| 35 | - public function send( $to, $subject, $email, $attachments = array() ) { |
|
| 34 | + */ |
|
| 35 | + public function send( $to, $subject, $email, $attachments = array() ) { |
|
| 36 | 36 | |
| 37 | - /* |
|
| 37 | + /* |
|
| 38 | 38 | * Allow to filter data on per-email basis. |
| 39 | 39 | */ |
| 40 | - $data = apply_filters( |
|
| 41 | - 'getpaid_email_data', |
|
| 42 | - array( |
|
| 43 | - 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
| 44 | - 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
| 45 | - 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
| 46 | - 'headers' => $this->get_headers(), |
|
| 47 | - 'attachments' => $attachments, |
|
| 48 | - ), |
|
| 49 | - $this |
|
| 50 | - ); |
|
| 40 | + $data = apply_filters( |
|
| 41 | + 'getpaid_email_data', |
|
| 42 | + array( |
|
| 43 | + 'to' => array_filter( array_unique( wpinv_parse_list( $to ) ) ), |
|
| 44 | + 'subject' => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ), |
|
| 45 | + 'email' => apply_filters( 'wpinv_mail_content', $email ), |
|
| 46 | + 'headers' => $this->get_headers(), |
|
| 47 | + 'attachments' => $attachments, |
|
| 48 | + ), |
|
| 49 | + $this |
|
| 50 | + ); |
|
| 51 | 51 | |
| 52 | 52 | // Remove slashes. |
| 53 | 53 | $data = (array) wp_unslash( $data ); |
| 54 | 54 | |
| 55 | 55 | // Cache it. |
| 56 | - $this->wp_mail_data = $data; |
|
| 56 | + $this->wp_mail_data = $data; |
|
| 57 | 57 | |
| 58 | - // Attach our own hooks. |
|
| 59 | - $this->before_sending(); |
|
| 58 | + // Attach our own hooks. |
|
| 59 | + $this->before_sending(); |
|
| 60 | 60 | |
| 61 | 61 | $result = false; |
| 62 | 62 | |
| 63 | 63 | foreach ( $this->wp_mail_data['to'] as $to ) { |
| 64 | - $result = $this->_send( $to, $data ); |
|
| 64 | + $result = $this->_send( $to, $data ); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - // Remove our hooks. |
|
| 68 | - $this->after_sending(); |
|
| 67 | + // Remove our hooks. |
|
| 68 | + $this->after_sending(); |
|
| 69 | 69 | |
| 70 | - $this->wp_mail_data = null; |
|
| 70 | + $this->wp_mail_data = null; |
|
| 71 | 71 | |
| 72 | - return $result; |
|
| 73 | - } |
|
| 72 | + return $result; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Does the actual sending. |
|
| 75 | + /** |
|
| 76 | + * Does the actual sending. |
|
| 77 | 77 | * |
| 78 | 78 | * @param string $to The recipient's email. |
| 79 | 79 | * @param array $data The email's data. |
@@ -81,81 +81,81 @@ discard block |
||
| 81 | 81 | * @param array $attachments The email attachments. |
| 82 | 82 | * |
| 83 | 83 | * @return bool |
| 84 | - */ |
|
| 85 | - protected function _send( $to, $data ) { |
|
| 86 | - |
|
| 87 | - // Prepare the sending function. |
|
| 88 | - $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
| 89 | - |
|
| 90 | - // Send the actual email. |
|
| 91 | - $result = call_user_func( |
|
| 92 | - $sending_function, |
|
| 93 | - $to, |
|
| 94 | - html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
| 95 | - $data['email'], |
|
| 96 | - $data['headers'], |
|
| 97 | - $data['attachments'] |
|
| 98 | - ); |
|
| 99 | - |
|
| 100 | - if ( ! $result ) { |
|
| 101 | - $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
| 102 | - wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $result; |
|
| 106 | - } |
|
| 84 | + */ |
|
| 85 | + protected function _send( $to, $data ) { |
|
| 86 | + |
|
| 87 | + // Prepare the sending function. |
|
| 88 | + $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' ); |
|
| 89 | + |
|
| 90 | + // Send the actual email. |
|
| 91 | + $result = call_user_func( |
|
| 92 | + $sending_function, |
|
| 93 | + $to, |
|
| 94 | + html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ), |
|
| 95 | + $data['email'], |
|
| 96 | + $data['headers'], |
|
| 97 | + $data['attachments'] |
|
| 98 | + ); |
|
| 99 | + |
|
| 100 | + if ( ! $result ) { |
|
| 101 | + $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] ); |
|
| 102 | + wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $result; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | - * Retrieves email headers. |
|
| 110 | - */ |
|
| 111 | - public function get_headers() { |
|
| 109 | + * Retrieves email headers. |
|
| 110 | + */ |
|
| 111 | + public function get_headers() { |
|
| 112 | 112 | |
| 113 | - $name = $this->get_from_name(); |
|
| 114 | - $reply_to = $this->get_reply_to(); |
|
| 115 | - $headers = array( "Reply-To:$name <$reply_to>" ); |
|
| 113 | + $name = $this->get_from_name(); |
|
| 114 | + $reply_to = $this->get_reply_to(); |
|
| 115 | + $headers = array( "Reply-To:$name <$reply_to>" ); |
|
| 116 | 116 | |
| 117 | - return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
| 117 | + return apply_filters( 'getpaid_email_headers', $headers, $this ); |
|
| 118 | 118 | |
| 119 | - } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | /** |
| 122 | - * Fires before an email is sent |
|
| 123 | - * |
|
| 124 | - * @since 1.0.0 |
|
| 125 | - */ |
|
| 126 | - public function before_sending() { |
|
| 122 | + * Fires before an email is sent |
|
| 123 | + * |
|
| 124 | + * @since 1.0.0 |
|
| 125 | + */ |
|
| 126 | + public function before_sending() { |
|
| 127 | 127 | |
| 128 | 128 | do_action( 'getpaid_before_send_email', $this ); |
| 129 | - add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
| 130 | - add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
| 131 | - add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
| 132 | - add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
| 129 | + add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
| 130 | + add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
| 131 | + add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
| 132 | + add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
| 133 | 133 | |
| 134 | - } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | - * Returns the from name. |
|
| 138 | - */ |
|
| 139 | - public function get_from_name() { |
|
| 137 | + * Returns the from name. |
|
| 138 | + */ |
|
| 139 | + public function get_from_name() { |
|
| 140 | 140 | |
| 141 | 141 | $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) ); |
| 142 | 142 | |
| 143 | - if ( empty( $from_name ) ) { |
|
| 144 | - $from_name = get_bloginfo( 'name' ); |
|
| 143 | + if ( empty( $from_name ) ) { |
|
| 144 | + $from_name = get_bloginfo( 'name' ); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
| 147 | + return wp_specialchars_decode( $from_name, ENT_QUOTES ); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | - * Returns the from email. |
|
| 152 | - */ |
|
| 153 | - public function get_from_address() { |
|
| 151 | + * Returns the from email. |
|
| 152 | + */ |
|
| 153 | + public function get_from_address() { |
|
| 154 | 154 | |
| 155 | 155 | $from_address = wpinv_get_option( 'email_from', $this->default_from_address() ); |
| 156 | 156 | |
| 157 | - if ( ! is_email( $from_address ) ) { |
|
| 158 | - $from_address = $this->default_from_address(); |
|
| 157 | + if ( ! is_email( $from_address ) ) { |
|
| 158 | + $from_address = $this->default_from_address(); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | return $from_address; |
@@ -163,75 +163,75 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
| 166 | - * The default emails from address. |
|
| 167 | - * |
|
| 168 | - * Defaults to wordpress@$sitename |
|
| 169 | - * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
| 170 | - * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
| 171 | - * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
| 172 | - * |
|
| 173 | - */ |
|
| 174 | - public function default_from_address() { |
|
| 175 | - |
|
| 176 | - // Get the site domain and get rid of www. |
|
| 177 | - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
| 178 | - if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
| 179 | - $sitename = substr( $sitename, 4 ); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - $from_email = 'wordpress@' . $sitename; |
|
| 183 | - |
|
| 184 | - return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
| 166 | + * The default emails from address. |
|
| 167 | + * |
|
| 168 | + * Defaults to wordpress@$sitename |
|
| 169 | + * Some hosts will block outgoing mail from this address if it doesn't exist, |
|
| 170 | + * but there's no easy alternative. Defaulting to admin_email might appear to be |
|
| 171 | + * another option, but some hosts may refuse to relay mail from an unknown domain. |
|
| 172 | + * |
|
| 173 | + */ |
|
| 174 | + public function default_from_address() { |
|
| 175 | + |
|
| 176 | + // Get the site domain and get rid of www. |
|
| 177 | + $sitename = strtolower( $_SERVER['SERVER_NAME'] ); |
|
| 178 | + if ( substr( $sitename, 0, 4 ) == 'www.' ) { |
|
| 179 | + $sitename = substr( $sitename, 4 ); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + $from_email = 'wordpress@' . $sitename; |
|
| 183 | + |
|
| 184 | + return apply_filters( 'getpaid_default_from_address', $from_email ); |
|
| 185 | 185 | |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
| 189 | - * Get the email reply-to. |
|
| 190 | - * |
|
| 191 | - * |
|
| 192 | - * @return string The email reply-to address. |
|
| 193 | - */ |
|
| 194 | - public function get_reply_to() { |
|
| 189 | + * Get the email reply-to. |
|
| 190 | + * |
|
| 191 | + * |
|
| 192 | + * @return string The email reply-to address. |
|
| 193 | + */ |
|
| 194 | + public function get_reply_to() { |
|
| 195 | 195 | |
| 196 | - $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
| 196 | + $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) ); |
|
| 197 | 197 | |
| 198 | - if ( ! is_email( $reply_to ) ) { |
|
| 199 | - $reply_to = get_option( 'admin_email' ); |
|
| 200 | - } |
|
| 198 | + if ( ! is_email( $reply_to ) ) { |
|
| 199 | + $reply_to = get_option( 'admin_email' ); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return $reply_to; |
|
| 202 | + return $reply_to; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
| 206 | - * Get the email content type. |
|
| 207 | - * |
|
| 208 | - */ |
|
| 209 | - public function get_content_type() { |
|
| 210 | - return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
| 206 | + * Get the email content type. |
|
| 207 | + * |
|
| 208 | + */ |
|
| 209 | + public function get_content_type() { |
|
| 210 | + return apply_filters( 'getpaid_email_content_type', 'text/html', $this ); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | - * Ensures that our email messages are not messed up by template plugins. |
|
| 215 | - * |
|
| 216 | - * @return array wp_mail_data. |
|
| 217 | - */ |
|
| 218 | - public function ensure_email_content( $args ) { |
|
| 219 | - $args['message'] = $this->wp_mail_data['email']; |
|
| 220 | - return $args; |
|
| 214 | + * Ensures that our email messages are not messed up by template plugins. |
|
| 215 | + * |
|
| 216 | + * @return array wp_mail_data. |
|
| 217 | + */ |
|
| 218 | + public function ensure_email_content( $args ) { |
|
| 219 | + $args['message'] = $this->wp_mail_data['email']; |
|
| 220 | + return $args; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
| 224 | - * A little house keeping after an email is sent. |
|
| 225 | - * |
|
| 226 | - */ |
|
| 227 | - public function after_sending() { |
|
| 224 | + * A little house keeping after an email is sent. |
|
| 225 | + * |
|
| 226 | + */ |
|
| 227 | + public function after_sending() { |
|
| 228 | 228 | |
| 229 | 229 | do_action( 'getpaid_after_send_email', $this->wp_mail_data ); |
| 230 | - remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
| 231 | - remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
| 232 | - remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
| 233 | - remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
| 230 | + remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 ); |
|
| 231 | + remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 ); |
|
| 232 | + remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 ); |
|
| 233 | + remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 ); |
|
| 234 | 234 | |
| 235 | - } |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | 237 | } |
@@ -12,184 +12,184 @@ 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 | - wp_send_json_error( __( '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 | + wp_send_json_error( __( '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 | + } |
|
| 133 | 117 | |
| 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 | - } |
|
| 118 | + /** |
|
| 119 | + * Retrieves submission invoice. |
|
| 120 | + * |
|
| 121 | + * @return WPInv_Invoice |
|
| 122 | + */ |
|
| 123 | + protected function get_submission_invoice() { |
|
| 124 | + $submission = $this->payment_form_submission; |
|
| 138 | 125 | |
| 139 | - return $invoice; |
|
| 140 | - } |
|
| 126 | + if ( ! $submission->has_invoice() ) { |
|
| 127 | + $invoice = new WPInv_Invoice(); |
|
| 128 | + $invoice->set_created_via( 'payment_form' ); |
|
| 129 | + return $invoice; |
|
| 130 | + } |
|
| 141 | 131 | |
| 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 ) { |
|
| 132 | + $invoice = $submission->get_invoice(); |
|
| 150 | 133 | |
| 151 | - $submission = $this->payment_form_submission; |
|
| 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 | + } |
|
| 152 | 138 | |
| 153 | - // Set-up the invoice details. |
|
| 154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 139 | + return $invoice; |
|
| 140 | + } |
|
| 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 ) { |
|
| 150 | + |
|
| 151 | + $submission = $this->payment_form_submission; |
|
| 152 | + |
|
| 153 | + // Set-up the invoice details. |
|
| 154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 157 | 157 | $invoice->set_items( $items ); |
| 158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
| 159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
| 160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
| 162 | - $invoice->set_currency( $submission->get_currency() ); |
|
| 160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
| 161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
| 162 | + $invoice->set_currency( $submission->get_currency() ); |
|
| 163 | 163 | |
| 164 | - if ( $submission->has_shipping() ) { |
|
| 165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
| 166 | - } |
|
| 164 | + if ( $submission->has_shipping() ) { |
|
| 165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 170 | 170 | |
| 171 | - if ( $submission->has_discount_code() ) { |
|
| 171 | + if ( $submission->has_discount_code() ) { |
|
| 172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
| 173 | - } |
|
| 174 | - |
|
| 175 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 176 | - return $invoice; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Retrieves the submission's customer. |
|
| 181 | - * |
|
| 182 | - * @return int The customer id. |
|
| 183 | - */ |
|
| 184 | - protected function get_submission_customer() { |
|
| 185 | - $submission = $this->payment_form_submission; |
|
| 186 | - |
|
| 187 | - // If this is an existing invoice... |
|
| 188 | - if ( $submission->has_invoice() ) { |
|
| 189 | - return $submission->get_invoice()->get_user_id(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // (Maybe) create the user. |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + getpaid_maybe_add_default_address( $invoice ); |
|
| 176 | + return $invoice; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Retrieves the submission's customer. |
|
| 181 | + * |
|
| 182 | + * @return int The customer id. |
|
| 183 | + */ |
|
| 184 | + protected function get_submission_customer() { |
|
| 185 | + $submission = $this->payment_form_submission; |
|
| 186 | + |
|
| 187 | + // If this is an existing invoice... |
|
| 188 | + if ( $submission->has_invoice() ) { |
|
| 189 | + return $submission->get_invoice()->get_user_id(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // (Maybe) create the user. |
|
| 193 | 193 | $user = get_current_user_id(); |
| 194 | 194 | |
| 195 | 195 | if ( empty( $user ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | if ( empty( $user ) ) { |
| 200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
| 201 | - $name = implode( '', array_filter( $name ) ); |
|
| 200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
| 201 | + $name = implode( '', array_filter( $name ) ); |
|
| 202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
| 203 | 203 | |
| 204 | - // (Maybe) send new user notification. |
|
| 205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
| 207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
| 208 | - } |
|
| 209 | - } |
|
| 204 | + // (Maybe) send new user notification. |
|
| 205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
| 207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | if ( is_wp_error( $user ) ) { |
| 212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | if ( is_numeric( $user ) ) { |
| 216 | 216 | return $user; |
| 217 | - } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - return $user->ID; |
|
| 219 | + return $user->ID; |
|
| 220 | 220 | |
| 221 | - } |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 223 | + /** |
|
| 224 | 224 | * Prepares submission data for saving to the database. |
| 225 | 225 | * |
| 226 | - * @return array |
|
| 226 | + * @return array |
|
| 227 | 227 | */ |
| 228 | 228 | public function prepare_submission_data_for_saving() { |
| 229 | 229 | |
| 230 | - $submission = $this->payment_form_submission; |
|
| 230 | + $submission = $this->payment_form_submission; |
|
| 231 | 231 | |
| 232 | - // Prepared submission details. |
|
| 232 | + // Prepared submission details. |
|
| 233 | 233 | $prepared = array( |
| 234 | - 'all' => array(), |
|
| 235 | - 'meta' => array(), |
|
| 236 | - ); |
|
| 234 | + 'all' => array(), |
|
| 235 | + 'meta' => array(), |
|
| 236 | + ); |
|
| 237 | 237 | |
| 238 | 238 | // Raw submission details. |
| 239 | - $data = $submission->get_data(); |
|
| 239 | + $data = $submission->get_data(); |
|
| 240 | 240 | |
| 241 | - // Loop through the submitted details. |
|
| 241 | + // Loop through the submitted details. |
|
| 242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
| 243 | 243 | |
| 244 | - // Skip premade fields. |
|
| 244 | + // Skip premade fields. |
|
| 245 | 245 | if ( ! empty( $field['premade'] ) ) { |
| 246 | 246 | continue; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - // Ensure address is provided. |
|
| 250 | - if ( $field['type'] == 'address' ) { |
|
| 249 | + // Ensure address is provided. |
|
| 250 | + if ( $field['type'] == 'address' ) { |
|
| 251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
| 252 | 252 | |
| 253 | - foreach ( $field['fields'] as $address_field ) { |
|
| 253 | + foreach ( $field['fields'] as $address_field ) { |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
| 256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - } |
|
| 255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
| 256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | 261 | // If it is required and not set, abort. |
| 262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
| 266 | 266 | // Handle misc fields. |
| 267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
| 268 | 268 | |
| 269 | - // Uploads. |
|
| 270 | - if ( $field['type'] == 'file_upload' ) { |
|
| 271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
| 269 | + // Uploads. |
|
| 270 | + if ( $field['type'] == 'file_upload' ) { |
|
| 271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
| 272 | 272 | |
| 273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
| 274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
| 275 | - } |
|
| 273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
| 274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - $value = array(); |
|
| 277 | + $value = array(); |
|
| 278 | 278 | |
| 279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
| 280 | - $value[] = sprintf( |
|
| 281 | - '<a href="%s" target="_blank">%s</a>', |
|
| 282 | - esc_url_raw( $url ), |
|
| 283 | - esc_html( $name ) |
|
| 284 | - ); |
|
| 285 | - } |
|
| 279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
| 280 | + $value[] = sprintf( |
|
| 281 | + '<a href="%s" target="_blank">%s</a>', |
|
| 282 | + esc_url_raw( $url ), |
|
| 283 | + esc_html( $name ) |
|
| 284 | + ); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - $value = implode( ' | ', $value ); |
|
| 287 | + $value = implode( ' | ', $value ); |
|
| 288 | 288 | |
| 289 | - } elseif ( $field['type'] == 'checkbox' ) { |
|
| 290 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
| 291 | - } else { |
|
| 292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
| 293 | - } |
|
| 289 | + } elseif ( $field['type'] == 'checkbox' ) { |
|
| 290 | + $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
| 291 | + } else { |
|
| 292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | 295 | $label = $field['id']; |
| 296 | 296 | |
@@ -298,188 +298,188 @@ discard block |
||
| 298 | 298 | $label = $field['label']; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
| 302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 303 | - } |
|
| 304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
| 302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 303 | + } |
|
| 304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 305 | 305 | |
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - return $prepared; |
|
| 309 | + return $prepared; |
|
| 310 | 310 | |
| 311 | - } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 313 | + /** |
|
| 314 | 314 | * Retrieves address details. |
| 315 | 315 | * |
| 316 | - * @return array |
|
| 317 | - * @param WPInv_Invoice $invoice |
|
| 318 | - * @param string $type |
|
| 316 | + * @return array |
|
| 317 | + * @param WPInv_Invoice $invoice |
|
| 318 | + * @param string $type |
|
| 319 | 319 | */ |
| 320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
| 321 | 321 | |
| 322 | - $data = $this->payment_form_submission->get_data(); |
|
| 323 | - $type = sanitize_key( $type ); |
|
| 324 | - $address = array(); |
|
| 325 | - $prepared = array(); |
|
| 322 | + $data = $this->payment_form_submission->get_data(); |
|
| 323 | + $type = sanitize_key( $type ); |
|
| 324 | + $address = array(); |
|
| 325 | + $prepared = array(); |
|
| 326 | 326 | |
| 327 | - if ( ! empty( $data[ $type ] ) ) { |
|
| 328 | - $address = $data[ $type ]; |
|
| 329 | - } |
|
| 327 | + if ( ! empty( $data[ $type ] ) ) { |
|
| 328 | + $address = $data[ $type ]; |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - // Clean address details. |
|
| 332 | - foreach ( $address as $key => $value ) { |
|
| 333 | - $key = sanitize_key( $key ); |
|
| 334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
| 335 | - $value = wpinv_clean( $value ); |
|
| 336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 337 | - } |
|
| 331 | + // Clean address details. |
|
| 332 | + foreach ( $address as $key => $value ) { |
|
| 333 | + $key = sanitize_key( $key ); |
|
| 334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
| 335 | + $value = wpinv_clean( $value ); |
|
| 336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - // Filter address details. |
|
| 340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 339 | + // Filter address details. |
|
| 340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 341 | 341 | |
| 342 | - // Remove non-whitelisted values. |
|
| 343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 342 | + // Remove non-whitelisted values. |
|
| 343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 344 | 344 | |
| 345 | - } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - /** |
|
| 347 | + /** |
|
| 348 | 348 | * Prepares the billing details. |
| 349 | 349 | * |
| 350 | - * @return array |
|
| 351 | - * @param WPInv_Invoice $invoice |
|
| 350 | + * @return array |
|
| 351 | + * @param WPInv_Invoice $invoice |
|
| 352 | 352 | */ |
| 353 | 353 | protected function prepare_billing_info( &$invoice ) { |
| 354 | 354 | |
| 355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 356 | 356 | |
| 357 | - // Update the invoice with the billing details. |
|
| 358 | - $invoice->set_props( $billing_address ); |
|
| 357 | + // Update the invoice with the billing details. |
|
| 358 | + $invoice->set_props( $billing_address ); |
|
| 359 | 359 | |
| 360 | - } |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - /** |
|
| 362 | + /** |
|
| 363 | 363 | * Prepares the shipping details. |
| 364 | 364 | * |
| 365 | - * @return array |
|
| 366 | - * @param WPInv_Invoice $invoice |
|
| 365 | + * @return array |
|
| 366 | + * @param WPInv_Invoice $invoice |
|
| 367 | 367 | */ |
| 368 | 368 | protected function prepare_shipping_info( $invoice ) { |
| 369 | 369 | |
| 370 | - $data = $this->payment_form_submission->get_data(); |
|
| 370 | + $data = $this->payment_form_submission->get_data(); |
|
| 371 | 371 | |
| 372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
| 373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 374 | - } |
|
| 372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
| 373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 377 | 377 | |
| 378 | - } |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * Confirms the submission is valid and send users to the gateway. |
|
| 382 | - * |
|
| 383 | - * @param WPInv_Invoice $invoice |
|
| 384 | - * @param array $prepared_payment_form_data |
|
| 385 | - * @param array $shipping |
|
| 386 | - */ |
|
| 387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 380 | + /** |
|
| 381 | + * Confirms the submission is valid and send users to the gateway. |
|
| 382 | + * |
|
| 383 | + * @param WPInv_Invoice $invoice |
|
| 384 | + * @param array $prepared_payment_form_data |
|
| 385 | + * @param array $shipping |
|
| 386 | + */ |
|
| 387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 388 | 388 | |
| 389 | - // Ensure the invoice exists. |
|
| 389 | + // Ensure the invoice exists. |
|
| 390 | 390 | if ( ! $invoice->exists() ) { |
| 391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - // Save payment form data. |
|
| 395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 394 | + // Save payment form data. |
|
| 395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
| 397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
| 398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
| 398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 399 | 399 | |
| 400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
| 401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
| 402 | - } |
|
| 400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
| 401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
| 405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
| 406 | - } |
|
| 404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
| 405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
| 406 | + } |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - // Save payment form data. |
|
| 410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
| 409 | + // Save payment form data. |
|
| 410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
| 411 | 411 | if ( ! empty( $shipping ) ) { |
| 412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
| 413 | - } |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | - // Backwards compatibility. |
|
| 415 | + // Backwards compatibility. |
|
| 416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
| 417 | 417 | |
| 418 | - $this->process_payment( $invoice ); |
|
| 418 | + $this->process_payment( $invoice ); |
|
| 419 | 419 | |
| 420 | 420 | // If we are here, there was an error. |
| 421 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 421 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 422 | 422 | |
| 423 | - } |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | - /** |
|
| 426 | - * Processes the actual payment. |
|
| 427 | - * |
|
| 428 | - * @param WPInv_Invoice $invoice |
|
| 429 | - */ |
|
| 430 | - protected function process_payment( $invoice ) { |
|
| 425 | + /** |
|
| 426 | + * Processes the actual payment. |
|
| 427 | + * |
|
| 428 | + * @param WPInv_Invoice $invoice |
|
| 429 | + */ |
|
| 430 | + protected function process_payment( $invoice ) { |
|
| 431 | 431 | |
| 432 | - // Clear any checkout errors. |
|
| 433 | - wpinv_clear_errors(); |
|
| 432 | + // Clear any checkout errors. |
|
| 433 | + wpinv_clear_errors(); |
|
| 434 | 434 | |
| 435 | - // No need to send free invoices to the gateway. |
|
| 436 | - if ( $invoice->is_free() ) { |
|
| 437 | - $this->process_free_payment( $invoice ); |
|
| 438 | - } |
|
| 435 | + // No need to send free invoices to the gateway. |
|
| 436 | + if ( $invoice->is_free() ) { |
|
| 437 | + $this->process_free_payment( $invoice ); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - $submission = $this->payment_form_submission; |
|
| 440 | + $submission = $this->payment_form_submission; |
|
| 441 | 441 | |
| 442 | - // Fires before sending to the gateway. |
|
| 443 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 442 | + // Fires before sending to the gateway. |
|
| 443 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 444 | 444 | |
| 445 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 446 | - $submission_data = $submission->get_data(); |
|
| 447 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 448 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 445 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 446 | + $submission_data = $submission->get_data(); |
|
| 447 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 448 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 449 | 449 | |
| 450 | - // Validate the currency. |
|
| 451 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 452 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
| 453 | - } |
|
| 450 | + // Validate the currency. |
|
| 451 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 452 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
| 453 | + } |
|
| 454 | 454 | |
| 455 | - // Check to see if we have any errors. |
|
| 456 | - if ( wpinv_get_errors() ) { |
|
| 457 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 458 | - } |
|
| 455 | + // Check to see if we have any errors. |
|
| 456 | + if ( wpinv_get_errors() ) { |
|
| 457 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - // Send info to the gateway for payment processing |
|
| 461 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 460 | + // Send info to the gateway for payment processing |
|
| 461 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 462 | 462 | |
| 463 | - // Backwards compatibility. |
|
| 464 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 463 | + // Backwards compatibility. |
|
| 464 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 465 | 465 | |
| 466 | - } |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | - /** |
|
| 469 | - * Marks the invoice as paid in case the checkout is free. |
|
| 470 | - * |
|
| 471 | - * @param WPInv_Invoice $invoice |
|
| 472 | - */ |
|
| 473 | - protected function process_free_payment( $invoice ) { |
|
| 468 | + /** |
|
| 469 | + * Marks the invoice as paid in case the checkout is free. |
|
| 470 | + * |
|
| 471 | + * @param WPInv_Invoice $invoice |
|
| 472 | + */ |
|
| 473 | + protected function process_free_payment( $invoice ) { |
|
| 474 | 474 | |
| 475 | - $invoice->set_gateway( 'none' ); |
|
| 476 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 477 | - $invoice->mark_paid(); |
|
| 478 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 475 | + $invoice->set_gateway( 'none' ); |
|
| 476 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 477 | + $invoice->mark_paid(); |
|
| 478 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 479 | 479 | |
| 480 | - } |
|
| 480 | + } |
|
| 481 | 481 | |
| 482 | - /** |
|
| 482 | + /** |
|
| 483 | 483 | * Sends a redrect response to payment details. |
| 484 | 484 | * |
| 485 | 485 | */ |
@@ -14,30 +14,30 @@ discard block |
||
| 14 | 14 | class WPInv_Invoice extends GetPaid_Data { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * Which data store to load. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 17 | + * Which data store to load. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | 21 | protected $data_store_name = 'invoice'; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * This is the name of this object type. |
|
| 25 | - * |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 24 | + * This is the name of this object type. |
|
| 25 | + * |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | 28 | protected $object_type = 'invoice'; |
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 32 | - * |
|
| 33 | - * @since 1.0.19 |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected $data = array( |
|
| 37 | - 'parent_id' => 0, |
|
| 38 | - 'status' => 'wpi-pending', |
|
| 39 | - 'version' => '', |
|
| 40 | - 'date_created' => null, |
|
| 31 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 32 | + * |
|
| 33 | + * @since 1.0.19 |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected $data = array( |
|
| 37 | + 'parent_id' => 0, |
|
| 38 | + 'status' => 'wpi-pending', |
|
| 39 | + 'version' => '', |
|
| 40 | + 'date_created' => null, |
|
| 41 | 41 | 'date_modified' => null, |
| 42 | 42 | 'due_date' => null, |
| 43 | 43 | 'completed_date' => null, |
@@ -60,17 +60,17 @@ discard block |
||
| 60 | 60 | 'state' => null, |
| 61 | 61 | 'zip' => null, |
| 62 | 62 | 'company' => null, |
| 63 | - 'company_id' => null, |
|
| 63 | + 'company_id' => null, |
|
| 64 | 64 | 'vat_number' => null, |
| 65 | 65 | 'vat_rate' => null, |
| 66 | 66 | 'address' => null, |
| 67 | 67 | 'address_confirmed' => false, |
| 68 | 68 | 'shipping' => null, |
| 69 | - 'subtotal' => 0, |
|
| 69 | + 'subtotal' => 0, |
|
| 70 | 70 | 'total_discount' => 0, |
| 71 | 71 | 'total_tax' => 0, |
| 72 | - 'total_fees' => 0, |
|
| 73 | - 'total' => 0, |
|
| 72 | + 'total_fees' => 0, |
|
| 73 | + 'total' => 0, |
|
| 74 | 74 | 'fees' => array(), |
| 75 | 75 | 'discounts' => array(), |
| 76 | 76 | 'taxes' => array(), |
@@ -82,22 +82,22 @@ discard block |
||
| 82 | 82 | 'transaction_id' => '', |
| 83 | 83 | 'currency' => '', |
| 84 | 84 | 'disable_taxes' => false, |
| 85 | - 'subscription_id' => null, |
|
| 86 | - 'remote_subscription_id' => null, |
|
| 87 | - 'is_viewed' => false, |
|
| 88 | - 'email_cc' => '', |
|
| 89 | - 'template' => 'quantity', // hours, amount only |
|
| 90 | - 'created_via' => null, |
|
| 85 | + 'subscription_id' => null, |
|
| 86 | + 'remote_subscription_id' => null, |
|
| 87 | + 'is_viewed' => false, |
|
| 88 | + 'email_cc' => '', |
|
| 89 | + 'template' => 'quantity', // hours, amount only |
|
| 90 | + 'created_via' => null, |
|
| 91 | 91 | ); |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | - * Stores meta in cache for future reads. |
|
| 95 | - * |
|
| 96 | - * A group must be set to to enable caching. |
|
| 97 | - * |
|
| 98 | - * @var string |
|
| 99 | - */ |
|
| 100 | - protected $cache_group = 'getpaid_invoices'; |
|
| 94 | + * Stores meta in cache for future reads. |
|
| 95 | + * |
|
| 96 | + * A group must be set to to enable caching. |
|
| 97 | + * |
|
| 98 | + * @var string |
|
| 99 | + */ |
|
| 100 | + protected $cache_group = 'getpaid_invoices'; |
|
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * Stores a reference to the original WP_Post object |
@@ -111,110 +111,110 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @var int |
| 113 | 113 | */ |
| 114 | - protected $recurring_item = null; |
|
| 114 | + protected $recurring_item = null; |
|
| 115 | 115 | |
| 116 | - /** |
|
| 116 | + /** |
|
| 117 | 117 | * Stores an array of item totals. |
| 118 | - * |
|
| 119 | - * e.g $totals['discount'] = array( |
|
| 120 | - * 'initial' => 10, |
|
| 121 | - * 'recurring' => 10, |
|
| 122 | - * ) |
|
| 118 | + * |
|
| 119 | + * e.g $totals['discount'] = array( |
|
| 120 | + * 'initial' => 10, |
|
| 121 | + * 'recurring' => 10, |
|
| 122 | + * ) |
|
| 123 | 123 | * |
| 124 | 124 | * @var array |
| 125 | 125 | */ |
| 126 | - protected $totals = array(); |
|
| 126 | + protected $totals = array(); |
|
| 127 | 127 | |
| 128 | - /** |
|
| 128 | + /** |
|
| 129 | 129 | * Tax rate. |
| 130 | - * |
|
| 130 | + * |
|
| 131 | 131 | * @var float |
| 132 | 132 | */ |
| 133 | - protected $tax_rate = 0; |
|
| 133 | + protected $tax_rate = 0; |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Stores the status transition information. |
|
| 137 | - * |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @var bool|array |
|
| 140 | - */ |
|
| 141 | - protected $status_transition = false; |
|
| 135 | + /** |
|
| 136 | + * Stores the status transition information. |
|
| 137 | + * |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @var bool|array |
|
| 140 | + */ |
|
| 141 | + protected $status_transition = false; |
|
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 145 | - * |
|
| 146 | - * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 147 | - */ |
|
| 144 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
| 145 | + * |
|
| 146 | + * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read. |
|
| 147 | + */ |
|
| 148 | 148 | public function __construct( $invoice = 0 ) { |
| 149 | 149 | |
| 150 | 150 | parent::__construct( $invoice ); |
| 151 | 151 | |
| 152 | - if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 153 | - $this->set_id( (int) $invoice ); |
|
| 154 | - } elseif ( $invoice instanceof self ) { |
|
| 155 | - $this->set_id( $invoice->get_id() ); |
|
| 156 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
| 157 | - $this->set_id( $invoice->ID ); |
|
| 158 | - } elseif ( is_array( $invoice ) ) { |
|
| 159 | - $this->set_props( $invoice ); |
|
| 160 | - |
|
| 161 | - if ( isset( $invoice['ID'] ) ) { |
|
| 162 | - $this->set_id( $invoice['ID'] ); |
|
| 163 | - } |
|
| 152 | + if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) { |
|
| 153 | + $this->set_id( (int) $invoice ); |
|
| 154 | + } elseif ( $invoice instanceof self ) { |
|
| 155 | + $this->set_id( $invoice->get_id() ); |
|
| 156 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
| 157 | + $this->set_id( $invoice->ID ); |
|
| 158 | + } elseif ( is_array( $invoice ) ) { |
|
| 159 | + $this->set_props( $invoice ); |
|
| 160 | + |
|
| 161 | + if ( isset( $invoice['ID'] ) ) { |
|
| 162 | + $this->set_id( $invoice['ID'] ); |
|
| 163 | + } |
|
| 164 | 164 | } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) { |
| 165 | - $this->set_id( $invoice_id ); |
|
| 166 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 167 | - $this->set_id( $invoice_id ); |
|
| 168 | - } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 169 | - $this->set_id( $invoice_id ); |
|
| 170 | - } else { |
|
| 171 | - $this->set_object_read( true ); |
|
| 172 | - } |
|
| 165 | + $this->set_id( $invoice_id ); |
|
| 166 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) { |
|
| 167 | + $this->set_id( $invoice_id ); |
|
| 168 | + } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) { |
|
| 169 | + $this->set_id( $invoice_id ); |
|
| 170 | + } else { |
|
| 171 | + $this->set_object_read( true ); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | // Load the datastore. |
| 175 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 175 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 176 | 176 | |
| 177 | - if ( $this->get_id() > 0 ) { |
|
| 177 | + if ( $this->get_id() > 0 ) { |
|
| 178 | 178 | $this->post = get_post( $this->get_id() ); |
| 179 | 179 | $this->ID = $this->get_id(); |
| 180 | - $this->data_store->read( $this ); |
|
| 180 | + $this->data_store->read( $this ); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | - * Given an invoice key/number, it returns its id. |
|
| 187 | - * |
|
| 188 | - * |
|
| 189 | - * @static |
|
| 190 | - * @param string $value The invoice key or number |
|
| 191 | - * @param string $field Either key, transaction_id or number. |
|
| 192 | - * @since 1.0.15 |
|
| 193 | - * @return int |
|
| 194 | - */ |
|
| 195 | - public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 186 | + * Given an invoice key/number, it returns its id. |
|
| 187 | + * |
|
| 188 | + * |
|
| 189 | + * @static |
|
| 190 | + * @param string $value The invoice key or number |
|
| 191 | + * @param string $field Either key, transaction_id or number. |
|
| 192 | + * @since 1.0.15 |
|
| 193 | + * @return int |
|
| 194 | + */ |
|
| 195 | + public static function get_invoice_id_by_field( $value, $field = 'key' ) { |
|
| 196 | 196 | global $wpdb; |
| 197 | 197 | |
| 198 | - // Trim the value. |
|
| 199 | - $value = trim( $value ); |
|
| 198 | + // Trim the value. |
|
| 199 | + $value = trim( $value ); |
|
| 200 | 200 | |
| 201 | - if ( empty( $value ) ) { |
|
| 202 | - return 0; |
|
| 203 | - } |
|
| 201 | + if ( empty( $value ) ) { |
|
| 202 | + return 0; |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | 205 | // Valid fields. |
| 206 | 206 | $fields = array( 'key', 'number', 'transaction_id' ); |
| 207 | 207 | |
| 208 | - // Ensure a field has been passed. |
|
| 209 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 210 | - return 0; |
|
| 211 | - } |
|
| 208 | + // Ensure a field has been passed. |
|
| 209 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 210 | + return 0; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - // Maybe retrieve from the cache. |
|
| 214 | - $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 215 | - if ( false !== $invoice_id ) { |
|
| 216 | - return $invoice_id; |
|
| 217 | - } |
|
| 213 | + // Maybe retrieve from the cache. |
|
| 214 | + $invoice_id = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 215 | + if ( false !== $invoice_id ) { |
|
| 216 | + return $invoice_id; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | 219 | // Fetch from the db. |
| 220 | 220 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | - // Update the cache with our data |
|
| 226 | - wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 225 | + // Update the cache with our data |
|
| 226 | + wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" ); |
|
| 227 | 227 | |
| 228 | - return $invoice_id; |
|
| 228 | + return $invoice_id; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -251,83 +251,83 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | - * Get parent invoice ID. |
|
| 255 | - * |
|
| 256 | - * @since 1.0.19 |
|
| 257 | - * @param string $context View or edit context. |
|
| 258 | - * @return int |
|
| 259 | - */ |
|
| 260 | - public function get_parent_id( $context = 'view' ) { |
|
| 261 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
| 254 | + * Get parent invoice ID. |
|
| 255 | + * |
|
| 256 | + * @since 1.0.19 |
|
| 257 | + * @param string $context View or edit context. |
|
| 258 | + * @return int |
|
| 259 | + */ |
|
| 260 | + public function get_parent_id( $context = 'view' ) { |
|
| 261 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
| 265 | - * Get parent invoice. |
|
| 266 | - * |
|
| 267 | - * @since 1.0.19 |
|
| 268 | - * @return WPInv_Invoice |
|
| 269 | - */ |
|
| 265 | + * Get parent invoice. |
|
| 266 | + * |
|
| 267 | + * @since 1.0.19 |
|
| 268 | + * @return WPInv_Invoice |
|
| 269 | + */ |
|
| 270 | 270 | public function get_parent_payment() { |
| 271 | 271 | return new WPInv_Invoice( $this->get_parent_id() ); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | - * Alias for self::get_parent_payment(). |
|
| 276 | - * |
|
| 277 | - * @since 1.0.19 |
|
| 278 | - * @return WPInv_Invoice |
|
| 279 | - */ |
|
| 275 | + * Alias for self::get_parent_payment(). |
|
| 276 | + * |
|
| 277 | + * @since 1.0.19 |
|
| 278 | + * @return WPInv_Invoice |
|
| 279 | + */ |
|
| 280 | 280 | public function get_parent() { |
| 281 | 281 | return $this->get_parent_payment(); |
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
| 285 | - * Get invoice status. |
|
| 286 | - * |
|
| 287 | - * @since 1.0.19 |
|
| 288 | - * @param string $context View or edit context. |
|
| 289 | - * @return string |
|
| 290 | - */ |
|
| 291 | - public function get_status( $context = 'view' ) { |
|
| 292 | - return $this->get_prop( 'status', $context ); |
|
| 293 | - } |
|
| 285 | + * Get invoice status. |
|
| 286 | + * |
|
| 287 | + * @since 1.0.19 |
|
| 288 | + * @param string $context View or edit context. |
|
| 289 | + * @return string |
|
| 290 | + */ |
|
| 291 | + public function get_status( $context = 'view' ) { |
|
| 292 | + return $this->get_prop( 'status', $context ); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - /** |
|
| 296 | - * Retrieves an array of possible invoice statuses. |
|
| 297 | - * |
|
| 298 | - * @since 1.0.19 |
|
| 299 | - * @return array |
|
| 300 | - */ |
|
| 301 | - public function get_all_statuses() { |
|
| 302 | - return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 295 | + /** |
|
| 296 | + * Retrieves an array of possible invoice statuses. |
|
| 297 | + * |
|
| 298 | + * @since 1.0.19 |
|
| 299 | + * @return array |
|
| 300 | + */ |
|
| 301 | + public function get_all_statuses() { |
|
| 302 | + return wpinv_get_invoice_statuses( true, true, $this ); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
| 306 | - * Get invoice status nice name. |
|
| 307 | - * |
|
| 308 | - * @since 1.0.19 |
|
| 309 | - * @return string |
|
| 310 | - */ |
|
| 306 | + * Get invoice status nice name. |
|
| 307 | + * |
|
| 308 | + * @since 1.0.19 |
|
| 309 | + * @return string |
|
| 310 | + */ |
|
| 311 | 311 | public function get_status_nicename() { |
| 312 | - $statuses = $this->get_all_statuses(); |
|
| 312 | + $statuses = $this->get_all_statuses(); |
|
| 313 | 313 | |
| 314 | 314 | $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status(); |
| 315 | 315 | |
| 316 | 316 | return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this ); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - /** |
|
| 320 | - * Retrieves the invoice status class |
|
| 321 | - * |
|
| 322 | - * @since 1.0.19 |
|
| 323 | - * @return string |
|
| 324 | - */ |
|
| 325 | - public function get_status_class() { |
|
| 326 | - $statuses = getpaid_get_invoice_status_classes(); |
|
| 327 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 328 | - } |
|
| 319 | + /** |
|
| 320 | + * Retrieves the invoice status class |
|
| 321 | + * |
|
| 322 | + * @since 1.0.19 |
|
| 323 | + * @return string |
|
| 324 | + */ |
|
| 325 | + public function get_status_class() { |
|
| 326 | + $statuses = getpaid_get_invoice_status_classes(); |
|
| 327 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - /** |
|
| 330 | + /** |
|
| 331 | 331 | * Retrieves the invoice status label html |
| 332 | 332 | * |
| 333 | 333 | * @since 1.0.0 |
@@ -335,263 +335,263 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | public function get_status_label_html() { |
| 337 | 337 | |
| 338 | - $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 339 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 340 | - $class = esc_attr( $this->get_status_class() ); |
|
| 341 | - |
|
| 342 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Get plugin version when the invoice was created. |
|
| 347 | - * |
|
| 348 | - * @since 1.0.19 |
|
| 349 | - * @param string $context View or edit context. |
|
| 350 | - * @return string |
|
| 351 | - */ |
|
| 352 | - public function get_version( $context = 'view' ) { |
|
| 353 | - return $this->get_prop( 'version', $context ); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * @deprecated |
|
| 358 | - */ |
|
| 359 | - public function get_invoice_date( $format = true ) { |
|
| 360 | - $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 361 | - $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 362 | - $formatted = getpaid_format_date( $date ); |
|
| 363 | - |
|
| 364 | - if ( $format ) { |
|
| 365 | - return $formatted; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - return empty( $formatted ) ? '' : $date; |
|
| 369 | - |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Get date when the invoice was created. |
|
| 374 | - * |
|
| 375 | - * @since 1.0.19 |
|
| 376 | - * @param string $context View or edit context. |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function get_date_created( $context = 'view' ) { |
|
| 380 | - return $this->get_prop( 'date_created', $context ); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Alias for self::get_date_created(). |
|
| 385 | - * |
|
| 386 | - * @since 1.0.19 |
|
| 387 | - * @param string $context View or edit context. |
|
| 388 | - * @return string |
|
| 389 | - */ |
|
| 390 | - public function get_created_date( $context = 'view' ) { |
|
| 391 | - return $this->get_date_created( $context ); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Get GMT date when the invoice was created. |
|
| 396 | - * |
|
| 397 | - * @since 1.0.19 |
|
| 398 | - * @param string $context View or edit context. |
|
| 399 | - * @return string |
|
| 400 | - */ |
|
| 401 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 338 | + $status_label = sanitize_text_field( $this->get_status_nicename() ); |
|
| 339 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 340 | + $class = esc_attr( $this->get_status_class() ); |
|
| 341 | + |
|
| 342 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Get plugin version when the invoice was created. |
|
| 347 | + * |
|
| 348 | + * @since 1.0.19 |
|
| 349 | + * @param string $context View or edit context. |
|
| 350 | + * @return string |
|
| 351 | + */ |
|
| 352 | + public function get_version( $context = 'view' ) { |
|
| 353 | + return $this->get_prop( 'version', $context ); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * @deprecated |
|
| 358 | + */ |
|
| 359 | + public function get_invoice_date( $format = true ) { |
|
| 360 | + $date = getpaid_format_date( $this->get_date_completed() ); |
|
| 361 | + $date = empty( $date ) ? $this->get_date_created() : $this->get_date_completed(); |
|
| 362 | + $formatted = getpaid_format_date( $date ); |
|
| 363 | + |
|
| 364 | + if ( $format ) { |
|
| 365 | + return $formatted; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + return empty( $formatted ) ? '' : $date; |
|
| 369 | + |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Get date when the invoice was created. |
|
| 374 | + * |
|
| 375 | + * @since 1.0.19 |
|
| 376 | + * @param string $context View or edit context. |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function get_date_created( $context = 'view' ) { |
|
| 380 | + return $this->get_prop( 'date_created', $context ); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Alias for self::get_date_created(). |
|
| 385 | + * |
|
| 386 | + * @since 1.0.19 |
|
| 387 | + * @param string $context View or edit context. |
|
| 388 | + * @return string |
|
| 389 | + */ |
|
| 390 | + public function get_created_date( $context = 'view' ) { |
|
| 391 | + return $this->get_date_created( $context ); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Get GMT date when the invoice was created. |
|
| 396 | + * |
|
| 397 | + * @since 1.0.19 |
|
| 398 | + * @param string $context View or edit context. |
|
| 399 | + * @return string |
|
| 400 | + */ |
|
| 401 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 402 | 402 | $date = $this->get_date_created( $context ); |
| 403 | 403 | |
| 404 | 404 | if ( $date ) { |
| 405 | 405 | $date = get_gmt_from_date( $date ); |
| 406 | 406 | } |
| 407 | - return $date; |
|
| 407 | + return $date; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
| 411 | - * Get date when the invoice was last modified. |
|
| 412 | - * |
|
| 413 | - * @since 1.0.19 |
|
| 414 | - * @param string $context View or edit context. |
|
| 415 | - * @return string |
|
| 416 | - */ |
|
| 417 | - public function get_date_modified( $context = 'view' ) { |
|
| 418 | - return $this->get_prop( 'date_modified', $context ); |
|
| 419 | - } |
|
| 411 | + * Get date when the invoice was last modified. |
|
| 412 | + * |
|
| 413 | + * @since 1.0.19 |
|
| 414 | + * @param string $context View or edit context. |
|
| 415 | + * @return string |
|
| 416 | + */ |
|
| 417 | + public function get_date_modified( $context = 'view' ) { |
|
| 418 | + return $this->get_prop( 'date_modified', $context ); |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * Alias for self::get_date_modified(). |
|
| 423 | - * |
|
| 424 | - * @since 1.0.19 |
|
| 425 | - * @param string $context View or edit context. |
|
| 426 | - * @return string |
|
| 427 | - */ |
|
| 428 | - public function get_modified_date( $context = 'view' ) { |
|
| 429 | - return $this->get_date_modified( $context ); |
|
| 421 | + /** |
|
| 422 | + * Alias for self::get_date_modified(). |
|
| 423 | + * |
|
| 424 | + * @since 1.0.19 |
|
| 425 | + * @param string $context View or edit context. |
|
| 426 | + * @return string |
|
| 427 | + */ |
|
| 428 | + public function get_modified_date( $context = 'view' ) { |
|
| 429 | + return $this->get_date_modified( $context ); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
| 433 | - * Get GMT date when the invoice was last modified. |
|
| 434 | - * |
|
| 435 | - * @since 1.0.19 |
|
| 436 | - * @param string $context View or edit context. |
|
| 437 | - * @return string |
|
| 438 | - */ |
|
| 439 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
| 433 | + * Get GMT date when the invoice was last modified. |
|
| 434 | + * |
|
| 435 | + * @since 1.0.19 |
|
| 436 | + * @param string $context View or edit context. |
|
| 437 | + * @return string |
|
| 438 | + */ |
|
| 439 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
| 440 | 440 | $date = $this->get_date_modified( $context ); |
| 441 | 441 | |
| 442 | 442 | if ( $date ) { |
| 443 | 443 | $date = get_gmt_from_date( $date ); |
| 444 | 444 | } |
| 445 | - return $date; |
|
| 445 | + return $date; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | /** |
| 449 | - * Get the invoice due date. |
|
| 450 | - * |
|
| 451 | - * @since 1.0.19 |
|
| 452 | - * @param string $context View or edit context. |
|
| 453 | - * @return string |
|
| 454 | - */ |
|
| 455 | - public function get_due_date( $context = 'view' ) { |
|
| 456 | - return $this->get_prop( 'due_date', $context ); |
|
| 449 | + * Get the invoice due date. |
|
| 450 | + * |
|
| 451 | + * @since 1.0.19 |
|
| 452 | + * @param string $context View or edit context. |
|
| 453 | + * @return string |
|
| 454 | + */ |
|
| 455 | + public function get_due_date( $context = 'view' ) { |
|
| 456 | + return $this->get_prop( 'due_date', $context ); |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | /** |
| 460 | - * Alias for self::get_due_date(). |
|
| 461 | - * |
|
| 462 | - * @since 1.0.19 |
|
| 463 | - * @param string $context View or edit context. |
|
| 464 | - * @return string |
|
| 465 | - */ |
|
| 466 | - public function get_date_due( $context = 'view' ) { |
|
| 467 | - return $this->get_due_date( $context ); |
|
| 460 | + * Alias for self::get_due_date(). |
|
| 461 | + * |
|
| 462 | + * @since 1.0.19 |
|
| 463 | + * @param string $context View or edit context. |
|
| 464 | + * @return string |
|
| 465 | + */ |
|
| 466 | + public function get_date_due( $context = 'view' ) { |
|
| 467 | + return $this->get_due_date( $context ); |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
| 471 | - * Get the invoice GMT due date. |
|
| 472 | - * |
|
| 473 | - * @since 1.0.19 |
|
| 474 | - * @param string $context View or edit context. |
|
| 475 | - * @return string |
|
| 476 | - */ |
|
| 477 | - public function get_due_date_gmt( $context = 'view' ) { |
|
| 471 | + * Get the invoice GMT due date. |
|
| 472 | + * |
|
| 473 | + * @since 1.0.19 |
|
| 474 | + * @param string $context View or edit context. |
|
| 475 | + * @return string |
|
| 476 | + */ |
|
| 477 | + public function get_due_date_gmt( $context = 'view' ) { |
|
| 478 | 478 | $date = $this->get_due_date( $context ); |
| 479 | 479 | |
| 480 | 480 | if ( $date ) { |
| 481 | 481 | $date = get_gmt_from_date( $date ); |
| 482 | 482 | } |
| 483 | - return $date; |
|
| 483 | + return $date; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
| 487 | - * Alias for self::get_due_date_gmt(). |
|
| 488 | - * |
|
| 489 | - * @since 1.0.19 |
|
| 490 | - * @param string $context View or edit context. |
|
| 491 | - * @return string |
|
| 492 | - */ |
|
| 493 | - public function get_gmt_date_due( $context = 'view' ) { |
|
| 494 | - return $this->get_due_date_gmt( $context ); |
|
| 487 | + * Alias for self::get_due_date_gmt(). |
|
| 488 | + * |
|
| 489 | + * @since 1.0.19 |
|
| 490 | + * @param string $context View or edit context. |
|
| 491 | + * @return string |
|
| 492 | + */ |
|
| 493 | + public function get_gmt_date_due( $context = 'view' ) { |
|
| 494 | + return $this->get_due_date_gmt( $context ); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
| 498 | - * Get date when the invoice was completed. |
|
| 499 | - * |
|
| 500 | - * @since 1.0.19 |
|
| 501 | - * @param string $context View or edit context. |
|
| 502 | - * @return string |
|
| 503 | - */ |
|
| 504 | - public function get_completed_date( $context = 'view' ) { |
|
| 505 | - return $this->get_prop( 'completed_date', $context ); |
|
| 498 | + * Get date when the invoice was completed. |
|
| 499 | + * |
|
| 500 | + * @since 1.0.19 |
|
| 501 | + * @param string $context View or edit context. |
|
| 502 | + * @return string |
|
| 503 | + */ |
|
| 504 | + public function get_completed_date( $context = 'view' ) { |
|
| 505 | + return $this->get_prop( 'completed_date', $context ); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
| 509 | - * Alias for self::get_completed_date(). |
|
| 510 | - * |
|
| 511 | - * @since 1.0.19 |
|
| 512 | - * @param string $context View or edit context. |
|
| 513 | - * @return string |
|
| 514 | - */ |
|
| 515 | - public function get_date_completed( $context = 'view' ) { |
|
| 516 | - return $this->get_completed_date( $context ); |
|
| 509 | + * Alias for self::get_completed_date(). |
|
| 510 | + * |
|
| 511 | + * @since 1.0.19 |
|
| 512 | + * @param string $context View or edit context. |
|
| 513 | + * @return string |
|
| 514 | + */ |
|
| 515 | + public function get_date_completed( $context = 'view' ) { |
|
| 516 | + return $this->get_completed_date( $context ); |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
| 520 | - * Get GMT date when the invoice was was completed. |
|
| 521 | - * |
|
| 522 | - * @since 1.0.19 |
|
| 523 | - * @param string $context View or edit context. |
|
| 524 | - * @return string |
|
| 525 | - */ |
|
| 526 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
| 520 | + * Get GMT date when the invoice was was completed. |
|
| 521 | + * |
|
| 522 | + * @since 1.0.19 |
|
| 523 | + * @param string $context View or edit context. |
|
| 524 | + * @return string |
|
| 525 | + */ |
|
| 526 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
| 527 | 527 | $date = $this->get_completed_date( $context ); |
| 528 | 528 | |
| 529 | 529 | if ( $date ) { |
| 530 | 530 | $date = get_gmt_from_date( $date ); |
| 531 | 531 | } |
| 532 | - return $date; |
|
| 532 | + return $date; |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
| 536 | - * Alias for self::get_completed_date_gmt(). |
|
| 537 | - * |
|
| 538 | - * @since 1.0.19 |
|
| 539 | - * @param string $context View or edit context. |
|
| 540 | - * @return string |
|
| 541 | - */ |
|
| 542 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
| 543 | - return $this->get_completed_date_gmt( $context ); |
|
| 536 | + * Alias for self::get_completed_date_gmt(). |
|
| 537 | + * |
|
| 538 | + * @since 1.0.19 |
|
| 539 | + * @param string $context View or edit context. |
|
| 540 | + * @return string |
|
| 541 | + */ |
|
| 542 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
| 543 | + return $this->get_completed_date_gmt( $context ); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
| 547 | - * Get the invoice number. |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param string $context View or edit context. |
|
| 551 | - * @return string |
|
| 552 | - */ |
|
| 553 | - public function get_number( $context = 'view' ) { |
|
| 554 | - $number = $this->get_prop( 'number', $context ); |
|
| 547 | + * Get the invoice number. |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param string $context View or edit context. |
|
| 551 | + * @return string |
|
| 552 | + */ |
|
| 553 | + public function get_number( $context = 'view' ) { |
|
| 554 | + $number = $this->get_prop( 'number', $context ); |
|
| 555 | 555 | |
| 556 | - if ( empty( $number ) ) { |
|
| 557 | - $number = $this->generate_number(); |
|
| 558 | - $this->set_number( $this->generate_number() ); |
|
| 559 | - } |
|
| 556 | + if ( empty( $number ) ) { |
|
| 557 | + $number = $this->generate_number(); |
|
| 558 | + $this->set_number( $this->generate_number() ); |
|
| 559 | + } |
|
| 560 | 560 | |
| 561 | - return $number; |
|
| 561 | + return $number; |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | - /** |
|
| 565 | - * Set the invoice number. |
|
| 566 | - * |
|
| 567 | - * @since 1.0.19 |
|
| 568 | - */ |
|
| 569 | - public function maybe_set_number() { |
|
| 564 | + /** |
|
| 565 | + * Set the invoice number. |
|
| 566 | + * |
|
| 567 | + * @since 1.0.19 |
|
| 568 | + */ |
|
| 569 | + public function maybe_set_number() { |
|
| 570 | 570 | $number = $this->get_number(); |
| 571 | 571 | |
| 572 | 572 | if ( empty( $number ) || $this->get_id() == $number ) { |
| 573 | - $this->set_number( $this->generate_number() ); |
|
| 573 | + $this->set_number( $this->generate_number() ); |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | - } |
|
| 576 | + } |
|
| 577 | 577 | |
| 578 | 578 | /** |
| 579 | - * Get the invoice key. |
|
| 580 | - * |
|
| 581 | - * @since 1.0.19 |
|
| 582 | - * @param string $context View or edit context. |
|
| 583 | - * @return string |
|
| 584 | - */ |
|
| 585 | - public function get_key( $context = 'view' ) { |
|
| 579 | + * Get the invoice key. |
|
| 580 | + * |
|
| 581 | + * @since 1.0.19 |
|
| 582 | + * @param string $context View or edit context. |
|
| 583 | + * @return string |
|
| 584 | + */ |
|
| 585 | + public function get_key( $context = 'view' ) { |
|
| 586 | 586 | return $this->get_prop( 'key', $context ); |
| 587 | - } |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Set the invoice key. |
|
| 591 | - * |
|
| 592 | - * @since 1.0.19 |
|
| 593 | - */ |
|
| 594 | - public function maybe_set_key() { |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Set the invoice key. |
|
| 591 | + * |
|
| 592 | + * @since 1.0.19 |
|
| 593 | + */ |
|
| 594 | + public function maybe_set_key() { |
|
| 595 | 595 | $key = $this->get_key(); |
| 596 | 596 | |
| 597 | 597 | if ( empty( $key ) ) { |
@@ -602,140 +602,140 @@ discard block |
||
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
| 605 | - * Get the invoice type. |
|
| 606 | - * |
|
| 607 | - * @since 1.0.19 |
|
| 608 | - * @param string $context View or edit context. |
|
| 609 | - * @return string |
|
| 610 | - */ |
|
| 611 | - public function get_type( $context = 'view' ) { |
|
| 605 | + * Get the invoice type. |
|
| 606 | + * |
|
| 607 | + * @since 1.0.19 |
|
| 608 | + * @param string $context View or edit context. |
|
| 609 | + * @return string |
|
| 610 | + */ |
|
| 611 | + public function get_type( $context = 'view' ) { |
|
| 612 | 612 | return $this->get_prop( 'type', $context ); |
| 613 | - } |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Returns the post type name. |
|
| 617 | - * |
|
| 618 | - * @since 1.0.19 |
|
| 619 | - * @return string |
|
| 620 | - */ |
|
| 621 | - public function get_invoice_quote_type() { |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Returns the post type name. |
|
| 617 | + * |
|
| 618 | + * @since 1.0.19 |
|
| 619 | + * @return string |
|
| 620 | + */ |
|
| 621 | + public function get_invoice_quote_type() { |
|
| 622 | 622 | return getpaid_get_post_type_label( $this->get_post_type(), false ); |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
| 626 | - * Get the invoice post type label. |
|
| 627 | - * |
|
| 628 | - * @since 1.0.19 |
|
| 629 | - * @param string $context View or edit context. |
|
| 630 | - * @return string |
|
| 631 | - */ |
|
| 632 | - public function get_label( $context = 'view' ) { |
|
| 626 | + * Get the invoice post type label. |
|
| 627 | + * |
|
| 628 | + * @since 1.0.19 |
|
| 629 | + * @param string $context View or edit context. |
|
| 630 | + * @return string |
|
| 631 | + */ |
|
| 632 | + public function get_label( $context = 'view' ) { |
|
| 633 | 633 | return getpaid_get_post_type_label( $this->get_post_type( $context ), false ); |
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Get the invoice post type. |
|
| 638 | - * |
|
| 639 | - * @since 1.0.19 |
|
| 640 | - * @param string $context View or edit context. |
|
| 641 | - * @return string |
|
| 642 | - */ |
|
| 643 | - public function get_post_type( $context = 'view' ) { |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Get the invoice post type. |
|
| 638 | + * |
|
| 639 | + * @since 1.0.19 |
|
| 640 | + * @param string $context View or edit context. |
|
| 641 | + * @return string |
|
| 642 | + */ |
|
| 643 | + public function get_post_type( $context = 'view' ) { |
|
| 644 | 644 | return $this->get_prop( 'post_type', $context ); |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | /** |
| 648 | - * Get the invoice mode. |
|
| 649 | - * |
|
| 650 | - * @since 1.0.19 |
|
| 651 | - * @param string $context View or edit context. |
|
| 652 | - * @return string |
|
| 653 | - */ |
|
| 654 | - public function get_mode( $context = 'view' ) { |
|
| 648 | + * Get the invoice mode. |
|
| 649 | + * |
|
| 650 | + * @since 1.0.19 |
|
| 651 | + * @param string $context View or edit context. |
|
| 652 | + * @return string |
|
| 653 | + */ |
|
| 654 | + public function get_mode( $context = 'view' ) { |
|
| 655 | 655 | return $this->get_prop( 'mode', $context ); |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
| 659 | - * Get the invoice path. |
|
| 660 | - * |
|
| 661 | - * @since 1.0.19 |
|
| 662 | - * @param string $context View or edit context. |
|
| 663 | - * @return string |
|
| 664 | - */ |
|
| 665 | - public function get_path( $context = 'view' ) { |
|
| 659 | + * Get the invoice path. |
|
| 660 | + * |
|
| 661 | + * @since 1.0.19 |
|
| 662 | + * @param string $context View or edit context. |
|
| 663 | + * @return string |
|
| 664 | + */ |
|
| 665 | + public function get_path( $context = 'view' ) { |
|
| 666 | 666 | $path = $this->get_prop( 'path', $context ); |
| 667 | - $prefix = $this->get_type(); |
|
| 667 | + $prefix = $this->get_type(); |
|
| 668 | 668 | |
| 669 | - if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 670 | - $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 671 | - $this->set_path( $path ); |
|
| 672 | - } |
|
| 669 | + if ( 0 !== strpos( $path, $prefix ) ) { |
|
| 670 | + $path = sanitize_title( $prefix . '-' . $this->get_id() ); |
|
| 671 | + $this->set_path( $path ); |
|
| 672 | + } |
|
| 673 | 673 | |
| 674 | - return $path; |
|
| 674 | + return $path; |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
| 678 | - * Get the invoice name/title. |
|
| 679 | - * |
|
| 680 | - * @since 1.0.19 |
|
| 681 | - * @param string $context View or edit context. |
|
| 682 | - * @return string |
|
| 683 | - */ |
|
| 684 | - public function get_name( $context = 'view' ) { |
|
| 678 | + * Get the invoice name/title. |
|
| 679 | + * |
|
| 680 | + * @since 1.0.19 |
|
| 681 | + * @param string $context View or edit context. |
|
| 682 | + * @return string |
|
| 683 | + */ |
|
| 684 | + public function get_name( $context = 'view' ) { |
|
| 685 | 685 | return $this->get_prop( 'title', $context ); |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | /** |
| 689 | - * Alias of self::get_name(). |
|
| 690 | - * |
|
| 691 | - * @since 1.0.19 |
|
| 692 | - * @param string $context View or edit context. |
|
| 693 | - * @return string |
|
| 694 | - */ |
|
| 695 | - public function get_title( $context = 'view' ) { |
|
| 696 | - return $this->get_name( $context ); |
|
| 689 | + * Alias of self::get_name(). |
|
| 690 | + * |
|
| 691 | + * @since 1.0.19 |
|
| 692 | + * @param string $context View or edit context. |
|
| 693 | + * @return string |
|
| 694 | + */ |
|
| 695 | + public function get_title( $context = 'view' ) { |
|
| 696 | + return $this->get_name( $context ); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | /** |
| 700 | - * Get the invoice description. |
|
| 701 | - * |
|
| 702 | - * @since 1.0.19 |
|
| 703 | - * @param string $context View or edit context. |
|
| 704 | - * @return string |
|
| 705 | - */ |
|
| 706 | - public function get_description( $context = 'view' ) { |
|
| 707 | - return $this->get_prop( 'description', $context ); |
|
| 700 | + * Get the invoice description. |
|
| 701 | + * |
|
| 702 | + * @since 1.0.19 |
|
| 703 | + * @param string $context View or edit context. |
|
| 704 | + * @return string |
|
| 705 | + */ |
|
| 706 | + public function get_description( $context = 'view' ) { |
|
| 707 | + return $this->get_prop( 'description', $context ); |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | /** |
| 711 | - * Alias of self::get_description(). |
|
| 712 | - * |
|
| 713 | - * @since 1.0.19 |
|
| 714 | - * @param string $context View or edit context. |
|
| 715 | - * @return string |
|
| 716 | - */ |
|
| 717 | - public function get_excerpt( $context = 'view' ) { |
|
| 718 | - return $this->get_description( $context ); |
|
| 711 | + * Alias of self::get_description(). |
|
| 712 | + * |
|
| 713 | + * @since 1.0.19 |
|
| 714 | + * @param string $context View or edit context. |
|
| 715 | + * @return string |
|
| 716 | + */ |
|
| 717 | + public function get_excerpt( $context = 'view' ) { |
|
| 718 | + return $this->get_description( $context ); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
| 722 | - * Alias of self::get_description(). |
|
| 723 | - * |
|
| 724 | - * @since 1.0.19 |
|
| 725 | - * @param string $context View or edit context. |
|
| 726 | - * @return string |
|
| 727 | - */ |
|
| 728 | - public function get_summary( $context = 'view' ) { |
|
| 729 | - return $this->get_description( $context ); |
|
| 722 | + * Alias of self::get_description(). |
|
| 723 | + * |
|
| 724 | + * @since 1.0.19 |
|
| 725 | + * @param string $context View or edit context. |
|
| 726 | + * @return string |
|
| 727 | + */ |
|
| 728 | + public function get_summary( $context = 'view' ) { |
|
| 729 | + return $this->get_description( $context ); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
| 733 | - * Returns the user info. |
|
| 734 | - * |
|
| 735 | - * @since 1.0.19 |
|
| 733 | + * Returns the user info. |
|
| 734 | + * |
|
| 735 | + * @since 1.0.19 |
|
| 736 | 736 | * @param string $context View or edit context. |
| 737 | - * @return array |
|
| 738 | - */ |
|
| 737 | + * @return array |
|
| 738 | + */ |
|
| 739 | 739 | public function get_user_info( $context = 'view' ) { |
| 740 | 740 | |
| 741 | 741 | $user_info = array( |
@@ -750,683 +750,683 @@ discard block |
||
| 750 | 750 | 'state' => $this->get_state( $context ), |
| 751 | 751 | 'zip' => $this->get_zip( $context ), |
| 752 | 752 | 'company' => $this->get_company( $context ), |
| 753 | - 'company_id' => $this->get_company_id( $context ), |
|
| 753 | + 'company_id' => $this->get_company_id( $context ), |
|
| 754 | 754 | 'vat_number' => $this->get_vat_number( $context ), |
| 755 | 755 | 'discount' => $this->get_discount_code( $context ), |
| 756 | - ); |
|
| 756 | + ); |
|
| 757 | 757 | |
| 758 | - return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 758 | + return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this ); |
|
| 759 | 759 | |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | /** |
| 763 | - * Get the customer id. |
|
| 764 | - * |
|
| 765 | - * @since 1.0.19 |
|
| 766 | - * @param string $context View or edit context. |
|
| 767 | - * @return int |
|
| 768 | - */ |
|
| 769 | - public function get_author( $context = 'view' ) { |
|
| 770 | - return (int) $this->get_prop( 'author', $context ); |
|
| 763 | + * Get the customer id. |
|
| 764 | + * |
|
| 765 | + * @since 1.0.19 |
|
| 766 | + * @param string $context View or edit context. |
|
| 767 | + * @return int |
|
| 768 | + */ |
|
| 769 | + public function get_author( $context = 'view' ) { |
|
| 770 | + return (int) $this->get_prop( 'author', $context ); |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | /** |
| 774 | - * Alias of self::get_author(). |
|
| 775 | - * |
|
| 776 | - * @since 1.0.19 |
|
| 777 | - * @param string $context View or edit context. |
|
| 778 | - * @return int |
|
| 779 | - */ |
|
| 780 | - public function get_user_id( $context = 'view' ) { |
|
| 781 | - return $this->get_author( $context ); |
|
| 774 | + * Alias of self::get_author(). |
|
| 775 | + * |
|
| 776 | + * @since 1.0.19 |
|
| 777 | + * @param string $context View or edit context. |
|
| 778 | + * @return int |
|
| 779 | + */ |
|
| 780 | + public function get_user_id( $context = 'view' ) { |
|
| 781 | + return $this->get_author( $context ); |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | - /** |
|
| 785 | - * Alias of self::get_author(). |
|
| 786 | - * |
|
| 787 | - * @since 1.0.19 |
|
| 788 | - * @param string $context View or edit context. |
|
| 789 | - * @return int |
|
| 790 | - */ |
|
| 791 | - public function get_customer_id( $context = 'view' ) { |
|
| 792 | - return $this->get_author( $context ); |
|
| 784 | + /** |
|
| 785 | + * Alias of self::get_author(). |
|
| 786 | + * |
|
| 787 | + * @since 1.0.19 |
|
| 788 | + * @param string $context View or edit context. |
|
| 789 | + * @return int |
|
| 790 | + */ |
|
| 791 | + public function get_customer_id( $context = 'view' ) { |
|
| 792 | + return $this->get_author( $context ); |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | /** |
| 796 | - * Get the customer's ip. |
|
| 797 | - * |
|
| 798 | - * @since 1.0.19 |
|
| 799 | - * @param string $context View or edit context. |
|
| 800 | - * @return string |
|
| 801 | - */ |
|
| 802 | - public function get_ip( $context = 'view' ) { |
|
| 803 | - return $this->get_prop( 'user_ip', $context ); |
|
| 796 | + * Get the customer's ip. |
|
| 797 | + * |
|
| 798 | + * @since 1.0.19 |
|
| 799 | + * @param string $context View or edit context. |
|
| 800 | + * @return string |
|
| 801 | + */ |
|
| 802 | + public function get_ip( $context = 'view' ) { |
|
| 803 | + return $this->get_prop( 'user_ip', $context ); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
| 807 | - * Alias of self::get_ip(). |
|
| 808 | - * |
|
| 809 | - * @since 1.0.19 |
|
| 810 | - * @param string $context View or edit context. |
|
| 811 | - * @return string |
|
| 812 | - */ |
|
| 813 | - public function get_user_ip( $context = 'view' ) { |
|
| 814 | - return $this->get_ip( $context ); |
|
| 807 | + * Alias of self::get_ip(). |
|
| 808 | + * |
|
| 809 | + * @since 1.0.19 |
|
| 810 | + * @param string $context View or edit context. |
|
| 811 | + * @return string |
|
| 812 | + */ |
|
| 813 | + public function get_user_ip( $context = 'view' ) { |
|
| 814 | + return $this->get_ip( $context ); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | - /** |
|
| 818 | - * Alias of self::get_ip(). |
|
| 819 | - * |
|
| 820 | - * @since 1.0.19 |
|
| 821 | - * @param string $context View or edit context. |
|
| 822 | - * @return string |
|
| 823 | - */ |
|
| 824 | - public function get_customer_ip( $context = 'view' ) { |
|
| 825 | - return $this->get_ip( $context ); |
|
| 817 | + /** |
|
| 818 | + * Alias of self::get_ip(). |
|
| 819 | + * |
|
| 820 | + * @since 1.0.19 |
|
| 821 | + * @param string $context View or edit context. |
|
| 822 | + * @return string |
|
| 823 | + */ |
|
| 824 | + public function get_customer_ip( $context = 'view' ) { |
|
| 825 | + return $this->get_ip( $context ); |
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | /** |
| 829 | - * Get the customer's first name. |
|
| 830 | - * |
|
| 831 | - * @since 1.0.19 |
|
| 832 | - * @param string $context View or edit context. |
|
| 833 | - * @return string |
|
| 834 | - */ |
|
| 835 | - public function get_first_name( $context = 'view' ) { |
|
| 836 | - return $this->get_prop( 'first_name', $context ); |
|
| 829 | + * Get the customer's first name. |
|
| 830 | + * |
|
| 831 | + * @since 1.0.19 |
|
| 832 | + * @param string $context View or edit context. |
|
| 833 | + * @return string |
|
| 834 | + */ |
|
| 835 | + public function get_first_name( $context = 'view' ) { |
|
| 836 | + return $this->get_prop( 'first_name', $context ); |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
| 840 | - * Alias of self::get_first_name(). |
|
| 841 | - * |
|
| 842 | - * @since 1.0.19 |
|
| 843 | - * @param string $context View or edit context. |
|
| 844 | - * @return string |
|
| 845 | - */ |
|
| 846 | - public function get_user_first_name( $context = 'view' ) { |
|
| 847 | - return $this->get_first_name( $context ); |
|
| 840 | + * Alias of self::get_first_name(). |
|
| 841 | + * |
|
| 842 | + * @since 1.0.19 |
|
| 843 | + * @param string $context View or edit context. |
|
| 844 | + * @return string |
|
| 845 | + */ |
|
| 846 | + public function get_user_first_name( $context = 'view' ) { |
|
| 847 | + return $this->get_first_name( $context ); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | - /** |
|
| 851 | - * Alias of self::get_first_name(). |
|
| 852 | - * |
|
| 853 | - * @since 1.0.19 |
|
| 854 | - * @param string $context View or edit context. |
|
| 855 | - * @return string |
|
| 856 | - */ |
|
| 857 | - public function get_customer_first_name( $context = 'view' ) { |
|
| 858 | - return $this->get_first_name( $context ); |
|
| 850 | + /** |
|
| 851 | + * Alias of self::get_first_name(). |
|
| 852 | + * |
|
| 853 | + * @since 1.0.19 |
|
| 854 | + * @param string $context View or edit context. |
|
| 855 | + * @return string |
|
| 856 | + */ |
|
| 857 | + public function get_customer_first_name( $context = 'view' ) { |
|
| 858 | + return $this->get_first_name( $context ); |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | /** |
| 862 | - * Get the customer's last name. |
|
| 863 | - * |
|
| 864 | - * @since 1.0.19 |
|
| 865 | - * @param string $context View or edit context. |
|
| 866 | - * @return string |
|
| 867 | - */ |
|
| 868 | - public function get_last_name( $context = 'view' ) { |
|
| 869 | - return $this->get_prop( 'last_name', $context ); |
|
| 862 | + * Get the customer's last name. |
|
| 863 | + * |
|
| 864 | + * @since 1.0.19 |
|
| 865 | + * @param string $context View or edit context. |
|
| 866 | + * @return string |
|
| 867 | + */ |
|
| 868 | + public function get_last_name( $context = 'view' ) { |
|
| 869 | + return $this->get_prop( 'last_name', $context ); |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | /** |
| 873 | - * Alias of self::get_last_name(). |
|
| 874 | - * |
|
| 875 | - * @since 1.0.19 |
|
| 876 | - * @param string $context View or edit context. |
|
| 877 | - * @return string |
|
| 878 | - */ |
|
| 879 | - public function get_user_last_name( $context = 'view' ) { |
|
| 880 | - return $this->get_last_name( $context ); |
|
| 873 | + * Alias of self::get_last_name(). |
|
| 874 | + * |
|
| 875 | + * @since 1.0.19 |
|
| 876 | + * @param string $context View or edit context. |
|
| 877 | + * @return string |
|
| 878 | + */ |
|
| 879 | + public function get_user_last_name( $context = 'view' ) { |
|
| 880 | + return $this->get_last_name( $context ); |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | /** |
| 884 | - * Alias of self::get_last_name(). |
|
| 885 | - * |
|
| 886 | - * @since 1.0.19 |
|
| 887 | - * @param string $context View or edit context. |
|
| 888 | - * @return string |
|
| 889 | - */ |
|
| 890 | - public function get_customer_last_name( $context = 'view' ) { |
|
| 891 | - return $this->get_last_name( $context ); |
|
| 884 | + * Alias of self::get_last_name(). |
|
| 885 | + * |
|
| 886 | + * @since 1.0.19 |
|
| 887 | + * @param string $context View or edit context. |
|
| 888 | + * @return string |
|
| 889 | + */ |
|
| 890 | + public function get_customer_last_name( $context = 'view' ) { |
|
| 891 | + return $this->get_last_name( $context ); |
|
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | /** |
| 895 | - * Get the customer's full name. |
|
| 896 | - * |
|
| 897 | - * @since 1.0.19 |
|
| 898 | - * @param string $context View or edit context. |
|
| 899 | - * @return string |
|
| 900 | - */ |
|
| 901 | - public function get_full_name( $context = 'view' ) { |
|
| 902 | - $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 895 | + * Get the customer's full name. |
|
| 896 | + * |
|
| 897 | + * @since 1.0.19 |
|
| 898 | + * @param string $context View or edit context. |
|
| 899 | + * @return string |
|
| 900 | + */ |
|
| 901 | + public function get_full_name( $context = 'view' ) { |
|
| 902 | + $name = trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
| 903 | 903 | |
| 904 | - if ( ! $name ) { |
|
| 905 | - $user = get_userdata( $this->get_author( $context ) ); |
|
| 904 | + if ( ! $name ) { |
|
| 905 | + $user = get_userdata( $this->get_author( $context ) ); |
|
| 906 | 906 | |
| 907 | - if ( $user ) { |
|
| 908 | - $name = $user->display_name; |
|
| 909 | - } |
|
| 910 | - } |
|
| 907 | + if ( $user ) { |
|
| 908 | + $name = $user->display_name; |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | - if ( ! $name ) { |
|
| 913 | - $name = $this->get_email( $context ); |
|
| 914 | - } |
|
| 912 | + if ( ! $name ) { |
|
| 913 | + $name = $this->get_email( $context ); |
|
| 914 | + } |
|
| 915 | 915 | |
| 916 | - return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
| 916 | + return apply_filters( 'wpinv_invoice_user_full_name', $name, $this ); |
|
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | /** |
| 920 | - * Alias of self::get_full_name(). |
|
| 921 | - * |
|
| 922 | - * @since 1.0.19 |
|
| 923 | - * @param string $context View or edit context. |
|
| 924 | - * @return string |
|
| 925 | - */ |
|
| 926 | - public function get_user_full_name( $context = 'view' ) { |
|
| 927 | - return $this->get_full_name( $context ); |
|
| 920 | + * Alias of self::get_full_name(). |
|
| 921 | + * |
|
| 922 | + * @since 1.0.19 |
|
| 923 | + * @param string $context View or edit context. |
|
| 924 | + * @return string |
|
| 925 | + */ |
|
| 926 | + public function get_user_full_name( $context = 'view' ) { |
|
| 927 | + return $this->get_full_name( $context ); |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | /** |
| 931 | - * Alias of self::get_full_name(). |
|
| 932 | - * |
|
| 933 | - * @since 1.0.19 |
|
| 934 | - * @param string $context View or edit context. |
|
| 935 | - * @return string |
|
| 936 | - */ |
|
| 937 | - public function get_customer_full_name( $context = 'view' ) { |
|
| 938 | - return $this->get_full_name( $context ); |
|
| 931 | + * Alias of self::get_full_name(). |
|
| 932 | + * |
|
| 933 | + * @since 1.0.19 |
|
| 934 | + * @param string $context View or edit context. |
|
| 935 | + * @return string |
|
| 936 | + */ |
|
| 937 | + public function get_customer_full_name( $context = 'view' ) { |
|
| 938 | + return $this->get_full_name( $context ); |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | /** |
| 942 | - * Get the customer's phone number. |
|
| 943 | - * |
|
| 944 | - * @since 1.0.19 |
|
| 945 | - * @param string $context View or edit context. |
|
| 946 | - * @return string |
|
| 947 | - */ |
|
| 948 | - public function get_phone( $context = 'view' ) { |
|
| 949 | - return $this->get_prop( 'phone', $context ); |
|
| 942 | + * Get the customer's phone number. |
|
| 943 | + * |
|
| 944 | + * @since 1.0.19 |
|
| 945 | + * @param string $context View or edit context. |
|
| 946 | + * @return string |
|
| 947 | + */ |
|
| 948 | + public function get_phone( $context = 'view' ) { |
|
| 949 | + return $this->get_prop( 'phone', $context ); |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | 952 | /** |
| 953 | - * Alias of self::get_phone(). |
|
| 954 | - * |
|
| 955 | - * @since 1.0.19 |
|
| 956 | - * @param string $context View or edit context. |
|
| 957 | - * @return string |
|
| 958 | - */ |
|
| 959 | - public function get_phone_number( $context = 'view' ) { |
|
| 960 | - return $this->get_phone( $context ); |
|
| 953 | + * Alias of self::get_phone(). |
|
| 954 | + * |
|
| 955 | + * @since 1.0.19 |
|
| 956 | + * @param string $context View or edit context. |
|
| 957 | + * @return string |
|
| 958 | + */ |
|
| 959 | + public function get_phone_number( $context = 'view' ) { |
|
| 960 | + return $this->get_phone( $context ); |
|
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | /** |
| 964 | - * Alias of self::get_phone(). |
|
| 965 | - * |
|
| 966 | - * @since 1.0.19 |
|
| 967 | - * @param string $context View or edit context. |
|
| 968 | - * @return string |
|
| 969 | - */ |
|
| 970 | - public function get_user_phone( $context = 'view' ) { |
|
| 971 | - return $this->get_phone( $context ); |
|
| 964 | + * Alias of self::get_phone(). |
|
| 965 | + * |
|
| 966 | + * @since 1.0.19 |
|
| 967 | + * @param string $context View or edit context. |
|
| 968 | + * @return string |
|
| 969 | + */ |
|
| 970 | + public function get_user_phone( $context = 'view' ) { |
|
| 971 | + return $this->get_phone( $context ); |
|
| 972 | + } |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * Alias of self::get_phone(). |
|
| 976 | + * |
|
| 977 | + * @since 1.0.19 |
|
| 978 | + * @param string $context View or edit context. |
|
| 979 | + * @return string |
|
| 980 | + */ |
|
| 981 | + public function get_customer_phone( $context = 'view' ) { |
|
| 982 | + return $this->get_phone( $context ); |
|
| 972 | 983 | } |
| 973 | 984 | |
| 974 | 985 | /** |
| 975 | - * Alias of self::get_phone(). |
|
| 976 | - * |
|
| 977 | - * @since 1.0.19 |
|
| 978 | - * @param string $context View or edit context. |
|
| 979 | - * @return string |
|
| 980 | - */ |
|
| 981 | - public function get_customer_phone( $context = 'view' ) { |
|
| 982 | - return $this->get_phone( $context ); |
|
| 986 | + * Get the customer's email address. |
|
| 987 | + * |
|
| 988 | + * @since 1.0.19 |
|
| 989 | + * @param string $context View or edit context. |
|
| 990 | + * @return string |
|
| 991 | + */ |
|
| 992 | + public function get_email( $context = 'view' ) { |
|
| 993 | + return $this->get_prop( 'email', $context ); |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + /** |
|
| 997 | + * Alias of self::get_email(). |
|
| 998 | + * |
|
| 999 | + * @since 1.0.19 |
|
| 1000 | + * @param string $context View or edit context. |
|
| 1001 | + * @return string |
|
| 1002 | + */ |
|
| 1003 | + public function get_email_address( $context = 'view' ) { |
|
| 1004 | + return $this->get_email( $context ); |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + /** |
|
| 1008 | + * Alias of self::get_email(). |
|
| 1009 | + * |
|
| 1010 | + * @since 1.0.19 |
|
| 1011 | + * @param string $context View or edit context. |
|
| 1012 | + * @return string |
|
| 1013 | + */ |
|
| 1014 | + public function get_user_email( $context = 'view' ) { |
|
| 1015 | + return $this->get_email( $context ); |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * Alias of self::get_email(). |
|
| 1020 | + * |
|
| 1021 | + * @since 1.0.19 |
|
| 1022 | + * @param string $context View or edit context. |
|
| 1023 | + * @return string |
|
| 1024 | + */ |
|
| 1025 | + public function get_customer_email( $context = 'view' ) { |
|
| 1026 | + return $this->get_email( $context ); |
|
| 983 | 1027 | } |
| 984 | 1028 | |
| 985 | 1029 | /** |
| 986 | - * Get the customer's email address. |
|
| 987 | - * |
|
| 988 | - * @since 1.0.19 |
|
| 989 | - * @param string $context View or edit context. |
|
| 990 | - * @return string |
|
| 991 | - */ |
|
| 992 | - public function get_email( $context = 'view' ) { |
|
| 993 | - return $this->get_prop( 'email', $context ); |
|
| 1030 | + * Get the customer's country. |
|
| 1031 | + * |
|
| 1032 | + * @since 1.0.19 |
|
| 1033 | + * @param string $context View or edit context. |
|
| 1034 | + * @return string |
|
| 1035 | + */ |
|
| 1036 | + public function get_country( $context = 'view' ) { |
|
| 1037 | + $country = $this->get_prop( 'country', $context ); |
|
| 1038 | + return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 994 | 1039 | } |
| 995 | 1040 | |
| 996 | 1041 | /** |
| 997 | - * Alias of self::get_email(). |
|
| 998 | - * |
|
| 999 | - * @since 1.0.19 |
|
| 1000 | - * @param string $context View or edit context. |
|
| 1001 | - * @return string |
|
| 1002 | - */ |
|
| 1003 | - public function get_email_address( $context = 'view' ) { |
|
| 1004 | - return $this->get_email( $context ); |
|
| 1042 | + * Alias of self::get_country(). |
|
| 1043 | + * |
|
| 1044 | + * @since 1.0.19 |
|
| 1045 | + * @param string $context View or edit context. |
|
| 1046 | + * @return string |
|
| 1047 | + */ |
|
| 1048 | + public function get_user_country( $context = 'view' ) { |
|
| 1049 | + return $this->get_country( $context ); |
|
| 1005 | 1050 | } |
| 1006 | 1051 | |
| 1007 | 1052 | /** |
| 1008 | - * Alias of self::get_email(). |
|
| 1009 | - * |
|
| 1010 | - * @since 1.0.19 |
|
| 1011 | - * @param string $context View or edit context. |
|
| 1012 | - * @return string |
|
| 1013 | - */ |
|
| 1014 | - public function get_user_email( $context = 'view' ) { |
|
| 1015 | - return $this->get_email( $context ); |
|
| 1053 | + * Alias of self::get_country(). |
|
| 1054 | + * |
|
| 1055 | + * @since 1.0.19 |
|
| 1056 | + * @param string $context View or edit context. |
|
| 1057 | + * @return string |
|
| 1058 | + */ |
|
| 1059 | + public function get_customer_country( $context = 'view' ) { |
|
| 1060 | + return $this->get_country( $context ); |
|
| 1016 | 1061 | } |
| 1017 | 1062 | |
| 1018 | 1063 | /** |
| 1019 | - * Alias of self::get_email(). |
|
| 1020 | - * |
|
| 1021 | - * @since 1.0.19 |
|
| 1022 | - * @param string $context View or edit context. |
|
| 1023 | - * @return string |
|
| 1024 | - */ |
|
| 1025 | - public function get_customer_email( $context = 'view' ) { |
|
| 1026 | - return $this->get_email( $context ); |
|
| 1064 | + * Get the customer's state. |
|
| 1065 | + * |
|
| 1066 | + * @since 1.0.19 |
|
| 1067 | + * @param string $context View or edit context. |
|
| 1068 | + * @return string |
|
| 1069 | + */ |
|
| 1070 | + public function get_state( $context = 'view' ) { |
|
| 1071 | + $state = $this->get_prop( 'state', $context ); |
|
| 1072 | + return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1027 | 1073 | } |
| 1028 | 1074 | |
| 1029 | 1075 | /** |
| 1030 | - * Get the customer's country. |
|
| 1031 | - * |
|
| 1032 | - * @since 1.0.19 |
|
| 1033 | - * @param string $context View or edit context. |
|
| 1034 | - * @return string |
|
| 1035 | - */ |
|
| 1036 | - public function get_country( $context = 'view' ) { |
|
| 1037 | - $country = $this->get_prop( 'country', $context ); |
|
| 1038 | - return empty( $country ) ? wpinv_get_default_country() : $country; |
|
| 1076 | + * Alias of self::get_state(). |
|
| 1077 | + * |
|
| 1078 | + * @since 1.0.19 |
|
| 1079 | + * @param string $context View or edit context. |
|
| 1080 | + * @return string |
|
| 1081 | + */ |
|
| 1082 | + public function get_user_state( $context = 'view' ) { |
|
| 1083 | + return $this->get_state( $context ); |
|
| 1039 | 1084 | } |
| 1040 | 1085 | |
| 1041 | 1086 | /** |
| 1042 | - * Alias of self::get_country(). |
|
| 1043 | - * |
|
| 1044 | - * @since 1.0.19 |
|
| 1045 | - * @param string $context View or edit context. |
|
| 1046 | - * @return string |
|
| 1047 | - */ |
|
| 1048 | - public function get_user_country( $context = 'view' ) { |
|
| 1049 | - return $this->get_country( $context ); |
|
| 1087 | + * Alias of self::get_state(). |
|
| 1088 | + * |
|
| 1089 | + * @since 1.0.19 |
|
| 1090 | + * @param string $context View or edit context. |
|
| 1091 | + * @return string |
|
| 1092 | + */ |
|
| 1093 | + public function get_customer_state( $context = 'view' ) { |
|
| 1094 | + return $this->get_state( $context ); |
|
| 1050 | 1095 | } |
| 1051 | 1096 | |
| 1052 | 1097 | /** |
| 1053 | - * Alias of self::get_country(). |
|
| 1054 | - * |
|
| 1055 | - * @since 1.0.19 |
|
| 1056 | - * @param string $context View or edit context. |
|
| 1057 | - * @return string |
|
| 1058 | - */ |
|
| 1059 | - public function get_customer_country( $context = 'view' ) { |
|
| 1060 | - return $this->get_country( $context ); |
|
| 1098 | + * Get the customer's city. |
|
| 1099 | + * |
|
| 1100 | + * @since 1.0.19 |
|
| 1101 | + * @param string $context View or edit context. |
|
| 1102 | + * @return string |
|
| 1103 | + */ |
|
| 1104 | + public function get_city( $context = 'view' ) { |
|
| 1105 | + return $this->get_prop( 'city', $context ); |
|
| 1061 | 1106 | } |
| 1062 | 1107 | |
| 1063 | 1108 | /** |
| 1064 | - * Get the customer's state. |
|
| 1065 | - * |
|
| 1066 | - * @since 1.0.19 |
|
| 1067 | - * @param string $context View or edit context. |
|
| 1068 | - * @return string |
|
| 1069 | - */ |
|
| 1070 | - public function get_state( $context = 'view' ) { |
|
| 1071 | - $state = $this->get_prop( 'state', $context ); |
|
| 1072 | - return empty( $state ) ? wpinv_get_default_state() : $state; |
|
| 1109 | + * Alias of self::get_city(). |
|
| 1110 | + * |
|
| 1111 | + * @since 1.0.19 |
|
| 1112 | + * @param string $context View or edit context. |
|
| 1113 | + * @return string |
|
| 1114 | + */ |
|
| 1115 | + public function get_user_city( $context = 'view' ) { |
|
| 1116 | + return $this->get_city( $context ); |
|
| 1073 | 1117 | } |
| 1074 | 1118 | |
| 1075 | 1119 | /** |
| 1076 | - * Alias of self::get_state(). |
|
| 1077 | - * |
|
| 1078 | - * @since 1.0.19 |
|
| 1079 | - * @param string $context View or edit context. |
|
| 1080 | - * @return string |
|
| 1081 | - */ |
|
| 1082 | - public function get_user_state( $context = 'view' ) { |
|
| 1083 | - return $this->get_state( $context ); |
|
| 1120 | + * Alias of self::get_city(). |
|
| 1121 | + * |
|
| 1122 | + * @since 1.0.19 |
|
| 1123 | + * @param string $context View or edit context. |
|
| 1124 | + * @return string |
|
| 1125 | + */ |
|
| 1126 | + public function get_customer_city( $context = 'view' ) { |
|
| 1127 | + return $this->get_city( $context ); |
|
| 1128 | + } |
|
| 1129 | + |
|
| 1130 | + /** |
|
| 1131 | + * Get the customer's zip. |
|
| 1132 | + * |
|
| 1133 | + * @since 1.0.19 |
|
| 1134 | + * @param string $context View or edit context. |
|
| 1135 | + * @return string |
|
| 1136 | + */ |
|
| 1137 | + public function get_zip( $context = 'view' ) { |
|
| 1138 | + return $this->get_prop( 'zip', $context ); |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + /** |
|
| 1142 | + * Alias of self::get_zip(). |
|
| 1143 | + * |
|
| 1144 | + * @since 1.0.19 |
|
| 1145 | + * @param string $context View or edit context. |
|
| 1146 | + * @return string |
|
| 1147 | + */ |
|
| 1148 | + public function get_user_zip( $context = 'view' ) { |
|
| 1149 | + return $this->get_zip( $context ); |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * Alias of self::get_zip(). |
|
| 1154 | + * |
|
| 1155 | + * @since 1.0.19 |
|
| 1156 | + * @param string $context View or edit context. |
|
| 1157 | + * @return string |
|
| 1158 | + */ |
|
| 1159 | + public function get_customer_zip( $context = 'view' ) { |
|
| 1160 | + return $this->get_zip( $context ); |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + /** |
|
| 1164 | + * Get the customer's company. |
|
| 1165 | + * |
|
| 1166 | + * @since 1.0.19 |
|
| 1167 | + * @param string $context View or edit context. |
|
| 1168 | + * @return string |
|
| 1169 | + */ |
|
| 1170 | + public function get_company( $context = 'view' ) { |
|
| 1171 | + return $this->get_prop( 'company', $context ); |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + /** |
|
| 1175 | + * Alias of self::get_company(). |
|
| 1176 | + * |
|
| 1177 | + * @since 1.0.19 |
|
| 1178 | + * @param string $context View or edit context. |
|
| 1179 | + * @return string |
|
| 1180 | + */ |
|
| 1181 | + public function get_user_company( $context = 'view' ) { |
|
| 1182 | + return $this->get_company( $context ); |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * Alias of self::get_company(). |
|
| 1187 | + * |
|
| 1188 | + * @since 1.0.19 |
|
| 1189 | + * @param string $context View or edit context. |
|
| 1190 | + * @return string |
|
| 1191 | + */ |
|
| 1192 | + public function get_customer_company( $context = 'view' ) { |
|
| 1193 | + return $this->get_company( $context ); |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * Get the customer's company id. |
|
| 1198 | + * |
|
| 1199 | + * @since 1.0.19 |
|
| 1200 | + * @param string $context View or edit context. |
|
| 1201 | + * @return string |
|
| 1202 | + */ |
|
| 1203 | + public function get_company_id( $context = 'view' ) { |
|
| 1204 | + return $this->get_prop( 'company_id', $context ); |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + /** |
|
| 1208 | + * Get the customer's vat number. |
|
| 1209 | + * |
|
| 1210 | + * @since 1.0.19 |
|
| 1211 | + * @param string $context View or edit context. |
|
| 1212 | + * @return string |
|
| 1213 | + */ |
|
| 1214 | + public function get_vat_number( $context = 'view' ) { |
|
| 1215 | + return $this->get_prop( 'vat_number', $context ); |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * Alias of self::get_vat_number(). |
|
| 1220 | + * |
|
| 1221 | + * @since 1.0.19 |
|
| 1222 | + * @param string $context View or edit context. |
|
| 1223 | + * @return string |
|
| 1224 | + */ |
|
| 1225 | + public function get_user_vat_number( $context = 'view' ) { |
|
| 1226 | + return $this->get_vat_number( $context ); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * Alias of self::get_vat_number(). |
|
| 1231 | + * |
|
| 1232 | + * @since 1.0.19 |
|
| 1233 | + * @param string $context View or edit context. |
|
| 1234 | + * @return string |
|
| 1235 | + */ |
|
| 1236 | + public function get_customer_vat_number( $context = 'view' ) { |
|
| 1237 | + return $this->get_vat_number( $context ); |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * Get the customer's vat rate. |
|
| 1242 | + * |
|
| 1243 | + * @since 1.0.19 |
|
| 1244 | + * @param string $context View or edit context. |
|
| 1245 | + * @return string |
|
| 1246 | + */ |
|
| 1247 | + public function get_vat_rate( $context = 'view' ) { |
|
| 1248 | + return $this->get_prop( 'vat_rate', $context ); |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + /** |
|
| 1252 | + * Alias of self::get_vat_rate(). |
|
| 1253 | + * |
|
| 1254 | + * @since 1.0.19 |
|
| 1255 | + * @param string $context View or edit context. |
|
| 1256 | + * @return string |
|
| 1257 | + */ |
|
| 1258 | + public function get_user_vat_rate( $context = 'view' ) { |
|
| 1259 | + return $this->get_vat_rate( $context ); |
|
| 1084 | 1260 | } |
| 1085 | 1261 | |
| 1086 | 1262 | /** |
| 1087 | - * Alias of self::get_state(). |
|
| 1088 | - * |
|
| 1089 | - * @since 1.0.19 |
|
| 1090 | - * @param string $context View or edit context. |
|
| 1091 | - * @return string |
|
| 1092 | - */ |
|
| 1093 | - public function get_customer_state( $context = 'view' ) { |
|
| 1094 | - return $this->get_state( $context ); |
|
| 1263 | + * Alias of self::get_vat_rate(). |
|
| 1264 | + * |
|
| 1265 | + * @since 1.0.19 |
|
| 1266 | + * @param string $context View or edit context. |
|
| 1267 | + * @return string |
|
| 1268 | + */ |
|
| 1269 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1270 | + return $this->get_vat_rate( $context ); |
|
| 1095 | 1271 | } |
| 1096 | 1272 | |
| 1097 | 1273 | /** |
| 1098 | - * Get the customer's city. |
|
| 1099 | - * |
|
| 1100 | - * @since 1.0.19 |
|
| 1101 | - * @param string $context View or edit context. |
|
| 1102 | - * @return string |
|
| 1103 | - */ |
|
| 1104 | - public function get_city( $context = 'view' ) { |
|
| 1105 | - return $this->get_prop( 'city', $context ); |
|
| 1274 | + * Get the customer's address. |
|
| 1275 | + * |
|
| 1276 | + * @since 1.0.19 |
|
| 1277 | + * @param string $context View or edit context. |
|
| 1278 | + * @return string |
|
| 1279 | + */ |
|
| 1280 | + public function get_address( $context = 'view' ) { |
|
| 1281 | + return $this->get_prop( 'address', $context ); |
|
| 1106 | 1282 | } |
| 1107 | 1283 | |
| 1108 | 1284 | /** |
| 1109 | - * Alias of self::get_city(). |
|
| 1110 | - * |
|
| 1111 | - * @since 1.0.19 |
|
| 1112 | - * @param string $context View or edit context. |
|
| 1113 | - * @return string |
|
| 1114 | - */ |
|
| 1115 | - public function get_user_city( $context = 'view' ) { |
|
| 1116 | - return $this->get_city( $context ); |
|
| 1285 | + * Alias of self::get_address(). |
|
| 1286 | + * |
|
| 1287 | + * @since 1.0.19 |
|
| 1288 | + * @param string $context View or edit context. |
|
| 1289 | + * @return string |
|
| 1290 | + */ |
|
| 1291 | + public function get_user_address( $context = 'view' ) { |
|
| 1292 | + return $this->get_address( $context ); |
|
| 1117 | 1293 | } |
| 1118 | 1294 | |
| 1119 | 1295 | /** |
| 1120 | - * Alias of self::get_city(). |
|
| 1121 | - * |
|
| 1122 | - * @since 1.0.19 |
|
| 1123 | - * @param string $context View or edit context. |
|
| 1124 | - * @return string |
|
| 1125 | - */ |
|
| 1126 | - public function get_customer_city( $context = 'view' ) { |
|
| 1127 | - return $this->get_city( $context ); |
|
| 1296 | + * Alias of self::get_address(). |
|
| 1297 | + * |
|
| 1298 | + * @since 1.0.19 |
|
| 1299 | + * @param string $context View or edit context. |
|
| 1300 | + * @return string |
|
| 1301 | + */ |
|
| 1302 | + public function get_customer_address( $context = 'view' ) { |
|
| 1303 | + return $this->get_address( $context ); |
|
| 1128 | 1304 | } |
| 1129 | 1305 | |
| 1130 | 1306 | /** |
| 1131 | - * Get the customer's zip. |
|
| 1132 | - * |
|
| 1133 | - * @since 1.0.19 |
|
| 1134 | - * @param string $context View or edit context. |
|
| 1135 | - * @return string |
|
| 1136 | - */ |
|
| 1137 | - public function get_zip( $context = 'view' ) { |
|
| 1138 | - return $this->get_prop( 'zip', $context ); |
|
| 1307 | + * Get whether the customer has viewed the invoice or not. |
|
| 1308 | + * |
|
| 1309 | + * @since 1.0.19 |
|
| 1310 | + * @param string $context View or edit context. |
|
| 1311 | + * @return bool |
|
| 1312 | + */ |
|
| 1313 | + public function get_is_viewed( $context = 'view' ) { |
|
| 1314 | + return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1139 | 1315 | } |
| 1140 | 1316 | |
| 1141 | 1317 | /** |
| 1142 | - * Alias of self::get_zip(). |
|
| 1143 | - * |
|
| 1144 | - * @since 1.0.19 |
|
| 1145 | - * @param string $context View or edit context. |
|
| 1146 | - * @return string |
|
| 1147 | - */ |
|
| 1148 | - public function get_user_zip( $context = 'view' ) { |
|
| 1149 | - return $this->get_zip( $context ); |
|
| 1318 | + * Get other recipients for invoice communications. |
|
| 1319 | + * |
|
| 1320 | + * @since 1.0.19 |
|
| 1321 | + * @param string $context View or edit context. |
|
| 1322 | + * @return bool |
|
| 1323 | + */ |
|
| 1324 | + public function get_email_cc( $context = 'view' ) { |
|
| 1325 | + return $this->get_prop( 'email_cc', $context ); |
|
| 1150 | 1326 | } |
| 1151 | 1327 | |
| 1152 | 1328 | /** |
| 1153 | - * Alias of self::get_zip(). |
|
| 1154 | - * |
|
| 1155 | - * @since 1.0.19 |
|
| 1156 | - * @param string $context View or edit context. |
|
| 1157 | - * @return string |
|
| 1158 | - */ |
|
| 1159 | - public function get_customer_zip( $context = 'view' ) { |
|
| 1160 | - return $this->get_zip( $context ); |
|
| 1329 | + * Get invoice template. |
|
| 1330 | + * |
|
| 1331 | + * @since 1.0.19 |
|
| 1332 | + * @param string $context View or edit context. |
|
| 1333 | + * @return bool |
|
| 1334 | + */ |
|
| 1335 | + public function get_template( $context = 'view' ) { |
|
| 1336 | + return $this->get_prop( 'template', $context ); |
|
| 1161 | 1337 | } |
| 1162 | 1338 | |
| 1163 | 1339 | /** |
| 1164 | - * Get the customer's company. |
|
| 1165 | - * |
|
| 1166 | - * @since 1.0.19 |
|
| 1167 | - * @param string $context View or edit context. |
|
| 1168 | - * @return string |
|
| 1169 | - */ |
|
| 1170 | - public function get_company( $context = 'view' ) { |
|
| 1171 | - return $this->get_prop( 'company', $context ); |
|
| 1340 | + * Get invoice source. |
|
| 1341 | + * |
|
| 1342 | + * @since 1.0.19 |
|
| 1343 | + * @param string $context View or edit context. |
|
| 1344 | + * @return bool |
|
| 1345 | + */ |
|
| 1346 | + public function get_created_via( $context = 'view' ) { |
|
| 1347 | + return $this->get_prop( 'created_via', $context ); |
|
| 1172 | 1348 | } |
| 1173 | 1349 | |
| 1174 | 1350 | /** |
| 1175 | - * Alias of self::get_company(). |
|
| 1176 | - * |
|
| 1177 | - * @since 1.0.19 |
|
| 1178 | - * @param string $context View or edit context. |
|
| 1179 | - * @return string |
|
| 1180 | - */ |
|
| 1181 | - public function get_user_company( $context = 'view' ) { |
|
| 1182 | - return $this->get_company( $context ); |
|
| 1351 | + * Get whether the customer has confirmed their address. |
|
| 1352 | + * |
|
| 1353 | + * @since 1.0.19 |
|
| 1354 | + * @param string $context View or edit context. |
|
| 1355 | + * @return bool |
|
| 1356 | + */ |
|
| 1357 | + public function get_address_confirmed( $context = 'view' ) { |
|
| 1358 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1183 | 1359 | } |
| 1184 | 1360 | |
| 1185 | 1361 | /** |
| 1186 | - * Alias of self::get_company(). |
|
| 1187 | - * |
|
| 1188 | - * @since 1.0.19 |
|
| 1189 | - * @param string $context View or edit context. |
|
| 1190 | - * @return string |
|
| 1191 | - */ |
|
| 1192 | - public function get_customer_company( $context = 'view' ) { |
|
| 1193 | - return $this->get_company( $context ); |
|
| 1362 | + * Alias of self::get_address_confirmed(). |
|
| 1363 | + * |
|
| 1364 | + * @since 1.0.19 |
|
| 1365 | + * @param string $context View or edit context. |
|
| 1366 | + * @return bool |
|
| 1367 | + */ |
|
| 1368 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1369 | + return $this->get_address_confirmed( $context ); |
|
| 1194 | 1370 | } |
| 1195 | 1371 | |
| 1196 | - /** |
|
| 1197 | - * Get the customer's company id. |
|
| 1198 | - * |
|
| 1199 | - * @since 1.0.19 |
|
| 1200 | - * @param string $context View or edit context. |
|
| 1201 | - * @return string |
|
| 1202 | - */ |
|
| 1203 | - public function get_company_id( $context = 'view' ) { |
|
| 1204 | - return $this->get_prop( 'company_id', $context ); |
|
| 1372 | + /** |
|
| 1373 | + * Alias of self::get_address(). |
|
| 1374 | + * |
|
| 1375 | + * @since 1.0.19 |
|
| 1376 | + * @param string $context View or edit context. |
|
| 1377 | + * @return bool |
|
| 1378 | + */ |
|
| 1379 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1380 | + return $this->get_address_confirmed( $context ); |
|
| 1205 | 1381 | } |
| 1206 | 1382 | |
| 1207 | 1383 | /** |
| 1208 | - * Get the customer's vat number. |
|
| 1209 | - * |
|
| 1210 | - * @since 1.0.19 |
|
| 1211 | - * @param string $context View or edit context. |
|
| 1212 | - * @return string |
|
| 1213 | - */ |
|
| 1214 | - public function get_vat_number( $context = 'view' ) { |
|
| 1215 | - return $this->get_prop( 'vat_number', $context ); |
|
| 1384 | + * Get the shipping address. |
|
| 1385 | + * |
|
| 1386 | + * @since 1.0.19 |
|
| 1387 | + * @return array|false |
|
| 1388 | + */ |
|
| 1389 | + public function get_shipping_address() { |
|
| 1390 | + |
|
| 1391 | + $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
| 1392 | + return is_array( $shipping_address ) ? $shipping_address : false; |
|
| 1216 | 1393 | } |
| 1217 | 1394 | |
| 1218 | 1395 | /** |
| 1219 | - * Alias of self::get_vat_number(). |
|
| 1220 | - * |
|
| 1221 | - * @since 1.0.19 |
|
| 1222 | - * @param string $context View or edit context. |
|
| 1223 | - * @return string |
|
| 1224 | - */ |
|
| 1225 | - public function get_user_vat_number( $context = 'view' ) { |
|
| 1226 | - return $this->get_vat_number( $context ); |
|
| 1396 | + * Check if the invoice has a shipping address. |
|
| 1397 | + */ |
|
| 1398 | + public function has_shipping_address() { |
|
| 1399 | + return false !== $this->get_shipping_address(); |
|
| 1227 | 1400 | } |
| 1228 | 1401 | |
| 1229 | 1402 | /** |
| 1230 | - * Alias of self::get_vat_number(). |
|
| 1231 | - * |
|
| 1232 | - * @since 1.0.19 |
|
| 1233 | - * @param string $context View or edit context. |
|
| 1234 | - * @return string |
|
| 1235 | - */ |
|
| 1236 | - public function get_customer_vat_number( $context = 'view' ) { |
|
| 1237 | - return $this->get_vat_number( $context ); |
|
| 1403 | + * Get the shipping amount. |
|
| 1404 | + * |
|
| 1405 | + * @since 1.0.19 |
|
| 1406 | + * @param string $context View or edit context. |
|
| 1407 | + * @return float |
|
| 1408 | + */ |
|
| 1409 | + public function get_shipping( $context = 'view' ) { |
|
| 1410 | + |
|
| 1411 | + if ( $context = 'view' ) { |
|
| 1412 | + return floatval( $this->get_prop( 'shipping', $context ) ); |
|
| 1413 | + } |
|
| 1414 | + |
|
| 1415 | + return $this->get_prop( 'shipping', $context ); |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + public function has_shipping() { |
|
| 1419 | + return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
| 1238 | 1420 | } |
| 1239 | 1421 | |
| 1240 | - /** |
|
| 1241 | - * Get the customer's vat rate. |
|
| 1242 | - * |
|
| 1243 | - * @since 1.0.19 |
|
| 1244 | - * @param string $context View or edit context. |
|
| 1245 | - * @return string |
|
| 1246 | - */ |
|
| 1247 | - public function get_vat_rate( $context = 'view' ) { |
|
| 1248 | - return $this->get_prop( 'vat_rate', $context ); |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - /** |
|
| 1252 | - * Alias of self::get_vat_rate(). |
|
| 1253 | - * |
|
| 1254 | - * @since 1.0.19 |
|
| 1255 | - * @param string $context View or edit context. |
|
| 1256 | - * @return string |
|
| 1257 | - */ |
|
| 1258 | - public function get_user_vat_rate( $context = 'view' ) { |
|
| 1259 | - return $this->get_vat_rate( $context ); |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - /** |
|
| 1263 | - * Alias of self::get_vat_rate(). |
|
| 1264 | - * |
|
| 1265 | - * @since 1.0.19 |
|
| 1266 | - * @param string $context View or edit context. |
|
| 1267 | - * @return string |
|
| 1268 | - */ |
|
| 1269 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
| 1270 | - return $this->get_vat_rate( $context ); |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * Get the customer's address. |
|
| 1275 | - * |
|
| 1276 | - * @since 1.0.19 |
|
| 1277 | - * @param string $context View or edit context. |
|
| 1278 | - * @return string |
|
| 1279 | - */ |
|
| 1280 | - public function get_address( $context = 'view' ) { |
|
| 1281 | - return $this->get_prop( 'address', $context ); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - /** |
|
| 1285 | - * Alias of self::get_address(). |
|
| 1286 | - * |
|
| 1287 | - * @since 1.0.19 |
|
| 1288 | - * @param string $context View or edit context. |
|
| 1289 | - * @return string |
|
| 1290 | - */ |
|
| 1291 | - public function get_user_address( $context = 'view' ) { |
|
| 1292 | - return $this->get_address( $context ); |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - /** |
|
| 1296 | - * Alias of self::get_address(). |
|
| 1297 | - * |
|
| 1298 | - * @since 1.0.19 |
|
| 1299 | - * @param string $context View or edit context. |
|
| 1300 | - * @return string |
|
| 1301 | - */ |
|
| 1302 | - public function get_customer_address( $context = 'view' ) { |
|
| 1303 | - return $this->get_address( $context ); |
|
| 1304 | - } |
|
| 1305 | - |
|
| 1306 | - /** |
|
| 1307 | - * Get whether the customer has viewed the invoice or not. |
|
| 1308 | - * |
|
| 1309 | - * @since 1.0.19 |
|
| 1310 | - * @param string $context View or edit context. |
|
| 1311 | - * @return bool |
|
| 1312 | - */ |
|
| 1313 | - public function get_is_viewed( $context = 'view' ) { |
|
| 1314 | - return (bool) $this->get_prop( 'is_viewed', $context ); |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * Get other recipients for invoice communications. |
|
| 1319 | - * |
|
| 1320 | - * @since 1.0.19 |
|
| 1321 | - * @param string $context View or edit context. |
|
| 1322 | - * @return bool |
|
| 1323 | - */ |
|
| 1324 | - public function get_email_cc( $context = 'view' ) { |
|
| 1325 | - return $this->get_prop( 'email_cc', $context ); |
|
| 1326 | - } |
|
| 1327 | - |
|
| 1328 | - /** |
|
| 1329 | - * Get invoice template. |
|
| 1330 | - * |
|
| 1331 | - * @since 1.0.19 |
|
| 1332 | - * @param string $context View or edit context. |
|
| 1333 | - * @return bool |
|
| 1334 | - */ |
|
| 1335 | - public function get_template( $context = 'view' ) { |
|
| 1336 | - return $this->get_prop( 'template', $context ); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * Get invoice source. |
|
| 1341 | - * |
|
| 1342 | - * @since 1.0.19 |
|
| 1343 | - * @param string $context View or edit context. |
|
| 1344 | - * @return bool |
|
| 1345 | - */ |
|
| 1346 | - public function get_created_via( $context = 'view' ) { |
|
| 1347 | - return $this->get_prop( 'created_via', $context ); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - /** |
|
| 1351 | - * Get whether the customer has confirmed their address. |
|
| 1352 | - * |
|
| 1353 | - * @since 1.0.19 |
|
| 1354 | - * @param string $context View or edit context. |
|
| 1355 | - * @return bool |
|
| 1356 | - */ |
|
| 1357 | - public function get_address_confirmed( $context = 'view' ) { |
|
| 1358 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - /** |
|
| 1362 | - * Alias of self::get_address_confirmed(). |
|
| 1363 | - * |
|
| 1364 | - * @since 1.0.19 |
|
| 1365 | - * @param string $context View or edit context. |
|
| 1366 | - * @return bool |
|
| 1367 | - */ |
|
| 1368 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
| 1369 | - return $this->get_address_confirmed( $context ); |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - /** |
|
| 1373 | - * Alias of self::get_address(). |
|
| 1374 | - * |
|
| 1375 | - * @since 1.0.19 |
|
| 1376 | - * @param string $context View or edit context. |
|
| 1377 | - * @return bool |
|
| 1378 | - */ |
|
| 1379 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
| 1380 | - return $this->get_address_confirmed( $context ); |
|
| 1381 | - } |
|
| 1382 | - |
|
| 1383 | - /** |
|
| 1384 | - * Get the shipping address. |
|
| 1385 | - * |
|
| 1386 | - * @since 1.0.19 |
|
| 1387 | - * @return array|false |
|
| 1388 | - */ |
|
| 1389 | - public function get_shipping_address() { |
|
| 1390 | - |
|
| 1391 | - $shipping_address = get_post_meta( $this->get_id(), 'shipping_address', true ); |
|
| 1392 | - return is_array( $shipping_address ) ? $shipping_address : false; |
|
| 1393 | - } |
|
| 1394 | - |
|
| 1395 | - /** |
|
| 1396 | - * Check if the invoice has a shipping address. |
|
| 1397 | - */ |
|
| 1398 | - public function has_shipping_address() { |
|
| 1399 | - return false !== $this->get_shipping_address(); |
|
| 1400 | - } |
|
| 1401 | - |
|
| 1402 | - /** |
|
| 1403 | - * Get the shipping amount. |
|
| 1404 | - * |
|
| 1405 | - * @since 1.0.19 |
|
| 1406 | - * @param string $context View or edit context. |
|
| 1407 | - * @return float |
|
| 1408 | - */ |
|
| 1409 | - public function get_shipping( $context = 'view' ) { |
|
| 1410 | - |
|
| 1411 | - if ( $context = 'view' ) { |
|
| 1412 | - return floatval( $this->get_prop( 'shipping', $context ) ); |
|
| 1413 | - } |
|
| 1414 | - |
|
| 1415 | - return $this->get_prop( 'shipping', $context ); |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - public function has_shipping() { |
|
| 1419 | - return defined( 'GETPAID_SHIPPING_CALCULATOR_VERSION' ) && null !== $this->get_prop( 'shipping', 'edit' ); |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - /** |
|
| 1423 | - * Get the invoice subtotal. |
|
| 1424 | - * |
|
| 1425 | - * @since 1.0.19 |
|
| 1426 | - * @param string $context View or edit context. |
|
| 1427 | - * @return float |
|
| 1428 | - */ |
|
| 1429 | - public function get_subtotal( $context = 'view' ) { |
|
| 1422 | + /** |
|
| 1423 | + * Get the invoice subtotal. |
|
| 1424 | + * |
|
| 1425 | + * @since 1.0.19 |
|
| 1426 | + * @param string $context View or edit context. |
|
| 1427 | + * @return float |
|
| 1428 | + */ |
|
| 1429 | + public function get_subtotal( $context = 'view' ) { |
|
| 1430 | 1430 | $subtotal = (float) $this->get_prop( 'subtotal', $context ); |
| 1431 | 1431 | |
| 1432 | 1432 | // Backwards compatibility. |
@@ -1438,198 +1438,198 @@ discard block |
||
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | 1440 | /** |
| 1441 | - * Get the invoice discount total. |
|
| 1442 | - * |
|
| 1443 | - * @since 1.0.19 |
|
| 1444 | - * @param string $context View or edit context. |
|
| 1445 | - * @return float |
|
| 1446 | - */ |
|
| 1447 | - public function get_total_discount( $context = 'view' ) { |
|
| 1448 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
| 1441 | + * Get the invoice discount total. |
|
| 1442 | + * |
|
| 1443 | + * @since 1.0.19 |
|
| 1444 | + * @param string $context View or edit context. |
|
| 1445 | + * @return float |
|
| 1446 | + */ |
|
| 1447 | + public function get_total_discount( $context = 'view' ) { |
|
| 1448 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_discount', $context ) ) ); |
|
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | 1451 | /** |
| 1452 | - * Get the invoice tax total. |
|
| 1453 | - * |
|
| 1454 | - * @since 1.0.19 |
|
| 1455 | - * @param string $context View or edit context. |
|
| 1456 | - * @return float |
|
| 1457 | - */ |
|
| 1458 | - public function get_total_tax( $context = 'view' ) { |
|
| 1459 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
| 1460 | - } |
|
| 1452 | + * Get the invoice tax total. |
|
| 1453 | + * |
|
| 1454 | + * @since 1.0.19 |
|
| 1455 | + * @param string $context View or edit context. |
|
| 1456 | + * @return float |
|
| 1457 | + */ |
|
| 1458 | + public function get_total_tax( $context = 'view' ) { |
|
| 1459 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_tax', $context ) ) ); |
|
| 1460 | + } |
|
| 1461 | 1461 | |
| 1462 | - /** |
|
| 1463 | - * @deprecated |
|
| 1464 | - */ |
|
| 1465 | - public function get_final_tax( $currency = false ) { |
|
| 1466 | - $tax = $this->get_total_tax(); |
|
| 1462 | + /** |
|
| 1463 | + * @deprecated |
|
| 1464 | + */ |
|
| 1465 | + public function get_final_tax( $currency = false ) { |
|
| 1466 | + $tax = $this->get_total_tax(); |
|
| 1467 | 1467 | |
| 1468 | 1468 | if ( $currency ) { |
| 1469 | - return wpinv_price( $tax, $this->get_currency() ); |
|
| 1469 | + return wpinv_price( $tax, $this->get_currency() ); |
|
| 1470 | 1470 | } |
| 1471 | 1471 | |
| 1472 | 1472 | return $tax; |
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 1475 | 1475 | /** |
| 1476 | - * Get the invoice fees total. |
|
| 1477 | - * |
|
| 1478 | - * @since 1.0.19 |
|
| 1479 | - * @param string $context View or edit context. |
|
| 1480 | - * @return float |
|
| 1481 | - */ |
|
| 1482 | - public function get_total_fees( $context = 'view' ) { |
|
| 1483 | - return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
| 1476 | + * Get the invoice fees total. |
|
| 1477 | + * |
|
| 1478 | + * @since 1.0.19 |
|
| 1479 | + * @param string $context View or edit context. |
|
| 1480 | + * @return float |
|
| 1481 | + */ |
|
| 1482 | + public function get_total_fees( $context = 'view' ) { |
|
| 1483 | + return wpinv_round_amount( wpinv_sanitize_amount( $this->get_prop( 'total_fees', $context ) ) ); |
|
| 1484 | 1484 | } |
| 1485 | 1485 | |
| 1486 | 1486 | /** |
| 1487 | - * Alias for self::get_total_fees(). |
|
| 1488 | - * |
|
| 1489 | - * @since 1.0.19 |
|
| 1490 | - * @param string $context View or edit context. |
|
| 1491 | - * @return float |
|
| 1492 | - */ |
|
| 1493 | - public function get_fees_total( $context = 'view' ) { |
|
| 1494 | - return $this->get_total_fees( $context ); |
|
| 1487 | + * Alias for self::get_total_fees(). |
|
| 1488 | + * |
|
| 1489 | + * @since 1.0.19 |
|
| 1490 | + * @param string $context View or edit context. |
|
| 1491 | + * @return float |
|
| 1492 | + */ |
|
| 1493 | + public function get_fees_total( $context = 'view' ) { |
|
| 1494 | + return $this->get_total_fees( $context ); |
|
| 1495 | 1495 | } |
| 1496 | 1496 | |
| 1497 | 1497 | /** |
| 1498 | - * Get the invoice total. |
|
| 1499 | - * |
|
| 1500 | - * @since 1.0.19 |
|
| 1498 | + * Get the invoice total. |
|
| 1499 | + * |
|
| 1500 | + * @since 1.0.19 |
|
| 1501 | 1501 | * @return float |
| 1502 | - */ |
|
| 1503 | - public function get_total( $context = 'view' ) { |
|
| 1504 | - $total = $this->get_prop( 'total', $context ); |
|
| 1505 | - |
|
| 1506 | - if ( $this->has_shipping() && $context == 'view' ) { |
|
| 1507 | - $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
| 1508 | - } |
|
| 1509 | - |
|
| 1510 | - return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1511 | - } |
|
| 1512 | - |
|
| 1513 | - /** |
|
| 1514 | - * Retrieves the non-recurring total of items. |
|
| 1515 | - * |
|
| 1516 | - * @since 2.3.0 |
|
| 1517 | - * @return float |
|
| 1518 | - */ |
|
| 1519 | - public function get_non_recurring_total() { |
|
| 1520 | - |
|
| 1521 | - $subtotal = 0; |
|
| 1522 | - foreach ( $this->get_items() as $item ) { |
|
| 1523 | - if ( ! $item->is_recurring() ) { |
|
| 1524 | - $subtotal += $item->get_sub_total(); |
|
| 1525 | - } |
|
| 1526 | - } |
|
| 1527 | - |
|
| 1528 | - foreach ( $this->get_fees() as $fee ) { |
|
| 1529 | - if ( empty( $fee['recurring_fee'] ) ) { |
|
| 1530 | - $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 1531 | - } |
|
| 1532 | - } |
|
| 1533 | - |
|
| 1534 | - $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
| 1502 | + */ |
|
| 1503 | + public function get_total( $context = 'view' ) { |
|
| 1504 | + $total = $this->get_prop( 'total', $context ); |
|
| 1505 | + |
|
| 1506 | + if ( $this->has_shipping() && $context == 'view' ) { |
|
| 1507 | + $total = $this->get_prop( 'total', $context ) + $this->get_shipping( $context ); |
|
| 1508 | + } |
|
| 1509 | + |
|
| 1510 | + return wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1511 | + } |
|
| 1512 | + |
|
| 1513 | + /** |
|
| 1514 | + * Retrieves the non-recurring total of items. |
|
| 1515 | + * |
|
| 1516 | + * @since 2.3.0 |
|
| 1517 | + * @return float |
|
| 1518 | + */ |
|
| 1519 | + public function get_non_recurring_total() { |
|
| 1520 | + |
|
| 1521 | + $subtotal = 0; |
|
| 1522 | + foreach ( $this->get_items() as $item ) { |
|
| 1523 | + if ( ! $item->is_recurring() ) { |
|
| 1524 | + $subtotal += $item->get_sub_total(); |
|
| 1525 | + } |
|
| 1526 | + } |
|
| 1527 | + |
|
| 1528 | + foreach ( $this->get_fees() as $fee ) { |
|
| 1529 | + if ( empty( $fee['recurring_fee'] ) ) { |
|
| 1530 | + $subtotal += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 1531 | + } |
|
| 1532 | + } |
|
| 1533 | + |
|
| 1534 | + $subtotal = wpinv_round_amount( wpinv_sanitize_amount( $subtotal ) ); |
|
| 1535 | 1535 | return apply_filters( 'wpinv_get_non_recurring_invoice_total', $subtotal, $this ); |
| 1536 | 1536 | |
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | - /** |
|
| 1540 | - * Get the invoice totals. |
|
| 1541 | - * |
|
| 1542 | - * @since 1.0.19 |
|
| 1539 | + /** |
|
| 1540 | + * Get the invoice totals. |
|
| 1541 | + * |
|
| 1542 | + * @since 1.0.19 |
|
| 1543 | 1543 | * @return array |
| 1544 | - */ |
|
| 1545 | - public function get_totals() { |
|
| 1546 | - return $this->totals; |
|
| 1544 | + */ |
|
| 1545 | + public function get_totals() { |
|
| 1546 | + return $this->totals; |
|
| 1547 | 1547 | } |
| 1548 | 1548 | |
| 1549 | 1549 | /** |
| 1550 | - * Get the initial invoice total. |
|
| 1551 | - * |
|
| 1552 | - * @since 1.0.19 |
|
| 1550 | + * Get the initial invoice total. |
|
| 1551 | + * |
|
| 1552 | + * @since 1.0.19 |
|
| 1553 | 1553 | * @param string $context View or edit context. |
| 1554 | 1554 | * @return float |
| 1555 | - */ |
|
| 1555 | + */ |
|
| 1556 | 1556 | public function get_initial_total() { |
| 1557 | 1557 | |
| 1558 | - if ( empty( $this->totals ) ) { |
|
| 1559 | - $this->recalculate_total(); |
|
| 1560 | - } |
|
| 1558 | + if ( empty( $this->totals ) ) { |
|
| 1559 | + $this->recalculate_total(); |
|
| 1560 | + } |
|
| 1561 | 1561 | |
| 1562 | - $tax = $this->totals['tax']['initial']; |
|
| 1563 | - $fee = $this->totals['fee']['initial']; |
|
| 1564 | - $discount = $this->totals['discount']['initial']; |
|
| 1565 | - $subtotal = $this->totals['subtotal']['initial']; |
|
| 1566 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1562 | + $tax = $this->totals['tax']['initial']; |
|
| 1563 | + $fee = $this->totals['fee']['initial']; |
|
| 1564 | + $discount = $this->totals['discount']['initial']; |
|
| 1565 | + $subtotal = $this->totals['subtotal']['initial']; |
|
| 1566 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1567 | 1567 | |
| 1568 | - if ( 0 > $total ) { |
|
| 1569 | - $total = 0; |
|
| 1570 | - } |
|
| 1568 | + if ( 0 > $total ) { |
|
| 1569 | + $total = 0; |
|
| 1570 | + } |
|
| 1571 | 1571 | |
| 1572 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1572 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1573 | 1573 | return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this ); |
| 1574 | - } |
|
| 1574 | + } |
|
| 1575 | 1575 | |
| 1576 | - /** |
|
| 1577 | - * Get the recurring invoice total. |
|
| 1578 | - * |
|
| 1579 | - * @since 1.0.19 |
|
| 1576 | + /** |
|
| 1577 | + * Get the recurring invoice total. |
|
| 1578 | + * |
|
| 1579 | + * @since 1.0.19 |
|
| 1580 | 1580 | * @param string $context View or edit context. |
| 1581 | 1581 | * @return float |
| 1582 | - */ |
|
| 1582 | + */ |
|
| 1583 | 1583 | public function get_recurring_total() { |
| 1584 | 1584 | |
| 1585 | - if ( empty( $this->totals ) ) { |
|
| 1586 | - $this->recalculate_total(); |
|
| 1587 | - } |
|
| 1585 | + if ( empty( $this->totals ) ) { |
|
| 1586 | + $this->recalculate_total(); |
|
| 1587 | + } |
|
| 1588 | 1588 | |
| 1589 | - $tax = $this->totals['tax']['recurring']; |
|
| 1590 | - $fee = $this->totals['fee']['recurring']; |
|
| 1591 | - $discount = $this->totals['discount']['recurring']; |
|
| 1592 | - $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1593 | - $total = $tax + $fee - $discount + $subtotal; |
|
| 1589 | + $tax = $this->totals['tax']['recurring']; |
|
| 1590 | + $fee = $this->totals['fee']['recurring']; |
|
| 1591 | + $discount = $this->totals['discount']['recurring']; |
|
| 1592 | + $subtotal = $this->totals['subtotal']['recurring']; |
|
| 1593 | + $total = $tax + $fee - $discount + $subtotal; |
|
| 1594 | 1594 | |
| 1595 | - if ( 0 > $total ) { |
|
| 1596 | - $total = 0; |
|
| 1597 | - } |
|
| 1595 | + if ( 0 > $total ) { |
|
| 1596 | + $total = 0; |
|
| 1597 | + } |
|
| 1598 | 1598 | |
| 1599 | - $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1599 | + $total = wpinv_round_amount( wpinv_sanitize_amount( $total ) ); |
|
| 1600 | 1600 | return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this ); |
| 1601 | - } |
|
| 1601 | + } |
|
| 1602 | 1602 | |
| 1603 | - /** |
|
| 1604 | - * Returns recurring payment details. |
|
| 1605 | - * |
|
| 1606 | - * @since 1.0.19 |
|
| 1603 | + /** |
|
| 1604 | + * Returns recurring payment details. |
|
| 1605 | + * |
|
| 1606 | + * @since 1.0.19 |
|
| 1607 | 1607 | * @param string $field Optionally provide a field to return. |
| 1608 | - * @param string $currency Whether to include the currency. |
|
| 1608 | + * @param string $currency Whether to include the currency. |
|
| 1609 | 1609 | * @return float|string |
| 1610 | - */ |
|
| 1610 | + */ |
|
| 1611 | 1611 | public function get_recurring_details( $field = '', $currency = false ) { |
| 1612 | 1612 | |
| 1613 | - // Maybe recalculate totals. |
|
| 1614 | - if ( empty( $this->totals ) ) { |
|
| 1615 | - $this->recalculate_total(); |
|
| 1616 | - } |
|
| 1613 | + // Maybe recalculate totals. |
|
| 1614 | + if ( empty( $this->totals ) ) { |
|
| 1615 | + $this->recalculate_total(); |
|
| 1616 | + } |
|
| 1617 | 1617 | |
| 1618 | - // Prepare recurring totals. |
|
| 1618 | + // Prepare recurring totals. |
|
| 1619 | 1619 | $data = apply_filters( |
| 1620 | - 'wpinv_get_invoice_recurring_details', |
|
| 1621 | - array( |
|
| 1622 | - 'cart_details' => $this->get_cart_details(), |
|
| 1623 | - 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1624 | - 'discount' => $this->totals['discount']['recurring'], |
|
| 1625 | - 'tax' => $this->totals['tax']['recurring'], |
|
| 1626 | - 'fee' => $this->totals['fee']['recurring'], |
|
| 1627 | - 'total' => $this->get_recurring_total(), |
|
| 1628 | - ), |
|
| 1629 | - $this, |
|
| 1630 | - $field, |
|
| 1631 | - $currency |
|
| 1632 | - ); |
|
| 1620 | + 'wpinv_get_invoice_recurring_details', |
|
| 1621 | + array( |
|
| 1622 | + 'cart_details' => $this->get_cart_details(), |
|
| 1623 | + 'subtotal' => $this->totals['subtotal']['recurring'], |
|
| 1624 | + 'discount' => $this->totals['discount']['recurring'], |
|
| 1625 | + 'tax' => $this->totals['tax']['recurring'], |
|
| 1626 | + 'fee' => $this->totals['fee']['recurring'], |
|
| 1627 | + 'total' => $this->get_recurring_total(), |
|
| 1628 | + ), |
|
| 1629 | + $this, |
|
| 1630 | + $field, |
|
| 1631 | + $currency |
|
| 1632 | + ); |
|
| 1633 | 1633 | |
| 1634 | 1634 | if ( isset( $data[ $field ] ) ) { |
| 1635 | 1635 | return ( $currency ? wpinv_price( $data[ $field ], $this->get_currency() ) : $data[ $field ] ); |
@@ -1639,166 +1639,166 @@ discard block |
||
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | 1641 | /** |
| 1642 | - * Get the invoice fees. |
|
| 1643 | - * |
|
| 1644 | - * @since 1.0.19 |
|
| 1645 | - * @param string $context View or edit context. |
|
| 1646 | - * @return array |
|
| 1647 | - */ |
|
| 1648 | - public function get_fees( $context = 'view' ) { |
|
| 1649 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1642 | + * Get the invoice fees. |
|
| 1643 | + * |
|
| 1644 | + * @since 1.0.19 |
|
| 1645 | + * @param string $context View or edit context. |
|
| 1646 | + * @return array |
|
| 1647 | + */ |
|
| 1648 | + public function get_fees( $context = 'view' ) { |
|
| 1649 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | 1652 | /** |
| 1653 | - * Get the invoice discounts. |
|
| 1654 | - * |
|
| 1655 | - * @since 1.0.19 |
|
| 1656 | - * @param string $context View or edit context. |
|
| 1657 | - * @return array |
|
| 1658 | - */ |
|
| 1659 | - public function get_discounts( $context = 'view' ) { |
|
| 1660 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1653 | + * Get the invoice discounts. |
|
| 1654 | + * |
|
| 1655 | + * @since 1.0.19 |
|
| 1656 | + * @param string $context View or edit context. |
|
| 1657 | + * @return array |
|
| 1658 | + */ |
|
| 1659 | + public function get_discounts( $context = 'view' ) { |
|
| 1660 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | /** |
| 1664 | - * Get the invoice taxes. |
|
| 1665 | - * |
|
| 1666 | - * @since 1.0.19 |
|
| 1667 | - * @param string $context View or edit context. |
|
| 1668 | - * @return array |
|
| 1669 | - */ |
|
| 1670 | - public function get_taxes( $context = 'view' ) { |
|
| 1671 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1664 | + * Get the invoice taxes. |
|
| 1665 | + * |
|
| 1666 | + * @since 1.0.19 |
|
| 1667 | + * @param string $context View or edit context. |
|
| 1668 | + * @return array |
|
| 1669 | + */ |
|
| 1670 | + public function get_taxes( $context = 'view' ) { |
|
| 1671 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
| 1672 | 1672 | } |
| 1673 | 1673 | |
| 1674 | 1674 | /** |
| 1675 | - * Get the invoice items. |
|
| 1676 | - * |
|
| 1677 | - * @since 1.0.19 |
|
| 1678 | - * @param string $context View or edit context. |
|
| 1679 | - * @return GetPaid_Form_Item[] |
|
| 1680 | - */ |
|
| 1681 | - public function get_items( $context = 'view' ) { |
|
| 1675 | + * Get the invoice items. |
|
| 1676 | + * |
|
| 1677 | + * @since 1.0.19 |
|
| 1678 | + * @param string $context View or edit context. |
|
| 1679 | + * @return GetPaid_Form_Item[] |
|
| 1680 | + */ |
|
| 1681 | + public function get_items( $context = 'view' ) { |
|
| 1682 | 1682 | return $this->get_prop( 'items', $context ); |
| 1683 | - } |
|
| 1683 | + } |
|
| 1684 | 1684 | |
| 1685 | - /** |
|
| 1686 | - * Get the invoice item ids. |
|
| 1687 | - * |
|
| 1688 | - * @since 1.0.19 |
|
| 1689 | - * @return string |
|
| 1690 | - */ |
|
| 1691 | - public function get_item_ids() { |
|
| 1692 | - return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
| 1685 | + /** |
|
| 1686 | + * Get the invoice item ids. |
|
| 1687 | + * |
|
| 1688 | + * @since 1.0.19 |
|
| 1689 | + * @return string |
|
| 1690 | + */ |
|
| 1691 | + public function get_item_ids() { |
|
| 1692 | + return implode( ', ', wp_list_pluck( $this->get_cart_details(), 'item_id' ) ); |
|
| 1693 | 1693 | } |
| 1694 | 1694 | |
| 1695 | 1695 | /** |
| 1696 | - * Get the invoice's payment form. |
|
| 1697 | - * |
|
| 1698 | - * @since 1.0.19 |
|
| 1699 | - * @param string $context View or edit context. |
|
| 1700 | - * @return int |
|
| 1701 | - */ |
|
| 1702 | - public function get_payment_form( $context = 'view' ) { |
|
| 1703 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1696 | + * Get the invoice's payment form. |
|
| 1697 | + * |
|
| 1698 | + * @since 1.0.19 |
|
| 1699 | + * @param string $context View or edit context. |
|
| 1700 | + * @return int |
|
| 1701 | + */ |
|
| 1702 | + public function get_payment_form( $context = 'view' ) { |
|
| 1703 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | /** |
| 1707 | - * Get the invoice's submission id. |
|
| 1708 | - * |
|
| 1709 | - * @since 1.0.19 |
|
| 1710 | - * @param string $context View or edit context. |
|
| 1711 | - * @return string |
|
| 1712 | - */ |
|
| 1713 | - public function get_submission_id( $context = 'view' ) { |
|
| 1714 | - return $this->get_prop( 'submission_id', $context ); |
|
| 1707 | + * Get the invoice's submission id. |
|
| 1708 | + * |
|
| 1709 | + * @since 1.0.19 |
|
| 1710 | + * @param string $context View or edit context. |
|
| 1711 | + * @return string |
|
| 1712 | + */ |
|
| 1713 | + public function get_submission_id( $context = 'view' ) { |
|
| 1714 | + return $this->get_prop( 'submission_id', $context ); |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | 1717 | /** |
| 1718 | - * Get the invoice's discount code. |
|
| 1719 | - * |
|
| 1720 | - * @since 1.0.19 |
|
| 1721 | - * @param string $context View or edit context. |
|
| 1722 | - * @return string |
|
| 1723 | - */ |
|
| 1724 | - public function get_discount_code( $context = 'view' ) { |
|
| 1725 | - return $this->get_prop( 'discount_code', $context ); |
|
| 1718 | + * Get the invoice's discount code. |
|
| 1719 | + * |
|
| 1720 | + * @since 1.0.19 |
|
| 1721 | + * @param string $context View or edit context. |
|
| 1722 | + * @return string |
|
| 1723 | + */ |
|
| 1724 | + public function get_discount_code( $context = 'view' ) { |
|
| 1725 | + return $this->get_prop( 'discount_code', $context ); |
|
| 1726 | 1726 | } |
| 1727 | 1727 | |
| 1728 | 1728 | /** |
| 1729 | - * Get the invoice's gateway. |
|
| 1730 | - * |
|
| 1731 | - * @since 1.0.19 |
|
| 1732 | - * @param string $context View or edit context. |
|
| 1733 | - * @return string |
|
| 1734 | - */ |
|
| 1735 | - public function get_gateway( $context = 'view' ) { |
|
| 1736 | - return $this->get_prop( 'gateway', $context ); |
|
| 1729 | + * Get the invoice's gateway. |
|
| 1730 | + * |
|
| 1731 | + * @since 1.0.19 |
|
| 1732 | + * @param string $context View or edit context. |
|
| 1733 | + * @return string |
|
| 1734 | + */ |
|
| 1735 | + public function get_gateway( $context = 'view' ) { |
|
| 1736 | + return $this->get_prop( 'gateway', $context ); |
|
| 1737 | 1737 | } |
| 1738 | 1738 | |
| 1739 | 1739 | /** |
| 1740 | - * Get the invoice's gateway display title. |
|
| 1741 | - * |
|
| 1742 | - * @since 1.0.19 |
|
| 1743 | - * @return string |
|
| 1744 | - */ |
|
| 1740 | + * Get the invoice's gateway display title. |
|
| 1741 | + * |
|
| 1742 | + * @since 1.0.19 |
|
| 1743 | + * @return string |
|
| 1744 | + */ |
|
| 1745 | 1745 | public function get_gateway_title() { |
| 1746 | 1746 | $title = wpinv_get_gateway_checkout_label( $this->get_gateway() ); |
| 1747 | 1747 | return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this ); |
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | 1750 | /** |
| 1751 | - * Get the invoice's transaction id. |
|
| 1752 | - * |
|
| 1753 | - * @since 1.0.19 |
|
| 1754 | - * @param string $context View or edit context. |
|
| 1755 | - * @return string |
|
| 1756 | - */ |
|
| 1757 | - public function get_transaction_id( $context = 'view' ) { |
|
| 1758 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 1751 | + * Get the invoice's transaction id. |
|
| 1752 | + * |
|
| 1753 | + * @since 1.0.19 |
|
| 1754 | + * @param string $context View or edit context. |
|
| 1755 | + * @return string |
|
| 1756 | + */ |
|
| 1757 | + public function get_transaction_id( $context = 'view' ) { |
|
| 1758 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 1759 | 1759 | } |
| 1760 | 1760 | |
| 1761 | 1761 | /** |
| 1762 | - * Get the invoice's currency. |
|
| 1763 | - * |
|
| 1764 | - * @since 1.0.19 |
|
| 1765 | - * @param string $context View or edit context. |
|
| 1766 | - * @return string |
|
| 1767 | - */ |
|
| 1768 | - public function get_currency( $context = 'view' ) { |
|
| 1762 | + * Get the invoice's currency. |
|
| 1763 | + * |
|
| 1764 | + * @since 1.0.19 |
|
| 1765 | + * @param string $context View or edit context. |
|
| 1766 | + * @return string |
|
| 1767 | + */ |
|
| 1768 | + public function get_currency( $context = 'view' ) { |
|
| 1769 | 1769 | $currency = $this->get_prop( 'currency', $context ); |
| 1770 | 1770 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | 1773 | /** |
| 1774 | - * Checks if we are charging taxes for this invoice. |
|
| 1775 | - * |
|
| 1776 | - * @since 1.0.19 |
|
| 1777 | - * @param string $context View or edit context. |
|
| 1778 | - * @return bool |
|
| 1779 | - */ |
|
| 1780 | - public function get_disable_taxes( $context = 'view' ) { |
|
| 1781 | - return (bool) $this->get_prop( 'disable_taxes', $context ); |
|
| 1774 | + * Checks if we are charging taxes for this invoice. |
|
| 1775 | + * |
|
| 1776 | + * @since 1.0.19 |
|
| 1777 | + * @param string $context View or edit context. |
|
| 1778 | + * @return bool |
|
| 1779 | + */ |
|
| 1780 | + public function get_disable_taxes( $context = 'view' ) { |
|
| 1781 | + return (bool) $this->get_prop( 'disable_taxes', $context ); |
|
| 1782 | + } |
|
| 1783 | + |
|
| 1784 | + /** |
|
| 1785 | + * Retrieves the subscription id for an invoice. |
|
| 1786 | + * |
|
| 1787 | + * @since 1.0.19 |
|
| 1788 | + * @param string $context View or edit context. |
|
| 1789 | + * @return int |
|
| 1790 | + */ |
|
| 1791 | + public function get_subscription_id( $context = 'view' ) { |
|
| 1792 | + return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1782 | 1793 | } |
| 1783 | 1794 | |
| 1784 | 1795 | /** |
| 1785 | - * Retrieves the subscription id for an invoice. |
|
| 1786 | - * |
|
| 1787 | - * @since 1.0.19 |
|
| 1788 | - * @param string $context View or edit context. |
|
| 1789 | - * @return int |
|
| 1790 | - */ |
|
| 1791 | - public function get_subscription_id( $context = 'view' ) { |
|
| 1792 | - return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context ); |
|
| 1793 | - } |
|
| 1794 | - |
|
| 1795 | - /** |
|
| 1796 | - * Retrieves the remote subscription id for an invoice. |
|
| 1797 | - * |
|
| 1798 | - * @since 1.0.19 |
|
| 1799 | - * @param string $context View or edit context. |
|
| 1800 | - * @return int |
|
| 1801 | - */ |
|
| 1796 | + * Retrieves the remote subscription id for an invoice. |
|
| 1797 | + * |
|
| 1798 | + * @since 1.0.19 |
|
| 1799 | + * @param string $context View or edit context. |
|
| 1800 | + * @return int |
|
| 1801 | + */ |
|
| 1802 | 1802 | public function get_remote_subscription_id( $context = 'view' ) { |
| 1803 | 1803 | $subscription_id = $this->get_prop( 'remote_subscription_id', $context ); |
| 1804 | 1804 | |
@@ -1811,12 +1811,12 @@ discard block |
||
| 1811 | 1811 | } |
| 1812 | 1812 | |
| 1813 | 1813 | /** |
| 1814 | - * Retrieves the payment meta for an invoice. |
|
| 1815 | - * |
|
| 1816 | - * @since 1.0.19 |
|
| 1817 | - * @param string $context View or edit context. |
|
| 1818 | - * @return array |
|
| 1819 | - */ |
|
| 1814 | + * Retrieves the payment meta for an invoice. |
|
| 1815 | + * |
|
| 1816 | + * @since 1.0.19 |
|
| 1817 | + * @param string $context View or edit context. |
|
| 1818 | + * @return array |
|
| 1819 | + */ |
|
| 1820 | 1820 | public function get_payment_meta( $context = 'view' ) { |
| 1821 | 1821 | |
| 1822 | 1822 | return array( |
@@ -1836,31 +1836,31 @@ discard block |
||
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | 1838 | /** |
| 1839 | - * Retrieves the cart details for an invoice. |
|
| 1840 | - * |
|
| 1841 | - * @since 1.0.19 |
|
| 1842 | - * @return array |
|
| 1843 | - */ |
|
| 1839 | + * Retrieves the cart details for an invoice. |
|
| 1840 | + * |
|
| 1841 | + * @since 1.0.19 |
|
| 1842 | + * @return array |
|
| 1843 | + */ |
|
| 1844 | 1844 | public function get_cart_details() { |
| 1845 | 1845 | $items = $this->get_items(); |
| 1846 | 1846 | $cart_details = array(); |
| 1847 | 1847 | |
| 1848 | 1848 | foreach ( $items as $item ) { |
| 1849 | - $item->invoice_id = $this->get_id(); |
|
| 1849 | + $item->invoice_id = $this->get_id(); |
|
| 1850 | 1850 | $cart_details[] = $item->prepare_data_for_saving(); |
| 1851 | 1851 | } |
| 1852 | 1852 | |
| 1853 | 1853 | return $cart_details; |
| 1854 | - } |
|
| 1854 | + } |
|
| 1855 | 1855 | |
| 1856 | - /** |
|
| 1857 | - * Retrieves the recurring item. |
|
| 1858 | - * |
|
| 1859 | - * @return null|GetPaid_Form_Item|int |
|
| 1860 | - */ |
|
| 1861 | - public function get_recurring( $object = false ) { |
|
| 1856 | + /** |
|
| 1857 | + * Retrieves the recurring item. |
|
| 1858 | + * |
|
| 1859 | + * @return null|GetPaid_Form_Item|int |
|
| 1860 | + */ |
|
| 1861 | + public function get_recurring( $object = false ) { |
|
| 1862 | 1862 | |
| 1863 | - // Are we returning an object? |
|
| 1863 | + // Are we returning an object? |
|
| 1864 | 1864 | if ( $object ) { |
| 1865 | 1865 | return $this->get_item( $this->recurring_item ); |
| 1866 | 1866 | } |
@@ -1868,124 +1868,124 @@ discard block |
||
| 1868 | 1868 | return $this->recurring_item; |
| 1869 | 1869 | } |
| 1870 | 1870 | |
| 1871 | - /** |
|
| 1872 | - * Retrieves the subscription name. |
|
| 1873 | - * |
|
| 1874 | - * @since 1.0.19 |
|
| 1875 | - * @return string |
|
| 1876 | - */ |
|
| 1877 | - public function get_subscription_name() { |
|
| 1871 | + /** |
|
| 1872 | + * Retrieves the subscription name. |
|
| 1873 | + * |
|
| 1874 | + * @since 1.0.19 |
|
| 1875 | + * @return string |
|
| 1876 | + */ |
|
| 1877 | + public function get_subscription_name() { |
|
| 1878 | 1878 | |
| 1879 | - // Retrieve the recurring name |
|
| 1879 | + // Retrieve the recurring name |
|
| 1880 | 1880 | $item = $this->get_recurring( true ); |
| 1881 | 1881 | |
| 1882 | - // Abort if it does not exist. |
|
| 1882 | + // Abort if it does not exist. |
|
| 1883 | 1883 | if ( empty( $item ) ) { |
| 1884 | 1884 | return ''; |
| 1885 | 1885 | } |
| 1886 | 1886 | |
| 1887 | - // Return the item name. |
|
| 1887 | + // Return the item name. |
|
| 1888 | 1888 | return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this ); |
| 1889 | - } |
|
| 1890 | - |
|
| 1891 | - /** |
|
| 1892 | - * Retrieves the view url. |
|
| 1893 | - * |
|
| 1894 | - * @since 1.0.19 |
|
| 1895 | - * @return string |
|
| 1896 | - */ |
|
| 1897 | - public function get_view_url() { |
|
| 1889 | + } |
|
| 1890 | + |
|
| 1891 | + /** |
|
| 1892 | + * Retrieves the view url. |
|
| 1893 | + * |
|
| 1894 | + * @since 1.0.19 |
|
| 1895 | + * @return string |
|
| 1896 | + */ |
|
| 1897 | + public function get_view_url() { |
|
| 1898 | 1898 | $invoice_url = get_permalink( $this->get_id() ); |
| 1899 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1899 | + $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 1900 | 1900 | return apply_filters( 'wpinv_get_view_url', $invoice_url, $this ); |
| 1901 | - } |
|
| 1901 | + } |
|
| 1902 | 1902 | |
| 1903 | - /** |
|
| 1904 | - * Retrieves the payment url. |
|
| 1905 | - * |
|
| 1906 | - * @since 1.0.19 |
|
| 1907 | - * @return string |
|
| 1908 | - */ |
|
| 1909 | - public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1903 | + /** |
|
| 1904 | + * Retrieves the payment url. |
|
| 1905 | + * |
|
| 1906 | + * @since 1.0.19 |
|
| 1907 | + * @return string |
|
| 1908 | + */ |
|
| 1909 | + public function get_checkout_payment_url( $deprecated = false, $secret = false ) { |
|
| 1910 | 1910 | |
| 1911 | - // Retrieve the checkout url. |
|
| 1911 | + // Retrieve the checkout url. |
|
| 1912 | 1912 | $pay_url = wpinv_get_checkout_uri(); |
| 1913 | 1913 | |
| 1914 | - // Maybe force ssl. |
|
| 1914 | + // Maybe force ssl. |
|
| 1915 | 1915 | if ( is_ssl() ) { |
| 1916 | 1916 | $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
| 1917 | 1917 | } |
| 1918 | 1918 | |
| 1919 | - // Add the invoice key. |
|
| 1920 | - $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1919 | + // Add the invoice key. |
|
| 1920 | + $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url ); |
|
| 1921 | 1921 | |
| 1922 | - // (Maybe?) add a secret |
|
| 1922 | + // (Maybe?) add a secret |
|
| 1923 | 1923 | if ( $secret ) { |
| 1924 | 1924 | $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url ); |
| 1925 | 1925 | } |
| 1926 | 1926 | |
| 1927 | 1927 | return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret ); |
| 1928 | - } |
|
| 1928 | + } |
|
| 1929 | 1929 | |
| 1930 | - /** |
|
| 1931 | - * Retrieves the receipt url. |
|
| 1932 | - * |
|
| 1933 | - * @since 1.0.19 |
|
| 1934 | - * @return string |
|
| 1935 | - */ |
|
| 1936 | - public function get_receipt_url() { |
|
| 1930 | + /** |
|
| 1931 | + * Retrieves the receipt url. |
|
| 1932 | + * |
|
| 1933 | + * @since 1.0.19 |
|
| 1934 | + * @return string |
|
| 1935 | + */ |
|
| 1936 | + public function get_receipt_url() { |
|
| 1937 | 1937 | |
| 1938 | - // Retrieve the checkout url. |
|
| 1938 | + // Retrieve the checkout url. |
|
| 1939 | 1939 | $receipt_url = wpinv_get_success_page_uri(); |
| 1940 | 1940 | |
| 1941 | - // Maybe force ssl. |
|
| 1941 | + // Maybe force ssl. |
|
| 1942 | 1942 | if ( is_ssl() ) { |
| 1943 | 1943 | $receipt_url = str_replace( 'http:', 'https:', $receipt_url ); |
| 1944 | 1944 | } |
| 1945 | 1945 | |
| 1946 | - // Add the invoice key. |
|
| 1947 | - $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1946 | + // Add the invoice key. |
|
| 1947 | + $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url ); |
|
| 1948 | 1948 | |
| 1949 | 1949 | return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this ); |
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - /** |
|
| 1953 | - * Retrieves the remote transaction url. |
|
| 1954 | - * |
|
| 1955 | - * @since 1.6.0 |
|
| 1956 | - * @return string |
|
| 1957 | - */ |
|
| 1958 | - public function get_transaction_url() { |
|
| 1959 | - return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
| 1960 | - } |
|
| 1961 | - |
|
| 1962 | - /** |
|
| 1963 | - * Retrieves the default status. |
|
| 1964 | - * |
|
| 1965 | - * @since 1.0.19 |
|
| 1966 | - * @return string |
|
| 1967 | - */ |
|
| 1968 | - public function get_default_status() { |
|
| 1969 | - |
|
| 1970 | - $type = $this->get_type(); |
|
| 1971 | - $status = "wpi-$type-pending"; |
|
| 1972 | - return str_replace( '-invoice', '', $status ); |
|
| 1973 | - |
|
| 1974 | - } |
|
| 1975 | - |
|
| 1976 | - /** |
|
| 1977 | - * Magic method for accessing invoice properties. |
|
| 1978 | - * |
|
| 1979 | - * @since 1.0.15 |
|
| 1980 | - * @access public |
|
| 1981 | - * |
|
| 1982 | - * @param string $key Discount data to retrieve |
|
| 1983 | - * @param string $context View or edit context. |
|
| 1984 | - * @return mixed Value of the given invoice property (if set). |
|
| 1985 | - */ |
|
| 1986 | - public function get( $key, $context = 'view' ) { |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + /** |
|
| 1953 | + * Retrieves the remote transaction url. |
|
| 1954 | + * |
|
| 1955 | + * @since 1.6.0 |
|
| 1956 | + * @return string |
|
| 1957 | + */ |
|
| 1958 | + public function get_transaction_url() { |
|
| 1959 | + return apply_filters( 'getpaid_gateway_' . $this->get_gateway() . '_transaction_url', '', $this ); |
|
| 1960 | + } |
|
| 1961 | + |
|
| 1962 | + /** |
|
| 1963 | + * Retrieves the default status. |
|
| 1964 | + * |
|
| 1965 | + * @since 1.0.19 |
|
| 1966 | + * @return string |
|
| 1967 | + */ |
|
| 1968 | + public function get_default_status() { |
|
| 1969 | + |
|
| 1970 | + $type = $this->get_type(); |
|
| 1971 | + $status = "wpi-$type-pending"; |
|
| 1972 | + return str_replace( '-invoice', '', $status ); |
|
| 1973 | + |
|
| 1974 | + } |
|
| 1975 | + |
|
| 1976 | + /** |
|
| 1977 | + * Magic method for accessing invoice properties. |
|
| 1978 | + * |
|
| 1979 | + * @since 1.0.15 |
|
| 1980 | + * @access public |
|
| 1981 | + * |
|
| 1982 | + * @param string $key Discount data to retrieve |
|
| 1983 | + * @param string $context View or edit context. |
|
| 1984 | + * @return mixed Value of the given invoice property (if set). |
|
| 1985 | + */ |
|
| 1986 | + public function get( $key, $context = 'view' ) { |
|
| 1987 | 1987 | return $this->get_prop( $key, $context ); |
| 1988 | - } |
|
| 1988 | + } |
|
| 1989 | 1989 | |
| 1990 | 1990 | /* |
| 1991 | 1991 | |-------------------------------------------------------------------------- |
@@ -1998,129 +1998,129 @@ discard block |
||
| 1998 | 1998 | */ |
| 1999 | 1999 | |
| 2000 | 2000 | /** |
| 2001 | - * Magic method for setting invoice properties. |
|
| 2002 | - * |
|
| 2003 | - * @since 1.0.19 |
|
| 2004 | - * @access public |
|
| 2005 | - * |
|
| 2006 | - * @param string $key Discount data to retrieve |
|
| 2007 | - * @param mixed $value new value. |
|
| 2008 | - * @return mixed Value of the given invoice property (if set). |
|
| 2009 | - */ |
|
| 2010 | - public function set( $key, $value ) { |
|
| 2001 | + * Magic method for setting invoice properties. |
|
| 2002 | + * |
|
| 2003 | + * @since 1.0.19 |
|
| 2004 | + * @access public |
|
| 2005 | + * |
|
| 2006 | + * @param string $key Discount data to retrieve |
|
| 2007 | + * @param mixed $value new value. |
|
| 2008 | + * @return mixed Value of the given invoice property (if set). |
|
| 2009 | + */ |
|
| 2010 | + public function set( $key, $value ) { |
|
| 2011 | 2011 | |
| 2012 | 2012 | $setter = "set_$key"; |
| 2013 | 2013 | if ( is_callable( array( $this, $setter ) ) ) { |
| 2014 | 2014 | $this->{$setter}( $value ); |
| 2015 | 2015 | } |
| 2016 | 2016 | |
| 2017 | - } |
|
| 2018 | - |
|
| 2019 | - /** |
|
| 2020 | - * Sets item status. |
|
| 2021 | - * |
|
| 2022 | - * @since 1.0.19 |
|
| 2023 | - * @param string $new_status New status. |
|
| 2024 | - * @param string $note Optional note to add. |
|
| 2025 | - * @param bool $manual_update Is this a manual status change?. |
|
| 2026 | - * @return array details of change. |
|
| 2027 | - */ |
|
| 2028 | - public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 2029 | - $old_status = $this->get_status(); |
|
| 2030 | - |
|
| 2031 | - $statuses = $this->get_all_statuses(); |
|
| 2032 | - |
|
| 2033 | - if ( isset( $statuses['draft'] ) ) { |
|
| 2034 | - unset( $statuses['draft'] ); |
|
| 2035 | - } |
|
| 2036 | - |
|
| 2037 | - $this->set_prop( 'status', $new_status ); |
|
| 2038 | - |
|
| 2039 | - // If setting the status, ensure it's set to a valid status. |
|
| 2040 | - if ( true === $this->object_read ) { |
|
| 2041 | - |
|
| 2042 | - // Only allow valid new status. |
|
| 2043 | - if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2044 | - $new_status = $this->get_default_status(); |
|
| 2045 | - } |
|
| 2046 | - |
|
| 2047 | - // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 2048 | - if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2049 | - $old_status = $this->get_default_status(); |
|
| 2050 | - } |
|
| 2051 | - |
|
| 2052 | - // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 2053 | - if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 2054 | - $old_status = 'wpi-pending'; |
|
| 2055 | - } |
|
| 2056 | - |
|
| 2057 | - if ( $old_status !== $new_status ) { |
|
| 2058 | - $this->status_transition = array( |
|
| 2059 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 2060 | - 'to' => $new_status, |
|
| 2061 | - 'note' => $note, |
|
| 2062 | - 'manual' => (bool) $manual_update, |
|
| 2063 | - ); |
|
| 2064 | - |
|
| 2065 | - if ( $manual_update ) { |
|
| 2066 | - do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - $this->maybe_set_date_paid(); |
|
| 2070 | - |
|
| 2071 | - } |
|
| 2072 | - } |
|
| 2073 | - |
|
| 2074 | - return array( |
|
| 2075 | - 'from' => $old_status, |
|
| 2076 | - 'to' => $new_status, |
|
| 2077 | - ); |
|
| 2078 | - } |
|
| 2079 | - |
|
| 2080 | - /** |
|
| 2081 | - * Maybe set date paid. |
|
| 2082 | - * |
|
| 2083 | - * Sets the date paid variable when transitioning to the payment complete |
|
| 2084 | - * order status. |
|
| 2085 | - * |
|
| 2086 | - * @since 1.0.19 |
|
| 2087 | - */ |
|
| 2088 | - public function maybe_set_date_paid() { |
|
| 2089 | - |
|
| 2090 | - if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 2091 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 2092 | - } |
|
| 2093 | - } |
|
| 2094 | - |
|
| 2095 | - /** |
|
| 2096 | - * Set parent invoice ID. |
|
| 2097 | - * |
|
| 2098 | - * @since 1.0.19 |
|
| 2099 | - */ |
|
| 2100 | - public function set_parent_id( $value ) { |
|
| 2101 | - if ( $value && ( $value === $this->get_id() ) ) { |
|
| 2102 | - return; |
|
| 2103 | - } |
|
| 2104 | - $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 2105 | - } |
|
| 2106 | - |
|
| 2107 | - /** |
|
| 2108 | - * Set plugin version when the invoice was created. |
|
| 2109 | - * |
|
| 2110 | - * @since 1.0.19 |
|
| 2111 | - */ |
|
| 2112 | - public function set_version( $value ) { |
|
| 2113 | - $this->set_prop( 'version', $value ); |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - /** |
|
| 2117 | - * Set date when the invoice was created. |
|
| 2118 | - * |
|
| 2119 | - * @since 1.0.19 |
|
| 2120 | - * @param string $value Value to set. |
|
| 2017 | + } |
|
| 2018 | + |
|
| 2019 | + /** |
|
| 2020 | + * Sets item status. |
|
| 2021 | + * |
|
| 2022 | + * @since 1.0.19 |
|
| 2023 | + * @param string $new_status New status. |
|
| 2024 | + * @param string $note Optional note to add. |
|
| 2025 | + * @param bool $manual_update Is this a manual status change?. |
|
| 2026 | + * @return array details of change. |
|
| 2027 | + */ |
|
| 2028 | + public function set_status( $new_status, $note = '', $manual_update = false ) { |
|
| 2029 | + $old_status = $this->get_status(); |
|
| 2030 | + |
|
| 2031 | + $statuses = $this->get_all_statuses(); |
|
| 2032 | + |
|
| 2033 | + if ( isset( $statuses['draft'] ) ) { |
|
| 2034 | + unset( $statuses['draft'] ); |
|
| 2035 | + } |
|
| 2036 | + |
|
| 2037 | + $this->set_prop( 'status', $new_status ); |
|
| 2038 | + |
|
| 2039 | + // If setting the status, ensure it's set to a valid status. |
|
| 2040 | + if ( true === $this->object_read ) { |
|
| 2041 | + |
|
| 2042 | + // Only allow valid new status. |
|
| 2043 | + if ( ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2044 | + $new_status = $this->get_default_status(); |
|
| 2045 | + } |
|
| 2046 | + |
|
| 2047 | + // If the old status is set but unknown (e.g. draft) assume its pending for action usage. |
|
| 2048 | + if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) { |
|
| 2049 | + $old_status = $this->get_default_status(); |
|
| 2050 | + } |
|
| 2051 | + |
|
| 2052 | + // Paid - Renewal (i.e when duplicating a parent invoice ) |
|
| 2053 | + if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) { |
|
| 2054 | + $old_status = 'wpi-pending'; |
|
| 2055 | + } |
|
| 2056 | + |
|
| 2057 | + if ( $old_status !== $new_status ) { |
|
| 2058 | + $this->status_transition = array( |
|
| 2059 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 2060 | + 'to' => $new_status, |
|
| 2061 | + 'note' => $note, |
|
| 2062 | + 'manual' => (bool) $manual_update, |
|
| 2063 | + ); |
|
| 2064 | + |
|
| 2065 | + if ( $manual_update ) { |
|
| 2066 | + do_action( 'getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status ); |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + $this->maybe_set_date_paid(); |
|
| 2070 | + |
|
| 2071 | + } |
|
| 2072 | + } |
|
| 2073 | + |
|
| 2074 | + return array( |
|
| 2075 | + 'from' => $old_status, |
|
| 2076 | + 'to' => $new_status, |
|
| 2077 | + ); |
|
| 2078 | + } |
|
| 2079 | + |
|
| 2080 | + /** |
|
| 2081 | + * Maybe set date paid. |
|
| 2082 | + * |
|
| 2083 | + * Sets the date paid variable when transitioning to the payment complete |
|
| 2084 | + * order status. |
|
| 2085 | + * |
|
| 2086 | + * @since 1.0.19 |
|
| 2087 | + */ |
|
| 2088 | + public function maybe_set_date_paid() { |
|
| 2089 | + |
|
| 2090 | + if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) { |
|
| 2091 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 2092 | + } |
|
| 2093 | + } |
|
| 2094 | + |
|
| 2095 | + /** |
|
| 2096 | + * Set parent invoice ID. |
|
| 2097 | + * |
|
| 2098 | + * @since 1.0.19 |
|
| 2099 | + */ |
|
| 2100 | + public function set_parent_id( $value ) { |
|
| 2101 | + if ( $value && ( $value === $this->get_id() ) ) { |
|
| 2102 | + return; |
|
| 2103 | + } |
|
| 2104 | + $this->set_prop( 'parent_id', absint( $value ) ); |
|
| 2105 | + } |
|
| 2106 | + |
|
| 2107 | + /** |
|
| 2108 | + * Set plugin version when the invoice was created. |
|
| 2109 | + * |
|
| 2110 | + * @since 1.0.19 |
|
| 2111 | + */ |
|
| 2112 | + public function set_version( $value ) { |
|
| 2113 | + $this->set_prop( 'version', $value ); |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + /** |
|
| 2117 | + * Set date when the invoice was created. |
|
| 2118 | + * |
|
| 2119 | + * @since 1.0.19 |
|
| 2120 | + * @param string $value Value to set. |
|
| 2121 | 2121 | * @return bool Whether or not the date was set. |
| 2122 | - */ |
|
| 2123 | - public function set_date_created( $value ) { |
|
| 2122 | + */ |
|
| 2123 | + public function set_date_created( $value ) { |
|
| 2124 | 2124 | $date = strtotime( $value ); |
| 2125 | 2125 | |
| 2126 | 2126 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2128,19 +2128,19 @@ discard block |
||
| 2128 | 2128 | return true; |
| 2129 | 2129 | } |
| 2130 | 2130 | |
| 2131 | - $this->set_prop( 'date_created', '' ); |
|
| 2132 | - return false; |
|
| 2131 | + $this->set_prop( 'date_created', '' ); |
|
| 2132 | + return false; |
|
| 2133 | 2133 | |
| 2134 | 2134 | } |
| 2135 | 2135 | |
| 2136 | 2136 | /** |
| 2137 | - * Set date invoice due date. |
|
| 2138 | - * |
|
| 2139 | - * @since 1.0.19 |
|
| 2140 | - * @param string $value Value to set. |
|
| 2137 | + * Set date invoice due date. |
|
| 2138 | + * |
|
| 2139 | + * @since 1.0.19 |
|
| 2140 | + * @param string $value Value to set. |
|
| 2141 | 2141 | * @return bool Whether or not the date was set. |
| 2142 | - */ |
|
| 2143 | - public function set_due_date( $value ) { |
|
| 2142 | + */ |
|
| 2143 | + public function set_due_date( $value ) { |
|
| 2144 | 2144 | $date = strtotime( $value ); |
| 2145 | 2145 | |
| 2146 | 2146 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2148,29 +2148,29 @@ discard block |
||
| 2148 | 2148 | return true; |
| 2149 | 2149 | } |
| 2150 | 2150 | |
| 2151 | - $this->set_prop( 'due_date', '' ); |
|
| 2151 | + $this->set_prop( 'due_date', '' ); |
|
| 2152 | 2152 | return false; |
| 2153 | 2153 | |
| 2154 | 2154 | } |
| 2155 | 2155 | |
| 2156 | 2156 | /** |
| 2157 | - * Alias of self::set_due_date(). |
|
| 2158 | - * |
|
| 2159 | - * @since 1.0.19 |
|
| 2160 | - * @param string $value New name. |
|
| 2161 | - */ |
|
| 2162 | - public function set_date_due( $value ) { |
|
| 2163 | - $this->set_due_date( $value ); |
|
| 2157 | + * Alias of self::set_due_date(). |
|
| 2158 | + * |
|
| 2159 | + * @since 1.0.19 |
|
| 2160 | + * @param string $value New name. |
|
| 2161 | + */ |
|
| 2162 | + public function set_date_due( $value ) { |
|
| 2163 | + $this->set_due_date( $value ); |
|
| 2164 | 2164 | } |
| 2165 | 2165 | |
| 2166 | 2166 | /** |
| 2167 | - * Set date invoice was completed. |
|
| 2168 | - * |
|
| 2169 | - * @since 1.0.19 |
|
| 2170 | - * @param string $value Value to set. |
|
| 2167 | + * Set date invoice was completed. |
|
| 2168 | + * |
|
| 2169 | + * @since 1.0.19 |
|
| 2170 | + * @param string $value Value to set. |
|
| 2171 | 2171 | * @return bool Whether or not the date was set. |
| 2172 | - */ |
|
| 2173 | - public function set_completed_date( $value ) { |
|
| 2172 | + */ |
|
| 2173 | + public function set_completed_date( $value ) { |
|
| 2174 | 2174 | $date = strtotime( $value ); |
| 2175 | 2175 | |
| 2176 | 2176 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2178,29 +2178,29 @@ discard block |
||
| 2178 | 2178 | return true; |
| 2179 | 2179 | } |
| 2180 | 2180 | |
| 2181 | - $this->set_prop( 'completed_date', '' ); |
|
| 2181 | + $this->set_prop( 'completed_date', '' ); |
|
| 2182 | 2182 | return false; |
| 2183 | 2183 | |
| 2184 | 2184 | } |
| 2185 | 2185 | |
| 2186 | 2186 | /** |
| 2187 | - * Alias of self::set_completed_date(). |
|
| 2188 | - * |
|
| 2189 | - * @since 1.0.19 |
|
| 2190 | - * @param string $value New name. |
|
| 2191 | - */ |
|
| 2192 | - public function set_date_completed( $value ) { |
|
| 2193 | - $this->set_completed_date( $value ); |
|
| 2187 | + * Alias of self::set_completed_date(). |
|
| 2188 | + * |
|
| 2189 | + * @since 1.0.19 |
|
| 2190 | + * @param string $value New name. |
|
| 2191 | + */ |
|
| 2192 | + public function set_date_completed( $value ) { |
|
| 2193 | + $this->set_completed_date( $value ); |
|
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | 2196 | /** |
| 2197 | - * Set date when the invoice was last modified. |
|
| 2198 | - * |
|
| 2199 | - * @since 1.0.19 |
|
| 2200 | - * @param string $value Value to set. |
|
| 2197 | + * Set date when the invoice was last modified. |
|
| 2198 | + * |
|
| 2199 | + * @since 1.0.19 |
|
| 2200 | + * @param string $value Value to set. |
|
| 2201 | 2201 | * @return bool Whether or not the date was set. |
| 2202 | - */ |
|
| 2203 | - public function set_date_modified( $value ) { |
|
| 2202 | + */ |
|
| 2203 | + public function set_date_modified( $value ) { |
|
| 2204 | 2204 | $date = strtotime( $value ); |
| 2205 | 2205 | |
| 2206 | 2206 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
@@ -2208,813 +2208,813 @@ discard block |
||
| 2208 | 2208 | return true; |
| 2209 | 2209 | } |
| 2210 | 2210 | |
| 2211 | - $this->set_prop( 'date_modified', '' ); |
|
| 2211 | + $this->set_prop( 'date_modified', '' ); |
|
| 2212 | 2212 | return false; |
| 2213 | 2213 | |
| 2214 | 2214 | } |
| 2215 | 2215 | |
| 2216 | 2216 | /** |
| 2217 | - * Set the invoice number. |
|
| 2218 | - * |
|
| 2219 | - * @since 1.0.19 |
|
| 2220 | - * @param string $value New number. |
|
| 2221 | - */ |
|
| 2222 | - public function set_number( $value ) { |
|
| 2217 | + * Set the invoice number. |
|
| 2218 | + * |
|
| 2219 | + * @since 1.0.19 |
|
| 2220 | + * @param string $value New number. |
|
| 2221 | + */ |
|
| 2222 | + public function set_number( $value ) { |
|
| 2223 | 2223 | $number = sanitize_text_field( $value ); |
| 2224 | - $this->set_prop( 'number', $number ); |
|
| 2224 | + $this->set_prop( 'number', $number ); |
|
| 2225 | 2225 | } |
| 2226 | 2226 | |
| 2227 | 2227 | /** |
| 2228 | - * Set the invoice type. |
|
| 2229 | - * |
|
| 2230 | - * @since 1.0.19 |
|
| 2231 | - * @param string $value Type. |
|
| 2232 | - */ |
|
| 2233 | - public function set_type( $value ) { |
|
| 2228 | + * Set the invoice type. |
|
| 2229 | + * |
|
| 2230 | + * @since 1.0.19 |
|
| 2231 | + * @param string $value Type. |
|
| 2232 | + */ |
|
| 2233 | + public function set_type( $value ) { |
|
| 2234 | 2234 | $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) ); |
| 2235 | - $this->set_prop( 'type', $type ); |
|
| 2236 | - } |
|
| 2235 | + $this->set_prop( 'type', $type ); |
|
| 2236 | + } |
|
| 2237 | 2237 | |
| 2238 | 2238 | /** |
| 2239 | - * Set the invoice post type. |
|
| 2240 | - * |
|
| 2241 | - * @since 1.0.19 |
|
| 2242 | - * @param string $value Post type. |
|
| 2243 | - */ |
|
| 2244 | - public function set_post_type( $value ) { |
|
| 2239 | + * Set the invoice post type. |
|
| 2240 | + * |
|
| 2241 | + * @since 1.0.19 |
|
| 2242 | + * @param string $value Post type. |
|
| 2243 | + */ |
|
| 2244 | + public function set_post_type( $value ) { |
|
| 2245 | 2245 | if ( getpaid_is_invoice_post_type( $value ) ) { |
| 2246 | - $this->set_type( $value ); |
|
| 2246 | + $this->set_type( $value ); |
|
| 2247 | 2247 | $this->set_prop( 'post_type', $value ); |
| 2248 | 2248 | } |
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | 2251 | /** |
| 2252 | - * Set the invoice key. |
|
| 2253 | - * |
|
| 2254 | - * @since 1.0.19 |
|
| 2255 | - * @param string $value New key. |
|
| 2256 | - */ |
|
| 2257 | - public function set_key( $value ) { |
|
| 2252 | + * Set the invoice key. |
|
| 2253 | + * |
|
| 2254 | + * @since 1.0.19 |
|
| 2255 | + * @param string $value New key. |
|
| 2256 | + */ |
|
| 2257 | + public function set_key( $value ) { |
|
| 2258 | 2258 | $key = sanitize_text_field( $value ); |
| 2259 | - $this->set_prop( 'key', $key ); |
|
| 2259 | + $this->set_prop( 'key', $key ); |
|
| 2260 | 2260 | } |
| 2261 | 2261 | |
| 2262 | 2262 | /** |
| 2263 | - * Set the invoice mode. |
|
| 2264 | - * |
|
| 2265 | - * @since 1.0.19 |
|
| 2266 | - * @param string $value mode. |
|
| 2267 | - */ |
|
| 2268 | - public function set_mode( $value ) { |
|
| 2263 | + * Set the invoice mode. |
|
| 2264 | + * |
|
| 2265 | + * @since 1.0.19 |
|
| 2266 | + * @param string $value mode. |
|
| 2267 | + */ |
|
| 2268 | + public function set_mode( $value ) { |
|
| 2269 | 2269 | if ( in_array( $value, array( 'live', 'test' ) ) ) { |
| 2270 | 2270 | $this->set_prop( 'mode', $value ); |
| 2271 | 2271 | } |
| 2272 | 2272 | } |
| 2273 | 2273 | |
| 2274 | 2274 | /** |
| 2275 | - * Set the invoice path. |
|
| 2276 | - * |
|
| 2277 | - * @since 1.0.19 |
|
| 2278 | - * @param string $value path. |
|
| 2279 | - */ |
|
| 2280 | - public function set_path( $value ) { |
|
| 2275 | + * Set the invoice path. |
|
| 2276 | + * |
|
| 2277 | + * @since 1.0.19 |
|
| 2278 | + * @param string $value path. |
|
| 2279 | + */ |
|
| 2280 | + public function set_path( $value ) { |
|
| 2281 | 2281 | $this->set_prop( 'path', $value ); |
| 2282 | 2282 | } |
| 2283 | 2283 | |
| 2284 | 2284 | /** |
| 2285 | - * Set the invoice name. |
|
| 2286 | - * |
|
| 2287 | - * @since 1.0.19 |
|
| 2288 | - * @param string $value New name. |
|
| 2289 | - */ |
|
| 2290 | - public function set_name( $value ) { |
|
| 2285 | + * Set the invoice name. |
|
| 2286 | + * |
|
| 2287 | + * @since 1.0.19 |
|
| 2288 | + * @param string $value New name. |
|
| 2289 | + */ |
|
| 2290 | + public function set_name( $value ) { |
|
| 2291 | 2291 | $name = sanitize_text_field( $value ); |
| 2292 | - $this->set_prop( 'name', $name ); |
|
| 2292 | + $this->set_prop( 'name', $name ); |
|
| 2293 | 2293 | } |
| 2294 | 2294 | |
| 2295 | 2295 | /** |
| 2296 | - * Alias of self::set_name(). |
|
| 2297 | - * |
|
| 2298 | - * @since 1.0.19 |
|
| 2299 | - * @param string $value New name. |
|
| 2300 | - */ |
|
| 2301 | - public function set_title( $value ) { |
|
| 2302 | - $this->set_name( $value ); |
|
| 2296 | + * Alias of self::set_name(). |
|
| 2297 | + * |
|
| 2298 | + * @since 1.0.19 |
|
| 2299 | + * @param string $value New name. |
|
| 2300 | + */ |
|
| 2301 | + public function set_title( $value ) { |
|
| 2302 | + $this->set_name( $value ); |
|
| 2303 | 2303 | } |
| 2304 | 2304 | |
| 2305 | 2305 | /** |
| 2306 | - * Set the invoice description. |
|
| 2307 | - * |
|
| 2308 | - * @since 1.0.19 |
|
| 2309 | - * @param string $value New description. |
|
| 2310 | - */ |
|
| 2311 | - public function set_description( $value ) { |
|
| 2306 | + * Set the invoice description. |
|
| 2307 | + * |
|
| 2308 | + * @since 1.0.19 |
|
| 2309 | + * @param string $value New description. |
|
| 2310 | + */ |
|
| 2311 | + public function set_description( $value ) { |
|
| 2312 | 2312 | $description = wp_kses_post( $value ); |
| 2313 | - $this->set_prop( 'description', $description ); |
|
| 2313 | + $this->set_prop( 'description', $description ); |
|
| 2314 | + } |
|
| 2315 | + |
|
| 2316 | + /** |
|
| 2317 | + * Alias of self::set_description(). |
|
| 2318 | + * |
|
| 2319 | + * @since 1.0.19 |
|
| 2320 | + * @param string $value New description. |
|
| 2321 | + */ |
|
| 2322 | + public function set_excerpt( $value ) { |
|
| 2323 | + $this->set_description( $value ); |
|
| 2324 | + } |
|
| 2325 | + |
|
| 2326 | + /** |
|
| 2327 | + * Alias of self::set_description(). |
|
| 2328 | + * |
|
| 2329 | + * @since 1.0.19 |
|
| 2330 | + * @param string $value New description. |
|
| 2331 | + */ |
|
| 2332 | + public function set_summary( $value ) { |
|
| 2333 | + $this->set_description( $value ); |
|
| 2334 | + } |
|
| 2335 | + |
|
| 2336 | + /** |
|
| 2337 | + * Set the receiver of the invoice. |
|
| 2338 | + * |
|
| 2339 | + * @since 1.0.19 |
|
| 2340 | + * @param int $value New author. |
|
| 2341 | + */ |
|
| 2342 | + public function set_author( $value ) { |
|
| 2343 | + $user = get_user_by( 'id', (int) $value ); |
|
| 2344 | + |
|
| 2345 | + if ( $user && $user->ID ) { |
|
| 2346 | + $this->set_prop( 'author', $user->ID ); |
|
| 2347 | + $this->set_prop( 'email', $user->user_email ); |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + } |
|
| 2351 | + |
|
| 2352 | + /** |
|
| 2353 | + * Alias of self::set_author(). |
|
| 2354 | + * |
|
| 2355 | + * @since 1.0.19 |
|
| 2356 | + * @param int $value New user id. |
|
| 2357 | + */ |
|
| 2358 | + public function set_user_id( $value ) { |
|
| 2359 | + $this->set_author( $value ); |
|
| 2360 | + } |
|
| 2361 | + |
|
| 2362 | + /** |
|
| 2363 | + * Alias of self::set_author(). |
|
| 2364 | + * |
|
| 2365 | + * @since 1.0.19 |
|
| 2366 | + * @param int $value New user id. |
|
| 2367 | + */ |
|
| 2368 | + public function set_customer_id( $value ) { |
|
| 2369 | + $this->set_author( $value ); |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + /** |
|
| 2373 | + * Set the customer's ip. |
|
| 2374 | + * |
|
| 2375 | + * @since 1.0.19 |
|
| 2376 | + * @param string $value ip address. |
|
| 2377 | + */ |
|
| 2378 | + public function set_ip( $value ) { |
|
| 2379 | + $this->set_prop( 'ip', $value ); |
|
| 2380 | + } |
|
| 2381 | + |
|
| 2382 | + /** |
|
| 2383 | + * Alias of self::set_ip(). |
|
| 2384 | + * |
|
| 2385 | + * @since 1.0.19 |
|
| 2386 | + * @param string $value ip address. |
|
| 2387 | + */ |
|
| 2388 | + public function set_user_ip( $value ) { |
|
| 2389 | + $this->set_ip( $value ); |
|
| 2390 | + } |
|
| 2391 | + |
|
| 2392 | + /** |
|
| 2393 | + * Set the customer's first name. |
|
| 2394 | + * |
|
| 2395 | + * @since 1.0.19 |
|
| 2396 | + * @param string $value first name. |
|
| 2397 | + */ |
|
| 2398 | + public function set_first_name( $value ) { |
|
| 2399 | + $this->set_prop( 'first_name', $value ); |
|
| 2400 | + } |
|
| 2401 | + |
|
| 2402 | + /** |
|
| 2403 | + * Alias of self::set_first_name(). |
|
| 2404 | + * |
|
| 2405 | + * @since 1.0.19 |
|
| 2406 | + * @param string $value first name. |
|
| 2407 | + */ |
|
| 2408 | + public function set_user_first_name( $value ) { |
|
| 2409 | + $this->set_first_name( $value ); |
|
| 2314 | 2410 | } |
| 2315 | 2411 | |
| 2316 | 2412 | /** |
| 2317 | - * Alias of self::set_description(). |
|
| 2318 | - * |
|
| 2319 | - * @since 1.0.19 |
|
| 2320 | - * @param string $value New description. |
|
| 2321 | - */ |
|
| 2322 | - public function set_excerpt( $value ) { |
|
| 2323 | - $this->set_description( $value ); |
|
| 2413 | + * Alias of self::set_first_name(). |
|
| 2414 | + * |
|
| 2415 | + * @since 1.0.19 |
|
| 2416 | + * @param string $value first name. |
|
| 2417 | + */ |
|
| 2418 | + public function set_customer_first_name( $value ) { |
|
| 2419 | + $this->set_first_name( $value ); |
|
| 2420 | + } |
|
| 2421 | + |
|
| 2422 | + /** |
|
| 2423 | + * Set the customer's last name. |
|
| 2424 | + * |
|
| 2425 | + * @since 1.0.19 |
|
| 2426 | + * @param string $value last name. |
|
| 2427 | + */ |
|
| 2428 | + public function set_last_name( $value ) { |
|
| 2429 | + $this->set_prop( 'last_name', $value ); |
|
| 2430 | + } |
|
| 2431 | + |
|
| 2432 | + /** |
|
| 2433 | + * Alias of self::set_last_name(). |
|
| 2434 | + * |
|
| 2435 | + * @since 1.0.19 |
|
| 2436 | + * @param string $value last name. |
|
| 2437 | + */ |
|
| 2438 | + public function set_user_last_name( $value ) { |
|
| 2439 | + $this->set_last_name( $value ); |
|
| 2440 | + } |
|
| 2441 | + |
|
| 2442 | + /** |
|
| 2443 | + * Alias of self::set_last_name(). |
|
| 2444 | + * |
|
| 2445 | + * @since 1.0.19 |
|
| 2446 | + * @param string $value last name. |
|
| 2447 | + */ |
|
| 2448 | + public function set_customer_last_name( $value ) { |
|
| 2449 | + $this->set_last_name( $value ); |
|
| 2450 | + } |
|
| 2451 | + |
|
| 2452 | + /** |
|
| 2453 | + * Set the customer's phone number. |
|
| 2454 | + * |
|
| 2455 | + * @since 1.0.19 |
|
| 2456 | + * @param string $value phone. |
|
| 2457 | + */ |
|
| 2458 | + public function set_phone( $value ) { |
|
| 2459 | + $this->set_prop( 'phone', $value ); |
|
| 2324 | 2460 | } |
| 2325 | 2461 | |
| 2326 | 2462 | /** |
| 2327 | - * Alias of self::set_description(). |
|
| 2328 | - * |
|
| 2329 | - * @since 1.0.19 |
|
| 2330 | - * @param string $value New description. |
|
| 2331 | - */ |
|
| 2332 | - public function set_summary( $value ) { |
|
| 2333 | - $this->set_description( $value ); |
|
| 2463 | + * Alias of self::set_phone(). |
|
| 2464 | + * |
|
| 2465 | + * @since 1.0.19 |
|
| 2466 | + * @param string $value phone. |
|
| 2467 | + */ |
|
| 2468 | + public function set_user_phone( $value ) { |
|
| 2469 | + $this->set_phone( $value ); |
|
| 2334 | 2470 | } |
| 2335 | 2471 | |
| 2336 | 2472 | /** |
| 2337 | - * Set the receiver of the invoice. |
|
| 2338 | - * |
|
| 2339 | - * @since 1.0.19 |
|
| 2340 | - * @param int $value New author. |
|
| 2341 | - */ |
|
| 2342 | - public function set_author( $value ) { |
|
| 2343 | - $user = get_user_by( 'id', (int) $value ); |
|
| 2473 | + * Alias of self::set_phone(). |
|
| 2474 | + * |
|
| 2475 | + * @since 1.0.19 |
|
| 2476 | + * @param string $value phone. |
|
| 2477 | + */ |
|
| 2478 | + public function set_customer_phone( $value ) { |
|
| 2479 | + $this->set_phone( $value ); |
|
| 2480 | + } |
|
| 2344 | 2481 | |
| 2345 | - if ( $user && $user->ID ) { |
|
| 2346 | - $this->set_prop( 'author', $user->ID ); |
|
| 2347 | - $this->set_prop( 'email', $user->user_email ); |
|
| 2348 | - } |
|
| 2482 | + /** |
|
| 2483 | + * Alias of self::set_phone(). |
|
| 2484 | + * |
|
| 2485 | + * @since 1.0.19 |
|
| 2486 | + * @param string $value phone. |
|
| 2487 | + */ |
|
| 2488 | + public function set_phone_number( $value ) { |
|
| 2489 | + $this->set_phone( $value ); |
|
| 2490 | + } |
|
| 2349 | 2491 | |
| 2492 | + /** |
|
| 2493 | + * Set the customer's email address. |
|
| 2494 | + * |
|
| 2495 | + * @since 1.0.19 |
|
| 2496 | + * @param string $value email address. |
|
| 2497 | + */ |
|
| 2498 | + public function set_email( $value ) { |
|
| 2499 | + $this->set_prop( 'email', $value ); |
|
| 2350 | 2500 | } |
| 2351 | 2501 | |
| 2352 | 2502 | /** |
| 2353 | - * Alias of self::set_author(). |
|
| 2354 | - * |
|
| 2355 | - * @since 1.0.19 |
|
| 2356 | - * @param int $value New user id. |
|
| 2357 | - */ |
|
| 2358 | - public function set_user_id( $value ) { |
|
| 2359 | - $this->set_author( $value ); |
|
| 2503 | + * Alias of self::set_email(). |
|
| 2504 | + * |
|
| 2505 | + * @since 1.0.19 |
|
| 2506 | + * @param string $value email address. |
|
| 2507 | + */ |
|
| 2508 | + public function set_user_email( $value ) { |
|
| 2509 | + $this->set_email( $value ); |
|
| 2360 | 2510 | } |
| 2361 | 2511 | |
| 2362 | 2512 | /** |
| 2363 | - * Alias of self::set_author(). |
|
| 2364 | - * |
|
| 2365 | - * @since 1.0.19 |
|
| 2366 | - * @param int $value New user id. |
|
| 2367 | - */ |
|
| 2368 | - public function set_customer_id( $value ) { |
|
| 2369 | - $this->set_author( $value ); |
|
| 2513 | + * Alias of self::set_email(). |
|
| 2514 | + * |
|
| 2515 | + * @since 1.0.19 |
|
| 2516 | + * @param string $value email address. |
|
| 2517 | + */ |
|
| 2518 | + public function set_email_address( $value ) { |
|
| 2519 | + $this->set_email( $value ); |
|
| 2370 | 2520 | } |
| 2371 | 2521 | |
| 2372 | 2522 | /** |
| 2373 | - * Set the customer's ip. |
|
| 2374 | - * |
|
| 2375 | - * @since 1.0.19 |
|
| 2376 | - * @param string $value ip address. |
|
| 2377 | - */ |
|
| 2378 | - public function set_ip( $value ) { |
|
| 2379 | - $this->set_prop( 'ip', $value ); |
|
| 2523 | + * Alias of self::set_email(). |
|
| 2524 | + * |
|
| 2525 | + * @since 1.0.19 |
|
| 2526 | + * @param string $value email address. |
|
| 2527 | + */ |
|
| 2528 | + public function set_customer_email( $value ) { |
|
| 2529 | + $this->set_email( $value ); |
|
| 2380 | 2530 | } |
| 2381 | 2531 | |
| 2382 | 2532 | /** |
| 2383 | - * Alias of self::set_ip(). |
|
| 2384 | - * |
|
| 2385 | - * @since 1.0.19 |
|
| 2386 | - * @param string $value ip address. |
|
| 2387 | - */ |
|
| 2388 | - public function set_user_ip( $value ) { |
|
| 2389 | - $this->set_ip( $value ); |
|
| 2533 | + * Set the customer's country. |
|
| 2534 | + * |
|
| 2535 | + * @since 1.0.19 |
|
| 2536 | + * @param string $value country. |
|
| 2537 | + */ |
|
| 2538 | + public function set_country( $value ) { |
|
| 2539 | + $this->set_prop( 'country', $value ); |
|
| 2390 | 2540 | } |
| 2391 | 2541 | |
| 2392 | 2542 | /** |
| 2393 | - * Set the customer's first name. |
|
| 2394 | - * |
|
| 2395 | - * @since 1.0.19 |
|
| 2396 | - * @param string $value first name. |
|
| 2397 | - */ |
|
| 2398 | - public function set_first_name( $value ) { |
|
| 2399 | - $this->set_prop( 'first_name', $value ); |
|
| 2543 | + * Alias of self::set_country(). |
|
| 2544 | + * |
|
| 2545 | + * @since 1.0.19 |
|
| 2546 | + * @param string $value country. |
|
| 2547 | + */ |
|
| 2548 | + public function set_user_country( $value ) { |
|
| 2549 | + $this->set_country( $value ); |
|
| 2400 | 2550 | } |
| 2401 | 2551 | |
| 2402 | 2552 | /** |
| 2403 | - * Alias of self::set_first_name(). |
|
| 2404 | - * |
|
| 2405 | - * @since 1.0.19 |
|
| 2406 | - * @param string $value first name. |
|
| 2407 | - */ |
|
| 2408 | - public function set_user_first_name( $value ) { |
|
| 2409 | - $this->set_first_name( $value ); |
|
| 2553 | + * Alias of self::set_country(). |
|
| 2554 | + * |
|
| 2555 | + * @since 1.0.19 |
|
| 2556 | + * @param string $value country. |
|
| 2557 | + */ |
|
| 2558 | + public function set_customer_country( $value ) { |
|
| 2559 | + $this->set_country( $value ); |
|
| 2410 | 2560 | } |
| 2411 | 2561 | |
| 2412 | 2562 | /** |
| 2413 | - * Alias of self::set_first_name(). |
|
| 2414 | - * |
|
| 2415 | - * @since 1.0.19 |
|
| 2416 | - * @param string $value first name. |
|
| 2417 | - */ |
|
| 2418 | - public function set_customer_first_name( $value ) { |
|
| 2419 | - $this->set_first_name( $value ); |
|
| 2563 | + * Set the customer's state. |
|
| 2564 | + * |
|
| 2565 | + * @since 1.0.19 |
|
| 2566 | + * @param string $value state. |
|
| 2567 | + */ |
|
| 2568 | + public function set_state( $value ) { |
|
| 2569 | + $this->set_prop( 'state', $value ); |
|
| 2420 | 2570 | } |
| 2421 | 2571 | |
| 2422 | 2572 | /** |
| 2423 | - * Set the customer's last name. |
|
| 2424 | - * |
|
| 2425 | - * @since 1.0.19 |
|
| 2426 | - * @param string $value last name. |
|
| 2427 | - */ |
|
| 2428 | - public function set_last_name( $value ) { |
|
| 2429 | - $this->set_prop( 'last_name', $value ); |
|
| 2573 | + * Alias of self::set_state(). |
|
| 2574 | + * |
|
| 2575 | + * @since 1.0.19 |
|
| 2576 | + * @param string $value state. |
|
| 2577 | + */ |
|
| 2578 | + public function set_user_state( $value ) { |
|
| 2579 | + $this->set_state( $value ); |
|
| 2430 | 2580 | } |
| 2431 | 2581 | |
| 2432 | 2582 | /** |
| 2433 | - * Alias of self::set_last_name(). |
|
| 2434 | - * |
|
| 2435 | - * @since 1.0.19 |
|
| 2436 | - * @param string $value last name. |
|
| 2437 | - */ |
|
| 2438 | - public function set_user_last_name( $value ) { |
|
| 2439 | - $this->set_last_name( $value ); |
|
| 2583 | + * Alias of self::set_state(). |
|
| 2584 | + * |
|
| 2585 | + * @since 1.0.19 |
|
| 2586 | + * @param string $value state. |
|
| 2587 | + */ |
|
| 2588 | + public function set_customer_state( $value ) { |
|
| 2589 | + $this->set_state( $value ); |
|
| 2440 | 2590 | } |
| 2441 | 2591 | |
| 2442 | 2592 | /** |
| 2443 | - * Alias of self::set_last_name(). |
|
| 2444 | - * |
|
| 2445 | - * @since 1.0.19 |
|
| 2446 | - * @param string $value last name. |
|
| 2447 | - */ |
|
| 2448 | - public function set_customer_last_name( $value ) { |
|
| 2449 | - $this->set_last_name( $value ); |
|
| 2593 | + * Set the customer's city. |
|
| 2594 | + * |
|
| 2595 | + * @since 1.0.19 |
|
| 2596 | + * @param string $value city. |
|
| 2597 | + */ |
|
| 2598 | + public function set_city( $value ) { |
|
| 2599 | + $this->set_prop( 'city', $value ); |
|
| 2450 | 2600 | } |
| 2451 | 2601 | |
| 2452 | 2602 | /** |
| 2453 | - * Set the customer's phone number. |
|
| 2454 | - * |
|
| 2455 | - * @since 1.0.19 |
|
| 2456 | - * @param string $value phone. |
|
| 2457 | - */ |
|
| 2458 | - public function set_phone( $value ) { |
|
| 2459 | - $this->set_prop( 'phone', $value ); |
|
| 2603 | + * Alias of self::set_city(). |
|
| 2604 | + * |
|
| 2605 | + * @since 1.0.19 |
|
| 2606 | + * @param string $value city. |
|
| 2607 | + */ |
|
| 2608 | + public function set_user_city( $value ) { |
|
| 2609 | + $this->set_city( $value ); |
|
| 2460 | 2610 | } |
| 2461 | 2611 | |
| 2462 | 2612 | /** |
| 2463 | - * Alias of self::set_phone(). |
|
| 2464 | - * |
|
| 2465 | - * @since 1.0.19 |
|
| 2466 | - * @param string $value phone. |
|
| 2467 | - */ |
|
| 2468 | - public function set_user_phone( $value ) { |
|
| 2469 | - $this->set_phone( $value ); |
|
| 2613 | + * Alias of self::set_city(). |
|
| 2614 | + * |
|
| 2615 | + * @since 1.0.19 |
|
| 2616 | + * @param string $value city. |
|
| 2617 | + */ |
|
| 2618 | + public function set_customer_city( $value ) { |
|
| 2619 | + $this->set_city( $value ); |
|
| 2470 | 2620 | } |
| 2471 | 2621 | |
| 2472 | 2622 | /** |
| 2473 | - * Alias of self::set_phone(). |
|
| 2474 | - * |
|
| 2475 | - * @since 1.0.19 |
|
| 2476 | - * @param string $value phone. |
|
| 2477 | - */ |
|
| 2478 | - public function set_customer_phone( $value ) { |
|
| 2479 | - $this->set_phone( $value ); |
|
| 2623 | + * Set the customer's zip code. |
|
| 2624 | + * |
|
| 2625 | + * @since 1.0.19 |
|
| 2626 | + * @param string $value zip. |
|
| 2627 | + */ |
|
| 2628 | + public function set_zip( $value ) { |
|
| 2629 | + $this->set_prop( 'zip', $value ); |
|
| 2480 | 2630 | } |
| 2481 | 2631 | |
| 2482 | 2632 | /** |
| 2483 | - * Alias of self::set_phone(). |
|
| 2484 | - * |
|
| 2485 | - * @since 1.0.19 |
|
| 2486 | - * @param string $value phone. |
|
| 2487 | - */ |
|
| 2488 | - public function set_phone_number( $value ) { |
|
| 2489 | - $this->set_phone( $value ); |
|
| 2633 | + * Alias of self::set_zip(). |
|
| 2634 | + * |
|
| 2635 | + * @since 1.0.19 |
|
| 2636 | + * @param string $value zip. |
|
| 2637 | + */ |
|
| 2638 | + public function set_user_zip( $value ) { |
|
| 2639 | + $this->set_zip( $value ); |
|
| 2490 | 2640 | } |
| 2491 | 2641 | |
| 2492 | 2642 | /** |
| 2493 | - * Set the customer's email address. |
|
| 2494 | - * |
|
| 2495 | - * @since 1.0.19 |
|
| 2496 | - * @param string $value email address. |
|
| 2497 | - */ |
|
| 2498 | - public function set_email( $value ) { |
|
| 2499 | - $this->set_prop( 'email', $value ); |
|
| 2643 | + * Alias of self::set_zip(). |
|
| 2644 | + * |
|
| 2645 | + * @since 1.0.19 |
|
| 2646 | + * @param string $value zip. |
|
| 2647 | + */ |
|
| 2648 | + public function set_customer_zip( $value ) { |
|
| 2649 | + $this->set_zip( $value ); |
|
| 2500 | 2650 | } |
| 2501 | 2651 | |
| 2502 | 2652 | /** |
| 2503 | - * Alias of self::set_email(). |
|
| 2504 | - * |
|
| 2505 | - * @since 1.0.19 |
|
| 2506 | - * @param string $value email address. |
|
| 2507 | - */ |
|
| 2508 | - public function set_user_email( $value ) { |
|
| 2509 | - $this->set_email( $value ); |
|
| 2653 | + * Set the customer's company. |
|
| 2654 | + * |
|
| 2655 | + * @since 1.0.19 |
|
| 2656 | + * @param string $value company. |
|
| 2657 | + */ |
|
| 2658 | + public function set_company( $value ) { |
|
| 2659 | + $this->set_prop( 'company', $value ); |
|
| 2510 | 2660 | } |
| 2511 | 2661 | |
| 2512 | 2662 | /** |
| 2513 | - * Alias of self::set_email(). |
|
| 2514 | - * |
|
| 2515 | - * @since 1.0.19 |
|
| 2516 | - * @param string $value email address. |
|
| 2517 | - */ |
|
| 2518 | - public function set_email_address( $value ) { |
|
| 2519 | - $this->set_email( $value ); |
|
| 2663 | + * Alias of self::set_company(). |
|
| 2664 | + * |
|
| 2665 | + * @since 1.0.19 |
|
| 2666 | + * @param string $value company. |
|
| 2667 | + */ |
|
| 2668 | + public function set_user_company( $value ) { |
|
| 2669 | + $this->set_company( $value ); |
|
| 2520 | 2670 | } |
| 2521 | 2671 | |
| 2522 | 2672 | /** |
| 2523 | - * Alias of self::set_email(). |
|
| 2524 | - * |
|
| 2525 | - * @since 1.0.19 |
|
| 2526 | - * @param string $value email address. |
|
| 2527 | - */ |
|
| 2528 | - public function set_customer_email( $value ) { |
|
| 2529 | - $this->set_email( $value ); |
|
| 2673 | + * Alias of self::set_company(). |
|
| 2674 | + * |
|
| 2675 | + * @since 1.0.19 |
|
| 2676 | + * @param string $value company. |
|
| 2677 | + */ |
|
| 2678 | + public function set_customer_company( $value ) { |
|
| 2679 | + $this->set_company( $value ); |
|
| 2530 | 2680 | } |
| 2531 | 2681 | |
| 2532 | 2682 | /** |
| 2533 | - * Set the customer's country. |
|
| 2534 | - * |
|
| 2535 | - * @since 1.0.19 |
|
| 2536 | - * @param string $value country. |
|
| 2537 | - */ |
|
| 2538 | - public function set_country( $value ) { |
|
| 2539 | - $this->set_prop( 'country', $value ); |
|
| 2683 | + * Set the customer's company id. |
|
| 2684 | + * |
|
| 2685 | + * @since 1.0.19 |
|
| 2686 | + * @param string $value company id. |
|
| 2687 | + */ |
|
| 2688 | + public function set_company_id( $value ) { |
|
| 2689 | + $this->set_prop( 'company_id', $value ); |
|
| 2540 | 2690 | } |
| 2541 | 2691 | |
| 2542 | 2692 | /** |
| 2543 | - * Alias of self::set_country(). |
|
| 2544 | - * |
|
| 2545 | - * @since 1.0.19 |
|
| 2546 | - * @param string $value country. |
|
| 2547 | - */ |
|
| 2548 | - public function set_user_country( $value ) { |
|
| 2549 | - $this->set_country( $value ); |
|
| 2693 | + * Set the customer's var number. |
|
| 2694 | + * |
|
| 2695 | + * @since 1.0.19 |
|
| 2696 | + * @param string $value var number. |
|
| 2697 | + */ |
|
| 2698 | + public function set_vat_number( $value ) { |
|
| 2699 | + $this->set_prop( 'vat_number', $value ); |
|
| 2550 | 2700 | } |
| 2551 | 2701 | |
| 2552 | 2702 | /** |
| 2553 | - * Alias of self::set_country(). |
|
| 2554 | - * |
|
| 2555 | - * @since 1.0.19 |
|
| 2556 | - * @param string $value country. |
|
| 2557 | - */ |
|
| 2558 | - public function set_customer_country( $value ) { |
|
| 2559 | - $this->set_country( $value ); |
|
| 2703 | + * Alias of self::set_vat_number(). |
|
| 2704 | + * |
|
| 2705 | + * @since 1.0.19 |
|
| 2706 | + * @param string $value var number. |
|
| 2707 | + */ |
|
| 2708 | + public function set_user_vat_number( $value ) { |
|
| 2709 | + $this->set_vat_number( $value ); |
|
| 2560 | 2710 | } |
| 2561 | 2711 | |
| 2562 | 2712 | /** |
| 2563 | - * Set the customer's state. |
|
| 2564 | - * |
|
| 2565 | - * @since 1.0.19 |
|
| 2566 | - * @param string $value state. |
|
| 2567 | - */ |
|
| 2568 | - public function set_state( $value ) { |
|
| 2569 | - $this->set_prop( 'state', $value ); |
|
| 2713 | + * Alias of self::set_vat_number(). |
|
| 2714 | + * |
|
| 2715 | + * @since 1.0.19 |
|
| 2716 | + * @param string $value var number. |
|
| 2717 | + */ |
|
| 2718 | + public function set_customer_vat_number( $value ) { |
|
| 2719 | + $this->set_vat_number( $value ); |
|
| 2570 | 2720 | } |
| 2571 | 2721 | |
| 2572 | 2722 | /** |
| 2573 | - * Alias of self::set_state(). |
|
| 2574 | - * |
|
| 2575 | - * @since 1.0.19 |
|
| 2576 | - * @param string $value state. |
|
| 2577 | - */ |
|
| 2578 | - public function set_user_state( $value ) { |
|
| 2579 | - $this->set_state( $value ); |
|
| 2723 | + * Set the customer's vat rate. |
|
| 2724 | + * |
|
| 2725 | + * @since 1.0.19 |
|
| 2726 | + * @param string $value var rate. |
|
| 2727 | + */ |
|
| 2728 | + public function set_vat_rate( $value ) { |
|
| 2729 | + $this->set_prop( 'vat_rate', $value ); |
|
| 2580 | 2730 | } |
| 2581 | 2731 | |
| 2582 | 2732 | /** |
| 2583 | - * Alias of self::set_state(). |
|
| 2584 | - * |
|
| 2585 | - * @since 1.0.19 |
|
| 2586 | - * @param string $value state. |
|
| 2587 | - */ |
|
| 2588 | - public function set_customer_state( $value ) { |
|
| 2589 | - $this->set_state( $value ); |
|
| 2733 | + * Alias of self::set_vat_rate(). |
|
| 2734 | + * |
|
| 2735 | + * @since 1.0.19 |
|
| 2736 | + * @param string $value var number. |
|
| 2737 | + */ |
|
| 2738 | + public function set_user_vat_rate( $value ) { |
|
| 2739 | + $this->set_vat_rate( $value ); |
|
| 2590 | 2740 | } |
| 2591 | 2741 | |
| 2592 | 2742 | /** |
| 2593 | - * Set the customer's city. |
|
| 2594 | - * |
|
| 2595 | - * @since 1.0.19 |
|
| 2596 | - * @param string $value city. |
|
| 2597 | - */ |
|
| 2598 | - public function set_city( $value ) { |
|
| 2599 | - $this->set_prop( 'city', $value ); |
|
| 2743 | + * Alias of self::set_vat_rate(). |
|
| 2744 | + * |
|
| 2745 | + * @since 1.0.19 |
|
| 2746 | + * @param string $value var number. |
|
| 2747 | + */ |
|
| 2748 | + public function set_customer_vat_rate( $value ) { |
|
| 2749 | + $this->set_vat_rate( $value ); |
|
| 2600 | 2750 | } |
| 2601 | 2751 | |
| 2602 | 2752 | /** |
| 2603 | - * Alias of self::set_city(). |
|
| 2604 | - * |
|
| 2605 | - * @since 1.0.19 |
|
| 2606 | - * @param string $value city. |
|
| 2607 | - */ |
|
| 2608 | - public function set_user_city( $value ) { |
|
| 2609 | - $this->set_city( $value ); |
|
| 2753 | + * Set the customer's address. |
|
| 2754 | + * |
|
| 2755 | + * @since 1.0.19 |
|
| 2756 | + * @param string $value address. |
|
| 2757 | + */ |
|
| 2758 | + public function set_address( $value ) { |
|
| 2759 | + $this->set_prop( 'address', $value ); |
|
| 2610 | 2760 | } |
| 2611 | 2761 | |
| 2612 | 2762 | /** |
| 2613 | - * Alias of self::set_city(). |
|
| 2614 | - * |
|
| 2615 | - * @since 1.0.19 |
|
| 2616 | - * @param string $value city. |
|
| 2617 | - */ |
|
| 2618 | - public function set_customer_city( $value ) { |
|
| 2619 | - $this->set_city( $value ); |
|
| 2763 | + * Alias of self::set_address(). |
|
| 2764 | + * |
|
| 2765 | + * @since 1.0.19 |
|
| 2766 | + * @param string $value address. |
|
| 2767 | + */ |
|
| 2768 | + public function set_user_address( $value ) { |
|
| 2769 | + $this->set_address( $value ); |
|
| 2620 | 2770 | } |
| 2621 | 2771 | |
| 2622 | 2772 | /** |
| 2623 | - * Set the customer's zip code. |
|
| 2624 | - * |
|
| 2625 | - * @since 1.0.19 |
|
| 2626 | - * @param string $value zip. |
|
| 2627 | - */ |
|
| 2628 | - public function set_zip( $value ) { |
|
| 2629 | - $this->set_prop( 'zip', $value ); |
|
| 2773 | + * Alias of self::set_address(). |
|
| 2774 | + * |
|
| 2775 | + * @since 1.0.19 |
|
| 2776 | + * @param string $value address. |
|
| 2777 | + */ |
|
| 2778 | + public function set_customer_address( $value ) { |
|
| 2779 | + $this->set_address( $value ); |
|
| 2630 | 2780 | } |
| 2631 | 2781 | |
| 2632 | 2782 | /** |
| 2633 | - * Alias of self::set_zip(). |
|
| 2634 | - * |
|
| 2635 | - * @since 1.0.19 |
|
| 2636 | - * @param string $value zip. |
|
| 2637 | - */ |
|
| 2638 | - public function set_user_zip( $value ) { |
|
| 2639 | - $this->set_zip( $value ); |
|
| 2783 | + * Set whether the customer has viewed the invoice or not. |
|
| 2784 | + * |
|
| 2785 | + * @since 1.0.19 |
|
| 2786 | + * @param int|bool $value confirmed. |
|
| 2787 | + */ |
|
| 2788 | + public function set_is_viewed( $value ) { |
|
| 2789 | + $this->set_prop( 'is_viewed', $value ); |
|
| 2640 | 2790 | } |
| 2641 | 2791 | |
| 2642 | 2792 | /** |
| 2643 | - * Alias of self::set_zip(). |
|
| 2644 | - * |
|
| 2645 | - * @since 1.0.19 |
|
| 2646 | - * @param string $value zip. |
|
| 2647 | - */ |
|
| 2648 | - public function set_customer_zip( $value ) { |
|
| 2649 | - $this->set_zip( $value ); |
|
| 2793 | + * Set extra email recipients. |
|
| 2794 | + * |
|
| 2795 | + * @since 1.0.19 |
|
| 2796 | + * @param string $value email recipients. |
|
| 2797 | + */ |
|
| 2798 | + public function set_email_cc( $value ) { |
|
| 2799 | + $this->set_prop( 'email_cc', $value ); |
|
| 2650 | 2800 | } |
| 2651 | 2801 | |
| 2652 | 2802 | /** |
| 2653 | - * Set the customer's company. |
|
| 2654 | - * |
|
| 2655 | - * @since 1.0.19 |
|
| 2656 | - * @param string $value company. |
|
| 2657 | - */ |
|
| 2658 | - public function set_company( $value ) { |
|
| 2659 | - $this->set_prop( 'company', $value ); |
|
| 2803 | + * Set the invoice template. |
|
| 2804 | + * |
|
| 2805 | + * @since 1.0.19 |
|
| 2806 | + * @param string $value template. |
|
| 2807 | + */ |
|
| 2808 | + public function set_template( $value ) { |
|
| 2809 | + if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2810 | + $this->set_prop( 'template', $value ); |
|
| 2811 | + } |
|
| 2660 | 2812 | } |
| 2661 | 2813 | |
| 2662 | 2814 | /** |
| 2663 | - * Alias of self::set_company(). |
|
| 2664 | - * |
|
| 2665 | - * @since 1.0.19 |
|
| 2666 | - * @param string $value company. |
|
| 2667 | - */ |
|
| 2668 | - public function set_user_company( $value ) { |
|
| 2669 | - $this->set_company( $value ); |
|
| 2815 | + * Set the invoice source. |
|
| 2816 | + * |
|
| 2817 | + * @since 1.0.19 |
|
| 2818 | + * @param string $value source. |
|
| 2819 | + * @deprecated |
|
| 2820 | + */ |
|
| 2821 | + public function created_via( $value ) { |
|
| 2822 | + $this->set_created_via( sanitize_text_field( $value ) ); |
|
| 2670 | 2823 | } |
| 2671 | 2824 | |
| 2672 | 2825 | /** |
| 2673 | - * Alias of self::set_company(). |
|
| 2674 | - * |
|
| 2675 | - * @since 1.0.19 |
|
| 2676 | - * @param string $value company. |
|
| 2677 | - */ |
|
| 2678 | - public function set_customer_company( $value ) { |
|
| 2679 | - $this->set_company( $value ); |
|
| 2826 | + * Set the invoice source. |
|
| 2827 | + * |
|
| 2828 | + * @since 1.0.19 |
|
| 2829 | + * @param string $value source. |
|
| 2830 | + */ |
|
| 2831 | + public function set_created_via( $value ) { |
|
| 2832 | + $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2680 | 2833 | } |
| 2681 | 2834 | |
| 2682 | - /** |
|
| 2683 | - * Set the customer's company id. |
|
| 2684 | - * |
|
| 2685 | - * @since 1.0.19 |
|
| 2686 | - * @param string $value company id. |
|
| 2687 | - */ |
|
| 2688 | - public function set_company_id( $value ) { |
|
| 2689 | - $this->set_prop( 'company_id', $value ); |
|
| 2835 | + /** |
|
| 2836 | + * Set the customer's address confirmed status. |
|
| 2837 | + * |
|
| 2838 | + * @since 1.0.19 |
|
| 2839 | + * @param int|bool $value confirmed. |
|
| 2840 | + */ |
|
| 2841 | + public function set_address_confirmed( $value ) { |
|
| 2842 | + $this->set_prop( 'address_confirmed', $value ); |
|
| 2690 | 2843 | } |
| 2691 | 2844 | |
| 2692 | 2845 | /** |
| 2693 | - * Set the customer's var number. |
|
| 2694 | - * |
|
| 2695 | - * @since 1.0.19 |
|
| 2696 | - * @param string $value var number. |
|
| 2697 | - */ |
|
| 2698 | - public function set_vat_number( $value ) { |
|
| 2699 | - $this->set_prop( 'vat_number', $value ); |
|
| 2846 | + * Alias of self::set_address_confirmed(). |
|
| 2847 | + * |
|
| 2848 | + * @since 1.0.19 |
|
| 2849 | + * @param int|bool $value confirmed. |
|
| 2850 | + */ |
|
| 2851 | + public function set_user_address_confirmed( $value ) { |
|
| 2852 | + $this->set_address_confirmed( $value ); |
|
| 2700 | 2853 | } |
| 2701 | 2854 | |
| 2702 | 2855 | /** |
| 2703 | - * Alias of self::set_vat_number(). |
|
| 2704 | - * |
|
| 2705 | - * @since 1.0.19 |
|
| 2706 | - * @param string $value var number. |
|
| 2707 | - */ |
|
| 2708 | - public function set_user_vat_number( $value ) { |
|
| 2709 | - $this->set_vat_number( $value ); |
|
| 2856 | + * Alias of self::set_address_confirmed(). |
|
| 2857 | + * |
|
| 2858 | + * @since 1.0.19 |
|
| 2859 | + * @param int|bool $value confirmed. |
|
| 2860 | + */ |
|
| 2861 | + public function set_customer_address_confirmed( $value ) { |
|
| 2862 | + $this->set_address_confirmed( $value ); |
|
| 2710 | 2863 | } |
| 2711 | 2864 | |
| 2712 | 2865 | /** |
| 2713 | - * Alias of self::set_vat_number(). |
|
| 2714 | - * |
|
| 2715 | - * @since 1.0.19 |
|
| 2716 | - * @param string $value var number. |
|
| 2717 | - */ |
|
| 2718 | - public function set_customer_vat_number( $value ) { |
|
| 2719 | - $this->set_vat_number( $value ); |
|
| 2866 | + * Set the shipping fee |
|
| 2867 | + * |
|
| 2868 | + * @since 1.0.19 |
|
| 2869 | + * @param float $value shipping amount. |
|
| 2870 | + */ |
|
| 2871 | + public function set_shipping( $value ) { |
|
| 2872 | + |
|
| 2873 | + if ( ! is_numeric( $value ) ) { |
|
| 2874 | + return $this->set_prop( 'shipping', null ); |
|
| 2875 | + } |
|
| 2876 | + |
|
| 2877 | + $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
| 2720 | 2878 | } |
| 2721 | 2879 | |
| 2722 | 2880 | /** |
| 2723 | - * Set the customer's vat rate. |
|
| 2724 | - * |
|
| 2725 | - * @since 1.0.19 |
|
| 2726 | - * @param string $value var rate. |
|
| 2727 | - */ |
|
| 2728 | - public function set_vat_rate( $value ) { |
|
| 2729 | - $this->set_prop( 'vat_rate', $value ); |
|
| 2881 | + * Set the invoice sub total. |
|
| 2882 | + * |
|
| 2883 | + * @since 1.0.19 |
|
| 2884 | + * @param float $value sub total. |
|
| 2885 | + */ |
|
| 2886 | + public function set_subtotal( $value ) { |
|
| 2887 | + $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
| 2730 | 2888 | } |
| 2731 | 2889 | |
| 2732 | - /** |
|
| 2733 | - * Alias of self::set_vat_rate(). |
|
| 2734 | - * |
|
| 2735 | - * @since 1.0.19 |
|
| 2736 | - * @param string $value var number. |
|
| 2737 | - */ |
|
| 2738 | - public function set_user_vat_rate( $value ) { |
|
| 2739 | - $this->set_vat_rate( $value ); |
|
| 2740 | - } |
|
| 2741 | - |
|
| 2742 | - /** |
|
| 2743 | - * Alias of self::set_vat_rate(). |
|
| 2744 | - * |
|
| 2745 | - * @since 1.0.19 |
|
| 2746 | - * @param string $value var number. |
|
| 2747 | - */ |
|
| 2748 | - public function set_customer_vat_rate( $value ) { |
|
| 2749 | - $this->set_vat_rate( $value ); |
|
| 2750 | - } |
|
| 2751 | - |
|
| 2752 | - /** |
|
| 2753 | - * Set the customer's address. |
|
| 2754 | - * |
|
| 2755 | - * @since 1.0.19 |
|
| 2756 | - * @param string $value address. |
|
| 2757 | - */ |
|
| 2758 | - public function set_address( $value ) { |
|
| 2759 | - $this->set_prop( 'address', $value ); |
|
| 2760 | - } |
|
| 2761 | - |
|
| 2762 | - /** |
|
| 2763 | - * Alias of self::set_address(). |
|
| 2764 | - * |
|
| 2765 | - * @since 1.0.19 |
|
| 2766 | - * @param string $value address. |
|
| 2767 | - */ |
|
| 2768 | - public function set_user_address( $value ) { |
|
| 2769 | - $this->set_address( $value ); |
|
| 2770 | - } |
|
| 2771 | - |
|
| 2772 | - /** |
|
| 2773 | - * Alias of self::set_address(). |
|
| 2774 | - * |
|
| 2775 | - * @since 1.0.19 |
|
| 2776 | - * @param string $value address. |
|
| 2777 | - */ |
|
| 2778 | - public function set_customer_address( $value ) { |
|
| 2779 | - $this->set_address( $value ); |
|
| 2780 | - } |
|
| 2781 | - |
|
| 2782 | - /** |
|
| 2783 | - * Set whether the customer has viewed the invoice or not. |
|
| 2784 | - * |
|
| 2785 | - * @since 1.0.19 |
|
| 2786 | - * @param int|bool $value confirmed. |
|
| 2787 | - */ |
|
| 2788 | - public function set_is_viewed( $value ) { |
|
| 2789 | - $this->set_prop( 'is_viewed', $value ); |
|
| 2790 | - } |
|
| 2791 | - |
|
| 2792 | - /** |
|
| 2793 | - * Set extra email recipients. |
|
| 2794 | - * |
|
| 2795 | - * @since 1.0.19 |
|
| 2796 | - * @param string $value email recipients. |
|
| 2797 | - */ |
|
| 2798 | - public function set_email_cc( $value ) { |
|
| 2799 | - $this->set_prop( 'email_cc', $value ); |
|
| 2800 | - } |
|
| 2801 | - |
|
| 2802 | - /** |
|
| 2803 | - * Set the invoice template. |
|
| 2804 | - * |
|
| 2805 | - * @since 1.0.19 |
|
| 2806 | - * @param string $value template. |
|
| 2807 | - */ |
|
| 2808 | - public function set_template( $value ) { |
|
| 2809 | - if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) { |
|
| 2810 | - $this->set_prop( 'template', $value ); |
|
| 2811 | - } |
|
| 2812 | - } |
|
| 2813 | - |
|
| 2814 | - /** |
|
| 2815 | - * Set the invoice source. |
|
| 2816 | - * |
|
| 2817 | - * @since 1.0.19 |
|
| 2818 | - * @param string $value source. |
|
| 2819 | - * @deprecated |
|
| 2820 | - */ |
|
| 2821 | - public function created_via( $value ) { |
|
| 2822 | - $this->set_created_via( sanitize_text_field( $value ) ); |
|
| 2823 | - } |
|
| 2824 | - |
|
| 2825 | - /** |
|
| 2826 | - * Set the invoice source. |
|
| 2827 | - * |
|
| 2828 | - * @since 1.0.19 |
|
| 2829 | - * @param string $value source. |
|
| 2830 | - */ |
|
| 2831 | - public function set_created_via( $value ) { |
|
| 2832 | - $this->set_prop( 'created_via', sanitize_text_field( $value ) ); |
|
| 2833 | - } |
|
| 2834 | - |
|
| 2835 | - /** |
|
| 2836 | - * Set the customer's address confirmed status. |
|
| 2837 | - * |
|
| 2838 | - * @since 1.0.19 |
|
| 2839 | - * @param int|bool $value confirmed. |
|
| 2840 | - */ |
|
| 2841 | - public function set_address_confirmed( $value ) { |
|
| 2842 | - $this->set_prop( 'address_confirmed', $value ); |
|
| 2843 | - } |
|
| 2844 | - |
|
| 2845 | - /** |
|
| 2846 | - * Alias of self::set_address_confirmed(). |
|
| 2847 | - * |
|
| 2848 | - * @since 1.0.19 |
|
| 2849 | - * @param int|bool $value confirmed. |
|
| 2850 | - */ |
|
| 2851 | - public function set_user_address_confirmed( $value ) { |
|
| 2852 | - $this->set_address_confirmed( $value ); |
|
| 2853 | - } |
|
| 2854 | - |
|
| 2855 | - /** |
|
| 2856 | - * Alias of self::set_address_confirmed(). |
|
| 2857 | - * |
|
| 2858 | - * @since 1.0.19 |
|
| 2859 | - * @param int|bool $value confirmed. |
|
| 2860 | - */ |
|
| 2861 | - public function set_customer_address_confirmed( $value ) { |
|
| 2862 | - $this->set_address_confirmed( $value ); |
|
| 2863 | - } |
|
| 2864 | - |
|
| 2865 | - /** |
|
| 2866 | - * Set the shipping fee |
|
| 2867 | - * |
|
| 2868 | - * @since 1.0.19 |
|
| 2869 | - * @param float $value shipping amount. |
|
| 2870 | - */ |
|
| 2871 | - public function set_shipping( $value ) { |
|
| 2872 | - |
|
| 2873 | - if ( ! is_numeric( $value ) ) { |
|
| 2874 | - return $this->set_prop( 'shipping', null ); |
|
| 2875 | - } |
|
| 2876 | - |
|
| 2877 | - $this->set_prop( 'shipping', max( 0, floatval( $value ) ) ); |
|
| 2878 | - } |
|
| 2879 | - |
|
| 2880 | - /** |
|
| 2881 | - * Set the invoice sub total. |
|
| 2882 | - * |
|
| 2883 | - * @since 1.0.19 |
|
| 2884 | - * @param float $value sub total. |
|
| 2885 | - */ |
|
| 2886 | - public function set_subtotal( $value ) { |
|
| 2887 | - $this->set_prop( 'subtotal', max( 0, $value ) ); |
|
| 2888 | - } |
|
| 2889 | - |
|
| 2890 | - /** |
|
| 2891 | - * Set the invoice total. |
|
| 2892 | - * |
|
| 2893 | - * @since 1.0.19 |
|
| 2894 | - * @param float $value sub total. |
|
| 2895 | - */ |
|
| 2896 | - public function set_total( $value ) { |
|
| 2897 | - $this->set_prop( 'total', max( 0, $value ) ); |
|
| 2890 | + /** |
|
| 2891 | + * Set the invoice total. |
|
| 2892 | + * |
|
| 2893 | + * @since 1.0.19 |
|
| 2894 | + * @param float $value sub total. |
|
| 2895 | + */ |
|
| 2896 | + public function set_total( $value ) { |
|
| 2897 | + $this->set_prop( 'total', max( 0, $value ) ); |
|
| 2898 | 2898 | } |
| 2899 | 2899 | |
| 2900 | 2900 | /** |
| 2901 | - * Set the invoice discount amount. |
|
| 2902 | - * |
|
| 2903 | - * @since 1.0.19 |
|
| 2904 | - * @param float $value discount total. |
|
| 2905 | - */ |
|
| 2906 | - public function set_total_discount( $value ) { |
|
| 2907 | - $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
| 2901 | + * Set the invoice discount amount. |
|
| 2902 | + * |
|
| 2903 | + * @since 1.0.19 |
|
| 2904 | + * @param float $value discount total. |
|
| 2905 | + */ |
|
| 2906 | + public function set_total_discount( $value ) { |
|
| 2907 | + $this->set_prop( 'total_discount', max( 0, $value ) ); |
|
| 2908 | 2908 | } |
| 2909 | 2909 | |
| 2910 | 2910 | /** |
| 2911 | - * Alias of self::set_total_discount(). |
|
| 2912 | - * |
|
| 2913 | - * @since 1.0.19 |
|
| 2914 | - * @param float $value discount total. |
|
| 2915 | - */ |
|
| 2916 | - public function set_discount( $value ) { |
|
| 2917 | - $this->set_total_discount( $value ); |
|
| 2911 | + * Alias of self::set_total_discount(). |
|
| 2912 | + * |
|
| 2913 | + * @since 1.0.19 |
|
| 2914 | + * @param float $value discount total. |
|
| 2915 | + */ |
|
| 2916 | + public function set_discount( $value ) { |
|
| 2917 | + $this->set_total_discount( $value ); |
|
| 2918 | 2918 | } |
| 2919 | 2919 | |
| 2920 | 2920 | /** |
| 2921 | - * Set the invoice tax amount. |
|
| 2922 | - * |
|
| 2923 | - * @since 1.0.19 |
|
| 2924 | - * @param float $value tax total. |
|
| 2925 | - */ |
|
| 2926 | - public function set_total_tax( $value ) { |
|
| 2927 | - $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
| 2921 | + * Set the invoice tax amount. |
|
| 2922 | + * |
|
| 2923 | + * @since 1.0.19 |
|
| 2924 | + * @param float $value tax total. |
|
| 2925 | + */ |
|
| 2926 | + public function set_total_tax( $value ) { |
|
| 2927 | + $this->set_prop( 'total_tax', max( 0, $value ) ); |
|
| 2928 | 2928 | } |
| 2929 | 2929 | |
| 2930 | 2930 | /** |
| 2931 | - * Alias of self::set_total_tax(). |
|
| 2932 | - * |
|
| 2933 | - * @since 1.0.19 |
|
| 2934 | - * @param float $value tax total. |
|
| 2935 | - */ |
|
| 2936 | - public function set_tax_total( $value ) { |
|
| 2937 | - $this->set_total_tax( $value ); |
|
| 2931 | + * Alias of self::set_total_tax(). |
|
| 2932 | + * |
|
| 2933 | + * @since 1.0.19 |
|
| 2934 | + * @param float $value tax total. |
|
| 2935 | + */ |
|
| 2936 | + public function set_tax_total( $value ) { |
|
| 2937 | + $this->set_total_tax( $value ); |
|
| 2938 | 2938 | } |
| 2939 | 2939 | |
| 2940 | 2940 | /** |
| 2941 | - * Set the invoice fees amount. |
|
| 2942 | - * |
|
| 2943 | - * @since 1.0.19 |
|
| 2944 | - * @param float $value fees total. |
|
| 2945 | - */ |
|
| 2946 | - public function set_total_fees( $value ) { |
|
| 2947 | - $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
| 2941 | + * Set the invoice fees amount. |
|
| 2942 | + * |
|
| 2943 | + * @since 1.0.19 |
|
| 2944 | + * @param float $value fees total. |
|
| 2945 | + */ |
|
| 2946 | + public function set_total_fees( $value ) { |
|
| 2947 | + $this->set_prop( 'total_fees', max( 0, $value ) ); |
|
| 2948 | 2948 | } |
| 2949 | 2949 | |
| 2950 | 2950 | /** |
| 2951 | - * Alias of self::set_total_fees(). |
|
| 2952 | - * |
|
| 2953 | - * @since 1.0.19 |
|
| 2954 | - * @param float $value fees total. |
|
| 2955 | - */ |
|
| 2956 | - public function set_fees_total( $value ) { |
|
| 2957 | - $this->set_total_fees( $value ); |
|
| 2951 | + * Alias of self::set_total_fees(). |
|
| 2952 | + * |
|
| 2953 | + * @since 1.0.19 |
|
| 2954 | + * @param float $value fees total. |
|
| 2955 | + */ |
|
| 2956 | + public function set_fees_total( $value ) { |
|
| 2957 | + $this->set_total_fees( $value ); |
|
| 2958 | 2958 | } |
| 2959 | 2959 | |
| 2960 | 2960 | /** |
| 2961 | - * Set the invoice fees. |
|
| 2962 | - * |
|
| 2963 | - * @since 1.0.19 |
|
| 2964 | - * @param array $value fees. |
|
| 2965 | - */ |
|
| 2966 | - public function set_fees( $value ) { |
|
| 2961 | + * Set the invoice fees. |
|
| 2962 | + * |
|
| 2963 | + * @since 1.0.19 |
|
| 2964 | + * @param array $value fees. |
|
| 2965 | + */ |
|
| 2966 | + public function set_fees( $value ) { |
|
| 2967 | 2967 | |
| 2968 | - if ( ! is_array( $value ) ) { |
|
| 2969 | - $value = array(); |
|
| 2970 | - } |
|
| 2968 | + if ( ! is_array( $value ) ) { |
|
| 2969 | + $value = array(); |
|
| 2970 | + } |
|
| 2971 | 2971 | |
| 2972 | - $this->set_prop( 'fees', $value ); |
|
| 2972 | + $this->set_prop( 'fees', $value ); |
|
| 2973 | 2973 | |
| 2974 | 2974 | } |
| 2975 | 2975 | |
| 2976 | 2976 | /** |
| 2977 | - * Set the invoice taxes. |
|
| 2978 | - * |
|
| 2979 | - * @since 1.0.19 |
|
| 2980 | - * @param array $value taxes. |
|
| 2981 | - */ |
|
| 2982 | - public function set_taxes( $value ) { |
|
| 2977 | + * Set the invoice taxes. |
|
| 2978 | + * |
|
| 2979 | + * @since 1.0.19 |
|
| 2980 | + * @param array $value taxes. |
|
| 2981 | + */ |
|
| 2982 | + public function set_taxes( $value ) { |
|
| 2983 | 2983 | |
| 2984 | - if ( ! is_array( $value ) ) { |
|
| 2985 | - $value = array(); |
|
| 2986 | - } |
|
| 2984 | + if ( ! is_array( $value ) ) { |
|
| 2985 | + $value = array(); |
|
| 2986 | + } |
|
| 2987 | 2987 | |
| 2988 | - $this->set_prop( 'taxes', $value ); |
|
| 2988 | + $this->set_prop( 'taxes', $value ); |
|
| 2989 | 2989 | |
| 2990 | 2990 | } |
| 2991 | 2991 | |
| 2992 | 2992 | /** |
| 2993 | - * Set the invoice discounts. |
|
| 2994 | - * |
|
| 2995 | - * @since 1.0.19 |
|
| 2996 | - * @param array $value discounts. |
|
| 2997 | - */ |
|
| 2998 | - public function set_discounts( $value ) { |
|
| 2993 | + * Set the invoice discounts. |
|
| 2994 | + * |
|
| 2995 | + * @since 1.0.19 |
|
| 2996 | + * @param array $value discounts. |
|
| 2997 | + */ |
|
| 2998 | + public function set_discounts( $value ) { |
|
| 2999 | 2999 | |
| 3000 | - if ( ! is_array( $value ) ) { |
|
| 3001 | - $value = array(); |
|
| 3002 | - } |
|
| 3000 | + if ( ! is_array( $value ) ) { |
|
| 3001 | + $value = array(); |
|
| 3002 | + } |
|
| 3003 | 3003 | |
| 3004 | - $this->set_prop( 'discounts', $value ); |
|
| 3004 | + $this->set_prop( 'discounts', $value ); |
|
| 3005 | 3005 | } |
| 3006 | 3006 | |
| 3007 | 3007 | /** |
| 3008 | - * Set the invoice items. |
|
| 3009 | - * |
|
| 3010 | - * @since 1.0.19 |
|
| 3011 | - * @param GetPaid_Form_Item[] $value items. |
|
| 3012 | - */ |
|
| 3013 | - public function set_items( $value ) { |
|
| 3008 | + * Set the invoice items. |
|
| 3009 | + * |
|
| 3010 | + * @since 1.0.19 |
|
| 3011 | + * @param GetPaid_Form_Item[] $value items. |
|
| 3012 | + */ |
|
| 3013 | + public function set_items( $value ) { |
|
| 3014 | 3014 | |
| 3015 | 3015 | // Remove existing items. |
| 3016 | 3016 | $this->set_prop( 'items', array() ); |
| 3017 | - $this->recurring_item = null; |
|
| 3017 | + $this->recurring_item = null; |
|
| 3018 | 3018 | |
| 3019 | 3019 | // Ensure that we have an array. |
| 3020 | 3020 | if ( ! is_array( $value ) ) { |
@@ -3028,95 +3028,95 @@ discard block |
||
| 3028 | 3028 | } |
| 3029 | 3029 | |
| 3030 | 3030 | /** |
| 3031 | - * Set the payment form. |
|
| 3032 | - * |
|
| 3033 | - * @since 1.0.19 |
|
| 3034 | - * @param int $value payment form. |
|
| 3035 | - */ |
|
| 3036 | - public function set_payment_form( $value ) { |
|
| 3037 | - $this->set_prop( 'payment_form', $value ); |
|
| 3031 | + * Set the payment form. |
|
| 3032 | + * |
|
| 3033 | + * @since 1.0.19 |
|
| 3034 | + * @param int $value payment form. |
|
| 3035 | + */ |
|
| 3036 | + public function set_payment_form( $value ) { |
|
| 3037 | + $this->set_prop( 'payment_form', $value ); |
|
| 3038 | 3038 | } |
| 3039 | 3039 | |
| 3040 | 3040 | /** |
| 3041 | - * Set the submission id. |
|
| 3042 | - * |
|
| 3043 | - * @since 1.0.19 |
|
| 3044 | - * @param string $value submission id. |
|
| 3045 | - */ |
|
| 3046 | - public function set_submission_id( $value ) { |
|
| 3047 | - $this->set_prop( 'submission_id', $value ); |
|
| 3041 | + * Set the submission id. |
|
| 3042 | + * |
|
| 3043 | + * @since 1.0.19 |
|
| 3044 | + * @param string $value submission id. |
|
| 3045 | + */ |
|
| 3046 | + public function set_submission_id( $value ) { |
|
| 3047 | + $this->set_prop( 'submission_id', $value ); |
|
| 3048 | 3048 | } |
| 3049 | 3049 | |
| 3050 | 3050 | /** |
| 3051 | - * Set the discount code. |
|
| 3052 | - * |
|
| 3053 | - * @since 1.0.19 |
|
| 3054 | - * @param string $value discount code. |
|
| 3055 | - */ |
|
| 3056 | - public function set_discount_code( $value ) { |
|
| 3057 | - $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
| 3051 | + * Set the discount code. |
|
| 3052 | + * |
|
| 3053 | + * @since 1.0.19 |
|
| 3054 | + * @param string $value discount code. |
|
| 3055 | + */ |
|
| 3056 | + public function set_discount_code( $value ) { |
|
| 3057 | + $this->set_prop( 'discount_code', sanitize_text_field( $value ) ); |
|
| 3058 | 3058 | } |
| 3059 | 3059 | |
| 3060 | 3060 | /** |
| 3061 | - * Set the gateway. |
|
| 3062 | - * |
|
| 3063 | - * @since 1.0.19 |
|
| 3064 | - * @param string $value gateway. |
|
| 3065 | - */ |
|
| 3066 | - public function set_gateway( $value ) { |
|
| 3067 | - $this->set_prop( 'gateway', $value ); |
|
| 3061 | + * Set the gateway. |
|
| 3062 | + * |
|
| 3063 | + * @since 1.0.19 |
|
| 3064 | + * @param string $value gateway. |
|
| 3065 | + */ |
|
| 3066 | + public function set_gateway( $value ) { |
|
| 3067 | + $this->set_prop( 'gateway', $value ); |
|
| 3068 | 3068 | } |
| 3069 | 3069 | |
| 3070 | 3070 | /** |
| 3071 | - * Set the transaction id. |
|
| 3072 | - * |
|
| 3073 | - * @since 1.0.19 |
|
| 3074 | - * @param string $value transaction id. |
|
| 3075 | - */ |
|
| 3076 | - public function set_transaction_id( $value ) { |
|
| 3077 | - if ( ! empty( $value ) ) { |
|
| 3078 | - $this->set_prop( 'transaction_id', $value ); |
|
| 3079 | - } |
|
| 3071 | + * Set the transaction id. |
|
| 3072 | + * |
|
| 3073 | + * @since 1.0.19 |
|
| 3074 | + * @param string $value transaction id. |
|
| 3075 | + */ |
|
| 3076 | + public function set_transaction_id( $value ) { |
|
| 3077 | + if ( ! empty( $value ) ) { |
|
| 3078 | + $this->set_prop( 'transaction_id', $value ); |
|
| 3079 | + } |
|
| 3080 | 3080 | } |
| 3081 | 3081 | |
| 3082 | 3082 | /** |
| 3083 | - * Set the currency id. |
|
| 3084 | - * |
|
| 3085 | - * @since 1.0.19 |
|
| 3086 | - * @param string $value currency id. |
|
| 3087 | - */ |
|
| 3088 | - public function set_currency( $value ) { |
|
| 3089 | - $this->set_prop( 'currency', $value ); |
|
| 3083 | + * Set the currency id. |
|
| 3084 | + * |
|
| 3085 | + * @since 1.0.19 |
|
| 3086 | + * @param string $value currency id. |
|
| 3087 | + */ |
|
| 3088 | + public function set_currency( $value ) { |
|
| 3089 | + $this->set_prop( 'currency', $value ); |
|
| 3090 | 3090 | } |
| 3091 | 3091 | |
| 3092 | - /** |
|
| 3093 | - * Set whether to disable taxes. |
|
| 3094 | - * |
|
| 3095 | - * @since 1.0.19 |
|
| 3096 | - * @param bool $value value. |
|
| 3097 | - */ |
|
| 3098 | - public function set_disable_taxes( $value ) { |
|
| 3099 | - $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 3100 | - } |
|
| 3092 | + /** |
|
| 3093 | + * Set whether to disable taxes. |
|
| 3094 | + * |
|
| 3095 | + * @since 1.0.19 |
|
| 3096 | + * @param bool $value value. |
|
| 3097 | + */ |
|
| 3098 | + public function set_disable_taxes( $value ) { |
|
| 3099 | + $this->set_prop( 'disable_taxes', (bool) $value ); |
|
| 3100 | + } |
|
| 3101 | 3101 | |
| 3102 | 3102 | /** |
| 3103 | - * Set the subscription id. |
|
| 3104 | - * |
|
| 3105 | - * @since 1.0.19 |
|
| 3106 | - * @param string $value subscription id. |
|
| 3107 | - */ |
|
| 3108 | - public function set_subscription_id( $value ) { |
|
| 3109 | - $this->set_prop( 'subscription_id', $value ); |
|
| 3110 | - } |
|
| 3103 | + * Set the subscription id. |
|
| 3104 | + * |
|
| 3105 | + * @since 1.0.19 |
|
| 3106 | + * @param string $value subscription id. |
|
| 3107 | + */ |
|
| 3108 | + public function set_subscription_id( $value ) { |
|
| 3109 | + $this->set_prop( 'subscription_id', $value ); |
|
| 3110 | + } |
|
| 3111 | 3111 | |
| 3112 | - /** |
|
| 3113 | - * Set the remote subscription id. |
|
| 3114 | - * |
|
| 3115 | - * @since 1.0.19 |
|
| 3116 | - * @param string $value subscription id. |
|
| 3117 | - */ |
|
| 3118 | - public function set_remote_subscription_id( $value ) { |
|
| 3119 | - $this->set_prop( 'remote_subscription_id', $value ); |
|
| 3112 | + /** |
|
| 3113 | + * Set the remote subscription id. |
|
| 3114 | + * |
|
| 3115 | + * @since 1.0.19 |
|
| 3116 | + * @param string $value subscription id. |
|
| 3117 | + */ |
|
| 3118 | + public function set_remote_subscription_id( $value ) { |
|
| 3119 | + $this->set_prop( 'remote_subscription_id', $value ); |
|
| 3120 | 3120 | } |
| 3121 | 3121 | |
| 3122 | 3122 | /* |
@@ -3155,24 +3155,24 @@ discard block |
||
| 3155 | 3155 | */ |
| 3156 | 3156 | public function is_taxable() { |
| 3157 | 3157 | return ! $this->get_disable_taxes(); |
| 3158 | - } |
|
| 3158 | + } |
|
| 3159 | 3159 | |
| 3160 | - /** |
|
| 3161 | - * @deprecated |
|
| 3162 | - */ |
|
| 3163 | - public function has_vat() { |
|
| 3160 | + /** |
|
| 3161 | + * @deprecated |
|
| 3162 | + */ |
|
| 3163 | + public function has_vat() { |
|
| 3164 | 3164 | return $this->is_taxable(); |
| 3165 | - } |
|
| 3165 | + } |
|
| 3166 | 3166 | |
| 3167 | - /** |
|
| 3168 | - * Checks to see if the invoice requires payment. |
|
| 3169 | - */ |
|
| 3170 | - public function is_free() { |
|
| 3167 | + /** |
|
| 3168 | + * Checks to see if the invoice requires payment. |
|
| 3169 | + */ |
|
| 3170 | + public function is_free() { |
|
| 3171 | 3171 | $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 ); |
| 3172 | 3172 | |
| 3173 | - if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 3174 | - $is_free = false; |
|
| 3175 | - } |
|
| 3173 | + if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) { |
|
| 3174 | + $is_free = false; |
|
| 3175 | + } |
|
| 3176 | 3176 | |
| 3177 | 3177 | return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
| 3178 | 3178 | } |
@@ -3183,46 +3183,46 @@ discard block |
||
| 3183 | 3183 | public function is_paid() { |
| 3184 | 3184 | $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
| 3185 | 3185 | return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
| 3186 | - } |
|
| 3186 | + } |
|
| 3187 | 3187 | |
| 3188 | - /** |
|
| 3188 | + /** |
|
| 3189 | 3189 | * Checks if the invoice needs payment. |
| 3190 | 3190 | */ |
| 3191 | - public function needs_payment() { |
|
| 3192 | - $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 3191 | + public function needs_payment() { |
|
| 3192 | + $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free(); |
|
| 3193 | 3193 | return apply_filters( 'wpinv_needs_payment', $needs_payment, $this ); |
| 3194 | 3194 | } |
| 3195 | 3195 | |
| 3196 | - /** |
|
| 3196 | + /** |
|
| 3197 | 3197 | * Checks if the invoice is refunded. |
| 3198 | 3198 | */ |
| 3199 | - public function is_refunded() { |
|
| 3199 | + public function is_refunded() { |
|
| 3200 | 3200 | $is_refunded = $this->has_status( 'wpi-refunded' ); |
| 3201 | 3201 | return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
| 3202 | - } |
|
| 3202 | + } |
|
| 3203 | 3203 | |
| 3204 | - /** |
|
| 3204 | + /** |
|
| 3205 | 3205 | * Checks if the invoice is held. |
| 3206 | 3206 | */ |
| 3207 | - public function is_held() { |
|
| 3207 | + public function is_held() { |
|
| 3208 | 3208 | $is_held = $this->has_status( 'wpi-onhold' ); |
| 3209 | 3209 | return apply_filters( 'wpinv_invoice_is_held', $is_held, $this ); |
| 3210 | - } |
|
| 3210 | + } |
|
| 3211 | 3211 | |
| 3212 | - /** |
|
| 3212 | + /** |
|
| 3213 | 3213 | * Checks if the invoice is due. |
| 3214 | 3214 | */ |
| 3215 | - public function is_due() { |
|
| 3216 | - $due_date = $this->get_due_date(); |
|
| 3217 | - return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3218 | - } |
|
| 3215 | + public function is_due() { |
|
| 3216 | + $due_date = $this->get_due_date(); |
|
| 3217 | + return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date ); |
|
| 3218 | + } |
|
| 3219 | 3219 | |
| 3220 | - /** |
|
| 3220 | + /** |
|
| 3221 | 3221 | * Checks if the invoice is draft. |
| 3222 | 3222 | */ |
| 3223 | - public function is_draft() { |
|
| 3223 | + public function is_draft() { |
|
| 3224 | 3224 | return $this->has_status( 'draft, auto-draft' ); |
| 3225 | - } |
|
| 3225 | + } |
|
| 3226 | 3226 | |
| 3227 | 3227 | /** |
| 3228 | 3228 | * Checks if the invoice has a given status. |
@@ -3230,9 +3230,9 @@ discard block |
||
| 3230 | 3230 | public function has_status( $status ) { |
| 3231 | 3231 | $status = wpinv_parse_list( $status ); |
| 3232 | 3232 | return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
| 3233 | - } |
|
| 3233 | + } |
|
| 3234 | 3234 | |
| 3235 | - /** |
|
| 3235 | + /** |
|
| 3236 | 3236 | * Checks if the invoice is of a given type. |
| 3237 | 3237 | */ |
| 3238 | 3238 | public function is_type( $type ) { |
@@ -3255,25 +3255,25 @@ discard block |
||
| 3255 | 3255 | */ |
| 3256 | 3256 | public function has_free_trial() { |
| 3257 | 3257 | return $this->is_recurring() && 0 == $this->get_initial_total(); |
| 3258 | - } |
|
| 3258 | + } |
|
| 3259 | 3259 | |
| 3260 | - /** |
|
| 3260 | + /** |
|
| 3261 | 3261 | * @deprecated |
| 3262 | 3262 | */ |
| 3263 | 3263 | public function is_free_trial() { |
| 3264 | 3264 | $this->has_free_trial(); |
| 3265 | 3265 | } |
| 3266 | 3266 | |
| 3267 | - /** |
|
| 3267 | + /** |
|
| 3268 | 3268 | * Check if the initial payment if 0. |
| 3269 | 3269 | * |
| 3270 | 3270 | */ |
| 3271 | - public function is_initial_free() { |
|
| 3271 | + public function is_initial_free() { |
|
| 3272 | 3272 | $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 ); |
| 3273 | 3273 | return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this ); |
| 3274 | 3274 | } |
| 3275 | 3275 | |
| 3276 | - /** |
|
| 3276 | + /** |
|
| 3277 | 3277 | * Check if the recurring item has a free trial. |
| 3278 | 3278 | * |
| 3279 | 3279 | */ |
@@ -3286,21 +3286,21 @@ discard block |
||
| 3286 | 3286 | |
| 3287 | 3287 | $item = $this->get_recurring( true ); |
| 3288 | 3288 | return $item->has_free_trial(); |
| 3289 | - } |
|
| 3289 | + } |
|
| 3290 | 3290 | |
| 3291 | - /** |
|
| 3291 | + /** |
|
| 3292 | 3292 | * Check if the free trial is a result of a discount. |
| 3293 | 3293 | */ |
| 3294 | 3294 | public function is_free_trial_from_discount() { |
| 3295 | - return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3296 | - } |
|
| 3295 | + return $this->has_free_trial() && ! $this->item_has_free_trial(); |
|
| 3296 | + } |
|
| 3297 | 3297 | |
| 3298 | - /** |
|
| 3298 | + /** |
|
| 3299 | 3299 | * @deprecated |
| 3300 | 3300 | */ |
| 3301 | 3301 | public function discount_first_payment_only() { |
| 3302 | 3302 | |
| 3303 | - $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3303 | + $discount = wpinv_get_discount_obj( $this->get_discount_code() ); |
|
| 3304 | 3304 | if ( ! $discount->exists() || ! $this->is_recurring() ) { |
| 3305 | 3305 | return true; |
| 3306 | 3306 | } |
@@ -3325,146 +3325,146 @@ discard block |
||
| 3325 | 3325 | */ |
| 3326 | 3326 | public function add_item( $item ) { |
| 3327 | 3327 | |
| 3328 | - if ( is_array( $item ) ) { |
|
| 3329 | - $item = $this->process_array_item( $item ); |
|
| 3330 | - } |
|
| 3328 | + if ( is_array( $item ) ) { |
|
| 3329 | + $item = $this->process_array_item( $item ); |
|
| 3330 | + } |
|
| 3331 | 3331 | |
| 3332 | - if ( is_numeric( $item ) ) { |
|
| 3333 | - $item = new GetPaid_Form_Item( $item ); |
|
| 3334 | - } |
|
| 3332 | + if ( is_numeric( $item ) ) { |
|
| 3333 | + $item = new GetPaid_Form_Item( $item ); |
|
| 3334 | + } |
|
| 3335 | 3335 | |
| 3336 | 3336 | // Make sure that it is available for purchase. |
| 3337 | - if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3338 | - return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3337 | + if ( $item->get_id() > 0 && ! $item->can_purchase() ) { |
|
| 3338 | + return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) ); |
|
| 3339 | 3339 | } |
| 3340 | 3340 | |
| 3341 | 3341 | // Do we have a recurring item? |
| 3342 | - if ( $item->is_recurring() ) { |
|
| 3343 | - $this->recurring_item = $item->get_id(); |
|
| 3342 | + if ( $item->is_recurring() ) { |
|
| 3343 | + $this->recurring_item = $item->get_id(); |
|
| 3344 | 3344 | } |
| 3345 | 3345 | |
| 3346 | 3346 | // Invoice id. |
| 3347 | 3347 | $item->invoice_id = (int) $this->get_id(); |
| 3348 | 3348 | |
| 3349 | - // Remove duplicates. |
|
| 3350 | - $this->remove_item( $item->get_id() ); |
|
| 3349 | + // Remove duplicates. |
|
| 3350 | + $this->remove_item( $item->get_id() ); |
|
| 3351 | 3351 | |
| 3352 | - if ( 0 == $item->get_quantity() ) { |
|
| 3353 | - return; |
|
| 3354 | - } |
|
| 3352 | + if ( 0 == $item->get_quantity() ) { |
|
| 3353 | + return; |
|
| 3354 | + } |
|
| 3355 | 3355 | |
| 3356 | - // Retrieve all items. |
|
| 3356 | + // Retrieve all items. |
|
| 3357 | 3357 | $items = $this->get_items(); |
| 3358 | 3358 | |
| 3359 | - // Add new item. |
|
| 3359 | + // Add new item. |
|
| 3360 | 3360 | $items[] = $item; |
| 3361 | 3361 | |
| 3362 | 3362 | $this->set_prop( 'items', $items ); |
| 3363 | 3363 | |
| 3364 | - return true; |
|
| 3365 | - } |
|
| 3364 | + return true; |
|
| 3365 | + } |
|
| 3366 | 3366 | |
| 3367 | - /** |
|
| 3368 | - * Converts an array to an item. |
|
| 3369 | - * |
|
| 3370 | - * @since 1.0.19 |
|
| 3371 | - * @return GetPaid_Form_Item |
|
| 3372 | - */ |
|
| 3373 | - protected function process_array_item( $array ) { |
|
| 3367 | + /** |
|
| 3368 | + * Converts an array to an item. |
|
| 3369 | + * |
|
| 3370 | + * @since 1.0.19 |
|
| 3371 | + * @return GetPaid_Form_Item |
|
| 3372 | + */ |
|
| 3373 | + protected function process_array_item( $array ) { |
|
| 3374 | 3374 | |
| 3375 | - $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3376 | - $item = new GetPaid_Form_Item( $item_id ); |
|
| 3375 | + $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0; |
|
| 3376 | + $item = new GetPaid_Form_Item( $item_id ); |
|
| 3377 | 3377 | |
| 3378 | - // Set item data. |
|
| 3379 | - foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3380 | - if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3381 | - $method = "set_$key"; |
|
| 3382 | - $item->$method( $array[ "item_$key" ] ); |
|
| 3383 | - } |
|
| 3384 | - } |
|
| 3378 | + // Set item data. |
|
| 3379 | + foreach ( array( 'name', 'price', 'description' ) as $key ) { |
|
| 3380 | + if ( isset( $array[ "item_$key" ] ) ) { |
|
| 3381 | + $method = "set_$key"; |
|
| 3382 | + $item->$method( $array[ "item_$key" ] ); |
|
| 3383 | + } |
|
| 3384 | + } |
|
| 3385 | 3385 | |
| 3386 | - if ( isset( $array['quantity'] ) ) { |
|
| 3387 | - $item->set_quantity( $array['quantity'] ); |
|
| 3388 | - } |
|
| 3386 | + if ( isset( $array['quantity'] ) ) { |
|
| 3387 | + $item->set_quantity( $array['quantity'] ); |
|
| 3388 | + } |
|
| 3389 | 3389 | |
| 3390 | - // Set item meta. |
|
| 3391 | - if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3392 | - $item->set_item_meta( $array['meta'] ); |
|
| 3393 | - } |
|
| 3390 | + // Set item meta. |
|
| 3391 | + if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) { |
|
| 3392 | + $item->set_item_meta( $array['meta'] ); |
|
| 3393 | + } |
|
| 3394 | 3394 | |
| 3395 | - return $item; |
|
| 3395 | + return $item; |
|
| 3396 | 3396 | |
| 3397 | - } |
|
| 3397 | + } |
|
| 3398 | 3398 | |
| 3399 | 3399 | /** |
| 3400 | - * Retrieves a specific item. |
|
| 3401 | - * |
|
| 3402 | - * @since 1.0.19 |
|
| 3403 | - * @return GetPaid_Form_Item|null |
|
| 3404 | - */ |
|
| 3405 | - public function get_item( $item_id ) { |
|
| 3400 | + * Retrieves a specific item. |
|
| 3401 | + * |
|
| 3402 | + * @since 1.0.19 |
|
| 3403 | + * @return GetPaid_Form_Item|null |
|
| 3404 | + */ |
|
| 3405 | + public function get_item( $item_id ) { |
|
| 3406 | 3406 | |
| 3407 | - foreach ( $this->get_items() as $item ) { |
|
| 3408 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3409 | - return $item; |
|
| 3410 | - } |
|
| 3411 | - } |
|
| 3407 | + foreach ( $this->get_items() as $item ) { |
|
| 3408 | + if ( (int) $item_id == $item->get_id() ) { |
|
| 3409 | + return $item; |
|
| 3410 | + } |
|
| 3411 | + } |
|
| 3412 | 3412 | |
| 3413 | - return null; |
|
| 3413 | + return null; |
|
| 3414 | 3414 | } |
| 3415 | 3415 | |
| 3416 | 3416 | /** |
| 3417 | - * Removes a specific item. |
|
| 3418 | - * |
|
| 3419 | - * @since 1.0.19 |
|
| 3420 | - */ |
|
| 3421 | - public function remove_item( $item_id ) { |
|
| 3422 | - $items = $this->get_items(); |
|
| 3423 | - $item_id = (int) $item_id; |
|
| 3417 | + * Removes a specific item. |
|
| 3418 | + * |
|
| 3419 | + * @since 1.0.19 |
|
| 3420 | + */ |
|
| 3421 | + public function remove_item( $item_id ) { |
|
| 3422 | + $items = $this->get_items(); |
|
| 3423 | + $item_id = (int) $item_id; |
|
| 3424 | 3424 | |
| 3425 | - foreach ( $items as $index => $item ) { |
|
| 3426 | - if ( (int) $item_id == $item->get_id() ) { |
|
| 3427 | - unset( $items[ $index ] ); |
|
| 3428 | - $this->set_prop( 'items', $items ); |
|
| 3425 | + foreach ( $items as $index => $item ) { |
|
| 3426 | + if ( (int) $item_id == $item->get_id() ) { |
|
| 3427 | + unset( $items[ $index ] ); |
|
| 3428 | + $this->set_prop( 'items', $items ); |
|
| 3429 | 3429 | |
| 3430 | - if ( $item_id == $this->recurring_item ) { |
|
| 3431 | - $this->recurring_item = null; |
|
| 3432 | - } |
|
| 3430 | + if ( $item_id == $this->recurring_item ) { |
|
| 3431 | + $this->recurring_item = null; |
|
| 3432 | + } |
|
| 3433 | 3433 | } |
| 3434 | - } |
|
| 3434 | + } |
|
| 3435 | 3435 | |
| 3436 | 3436 | } |
| 3437 | 3437 | |
| 3438 | 3438 | /** |
| 3439 | - * Adds a fee to the invoice. |
|
| 3440 | - * |
|
| 3441 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3442 | - * @since 1.0.19 |
|
| 3443 | - */ |
|
| 3439 | + * Adds a fee to the invoice. |
|
| 3440 | + * |
|
| 3441 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 3442 | + * @since 1.0.19 |
|
| 3443 | + */ |
|
| 3444 | 3444 | public function add_fee( $fee ) { |
| 3445 | 3445 | |
| 3446 | - $fees = $this->get_fees(); |
|
| 3447 | - $fees[ $fee['name'] ] = $fee; |
|
| 3448 | - $this->set_prop( 'fees', $fees ); |
|
| 3446 | + $fees = $this->get_fees(); |
|
| 3447 | + $fees[ $fee['name'] ] = $fee; |
|
| 3448 | + $this->set_prop( 'fees', $fees ); |
|
| 3449 | 3449 | |
| 3450 | 3450 | } |
| 3451 | 3451 | |
| 3452 | 3452 | /** |
| 3453 | - * Retrieves a specific fee. |
|
| 3454 | - * |
|
| 3455 | - * @since 1.0.19 |
|
| 3456 | - */ |
|
| 3457 | - public function get_fee( $fee ) { |
|
| 3453 | + * Retrieves a specific fee. |
|
| 3454 | + * |
|
| 3455 | + * @since 1.0.19 |
|
| 3456 | + */ |
|
| 3457 | + public function get_fee( $fee ) { |
|
| 3458 | 3458 | $fees = $this->get_fees(); |
| 3459 | - return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3459 | + return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null; |
|
| 3460 | 3460 | } |
| 3461 | 3461 | |
| 3462 | 3462 | /** |
| 3463 | - * Removes a specific fee. |
|
| 3464 | - * |
|
| 3465 | - * @since 1.0.19 |
|
| 3466 | - */ |
|
| 3467 | - public function remove_fee( $fee ) { |
|
| 3463 | + * Removes a specific fee. |
|
| 3464 | + * |
|
| 3465 | + * @since 1.0.19 |
|
| 3466 | + */ |
|
| 3467 | + public function remove_fee( $fee ) { |
|
| 3468 | 3468 | $fees = $this->get_fees(); |
| 3469 | 3469 | if ( isset( $fees[ $fee ] ) ) { |
| 3470 | 3470 | unset( $fees[ $fee ] ); |
@@ -3472,55 +3472,55 @@ discard block |
||
| 3472 | 3472 | } |
| 3473 | 3473 | } |
| 3474 | 3474 | |
| 3475 | - /** |
|
| 3476 | - * Adds a discount to the invoice. |
|
| 3477 | - * |
|
| 3478 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 3479 | - * @since 1.0.19 |
|
| 3480 | - */ |
|
| 3481 | - public function add_discount( $discount ) { |
|
| 3475 | + /** |
|
| 3476 | + * Adds a discount to the invoice. |
|
| 3477 | + * |
|
| 3478 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 3479 | + * @since 1.0.19 |
|
| 3480 | + */ |
|
| 3481 | + public function add_discount( $discount ) { |
|
| 3482 | 3482 | |
| 3483 | - $discounts = $this->get_discounts(); |
|
| 3484 | - $discounts[ $discount['name'] ] = $discount; |
|
| 3485 | - $this->set_prop( 'discounts', $discounts ); |
|
| 3483 | + $discounts = $this->get_discounts(); |
|
| 3484 | + $discounts[ $discount['name'] ] = $discount; |
|
| 3485 | + $this->set_prop( 'discounts', $discounts ); |
|
| 3486 | 3486 | |
| 3487 | - } |
|
| 3487 | + } |
|
| 3488 | 3488 | |
| 3489 | 3489 | /** |
| 3490 | - * Retrieves a specific discount. |
|
| 3491 | - * |
|
| 3492 | - * @since 1.0.19 |
|
| 3493 | - * @return float |
|
| 3494 | - */ |
|
| 3495 | - public function get_discount( $discount = false ) { |
|
| 3490 | + * Retrieves a specific discount. |
|
| 3491 | + * |
|
| 3492 | + * @since 1.0.19 |
|
| 3493 | + * @return float |
|
| 3494 | + */ |
|
| 3495 | + public function get_discount( $discount = false ) { |
|
| 3496 | 3496 | |
| 3497 | - // Backwards compatibilty. |
|
| 3498 | - if ( empty( $discount ) ) { |
|
| 3499 | - return $this->get_total_discount(); |
|
| 3500 | - } |
|
| 3497 | + // Backwards compatibilty. |
|
| 3498 | + if ( empty( $discount ) ) { |
|
| 3499 | + return $this->get_total_discount(); |
|
| 3500 | + } |
|
| 3501 | 3501 | |
| 3502 | 3502 | $discounts = $this->get_discounts(); |
| 3503 | - return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3503 | + return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null; |
|
| 3504 | 3504 | } |
| 3505 | 3505 | |
| 3506 | 3506 | /** |
| 3507 | - * Removes a specific discount. |
|
| 3508 | - * |
|
| 3509 | - * @since 1.0.19 |
|
| 3510 | - */ |
|
| 3511 | - public function remove_discount( $discount ) { |
|
| 3507 | + * Removes a specific discount. |
|
| 3508 | + * |
|
| 3509 | + * @since 1.0.19 |
|
| 3510 | + */ |
|
| 3511 | + public function remove_discount( $discount ) { |
|
| 3512 | 3512 | $discounts = $this->get_discounts(); |
| 3513 | 3513 | if ( isset( $discounts[ $discount ] ) ) { |
| 3514 | 3514 | unset( $discounts[ $discount ] ); |
| 3515 | 3515 | $this->set_prop( 'discounts', $discounts ); |
| 3516 | 3516 | } |
| 3517 | 3517 | |
| 3518 | - if ( 'discount_code' == $discount ) { |
|
| 3519 | - foreach ( $this->get_items() as $item ) { |
|
| 3520 | - $item->item_discount = 0; |
|
| 3521 | - $item->recurring_item_discount = 0; |
|
| 3522 | - } |
|
| 3523 | - } |
|
| 3518 | + if ( 'discount_code' == $discount ) { |
|
| 3519 | + foreach ( $this->get_items() as $item ) { |
|
| 3520 | + $item->item_discount = 0; |
|
| 3521 | + $item->recurring_item_discount = 0; |
|
| 3522 | + } |
|
| 3523 | + } |
|
| 3524 | 3524 | |
| 3525 | 3525 | } |
| 3526 | 3526 | |
@@ -3533,34 +3533,34 @@ discard block |
||
| 3533 | 3533 | if ( $this->is_taxable() ) { |
| 3534 | 3534 | |
| 3535 | 3535 | $taxes = $this->get_taxes(); |
| 3536 | - $taxes[ $tax['name'] ] = $tax; |
|
| 3537 | - $this->set_prop( 'taxes', $tax ); |
|
| 3536 | + $taxes[ $tax['name'] ] = $tax; |
|
| 3537 | + $this->set_prop( 'taxes', $tax ); |
|
| 3538 | 3538 | |
| 3539 | 3539 | } |
| 3540 | 3540 | } |
| 3541 | 3541 | |
| 3542 | 3542 | /** |
| 3543 | - * Retrieves a specific tax. |
|
| 3544 | - * |
|
| 3545 | - * @since 1.0.19 |
|
| 3546 | - */ |
|
| 3547 | - public function get_tax( $tax = null ) { |
|
| 3543 | + * Retrieves a specific tax. |
|
| 3544 | + * |
|
| 3545 | + * @since 1.0.19 |
|
| 3546 | + */ |
|
| 3547 | + public function get_tax( $tax = null ) { |
|
| 3548 | 3548 | |
| 3549 | - // Backwards compatility. |
|
| 3550 | - if ( empty( $tax ) ) { |
|
| 3551 | - return $this->get_total_tax(); |
|
| 3552 | - } |
|
| 3549 | + // Backwards compatility. |
|
| 3550 | + if ( empty( $tax ) ) { |
|
| 3551 | + return $this->get_total_tax(); |
|
| 3552 | + } |
|
| 3553 | 3553 | |
| 3554 | 3554 | $taxes = $this->get_taxes(); |
| 3555 | - return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3555 | + return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null; |
|
| 3556 | 3556 | } |
| 3557 | 3557 | |
| 3558 | 3558 | /** |
| 3559 | - * Removes a specific tax. |
|
| 3560 | - * |
|
| 3561 | - * @since 1.0.19 |
|
| 3562 | - */ |
|
| 3563 | - public function remove_tax( $tax ) { |
|
| 3559 | + * Removes a specific tax. |
|
| 3560 | + * |
|
| 3561 | + * @since 1.0.19 |
|
| 3562 | + */ |
|
| 3563 | + public function remove_tax( $tax ) { |
|
| 3564 | 3564 | $taxes = $this->get_taxes(); |
| 3565 | 3565 | if ( isset( $taxes[ $tax ] ) ) { |
| 3566 | 3566 | unset( $taxes[ $tax ] ); |
@@ -3569,184 +3569,184 @@ discard block |
||
| 3569 | 3569 | } |
| 3570 | 3570 | |
| 3571 | 3571 | /** |
| 3572 | - * Recalculates the invoice subtotal. |
|
| 3573 | - * |
|
| 3574 | - * @since 1.0.19 |
|
| 3575 | - * @return float The recalculated subtotal |
|
| 3576 | - */ |
|
| 3577 | - public function recalculate_subtotal() { |
|
| 3572 | + * Recalculates the invoice subtotal. |
|
| 3573 | + * |
|
| 3574 | + * @since 1.0.19 |
|
| 3575 | + * @return float The recalculated subtotal |
|
| 3576 | + */ |
|
| 3577 | + public function recalculate_subtotal() { |
|
| 3578 | 3578 | $items = $this->get_items(); |
| 3579 | - $subtotal = 0; |
|
| 3580 | - $recurring = 0; |
|
| 3579 | + $subtotal = 0; |
|
| 3580 | + $recurring = 0; |
|
| 3581 | 3581 | |
| 3582 | 3582 | foreach ( $items as $item ) { |
| 3583 | - $subtotal += $item->get_sub_total( 'edit' ); |
|
| 3584 | - $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
| 3583 | + $subtotal += $item->get_sub_total( 'edit' ); |
|
| 3584 | + $recurring += $item->get_recurring_sub_total( 'edit' ); |
|
| 3585 | 3585 | } |
| 3586 | 3586 | |
| 3587 | - if ( wpinv_prices_include_tax() ) { |
|
| 3588 | - $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
| 3589 | - $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
| 3590 | - } |
|
| 3587 | + if ( wpinv_prices_include_tax() ) { |
|
| 3588 | + $subtotal = max( 0, $subtotal - $this->totals['tax']['initial'] ); |
|
| 3589 | + $recurring = max( 0, $recurring - $this->totals['tax']['recurring'] ); |
|
| 3590 | + } |
|
| 3591 | 3591 | |
| 3592 | - $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3593 | - $this->set_subtotal( $current ); |
|
| 3592 | + $current = $this->is_renewal() ? $recurring : $subtotal; |
|
| 3593 | + $this->set_subtotal( $current ); |
|
| 3594 | 3594 | |
| 3595 | - $this->totals['subtotal'] = array( |
|
| 3596 | - 'initial' => $subtotal, |
|
| 3597 | - 'recurring' => $recurring, |
|
| 3598 | - ); |
|
| 3595 | + $this->totals['subtotal'] = array( |
|
| 3596 | + 'initial' => $subtotal, |
|
| 3597 | + 'recurring' => $recurring, |
|
| 3598 | + ); |
|
| 3599 | 3599 | |
| 3600 | 3600 | return $current; |
| 3601 | 3601 | } |
| 3602 | 3602 | |
| 3603 | 3603 | /** |
| 3604 | - * Recalculates the invoice discount total. |
|
| 3605 | - * |
|
| 3606 | - * @since 1.0.19 |
|
| 3607 | - * @return float The recalculated discount |
|
| 3608 | - */ |
|
| 3609 | - public function recalculate_total_discount() { |
|
| 3604 | + * Recalculates the invoice discount total. |
|
| 3605 | + * |
|
| 3606 | + * @since 1.0.19 |
|
| 3607 | + * @return float The recalculated discount |
|
| 3608 | + */ |
|
| 3609 | + public function recalculate_total_discount() { |
|
| 3610 | 3610 | $discounts = $this->get_discounts(); |
| 3611 | - $discount = 0; |
|
| 3612 | - $recurring = 0; |
|
| 3611 | + $discount = 0; |
|
| 3612 | + $recurring = 0; |
|
| 3613 | 3613 | |
| 3614 | 3614 | foreach ( $discounts as $data ) { |
| 3615 | - $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3616 | - $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3617 | - } |
|
| 3615 | + $discount += wpinv_sanitize_amount( $data['initial_discount'] ); |
|
| 3616 | + $recurring += wpinv_sanitize_amount( $data['recurring_discount'] ); |
|
| 3617 | + } |
|
| 3618 | 3618 | |
| 3619 | - $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3619 | + $current = $this->is_renewal() ? $recurring : $discount; |
|
| 3620 | 3620 | |
| 3621 | - $this->set_total_discount( $current ); |
|
| 3621 | + $this->set_total_discount( $current ); |
|
| 3622 | 3622 | |
| 3623 | - $this->totals['discount'] = array( |
|
| 3624 | - 'initial' => $discount, |
|
| 3625 | - 'recurring' => $recurring, |
|
| 3626 | - ); |
|
| 3623 | + $this->totals['discount'] = array( |
|
| 3624 | + 'initial' => $discount, |
|
| 3625 | + 'recurring' => $recurring, |
|
| 3626 | + ); |
|
| 3627 | 3627 | |
| 3628 | - return $current; |
|
| 3628 | + return $current; |
|
| 3629 | 3629 | |
| 3630 | 3630 | } |
| 3631 | 3631 | |
| 3632 | 3632 | /** |
| 3633 | - * Recalculates the invoice tax total. |
|
| 3634 | - * |
|
| 3635 | - * @since 1.0.19 |
|
| 3636 | - * @return float The recalculated tax |
|
| 3637 | - */ |
|
| 3638 | - public function recalculate_total_tax() { |
|
| 3633 | + * Recalculates the invoice tax total. |
|
| 3634 | + * |
|
| 3635 | + * @since 1.0.19 |
|
| 3636 | + * @return float The recalculated tax |
|
| 3637 | + */ |
|
| 3638 | + public function recalculate_total_tax() { |
|
| 3639 | 3639 | |
| 3640 | - // Maybe disable taxes. |
|
| 3641 | - $vat_number = $this->get_vat_number(); |
|
| 3642 | - $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
| 3640 | + // Maybe disable taxes. |
|
| 3641 | + $vat_number = $this->get_vat_number(); |
|
| 3642 | + $skip_tax = GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $this->get_country() ) && ! empty( $vat_number ); |
|
| 3643 | 3643 | |
| 3644 | - if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 3645 | - $skip_tax = false; |
|
| 3646 | - } |
|
| 3644 | + if ( wpinv_is_base_country( $this->get_country() ) && 'vat_too' === wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 3645 | + $skip_tax = false; |
|
| 3646 | + } |
|
| 3647 | 3647 | |
| 3648 | - if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
| 3648 | + if ( ! wpinv_use_taxes() || $this->get_disable_taxes() || ! wpinv_is_country_taxable( $this->get_country() ) || $skip_tax ) { |
|
| 3649 | 3649 | |
| 3650 | - $this->totals['tax'] = array( |
|
| 3651 | - 'initial' => 0, |
|
| 3652 | - 'recurring' => 0, |
|
| 3653 | - ); |
|
| 3650 | + $this->totals['tax'] = array( |
|
| 3651 | + 'initial' => 0, |
|
| 3652 | + 'recurring' => 0, |
|
| 3653 | + ); |
|
| 3654 | 3654 | |
| 3655 | - $this->tax_rate = 0; |
|
| 3655 | + $this->tax_rate = 0; |
|
| 3656 | 3656 | |
| 3657 | - $this->set_taxes( array() ); |
|
| 3658 | - $current = 0; |
|
| 3659 | - } else { |
|
| 3657 | + $this->set_taxes( array() ); |
|
| 3658 | + $current = 0; |
|
| 3659 | + } else { |
|
| 3660 | 3660 | |
| 3661 | - $item_taxes = array(); |
|
| 3661 | + $item_taxes = array(); |
|
| 3662 | 3662 | |
| 3663 | - foreach ( $this->get_items() as $item ) { |
|
| 3664 | - $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
| 3665 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 3666 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 3667 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 3668 | - foreach ( $taxes as $name => $amount ) { |
|
| 3669 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 3670 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 3663 | + foreach ( $this->get_items() as $item ) { |
|
| 3664 | + $rates = getpaid_get_item_tax_rates( $item, $this->get_country(), $this->get_state() ); |
|
| 3665 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 3666 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
| 3667 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
| 3668 | + foreach ( $taxes as $name => $amount ) { |
|
| 3669 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 3670 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 3671 | 3671 | |
| 3672 | - if ( ! isset( $item_taxes[ $name ] ) ) { |
|
| 3673 | - $item_taxes[ $name ] = $tax; |
|
| 3674 | - continue; |
|
| 3675 | - } |
|
| 3672 | + if ( ! isset( $item_taxes[ $name ] ) ) { |
|
| 3673 | + $item_taxes[ $name ] = $tax; |
|
| 3674 | + continue; |
|
| 3675 | + } |
|
| 3676 | 3676 | |
| 3677 | - $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 3678 | - $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3677 | + $item_taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 3678 | + $item_taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 3679 | 3679 | |
| 3680 | - } |
|
| 3681 | - } |
|
| 3680 | + } |
|
| 3681 | + } |
|
| 3682 | 3682 | |
| 3683 | - $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
| 3684 | - $this->set_taxes( $item_taxes ); |
|
| 3683 | + $item_taxes = array_replace( $this->get_taxes(), $item_taxes ); |
|
| 3684 | + $this->set_taxes( $item_taxes ); |
|
| 3685 | 3685 | |
| 3686 | - $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
| 3687 | - $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
| 3686 | + $initial_tax = array_sum( wp_list_pluck( $item_taxes, 'initial_tax' ) ); |
|
| 3687 | + $recurring_tax = array_sum( wp_list_pluck( $item_taxes, 'recurring_tax' ) ); |
|
| 3688 | 3688 | |
| 3689 | - $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
| 3689 | + $current = $this->is_renewal() ? $recurring_tax : $initial_tax; |
|
| 3690 | 3690 | |
| 3691 | - $this->totals['tax'] = array( |
|
| 3692 | - 'initial' => $initial_tax, |
|
| 3693 | - 'recurring' => $recurring_tax, |
|
| 3694 | - ); |
|
| 3691 | + $this->totals['tax'] = array( |
|
| 3692 | + 'initial' => $initial_tax, |
|
| 3693 | + 'recurring' => $recurring_tax, |
|
| 3694 | + ); |
|
| 3695 | 3695 | |
| 3696 | - } |
|
| 3696 | + } |
|
| 3697 | 3697 | |
| 3698 | - $this->set_total_tax( $current ); |
|
| 3698 | + $this->set_total_tax( $current ); |
|
| 3699 | 3699 | |
| 3700 | - return $current; |
|
| 3700 | + return $current; |
|
| 3701 | 3701 | |
| 3702 | 3702 | } |
| 3703 | 3703 | |
| 3704 | 3704 | /** |
| 3705 | - * Recalculates the invoice fees total. |
|
| 3706 | - * |
|
| 3707 | - * @since 1.0.19 |
|
| 3708 | - * @return float The recalculated fee |
|
| 3709 | - */ |
|
| 3710 | - public function recalculate_total_fees() { |
|
| 3711 | - $fees = $this->get_fees(); |
|
| 3712 | - $fee = 0; |
|
| 3713 | - $recurring = 0; |
|
| 3705 | + * Recalculates the invoice fees total. |
|
| 3706 | + * |
|
| 3707 | + * @since 1.0.19 |
|
| 3708 | + * @return float The recalculated fee |
|
| 3709 | + */ |
|
| 3710 | + public function recalculate_total_fees() { |
|
| 3711 | + $fees = $this->get_fees(); |
|
| 3712 | + $fee = 0; |
|
| 3713 | + $recurring = 0; |
|
| 3714 | 3714 | |
| 3715 | 3715 | foreach ( $fees as $data ) { |
| 3716 | - $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3717 | - $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3718 | - } |
|
| 3716 | + $fee += wpinv_sanitize_amount( $data['initial_fee'] ); |
|
| 3717 | + $recurring += wpinv_sanitize_amount( $data['recurring_fee'] ); |
|
| 3718 | + } |
|
| 3719 | 3719 | |
| 3720 | - $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3721 | - $this->set_total_fees( $current ); |
|
| 3720 | + $current = $this->is_renewal() ? $recurring : $fee; |
|
| 3721 | + $this->set_total_fees( $current ); |
|
| 3722 | 3722 | |
| 3723 | - $this->totals['fee'] = array( |
|
| 3724 | - 'initial' => $fee, |
|
| 3725 | - 'recurring' => $recurring, |
|
| 3726 | - ); |
|
| 3723 | + $this->totals['fee'] = array( |
|
| 3724 | + 'initial' => $fee, |
|
| 3725 | + 'recurring' => $recurring, |
|
| 3726 | + ); |
|
| 3727 | 3727 | |
| 3728 | 3728 | $this->set_total_fees( $fee ); |
| 3729 | 3729 | return $current; |
| 3730 | 3730 | } |
| 3731 | 3731 | |
| 3732 | 3732 | /** |
| 3733 | - * Recalculates the invoice total. |
|
| 3734 | - * |
|
| 3735 | - * @since 1.0.19 |
|
| 3733 | + * Recalculates the invoice total. |
|
| 3734 | + * |
|
| 3735 | + * @since 1.0.19 |
|
| 3736 | 3736 | * @return float The invoice total |
| 3737 | - */ |
|
| 3738 | - public function recalculate_total() { |
|
| 3737 | + */ |
|
| 3738 | + public function recalculate_total() { |
|
| 3739 | 3739 | $this->recalculate_total_fees(); |
| 3740 | 3740 | $this->recalculate_total_discount(); |
| 3741 | - $this->recalculate_total_tax(); |
|
| 3742 | - $this->recalculate_subtotal(); |
|
| 3743 | - $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
| 3744 | - return $this->get_total(); |
|
| 3745 | - } |
|
| 3746 | - |
|
| 3747 | - /** |
|
| 3748 | - * @deprecated |
|
| 3749 | - */ |
|
| 3741 | + $this->recalculate_total_tax(); |
|
| 3742 | + $this->recalculate_subtotal(); |
|
| 3743 | + $this->set_total( $this->get_total_tax( 'edit' ) + $this->get_total_fees( 'edit' ) + $this->get_subtotal( 'edit' ) - $this->get_total_discount( 'edit' ) ); |
|
| 3744 | + return $this->get_total(); |
|
| 3745 | + } |
|
| 3746 | + |
|
| 3747 | + /** |
|
| 3748 | + * @deprecated |
|
| 3749 | + */ |
|
| 3750 | 3750 | public function recalculate_totals() { |
| 3751 | 3751 | $this->recalculate_total(); |
| 3752 | 3752 | $this->save( true ); |
@@ -3760,22 +3760,22 @@ discard block |
||
| 3760 | 3760 | return $this->get_data(); |
| 3761 | 3761 | } |
| 3762 | 3762 | |
| 3763 | - /** |
|
| 3763 | + /** |
|
| 3764 | 3764 | * Adds a system note to an invoice. |
| 3765 | 3765 | * |
| 3766 | 3766 | * @param string $note The note being added. |
| 3767 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3767 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3768 | 3768 | * |
| 3769 | 3769 | */ |
| 3770 | 3770 | public function add_system_note( $note ) { |
| 3771 | - return $this->add_note( $note, false, false, true ); |
|
| 3772 | - } |
|
| 3771 | + return $this->add_note( $note, false, false, true ); |
|
| 3772 | + } |
|
| 3773 | 3773 | |
| 3774 | 3774 | /** |
| 3775 | 3775 | * Adds a note to an invoice. |
| 3776 | 3776 | * |
| 3777 | 3777 | * @param string $note The note being added. |
| 3778 | - * @return int|false The new note's ID on success, false on failure. |
|
| 3778 | + * @return int|false The new note's ID on success, false on failure. |
|
| 3779 | 3779 | * |
| 3780 | 3780 | */ |
| 3781 | 3781 | public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
@@ -3785,21 +3785,21 @@ discard block |
||
| 3785 | 3785 | return false; |
| 3786 | 3786 | } |
| 3787 | 3787 | |
| 3788 | - $author = 'System'; |
|
| 3789 | - $author_email = '[email protected]'; |
|
| 3788 | + $author = 'System'; |
|
| 3789 | + $author_email = '[email protected]'; |
|
| 3790 | 3790 | |
| 3791 | - // If this is an admin comment or it has been added by the user. |
|
| 3792 | - if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3793 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3791 | + // If this is an admin comment or it has been added by the user. |
|
| 3792 | + if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) { |
|
| 3793 | + $user = get_user_by( 'id', get_current_user_id() ); |
|
| 3794 | 3794 | $author = $user->display_name; |
| 3795 | 3795 | $author_email = $user->user_email; |
| 3796 | - } |
|
| 3796 | + } |
|
| 3797 | 3797 | |
| 3798 | - return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3798 | + return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type ); |
|
| 3799 | 3799 | |
| 3800 | - } |
|
| 3800 | + } |
|
| 3801 | 3801 | |
| 3802 | - /** |
|
| 3802 | + /** |
|
| 3803 | 3803 | * Generates a unique key for the invoice. |
| 3804 | 3804 | */ |
| 3805 | 3805 | public function generate_key( $string = '' ) { |
@@ -3819,113 +3819,113 @@ discard block |
||
| 3819 | 3819 | $number = wpinv_get_next_invoice_number( $this->get_post_type() ); |
| 3820 | 3820 | } |
| 3821 | 3821 | |
| 3822 | - return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3823 | - |
|
| 3824 | - } |
|
| 3825 | - |
|
| 3826 | - /** |
|
| 3827 | - * Handle the status transition. |
|
| 3828 | - */ |
|
| 3829 | - protected function status_transition() { |
|
| 3830 | - $status_transition = $this->status_transition; |
|
| 3831 | - |
|
| 3832 | - // Reset status transition variable. |
|
| 3833 | - $this->status_transition = false; |
|
| 3834 | - |
|
| 3835 | - if ( $status_transition ) { |
|
| 3836 | - try { |
|
| 3822 | + return wpinv_format_invoice_number( $number, $this->get_post_type() ); |
|
| 3837 | 3823 | |
| 3838 | - // Fire a hook for the status change. |
|
| 3839 | - do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3840 | - |
|
| 3841 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3842 | - do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3843 | - |
|
| 3844 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 3845 | - |
|
| 3846 | - /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3847 | - $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3848 | - |
|
| 3849 | - // Fire another hook. |
|
| 3850 | - do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3851 | - do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3852 | - |
|
| 3853 | - // @deprecated this is deprecated and will be removed in the future. |
|
| 3854 | - do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3855 | - |
|
| 3856 | - // Note the transition occurred. |
|
| 3857 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3858 | - |
|
| 3859 | - // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3860 | - if ( |
|
| 3861 | - in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3862 | - && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3863 | - ) { |
|
| 3864 | - do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3865 | - } |
|
| 3866 | - |
|
| 3867 | - // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3868 | - if ( |
|
| 3869 | - in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3870 | - && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3871 | - ) { |
|
| 3872 | - do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3873 | - } |
|
| 3874 | - } else { |
|
| 3875 | - /* translators: %s: new invoice status */ |
|
| 3876 | - $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3877 | - |
|
| 3878 | - // Note the transition occurred. |
|
| 3879 | - $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3824 | + } |
|
| 3880 | 3825 | |
| 3881 | - } |
|
| 3882 | - } catch ( Exception $e ) { |
|
| 3883 | - $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3884 | - } |
|
| 3885 | - } |
|
| 3886 | - } |
|
| 3826 | + /** |
|
| 3827 | + * Handle the status transition. |
|
| 3828 | + */ |
|
| 3829 | + protected function status_transition() { |
|
| 3830 | + $status_transition = $this->status_transition; |
|
| 3831 | + |
|
| 3832 | + // Reset status transition variable. |
|
| 3833 | + $this->status_transition = false; |
|
| 3834 | + |
|
| 3835 | + if ( $status_transition ) { |
|
| 3836 | + try { |
|
| 3837 | + |
|
| 3838 | + // Fire a hook for the status change. |
|
| 3839 | + do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition ); |
|
| 3840 | + |
|
| 3841 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3842 | + do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3843 | + |
|
| 3844 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 3845 | + |
|
| 3846 | + /* translators: 1: old invoice status 2: new invoice status */ |
|
| 3847 | + $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3848 | + |
|
| 3849 | + // Fire another hook. |
|
| 3850 | + do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this ); |
|
| 3851 | + do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 3852 | + |
|
| 3853 | + // @deprecated this is deprecated and will be removed in the future. |
|
| 3854 | + do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] ); |
|
| 3855 | + |
|
| 3856 | + // Note the transition occurred. |
|
| 3857 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] ); |
|
| 3858 | + |
|
| 3859 | + // Work out if this was for a payment, and trigger a payment_status hook instead. |
|
| 3860 | + if ( |
|
| 3861 | + in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3862 | + && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3863 | + ) { |
|
| 3864 | + do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition ); |
|
| 3865 | + } |
|
| 3866 | + |
|
| 3867 | + // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead. |
|
| 3868 | + if ( |
|
| 3869 | + in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true ) |
|
| 3870 | + && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true ) |
|
| 3871 | + ) { |
|
| 3872 | + do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition ); |
|
| 3873 | + } |
|
| 3874 | + } else { |
|
| 3875 | + /* translators: %s: new invoice status */ |
|
| 3876 | + $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this ) ); |
|
| 3877 | + |
|
| 3878 | + // Note the transition occurred. |
|
| 3879 | + $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] ); |
|
| 3880 | + |
|
| 3881 | + } |
|
| 3882 | + } catch ( Exception $e ) { |
|
| 3883 | + $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 3884 | + } |
|
| 3885 | + } |
|
| 3886 | + } |
|
| 3887 | 3887 | |
| 3888 | - /** |
|
| 3889 | - * Updates an invoice status. |
|
| 3890 | - */ |
|
| 3891 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3888 | + /** |
|
| 3889 | + * Updates an invoice status. |
|
| 3890 | + */ |
|
| 3891 | + public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 3892 | 3892 | |
| 3893 | - // Fires before updating a status. |
|
| 3894 | - do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3893 | + // Fires before updating a status. |
|
| 3894 | + do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) ); |
|
| 3895 | 3895 | |
| 3896 | - // Update the status. |
|
| 3897 | - $this->set_status( $new_status, $note, $manual ); |
|
| 3896 | + // Update the status. |
|
| 3897 | + $this->set_status( $new_status, $note, $manual ); |
|
| 3898 | 3898 | |
| 3899 | - // Save the order. |
|
| 3900 | - return $this->save(); |
|
| 3899 | + // Save the order. |
|
| 3900 | + return $this->save(); |
|
| 3901 | 3901 | |
| 3902 | - } |
|
| 3902 | + } |
|
| 3903 | 3903 | |
| 3904 | - /** |
|
| 3905 | - * @deprecated |
|
| 3906 | - */ |
|
| 3907 | - public function refresh_item_ids() { |
|
| 3904 | + /** |
|
| 3905 | + * @deprecated |
|
| 3906 | + */ |
|
| 3907 | + public function refresh_item_ids() { |
|
| 3908 | 3908 | $item_ids = implode( ',', array_unique( wp_list_pluck( $this->get_cart_details(), 'item_id' ) ) ); |
| 3909 | 3909 | update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids ); |
| 3910 | - } |
|
| 3910 | + } |
|
| 3911 | 3911 | |
| 3912 | - /** |
|
| 3913 | - * @deprecated |
|
| 3914 | - */ |
|
| 3915 | - public function update_items( $temp = false ) { |
|
| 3912 | + /** |
|
| 3913 | + * @deprecated |
|
| 3914 | + */ |
|
| 3915 | + public function update_items( $temp = false ) { |
|
| 3916 | 3916 | |
| 3917 | - $this->set_items( $this->get_items() ); |
|
| 3917 | + $this->set_items( $this->get_items() ); |
|
| 3918 | 3918 | |
| 3919 | - if ( ! $temp ) { |
|
| 3920 | - $this->save(); |
|
| 3921 | - } |
|
| 3919 | + if ( ! $temp ) { |
|
| 3920 | + $this->save(); |
|
| 3921 | + } |
|
| 3922 | 3922 | |
| 3923 | 3923 | return $this; |
| 3924 | - } |
|
| 3924 | + } |
|
| 3925 | 3925 | |
| 3926 | - /** |
|
| 3927 | - * @deprecated |
|
| 3928 | - */ |
|
| 3926 | + /** |
|
| 3927 | + * @deprecated |
|
| 3928 | + */ |
|
| 3929 | 3929 | public function validate_discount() { |
| 3930 | 3930 | |
| 3931 | 3931 | $discount_code = $this->get_discount_code(); |
@@ -3941,93 +3941,93 @@ discard block |
||
| 3941 | 3941 | |
| 3942 | 3942 | } |
| 3943 | 3943 | |
| 3944 | - /** |
|
| 3945 | - * Refunds an invoice. |
|
| 3946 | - */ |
|
| 3944 | + /** |
|
| 3945 | + * Refunds an invoice. |
|
| 3946 | + */ |
|
| 3947 | 3947 | public function refund() { |
| 3948 | - $this->set_status( 'wpi-refunded' ); |
|
| 3948 | + $this->set_status( 'wpi-refunded' ); |
|
| 3949 | 3949 | $this->save(); |
| 3950 | - } |
|
| 3950 | + } |
|
| 3951 | 3951 | |
| 3952 | - /** |
|
| 3953 | - * Marks an invoice as paid. |
|
| 3954 | - * |
|
| 3955 | - * @param string $transaction_id |
|
| 3956 | - */ |
|
| 3952 | + /** |
|
| 3953 | + * Marks an invoice as paid. |
|
| 3954 | + * |
|
| 3955 | + * @param string $transaction_id |
|
| 3956 | + */ |
|
| 3957 | 3957 | public function mark_paid( $transaction_id = null, $note = '' ) { |
| 3958 | 3958 | |
| 3959 | - // Set the transaction id. |
|
| 3960 | - if ( empty( $transaction_id ) ) { |
|
| 3961 | - $transaction_id = $this->generate_key( 'trans_' ); |
|
| 3962 | - } |
|
| 3959 | + // Set the transaction id. |
|
| 3960 | + if ( empty( $transaction_id ) ) { |
|
| 3961 | + $transaction_id = $this->generate_key( 'trans_' ); |
|
| 3962 | + } |
|
| 3963 | 3963 | |
| 3964 | - if ( ! $this->get_transaction_id() ) { |
|
| 3965 | - $this->set_transaction_id( $transaction_id ); |
|
| 3966 | - } |
|
| 3964 | + if ( ! $this->get_transaction_id() ) { |
|
| 3965 | + $this->set_transaction_id( $transaction_id ); |
|
| 3966 | + } |
|
| 3967 | 3967 | |
| 3968 | - if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3969 | - return $this->save(); |
|
| 3970 | - } |
|
| 3968 | + if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) { |
|
| 3969 | + return $this->save(); |
|
| 3970 | + } |
|
| 3971 | 3971 | |
| 3972 | - // Set the completed date. |
|
| 3973 | - $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3972 | + // Set the completed date. |
|
| 3973 | + $this->set_date_completed( current_time( 'mysql' ) ); |
|
| 3974 | 3974 | |
| 3975 | - // Set the new status. |
|
| 3976 | - $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
| 3977 | - if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
| 3975 | + // Set the new status. |
|
| 3976 | + $gateway = sanitize_text_field( $this->get_gateway_title() ); |
|
| 3977 | + if ( $this->is_renewal() || ! $this->is_parent() ) { |
|
| 3978 | 3978 | |
| 3979 | - $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
| 3980 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3979 | + $_note = wp_sprintf( __( 'Renewed via %s', 'invoicing' ), $gateway ); |
|
| 3980 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3981 | 3981 | |
| 3982 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3983 | - $_note = $note; |
|
| 3984 | - } |
|
| 3982 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3983 | + $_note = $note; |
|
| 3984 | + } |
|
| 3985 | 3985 | |
| 3986 | - $this->set_status( 'wpi-renewal', $_note ); |
|
| 3986 | + $this->set_status( 'wpi-renewal', $_note ); |
|
| 3987 | 3987 | |
| 3988 | - } else { |
|
| 3988 | + } else { |
|
| 3989 | 3989 | |
| 3990 | - $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 3991 | - $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3990 | + $_note = wp_sprintf( __( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 3991 | + $_note = $_note . empty( $note ) ? '' : " ($note)"; |
|
| 3992 | 3992 | |
| 3993 | - if ( 'none' == $this->get_gateway() ) { |
|
| 3994 | - $_note = $note; |
|
| 3995 | - } |
|
| 3993 | + if ( 'none' == $this->get_gateway() ) { |
|
| 3994 | + $_note = $note; |
|
| 3995 | + } |
|
| 3996 | 3996 | |
| 3997 | - $this->set_status( 'publish', $_note ); |
|
| 3997 | + $this->set_status( 'publish', $_note ); |
|
| 3998 | 3998 | |
| 3999 | - } |
|
| 3999 | + } |
|
| 4000 | 4000 | |
| 4001 | - // Set checkout mode. |
|
| 4002 | - $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 4003 | - $this->set_mode( $mode ); |
|
| 4001 | + // Set checkout mode. |
|
| 4002 | + $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live'; |
|
| 4003 | + $this->set_mode( $mode ); |
|
| 4004 | 4004 | |
| 4005 | - // Save the invoice. |
|
| 4005 | + // Save the invoice. |
|
| 4006 | 4006 | $this->save(); |
| 4007 | - } |
|
| 4008 | - |
|
| 4009 | - /** |
|
| 4010 | - * Save data to the database. |
|
| 4011 | - * |
|
| 4012 | - * @since 1.0.19 |
|
| 4013 | - * @return int invoice ID |
|
| 4014 | - */ |
|
| 4015 | - public function save() { |
|
| 4016 | - $this->maybe_set_date_paid(); |
|
| 4017 | - $this->maybe_set_key(); |
|
| 4018 | - parent::save(); |
|
| 4019 | - $this->clear_cache(); |
|
| 4020 | - $this->status_transition(); |
|
| 4021 | - return $this->get_id(); |
|
| 4022 | - } |
|
| 4023 | - |
|
| 4024 | - /** |
|
| 4007 | + } |
|
| 4008 | + |
|
| 4009 | + /** |
|
| 4010 | + * Save data to the database. |
|
| 4011 | + * |
|
| 4012 | + * @since 1.0.19 |
|
| 4013 | + * @return int invoice ID |
|
| 4014 | + */ |
|
| 4015 | + public function save() { |
|
| 4016 | + $this->maybe_set_date_paid(); |
|
| 4017 | + $this->maybe_set_key(); |
|
| 4018 | + parent::save(); |
|
| 4019 | + $this->clear_cache(); |
|
| 4020 | + $this->status_transition(); |
|
| 4021 | + return $this->get_id(); |
|
| 4022 | + } |
|
| 4023 | + |
|
| 4024 | + /** |
|
| 4025 | 4025 | * Clears the subscription's cache. |
| 4026 | 4026 | */ |
| 4027 | 4027 | public function clear_cache() { |
| 4028 | - wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 4029 | - wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 4030 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 4031 | - } |
|
| 4028 | + wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' ); |
|
| 4029 | + wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' ); |
|
| 4030 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' ); |
|
| 4031 | + } |
|
| 4032 | 4032 | |
| 4033 | 4033 | } |