@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | - exit; // Exit if accessed directly |
|
| 11 | + exit; // Exit if accessed directly |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -16,84 +16,84 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class GetPaid_Meta_Box_Invoice_Address { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Output the metabox. |
|
| 21 | - * |
|
| 22 | - * @param WP_Post $post |
|
| 23 | - */ |
|
| 24 | - public static function output( $post ) { |
|
| 25 | - |
|
| 26 | - // Prepare the invoice. |
|
| 27 | - $invoice = new WPInv_Invoice( $post ); |
|
| 28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
| 29 | - $customer = new WP_User( $customer ); |
|
| 30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
| 31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
| 32 | - |
|
| 33 | - // Address fields. |
|
| 34 | - $address_fields = array( |
|
| 35 | - 'first_name' => array( |
|
| 36 | - 'label' => __( 'First Name', 'invoicing' ), |
|
| 37 | - 'type' => 'text', |
|
| 38 | - ), |
|
| 39 | - 'last_name' => array( |
|
| 40 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
| 41 | - 'type' => 'text', |
|
| 42 | - ), |
|
| 43 | - 'company' => array( |
|
| 44 | - 'label' => __( 'Company', 'invoicing' ), |
|
| 45 | - 'type' => 'text', |
|
| 46 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
| 47 | - ), |
|
| 48 | - 'vat_number' => array( |
|
| 49 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 50 | - 'type' => 'text', |
|
| 51 | - ), |
|
| 52 | - 'address' => array( |
|
| 53 | - 'label' => __( 'Address', 'invoicing' ), |
|
| 54 | - 'type' => 'text', |
|
| 55 | - ), |
|
| 56 | - 'city' => array( |
|
| 57 | - 'label' => __( 'City', 'invoicing' ), |
|
| 58 | - 'type' => 'text', |
|
| 59 | - ), |
|
| 60 | - 'country' => array( |
|
| 61 | - 'label' => __( 'Country', 'invoicing' ), |
|
| 62 | - 'type' => 'select', |
|
| 63 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
| 64 | - 'options' => wpinv_get_country_list(), |
|
| 65 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
| 66 | - ), |
|
| 67 | - 'state' => array( |
|
| 68 | - 'label' => __( 'State', 'invoicing' ), |
|
| 69 | - 'type' => 'text', |
|
| 70 | - 'class' => 'getpaid-recalculate-prices-on-change', |
|
| 71 | - ), |
|
| 72 | - 'zip' => array( |
|
| 73 | - 'label' => __( 'Zip', 'invoicing' ), |
|
| 74 | - 'type' => 'text', |
|
| 75 | - ), |
|
| 76 | - 'phone' => array( |
|
| 77 | - 'label' => __( 'Phone', 'invoicing' ), |
|
| 78 | - 'type' => 'text', |
|
| 79 | - ), |
|
| 80 | - ); |
|
| 81 | - |
|
| 82 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
| 83 | - |
|
| 84 | - if ( ! empty( $states ) ) { |
|
| 85 | - $address_fields['state']['type'] = 'select'; |
|
| 86 | - $address_fields['state']['options'] = $states; |
|
| 87 | - $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Maybe remove the VAT field. |
|
| 91 | - if ( ! wpinv_use_taxes() ) { |
|
| 92 | - unset( $address_fields['vat_number'] ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
| 96 | - ?> |
|
| 19 | + /** |
|
| 20 | + * Output the metabox. |
|
| 21 | + * |
|
| 22 | + * @param WP_Post $post |
|
| 23 | + */ |
|
| 24 | + public static function output( $post ) { |
|
| 25 | + |
|
| 26 | + // Prepare the invoice. |
|
| 27 | + $invoice = new WPInv_Invoice( $post ); |
|
| 28 | + $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
| 29 | + $customer = new WP_User( $customer ); |
|
| 30 | + $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
| 31 | + wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
| 32 | + |
|
| 33 | + // Address fields. |
|
| 34 | + $address_fields = array( |
|
| 35 | + 'first_name' => array( |
|
| 36 | + 'label' => __( 'First Name', 'invoicing' ), |
|
| 37 | + 'type' => 'text', |
|
| 38 | + ), |
|
| 39 | + 'last_name' => array( |
|
| 40 | + 'label' => __( 'Last Name', 'invoicing' ), |
|
| 41 | + 'type' => 'text', |
|
| 42 | + ), |
|
| 43 | + 'company' => array( |
|
| 44 | + 'label' => __( 'Company', 'invoicing' ), |
|
| 45 | + 'type' => 'text', |
|
| 46 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
| 47 | + ), |
|
| 48 | + 'vat_number' => array( |
|
| 49 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 50 | + 'type' => 'text', |
|
| 51 | + ), |
|
| 52 | + 'address' => array( |
|
| 53 | + 'label' => __( 'Address', 'invoicing' ), |
|
| 54 | + 'type' => 'text', |
|
| 55 | + ), |
|
| 56 | + 'city' => array( |
|
| 57 | + 'label' => __( 'City', 'invoicing' ), |
|
| 58 | + 'type' => 'text', |
|
| 59 | + ), |
|
| 60 | + 'country' => array( |
|
| 61 | + 'label' => __( 'Country', 'invoicing' ), |
|
| 62 | + 'type' => 'select', |
|
| 63 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
| 64 | + 'options' => wpinv_get_country_list(), |
|
| 65 | + 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
| 66 | + ), |
|
| 67 | + 'state' => array( |
|
| 68 | + 'label' => __( 'State', 'invoicing' ), |
|
| 69 | + 'type' => 'text', |
|
| 70 | + 'class' => 'getpaid-recalculate-prices-on-change', |
|
| 71 | + ), |
|
| 72 | + 'zip' => array( |
|
| 73 | + 'label' => __( 'Zip', 'invoicing' ), |
|
| 74 | + 'type' => 'text', |
|
| 75 | + ), |
|
| 76 | + 'phone' => array( |
|
| 77 | + 'label' => __( 'Phone', 'invoicing' ), |
|
| 78 | + 'type' => 'text', |
|
| 79 | + ), |
|
| 80 | + ); |
|
| 81 | + |
|
| 82 | + $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
| 83 | + |
|
| 84 | + if ( ! empty( $states ) ) { |
|
| 85 | + $address_fields['state']['type'] = 'select'; |
|
| 86 | + $address_fields['state']['options'] = $states; |
|
| 87 | + $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Maybe remove the VAT field. |
|
| 91 | + if ( ! wpinv_use_taxes() ) { |
|
| 92 | + unset( $address_fields['vat_number'] ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
| 96 | + ?> |
|
| 97 | 97 | |
| 98 | 98 | <style> |
| 99 | 99 | #wpinv-address label { |
@@ -118,19 +118,19 @@ discard block |
||
| 118 | 118 | <div id="getpaid-invoice-email-wrapper" class="d-none"> |
| 119 | 119 | <input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" /> |
| 120 | 120 | <?php |
| 121 | - aui()->input( |
|
| 122 | - array( |
|
| 123 | - 'type' => 'text', |
|
| 124 | - 'id' => 'getpaid-invoice-new-user-email', |
|
| 125 | - 'name' => 'wpinv_email', |
|
| 126 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
| 127 | - 'label_type' => 'vertical', |
|
| 128 | - 'placeholder' => '[email protected]', |
|
| 129 | - 'class' => 'form-control-sm', |
|
| 130 | - ), |
|
| 131 | - true |
|
| 132 | - ); |
|
| 133 | - ?> |
|
| 121 | + aui()->input( |
|
| 122 | + array( |
|
| 123 | + 'type' => 'text', |
|
| 124 | + 'id' => 'getpaid-invoice-new-user-email', |
|
| 125 | + 'name' => 'wpinv_email', |
|
| 126 | + 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
| 127 | + 'label_type' => 'vertical', |
|
| 128 | + 'placeholder' => '[email protected]', |
|
| 129 | + 'class' => 'form-control-sm', |
|
| 130 | + ), |
|
| 131 | + true |
|
| 132 | + ); |
|
| 133 | + ?> |
|
| 134 | 134 | </div> |
| 135 | 135 | </div> |
| 136 | 136 | <div class="col-12 col-sm-6 form-group mb-3 mt-sm-4"> |
@@ -154,39 +154,39 @@ discard block |
||
| 154 | 154 | <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper"> |
| 155 | 155 | <?php |
| 156 | 156 | |
| 157 | - if ( 'select' === $field['type'] ) { |
|
| 158 | - aui()->select( |
|
| 159 | - array( |
|
| 160 | - 'id' => 'wpinv_' . $key, |
|
| 161 | - 'name' => 'wpinv_' . $key, |
|
| 162 | - 'label' => $field['label'], |
|
| 163 | - 'label_type' => 'vertical', |
|
| 164 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
| 165 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
| 166 | - 'value' => $invoice->get( $key, 'edit' ), |
|
| 167 | - 'options' => $field['options'], |
|
| 168 | - 'data-allow-clear' => 'false', |
|
| 169 | - 'select2' => true, |
|
| 170 | - ), |
|
| 171 | - true |
|
| 172 | - ); |
|
| 173 | - } else { |
|
| 174 | - aui()->input( |
|
| 175 | - array( |
|
| 176 | - 'type' => $field['type'], |
|
| 177 | - 'id' => 'wpinv_' . $key, |
|
| 178 | - 'name' => 'wpinv_' . $key, |
|
| 179 | - 'label' => $field['label'], |
|
| 180 | - 'label_type' => 'vertical', |
|
| 181 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
| 182 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
| 183 | - 'value' => $invoice->get( $key, 'edit' ), |
|
| 184 | - ), |
|
| 185 | - true |
|
| 186 | - ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - ?> |
|
| 157 | + if ( 'select' === $field['type'] ) { |
|
| 158 | + aui()->select( |
|
| 159 | + array( |
|
| 160 | + 'id' => 'wpinv_' . $key, |
|
| 161 | + 'name' => 'wpinv_' . $key, |
|
| 162 | + 'label' => $field['label'], |
|
| 163 | + 'label_type' => 'vertical', |
|
| 164 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
| 165 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
| 166 | + 'value' => $invoice->get( $key, 'edit' ), |
|
| 167 | + 'options' => $field['options'], |
|
| 168 | + 'data-allow-clear' => 'false', |
|
| 169 | + 'select2' => true, |
|
| 170 | + ), |
|
| 171 | + true |
|
| 172 | + ); |
|
| 173 | + } else { |
|
| 174 | + aui()->input( |
|
| 175 | + array( |
|
| 176 | + 'type' => $field['type'], |
|
| 177 | + 'id' => 'wpinv_' . $key, |
|
| 178 | + 'name' => 'wpinv_' . $key, |
|
| 179 | + 'label' => $field['label'], |
|
| 180 | + 'label_type' => 'vertical', |
|
| 181 | + 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
| 182 | + 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
| 183 | + 'value' => $invoice->get( $key, 'edit' ), |
|
| 184 | + ), |
|
| 185 | + true |
|
| 186 | + ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + ?> |
|
| 190 | 190 | </div> |
| 191 | 191 | <?php endforeach; ?> |
| 192 | 192 | </div> |
@@ -197,48 +197,48 @@ discard block |
||
| 197 | 197 | <div class="row"> |
| 198 | 198 | <div class="col-12 col-sm-6"> |
| 199 | 199 | <?php |
| 200 | - aui()->select( |
|
| 201 | - array( |
|
| 202 | - 'id' => 'wpinv_template', |
|
| 203 | - 'name' => 'wpinv_template', |
|
| 204 | - 'label' => __( 'Template', 'invoicing' ), |
|
| 205 | - 'label_type' => 'vertical', |
|
| 206 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
| 207 | - 'class' => 'form-control-sm', |
|
| 208 | - 'value' => $invoice->get_template( 'edit' ), |
|
| 209 | - 'options' => array( |
|
| 210 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
| 211 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
| 212 | - ), |
|
| 213 | - 'data-allow-clear' => 'false', |
|
| 214 | - 'select2' => true, |
|
| 215 | - ), |
|
| 216 | - true |
|
| 217 | - ); |
|
| 218 | - ?> |
|
| 200 | + aui()->select( |
|
| 201 | + array( |
|
| 202 | + 'id' => 'wpinv_template', |
|
| 203 | + 'name' => 'wpinv_template', |
|
| 204 | + 'label' => __( 'Template', 'invoicing' ), |
|
| 205 | + 'label_type' => 'vertical', |
|
| 206 | + 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
| 207 | + 'class' => 'form-control-sm', |
|
| 208 | + 'value' => $invoice->get_template( 'edit' ), |
|
| 209 | + 'options' => array( |
|
| 210 | + 'quantity' => __( 'Quantity', 'invoicing' ), |
|
| 211 | + 'hours' => __( 'Hours', 'invoicing' ), |
|
| 212 | + ), |
|
| 213 | + 'data-allow-clear' => 'false', |
|
| 214 | + 'select2' => true, |
|
| 215 | + ), |
|
| 216 | + true |
|
| 217 | + ); |
|
| 218 | + ?> |
|
| 219 | 219 | </div> |
| 220 | 220 | <div class="col-12 col-sm-6"> |
| 221 | 221 | <?php |
| 222 | 222 | |
| 223 | - // Set currency. |
|
| 224 | - aui()->select( |
|
| 225 | - array( |
|
| 226 | - 'id' => 'wpinv_currency', |
|
| 227 | - 'name' => 'wpinv_currency', |
|
| 228 | - 'label' => __( 'Currency', 'invoicing' ), |
|
| 229 | - 'label_type' => 'vertical', |
|
| 230 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
| 231 | - 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
| 232 | - 'value' => $invoice->get_currency( 'edit' ), |
|
| 233 | - 'required' => false, |
|
| 234 | - 'data-allow-clear' => 'false', |
|
| 235 | - 'select2' => true, |
|
| 236 | - 'options' => wpinv_get_currencies(), |
|
| 237 | - ), |
|
| 238 | - true |
|
| 239 | - ); |
|
| 240 | - |
|
| 241 | - ?> |
|
| 223 | + // Set currency. |
|
| 224 | + aui()->select( |
|
| 225 | + array( |
|
| 226 | + 'id' => 'wpinv_currency', |
|
| 227 | + 'name' => 'wpinv_currency', |
|
| 228 | + 'label' => __( 'Currency', 'invoicing' ), |
|
| 229 | + 'label_type' => 'vertical', |
|
| 230 | + 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
| 231 | + 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
|
| 232 | + 'value' => $invoice->get_currency( 'edit' ), |
|
| 233 | + 'required' => false, |
|
| 234 | + 'data-allow-clear' => 'false', |
|
| 235 | + 'select2' => true, |
|
| 236 | + 'options' => wpinv_get_currencies(), |
|
| 237 | + ), |
|
| 238 | + true |
|
| 239 | + ); |
|
| 240 | + |
|
| 241 | + ?> |
|
| 242 | 242 | </div> |
| 243 | 243 | </div> |
| 244 | 244 | |
@@ -248,123 +248,123 @@ discard block |
||
| 248 | 248 | <div class="row"> |
| 249 | 249 | <div class="col-12 col-sm-6"> |
| 250 | 250 | <?php |
| 251 | - aui()->input( |
|
| 252 | - array( |
|
| 253 | - 'type' => 'text', |
|
| 254 | - 'id' => 'wpinv_company_id', |
|
| 255 | - 'name' => 'wpinv_company_id', |
|
| 256 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
| 257 | - 'label_type' => 'vertical', |
|
| 258 | - 'placeholder' => '', |
|
| 259 | - 'class' => 'form-control-sm', |
|
| 260 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
| 261 | - ), |
|
| 262 | - true |
|
| 263 | - ); |
|
| 264 | - ?> |
|
| 251 | + aui()->input( |
|
| 252 | + array( |
|
| 253 | + 'type' => 'text', |
|
| 254 | + 'id' => 'wpinv_company_id', |
|
| 255 | + 'name' => 'wpinv_company_id', |
|
| 256 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
| 257 | + 'label_type' => 'vertical', |
|
| 258 | + 'placeholder' => '', |
|
| 259 | + 'class' => 'form-control-sm', |
|
| 260 | + 'value' => $invoice->get_company_id( 'edit' ), |
|
| 261 | + ), |
|
| 262 | + true |
|
| 263 | + ); |
|
| 264 | + ?> |
|
| 265 | 265 | </div> |
| 266 | 266 | </div> |
| 267 | 267 | |
| 268 | 268 | <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
| 269 | 269 | </div> |
| 270 | 270 | <?php |
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Save meta box data. |
|
| 275 | - * |
|
| 276 | - * @param int $post_id |
|
| 277 | - * @param array $posted the posted data. |
|
| 278 | - */ |
|
| 279 | - public static function save( $post_id, $posted ) { |
|
| 280 | - |
|
| 281 | - // Prepare the invoice. |
|
| 282 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 283 | - |
|
| 284 | - // Load new data. |
|
| 285 | - $invoice->set_props( |
|
| 286 | - array( |
|
| 287 | - 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
| 288 | - 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
| 289 | - 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
| 290 | - 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
| 291 | - 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
| 292 | - 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
| 293 | - 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
| 294 | - 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
| 295 | - 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
| 296 | - 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
| 297 | - 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
| 298 | - 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
| 299 | - 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
| 300 | - 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
| 301 | - 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
| 302 | - 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
| 303 | - 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
| 304 | - 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
| 305 | - 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
| 306 | - 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
| 307 | - 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
| 308 | - 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
| 309 | - ) |
|
| 310 | - ); |
|
| 311 | - |
|
| 312 | - // Discount code. |
|
| 313 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 314 | - |
|
| 315 | - if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
| 316 | - $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 320 | - if ( $discount->exists() ) { |
|
| 321 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 322 | - } else { |
|
| 323 | - $invoice->remove_discount( 'discount_code' ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // Recalculate totals. |
|
| 327 | - $invoice->recalculate_total(); |
|
| 328 | - |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // If we're creating a new user... |
|
| 332 | - if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
| 333 | - |
|
| 334 | - // Attempt to create the user. |
|
| 335 | - $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
| 336 | - |
|
| 337 | - // If successful, update the invoice author. |
|
| 338 | - if ( is_numeric( $user ) ) { |
|
| 339 | - $invoice->set_author( $user ); |
|
| 340 | - } else { |
|
| 341 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - // Do not send new invoice notifications. |
|
| 346 | - $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
| 347 | - |
|
| 348 | - // Save the invoice. |
|
| 349 | - $invoice->save(); |
|
| 350 | - |
|
| 351 | - // Save the user address. |
|
| 352 | - getpaid_save_invoice_user_address( $invoice ); |
|
| 353 | - |
|
| 354 | - // Undo do not send new invoice notifications. |
|
| 355 | - $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
| 356 | - |
|
| 357 | - // (Maybe) send new user notification. |
|
| 358 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 359 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
| 360 | - wp_send_new_user_notifications( $user, 'user' ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
| 364 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - // Fires after an invoice is saved. |
|
| 368 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
| 369 | - } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Save meta box data. |
|
| 275 | + * |
|
| 276 | + * @param int $post_id |
|
| 277 | + * @param array $posted the posted data. |
|
| 278 | + */ |
|
| 279 | + public static function save( $post_id, $posted ) { |
|
| 280 | + |
|
| 281 | + // Prepare the invoice. |
|
| 282 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 283 | + |
|
| 284 | + // Load new data. |
|
| 285 | + $invoice->set_props( |
|
| 286 | + array( |
|
| 287 | + 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
| 288 | + 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
| 289 | + 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
| 290 | + 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
| 291 | + 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
| 292 | + 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
| 293 | + 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
| 294 | + 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
| 295 | + 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
| 296 | + 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
| 297 | + 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
| 298 | + 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
| 299 | + 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
| 300 | + 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
| 301 | + 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
| 302 | + 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
| 303 | + 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
| 304 | + 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
| 305 | + 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
| 306 | + 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
| 307 | + 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
| 308 | + 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
| 309 | + ) |
|
| 310 | + ); |
|
| 311 | + |
|
| 312 | + // Discount code. |
|
| 313 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 314 | + |
|
| 315 | + if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
| 316 | + $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 320 | + if ( $discount->exists() ) { |
|
| 321 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 322 | + } else { |
|
| 323 | + $invoice->remove_discount( 'discount_code' ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // Recalculate totals. |
|
| 327 | + $invoice->recalculate_total(); |
|
| 328 | + |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // If we're creating a new user... |
|
| 332 | + if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
| 333 | + |
|
| 334 | + // Attempt to create the user. |
|
| 335 | + $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
| 336 | + |
|
| 337 | + // If successful, update the invoice author. |
|
| 338 | + if ( is_numeric( $user ) ) { |
|
| 339 | + $invoice->set_author( $user ); |
|
| 340 | + } else { |
|
| 341 | + wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + // Do not send new invoice notifications. |
|
| 346 | + $GLOBALS['wpinv_skip_invoice_notification'] = true; |
|
| 347 | + |
|
| 348 | + // Save the invoice. |
|
| 349 | + $invoice->save(); |
|
| 350 | + |
|
| 351 | + // Save the user address. |
|
| 352 | + getpaid_save_invoice_user_address( $invoice ); |
|
| 353 | + |
|
| 354 | + // Undo do not send new invoice notifications. |
|
| 355 | + $GLOBALS['wpinv_skip_invoice_notification'] = false; |
|
| 356 | + |
|
| 357 | + // (Maybe) send new user notification. |
|
| 358 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 359 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
| 360 | + wp_send_new_user_notifications( $user, 'user' ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
| 364 | + getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + // Fires after an invoice is saved. |
|
| 368 | + do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
| 369 | + } |
|
| 370 | 370 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 10 | +if (!defined('ABSPATH')) { |
|
| 11 | 11 | exit; // Exit if accessed directly |
| 12 | 12 | } |
| 13 | 13 | |
@@ -21,78 +21,78 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @param WP_Post $post |
| 23 | 23 | */ |
| 24 | - public static function output( $post ) { |
|
| 24 | + public static function output($post) { |
|
| 25 | 25 | |
| 26 | 26 | // Prepare the invoice. |
| 27 | - $invoice = new WPInv_Invoice( $post ); |
|
| 28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
| 29 | - $customer = new WP_User( $customer ); |
|
| 30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
| 31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
| 27 | + $invoice = new WPInv_Invoice($post); |
|
| 28 | + $customer = $invoice->exists() ? $invoice->get_user_id('edit') : get_current_user_id(); |
|
| 29 | + $customer = new WP_User($customer); |
|
| 30 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email); |
|
| 31 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
| 32 | 32 | |
| 33 | 33 | // Address fields. |
| 34 | 34 | $address_fields = array( |
| 35 | 35 | 'first_name' => array( |
| 36 | - 'label' => __( 'First Name', 'invoicing' ), |
|
| 36 | + 'label' => __('First Name', 'invoicing'), |
|
| 37 | 37 | 'type' => 'text', |
| 38 | 38 | ), |
| 39 | 39 | 'last_name' => array( |
| 40 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
| 40 | + 'label' => __('Last Name', 'invoicing'), |
|
| 41 | 41 | 'type' => 'text', |
| 42 | 42 | ), |
| 43 | 43 | 'company' => array( |
| 44 | - 'label' => __( 'Company', 'invoicing' ), |
|
| 44 | + 'label' => __('Company', 'invoicing'), |
|
| 45 | 45 | 'type' => 'text', |
| 46 | 46 | 'class' => 'getpaid-recalculate-prices-on-change', |
| 47 | 47 | ), |
| 48 | 48 | 'vat_number' => array( |
| 49 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 49 | + 'label' => __('VAT Number', 'invoicing'), |
|
| 50 | 50 | 'type' => 'text', |
| 51 | 51 | ), |
| 52 | 52 | 'address' => array( |
| 53 | - 'label' => __( 'Address', 'invoicing' ), |
|
| 53 | + 'label' => __('Address', 'invoicing'), |
|
| 54 | 54 | 'type' => 'text', |
| 55 | 55 | ), |
| 56 | 56 | 'city' => array( |
| 57 | - 'label' => __( 'City', 'invoicing' ), |
|
| 57 | + 'label' => __('City', 'invoicing'), |
|
| 58 | 58 | 'type' => 'text', |
| 59 | 59 | ), |
| 60 | 60 | 'country' => array( |
| 61 | - 'label' => __( 'Country', 'invoicing' ), |
|
| 61 | + 'label' => __('Country', 'invoicing'), |
|
| 62 | 62 | 'type' => 'select', |
| 63 | 63 | 'class' => 'getpaid-recalculate-prices-on-change', |
| 64 | 64 | 'options' => wpinv_get_country_list(), |
| 65 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
| 65 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
| 66 | 66 | ), |
| 67 | 67 | 'state' => array( |
| 68 | - 'label' => __( 'State', 'invoicing' ), |
|
| 68 | + 'label' => __('State', 'invoicing'), |
|
| 69 | 69 | 'type' => 'text', |
| 70 | 70 | 'class' => 'getpaid-recalculate-prices-on-change', |
| 71 | 71 | ), |
| 72 | 72 | 'zip' => array( |
| 73 | - 'label' => __( 'Zip', 'invoicing' ), |
|
| 73 | + 'label' => __('Zip', 'invoicing'), |
|
| 74 | 74 | 'type' => 'text', |
| 75 | 75 | ), |
| 76 | 76 | 'phone' => array( |
| 77 | - 'label' => __( 'Phone', 'invoicing' ), |
|
| 77 | + 'label' => __('Phone', 'invoicing'), |
|
| 78 | 78 | 'type' => 'text', |
| 79 | 79 | ), |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
| 82 | + $states = wpinv_get_country_states($invoice->get_country('edit')); |
|
| 83 | 83 | |
| 84 | - if ( ! empty( $states ) ) { |
|
| 84 | + if (!empty($states)) { |
|
| 85 | 85 | $address_fields['state']['type'] = 'select'; |
| 86 | 86 | $address_fields['state']['options'] = $states; |
| 87 | - $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' ); |
|
| 87 | + $address_fields['state']['placeholder'] = __('Choose a state', 'invoicing'); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // Maybe remove the VAT field. |
| 91 | - if ( ! wpinv_use_taxes() ) { |
|
| 92 | - unset( $address_fields['vat_number'] ); |
|
| 91 | + if (!wpinv_use_taxes()) { |
|
| 92 | + unset($address_fields['vat_number']); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice ); |
|
| 95 | + $address_fields = apply_filters('getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice); |
|
| 96 | 96 | ?> |
| 97 | 97 | |
| 98 | 98 | <style> |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | <div class="col-12 col-sm-6"> |
| 107 | 107 | <div id="getpaid-invoice-user-id-wrapper" class="form-group mb-3"> |
| 108 | 108 | <div> |
| 109 | - <label for="post_author_override"><?php esc_html_e( 'Customer', 'invoicing' ); ?></label> |
|
| 109 | + <label for="post_author_override"><?php esc_html_e('Customer', 'invoicing'); ?></label> |
|
| 110 | 110 | </div> |
| 111 | 111 | <div> |
| 112 | - <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>"> |
|
| 113 | - <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html( $display ); ?> </option>) |
|
| 112 | + <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e('Search for a customer by email or name', 'invoicing'); ?>"> |
|
| 113 | + <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html($display); ?> </option>) |
|
| 114 | 114 | </select> |
| 115 | 115 | </div> |
| 116 | 116 | </div> |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | 'type' => 'text', |
| 124 | 124 | 'id' => 'getpaid-invoice-new-user-email', |
| 125 | 125 | 'name' => 'wpinv_email', |
| 126 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
| 126 | + 'label' => __('Email', 'invoicing') . '<span class="required">*</span>', |
|
| 127 | 127 | 'label_type' => 'vertical', |
| 128 | 128 | 'placeholder' => '[email protected]', |
| 129 | 129 | 'class' => 'form-control-sm', |
@@ -134,36 +134,36 @@ discard block |
||
| 134 | 134 | </div> |
| 135 | 135 | </div> |
| 136 | 136 | <div class="col-12 col-sm-6 form-group mb-3 mt-sm-4"> |
| 137 | - <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
|
| 137 | + <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?> |
|
| 138 | 138 | <a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)"> |
| 139 | 139 | <i aria-hidden="true" class="fa fa-refresh"></i> |
| 140 | - <?php esc_html_e( 'Fill User Details', 'invoicing' ); ?> |
|
| 140 | + <?php esc_html_e('Fill User Details', 'invoicing'); ?> |
|
| 141 | 141 | </a> |
| 142 | 142 | <a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)"> |
| 143 | 143 | <i aria-hidden="true" class="fa fa-plus"></i> |
| 144 | - <?php esc_html_e( 'Add New User', 'invoicing' ); ?> |
|
| 144 | + <?php esc_html_e('Add New User', 'invoicing'); ?> |
|
| 145 | 145 | </a> |
| 146 | 146 | <a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)"> |
| 147 | 147 | <i aria-hidden="true" class="fa fa-close"></i> |
| 148 | - <?php esc_html_e( 'Cancel', 'invoicing' ); ?> |
|
| 148 | + <?php esc_html_e('Cancel', 'invoicing'); ?> |
|
| 149 | 149 | </a> |
| 150 | 150 | <?php endif; ?> |
| 151 | 151 | </div> |
| 152 | 152 | |
| 153 | - <?php foreach ( $address_fields as $key => $field ) : ?> |
|
| 154 | - <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper"> |
|
| 153 | + <?php foreach ($address_fields as $key => $field) : ?> |
|
| 154 | + <div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr($key); ?>--wrapper"> |
|
| 155 | 155 | <?php |
| 156 | 156 | |
| 157 | - if ( 'select' === $field['type'] ) { |
|
| 157 | + if ('select' === $field['type']) { |
|
| 158 | 158 | aui()->select( |
| 159 | 159 | array( |
| 160 | 160 | 'id' => 'wpinv_' . $key, |
| 161 | 161 | 'name' => 'wpinv_' . $key, |
| 162 | 162 | 'label' => $field['label'], |
| 163 | 163 | 'label_type' => 'vertical', |
| 164 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
| 165 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
| 166 | - 'value' => $invoice->get( $key, 'edit' ), |
|
| 164 | + 'placeholder' => isset($field['placeholder']) ? $field['placeholder'] : '', |
|
| 165 | + 'class' => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''), |
|
| 166 | + 'value' => $invoice->get($key, 'edit'), |
|
| 167 | 167 | 'options' => $field['options'], |
| 168 | 168 | 'data-allow-clear' => 'false', |
| 169 | 169 | 'select2' => true, |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | 'name' => 'wpinv_' . $key, |
| 179 | 179 | 'label' => $field['label'], |
| 180 | 180 | 'label_type' => 'vertical', |
| 181 | - 'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '', |
|
| 182 | - 'class' => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ), |
|
| 183 | - 'value' => $invoice->get( $key, 'edit' ), |
|
| 181 | + 'placeholder' => isset($field['placeholder']) ? $field['placeholder'] : '', |
|
| 182 | + 'class' => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''), |
|
| 183 | + 'value' => $invoice->get($key, 'edit'), |
|
| 184 | 184 | ), |
| 185 | 185 | true |
| 186 | 186 | ); |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | <?php endforeach; ?> |
| 192 | 192 | </div> |
| 193 | 193 | |
| 194 | - <?php if ( ! apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) : ?> |
|
| 195 | - <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
|
| 194 | + <?php if (!apply_filters('getpaid_use_new_invoice_items_metabox', false)) : ?> |
|
| 195 | + <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?> |
|
| 196 | 196 | |
| 197 | 197 | <div class="row"> |
| 198 | 198 | <div class="col-12 col-sm-6"> |
@@ -201,14 +201,14 @@ discard block |
||
| 201 | 201 | array( |
| 202 | 202 | 'id' => 'wpinv_template', |
| 203 | 203 | 'name' => 'wpinv_template', |
| 204 | - 'label' => __( 'Template', 'invoicing' ), |
|
| 204 | + 'label' => __('Template', 'invoicing'), |
|
| 205 | 205 | 'label_type' => 'vertical', |
| 206 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
| 206 | + 'placeholder' => __('Choose a template', 'invoicing'), |
|
| 207 | 207 | 'class' => 'form-control-sm', |
| 208 | - 'value' => $invoice->get_template( 'edit' ), |
|
| 208 | + 'value' => $invoice->get_template('edit'), |
|
| 209 | 209 | 'options' => array( |
| 210 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
| 211 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
| 210 | + 'quantity' => __('Quantity', 'invoicing'), |
|
| 211 | + 'hours' => __('Hours', 'invoicing'), |
|
| 212 | 212 | ), |
| 213 | 213 | 'data-allow-clear' => 'false', |
| 214 | 214 | 'select2' => true, |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | array( |
| 226 | 226 | 'id' => 'wpinv_currency', |
| 227 | 227 | 'name' => 'wpinv_currency', |
| 228 | - 'label' => __( 'Currency', 'invoicing' ), |
|
| 228 | + 'label' => __('Currency', 'invoicing'), |
|
| 229 | 229 | 'label_type' => 'vertical', |
| 230 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
| 230 | + 'placeholder' => __('Select Invoice Currency', 'invoicing'), |
|
| 231 | 231 | 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
| 232 | - 'value' => $invoice->get_currency( 'edit' ), |
|
| 232 | + 'value' => $invoice->get_currency('edit'), |
|
| 233 | 233 | 'required' => false, |
| 234 | 234 | 'data-allow-clear' => 'false', |
| 235 | 235 | 'select2' => true, |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | </div> |
| 243 | 243 | </div> |
| 244 | 244 | |
| 245 | - <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
|
| 245 | + <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?> |
|
| 246 | 246 | <?php endif; ?> |
| 247 | 247 | |
| 248 | 248 | <div class="row"> |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | 'type' => 'text', |
| 254 | 254 | 'id' => 'wpinv_company_id', |
| 255 | 255 | 'name' => 'wpinv_company_id', |
| 256 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
| 256 | + 'label' => __('Company ID', 'invoicing'), |
|
| 257 | 257 | 'label_type' => 'vertical', |
| 258 | 258 | 'placeholder' => '', |
| 259 | 259 | 'class' => 'form-control-sm', |
| 260 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
| 260 | + 'value' => $invoice->get_company_id('edit'), |
|
| 261 | 261 | ), |
| 262 | 262 | true |
| 263 | 263 | ); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | </div> |
| 266 | 266 | </div> |
| 267 | 267 | |
| 268 | - <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
|
| 268 | + <?php do_action('getpaid_after_metabox_invoice_address', $invoice); ?> |
|
| 269 | 269 | </div> |
| 270 | 270 | <?php |
| 271 | 271 | } |
@@ -276,51 +276,51 @@ discard block |
||
| 276 | 276 | * @param int $post_id |
| 277 | 277 | * @param array $posted the posted data. |
| 278 | 278 | */ |
| 279 | - public static function save( $post_id, $posted ) { |
|
| 279 | + public static function save($post_id, $posted) { |
|
| 280 | 280 | |
| 281 | 281 | // Prepare the invoice. |
| 282 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 282 | + $invoice = new WPInv_Invoice($post_id); |
|
| 283 | 283 | |
| 284 | 284 | // Load new data. |
| 285 | 285 | $invoice->set_props( |
| 286 | 286 | array( |
| 287 | - 'template' => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null, |
|
| 288 | - 'email_cc' => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null, |
|
| 289 | - 'disable_taxes' => ! empty( $posted['disable_taxes'] ), |
|
| 290 | - 'currency' => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null, |
|
| 291 | - 'gateway' => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null, |
|
| 292 | - 'address' => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null, |
|
| 293 | - 'vat_number' => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null, |
|
| 294 | - 'company' => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null, |
|
| 295 | - 'company_id' => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null, |
|
| 296 | - 'zip' => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null, |
|
| 297 | - 'state' => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null, |
|
| 298 | - 'city' => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null, |
|
| 299 | - 'country' => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null, |
|
| 300 | - 'phone' => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null, |
|
| 301 | - 'first_name' => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null, |
|
| 302 | - 'last_name' => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null, |
|
| 303 | - 'author' => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null, |
|
| 304 | - 'date_created' => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null, |
|
| 305 | - 'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null, |
|
| 306 | - 'due_date' => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null, |
|
| 307 | - 'number' => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null, |
|
| 308 | - 'status' => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null, |
|
| 287 | + 'template' => isset($posted['wpinv_template']) ? wpinv_clean($posted['wpinv_template']) : null, |
|
| 288 | + 'email_cc' => isset($posted['wpinv_cc']) ? wpinv_clean($posted['wpinv_cc']) : null, |
|
| 289 | + 'disable_taxes' => !empty($posted['disable_taxes']), |
|
| 290 | + 'currency' => isset($posted['wpinv_currency']) ? wpinv_clean($posted['wpinv_currency']) : null, |
|
| 291 | + 'gateway' => ($invoice->needs_payment() && isset($posted['wpinv_gateway'])) ? wpinv_clean($posted['wpinv_gateway']) : null, |
|
| 292 | + 'address' => isset($posted['wpinv_address']) ? wpinv_clean($posted['wpinv_address']) : null, |
|
| 293 | + 'vat_number' => isset($posted['wpinv_vat_number']) ? wpinv_clean($posted['wpinv_vat_number']) : null, |
|
| 294 | + 'company' => isset($posted['wpinv_company']) ? wpinv_clean($posted['wpinv_company']) : null, |
|
| 295 | + 'company_id' => isset($posted['wpinv_company_id']) ? wpinv_clean($posted['wpinv_company_id']) : null, |
|
| 296 | + 'zip' => isset($posted['wpinv_zip']) ? wpinv_clean($posted['wpinv_zip']) : null, |
|
| 297 | + 'state' => isset($posted['wpinv_state']) ? wpinv_clean($posted['wpinv_state']) : null, |
|
| 298 | + 'city' => isset($posted['wpinv_city']) ? wpinv_clean($posted['wpinv_city']) : null, |
|
| 299 | + 'country' => isset($posted['wpinv_country']) ? wpinv_clean($posted['wpinv_country']) : null, |
|
| 300 | + 'phone' => isset($posted['wpinv_phone']) ? wpinv_clean($posted['wpinv_phone']) : null, |
|
| 301 | + 'first_name' => isset($posted['wpinv_first_name']) ? wpinv_clean($posted['wpinv_first_name']) : null, |
|
| 302 | + 'last_name' => isset($posted['wpinv_last_name']) ? wpinv_clean($posted['wpinv_last_name']) : null, |
|
| 303 | + 'author' => isset($posted['post_author_override']) ? wpinv_clean($posted['post_author_override']) : null, |
|
| 304 | + 'date_created' => isset($posted['date_created']) ? wpinv_clean($posted['date_created']) : null, |
|
| 305 | + 'date_completed' => isset($posted['wpinv_date_completed']) ? wpinv_clean($posted['wpinv_date_completed']) : null, |
|
| 306 | + 'due_date' => isset($posted['wpinv_due_date']) ? wpinv_clean($posted['wpinv_due_date']) : null, |
|
| 307 | + 'number' => isset($posted['wpinv_number']) ? wpinv_clean($posted['wpinv_number']) : null, |
|
| 308 | + 'status' => isset($posted['wpinv_status']) ? wpinv_clean($posted['wpinv_status']) : null, |
|
| 309 | 309 | ) |
| 310 | 310 | ); |
| 311 | 311 | |
| 312 | 312 | // Discount code. |
| 313 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 313 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
| 314 | 314 | |
| 315 | - if ( isset( $posted['wpinv_discount_code'] ) ) { |
|
| 316 | - $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) ); |
|
| 315 | + if (isset($posted['wpinv_discount_code'])) { |
|
| 316 | + $invoice->set_discount_code(wpinv_clean($posted['wpinv_discount_code'])); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 320 | - if ( $discount->exists() ) { |
|
| 321 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 319 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 320 | + if ($discount->exists()) { |
|
| 321 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 322 | 322 | } else { |
| 323 | - $invoice->remove_discount( 'discount_code' ); |
|
| 323 | + $invoice->remove_discount('discount_code'); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | // Recalculate totals. |
@@ -329,16 +329,16 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | // If we're creating a new user... |
| 332 | - if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) { |
|
| 332 | + if (!empty($posted['wpinv_new_user']) && is_email(stripslashes($posted['wpinv_email']))) { |
|
| 333 | 333 | |
| 334 | 334 | // Attempt to create the user. |
| 335 | - $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() ); |
|
| 335 | + $user = wpinv_create_user(sanitize_email(stripslashes($posted['wpinv_email'])), $invoice->get_first_name() . $invoice->get_last_name()); |
|
| 336 | 336 | |
| 337 | 337 | // If successful, update the invoice author. |
| 338 | - if ( is_numeric( $user ) ) { |
|
| 339 | - $invoice->set_author( $user ); |
|
| 338 | + if (is_numeric($user)) { |
|
| 339 | + $invoice->set_author($user); |
|
| 340 | 340 | } else { |
| 341 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
| 341 | + wpinv_error_log($user->get_error_message(), __('Invoice add new user', 'invoicing'), __FILE__, __LINE__); |
|
| 342 | 342 | } |
| 343 | 343 | } |
| 344 | 344 | |
@@ -349,22 +349,22 @@ discard block |
||
| 349 | 349 | $invoice->save(); |
| 350 | 350 | |
| 351 | 351 | // Save the user address. |
| 352 | - getpaid_save_invoice_user_address( $invoice ); |
|
| 352 | + getpaid_save_invoice_user_address($invoice); |
|
| 353 | 353 | |
| 354 | 354 | // Undo do not send new invoice notifications. |
| 355 | 355 | $GLOBALS['wpinv_skip_invoice_notification'] = false; |
| 356 | 356 | |
| 357 | 357 | // (Maybe) send new user notification. |
| 358 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 359 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
| 360 | - wp_send_new_user_notifications( $user, 'user' ); |
|
| 358 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
| 359 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) { |
|
| 360 | + wp_send_new_user_notifications($user, 'user'); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
| 364 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
| 363 | + if (!empty($posted['send_to_customer']) && !$invoice->is_draft()) { |
|
| 364 | + getpaid()->get('invoice_emails')->user_invoice($invoice, true); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | // Fires after an invoice is saved. |
| 368 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
| 368 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
| 369 | 369 | } |
| 370 | 370 | } |
@@ -12,184 +12,184 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Checkout { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var GetPaid_Payment_Form_Submission |
|
| 17 | - */ |
|
| 18 | - protected $payment_form_submission; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | - */ |
|
| 25 | - public function __construct( $submission ) { |
|
| 26 | - $this->payment_form_submission = $submission; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Processes the checkout. |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - public function process_checkout() { |
|
| 34 | - |
|
| 35 | - // Validate the submission. |
|
| 36 | - $this->validate_submission(); |
|
| 37 | - |
|
| 38 | - // Prepare the invoice. |
|
| 39 | - $items = $this->get_submission_items(); |
|
| 40 | - $invoice = $this->get_submission_invoice(); |
|
| 41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
| 43 | - |
|
| 44 | - $this->prepare_billing_info( $invoice ); |
|
| 45 | - |
|
| 46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 47 | - |
|
| 48 | - // Save the invoice. |
|
| 49 | - $invoice->set_is_viewed( true ); |
|
| 50 | - $invoice->recalculate_total(); |
|
| 15 | + /** |
|
| 16 | + * @var GetPaid_Payment_Form_Submission |
|
| 17 | + */ |
|
| 18 | + protected $payment_form_submission; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | + */ |
|
| 25 | + public function __construct( $submission ) { |
|
| 26 | + $this->payment_form_submission = $submission; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Processes the checkout. |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + public function process_checkout() { |
|
| 34 | + |
|
| 35 | + // Validate the submission. |
|
| 36 | + $this->validate_submission(); |
|
| 37 | + |
|
| 38 | + // Prepare the invoice. |
|
| 39 | + $items = $this->get_submission_items(); |
|
| 40 | + $invoice = $this->get_submission_invoice(); |
|
| 41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
| 43 | + |
|
| 44 | + $this->prepare_billing_info( $invoice ); |
|
| 45 | + |
|
| 46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 47 | + |
|
| 48 | + // Save the invoice. |
|
| 49 | + $invoice->set_is_viewed( true ); |
|
| 50 | + $invoice->recalculate_total(); |
|
| 51 | 51 | $invoice->save(); |
| 52 | 52 | |
| 53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 54 | 54 | |
| 55 | - // Send to the gateway. |
|
| 56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 57 | - } |
|
| 55 | + // Send to the gateway. |
|
| 56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Validates the submission. |
|
| 61 | - * |
|
| 62 | - */ |
|
| 63 | - protected function validate_submission() { |
|
| 59 | + /** |
|
| 60 | + * Validates the submission. |
|
| 61 | + * |
|
| 62 | + */ |
|
| 63 | + protected function validate_submission() { |
|
| 64 | 64 | |
| 65 | - $submission = $this->payment_form_submission; |
|
| 66 | - $data = $submission->get_data(); |
|
| 65 | + $submission = $this->payment_form_submission; |
|
| 66 | + $data = $submission->get_data(); |
|
| 67 | 67 | |
| 68 | - // Do we have an error? |
|
| 68 | + // Do we have an error? |
|
| 69 | 69 | if ( ! empty( $submission->last_error ) ) { |
| 70 | - wp_send_json_error( $submission->last_error ); |
|
| 70 | + wp_send_json_error( $submission->last_error ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - // We need a billing email. |
|
| 73 | + // We need a billing email. |
|
| 74 | 74 | if ( ! $submission->has_billing_email() ) { |
| 75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
| 76 | - } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 81 | - } |
|
| 78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - // Ensure the gateway is active. |
|
| 84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 86 | - } |
|
| 83 | + // Ensure the gateway is active. |
|
| 84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - // Clear any existing errors. |
|
| 89 | - wpinv_clear_errors(); |
|
| 88 | + // Clear any existing errors. |
|
| 89 | + wpinv_clear_errors(); |
|
| 90 | 90 | |
| 91 | - // Allow themes and plugins to hook to errors |
|
| 92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 91 | + // Allow themes and plugins to hook to errors |
|
| 92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 93 | 93 | |
| 94 | - // Do we have any errors? |
|
| 94 | + // Do we have any errors? |
|
| 95 | 95 | if ( wpinv_get_errors() ) { |
| 96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Retrieves submission items. |
|
| 103 | - * |
|
| 104 | - * @return GetPaid_Form_Item[] |
|
| 105 | - */ |
|
| 106 | - protected function get_submission_items() { |
|
| 101 | + /** |
|
| 102 | + * Retrieves submission items. |
|
| 103 | + * |
|
| 104 | + * @return GetPaid_Form_Item[] |
|
| 105 | + */ |
|
| 106 | + protected function get_submission_items() { |
|
| 107 | 107 | |
| 108 | - $items = $this->payment_form_submission->get_items(); |
|
| 108 | + $items = $this->payment_form_submission->get_items(); |
|
| 109 | 109 | |
| 110 | 110 | // Ensure that we have items. |
| 111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
| 112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
| 113 | - } |
|
| 114 | - |
|
| 115 | - return $items; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Retrieves submission invoice. |
|
| 120 | - * |
|
| 121 | - * @return WPInv_Invoice |
|
| 122 | - */ |
|
| 123 | - protected function get_submission_invoice() { |
|
| 124 | - $submission = $this->payment_form_submission; |
|
| 125 | - |
|
| 126 | - if ( ! $submission->has_invoice() ) { |
|
| 127 | - $invoice = new WPInv_Invoice(); |
|
| 128 | - $invoice->set_created_via( 'payment_form' ); |
|
| 129 | - return $invoice; |
|
| 130 | 113 | } |
| 131 | 114 | |
| 132 | - $invoice = $submission->get_invoice(); |
|
| 115 | + return $items; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Retrieves submission invoice. |
|
| 120 | + * |
|
| 121 | + * @return WPInv_Invoice |
|
| 122 | + */ |
|
| 123 | + protected function get_submission_invoice() { |
|
| 124 | + $submission = $this->payment_form_submission; |
|
| 133 | 125 | |
| 134 | - // Make sure that it is neither paid or refunded. |
|
| 135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 137 | - } |
|
| 126 | + if ( ! $submission->has_invoice() ) { |
|
| 127 | + $invoice = new WPInv_Invoice(); |
|
| 128 | + $invoice->set_created_via( 'payment_form' ); |
|
| 129 | + return $invoice; |
|
| 130 | + } |
|
| 138 | 131 | |
| 139 | - return $invoice; |
|
| 140 | - } |
|
| 132 | + $invoice = $submission->get_invoice(); |
|
| 141 | 133 | |
| 142 | - /** |
|
| 143 | - * Processes the submission invoice. |
|
| 144 | - * |
|
| 145 | - * @param WPInv_Invoice $invoice |
|
| 146 | - * @param GetPaid_Form_Item[] $items |
|
| 147 | - * @return WPInv_Invoice |
|
| 148 | - */ |
|
| 149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 134 | + // Make sure that it is neither paid or refunded. |
|
| 135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 137 | + } |
|
| 150 | 138 | |
| 151 | - $submission = $this->payment_form_submission; |
|
| 139 | + return $invoice; |
|
| 140 | + } |
|
| 152 | 141 | |
| 153 | - // Set-up the invoice details. |
|
| 154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 142 | + /** |
|
| 143 | + * Processes the submission invoice. |
|
| 144 | + * |
|
| 145 | + * @param WPInv_Invoice $invoice |
|
| 146 | + * @param GetPaid_Form_Item[] $items |
|
| 147 | + * @return WPInv_Invoice |
|
| 148 | + */ |
|
| 149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
| 150 | + |
|
| 151 | + $submission = $this->payment_form_submission; |
|
| 152 | + |
|
| 153 | + // Set-up the invoice details. |
|
| 154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 157 | 157 | $invoice->set_items( $items ); |
| 158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
| 159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
| 160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
| 162 | - $invoice->set_currency( $submission->get_currency() ); |
|
| 160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
| 161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
| 162 | + $invoice->set_currency( $submission->get_currency() ); |
|
| 163 | 163 | |
| 164 | - if ( $submission->has_shipping() ) { |
|
| 165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
| 166 | - } |
|
| 164 | + if ( $submission->has_shipping() ) { |
|
| 165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 170 | 170 | |
| 171 | - if ( $submission->has_discount_code() ) { |
|
| 171 | + if ( $submission->has_discount_code() ) { |
|
| 172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
| 173 | - } |
|
| 174 | - |
|
| 175 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 176 | - return $invoice; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Retrieves the submission's customer. |
|
| 181 | - * |
|
| 182 | - * @return int The customer id. |
|
| 183 | - */ |
|
| 184 | - protected function get_submission_customer() { |
|
| 185 | - $submission = $this->payment_form_submission; |
|
| 186 | - |
|
| 187 | - // If this is an existing invoice... |
|
| 188 | - if ( $submission->has_invoice() ) { |
|
| 189 | - return $submission->get_invoice()->get_user_id(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // (Maybe) create the user. |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + getpaid_maybe_add_default_address( $invoice ); |
|
| 176 | + return $invoice; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Retrieves the submission's customer. |
|
| 181 | + * |
|
| 182 | + * @return int The customer id. |
|
| 183 | + */ |
|
| 184 | + protected function get_submission_customer() { |
|
| 185 | + $submission = $this->payment_form_submission; |
|
| 186 | + |
|
| 187 | + // If this is an existing invoice... |
|
| 188 | + if ( $submission->has_invoice() ) { |
|
| 189 | + return $submission->get_invoice()->get_user_id(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // (Maybe) create the user. |
|
| 193 | 193 | $user = get_current_user_id(); |
| 194 | 194 | |
| 195 | 195 | if ( empty( $user ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | if ( empty( $user ) ) { |
| 200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
| 201 | - $name = implode( '', array_filter( $name ) ); |
|
| 200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
| 201 | + $name = implode( '', array_filter( $name ) ); |
|
| 202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
| 203 | 203 | |
| 204 | - // (Maybe) send new user notification. |
|
| 205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
| 207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
| 208 | - } |
|
| 209 | - } |
|
| 204 | + // (Maybe) send new user notification. |
|
| 205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
| 207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | if ( is_wp_error( $user ) ) { |
| 212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | if ( is_numeric( $user ) ) { |
| 216 | 216 | return $user; |
| 217 | - } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - return $user->ID; |
|
| 219 | + return $user->ID; |
|
| 220 | 220 | |
| 221 | - } |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 223 | + /** |
|
| 224 | 224 | * Prepares submission data for saving to the database. |
| 225 | 225 | * |
| 226 | - * @return array |
|
| 226 | + * @return array |
|
| 227 | 227 | */ |
| 228 | 228 | public function prepare_submission_data_for_saving() { |
| 229 | 229 | |
| 230 | - $submission = $this->payment_form_submission; |
|
| 230 | + $submission = $this->payment_form_submission; |
|
| 231 | 231 | |
| 232 | - // Prepared submission details. |
|
| 232 | + // Prepared submission details. |
|
| 233 | 233 | $prepared = array( |
| 234 | - 'all' => array(), |
|
| 235 | - 'meta' => array(), |
|
| 236 | - ); |
|
| 234 | + 'all' => array(), |
|
| 235 | + 'meta' => array(), |
|
| 236 | + ); |
|
| 237 | 237 | |
| 238 | 238 | // Raw submission details. |
| 239 | - $data = $submission->get_data(); |
|
| 239 | + $data = $submission->get_data(); |
|
| 240 | 240 | |
| 241 | - // Loop through the submitted details. |
|
| 241 | + // Loop through the submitted details. |
|
| 242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
| 243 | 243 | |
| 244 | - // Skip premade fields. |
|
| 244 | + // Skip premade fields. |
|
| 245 | 245 | if ( ! empty( $field['premade'] ) ) { |
| 246 | 246 | continue; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - // Ensure address is provided. |
|
| 250 | - if ( 'address' === $field['type'] ) { |
|
| 249 | + // Ensure address is provided. |
|
| 250 | + if ( 'address' === $field['type'] ) { |
|
| 251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
| 252 | 252 | |
| 253 | - foreach ( $field['fields'] as $address_field ) { |
|
| 253 | + foreach ( $field['fields'] as $address_field ) { |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - } |
|
| 255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | 261 | // If it is required and not set, abort. |
| 262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
| 266 | 266 | // Handle misc fields. |
| 267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
| 268 | 268 | |
| 269 | - // Uploads. |
|
| 270 | - if ( 'file_upload' === $field['type'] ) { |
|
| 271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
| 269 | + // Uploads. |
|
| 270 | + if ( 'file_upload' === $field['type'] ) { |
|
| 271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
| 272 | 272 | |
| 273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
| 274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
| 275 | - } |
|
| 273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
| 274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - $value = array(); |
|
| 277 | + $value = array(); |
|
| 278 | 278 | |
| 279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
| 280 | - $value[] = sprintf( |
|
| 281 | - '<a href="%s" target="_blank">%s</a>', |
|
| 282 | - esc_url_raw( $url ), |
|
| 283 | - esc_html( $name ) |
|
| 284 | - ); |
|
| 285 | - } |
|
| 279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
| 280 | + $value[] = sprintf( |
|
| 281 | + '<a href="%s" target="_blank">%s</a>', |
|
| 282 | + esc_url_raw( $url ), |
|
| 283 | + esc_html( $name ) |
|
| 284 | + ); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - $value = implode( ' | ', $value ); |
|
| 287 | + $value = implode( ' | ', $value ); |
|
| 288 | 288 | |
| 289 | - } elseif ( 'checkbox' === $field['type'] ) { |
|
| 290 | - $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
| 291 | - } else { |
|
| 292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
| 293 | - } |
|
| 289 | + } elseif ( 'checkbox' === $field['type'] ) { |
|
| 290 | + $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
| 291 | + } else { |
|
| 292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | 295 | $label = $field['id']; |
| 296 | 296 | |
@@ -298,192 +298,192 @@ discard block |
||
| 298 | 298 | $label = $field['label']; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
| 302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 303 | - } |
|
| 304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
| 302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 303 | + } |
|
| 304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 305 | 305 | |
| 306 | 306 | } |
| 307 | - } |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - return $prepared; |
|
| 309 | + return $prepared; |
|
| 310 | 310 | |
| 311 | - } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 313 | + /** |
|
| 314 | 314 | * Retrieves address details. |
| 315 | 315 | * |
| 316 | - * @return array |
|
| 317 | - * @param WPInv_Invoice $invoice |
|
| 318 | - * @param string $type |
|
| 316 | + * @return array |
|
| 317 | + * @param WPInv_Invoice $invoice |
|
| 318 | + * @param string $type |
|
| 319 | 319 | */ |
| 320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
| 321 | 321 | |
| 322 | - $data = $this->payment_form_submission->get_data(); |
|
| 323 | - $type = sanitize_key( $type ); |
|
| 324 | - $address = array(); |
|
| 325 | - $prepared = array(); |
|
| 322 | + $data = $this->payment_form_submission->get_data(); |
|
| 323 | + $type = sanitize_key( $type ); |
|
| 324 | + $address = array(); |
|
| 325 | + $prepared = array(); |
|
| 326 | 326 | |
| 327 | - if ( ! empty( $data[ $type ] ) ) { |
|
| 328 | - $address = $data[ $type ]; |
|
| 329 | - } |
|
| 327 | + if ( ! empty( $data[ $type ] ) ) { |
|
| 328 | + $address = $data[ $type ]; |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - // Clean address details. |
|
| 332 | - foreach ( $address as $key => $value ) { |
|
| 333 | - $key = sanitize_key( $key ); |
|
| 334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
| 335 | - $value = wpinv_clean( $value ); |
|
| 336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 337 | - } |
|
| 331 | + // Clean address details. |
|
| 332 | + foreach ( $address as $key => $value ) { |
|
| 333 | + $key = sanitize_key( $key ); |
|
| 334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
| 335 | + $value = wpinv_clean( $value ); |
|
| 336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - // Filter address details. |
|
| 340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 339 | + // Filter address details. |
|
| 340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 341 | 341 | |
| 342 | - // Remove non-whitelisted values. |
|
| 343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 342 | + // Remove non-whitelisted values. |
|
| 343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 344 | 344 | |
| 345 | - } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - /** |
|
| 347 | + /** |
|
| 348 | 348 | * Prepares the billing details. |
| 349 | 349 | * |
| 350 | - * @return array |
|
| 351 | - * @param WPInv_Invoice $invoice |
|
| 350 | + * @return array |
|
| 351 | + * @param WPInv_Invoice $invoice |
|
| 352 | 352 | */ |
| 353 | 353 | protected function prepare_billing_info( &$invoice ) { |
| 354 | 354 | |
| 355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 356 | 356 | |
| 357 | - // Update the invoice with the billing details. |
|
| 358 | - $invoice->set_props( $billing_address ); |
|
| 357 | + // Update the invoice with the billing details. |
|
| 358 | + $invoice->set_props( $billing_address ); |
|
| 359 | 359 | |
| 360 | - } |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - /** |
|
| 362 | + /** |
|
| 363 | 363 | * Prepares the shipping details. |
| 364 | 364 | * |
| 365 | - * @return array |
|
| 366 | - * @param WPInv_Invoice $invoice |
|
| 365 | + * @return array |
|
| 366 | + * @param WPInv_Invoice $invoice |
|
| 367 | 367 | */ |
| 368 | 368 | protected function prepare_shipping_info( $invoice ) { |
| 369 | 369 | |
| 370 | - $data = $this->payment_form_submission->get_data(); |
|
| 370 | + $data = $this->payment_form_submission->get_data(); |
|
| 371 | 371 | |
| 372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
| 373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 374 | - } |
|
| 372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
| 373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 377 | 377 | |
| 378 | - } |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * Confirms the submission is valid and send users to the gateway. |
|
| 382 | - * |
|
| 383 | - * @param WPInv_Invoice $invoice |
|
| 384 | - * @param array $prepared_payment_form_data |
|
| 385 | - * @param array $shipping |
|
| 386 | - */ |
|
| 387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 380 | + /** |
|
| 381 | + * Confirms the submission is valid and send users to the gateway. |
|
| 382 | + * |
|
| 383 | + * @param WPInv_Invoice $invoice |
|
| 384 | + * @param array $prepared_payment_form_data |
|
| 385 | + * @param array $shipping |
|
| 386 | + */ |
|
| 387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 388 | 388 | |
| 389 | - // Ensure the invoice exists. |
|
| 389 | + // Ensure the invoice exists. |
|
| 390 | 390 | if ( ! $invoice->exists() ) { |
| 391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - // Save payment form data. |
|
| 395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 394 | + // Save payment form data. |
|
| 395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
| 397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
| 398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
| 398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 399 | 399 | |
| 400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
| 401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
| 402 | - } |
|
| 400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
| 401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
| 405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
| 406 | - } |
|
| 407 | - } |
|
| 404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
| 405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - // Save payment form data. |
|
| 410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
| 409 | + // Save payment form data. |
|
| 410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
| 411 | 411 | if ( ! empty( $shipping ) ) { |
| 412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
| 413 | - } |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | - // Backwards compatibility. |
|
| 415 | + // Backwards compatibility. |
|
| 416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
| 417 | 417 | |
| 418 | - try { |
|
| 419 | - $this->process_payment( $invoice ); |
|
| 420 | - } catch ( Exception $e ) { |
|
| 421 | - wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
| 422 | - } |
|
| 418 | + try { |
|
| 419 | + $this->process_payment( $invoice ); |
|
| 420 | + } catch ( Exception $e ) { |
|
| 421 | + wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | 424 | // If we are here, there was an error. |
| 425 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 425 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 426 | 426 | |
| 427 | - } |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - /** |
|
| 430 | - * Processes the actual payment. |
|
| 431 | - * |
|
| 432 | - * @param WPInv_Invoice $invoice |
|
| 433 | - */ |
|
| 434 | - protected function process_payment( $invoice ) { |
|
| 429 | + /** |
|
| 430 | + * Processes the actual payment. |
|
| 431 | + * |
|
| 432 | + * @param WPInv_Invoice $invoice |
|
| 433 | + */ |
|
| 434 | + protected function process_payment( $invoice ) { |
|
| 435 | 435 | |
| 436 | - // Clear any checkout errors. |
|
| 437 | - wpinv_clear_errors(); |
|
| 436 | + // Clear any checkout errors. |
|
| 437 | + wpinv_clear_errors(); |
|
| 438 | 438 | |
| 439 | - // No need to send free invoices to the gateway. |
|
| 440 | - if ( $invoice->is_free() ) { |
|
| 441 | - $this->process_free_payment( $invoice ); |
|
| 442 | - } |
|
| 439 | + // No need to send free invoices to the gateway. |
|
| 440 | + if ( $invoice->is_free() ) { |
|
| 441 | + $this->process_free_payment( $invoice ); |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | - $submission = $this->payment_form_submission; |
|
| 444 | + $submission = $this->payment_form_submission; |
|
| 445 | 445 | |
| 446 | - // Fires before sending to the gateway. |
|
| 447 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 446 | + // Fires before sending to the gateway. |
|
| 447 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 448 | 448 | |
| 449 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 450 | - $submission_data = $submission->get_data(); |
|
| 451 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 452 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 449 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 450 | + $submission_data = $submission->get_data(); |
|
| 451 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 452 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 453 | 453 | |
| 454 | - // Validate the currency. |
|
| 455 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 456 | - wpinv_set_error( 'invalid_currency' ); |
|
| 457 | - } |
|
| 454 | + // Validate the currency. |
|
| 455 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 456 | + wpinv_set_error( 'invalid_currency' ); |
|
| 457 | + } |
|
| 458 | 458 | |
| 459 | - // Check to see if we have any errors. |
|
| 460 | - if ( wpinv_get_errors() ) { |
|
| 461 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 462 | - } |
|
| 459 | + // Check to see if we have any errors. |
|
| 460 | + if ( wpinv_get_errors() ) { |
|
| 461 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - // Send info to the gateway for payment processing |
|
| 465 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 464 | + // Send info to the gateway for payment processing |
|
| 465 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 466 | 466 | |
| 467 | - // Backwards compatibility. |
|
| 468 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 467 | + // Backwards compatibility. |
|
| 468 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 469 | 469 | |
| 470 | - } |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | - /** |
|
| 473 | - * Marks the invoice as paid in case the checkout is free. |
|
| 474 | - * |
|
| 475 | - * @param WPInv_Invoice $invoice |
|
| 476 | - */ |
|
| 477 | - protected function process_free_payment( $invoice ) { |
|
| 472 | + /** |
|
| 473 | + * Marks the invoice as paid in case the checkout is free. |
|
| 474 | + * |
|
| 475 | + * @param WPInv_Invoice $invoice |
|
| 476 | + */ |
|
| 477 | + protected function process_free_payment( $invoice ) { |
|
| 478 | 478 | |
| 479 | - $invoice->set_gateway( 'none' ); |
|
| 480 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 481 | - $invoice->mark_paid(); |
|
| 482 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 479 | + $invoice->set_gateway( 'none' ); |
|
| 480 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 481 | + $invoice->mark_paid(); |
|
| 482 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 483 | 483 | |
| 484 | - } |
|
| 484 | + } |
|
| 485 | 485 | |
| 486 | - /** |
|
| 486 | + /** |
|
| 487 | 487 | * Sends a redrect response to payment details. |
| 488 | 488 | * |
| 489 | 489 | */ |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
| 24 | 24 | */ |
| 25 | - public function __construct( $submission ) { |
|
| 25 | + public function __construct($submission) { |
|
| 26 | 26 | $this->payment_form_submission = $submission; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
| 38 | 38 | // Prepare the invoice. |
| 39 | 39 | $items = $this->get_submission_items(); |
| 40 | 40 | $invoice = $this->get_submission_invoice(); |
| 41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
| 42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
| 43 | 43 | |
| 44 | - $this->prepare_billing_info( $invoice ); |
|
| 44 | + $this->prepare_billing_info($invoice); |
|
| 45 | 45 | |
| 46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
| 47 | 47 | |
| 48 | 48 | // Save the invoice. |
| 49 | - $invoice->set_is_viewed( true ); |
|
| 49 | + $invoice->set_is_viewed(true); |
|
| 50 | 50 | $invoice->recalculate_total(); |
| 51 | 51 | $invoice->save(); |
| 52 | 52 | |
| 53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
| 54 | 54 | |
| 55 | 55 | // Send to the gateway. |
| 56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
| 66 | 66 | $data = $submission->get_data(); |
| 67 | 67 | |
| 68 | 68 | // Do we have an error? |
| 69 | - if ( ! empty( $submission->last_error ) ) { |
|
| 70 | - wp_send_json_error( $submission->last_error ); |
|
| 69 | + if (!empty($submission->last_error)) { |
|
| 70 | + wp_send_json_error($submission->last_error); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // We need a billing email. |
| 74 | - if ( ! $submission->has_billing_email() ) { |
|
| 75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
| 74 | + if (!$submission->has_billing_email()) { |
|
| 75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
| 79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
| 80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // Ensure the gateway is active. |
| 84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
| 85 | + wp_send_json_error(__('The selected payment gateway is not active', 'invoicing')); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Clear any existing errors. |
| 89 | 89 | wpinv_clear_errors(); |
| 90 | 90 | |
| 91 | 91 | // Allow themes and plugins to hook to errors |
| 92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
| 93 | 93 | |
| 94 | 94 | // Do we have any errors? |
| 95 | - if ( wpinv_get_errors() ) { |
|
| 96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
| 95 | + if (wpinv_get_errors()) { |
|
| 96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | $items = $this->payment_form_submission->get_items(); |
| 109 | 109 | |
| 110 | 110 | // Ensure that we have items. |
| 111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
| 112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
| 111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
| 112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
| 123 | 123 | protected function get_submission_invoice() { |
| 124 | 124 | $submission = $this->payment_form_submission; |
| 125 | 125 | |
| 126 | - if ( ! $submission->has_invoice() ) { |
|
| 126 | + if (!$submission->has_invoice()) { |
|
| 127 | 127 | $invoice = new WPInv_Invoice(); |
| 128 | - $invoice->set_created_via( 'payment_form' ); |
|
| 128 | + $invoice->set_created_via('payment_form'); |
|
| 129 | 129 | return $invoice; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $invoice = $submission->get_invoice(); |
| 133 | 133 | |
| 134 | 134 | // Make sure that it is neither paid or refunded. |
| 135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return $invoice; |
@@ -146,33 +146,33 @@ discard block |
||
| 146 | 146 | * @param GetPaid_Form_Item[] $items |
| 147 | 147 | * @return WPInv_Invoice |
| 148 | 148 | */ |
| 149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 149 | + protected function process_submission_invoice($invoice, $items) { |
|
| 150 | 150 | |
| 151 | 151 | $submission = $this->payment_form_submission; |
| 152 | 152 | |
| 153 | 153 | // Set-up the invoice details. |
| 154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 157 | - $invoice->set_items( $items ); |
|
| 158 | - $invoice->set_fees( $submission->get_fees() ); |
|
| 159 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
| 160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
| 162 | - $invoice->set_currency( $submission->get_currency() ); |
|
| 163 | - |
|
| 164 | - if ( $submission->has_shipping() ) { |
|
| 165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
| 154 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
| 155 | + $invoice->set_user_id($this->get_submission_customer()); |
|
| 156 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
| 157 | + $invoice->set_items($items); |
|
| 158 | + $invoice->set_fees($submission->get_fees()); |
|
| 159 | + $invoice->set_taxes($submission->get_taxes()); |
|
| 160 | + $invoice->set_discounts($submission->get_discounts()); |
|
| 161 | + $invoice->set_gateway($submission->get_field('wpi-gateway')); |
|
| 162 | + $invoice->set_currency($submission->get_currency()); |
|
| 163 | + |
|
| 164 | + if ($submission->has_shipping()) { |
|
| 165 | + $invoice->set_shipping($submission->get_shipping()); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 168 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
| 169 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
| 170 | 170 | |
| 171 | - if ( $submission->has_discount_code() ) { |
|
| 172 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
| 171 | + if ($submission->has_discount_code()) { |
|
| 172 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 175 | + getpaid_maybe_add_default_address($invoice); |
|
| 176 | 176 | return $invoice; |
| 177 | 177 | } |
| 178 | 178 | |
@@ -185,34 +185,34 @@ discard block |
||
| 185 | 185 | $submission = $this->payment_form_submission; |
| 186 | 186 | |
| 187 | 187 | // If this is an existing invoice... |
| 188 | - if ( $submission->has_invoice() ) { |
|
| 188 | + if ($submission->has_invoice()) { |
|
| 189 | 189 | return $submission->get_invoice()->get_user_id(); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | // (Maybe) create the user. |
| 193 | 193 | $user = get_current_user_id(); |
| 194 | 194 | |
| 195 | - if ( empty( $user ) ) { |
|
| 196 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
| 195 | + if (empty($user)) { |
|
| 196 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if ( empty( $user ) ) { |
|
| 200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
| 201 | - $name = implode( '', array_filter( $name ) ); |
|
| 202 | - $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
|
| 199 | + if (empty($user)) { |
|
| 200 | + $name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing')); |
|
| 201 | + $name = implode('', array_filter($name)); |
|
| 202 | + $user = wpinv_create_user($submission->get_billing_email(), $name); |
|
| 203 | 203 | |
| 204 | 204 | // (Maybe) send new user notification. |
| 205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
| 207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
| 205 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
| 206 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
| 207 | + wp_send_new_user_notifications($user, 'user'); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( is_wp_error( $user ) ) { |
|
| 212 | - wp_send_json_error( $user->get_error_message() ); |
|
| 211 | + if (is_wp_error($user)) { |
|
| 212 | + wp_send_json_error($user->get_error_message()); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if ( is_numeric( $user ) ) { |
|
| 215 | + if (is_numeric($user)) { |
|
| 216 | 216 | return $user; |
| 217 | 217 | } |
| 218 | 218 | |
@@ -236,72 +236,72 @@ discard block |
||
| 236 | 236 | ); |
| 237 | 237 | |
| 238 | 238 | // Raw submission details. |
| 239 | - $data = $submission->get_data(); |
|
| 239 | + $data = $submission->get_data(); |
|
| 240 | 240 | |
| 241 | 241 | // Loop through the submitted details. |
| 242 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
| 242 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
| 243 | 243 | |
| 244 | 244 | // Skip premade fields. |
| 245 | - if ( ! empty( $field['premade'] ) ) { |
|
| 245 | + if (!empty($field['premade'])) { |
|
| 246 | 246 | continue; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | // Ensure address is provided. |
| 250 | - if ( 'address' === $field['type'] ) { |
|
| 251 | - $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
| 250 | + if ('address' === $field['type']) { |
|
| 251 | + $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
| 252 | 252 | |
| 253 | - foreach ( $field['fields'] as $address_field ) { |
|
| 253 | + foreach ($field['fields'] as $address_field) { |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
| 255 | + if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 256 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // If it is required and not set, abort. |
| 262 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
| 263 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
| 262 | + if (!$submission->is_required_field_set($field)) { |
|
| 263 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // Handle misc fields. |
| 267 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
| 267 | + if (isset($data[$field['id']])) { |
|
| 268 | 268 | |
| 269 | 269 | // Uploads. |
| 270 | - if ( 'file_upload' === $field['type'] ) { |
|
| 271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
| 270 | + if ('file_upload' === $field['type']) { |
|
| 271 | + $max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']); |
|
| 272 | 272 | |
| 273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
| 274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
| 273 | + if (count($data[$field['id']]) > $max_file_num) { |
|
| 274 | + wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing')); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | $value = array(); |
| 278 | 278 | |
| 279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
| 279 | + foreach ($data[$field['id']] as $url => $name) { |
|
| 280 | 280 | $value[] = sprintf( |
| 281 | 281 | '<a href="%s" target="_blank">%s</a>', |
| 282 | - esc_url_raw( $url ), |
|
| 283 | - esc_html( $name ) |
|
| 282 | + esc_url_raw($url), |
|
| 283 | + esc_html($name) |
|
| 284 | 284 | ); |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - $value = implode( ' | ', $value ); |
|
| 287 | + $value = implode(' | ', $value); |
|
| 288 | 288 | |
| 289 | - } elseif ( 'checkbox' === $field['type'] ) { |
|
| 290 | - $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
| 289 | + } elseif ('checkbox' === $field['type']) { |
|
| 290 | + $value = !empty($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
| 291 | 291 | } else { |
| 292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
| 292 | + $value = wp_kses_post($data[$field['id']]); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | $label = $field['id']; |
| 296 | 296 | |
| 297 | - if ( isset( $field['label'] ) ) { |
|
| 297 | + if (isset($field['label'])) { |
|
| 298 | 298 | $label = $field['label']; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
| 302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 301 | + if (!empty($field['add_meta'])) { |
|
| 302 | + $prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
| 303 | 303 | } |
| 304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 304 | + $prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
| 305 | 305 | |
| 306 | 306 | } |
| 307 | 307 | } |
@@ -317,30 +317,30 @@ discard block |
||
| 317 | 317 | * @param WPInv_Invoice $invoice |
| 318 | 318 | * @param string $type |
| 319 | 319 | */ |
| 320 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
| 320 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
| 321 | 321 | |
| 322 | 322 | $data = $this->payment_form_submission->get_data(); |
| 323 | - $type = sanitize_key( $type ); |
|
| 323 | + $type = sanitize_key($type); |
|
| 324 | 324 | $address = array(); |
| 325 | 325 | $prepared = array(); |
| 326 | 326 | |
| 327 | - if ( ! empty( $data[ $type ] ) ) { |
|
| 328 | - $address = $data[ $type ]; |
|
| 327 | + if (!empty($data[$type])) { |
|
| 328 | + $address = $data[$type]; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | // Clean address details. |
| 332 | - foreach ( $address as $key => $value ) { |
|
| 333 | - $key = sanitize_key( $key ); |
|
| 334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
| 335 | - $value = wpinv_clean( $value ); |
|
| 336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 332 | + foreach ($address as $key => $value) { |
|
| 333 | + $key = sanitize_key($key); |
|
| 334 | + $key = str_replace('wpinv_', '', $key); |
|
| 335 | + $value = wpinv_clean($value); |
|
| 336 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // Filter address details. |
| 340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 340 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
| 341 | 341 | |
| 342 | 342 | // Remove non-whitelisted values. |
| 343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 343 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
| 344 | 344 | |
| 345 | 345 | } |
| 346 | 346 | |
@@ -350,12 +350,12 @@ discard block |
||
| 350 | 350 | * @return array |
| 351 | 351 | * @param WPInv_Invoice $invoice |
| 352 | 352 | */ |
| 353 | - protected function prepare_billing_info( &$invoice ) { |
|
| 353 | + protected function prepare_billing_info(&$invoice) { |
|
| 354 | 354 | |
| 355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 355 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
| 356 | 356 | |
| 357 | 357 | // Update the invoice with the billing details. |
| 358 | - $invoice->set_props( $billing_address ); |
|
| 358 | + $invoice->set_props($billing_address); |
|
| 359 | 359 | |
| 360 | 360 | } |
| 361 | 361 | |
@@ -365,15 +365,15 @@ discard block |
||
| 365 | 365 | * @return array |
| 366 | 366 | * @param WPInv_Invoice $invoice |
| 367 | 367 | */ |
| 368 | - protected function prepare_shipping_info( $invoice ) { |
|
| 368 | + protected function prepare_shipping_info($invoice) { |
|
| 369 | 369 | |
| 370 | 370 | $data = $this->payment_form_submission->get_data(); |
| 371 | 371 | |
| 372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
| 373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 372 | + if (empty($data['same-shipping-address'])) { |
|
| 373 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 376 | + return $this->prepare_address_details($invoice, 'billing'); |
|
| 377 | 377 | |
| 378 | 378 | } |
| 379 | 379 | |
@@ -384,45 +384,45 @@ discard block |
||
| 384 | 384 | * @param array $prepared_payment_form_data |
| 385 | 385 | * @param array $shipping |
| 386 | 386 | */ |
| 387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 387 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
| 388 | 388 | |
| 389 | 389 | // Ensure the invoice exists. |
| 390 | - if ( ! $invoice->exists() ) { |
|
| 391 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
| 390 | + if (!$invoice->exists()) { |
|
| 391 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | // Save payment form data. |
| 395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 396 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
| 397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
| 398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 395 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
| 396 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
| 397 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
| 398 | + if (!empty($prepared_payment_form_data)) { |
|
| 399 | 399 | |
| 400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
| 401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
| 400 | + if (!empty($prepared_payment_form_data['all'])) { |
|
| 401 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
| 405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
| 404 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
| 405 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | // Save payment form data. |
| 410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
| 411 | - if ( ! empty( $shipping ) ) { |
|
| 412 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
| 410 | + $shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission); |
|
| 411 | + if (!empty($shipping)) { |
|
| 412 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | // Backwards compatibility. |
| 416 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
| 416 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
| 417 | 417 | |
| 418 | 418 | try { |
| 419 | - $this->process_payment( $invoice ); |
|
| 420 | - } catch ( Exception $e ) { |
|
| 421 | - wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
| 419 | + $this->process_payment($invoice); |
|
| 420 | + } catch (Exception $e) { |
|
| 421 | + wpinv_set_error('payment_error', $e->getMessage()); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | // If we are here, there was an error. |
| 425 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 425 | + wpinv_send_back_to_checkout($invoice); |
|
| 426 | 426 | |
| 427 | 427 | } |
| 428 | 428 | |
@@ -431,41 +431,41 @@ discard block |
||
| 431 | 431 | * |
| 432 | 432 | * @param WPInv_Invoice $invoice |
| 433 | 433 | */ |
| 434 | - protected function process_payment( $invoice ) { |
|
| 434 | + protected function process_payment($invoice) { |
|
| 435 | 435 | |
| 436 | 436 | // Clear any checkout errors. |
| 437 | 437 | wpinv_clear_errors(); |
| 438 | 438 | |
| 439 | 439 | // No need to send free invoices to the gateway. |
| 440 | - if ( $invoice->is_free() ) { |
|
| 441 | - $this->process_free_payment( $invoice ); |
|
| 440 | + if ($invoice->is_free()) { |
|
| 441 | + $this->process_free_payment($invoice); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | $submission = $this->payment_form_submission; |
| 445 | 445 | |
| 446 | 446 | // Fires before sending to the gateway. |
| 447 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 447 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
| 448 | 448 | |
| 449 | 449 | // Allow the sumission data to be modified before it is sent to the gateway. |
| 450 | 450 | $submission_data = $submission->get_data(); |
| 451 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 452 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 451 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
| 452 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
| 453 | 453 | |
| 454 | 454 | // Validate the currency. |
| 455 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 456 | - wpinv_set_error( 'invalid_currency' ); |
|
| 455 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
| 456 | + wpinv_set_error('invalid_currency'); |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | // Check to see if we have any errors. |
| 460 | - if ( wpinv_get_errors() ) { |
|
| 461 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 460 | + if (wpinv_get_errors()) { |
|
| 461 | + wpinv_send_back_to_checkout($invoice); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // Send info to the gateway for payment processing |
| 465 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 465 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
| 466 | 466 | |
| 467 | 467 | // Backwards compatibility. |
| 468 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 468 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
| 469 | 469 | |
| 470 | 470 | } |
| 471 | 471 | |
@@ -474,12 +474,12 @@ discard block |
||
| 474 | 474 | * |
| 475 | 475 | * @param WPInv_Invoice $invoice |
| 476 | 476 | */ |
| 477 | - protected function process_free_payment( $invoice ) { |
|
| 477 | + protected function process_free_payment($invoice) { |
|
| 478 | 478 | |
| 479 | - $invoice->set_gateway( 'none' ); |
|
| 480 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 479 | + $invoice->set_gateway('none'); |
|
| 480 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
| 481 | 481 | $invoice->mark_paid(); |
| 482 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 482 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 483 | 483 | |
| 484 | 484 | } |
| 485 | 485 | |
@@ -487,9 +487,9 @@ discard block |
||
| 487 | 487 | * Sends a redrect response to payment details. |
| 488 | 488 | * |
| 489 | 489 | */ |
| 490 | - public function send_redirect_response( $url ) { |
|
| 491 | - $url = rawurlencode( $url ); |
|
| 492 | - wp_send_json_success( $url ); |
|
| 490 | + public function send_redirect_response($url) { |
|
| 491 | + $url = rawurlencode($url); |
|
| 492 | + wp_send_json_success($url); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | } |