@@ -9,31 +9,31 @@ |
||
| 9 | 9 | defined( 'ABSPATH' ) || exit; |
| 10 | 10 | |
| 11 | 11 | return array( |
| 12 | - 'AT', |
|
| 13 | - 'BE', |
|
| 14 | - 'BG', |
|
| 15 | - 'HR', |
|
| 16 | - 'CY', |
|
| 17 | - 'CZ', |
|
| 18 | - 'DK', |
|
| 19 | - 'EE', |
|
| 20 | - 'FI', |
|
| 21 | - 'FR', |
|
| 22 | - 'DE', |
|
| 23 | - 'GR', |
|
| 24 | - 'HU', |
|
| 25 | - 'IE', |
|
| 26 | - 'IT', |
|
| 27 | - 'LV', |
|
| 28 | - 'LT', |
|
| 29 | - 'LU', |
|
| 30 | - 'MT', |
|
| 31 | - 'NL', |
|
| 32 | - 'PL', |
|
| 33 | - 'PT', |
|
| 34 | - 'RO', |
|
| 35 | - 'SK', |
|
| 36 | - 'SI', |
|
| 37 | - 'ES', |
|
| 38 | - 'SE' |
|
| 12 | + 'AT', |
|
| 13 | + 'BE', |
|
| 14 | + 'BG', |
|
| 15 | + 'HR', |
|
| 16 | + 'CY', |
|
| 17 | + 'CZ', |
|
| 18 | + 'DK', |
|
| 19 | + 'EE', |
|
| 20 | + 'FI', |
|
| 21 | + 'FR', |
|
| 22 | + 'DE', |
|
| 23 | + 'GR', |
|
| 24 | + 'HU', |
|
| 25 | + 'IE', |
|
| 26 | + 'IT', |
|
| 27 | + 'LV', |
|
| 28 | + 'LT', |
|
| 29 | + 'LU', |
|
| 30 | + 'MT', |
|
| 31 | + 'NL', |
|
| 32 | + 'PL', |
|
| 33 | + 'PT', |
|
| 34 | + 'RO', |
|
| 35 | + 'SK', |
|
| 36 | + 'SI', |
|
| 37 | + 'ES', |
|
| 38 | + 'SE' |
|
| 39 | 39 | ); |
@@ -34,11 +34,11 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) { |
| 36 | 36 | |
| 37 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 38 | - return 'manage_options'; |
|
| 39 | - }; |
|
| 37 | + if ( current_user_can( 'manage_options' ) ) { |
|
| 38 | + return 'manage_options'; |
|
| 39 | + }; |
|
| 40 | 40 | |
| 41 | - return $capalibilty; |
|
| 41 | + return $capalibilty; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | // Prepare user values. |
| 63 | 63 | $prefix = preg_replace( '/\s+/', '', $prefix ); |
| 64 | 64 | $prefix = empty( $prefix ) ? $email : $prefix; |
| 65 | - $args = array( |
|
| 66 | - 'user_login' => wpinv_generate_user_name( $prefix ), |
|
| 67 | - 'user_pass' => wp_generate_password(), |
|
| 68 | - 'user_email' => $email, |
|
| 65 | + $args = array( |
|
| 66 | + 'user_login' => wpinv_generate_user_name( $prefix ), |
|
| 67 | + 'user_pass' => wp_generate_password(), |
|
| 68 | + 'user_email' => $email, |
|
| 69 | 69 | 'role' => 'subscriber', |
| 70 | 70 | ); |
| 71 | 71 | |
@@ -82,16 +82,16 @@ discard block |
||
| 82 | 82 | function wpinv_generate_user_name( $prefix = '' ) { |
| 83 | 83 | |
| 84 | 84 | // If prefix is an email, retrieve the part before the email. |
| 85 | - $prefix = strtok( $prefix, '@' ); |
|
| 85 | + $prefix = strtok( $prefix, '@' ); |
|
| 86 | 86 | $prefix = trim( $prefix, '.' ); |
| 87 | 87 | |
| 88 | - // Sanitize the username. |
|
| 89 | - $prefix = sanitize_user( $prefix, true ); |
|
| 88 | + // Sanitize the username. |
|
| 89 | + $prefix = sanitize_user( $prefix, true ); |
|
| 90 | 90 | |
| 91 | - $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
| 92 | - if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
| 93 | - $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
| 94 | - } |
|
| 91 | + $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); |
|
| 92 | + if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { |
|
| 93 | + $prefix = 'gtp_' . zeroise( wp_rand( 0, 9999 ), 4 ); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | $username = $prefix; |
| 97 | 97 | $postfix = 2; |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | // Load WP_List_Table if not loaded |
| 11 | 11 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 12 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 12 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -21,354 +21,354 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class WPInv_Customers_Table extends WP_List_Table { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var int Number of items per page |
|
| 26 | - * @since 1.0.19 |
|
| 27 | - */ |
|
| 28 | - public $per_page = 10; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var int Number of items |
|
| 32 | - * @since 1.0.19 |
|
| 33 | - */ |
|
| 34 | - public $total = 0; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Get things started |
|
| 38 | - * |
|
| 39 | - * @since 1.0.19 |
|
| 40 | - * @see WP_List_Table::__construct() |
|
| 41 | - */ |
|
| 42 | - public function __construct() { |
|
| 43 | - |
|
| 44 | - // Set parent defaults |
|
| 45 | - parent::__construct( array( |
|
| 46 | - 'singular' => 'id', |
|
| 47 | - 'plural' => 'ids', |
|
| 48 | - 'ajax' => false, |
|
| 49 | - ) ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Gets the name of the primary column. |
|
| 55 | - * |
|
| 56 | - * @since 1.0.19 |
|
| 57 | - * @access protected |
|
| 58 | - * |
|
| 59 | - * @return string Name of the primary column. |
|
| 60 | - */ |
|
| 61 | - protected function get_primary_column_name() { |
|
| 62 | - return 'name'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * This function renders most of the columns in the list table. |
|
| 67 | - * |
|
| 68 | - * @since 1.0.19 |
|
| 69 | - * |
|
| 70 | - * @param WP_User $item |
|
| 71 | - * @param string $column_name The name of the column |
|
| 72 | - * |
|
| 73 | - * @return string Column Name |
|
| 74 | - */ |
|
| 75 | - public function column_default( $item, $column_name ) { |
|
| 76 | - $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | - return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Displays the country column. |
|
| 82 | - * |
|
| 83 | - * @since 1.0.19 |
|
| 84 | - * |
|
| 85 | - * @param WP_User $user |
|
| 86 | - * |
|
| 87 | - * @return string Column Name |
|
| 88 | - */ |
|
| 89 | - public function column_country( $user ) { |
|
| 90 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | - if ( $country ) { |
|
| 92 | - $country = wpinv_country_name( $country ); |
|
| 93 | - } |
|
| 94 | - return sanitize_text_field( $country ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Displays the state column. |
|
| 99 | - * |
|
| 100 | - * @since 1.0.19 |
|
| 101 | - * |
|
| 102 | - * @param WP_User $user |
|
| 103 | - * |
|
| 104 | - * @return string Column Name |
|
| 105 | - */ |
|
| 106 | - public function column_state( $user ) { |
|
| 107 | - $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 108 | - $state = $user->_wpinv_state; |
|
| 109 | - if ( $state ) { |
|
| 110 | - $state = wpinv_state_name( $state, $country ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return sanitize_text_field( $state ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Displays the signup column. |
|
| 118 | - * |
|
| 119 | - * @since 1.0.19 |
|
| 120 | - * |
|
| 121 | - * @param WP_User $user |
|
| 122 | - * |
|
| 123 | - * @return string Column Name |
|
| 124 | - */ |
|
| 125 | - public function column_signup( $user ) { |
|
| 126 | - return getpaid_format_date_value( $user->user_registered ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Displays the total spent column. |
|
| 131 | - * |
|
| 132 | - * @since 1.0.19 |
|
| 133 | - * |
|
| 134 | - * @param WP_User $user |
|
| 135 | - * |
|
| 136 | - * @return string Column Name |
|
| 137 | - */ |
|
| 138 | - public function column_total( $user ) { |
|
| 139 | - |
|
| 140 | - $args = array( |
|
| 141 | - 'data' => array( |
|
| 142 | - |
|
| 143 | - 'total' => array( |
|
| 144 | - 'type' => 'invoice_data', |
|
| 145 | - 'function' => 'SUM', |
|
| 146 | - 'name' => 'total_sales', |
|
| 147 | - ) |
|
| 148 | - |
|
| 149 | - ), |
|
| 150 | - 'where' => array( |
|
| 151 | - |
|
| 152 | - 'author' => array( |
|
| 153 | - 'type' => 'post_data', |
|
| 154 | - 'value' => absint( $user->ID ), |
|
| 155 | - 'key' => 'posts.post_author', |
|
| 156 | - 'operator' => '=', |
|
| 157 | - ), |
|
| 158 | - |
|
| 159 | - ), |
|
| 160 | - 'query_type' => 'get_var', |
|
| 161 | - 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 165 | - |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Displays the total spent column. |
|
| 170 | - * |
|
| 171 | - * @since 1.0.19 |
|
| 172 | - * |
|
| 173 | - * @param WP_User $user |
|
| 174 | - * |
|
| 175 | - * @return string Column Name |
|
| 176 | - */ |
|
| 177 | - public function column_invoices( $user ) { |
|
| 178 | - |
|
| 179 | - $args = array( |
|
| 180 | - 'data' => array( |
|
| 181 | - |
|
| 182 | - 'ID' => array( |
|
| 183 | - 'type' => 'post_data', |
|
| 184 | - 'function' => 'COUNT', |
|
| 185 | - 'name' => 'count', |
|
| 186 | - 'distinct' => true, |
|
| 187 | - ), |
|
| 188 | - |
|
| 189 | - ), |
|
| 190 | - 'where' => array( |
|
| 191 | - |
|
| 192 | - 'author' => array( |
|
| 193 | - 'type' => 'post_data', |
|
| 194 | - 'value' => absint( $user->ID ), |
|
| 195 | - 'key' => 'posts.post_author', |
|
| 196 | - 'operator' => '=', |
|
| 197 | - ), |
|
| 198 | - |
|
| 199 | - ), |
|
| 200 | - 'query_type' => 'get_var', |
|
| 201 | - 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 202 | - ); |
|
| 203 | - |
|
| 204 | - return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 205 | - |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Generates content for a single row of the table |
|
| 210 | - * @since 1.0.19 |
|
| 211 | - * |
|
| 212 | - * @param int $item The user id. |
|
| 213 | - */ |
|
| 214 | - public function single_row( $item ) { |
|
| 215 | - $item = get_user_by( 'id', $item ); |
|
| 216 | - |
|
| 217 | - if ( empty( $item ) ) { |
|
| 218 | - return; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - echo '<tr>'; |
|
| 222 | - $this->single_row_columns( $item ); |
|
| 223 | - echo '</tr>'; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Displays the customers name |
|
| 228 | - * |
|
| 229 | - * @param WP_User $customer customer. |
|
| 230 | - * @return string |
|
| 231 | - */ |
|
| 232 | - public function column_name( $customer ) { |
|
| 233 | - |
|
| 234 | - // Customer view URL. |
|
| 235 | - $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 236 | - $row_actions = $this->row_actions( |
|
| 237 | - array( |
|
| 238 | - 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - |
|
| 242 | - // Get user's address. |
|
| 243 | - $address = wpinv_get_user_address( $customer->ID ); |
|
| 244 | - |
|
| 245 | - // Customer email address. |
|
| 246 | - $email = sanitize_email( $customer->user_email ); |
|
| 247 | - |
|
| 248 | - // Customer's avatar. |
|
| 249 | - $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 250 | - $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 251 | - |
|
| 252 | - // Customer's name. |
|
| 253 | - $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
| 254 | - |
|
| 255 | - if ( ! empty( $name ) ) { |
|
| 256 | - $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 260 | - |
|
| 261 | - return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 262 | - |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Retrieve the table columns |
|
| 267 | - * |
|
| 268 | - * @since 1.0.19 |
|
| 269 | - * @return array $columns Array of all the list table columns |
|
| 270 | - */ |
|
| 271 | - public function get_columns() { |
|
| 272 | - |
|
| 273 | - $columns = array( |
|
| 274 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 275 | - 'country' => __( 'Country', 'invoicing' ), |
|
| 276 | - 'state' => __( 'State', 'invoicing' ), |
|
| 277 | - 'city' => __( 'City', 'invoicing' ), |
|
| 278 | - 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 279 | - 'address' => __( 'Address', 'invoicing' ), |
|
| 280 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
| 281 | - 'company' => __( 'Company', 'invoicing' ), |
|
| 282 | - 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 283 | - 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 284 | - 'signup' => __( 'Date created', 'invoicing' ), |
|
| 285 | - ); |
|
| 286 | - return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 287 | - |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Retrieve the current page number |
|
| 292 | - * |
|
| 293 | - * @since 1.0.19 |
|
| 294 | - * @return int Current page number |
|
| 295 | - */ |
|
| 296 | - public function get_paged() { |
|
| 297 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Returns bulk actions. |
|
| 302 | - * |
|
| 303 | - * @since 1.0.19 |
|
| 304 | - * @return void |
|
| 305 | - */ |
|
| 306 | - public function bulk_actions( $which = '' ) { |
|
| 307 | - return array(); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Prepares the display query |
|
| 312 | - */ |
|
| 313 | - public function prepare_query() { |
|
| 314 | - global $wpdb; |
|
| 315 | - |
|
| 316 | - $post_types = ''; |
|
| 317 | - |
|
| 318 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 319 | - $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $post_types = rtrim( $post_types, ' OR' ); |
|
| 323 | - |
|
| 324 | - // Maybe search. |
|
| 325 | - if ( ! empty( $_POST['s'] ) ) { |
|
| 326 | - $users = get_users( |
|
| 327 | - array( |
|
| 328 | - 'search' => sanitize_text_field( urldecode( $_POST['s'] ) ), |
|
| 329 | - 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 330 | - 'fields' => 'ID', |
|
| 331 | - ) |
|
| 332 | - ); |
|
| 333 | - |
|
| 334 | - $users = implode( ', ', $users ); |
|
| 335 | - $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - // Users with invoices. |
|
| 339 | - $customers = $wpdb->get_col( |
|
| 340 | - $wpdb->prepare( |
|
| 341 | - "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
| 342 | - $this->get_paged() * 10 - 10, |
|
| 343 | - $this->per_page |
|
| 344 | - ) |
|
| 345 | - ); |
|
| 346 | - |
|
| 347 | - $this->items = $customers; |
|
| 348 | - $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 349 | - |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Setup the final data for the table |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @return void |
|
| 357 | - */ |
|
| 358 | - public function prepare_items() { |
|
| 359 | - $columns = $this->get_columns(); |
|
| 360 | - $hidden = array(); // No hidden columns |
|
| 361 | - $sortable = $this->get_sortable_columns(); |
|
| 362 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 363 | - $this->prepare_query(); |
|
| 364 | - |
|
| 365 | - $this->set_pagination_args( |
|
| 366 | - array( |
|
| 367 | - 'total_items' => $this->total, |
|
| 368 | - 'per_page' => $this->per_page, |
|
| 369 | - 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 370 | - ) |
|
| 371 | - ); |
|
| 372 | - |
|
| 373 | - } |
|
| 24 | + /** |
|
| 25 | + * @var int Number of items per page |
|
| 26 | + * @since 1.0.19 |
|
| 27 | + */ |
|
| 28 | + public $per_page = 10; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var int Number of items |
|
| 32 | + * @since 1.0.19 |
|
| 33 | + */ |
|
| 34 | + public $total = 0; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Get things started |
|
| 38 | + * |
|
| 39 | + * @since 1.0.19 |
|
| 40 | + * @see WP_List_Table::__construct() |
|
| 41 | + */ |
|
| 42 | + public function __construct() { |
|
| 43 | + |
|
| 44 | + // Set parent defaults |
|
| 45 | + parent::__construct( array( |
|
| 46 | + 'singular' => 'id', |
|
| 47 | + 'plural' => 'ids', |
|
| 48 | + 'ajax' => false, |
|
| 49 | + ) ); |
|
| 50 | + |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Gets the name of the primary column. |
|
| 55 | + * |
|
| 56 | + * @since 1.0.19 |
|
| 57 | + * @access protected |
|
| 58 | + * |
|
| 59 | + * @return string Name of the primary column. |
|
| 60 | + */ |
|
| 61 | + protected function get_primary_column_name() { |
|
| 62 | + return 'name'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * This function renders most of the columns in the list table. |
|
| 67 | + * |
|
| 68 | + * @since 1.0.19 |
|
| 69 | + * |
|
| 70 | + * @param WP_User $item |
|
| 71 | + * @param string $column_name The name of the column |
|
| 72 | + * |
|
| 73 | + * @return string Column Name |
|
| 74 | + */ |
|
| 75 | + public function column_default( $item, $column_name ) { |
|
| 76 | + $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) ); |
|
| 77 | + return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Displays the country column. |
|
| 82 | + * |
|
| 83 | + * @since 1.0.19 |
|
| 84 | + * |
|
| 85 | + * @param WP_User $user |
|
| 86 | + * |
|
| 87 | + * @return string Column Name |
|
| 88 | + */ |
|
| 89 | + public function column_country( $user ) { |
|
| 90 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 91 | + if ( $country ) { |
|
| 92 | + $country = wpinv_country_name( $country ); |
|
| 93 | + } |
|
| 94 | + return sanitize_text_field( $country ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Displays the state column. |
|
| 99 | + * |
|
| 100 | + * @since 1.0.19 |
|
| 101 | + * |
|
| 102 | + * @param WP_User $user |
|
| 103 | + * |
|
| 104 | + * @return string Column Name |
|
| 105 | + */ |
|
| 106 | + public function column_state( $user ) { |
|
| 107 | + $country = wpinv_sanitize_country( $user->_wpinv_country ); |
|
| 108 | + $state = $user->_wpinv_state; |
|
| 109 | + if ( $state ) { |
|
| 110 | + $state = wpinv_state_name( $state, $country ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return sanitize_text_field( $state ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Displays the signup column. |
|
| 118 | + * |
|
| 119 | + * @since 1.0.19 |
|
| 120 | + * |
|
| 121 | + * @param WP_User $user |
|
| 122 | + * |
|
| 123 | + * @return string Column Name |
|
| 124 | + */ |
|
| 125 | + public function column_signup( $user ) { |
|
| 126 | + return getpaid_format_date_value( $user->user_registered ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Displays the total spent column. |
|
| 131 | + * |
|
| 132 | + * @since 1.0.19 |
|
| 133 | + * |
|
| 134 | + * @param WP_User $user |
|
| 135 | + * |
|
| 136 | + * @return string Column Name |
|
| 137 | + */ |
|
| 138 | + public function column_total( $user ) { |
|
| 139 | + |
|
| 140 | + $args = array( |
|
| 141 | + 'data' => array( |
|
| 142 | + |
|
| 143 | + 'total' => array( |
|
| 144 | + 'type' => 'invoice_data', |
|
| 145 | + 'function' => 'SUM', |
|
| 146 | + 'name' => 'total_sales', |
|
| 147 | + ) |
|
| 148 | + |
|
| 149 | + ), |
|
| 150 | + 'where' => array( |
|
| 151 | + |
|
| 152 | + 'author' => array( |
|
| 153 | + 'type' => 'post_data', |
|
| 154 | + 'value' => absint( $user->ID ), |
|
| 155 | + 'key' => 'posts.post_author', |
|
| 156 | + 'operator' => '=', |
|
| 157 | + ), |
|
| 158 | + |
|
| 159 | + ), |
|
| 160 | + 'query_type' => 'get_var', |
|
| 161 | + 'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ), |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + return wpinv_price( (float) GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 165 | + |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Displays the total spent column. |
|
| 170 | + * |
|
| 171 | + * @since 1.0.19 |
|
| 172 | + * |
|
| 173 | + * @param WP_User $user |
|
| 174 | + * |
|
| 175 | + * @return string Column Name |
|
| 176 | + */ |
|
| 177 | + public function column_invoices( $user ) { |
|
| 178 | + |
|
| 179 | + $args = array( |
|
| 180 | + 'data' => array( |
|
| 181 | + |
|
| 182 | + 'ID' => array( |
|
| 183 | + 'type' => 'post_data', |
|
| 184 | + 'function' => 'COUNT', |
|
| 185 | + 'name' => 'count', |
|
| 186 | + 'distinct' => true, |
|
| 187 | + ), |
|
| 188 | + |
|
| 189 | + ), |
|
| 190 | + 'where' => array( |
|
| 191 | + |
|
| 192 | + 'author' => array( |
|
| 193 | + 'type' => 'post_data', |
|
| 194 | + 'value' => absint( $user->ID ), |
|
| 195 | + 'key' => 'posts.post_author', |
|
| 196 | + 'operator' => '=', |
|
| 197 | + ), |
|
| 198 | + |
|
| 199 | + ), |
|
| 200 | + 'query_type' => 'get_var', |
|
| 201 | + 'invoice_status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 202 | + ); |
|
| 203 | + |
|
| 204 | + return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) ); |
|
| 205 | + |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Generates content for a single row of the table |
|
| 210 | + * @since 1.0.19 |
|
| 211 | + * |
|
| 212 | + * @param int $item The user id. |
|
| 213 | + */ |
|
| 214 | + public function single_row( $item ) { |
|
| 215 | + $item = get_user_by( 'id', $item ); |
|
| 216 | + |
|
| 217 | + if ( empty( $item ) ) { |
|
| 218 | + return; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + echo '<tr>'; |
|
| 222 | + $this->single_row_columns( $item ); |
|
| 223 | + echo '</tr>'; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Displays the customers name |
|
| 228 | + * |
|
| 229 | + * @param WP_User $customer customer. |
|
| 230 | + * @return string |
|
| 231 | + */ |
|
| 232 | + public function column_name( $customer ) { |
|
| 233 | + |
|
| 234 | + // Customer view URL. |
|
| 235 | + $view_url = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) ); |
|
| 236 | + $row_actions = $this->row_actions( |
|
| 237 | + array( |
|
| 238 | + 'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>', |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + |
|
| 242 | + // Get user's address. |
|
| 243 | + $address = wpinv_get_user_address( $customer->ID ); |
|
| 244 | + |
|
| 245 | + // Customer email address. |
|
| 246 | + $email = sanitize_email( $customer->user_email ); |
|
| 247 | + |
|
| 248 | + // Customer's avatar. |
|
| 249 | + $avatar = esc_url( get_avatar_url( $email ) ); |
|
| 250 | + $avatar = "<img src='$avatar' height='32' width='32'/>"; |
|
| 251 | + |
|
| 252 | + // Customer's name. |
|
| 253 | + $name = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" ); |
|
| 254 | + |
|
| 255 | + if ( ! empty( $name ) ) { |
|
| 256 | + $name = "<div style='overflow: hidden;height: 18px;'>$name</div>"; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $email = "<div class='row-title'><a href='$view_url'>$email</a></div>"; |
|
| 260 | + |
|
| 261 | + return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>"; |
|
| 262 | + |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Retrieve the table columns |
|
| 267 | + * |
|
| 268 | + * @since 1.0.19 |
|
| 269 | + * @return array $columns Array of all the list table columns |
|
| 270 | + */ |
|
| 271 | + public function get_columns() { |
|
| 272 | + |
|
| 273 | + $columns = array( |
|
| 274 | + 'name' => __( 'Name', 'invoicing' ), |
|
| 275 | + 'country' => __( 'Country', 'invoicing' ), |
|
| 276 | + 'state' => __( 'State', 'invoicing' ), |
|
| 277 | + 'city' => __( 'City', 'invoicing' ), |
|
| 278 | + 'zip' => __( 'ZIP', 'invoicing' ), |
|
| 279 | + 'address' => __( 'Address', 'invoicing' ), |
|
| 280 | + 'phone' => __( 'Phone', 'invoicing' ), |
|
| 281 | + 'company' => __( 'Company', 'invoicing' ), |
|
| 282 | + 'invoices' => __( 'Invoices', 'invoicing' ), |
|
| 283 | + 'total' => __( 'Total Spend', 'invoicing' ), |
|
| 284 | + 'signup' => __( 'Date created', 'invoicing' ), |
|
| 285 | + ); |
|
| 286 | + return apply_filters( 'wpinv_customers_table_columns', $columns ); |
|
| 287 | + |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Retrieve the current page number |
|
| 292 | + * |
|
| 293 | + * @since 1.0.19 |
|
| 294 | + * @return int Current page number |
|
| 295 | + */ |
|
| 296 | + public function get_paged() { |
|
| 297 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Returns bulk actions. |
|
| 302 | + * |
|
| 303 | + * @since 1.0.19 |
|
| 304 | + * @return void |
|
| 305 | + */ |
|
| 306 | + public function bulk_actions( $which = '' ) { |
|
| 307 | + return array(); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Prepares the display query |
|
| 312 | + */ |
|
| 313 | + public function prepare_query() { |
|
| 314 | + global $wpdb; |
|
| 315 | + |
|
| 316 | + $post_types = ''; |
|
| 317 | + |
|
| 318 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
| 319 | + $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $post_types = rtrim( $post_types, ' OR' ); |
|
| 323 | + |
|
| 324 | + // Maybe search. |
|
| 325 | + if ( ! empty( $_POST['s'] ) ) { |
|
| 326 | + $users = get_users( |
|
| 327 | + array( |
|
| 328 | + 'search' => sanitize_text_field( urldecode( $_POST['s'] ) ), |
|
| 329 | + 'search_columns' => array( 'user_login', 'user_email', 'display_name' ), |
|
| 330 | + 'fields' => 'ID', |
|
| 331 | + ) |
|
| 332 | + ); |
|
| 333 | + |
|
| 334 | + $users = implode( ', ', $users ); |
|
| 335 | + $post_types = "($post_types) AND ( post_author IN ( $users ) )"; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + // Users with invoices. |
|
| 339 | + $customers = $wpdb->get_col( |
|
| 340 | + $wpdb->prepare( |
|
| 341 | + "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d", |
|
| 342 | + $this->get_paged() * 10 - 10, |
|
| 343 | + $this->per_page |
|
| 344 | + ) |
|
| 345 | + ); |
|
| 346 | + |
|
| 347 | + $this->items = $customers; |
|
| 348 | + $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" ); |
|
| 349 | + |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Setup the final data for the table |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @return void |
|
| 357 | + */ |
|
| 358 | + public function prepare_items() { |
|
| 359 | + $columns = $this->get_columns(); |
|
| 360 | + $hidden = array(); // No hidden columns |
|
| 361 | + $sortable = $this->get_sortable_columns(); |
|
| 362 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 363 | + $this->prepare_query(); |
|
| 364 | + |
|
| 365 | + $this->set_pagination_args( |
|
| 366 | + array( |
|
| 367 | + 'total_items' => $this->total, |
|
| 368 | + 'per_page' => $this->per_page, |
|
| 369 | + 'total_pages' => ceil( $this->total / $this->per_page ) |
|
| 370 | + ) |
|
| 371 | + ); |
|
| 372 | + |
|
| 373 | + } |
|
| 374 | 374 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,187 +10,187 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Sets the associated payment form. |
|
| 57 | - * |
|
| 58 | - * @var GetPaid_Payment_Form |
|
| 59 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Sets the associated payment form. |
|
| 57 | + * |
|
| 58 | + * @var GetPaid_Payment_Form |
|
| 59 | + */ |
|
| 60 | 60 | protected $payment_form = null; |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | - * The country for the submission. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - public $country = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The state for the submission. |
|
| 71 | - * |
|
| 72 | - * @since 1.0.19 |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - public $state = null; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * The invoice associated with the submission. |
|
| 79 | - * |
|
| 80 | - * @var WPInv_Invoice |
|
| 81 | - */ |
|
| 82 | - protected $invoice = null; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * The recurring item for the submission. |
|
| 86 | - * |
|
| 87 | - * @var int |
|
| 88 | - */ |
|
| 89 | - public $has_recurring = 0; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * An array of fees for the submission. |
|
| 93 | - * |
|
| 94 | - * @var array |
|
| 95 | - */ |
|
| 96 | - protected $fees = array(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * An array of discounts for the submission. |
|
| 100 | - * |
|
| 101 | - * @var array |
|
| 102 | - */ |
|
| 103 | - protected $discounts = array(); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * An array of taxes for the submission. |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $taxes = array(); |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * An array of items for the submission. |
|
| 114 | - * |
|
| 115 | - * @var GetPaid_Form_Item[] |
|
| 116 | - */ |
|
| 117 | - protected $items = array(); |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * The last error. |
|
| 121 | - * |
|
| 122 | - * @var string |
|
| 123 | - */ |
|
| 124 | - public $last_error = null; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Class constructor. |
|
| 128 | - * |
|
| 129 | - */ |
|
| 130 | - public function __construct() { |
|
| 131 | - |
|
| 132 | - // Set the state and country to the default state and country. |
|
| 133 | - $this->country = wpinv_default_billing_country(); |
|
| 134 | - $this->state = wpinv_get_default_state(); |
|
| 135 | - |
|
| 136 | - // Do we have an actual submission? |
|
| 137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | - $this->load_data( $_POST ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Loads submission data. |
|
| 145 | - * |
|
| 146 | - * @param array $data |
|
| 147 | - */ |
|
| 148 | - public function load_data( $data ) { |
|
| 149 | - |
|
| 150 | - // Remove slashes from the submitted data... |
|
| 151 | - $data = wp_unslash( $data ); |
|
| 152 | - |
|
| 153 | - // Allow plugins to filter the data. |
|
| 154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 155 | - |
|
| 156 | - // Cache it... |
|
| 157 | - $this->data = $data; |
|
| 158 | - |
|
| 159 | - // Then generate a unique id from the data. |
|
| 160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 161 | - |
|
| 162 | - // Finally, process the submission. |
|
| 163 | - try { |
|
| 164 | - |
|
| 165 | - // Each process is passed an instance of the class (with reference) |
|
| 166 | - // and should throw an Exception whenever it encounters one. |
|
| 167 | - $processors = apply_filters( |
|
| 168 | - 'getpaid_payment_form_submission_processors', |
|
| 169 | - array( |
|
| 170 | - array( $this, 'process_payment_form' ), |
|
| 171 | - array( $this, 'process_invoice' ), |
|
| 172 | - array( $this, 'process_fees' ), |
|
| 173 | - array( $this, 'process_items' ), |
|
| 174 | - array( $this, 'process_discount' ), |
|
| 175 | - array( $this, 'process_taxes' ), |
|
| 176 | - ), |
|
| 177 | - $this |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - foreach ( $processors as $processor ) { |
|
| 181 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - } catch ( Exception $e ) { |
|
| 185 | - $this->last_error = $e->getMessage(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Fired when we are done processing a submission. |
|
| 189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 190 | - |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /* |
|
| 63 | + * The country for the submission. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + public $country = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The state for the submission. |
|
| 71 | + * |
|
| 72 | + * @since 1.0.19 |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + public $state = null; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * The invoice associated with the submission. |
|
| 79 | + * |
|
| 80 | + * @var WPInv_Invoice |
|
| 81 | + */ |
|
| 82 | + protected $invoice = null; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * The recurring item for the submission. |
|
| 86 | + * |
|
| 87 | + * @var int |
|
| 88 | + */ |
|
| 89 | + public $has_recurring = 0; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * An array of fees for the submission. |
|
| 93 | + * |
|
| 94 | + * @var array |
|
| 95 | + */ |
|
| 96 | + protected $fees = array(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * An array of discounts for the submission. |
|
| 100 | + * |
|
| 101 | + * @var array |
|
| 102 | + */ |
|
| 103 | + protected $discounts = array(); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * An array of taxes for the submission. |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $taxes = array(); |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * An array of items for the submission. |
|
| 114 | + * |
|
| 115 | + * @var GetPaid_Form_Item[] |
|
| 116 | + */ |
|
| 117 | + protected $items = array(); |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * The last error. |
|
| 121 | + * |
|
| 122 | + * @var string |
|
| 123 | + */ |
|
| 124 | + public $last_error = null; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Class constructor. |
|
| 128 | + * |
|
| 129 | + */ |
|
| 130 | + public function __construct() { |
|
| 131 | + |
|
| 132 | + // Set the state and country to the default state and country. |
|
| 133 | + $this->country = wpinv_default_billing_country(); |
|
| 134 | + $this->state = wpinv_get_default_state(); |
|
| 135 | + |
|
| 136 | + // Do we have an actual submission? |
|
| 137 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | + $this->load_data( $_POST ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Loads submission data. |
|
| 145 | + * |
|
| 146 | + * @param array $data |
|
| 147 | + */ |
|
| 148 | + public function load_data( $data ) { |
|
| 149 | + |
|
| 150 | + // Remove slashes from the submitted data... |
|
| 151 | + $data = wp_unslash( $data ); |
|
| 152 | + |
|
| 153 | + // Allow plugins to filter the data. |
|
| 154 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 155 | + |
|
| 156 | + // Cache it... |
|
| 157 | + $this->data = $data; |
|
| 158 | + |
|
| 159 | + // Then generate a unique id from the data. |
|
| 160 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 161 | + |
|
| 162 | + // Finally, process the submission. |
|
| 163 | + try { |
|
| 164 | + |
|
| 165 | + // Each process is passed an instance of the class (with reference) |
|
| 166 | + // and should throw an Exception whenever it encounters one. |
|
| 167 | + $processors = apply_filters( |
|
| 168 | + 'getpaid_payment_form_submission_processors', |
|
| 169 | + array( |
|
| 170 | + array( $this, 'process_payment_form' ), |
|
| 171 | + array( $this, 'process_invoice' ), |
|
| 172 | + array( $this, 'process_fees' ), |
|
| 173 | + array( $this, 'process_items' ), |
|
| 174 | + array( $this, 'process_discount' ), |
|
| 175 | + array( $this, 'process_taxes' ), |
|
| 176 | + ), |
|
| 177 | + $this |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + foreach ( $processors as $processor ) { |
|
| 181 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + } catch ( Exception $e ) { |
|
| 185 | + $this->last_error = $e->getMessage(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Fired when we are done processing a submission. |
|
| 189 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 190 | + |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /* |
|
| 194 | 194 | |-------------------------------------------------------------------------- |
| 195 | 195 | | Payment Forms. |
| 196 | 196 | |-------------------------------------------------------------------------- |
@@ -199,39 +199,39 @@ discard block |
||
| 199 | 199 | | submission has an active payment form etc. |
| 200 | 200 | */ |
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Prepares the submission's payment form. |
|
| 204 | - * |
|
| 205 | - * @since 1.0.19 |
|
| 206 | - */ |
|
| 207 | - public function process_payment_form() { |
|
| 202 | + /** |
|
| 203 | + * Prepares the submission's payment form. |
|
| 204 | + * |
|
| 205 | + * @since 1.0.19 |
|
| 206 | + */ |
|
| 207 | + public function process_payment_form() { |
|
| 208 | 208 | |
| 209 | - // Every submission needs an active payment form. |
|
| 210 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 212 | - } |
|
| 209 | + // Every submission needs an active payment form. |
|
| 210 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - // Fetch the payment form. |
|
| 215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 214 | + // Fetch the payment form. |
|
| 215 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 216 | 216 | |
| 217 | - if ( ! $this->payment_form->is_active() ) { |
|
| 218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 219 | - } |
|
| 217 | + if ( ! $this->payment_form->is_active() ) { |
|
| 218 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 222 | - } |
|
| 221 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | - * Returns the payment form. |
|
| 226 | - * |
|
| 227 | - * @since 1.0.19 |
|
| 228 | - * @return GetPaid_Payment_Form |
|
| 229 | - */ |
|
| 230 | - public function get_payment_form() { |
|
| 231 | - return $this->payment_form; |
|
| 232 | - } |
|
| 225 | + * Returns the payment form. |
|
| 226 | + * |
|
| 227 | + * @since 1.0.19 |
|
| 228 | + * @return GetPaid_Payment_Form |
|
| 229 | + */ |
|
| 230 | + public function get_payment_form() { |
|
| 231 | + return $this->payment_form; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /* |
|
| 234 | + /* |
|
| 235 | 235 | |-------------------------------------------------------------------------- |
| 236 | 236 | | Invoices. |
| 237 | 237 | |-------------------------------------------------------------------------- |
@@ -240,61 +240,61 @@ discard block |
||
| 240 | 240 | | might be for an existing invoice. |
| 241 | 241 | */ |
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Prepares the submission's invoice. |
|
| 245 | - * |
|
| 246 | - * @since 1.0.19 |
|
| 247 | - */ |
|
| 248 | - public function process_invoice() { |
|
| 243 | + /** |
|
| 244 | + * Prepares the submission's invoice. |
|
| 245 | + * |
|
| 246 | + * @since 1.0.19 |
|
| 247 | + */ |
|
| 248 | + public function process_invoice() { |
|
| 249 | 249 | |
| 250 | - // Abort if there is no invoice. |
|
| 251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 252 | - return; |
|
| 253 | - } |
|
| 250 | + // Abort if there is no invoice. |
|
| 251 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 256 | - // and that it is not paid for. |
|
| 257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 255 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 256 | + // and that it is not paid for. |
|
| 257 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 258 | 258 | |
| 259 | 259 | if ( empty( $invoice ) ) { |
| 260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if ( $invoice->is_paid() ) { |
|
| 264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 268 | - $this->payment_form->invoice = $invoice; |
|
| 269 | - |
|
| 270 | - $this->country = $invoice->get_country(); |
|
| 271 | - $this->state = $invoice->get_state(); |
|
| 272 | - $this->invoice = $invoice; |
|
| 273 | - |
|
| 274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Returns the associated invoice. |
|
| 279 | - * |
|
| 280 | - * @since 1.0.19 |
|
| 281 | - * @return WPInv_Invoice |
|
| 282 | - */ |
|
| 283 | - public function get_invoice() { |
|
| 284 | - return $this->invoice; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Checks whether there is an invoice associated with this submission. |
|
| 289 | - * |
|
| 290 | - * @since 1.0.19 |
|
| 291 | - * @return bool |
|
| 292 | - */ |
|
| 293 | - public function has_invoice() { |
|
| 294 | - return ! empty( $this->invoice ); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /* |
|
| 260 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if ( $invoice->is_paid() ) { |
|
| 264 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 268 | + $this->payment_form->invoice = $invoice; |
|
| 269 | + |
|
| 270 | + $this->country = $invoice->get_country(); |
|
| 271 | + $this->state = $invoice->get_state(); |
|
| 272 | + $this->invoice = $invoice; |
|
| 273 | + |
|
| 274 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Returns the associated invoice. |
|
| 279 | + * |
|
| 280 | + * @since 1.0.19 |
|
| 281 | + * @return WPInv_Invoice |
|
| 282 | + */ |
|
| 283 | + public function get_invoice() { |
|
| 284 | + return $this->invoice; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Checks whether there is an invoice associated with this submission. |
|
| 289 | + * |
|
| 290 | + * @since 1.0.19 |
|
| 291 | + * @return bool |
|
| 292 | + */ |
|
| 293 | + public function has_invoice() { |
|
| 294 | + return ! empty( $this->invoice ); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /* |
|
| 298 | 298 | |-------------------------------------------------------------------------- |
| 299 | 299 | | Items. |
| 300 | 300 | |-------------------------------------------------------------------------- |
@@ -303,115 +303,115 @@ discard block |
||
| 303 | 303 | | recurring item. But can have an unlimited number of non-recurring items. |
| 304 | 304 | */ |
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Prepares the submission's items. |
|
| 308 | - * |
|
| 309 | - * @since 1.0.19 |
|
| 310 | - */ |
|
| 311 | - public function process_items() { |
|
| 312 | - |
|
| 313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 314 | - |
|
| 315 | - foreach ( $processor->items as $item ) { |
|
| 316 | - $this->add_item( $item ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Adds an item to the submission. |
|
| 324 | - * |
|
| 325 | - * @since 1.0.19 |
|
| 326 | - * @param GetPaid_Form_Item $item |
|
| 327 | - */ |
|
| 328 | - public function add_item( $item ) { |
|
| 329 | - |
|
| 330 | - // Make sure that it is available for purchase. |
|
| 331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 332 | - return; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // Each submission can only contain one recurring item. |
|
| 336 | - if ( $item->is_recurring() ) { |
|
| 337 | - |
|
| 338 | - if ( $this->has_recurring != 0 ) { |
|
| 339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - $this->has_recurring = $item->get_id(); |
|
| 343 | - |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Update the items and totals. |
|
| 347 | - $this->items[ $item->get_id() ] = $item; |
|
| 348 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 349 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 350 | - |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Removes a specific item. |
|
| 355 | - * |
|
| 356 | - * You should not call this method after the discounts and taxes |
|
| 357 | - * have been calculated. |
|
| 358 | - * |
|
| 359 | - * @since 1.0.19 |
|
| 360 | - */ |
|
| 361 | - public function remove_item( $item_id ) { |
|
| 362 | - |
|
| 363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 366 | - |
|
| 367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 368 | - $this->has_recurring = 0; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - unset( $this->items[ $item_id ] ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Returns the subtotal. |
|
| 378 | - * |
|
| 379 | - * @since 1.0.19 |
|
| 380 | - */ |
|
| 381 | - public function get_subtotal() { |
|
| 382 | - |
|
| 383 | - if ( wpinv_prices_include_tax() ) { |
|
| 384 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - return $this->totals['subtotal']['initial']; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Returns the recurring subtotal. |
|
| 392 | - * |
|
| 393 | - * @since 1.0.19 |
|
| 394 | - */ |
|
| 395 | - public function get_recurring_subtotal() { |
|
| 396 | - |
|
| 397 | - if ( wpinv_prices_include_tax() ) { |
|
| 398 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - return $this->totals['subtotal']['recurring']; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Returns all items. |
|
| 406 | - * |
|
| 407 | - * @since 1.0.19 |
|
| 408 | - * @return GetPaid_Form_Item[] |
|
| 409 | - */ |
|
| 410 | - public function get_items() { |
|
| 411 | - return $this->items; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /* |
|
| 306 | + /** |
|
| 307 | + * Prepares the submission's items. |
|
| 308 | + * |
|
| 309 | + * @since 1.0.19 |
|
| 310 | + */ |
|
| 311 | + public function process_items() { |
|
| 312 | + |
|
| 313 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 314 | + |
|
| 315 | + foreach ( $processor->items as $item ) { |
|
| 316 | + $this->add_item( $item ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Adds an item to the submission. |
|
| 324 | + * |
|
| 325 | + * @since 1.0.19 |
|
| 326 | + * @param GetPaid_Form_Item $item |
|
| 327 | + */ |
|
| 328 | + public function add_item( $item ) { |
|
| 329 | + |
|
| 330 | + // Make sure that it is available for purchase. |
|
| 331 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // Each submission can only contain one recurring item. |
|
| 336 | + if ( $item->is_recurring() ) { |
|
| 337 | + |
|
| 338 | + if ( $this->has_recurring != 0 ) { |
|
| 339 | + throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + $this->has_recurring = $item->get_id(); |
|
| 343 | + |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Update the items and totals. |
|
| 347 | + $this->items[ $item->get_id() ] = $item; |
|
| 348 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 349 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 350 | + |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Removes a specific item. |
|
| 355 | + * |
|
| 356 | + * You should not call this method after the discounts and taxes |
|
| 357 | + * have been calculated. |
|
| 358 | + * |
|
| 359 | + * @since 1.0.19 |
|
| 360 | + */ |
|
| 361 | + public function remove_item( $item_id ) { |
|
| 362 | + |
|
| 363 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 366 | + |
|
| 367 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 368 | + $this->has_recurring = 0; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + unset( $this->items[ $item_id ] ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Returns the subtotal. |
|
| 378 | + * |
|
| 379 | + * @since 1.0.19 |
|
| 380 | + */ |
|
| 381 | + public function get_subtotal() { |
|
| 382 | + |
|
| 383 | + if ( wpinv_prices_include_tax() ) { |
|
| 384 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + return $this->totals['subtotal']['initial']; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Returns the recurring subtotal. |
|
| 392 | + * |
|
| 393 | + * @since 1.0.19 |
|
| 394 | + */ |
|
| 395 | + public function get_recurring_subtotal() { |
|
| 396 | + |
|
| 397 | + if ( wpinv_prices_include_tax() ) { |
|
| 398 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + return $this->totals['subtotal']['recurring']; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Returns all items. |
|
| 406 | + * |
|
| 407 | + * @since 1.0.19 |
|
| 408 | + * @return GetPaid_Form_Item[] |
|
| 409 | + */ |
|
| 410 | + public function get_items() { |
|
| 411 | + return $this->items; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /* |
|
| 415 | 415 | |-------------------------------------------------------------------------- |
| 416 | 416 | | Taxes |
| 417 | 417 | |-------------------------------------------------------------------------- |
@@ -420,128 +420,128 @@ discard block |
||
| 420 | 420 | | or only one-time. |
| 421 | 421 | */ |
| 422 | 422 | |
| 423 | - /** |
|
| 424 | - * Prepares the submission's taxes. |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - */ |
|
| 428 | - public function process_taxes() { |
|
| 429 | - |
|
| 430 | - // Abort if we're not using taxes. |
|
| 431 | - if ( ! $this->use_taxes() ) { |
|
| 432 | - return; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 437 | - if ( ! empty( $country ) ) { |
|
| 438 | - $this->country = $country; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 442 | - if ( ! empty( $state ) ) { |
|
| 443 | - $this->state = $state; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - // Confirm if the provided country and the ip country are similar. |
|
| 447 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 448 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 449 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - // Abort if the country is not taxable. |
|
| 453 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 454 | - return; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 458 | - |
|
| 459 | - foreach ( $processor->taxes as $tax ) { |
|
| 460 | - $this->add_tax( $tax ); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * Adds a tax to the submission. |
|
| 468 | - * |
|
| 469 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 470 | - * @since 1.0.19 |
|
| 471 | - */ |
|
| 472 | - public function add_tax( $tax ) { |
|
| 473 | - |
|
| 474 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 475 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 476 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 480 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 481 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 482 | - |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Removes a specific tax. |
|
| 487 | - * |
|
| 488 | - * @since 1.0.19 |
|
| 489 | - */ |
|
| 490 | - public function remove_tax( $tax_name ) { |
|
| 491 | - |
|
| 492 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 493 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 494 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 495 | - unset( $this->taxes[ $tax_name ] ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * Whether or not we'll use taxes for the submission. |
|
| 502 | - * |
|
| 503 | - * @since 1.0.19 |
|
| 504 | - */ |
|
| 505 | - public function use_taxes() { |
|
| 506 | - |
|
| 507 | - $use_taxes = wpinv_use_taxes(); |
|
| 508 | - |
|
| 509 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 510 | - $use_taxes = false; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 514 | - |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Returns the tax. |
|
| 519 | - * |
|
| 520 | - * @since 1.0.19 |
|
| 521 | - */ |
|
| 522 | - public function get_tax() { |
|
| 523 | - return $this->totals['taxes']['initial']; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Returns the recurring tax. |
|
| 528 | - * |
|
| 529 | - * @since 1.0.19 |
|
| 530 | - */ |
|
| 531 | - public function get_recurring_tax() { |
|
| 532 | - return $this->totals['taxes']['recurring']; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * Returns all taxes. |
|
| 537 | - * |
|
| 538 | - * @since 1.0.19 |
|
| 539 | - */ |
|
| 540 | - public function get_taxes() { |
|
| 541 | - return $this->taxes; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /* |
|
| 423 | + /** |
|
| 424 | + * Prepares the submission's taxes. |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + */ |
|
| 428 | + public function process_taxes() { |
|
| 429 | + |
|
| 430 | + // Abort if we're not using taxes. |
|
| 431 | + if ( ! $this->use_taxes() ) { |
|
| 432 | + return; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 436 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
| 437 | + if ( ! empty( $country ) ) { |
|
| 438 | + $this->country = $country; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
| 442 | + if ( ! empty( $state ) ) { |
|
| 443 | + $this->state = $state; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + // Confirm if the provided country and the ip country are similar. |
|
| 447 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
| 448 | + if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
| 449 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + // Abort if the country is not taxable. |
|
| 453 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
| 454 | + return; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 458 | + |
|
| 459 | + foreach ( $processor->taxes as $tax ) { |
|
| 460 | + $this->add_tax( $tax ); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * Adds a tax to the submission. |
|
| 468 | + * |
|
| 469 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 470 | + * @since 1.0.19 |
|
| 471 | + */ |
|
| 472 | + public function add_tax( $tax ) { |
|
| 473 | + |
|
| 474 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
| 475 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
| 476 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 480 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 481 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 482 | + |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Removes a specific tax. |
|
| 487 | + * |
|
| 488 | + * @since 1.0.19 |
|
| 489 | + */ |
|
| 490 | + public function remove_tax( $tax_name ) { |
|
| 491 | + |
|
| 492 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 493 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 494 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 495 | + unset( $this->taxes[ $tax_name ] ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * Whether or not we'll use taxes for the submission. |
|
| 502 | + * |
|
| 503 | + * @since 1.0.19 |
|
| 504 | + */ |
|
| 505 | + public function use_taxes() { |
|
| 506 | + |
|
| 507 | + $use_taxes = wpinv_use_taxes(); |
|
| 508 | + |
|
| 509 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 510 | + $use_taxes = false; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 514 | + |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Returns the tax. |
|
| 519 | + * |
|
| 520 | + * @since 1.0.19 |
|
| 521 | + */ |
|
| 522 | + public function get_tax() { |
|
| 523 | + return $this->totals['taxes']['initial']; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Returns the recurring tax. |
|
| 528 | + * |
|
| 529 | + * @since 1.0.19 |
|
| 530 | + */ |
|
| 531 | + public function get_recurring_tax() { |
|
| 532 | + return $this->totals['taxes']['recurring']; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * Returns all taxes. |
|
| 537 | + * |
|
| 538 | + * @since 1.0.19 |
|
| 539 | + */ |
|
| 540 | + public function get_taxes() { |
|
| 541 | + return $this->taxes; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /* |
|
| 545 | 545 | |-------------------------------------------------------------------------- |
| 546 | 546 | | Discounts |
| 547 | 547 | |-------------------------------------------------------------------------- |
@@ -550,99 +550,99 @@ discard block |
||
| 550 | 550 | | or only one-time. They also do not have to come from a discount code. |
| 551 | 551 | */ |
| 552 | 552 | |
| 553 | - /** |
|
| 554 | - * Prepares the submission's discount. |
|
| 555 | - * |
|
| 556 | - * @since 1.0.19 |
|
| 557 | - */ |
|
| 558 | - public function process_discount() { |
|
| 559 | - |
|
| 560 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 561 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 562 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 563 | - |
|
| 564 | - foreach ( $processor->discounts as $discount ) { |
|
| 565 | - $this->add_discount( $discount ); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Adds a discount to the submission. |
|
| 573 | - * |
|
| 574 | - * @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. |
|
| 575 | - * @since 1.0.19 |
|
| 576 | - */ |
|
| 577 | - public function add_discount( $discount ) { |
|
| 578 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 579 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 580 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Removes a discount from the submission. |
|
| 585 | - * |
|
| 586 | - * @since 1.0.19 |
|
| 587 | - */ |
|
| 588 | - public function remove_discount( $name ) { |
|
| 589 | - |
|
| 590 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 591 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 592 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 593 | - unset( $this->discounts[ $name ] ); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * Checks whether there is a discount code associated with this submission. |
|
| 600 | - * |
|
| 601 | - * @since 1.0.19 |
|
| 602 | - * @return bool |
|
| 603 | - */ |
|
| 604 | - public function has_discount_code() { |
|
| 605 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Returns the discount code. |
|
| 610 | - * |
|
| 611 | - * @since 1.0.19 |
|
| 612 | - * @return string |
|
| 613 | - */ |
|
| 614 | - public function get_discount_code() { |
|
| 615 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * Returns the discount. |
|
| 620 | - * |
|
| 621 | - * @since 1.0.19 |
|
| 622 | - */ |
|
| 623 | - public function get_discount() { |
|
| 624 | - return $this->totals['discount']['initial']; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Returns the recurring discount. |
|
| 629 | - * |
|
| 630 | - * @since 1.0.19 |
|
| 631 | - */ |
|
| 632 | - public function get_recurring_discount() { |
|
| 633 | - return $this->totals['discount']['recurring']; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * Returns all discounts. |
|
| 638 | - * |
|
| 639 | - * @since 1.0.19 |
|
| 640 | - */ |
|
| 641 | - public function get_discounts() { |
|
| 642 | - return $this->discounts; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /* |
|
| 553 | + /** |
|
| 554 | + * Prepares the submission's discount. |
|
| 555 | + * |
|
| 556 | + * @since 1.0.19 |
|
| 557 | + */ |
|
| 558 | + public function process_discount() { |
|
| 559 | + |
|
| 560 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 561 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 562 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 563 | + |
|
| 564 | + foreach ( $processor->discounts as $discount ) { |
|
| 565 | + $this->add_discount( $discount ); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Adds a discount to the submission. |
|
| 573 | + * |
|
| 574 | + * @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. |
|
| 575 | + * @since 1.0.19 |
|
| 576 | + */ |
|
| 577 | + public function add_discount( $discount ) { |
|
| 578 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 579 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 580 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Removes a discount from the submission. |
|
| 585 | + * |
|
| 586 | + * @since 1.0.19 |
|
| 587 | + */ |
|
| 588 | + public function remove_discount( $name ) { |
|
| 589 | + |
|
| 590 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 591 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 592 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 593 | + unset( $this->discounts[ $name ] ); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * Checks whether there is a discount code associated with this submission. |
|
| 600 | + * |
|
| 601 | + * @since 1.0.19 |
|
| 602 | + * @return bool |
|
| 603 | + */ |
|
| 604 | + public function has_discount_code() { |
|
| 605 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Returns the discount code. |
|
| 610 | + * |
|
| 611 | + * @since 1.0.19 |
|
| 612 | + * @return string |
|
| 613 | + */ |
|
| 614 | + public function get_discount_code() { |
|
| 615 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * Returns the discount. |
|
| 620 | + * |
|
| 621 | + * @since 1.0.19 |
|
| 622 | + */ |
|
| 623 | + public function get_discount() { |
|
| 624 | + return $this->totals['discount']['initial']; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Returns the recurring discount. |
|
| 629 | + * |
|
| 630 | + * @since 1.0.19 |
|
| 631 | + */ |
|
| 632 | + public function get_recurring_discount() { |
|
| 633 | + return $this->totals['discount']['recurring']; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * Returns all discounts. |
|
| 638 | + * |
|
| 639 | + * @since 1.0.19 |
|
| 640 | + */ |
|
| 641 | + public function get_discounts() { |
|
| 642 | + return $this->discounts; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /* |
|
| 646 | 646 | |-------------------------------------------------------------------------- |
| 647 | 647 | | Fees |
| 648 | 648 | |-------------------------------------------------------------------------- |
@@ -652,89 +652,89 @@ discard block |
||
| 652 | 652 | | fees. |
| 653 | 653 | */ |
| 654 | 654 | |
| 655 | - /** |
|
| 656 | - * Prepares the submission's fees. |
|
| 657 | - * |
|
| 658 | - * @since 1.0.19 |
|
| 659 | - */ |
|
| 660 | - public function process_fees() { |
|
| 661 | - |
|
| 662 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 663 | - |
|
| 664 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 665 | - $this->add_fee( $fee ); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Adds a fee to the submission. |
|
| 673 | - * |
|
| 674 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 675 | - * @since 1.0.19 |
|
| 676 | - */ |
|
| 677 | - public function add_fee( $fee ) { |
|
| 678 | - |
|
| 679 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 680 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 681 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 682 | - |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Removes a fee from the submission. |
|
| 687 | - * |
|
| 688 | - * @since 1.0.19 |
|
| 689 | - */ |
|
| 690 | - public function remove_fee( $name ) { |
|
| 691 | - |
|
| 692 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 693 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 694 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 695 | - unset( $this->fees[ $name ] ); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * Returns the fees. |
|
| 702 | - * |
|
| 703 | - * @since 1.0.19 |
|
| 704 | - */ |
|
| 705 | - public function get_fee() { |
|
| 706 | - return $this->totals['fees']['initial']; |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - /** |
|
| 710 | - * Returns the recurring fees. |
|
| 711 | - * |
|
| 712 | - * @since 1.0.19 |
|
| 713 | - */ |
|
| 714 | - public function get_recurring_fee() { |
|
| 715 | - return $this->totals['fees']['recurring']; |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * Returns all fees. |
|
| 720 | - * |
|
| 721 | - * @since 1.0.19 |
|
| 722 | - */ |
|
| 723 | - public function get_fees() { |
|
| 724 | - return $this->fees; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * Checks if there are any fees for the form. |
|
| 729 | - * |
|
| 730 | - * @return bool |
|
| 731 | - * @since 1.0.19 |
|
| 732 | - */ |
|
| 733 | - public function has_fees() { |
|
| 734 | - return count( $this->fees ) !== 0; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - /* |
|
| 655 | + /** |
|
| 656 | + * Prepares the submission's fees. |
|
| 657 | + * |
|
| 658 | + * @since 1.0.19 |
|
| 659 | + */ |
|
| 660 | + public function process_fees() { |
|
| 661 | + |
|
| 662 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 663 | + |
|
| 664 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 665 | + $this->add_fee( $fee ); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Adds a fee to the submission. |
|
| 673 | + * |
|
| 674 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 675 | + * @since 1.0.19 |
|
| 676 | + */ |
|
| 677 | + public function add_fee( $fee ) { |
|
| 678 | + |
|
| 679 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 680 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 681 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 682 | + |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Removes a fee from the submission. |
|
| 687 | + * |
|
| 688 | + * @since 1.0.19 |
|
| 689 | + */ |
|
| 690 | + public function remove_fee( $name ) { |
|
| 691 | + |
|
| 692 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 693 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 694 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 695 | + unset( $this->fees[ $name ] ); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * Returns the fees. |
|
| 702 | + * |
|
| 703 | + * @since 1.0.19 |
|
| 704 | + */ |
|
| 705 | + public function get_fee() { |
|
| 706 | + return $this->totals['fees']['initial']; |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /** |
|
| 710 | + * Returns the recurring fees. |
|
| 711 | + * |
|
| 712 | + * @since 1.0.19 |
|
| 713 | + */ |
|
| 714 | + public function get_recurring_fee() { |
|
| 715 | + return $this->totals['fees']['recurring']; |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * Returns all fees. |
|
| 720 | + * |
|
| 721 | + * @since 1.0.19 |
|
| 722 | + */ |
|
| 723 | + public function get_fees() { |
|
| 724 | + return $this->fees; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * Checks if there are any fees for the form. |
|
| 729 | + * |
|
| 730 | + * @return bool |
|
| 731 | + * @since 1.0.19 |
|
| 732 | + */ |
|
| 733 | + public function has_fees() { |
|
| 734 | + return count( $this->fees ) !== 0; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + /* |
|
| 738 | 738 | |-------------------------------------------------------------------------- |
| 739 | 739 | | MISC |
| 740 | 740 | |-------------------------------------------------------------------------- |
@@ -742,119 +742,119 @@ discard block |
||
| 742 | 742 | | Extra submission functions. |
| 743 | 743 | */ |
| 744 | 744 | |
| 745 | - /** |
|
| 746 | - * Checks if this is the initial fetch. |
|
| 747 | - * |
|
| 748 | - * @return bool |
|
| 749 | - * @since 1.0.19 |
|
| 750 | - */ |
|
| 751 | - public function is_initial_fetch() { |
|
| 752 | - return empty( $this->data['initial_state'] ); |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * Returns the total amount to collect for this submission. |
|
| 757 | - * |
|
| 758 | - * @since 1.0.19 |
|
| 759 | - */ |
|
| 760 | - public function get_total() { |
|
| 761 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 762 | - return max( $total, 0 ); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Returns the recurring total amount to collect for this submission. |
|
| 767 | - * |
|
| 768 | - * @since 1.0.19 |
|
| 769 | - */ |
|
| 770 | - public function get_recurring_total() { |
|
| 771 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 772 | - return max( $total, 0 ); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /** |
|
| 776 | - * Whether payment details should be collected for this submission. |
|
| 777 | - * |
|
| 778 | - * @since 1.0.19 |
|
| 779 | - */ |
|
| 780 | - public function should_collect_payment_details() { |
|
| 781 | - $initial = $this->get_total(); |
|
| 782 | - $recurring = $this->get_recurring_total(); |
|
| 783 | - |
|
| 784 | - if ( $this->has_recurring == 0 ) { |
|
| 785 | - $recurring = 0; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - $collect = $initial > 0 || $recurring > 0; |
|
| 789 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * Returns the billing email of the user. |
|
| 794 | - * |
|
| 795 | - * @since 1.0.19 |
|
| 796 | - */ |
|
| 797 | - public function get_billing_email() { |
|
| 798 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * Checks if the submitter has a billing email. |
|
| 803 | - * |
|
| 804 | - * @since 1.0.19 |
|
| 805 | - */ |
|
| 806 | - public function has_billing_email() { |
|
| 807 | - $billing_email = $this->get_billing_email(); |
|
| 808 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * Returns the appropriate currency for the submission. |
|
| 813 | - * |
|
| 814 | - * @since 1.0.19 |
|
| 815 | - * @return string |
|
| 816 | - */ |
|
| 817 | - public function get_currency() { |
|
| 818 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * Returns the raw submission data. |
|
| 823 | - * |
|
| 824 | - * @since 1.0.19 |
|
| 825 | - * @return array |
|
| 826 | - */ |
|
| 827 | - public function get_data() { |
|
| 828 | - return $this->data; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - /** |
|
| 832 | - * Returns a field from the submission data |
|
| 833 | - * |
|
| 834 | - * @param string $field |
|
| 835 | - * @since 1.0.19 |
|
| 836 | - * @return mixed|null |
|
| 837 | - */ |
|
| 838 | - public function get_field( $field, $sub_array_key = null ) { |
|
| 839 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - /** |
|
| 843 | - * Checks if a required field is set. |
|
| 844 | - * |
|
| 845 | - * @since 1.0.19 |
|
| 846 | - */ |
|
| 847 | - public function is_required_field_set( $field ) { |
|
| 848 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * Formats an amount |
|
| 853 | - * |
|
| 854 | - * @since 1.0.19 |
|
| 855 | - */ |
|
| 856 | - public function format_amount( $amount ) { |
|
| 857 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 858 | - } |
|
| 745 | + /** |
|
| 746 | + * Checks if this is the initial fetch. |
|
| 747 | + * |
|
| 748 | + * @return bool |
|
| 749 | + * @since 1.0.19 |
|
| 750 | + */ |
|
| 751 | + public function is_initial_fetch() { |
|
| 752 | + return empty( $this->data['initial_state'] ); |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * Returns the total amount to collect for this submission. |
|
| 757 | + * |
|
| 758 | + * @since 1.0.19 |
|
| 759 | + */ |
|
| 760 | + public function get_total() { |
|
| 761 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 762 | + return max( $total, 0 ); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Returns the recurring total amount to collect for this submission. |
|
| 767 | + * |
|
| 768 | + * @since 1.0.19 |
|
| 769 | + */ |
|
| 770 | + public function get_recurring_total() { |
|
| 771 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 772 | + return max( $total, 0 ); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /** |
|
| 776 | + * Whether payment details should be collected for this submission. |
|
| 777 | + * |
|
| 778 | + * @since 1.0.19 |
|
| 779 | + */ |
|
| 780 | + public function should_collect_payment_details() { |
|
| 781 | + $initial = $this->get_total(); |
|
| 782 | + $recurring = $this->get_recurring_total(); |
|
| 783 | + |
|
| 784 | + if ( $this->has_recurring == 0 ) { |
|
| 785 | + $recurring = 0; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + $collect = $initial > 0 || $recurring > 0; |
|
| 789 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * Returns the billing email of the user. |
|
| 794 | + * |
|
| 795 | + * @since 1.0.19 |
|
| 796 | + */ |
|
| 797 | + public function get_billing_email() { |
|
| 798 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * Checks if the submitter has a billing email. |
|
| 803 | + * |
|
| 804 | + * @since 1.0.19 |
|
| 805 | + */ |
|
| 806 | + public function has_billing_email() { |
|
| 807 | + $billing_email = $this->get_billing_email(); |
|
| 808 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * Returns the appropriate currency for the submission. |
|
| 813 | + * |
|
| 814 | + * @since 1.0.19 |
|
| 815 | + * @return string |
|
| 816 | + */ |
|
| 817 | + public function get_currency() { |
|
| 818 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * Returns the raw submission data. |
|
| 823 | + * |
|
| 824 | + * @since 1.0.19 |
|
| 825 | + * @return array |
|
| 826 | + */ |
|
| 827 | + public function get_data() { |
|
| 828 | + return $this->data; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + /** |
|
| 832 | + * Returns a field from the submission data |
|
| 833 | + * |
|
| 834 | + * @param string $field |
|
| 835 | + * @since 1.0.19 |
|
| 836 | + * @return mixed|null |
|
| 837 | + */ |
|
| 838 | + public function get_field( $field, $sub_array_key = null ) { |
|
| 839 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + /** |
|
| 843 | + * Checks if a required field is set. |
|
| 844 | + * |
|
| 845 | + * @since 1.0.19 |
|
| 846 | + */ |
|
| 847 | + public function is_required_field_set( $field ) { |
|
| 848 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * Formats an amount |
|
| 853 | + * |
|
| 854 | + * @since 1.0.19 |
|
| 855 | + */ |
|
| 856 | + public function format_amount( $amount ) { |
|
| 857 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | 860 | } |
@@ -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( 'addons' ); |
|
| 22 | + /** |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $supports = array( 'addons' ); |
|
| 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,23 +44,23 @@ 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 ); |
|
| 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 | 51 | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | - * Process Payment. |
|
| 56 | - * |
|
| 57 | - * |
|
| 58 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 59 | - * @param array $submission_data Posted checkout fields. |
|
| 60 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 61 | - * @return array |
|
| 62 | - */ |
|
| 63 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 55 | + * Process Payment. |
|
| 56 | + * |
|
| 57 | + * |
|
| 58 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 59 | + * @param array $submission_data Posted checkout fields. |
|
| 60 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 61 | + * @return array |
|
| 62 | + */ |
|
| 63 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 64 | 64 | |
| 65 | 65 | // Add a transaction id. |
| 66 | 66 | $invoice->set_transaction_id( $invoice->generate_key('trans_') ); |
@@ -81,66 +81,66 @@ discard block |
||
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | - * Output for the order received page. |
|
| 85 | - * |
|
| 86 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 87 | - */ |
|
| 88 | - public function thankyou_page( $invoice ) { |
|
| 84 | + * Output for the order received page. |
|
| 85 | + * |
|
| 86 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 87 | + */ |
|
| 88 | + public function thankyou_page( $invoice ) { |
|
| 89 | 89 | |
| 90 | 90 | if ( 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
| 91 | 91 | |
| 92 | - echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
| 92 | + echo '<div class="mt-4 mb-2 getpaid-bank-transfer-details">' . PHP_EOL; |
|
| 93 | 93 | |
| 94 | 94 | if ( ! empty( $this->instructions ) ) { |
| 95 | 95 | echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) ); |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - $this->bank_details( $invoice ); |
|
| 98 | + $this->bank_details( $invoice ); |
|
| 99 | 99 | |
| 100 | - echo '</div>'; |
|
| 100 | + echo '</div>'; |
|
| 101 | 101 | |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * Add content to the WPI emails. |
|
| 108 | - * |
|
| 109 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 110 | - * @param string $email_type Email format: plain text or HTML. |
|
| 111 | - * @param bool $sent_to_admin Sent to admin. |
|
| 112 | - */ |
|
| 113 | - public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
| 107 | + * Add content to the WPI emails. |
|
| 108 | + * |
|
| 109 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 110 | + * @param string $email_type Email format: plain text or HTML. |
|
| 111 | + * @param bool $sent_to_admin Sent to admin. |
|
| 112 | + */ |
|
| 113 | + public function email_instructions( $invoice, $email_type, $sent_to_admin ) { |
|
| 114 | 114 | |
| 115 | - if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
| 115 | + if ( ! $sent_to_admin && 'bank_transfer' === $invoice->get_gateway() && $invoice->needs_payment() ) { |
|
| 116 | 116 | |
| 117 | - echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
| 117 | + echo '<div class="wpi-email-row getpaid-bank-transfer-details">'; |
|
| 118 | 118 | |
| 119 | - if ( $this->instructions ) { |
|
| 120 | - echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
| 119 | + if ( $this->instructions ) { |
|
| 120 | + echo wp_kses_post( wpautop( wptexturize( $this->instructions ) ) . PHP_EOL ); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $this->bank_details( $invoice ); |
|
| 123 | + $this->bank_details( $invoice ); |
|
| 124 | 124 | |
| 125 | - echo '</div>'; |
|
| 125 | + echo '</div>'; |
|
| 126 | 126 | |
| 127 | - } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
| 132 | - * Get bank details and place into a list format. |
|
| 133 | - * |
|
| 134 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 135 | - */ |
|
| 136 | - protected function bank_details( $invoice ) { |
|
| 132 | + * Get bank details and place into a list format. |
|
| 133 | + * |
|
| 134 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 135 | + */ |
|
| 136 | + protected function bank_details( $invoice ) { |
|
| 137 | 137 | |
| 138 | - // Get the invoice country and country $locale. |
|
| 139 | - $country = $invoice->get_country(); |
|
| 140 | - $locale = $this->get_country_locale(); |
|
| 138 | + // Get the invoice country and country $locale. |
|
| 139 | + $country = $invoice->get_country(); |
|
| 140 | + $locale = $this->get_country_locale(); |
|
| 141 | 141 | |
| 142 | - // Get sortcode label in the $locale array and use appropriate one. |
|
| 143 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
| 142 | + // Get sortcode label in the $locale array and use appropriate one. |
|
| 143 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
| 144 | 144 | |
| 145 | 145 | $bank_fields = array( |
| 146 | 146 | 'ac_name' => __( 'Account Name', 'invoicing' ), |
@@ -169,144 +169,144 @@ discard block |
||
| 169 | 169 | return; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
| 172 | + echo '<h3 class="getpaid-bank-transfer-title"> ' . apply_filters( 'wpinv_receipt_bank_details_title', __( 'Bank Details', 'invoicing' ) ) . '</h3>' . PHP_EOL; |
|
| 173 | 173 | |
| 174 | - echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
| 174 | + echo '<table class="table table-bordered getpaid-bank-transfer-details">' . PHP_EOL; |
|
| 175 | 175 | |
| 176 | - foreach ( $bank_info as $key => $data ) { |
|
| 176 | + foreach ( $bank_info as $key => $data ) { |
|
| 177 | 177 | |
| 178 | - $key = sanitize_html_class( $key ); |
|
| 179 | - $label = wp_kses_post( $data['label'] ); |
|
| 180 | - $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
| 178 | + $key = sanitize_html_class( $key ); |
|
| 179 | + $label = wp_kses_post( $data['label'] ); |
|
| 180 | + $value = wp_kses_post( wptexturize( $data['value'] ) ); |
|
| 181 | 181 | |
| 182 | - echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL; |
|
| 183 | - } |
|
| 182 | + echo "<tr class='getpaid-bank-transfer-$key'><th class='font-weight-bold'>$label</th><td class='w-75'>$value</td></tr>" . PHP_EOL; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - echo '</table>'; |
|
| 185 | + echo '</table>'; |
|
| 186 | 186 | |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
| 190 | - * Get country locale if localized. |
|
| 191 | - * |
|
| 192 | - * @return array |
|
| 193 | - */ |
|
| 194 | - public function get_country_locale() { |
|
| 195 | - |
|
| 196 | - if ( empty( $this->locale ) ) { |
|
| 197 | - |
|
| 198 | - // Locale information to be used - only those that are not 'Sort Code'. |
|
| 199 | - $this->locale = apply_filters( |
|
| 200 | - 'getpaid_get_bank_transfer_locale', |
|
| 201 | - array( |
|
| 202 | - 'AU' => array( |
|
| 203 | - 'sortcode' => array( |
|
| 204 | - 'label' => __( 'BSB', 'invoicing' ), |
|
| 205 | - ), |
|
| 206 | - ), |
|
| 207 | - 'CA' => array( |
|
| 208 | - 'sortcode' => array( |
|
| 209 | - 'label' => __( 'Bank transit number', 'invoicing' ), |
|
| 210 | - ), |
|
| 211 | - ), |
|
| 212 | - 'IN' => array( |
|
| 213 | - 'sortcode' => array( |
|
| 214 | - 'label' => __( 'IFSC', 'invoicing' ), |
|
| 215 | - ), |
|
| 216 | - ), |
|
| 217 | - 'IT' => array( |
|
| 218 | - 'sortcode' => array( |
|
| 219 | - 'label' => __( 'Branch sort', 'invoicing' ), |
|
| 220 | - ), |
|
| 221 | - ), |
|
| 222 | - 'NZ' => array( |
|
| 223 | - 'sortcode' => array( |
|
| 224 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
| 225 | - ), |
|
| 226 | - ), |
|
| 227 | - 'SE' => array( |
|
| 228 | - 'sortcode' => array( |
|
| 229 | - 'label' => __( 'Bank code', 'invoicing' ), |
|
| 230 | - ), |
|
| 231 | - ), |
|
| 232 | - 'US' => array( |
|
| 233 | - 'sortcode' => array( |
|
| 234 | - 'label' => __( 'Routing number', 'invoicing' ), |
|
| 235 | - ), |
|
| 236 | - ), |
|
| 237 | - 'ZA' => array( |
|
| 238 | - 'sortcode' => array( |
|
| 239 | - 'label' => __( 'Branch code', 'invoicing' ), |
|
| 240 | - ), |
|
| 241 | - ), |
|
| 242 | - ) |
|
| 243 | - ); |
|
| 244 | - |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return $this->locale; |
|
| 248 | - |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Filters the gateway settings. |
|
| 253 | - * |
|
| 254 | - * @param array $admin_settings |
|
| 255 | - */ |
|
| 256 | - public function admin_settings( $admin_settings ) { |
|
| 190 | + * Get country locale if localized. |
|
| 191 | + * |
|
| 192 | + * @return array |
|
| 193 | + */ |
|
| 194 | + public function get_country_locale() { |
|
| 195 | + |
|
| 196 | + if ( empty( $this->locale ) ) { |
|
| 197 | + |
|
| 198 | + // Locale information to be used - only those that are not 'Sort Code'. |
|
| 199 | + $this->locale = apply_filters( |
|
| 200 | + 'getpaid_get_bank_transfer_locale', |
|
| 201 | + array( |
|
| 202 | + 'AU' => array( |
|
| 203 | + 'sortcode' => array( |
|
| 204 | + 'label' => __( 'BSB', 'invoicing' ), |
|
| 205 | + ), |
|
| 206 | + ), |
|
| 207 | + 'CA' => array( |
|
| 208 | + 'sortcode' => array( |
|
| 209 | + 'label' => __( 'Bank transit number', 'invoicing' ), |
|
| 210 | + ), |
|
| 211 | + ), |
|
| 212 | + 'IN' => array( |
|
| 213 | + 'sortcode' => array( |
|
| 214 | + 'label' => __( 'IFSC', 'invoicing' ), |
|
| 215 | + ), |
|
| 216 | + ), |
|
| 217 | + 'IT' => array( |
|
| 218 | + 'sortcode' => array( |
|
| 219 | + 'label' => __( 'Branch sort', 'invoicing' ), |
|
| 220 | + ), |
|
| 221 | + ), |
|
| 222 | + 'NZ' => array( |
|
| 223 | + 'sortcode' => array( |
|
| 224 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
| 225 | + ), |
|
| 226 | + ), |
|
| 227 | + 'SE' => array( |
|
| 228 | + 'sortcode' => array( |
|
| 229 | + 'label' => __( 'Bank code', 'invoicing' ), |
|
| 230 | + ), |
|
| 231 | + ), |
|
| 232 | + 'US' => array( |
|
| 233 | + 'sortcode' => array( |
|
| 234 | + 'label' => __( 'Routing number', 'invoicing' ), |
|
| 235 | + ), |
|
| 236 | + ), |
|
| 237 | + 'ZA' => array( |
|
| 238 | + 'sortcode' => array( |
|
| 239 | + 'label' => __( 'Branch code', 'invoicing' ), |
|
| 240 | + ), |
|
| 241 | + ), |
|
| 242 | + ) |
|
| 243 | + ); |
|
| 244 | + |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return $this->locale; |
|
| 248 | + |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Filters the gateway settings. |
|
| 253 | + * |
|
| 254 | + * @param array $admin_settings |
|
| 255 | + */ |
|
| 256 | + public function admin_settings( $admin_settings ) { |
|
| 257 | 257 | |
| 258 | 258 | $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' ); |
| 259 | - $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
| 259 | + $admin_settings['bank_transfer_active']['desc'] = __( 'Enable bank transfer', 'invoicing' ); |
|
| 260 | 260 | |
| 261 | - $locale = $this->get_country_locale(); |
|
| 261 | + $locale = $this->get_country_locale(); |
|
| 262 | 262 | |
| 263 | - // Get sortcode label in the $locale array and use appropriate one. |
|
| 264 | - $country = wpinv_default_billing_country(); |
|
| 265 | - $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
| 263 | + // Get sortcode label in the $locale array and use appropriate one. |
|
| 264 | + $country = wpinv_default_billing_country(); |
|
| 265 | + $sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'invoicing' ); |
|
| 266 | 266 | |
| 267 | - $admin_settings['bank_transfer_ac_name'] = array( |
|
| 267 | + $admin_settings['bank_transfer_ac_name'] = array( |
|
| 268 | 268 | 'type' => 'text', |
| 269 | 269 | 'id' => 'bank_transfer_ac_name', |
| 270 | 270 | 'name' => __( 'Account Name', 'invoicing' ), |
| 271 | - ); |
|
| 271 | + ); |
|
| 272 | 272 | |
| 273 | - $admin_settings['bank_transfer_ac_no'] = array( |
|
| 273 | + $admin_settings['bank_transfer_ac_no'] = array( |
|
| 274 | 274 | 'type' => 'text', |
| 275 | 275 | 'id' => 'bank_transfer_ac_no', |
| 276 | 276 | 'name' => __( 'Account Number', 'invoicing' ), |
| 277 | - ); |
|
| 277 | + ); |
|
| 278 | 278 | |
| 279 | - $admin_settings['bank_transfer_bank_name'] = array( |
|
| 279 | + $admin_settings['bank_transfer_bank_name'] = array( |
|
| 280 | 280 | 'type' => 'text', |
| 281 | 281 | 'id' => 'bank_transfer_bank_name', |
| 282 | 282 | 'name' => __( 'Bank Name', 'invoicing' ), |
| 283 | - ); |
|
| 283 | + ); |
|
| 284 | 284 | |
| 285 | - $admin_settings['bank_transfer_ifsc'] = array( |
|
| 285 | + $admin_settings['bank_transfer_ifsc'] = array( |
|
| 286 | 286 | 'type' => 'text', |
| 287 | 287 | 'id' => 'bank_transfer_ifsc', |
| 288 | 288 | 'name' => __( 'IFSC Code', 'invoicing' ), |
| 289 | - ); |
|
| 289 | + ); |
|
| 290 | 290 | |
| 291 | - $admin_settings['bank_transfer_iban'] = array( |
|
| 291 | + $admin_settings['bank_transfer_iban'] = array( |
|
| 292 | 292 | 'type' => 'text', |
| 293 | 293 | 'id' => 'bank_transfer_iban', |
| 294 | 294 | 'name' => __( 'IBAN', 'invoicing' ), |
| 295 | - ); |
|
| 295 | + ); |
|
| 296 | 296 | |
| 297 | - $admin_settings['bank_transfer_bic'] = array( |
|
| 297 | + $admin_settings['bank_transfer_bic'] = array( |
|
| 298 | 298 | 'type' => 'text', |
| 299 | 299 | 'id' => 'bank_transfer_bic', |
| 300 | 300 | 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
| 301 | - ); |
|
| 301 | + ); |
|
| 302 | 302 | |
| 303 | - $admin_settings['bank_transfer_sort_code'] = array( |
|
| 304 | - 'type' => 'text', |
|
| 305 | - 'id' => 'bank_transfer_sort_code', |
|
| 306 | - 'name' => $sortcode, |
|
| 307 | - ); |
|
| 303 | + $admin_settings['bank_transfer_sort_code'] = array( |
|
| 304 | + 'type' => 'text', |
|
| 305 | + 'id' => 'bank_transfer_sort_code', |
|
| 306 | + 'name' => $sortcode, |
|
| 307 | + ); |
|
| 308 | 308 | |
| 309 | - $admin_settings['bank_transfer_info'] = array( |
|
| 309 | + $admin_settings['bank_transfer_info'] = array( |
|
| 310 | 310 | 'id' => 'bank_transfer_info', |
| 311 | 311 | 'name' => __( 'Instructions', 'invoicing' ), |
| 312 | 312 | 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
@@ -316,17 +316,17 @@ discard block |
||
| 316 | 316 | 'rows' => 5 |
| 317 | 317 | ); |
| 318 | 318 | |
| 319 | - return $admin_settings; |
|
| 320 | - } |
|
| 319 | + return $admin_settings; |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * Processes invoice addons. |
|
| 324 | - * |
|
| 325 | - * @param WPInv_Invoice $invoice |
|
| 326 | - * @param GetPaid_Form_Item[] $items |
|
| 327 | - * @return WPInv_Invoice |
|
| 328 | - */ |
|
| 329 | - public function process_addons( $invoice, $items ) { |
|
| 322 | + /** |
|
| 323 | + * Processes invoice addons. |
|
| 324 | + * |
|
| 325 | + * @param WPInv_Invoice $invoice |
|
| 326 | + * @param GetPaid_Form_Item[] $items |
|
| 327 | + * @return WPInv_Invoice |
|
| 328 | + */ |
|
| 329 | + public function process_addons( $invoice, $items ) { |
|
| 330 | 330 | |
| 331 | 331 | foreach ( $items as $item ) { |
| 332 | 332 | $invoice->add_item( $item ); |
@@ -334,6 +334,6 @@ discard block |
||
| 334 | 334 | |
| 335 | 335 | $invoice->recalculate_total(); |
| 336 | 336 | $invoice->save(); |
| 337 | - } |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | 339 | } |
@@ -12,229 +12,229 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission taxes. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $taxes = array(); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Whether or not we should skip the taxes. |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $skip_taxes = false; |
|
| 15 | + /** |
|
| 16 | + * Submission taxes. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $taxes = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Whether or not we should skip the taxes. |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $skip_taxes = false; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Validate VAT number. |
|
| 35 | + $this->validate_vat( $submission ); |
|
| 36 | + |
|
| 37 | + if ( $this->skip_taxes ) { |
|
| 38 | + return; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + foreach ( $submission->get_items() as $item ) { |
|
| 42 | + $this->process_item_tax( $item, $submission ); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + // Process any existing invoice taxes. |
|
| 46 | + if ( $submission->has_invoice() ) { |
|
| 47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Maybe process tax. |
|
| 54 | + * |
|
| 55 | + * @since 1.0.19 |
|
| 56 | + * @param GetPaid_Form_Item $item |
|
| 57 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | + */ |
|
| 59 | + public function process_item_tax( $item, $submission ) { |
|
| 60 | + |
|
| 61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates ); |
|
| 64 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates ); |
|
| 65 | + |
|
| 66 | + foreach ( $taxes as $name => $amount ) { |
|
| 67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | + |
|
| 70 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | + $this->taxes[ $name ] = $tax; |
|
| 72 | + continue; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Checks if the submission has a digital item. |
|
| 84 | + * |
|
| 85 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | + * @since 1.0.19 |
|
| 87 | + * @return bool |
|
| 88 | + */ |
|
| 89 | + public function has_digital_item( $submission ) { |
|
| 90 | + |
|
| 91 | + foreach ( $submission->get_items() as $item ) { |
|
| 92 | + |
|
| 93 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return false; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Checks if this is an eu store. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.19 |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + public static function is_eu_store() { |
|
| 109 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
| 110 | + } |
|
| 26 | 111 | |
| 27 | 112 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Validate VAT number. |
|
| 35 | - $this->validate_vat( $submission ); |
|
| 36 | - |
|
| 37 | - if ( $this->skip_taxes ) { |
|
| 38 | - return; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - foreach ( $submission->get_items() as $item ) { |
|
| 42 | - $this->process_item_tax( $item, $submission ); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - // Process any existing invoice taxes. |
|
| 46 | - if ( $submission->has_invoice() ) { |
|
| 47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Maybe process tax. |
|
| 54 | - * |
|
| 55 | - * @since 1.0.19 |
|
| 56 | - * @param GetPaid_Form_Item $item |
|
| 57 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 58 | - */ |
|
| 59 | - public function process_item_tax( $item, $submission ) { |
|
| 60 | - |
|
| 61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
| 62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
| 63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates ); |
|
| 64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates ); |
|
| 65 | - |
|
| 66 | - foreach ( $taxes as $name => $amount ) { |
|
| 67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
| 68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
| 69 | - |
|
| 70 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
| 71 | - $this->taxes[ $name ] = $tax; |
|
| 72 | - continue; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
| 76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Checks if the submission has a digital item. |
|
| 84 | - * |
|
| 85 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | - * @since 1.0.19 |
|
| 87 | - * @return bool |
|
| 88 | - */ |
|
| 89 | - public function has_digital_item( $submission ) { |
|
| 90 | - |
|
| 91 | - foreach ( $submission->get_items() as $item ) { |
|
| 92 | - |
|
| 93 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 94 | - return true; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return false; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Checks if this is an eu store. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.19 |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - public static function is_eu_store() { |
|
| 109 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Checks if this is an eu country. |
|
| 114 | - * |
|
| 115 | - * @param string $country |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - * @return bool |
|
| 118 | - */ |
|
| 119 | - public static function is_eu_country( $country ) { |
|
| 120 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Checks if this is an eu purchase. |
|
| 125 | - * |
|
| 126 | - * @param string $customer_country |
|
| 127 | - * @since 1.0.19 |
|
| 128 | - * @return bool |
|
| 129 | - */ |
|
| 130 | - public static function is_eu_transaction( $customer_country ) { |
|
| 131 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Retrieves the vat number. |
|
| 136 | - * |
|
| 137 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 138 | - * @since 1.0.19 |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function get_vat_number( $submission ) { |
|
| 142 | - |
|
| 143 | - // Retrieve from the posted number. |
|
| 144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | - if ( ! empty( $vat_number ) ) { |
|
| 146 | - return wpinv_clean( $vat_number ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // Retrieve from the invoice. |
|
| 150 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Retrieves the company. |
|
| 155 | - * |
|
| 156 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 157 | - * @since 1.0.19 |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - public function get_company( $submission ) { |
|
| 161 | - |
|
| 162 | - // Retrieve from the posted data. |
|
| 163 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | - if ( ! empty( $company ) ) { |
|
| 165 | - return wpinv_clean( $company ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Retrieve from the invoice. |
|
| 169 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Checks if we require a VAT number. |
|
| 174 | - * |
|
| 175 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 176 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 177 | - * @since 1.0.19 |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 180 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 181 | - |
|
| 182 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 184 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
| 185 | - |
|
| 186 | - return $prevent_b2c && $is_eu; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Validate VAT data. |
|
| 191 | - * |
|
| 192 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 193 | - * @since 1.0.19 |
|
| 194 | - */ |
|
| 195 | - public function validate_vat( $submission ) { |
|
| 196 | - |
|
| 197 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 198 | - |
|
| 199 | - // Abort if we are not validating vat numbers. |
|
| 200 | - if ( ! $in_eu ) { |
|
| 113 | + * Checks if this is an eu country. |
|
| 114 | + * |
|
| 115 | + * @param string $country |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + * @return bool |
|
| 118 | + */ |
|
| 119 | + public static function is_eu_country( $country ) { |
|
| 120 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Checks if this is an eu purchase. |
|
| 125 | + * |
|
| 126 | + * @param string $customer_country |
|
| 127 | + * @since 1.0.19 |
|
| 128 | + * @return bool |
|
| 129 | + */ |
|
| 130 | + public static function is_eu_transaction( $customer_country ) { |
|
| 131 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Retrieves the vat number. |
|
| 136 | + * |
|
| 137 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 138 | + * @since 1.0.19 |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function get_vat_number( $submission ) { |
|
| 142 | + |
|
| 143 | + // Retrieve from the posted number. |
|
| 144 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
| 145 | + if ( ! empty( $vat_number ) ) { |
|
| 146 | + return wpinv_clean( $vat_number ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // Retrieve from the invoice. |
|
| 150 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Retrieves the company. |
|
| 155 | + * |
|
| 156 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 157 | + * @since 1.0.19 |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + public function get_company( $submission ) { |
|
| 161 | + |
|
| 162 | + // Retrieve from the posted data. |
|
| 163 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
| 164 | + if ( ! empty( $company ) ) { |
|
| 165 | + return wpinv_clean( $company ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // Retrieve from the invoice. |
|
| 169 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Checks if we require a VAT number. |
|
| 174 | + * |
|
| 175 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 176 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 177 | + * @since 1.0.19 |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 181 | + |
|
| 182 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 183 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 184 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
| 185 | + |
|
| 186 | + return $prevent_b2c && $is_eu; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Validate VAT data. |
|
| 191 | + * |
|
| 192 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 193 | + * @since 1.0.19 |
|
| 194 | + */ |
|
| 195 | + public function validate_vat( $submission ) { |
|
| 196 | + |
|
| 197 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 198 | + |
|
| 199 | + // Abort if we are not validating vat numbers. |
|
| 200 | + if ( ! $in_eu ) { |
|
| 201 | 201 | return; |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - // Prepare variables. |
|
| 205 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 206 | - $ip_country = getpaid_get_ip_country(); |
|
| 204 | + // Prepare variables. |
|
| 205 | + $vat_number = $this->get_vat_number( $submission ); |
|
| 206 | + $ip_country = getpaid_get_ip_country(); |
|
| 207 | 207 | $is_eu = $this->is_eu_country( $submission->country ); |
| 208 | 208 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
| 209 | 209 | |
| 210 | - // Maybe abort early for initial fetches. |
|
| 211 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 212 | - return; |
|
| 213 | - } |
|
| 210 | + // Maybe abort early for initial fetches. |
|
| 211 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
| 212 | + return; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - // If we're preventing business to consumer purchases, |
|
| 216 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 215 | + // If we're preventing business to consumer purchases, |
|
| 216 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 217 | 217 | |
| 218 | - // Ensure that a vat number has been specified. |
|
| 219 | - throw new Exception( |
|
| 220 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 221 | - ); |
|
| 218 | + // Ensure that a vat number has been specified. |
|
| 219 | + throw new Exception( |
|
| 220 | + __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) |
|
| 221 | + ); |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - if ( empty( $vat_number ) ) { |
|
| 226 | - return; |
|
| 227 | - } |
|
| 225 | + if ( empty( $vat_number ) ) { |
|
| 226 | + return; |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 230 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 231 | - } |
|
| 229 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
| 230 | + throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 234 | - return; |
|
| 235 | - } |
|
| 233 | + if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
| 234 | + return; |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - $this->skip_taxes = true; |
|
| 238 | - } |
|
| 237 | + $this->skip_taxes = true; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | 240 | } |
@@ -24,64 +24,64 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | <?php |
| 26 | 26 | |
| 27 | - // Fires before printing a line item column. |
|
| 28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
| 27 | + // Fires before printing a line item column. |
|
| 28 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
| 29 | 29 | |
| 30 | - // Item name. |
|
| 31 | - if ( 'name' == $key ) { |
|
| 30 | + // Item name. |
|
| 31 | + if ( 'name' == $key ) { |
|
| 32 | 32 | |
| 33 | - // Display the name. |
|
| 34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
| 33 | + // Display the name. |
|
| 34 | + echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
| 35 | 35 | |
| 36 | - // And an optional description. |
|
| 36 | + // And an optional description. |
|
| 37 | 37 | $description = $item->get_description(); |
| 38 | 38 | |
| 39 | 39 | if ( ! empty( $description ) ) { |
| 40 | 40 | $description = wp_kses_post( $description ); |
| 41 | 41 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // Price help text. |
|
| 44 | + // Price help text. |
|
| 45 | 45 | $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
| 46 | 46 | if ( $description ) { |
| 47 | 47 | echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>"; |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // Item price. |
|
| 53 | - if ( 'price' == $key ) { |
|
| 52 | + // Item price. |
|
| 53 | + if ( 'price' == $key ) { |
|
| 54 | 54 | |
| 55 | - // Set the currency position. |
|
| 56 | - $position = wpinv_currency_position(); |
|
| 55 | + // Set the currency position. |
|
| 56 | + $position = wpinv_currency_position(); |
|
| 57 | 57 | |
| 58 | - if ( $position == 'left_space' ) { |
|
| 59 | - $position = 'left'; |
|
| 60 | - } |
|
| 58 | + if ( $position == 'left_space' ) { |
|
| 59 | + $position = 'left'; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - if ( $position == 'right_space' ) { |
|
| 63 | - $position = 'right'; |
|
| 64 | - } |
|
| 62 | + if ( $position == 'right_space' ) { |
|
| 63 | + $position = 'right'; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if ( $item->user_can_set_their_price() ) { |
|
| 67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
| 68 | - $minimum = (float) $item->get_minimum_price(); |
|
| 69 | - $validate_minimum = ''; |
|
| 70 | - $class = ''; |
|
| 71 | - $data_minimum = ''; |
|
| 66 | + if ( $item->user_can_set_their_price() ) { |
|
| 67 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
| 68 | + $minimum = (float) $item->get_minimum_price(); |
|
| 69 | + $validate_minimum = ''; |
|
| 70 | + $class = ''; |
|
| 71 | + $data_minimum = ''; |
|
| 72 | 72 | |
| 73 | - if ( $minimum > 0 ) { |
|
| 74 | - $validate_minimum = sprintf( |
|
| 75 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
| 76 | - sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
| 77 | - ); |
|
| 73 | + if ( $minimum > 0 ) { |
|
| 74 | + $validate_minimum = sprintf( |
|
| 75 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
| 76 | + sanitize_text_field( wpinv_price( $minimum, $currency ) ) |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - $class = 'getpaid-validate-minimum-amount'; |
|
| 79 | + $class = 'getpaid-validate-minimum-amount'; |
|
| 80 | 80 | |
| 81 | - $data_minimum = "data-minimum-amount='$minimum'"; |
|
| 82 | - } |
|
| 81 | + $data_minimum = "data-minimum-amount='$minimum'"; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - ?> |
|
| 84 | + ?> |
|
| 85 | 85 | <div class="input-group input-group-sm"> |
| 86 | 86 | <?php if( 'left' == $position ) : ?> |
| 87 | 87 | <div class="input-group-prepend"> |
@@ -105,37 +105,37 @@ discard block |
||
| 105 | 105 | </div> |
| 106 | 106 | |
| 107 | 107 | <?php |
| 108 | - } else { |
|
| 109 | - echo wpinv_price( $item->get_price(), $currency ); |
|
| 110 | - ?> |
|
| 108 | + } else { |
|
| 109 | + echo wpinv_price( $item->get_price(), $currency ); |
|
| 110 | + ?> |
|
| 111 | 111 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
| 112 | 112 | <?php |
| 113 | - } |
|
| 114 | - } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - // Item quantity. |
|
| 117 | - if ( 'quantity' == $key ) { |
|
| 116 | + // Item quantity. |
|
| 117 | + if ( 'quantity' == $key ) { |
|
| 118 | 118 | |
| 119 | - if ( $item->allows_quantities() ) { |
|
| 120 | - ?> |
|
| 119 | + if ( $item->allows_quantities() ) { |
|
| 120 | + ?> |
|
| 121 | 121 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required> |
| 122 | 122 | <?php |
| 123 | - } else { |
|
| 124 | - echo (float) $item->get_quantity(); |
|
| 125 | - echo ' '; |
|
| 126 | - ?> |
|
| 123 | + } else { |
|
| 124 | + echo (float) $item->get_quantity(); |
|
| 125 | + echo ' '; |
|
| 126 | + ?> |
|
| 127 | 127 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
| 128 | 128 | <?php |
| 129 | - } |
|
| 130 | - } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - // Item sub total. |
|
| 133 | - if ( 'subtotal' == $key ) { |
|
| 134 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
| 135 | - } |
|
| 132 | + // Item sub total. |
|
| 133 | + if ( 'subtotal' == $key ) { |
|
| 134 | + echo wpinv_price( $item->get_sub_total(), $currency ); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
| 138 | - ?> |
|
| 137 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
| 138 | + ?> |
|
| 139 | 139 | |
| 140 | 140 | </div> |
| 141 | 141 | |
@@ -12,255 +12,255 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Contains the response for refreshing prices. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $response = array(); |
|
| 15 | + /** |
|
| 16 | + * Contains the response for refreshing prices. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $response = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $this->response = array( |
|
| 29 | - 'submission_id' => $submission->id, |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $this->response = array( |
|
| 29 | + 'submission_id' => $submission->id, |
|
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | 31 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 32 | - ); |
|
| 33 | - |
|
| 34 | - $this->add_totals( $submission ); |
|
| 35 | - $this->add_texts( $submission ); |
|
| 36 | - $this->add_items( $submission ); |
|
| 37 | - $this->add_fees( $submission ); |
|
| 38 | - $this->add_discounts( $submission ); |
|
| 39 | - $this->add_taxes( $submission ); |
|
| 40 | - $this->add_gateways( $submission ); |
|
| 41 | - |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Adds totals to a response for submission refresh prices. |
|
| 46 | - * |
|
| 47 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 48 | - */ |
|
| 49 | - public function add_totals( $submission ) { |
|
| 50 | - |
|
| 51 | - $this->response = array_merge( |
|
| 52 | - $this->response, |
|
| 53 | - array( |
|
| 54 | - |
|
| 55 | - 'totals' => array( |
|
| 56 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 57 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 58 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 59 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 60 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 61 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 62 | - ), |
|
| 63 | - |
|
| 64 | - 'recurring' => array( |
|
| 65 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 66 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 67 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 68 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 69 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 70 | - ), |
|
| 71 | - |
|
| 72 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 73 | - 'currency' => $submission->get_currency(), |
|
| 74 | - |
|
| 75 | - ) |
|
| 76 | - ); |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Adds texts to a response for submission refresh prices. |
|
| 82 | - * |
|
| 83 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 84 | - */ |
|
| 85 | - public function add_texts( $submission ) { |
|
| 86 | - |
|
| 87 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 88 | - |
|
| 89 | - if ( $submission->has_recurring != 0 ) { |
|
| 90 | - |
|
| 91 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 92 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 93 | - |
|
| 94 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 95 | - $payable = "$payable / $period"; |
|
| 96 | - } else { |
|
| 97 | - $payable = sprintf( |
|
| 98 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 99 | - $submission->format_amount( $submission->get_total() ), |
|
| 100 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 101 | - $period |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $texts = array( |
|
| 108 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 109 | - ); |
|
| 110 | - |
|
| 111 | - foreach ( $submission->get_items() as $item_id => $item ) { |
|
| 112 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 113 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 114 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 118 | - |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Adds items to a response for submission refresh prices. |
|
| 123 | - * |
|
| 124 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 125 | - */ |
|
| 126 | - public function add_items( $submission ) { |
|
| 127 | - |
|
| 128 | - // Add items. |
|
| 129 | - $items = array(); |
|
| 32 | + ); |
|
| 33 | + |
|
| 34 | + $this->add_totals( $submission ); |
|
| 35 | + $this->add_texts( $submission ); |
|
| 36 | + $this->add_items( $submission ); |
|
| 37 | + $this->add_fees( $submission ); |
|
| 38 | + $this->add_discounts( $submission ); |
|
| 39 | + $this->add_taxes( $submission ); |
|
| 40 | + $this->add_gateways( $submission ); |
|
| 41 | + |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Adds totals to a response for submission refresh prices. |
|
| 46 | + * |
|
| 47 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 48 | + */ |
|
| 49 | + public function add_totals( $submission ) { |
|
| 50 | + |
|
| 51 | + $this->response = array_merge( |
|
| 52 | + $this->response, |
|
| 53 | + array( |
|
| 54 | + |
|
| 55 | + 'totals' => array( |
|
| 56 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 57 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 58 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 59 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 60 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 61 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 62 | + ), |
|
| 63 | + |
|
| 64 | + 'recurring' => array( |
|
| 65 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 66 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 67 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 68 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 69 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 70 | + ), |
|
| 71 | + |
|
| 72 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 73 | + 'currency' => $submission->get_currency(), |
|
| 74 | + |
|
| 75 | + ) |
|
| 76 | + ); |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Adds texts to a response for submission refresh prices. |
|
| 82 | + * |
|
| 83 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 84 | + */ |
|
| 85 | + public function add_texts( $submission ) { |
|
| 86 | + |
|
| 87 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 88 | + |
|
| 89 | + if ( $submission->has_recurring != 0 ) { |
|
| 90 | + |
|
| 91 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 92 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 93 | + |
|
| 94 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 95 | + $payable = "$payable / $period"; |
|
| 96 | + } else { |
|
| 97 | + $payable = sprintf( |
|
| 98 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 99 | + $submission->format_amount( $submission->get_total() ), |
|
| 100 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 101 | + $period |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $texts = array( |
|
| 108 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 109 | + ); |
|
| 130 | 110 | |
| 131 | 111 | foreach ( $submission->get_items() as $item_id => $item ) { |
| 132 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 133 | - } |
|
| 112 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 113 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 114 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 115 | + } |
|
| 134 | 116 | |
| 135 | - $this->response = array_merge( |
|
| 136 | - $this->response, |
|
| 137 | - array( 'items' => $items ) |
|
| 138 | - ); |
|
| 117 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 139 | 118 | |
| 140 | - } |
|
| 119 | + } |
|
| 141 | 120 | |
| 142 | - /** |
|
| 143 | - * Adds fees to a response for submission refresh prices. |
|
| 144 | - * |
|
| 145 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 146 | - */ |
|
| 147 | - public function add_fees( $submission ) { |
|
| 121 | + /** |
|
| 122 | + * Adds items to a response for submission refresh prices. |
|
| 123 | + * |
|
| 124 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 125 | + */ |
|
| 126 | + public function add_items( $submission ) { |
|
| 127 | + |
|
| 128 | + // Add items. |
|
| 129 | + $items = array(); |
|
| 130 | + |
|
| 131 | + foreach ( $submission->get_items() as $item_id => $item ) { |
|
| 132 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 133 | + } |
|
| 148 | 134 | |
| 149 | - $fees = array(); |
|
| 135 | + $this->response = array_merge( |
|
| 136 | + $this->response, |
|
| 137 | + array( 'items' => $items ) |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Adds fees to a response for submission refresh prices. |
|
| 144 | + * |
|
| 145 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 146 | + */ |
|
| 147 | + public function add_fees( $submission ) { |
|
| 148 | + |
|
| 149 | + $fees = array(); |
|
| 150 | 150 | |
| 151 | 151 | foreach ( $submission->get_fees() as $name => $data ) { |
| 152 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 153 | - } |
|
| 152 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - $this->response = array_merge( |
|
| 156 | - $this->response, |
|
| 157 | - array( 'fees' => $fees ) |
|
| 158 | - ); |
|
| 155 | + $this->response = array_merge( |
|
| 156 | + $this->response, |
|
| 157 | + array( 'fees' => $fees ) |
|
| 158 | + ); |
|
| 159 | 159 | |
| 160 | - } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Adds discounts to a response for submission refresh prices. |
|
| 164 | - * |
|
| 165 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 166 | - */ |
|
| 167 | - public function add_discounts( $submission ) { |
|
| 162 | + /** |
|
| 163 | + * Adds discounts to a response for submission refresh prices. |
|
| 164 | + * |
|
| 165 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 166 | + */ |
|
| 167 | + public function add_discounts( $submission ) { |
|
| 168 | 168 | |
| 169 | - $discounts = array(); |
|
| 169 | + $discounts = array(); |
|
| 170 | 170 | |
| 171 | 171 | foreach ( $submission->get_discounts() as $name => $data ) { |
| 172 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $this->response = array_merge( |
|
| 176 | - $this->response, |
|
| 177 | - array( 'discounts' => $discounts ) |
|
| 178 | - ); |
|
| 172 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 173 | + } |
|
| 179 | 174 | |
| 180 | - } |
|
| 175 | + $this->response = array_merge( |
|
| 176 | + $this->response, |
|
| 177 | + array( 'discounts' => $discounts ) |
|
| 178 | + ); |
|
| 181 | 179 | |
| 182 | - /** |
|
| 183 | - * Adds taxes to a response for submission refresh prices. |
|
| 184 | - * |
|
| 185 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 186 | - */ |
|
| 187 | - public function add_taxes( $submission ) { |
|
| 180 | + } |
|
| 188 | 181 | |
| 189 | - $taxes = array(); |
|
| 190 | - $markup = ''; |
|
| 182 | + /** |
|
| 183 | + * Adds taxes to a response for submission refresh prices. |
|
| 184 | + * |
|
| 185 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 186 | + */ |
|
| 187 | + public function add_taxes( $submission ) { |
|
| 188 | + |
|
| 189 | + $taxes = array(); |
|
| 190 | + $markup = ''; |
|
| 191 | 191 | foreach ( $submission->get_taxes() as $name => $data ) { |
| 192 | - $name = sanitize_text_field( $name ); |
|
| 193 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 194 | - $taxes[$name] = $amount; |
|
| 195 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 196 | - } |
|
| 192 | + $name = sanitize_text_field( $name ); |
|
| 193 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 194 | + $taxes[$name] = $amount; |
|
| 195 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - if ( wpinv_display_individual_tax_rates() ) { |
|
| 199 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 200 | - } |
|
| 198 | + if ( wpinv_display_individual_tax_rates() ) { |
|
| 199 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - $this->response = array_merge( |
|
| 203 | - $this->response, |
|
| 204 | - array( 'taxes' => $taxes ) |
|
| 205 | - ); |
|
| 202 | + $this->response = array_merge( |
|
| 203 | + $this->response, |
|
| 204 | + array( 'taxes' => $taxes ) |
|
| 205 | + ); |
|
| 206 | 206 | |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Adds gateways to a response for submission refresh prices. |
|
| 211 | - * |
|
| 212 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 213 | - */ |
|
| 214 | - public function add_gateways( $submission ) { |
|
| 209 | + /** |
|
| 210 | + * Adds gateways to a response for submission refresh prices. |
|
| 211 | + * |
|
| 212 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 213 | + */ |
|
| 214 | + public function add_gateways( $submission ) { |
|
| 215 | 215 | |
| 216 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 216 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 217 | 217 | |
| 218 | - if ( $this->response['has_recurring'] ) { |
|
| 218 | + if ( $this->response['has_recurring'] ) { |
|
| 219 | 219 | |
| 220 | - foreach ( $gateways as $i => $gateway ) { |
|
| 220 | + foreach ( $gateways as $i => $gateway ) { |
|
| 221 | 221 | |
| 222 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 223 | - unset( $gateways[ $i ] ); |
|
| 224 | - } |
|
| 222 | + if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 223 | + unset( $gateways[ $i ] ); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - } |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | 230 | |
| 231 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 232 | - $this->response = array_merge( |
|
| 233 | - $this->response, |
|
| 234 | - array( 'gateways' => $gateways ) |
|
| 235 | - ); |
|
| 231 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 232 | + $this->response = array_merge( |
|
| 233 | + $this->response, |
|
| 234 | + array( 'gateways' => $gateways ) |
|
| 235 | + ); |
|
| 236 | 236 | |
| 237 | - } |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Standardizes prices. |
|
| 241 | - * |
|
| 242 | - * @param int $item_id |
|
| 243 | - * @param float $item_total |
|
| 244 | - * @param string $discount_code |
|
| 245 | - * @param bool $recurring |
|
| 246 | - */ |
|
| 247 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 239 | + /** |
|
| 240 | + * Standardizes prices. |
|
| 241 | + * |
|
| 242 | + * @param int $item_id |
|
| 243 | + * @param float $item_total |
|
| 244 | + * @param string $discount_code |
|
| 245 | + * @param bool $recurring |
|
| 246 | + */ |
|
| 247 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 248 | 248 | |
| 249 | - $standardadized_price = $item_total; |
|
| 249 | + $standardadized_price = $item_total; |
|
| 250 | 250 | |
| 251 | - // Do we have a $discount_code? |
|
| 252 | - if ( ! empty( $discount_code ) ) { |
|
| 251 | + // Do we have a $discount_code? |
|
| 252 | + if ( ! empty( $discount_code ) ) { |
|
| 253 | 253 | |
| 254 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 254 | + $discount = new WPInv_Discount( $discount_code ); |
|
| 255 | 255 | |
| 256 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 257 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 258 | - } |
|
| 256 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 257 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return max( 0, $standardadized_price ); |
|
| 262 | + return max( 0, $standardadized_price ); |
|
| 263 | 263 | |
| 264 | - } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | } |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | * Bail if we are not in WP. |
| 8 | 8 | */ |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; |
|
| 10 | + exit; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Set the version only if its the current newest while loading. |
| 15 | 15 | */ |
| 16 | 16 | add_action('after_setup_theme', function () { |
| 17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | - $this_version = "0.1.43"; |
|
| 19 | - if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | - $ayecode_ui_version = $this_version ; |
|
| 21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | - } |
|
| 17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
| 18 | + $this_version = "0.1.43"; |
|
| 19 | + if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
| 20 | + $ayecode_ui_version = $this_version ; |
|
| 21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
| 22 | + } |
|
| 23 | 23 | },0); |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
| 27 | 27 | */ |
| 28 | 28 | add_action('after_setup_theme', function () { |
| 29 | - global $ayecode_ui_file_key; |
|
| 30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | - } |
|
| 29 | + global $ayecode_ui_file_key; |
|
| 30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
| 31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
| 32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
| 33 | + } |
|
| 34 | 34 | },1); |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Add the function that calls the class. |
| 38 | 38 | */ |
| 39 | 39 | if(!function_exists('aui')){ |
| 40 | - function aui(){ |
|
| 41 | - if(!class_exists("AUI",false)){ |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - return AUI::instance(); |
|
| 45 | - } |
|
| 40 | + function aui(){ |
|
| 41 | + if(!class_exists("AUI",false)){ |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + return AUI::instance(); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | \ No newline at end of file |