@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; // Exit if accessed directly |
|
| 10 | + exit; // Exit if accessed directly |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -16,10 +16,10 @@ discard block |
||
| 16 | 16 | class GetPaid_Meta_Box_Payment_Form { |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | - * Output the metabox. |
|
| 20 | - * |
|
| 21 | - * @param WP_Post $post |
|
| 22 | - */ |
|
| 19 | + * Output the metabox. |
|
| 20 | + * |
|
| 21 | + * @param WP_Post $post |
|
| 22 | + */ |
|
| 23 | 23 | public static function output( $post ) { |
| 24 | 24 | ?> |
| 25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | - * Save meta box data. |
|
| 90 | - * |
|
| 91 | - * @param int $post_id |
|
| 92 | - */ |
|
| 93 | - public static function save( $post_id ) { |
|
| 89 | + * Save meta box data. |
|
| 90 | + * |
|
| 91 | + * @param int $post_id |
|
| 92 | + */ |
|
| 93 | + public static function save( $post_id ) { |
|
| 94 | 94 | |
| 95 | 95 | // Prepare the form. |
| 96 | 96 | $form = new GetPaid_Payment_Form( $post_id ); |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | - * Converts an array fo form items to objects. |
|
| 125 | - * |
|
| 126 | - * @param array $items |
|
| 127 | - */ |
|
| 128 | - public static function item_to_objects( $items ) { |
|
| 124 | + * Converts an array fo form items to objects. |
|
| 125 | + * |
|
| 126 | + * @param array $items |
|
| 127 | + */ |
|
| 128 | + public static function item_to_objects( $items ) { |
|
| 129 | 129 | |
| 130 | 130 | $objects = array(); |
| 131 | 131 | |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if (!defined('ABSPATH')) { |
|
| 10 | 10 | exit; // Exit if accessed directly |
| 11 | 11 | } |
| 12 | 12 | |
@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @param WP_Post $post |
| 22 | 22 | */ |
| 23 | - public static function output( $post ) { |
|
| 23 | + public static function output($post) { |
|
| 24 | 24 | ?> |
| 25 | 25 | <div id="wpinv-form-builder" class="bsui"> |
| 26 | 26 | <div class="row"> |
| 27 | 27 | <div class="col-sm-4"> |
| 28 | 28 | |
| 29 | 29 | <!-- Builder tabs --> |
| 30 | - <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e( 'Go Back', 'invoicing' ); ?></button> |
|
| 30 | + <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e('Go Back', 'invoicing'); ?></button> |
|
| 31 | 31 | |
| 32 | 32 | <!-- Builder tab content --> |
| 33 | 33 | <div class="mt-4"> |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | <!-- Available builder elements --> |
| 36 | 36 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
| 37 | 37 | <div class="wpinv-form-builder-add-field-types"> |
| 38 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
| 38 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
| 39 | 39 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
| 40 | 40 | <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
| 41 | 41 | <button class="button btn"> |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | <!-- Edit an element --> |
| 51 | 51 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='edit_item'" style="font-size: 14px;"> |
| 52 | 52 | <div class="wpinv-form-builder-edit-field-wrapper"> |
| 53 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
| 54 | - <?php do_action( 'getpaid_payment_form_edit_element_template', $post ); ?> |
|
| 53 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
| 54 | + <?php do_action('getpaid_payment_form_edit_element_template', $post); ?> |
|
| 55 | 55 | <div> |
| 56 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Element', 'invoicing' ); ?></button> |
|
| 56 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Element', 'invoicing'); ?></button> |
|
| 57 | 57 | </div> |
| 58 | 58 | </div> |
| 59 | 59 | </div> |
@@ -62,14 +62,14 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | </div> |
| 64 | 64 | <div class="col-sm-8 border-left"> |
| 65 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
| 66 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
| 65 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
| 66 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
| 67 | 67 | |
| 68 | 68 | <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 14px;"> |
| 69 | 69 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="[{ active: active_form_element==form_element && active_tab=='edit_item' }, form_element.type]" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
| 70 | 70 | <div class="wpinv-form-builder-element-preview-inner"> |
| 71 | 71 | <div class="wpinv-payment-form-field-preview-overlay"></div> |
| 72 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
| 72 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
| 73 | 73 | </div> |
| 74 | 74 | </div> |
| 75 | 75 | </draggable> |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | </div> |
| 83 | 83 | <?php |
| 84 | 84 | |
| 85 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
| 85 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -90,33 +90,33 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @param int $post_id |
| 92 | 92 | */ |
| 93 | - public static function save( $post_id ) { |
|
| 93 | + public static function save($post_id) { |
|
| 94 | 94 | |
| 95 | 95 | // Prepare the form. |
| 96 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
| 96 | + $form = new GetPaid_Payment_Form($post_id); |
|
| 97 | 97 | |
| 98 | 98 | // Fetch form items. |
| 99 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
| 99 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
| 100 | 100 | |
| 101 | 101 | // Ensure that we have an array... |
| 102 | - if ( empty( $form_items ) ) { |
|
| 102 | + if (empty($form_items)) { |
|
| 103 | 103 | $form_items = array(); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Add it to the form. |
| 107 | - $form->set_items( self::item_to_objects( $form_items ) ); |
|
| 107 | + $form->set_items(self::item_to_objects($form_items)); |
|
| 108 | 108 | |
| 109 | 109 | // Save form elements. |
| 110 | - $form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
| 111 | - if ( empty( $form_elements ) ) { |
|
| 110 | + $form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
| 111 | + if (empty($form_elements)) { |
|
| 112 | 112 | $form_elements = array(); |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $form->set_elements( $form_elements ); |
|
| 115 | + $form->set_elements($form_elements); |
|
| 116 | 116 | |
| 117 | 117 | // Persist data to the datastore. |
| 118 | 118 | $form->save(); |
| 119 | - do_action( 'getpaid_payment_form_metabox_save', $post_id, $form ); |
|
| 119 | + do_action('getpaid_payment_form_metabox_save', $post_id, $form); |
|
| 120 | 120 | |
| 121 | 121 | } |
| 122 | 122 | |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @param array $items |
| 127 | 127 | */ |
| 128 | - public static function item_to_objects( $items ) { |
|
| 128 | + public static function item_to_objects($items) { |
|
| 129 | 129 | |
| 130 | 130 | $objects = array(); |
| 131 | 131 | |
| 132 | - foreach ( $items as $item ) { |
|
| 133 | - $_item = new GetPaid_Form_Item( $item['id'] ); |
|
| 134 | - $_item->set_allow_quantities( (bool) $item['allow_quantities'] ); |
|
| 135 | - $_item->set_is_required( (bool) $item['required'] ); |
|
| 132 | + foreach ($items as $item) { |
|
| 133 | + $_item = new GetPaid_Form_Item($item['id']); |
|
| 134 | + $_item->set_allow_quantities((bool) $item['allow_quantities']); |
|
| 135 | + $_item->set_is_required((bool) $item['required']); |
|
| 136 | 136 | $objects[] = $_item; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | - exit; // Exit if accessed directly |
|
| 11 | + exit; // Exit if accessed directly |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Output the metabox. |
|
| 21 | - * |
|
| 22 | - * @param WP_Post $post |
|
| 23 | - */ |
|
| 20 | + * Output the metabox. |
|
| 21 | + * |
|
| 22 | + * @param WP_Post $post |
|
| 23 | + */ |
|
| 24 | 24 | public static function output( $post ) { |
| 25 | 25 | |
| 26 | 26 | // Prepare the discount. |
@@ -368,34 +368,34 @@ discard block |
||
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
| 371 | - * Save meta box data. |
|
| 372 | - * |
|
| 373 | - * @param int $post_id |
|
| 374 | - */ |
|
| 375 | - public static function save( $post_id ) { |
|
| 371 | + * Save meta box data. |
|
| 372 | + * |
|
| 373 | + * @param int $post_id |
|
| 374 | + */ |
|
| 375 | + public static function save( $post_id ) { |
|
| 376 | 376 | |
| 377 | 377 | // Prepare the discount. |
| 378 | 378 | $discount = new WPInv_Discount( $post_id ); |
| 379 | 379 | |
| 380 | 380 | // Load new data. |
| 381 | 381 | $discount->set_props( |
| 382 | - array( |
|
| 383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
| 384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
| 385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
| 386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
| 387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
| 382 | + array( |
|
| 383 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
| 384 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
| 385 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
| 386 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
| 387 | + 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
| 388 | 388 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
| 389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
| 390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
| 391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
| 392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
| 393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
| 394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
| 395 | - ) |
|
| 389 | + 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
| 390 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
| 391 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
| 392 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
| 393 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
| 394 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
| 395 | + ) |
|
| 396 | 396 | ); |
| 397 | 397 | |
| 398 | - $discount->save(); |
|
| 399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
| 400 | - } |
|
| 398 | + $discount->save(); |
|
| 399 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
| 400 | + } |
|
| 401 | 401 | } |
@@ -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,24 +21,24 @@ 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 discount. |
| 27 | - $discount = new WPInv_Discount( $post ); |
|
| 27 | + $discount = new WPInv_Discount($post); |
|
| 28 | 28 | |
| 29 | 29 | // Nonce field. |
| 30 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
| 30 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
| 31 | 31 | |
| 32 | - do_action( 'wpinv_discount_form_top', $discount ); |
|
| 32 | + do_action('wpinv_discount_form_top', $discount); |
|
| 33 | 33 | |
| 34 | 34 | // Set the currency position. |
| 35 | 35 | $position = wpinv_currency_position(); |
| 36 | 36 | |
| 37 | - if ( $position == 'left_space' ) { |
|
| 37 | + if ($position == 'left_space') { |
|
| 38 | 38 | $position = 'left'; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - if ( $position == 'right_space' ) { |
|
| 41 | + if ($position == 'right_space') { |
|
| 42 | 42 | $position = 'right'; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -52,66 +52,66 @@ discard block |
||
| 52 | 52 | </style> |
| 53 | 53 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
| 54 | 54 | |
| 55 | - <?php do_action( 'wpinv_discount_form_first', $discount ); ?> |
|
| 55 | + <?php do_action('wpinv_discount_form_first', $discount); ?> |
|
| 56 | 56 | |
| 57 | - <?php do_action( 'wpinv_discount_form_before_code', $discount ); ?> |
|
| 57 | + <?php do_action('wpinv_discount_form_before_code', $discount); ?> |
|
| 58 | 58 | <div class="form-group row"> |
| 59 | 59 | <label for="wpinv_discount_code" class="col-sm-3 col-form-label"> |
| 60 | - <?php _e( 'Discount Code', 'invoicing' );?> |
|
| 60 | + <?php _e('Discount Code', 'invoicing'); ?> |
|
| 61 | 61 | </label> |
| 62 | 62 | <div class="col-sm-8"> |
| 63 | 63 | <div class="row"> |
| 64 | 64 | <div class="col-sm-12 form-group"> |
| 65 | - <input type="text" value="<?php echo esc_attr( $discount->get_code( 'edit' ) ); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
| 65 | + <input type="text" value="<?php echo esc_attr($discount->get_code('edit')); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
| 66 | 66 | </div> |
| 67 | 67 | <div class="col-sm-12"> |
| 68 | 68 | <?php |
| 69 | - do_action( 'wpinv_discount_form_before_single_use', $discount ); |
|
| 69 | + do_action('wpinv_discount_form_before_single_use', $discount); |
|
| 70 | 70 | |
| 71 | 71 | echo aui()->input( |
| 72 | 72 | array( |
| 73 | 73 | 'id' => 'wpinv_discount_single_use', |
| 74 | 74 | 'name' => 'wpinv_discount_single_use', |
| 75 | 75 | 'type' => 'checkbox', |
| 76 | - 'label' => __( 'Each customer can only use this discount once', 'invoicing' ), |
|
| 76 | + 'label' => __('Each customer can only use this discount once', 'invoicing'), |
|
| 77 | 77 | 'value' => '1', |
| 78 | 78 | 'checked' => $discount->is_single_use(), |
| 79 | 79 | ) |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - do_action( 'wpinv_discount_form_single_use', $discount ); |
|
| 82 | + do_action('wpinv_discount_form_single_use', $discount); |
|
| 83 | 83 | ?> |
| 84 | 84 | </div> |
| 85 | 85 | <div class="col-sm-12"> |
| 86 | 86 | <?php |
| 87 | - do_action( 'wpinv_discount_form_before_recurring', $discount ); |
|
| 87 | + do_action('wpinv_discount_form_before_recurring', $discount); |
|
| 88 | 88 | |
| 89 | 89 | echo aui()->input( |
| 90 | 90 | array( |
| 91 | 91 | 'id' => 'wpinv_discount_recurring', |
| 92 | 92 | 'name' => 'wpinv_discount_recurring', |
| 93 | 93 | 'type' => 'checkbox', |
| 94 | - 'label' => __( 'Apply this discount to all recurring payments for subscriptions', 'invoicing' ), |
|
| 94 | + 'label' => __('Apply this discount to all recurring payments for subscriptions', 'invoicing'), |
|
| 95 | 95 | 'value' => '1', |
| 96 | 96 | 'checked' => $discount->is_recurring(), |
| 97 | 97 | ) |
| 98 | 98 | ); |
| 99 | 99 | |
| 100 | - do_action( 'wpinv_discount_form_recurring', $discount ); |
|
| 100 | + do_action('wpinv_discount_form_recurring', $discount); |
|
| 101 | 101 | ?> |
| 102 | 102 | </div> |
| 103 | 103 | </div> |
| 104 | 104 | </div> |
| 105 | 105 | <div class="col-sm-1 pt-2 pl-0"> |
| 106 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter a discount code such as 10OFF.', 'invoicing' ); ?>"></span> |
|
| 106 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter a discount code such as 10OFF.', 'invoicing'); ?>"></span> |
|
| 107 | 107 | </div> |
| 108 | 108 | </div> |
| 109 | - <?php do_action( 'wpinv_discount_form_code', $discount ); ?> |
|
| 109 | + <?php do_action('wpinv_discount_form_code', $discount); ?> |
|
| 110 | 110 | |
| 111 | - <?php do_action( 'wpinv_discount_form_before_type', $discount ); ?> |
|
| 111 | + <?php do_action('wpinv_discount_form_before_type', $discount); ?> |
|
| 112 | 112 | <div class="form-group row"> |
| 113 | 113 | <label for="wpinv_discount_type" class="col-sm-3 col-form-label"> |
| 114 | - <?php _e( 'Discount Type', 'invoicing' );?> |
|
| 114 | + <?php _e('Discount Type', 'invoicing'); ?> |
|
| 115 | 115 | </label> |
| 116 | 116 | <div class="col-sm-8"> |
| 117 | 117 | <?php |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | array( |
| 120 | 120 | 'id' => 'wpinv_discount_type', |
| 121 | 121 | 'name' => 'wpinv_discount_type', |
| 122 | - 'label' => __( 'Discount Type', 'invoicing' ), |
|
| 123 | - 'placeholder' => __( 'Select Discount Type', 'invoicing' ), |
|
| 124 | - 'value' => $discount->get_type( 'edit' ), |
|
| 122 | + 'label' => __('Discount Type', 'invoicing'), |
|
| 123 | + 'placeholder' => __('Select Discount Type', 'invoicing'), |
|
| 124 | + 'value' => $discount->get_type('edit'), |
|
| 125 | 125 | 'select2' => true, |
| 126 | 126 | 'data-allow-clear' => 'false', |
| 127 | 127 | 'options' => wpinv_get_discount_types() |
@@ -130,19 +130,19 @@ discard block |
||
| 130 | 130 | ?> |
| 131 | 131 | </div> |
| 132 | 132 | <div class="col-sm-1 pt-2 pl-0"> |
| 133 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Discount type.', 'invoicing' ); ?>"></span> |
|
| 133 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Discount type.', 'invoicing'); ?>"></span> |
|
| 134 | 134 | </div> |
| 135 | 135 | </div> |
| 136 | - <?php do_action( 'wpinv_discount_form_type', $discount ); ?> |
|
| 136 | + <?php do_action('wpinv_discount_form_type', $discount); ?> |
|
| 137 | 137 | |
| 138 | - <?php do_action( 'wpinv_discount_form_before_amount', $discount ); ?> |
|
| 139 | - <div class="form-group row <?php echo esc_attr( $discount->get_type( 'edit' ) ); ?>" id="wpinv_discount_amount_wrap"> |
|
| 138 | + <?php do_action('wpinv_discount_form_before_amount', $discount); ?> |
|
| 139 | + <div class="form-group row <?php echo esc_attr($discount->get_type('edit')); ?>" id="wpinv_discount_amount_wrap"> |
|
| 140 | 140 | <label for="wpinv_discount_amount" class="col-sm-3 col-form-label"> |
| 141 | - <?php _e( 'Discount Amount', 'invoicing' );?> |
|
| 141 | + <?php _e('Discount Amount', 'invoicing'); ?> |
|
| 142 | 142 | </label> |
| 143 | 143 | <div class="col-sm-8"> |
| 144 | 144 | <div class="input-group input-group-sm"> |
| 145 | - <?php if( 'left' == $position ) : ?> |
|
| 145 | + <?php if ('left' == $position) : ?> |
|
| 146 | 146 | <div class="input-group-prepend left wpinv-if-flat"> |
| 147 | 147 | <span class="input-group-text"> |
| 148 | 148 | <?php echo wpinv_currency_symbol(); ?> |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | </div> |
| 151 | 151 | <?php endif; ?> |
| 152 | 152 | |
| 153 | - <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr( $discount->get_amount( 'edit' ) ); ?>" placeholder="0" class="form-control"> |
|
| 153 | + <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr($discount->get_amount('edit')); ?>" placeholder="0" class="form-control"> |
|
| 154 | 154 | |
| 155 | - <?php if( 'right' == $position ) : ?> |
|
| 155 | + <?php if ('right' == $position) : ?> |
|
| 156 | 156 | <div class="input-group-prepend left wpinv-if-flat"> |
| 157 | 157 | <span class="input-group-text"> |
| 158 | 158 | <?php echo wpinv_currency_symbol(); ?> |
@@ -165,15 +165,15 @@ discard block |
||
| 165 | 165 | </div> |
| 166 | 166 | </div> |
| 167 | 167 | <div class="col-sm-1 pt-2 pl-0"> |
| 168 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?>"></span> |
|
| 168 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the discount value. Ex: 10', 'invoicing'); ?>"></span> |
|
| 169 | 169 | </div> |
| 170 | 170 | </div> |
| 171 | - <?php do_action( 'wpinv_discount_form_amount', $discount ); ?> |
|
| 171 | + <?php do_action('wpinv_discount_form_amount', $discount); ?> |
|
| 172 | 172 | |
| 173 | - <?php do_action( 'wpinv_discount_form_before_items', $discount ); ?> |
|
| 173 | + <?php do_action('wpinv_discount_form_before_items', $discount); ?> |
|
| 174 | 174 | <div class="form-group row"> |
| 175 | 175 | <label for="wpinv_discount_items" class="col-sm-3 col-form-label"> |
| 176 | - <?php _e( 'Items', 'invoicing' );?> |
|
| 176 | + <?php _e('Items', 'invoicing'); ?> |
|
| 177 | 177 | </label> |
| 178 | 178 | <div class="col-sm-8"> |
| 179 | 179 | <?php |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | array( |
| 182 | 182 | 'id' => 'wpinv_discount_items', |
| 183 | 183 | 'name' => 'wpinv_discount_items[]', |
| 184 | - 'label' => __( 'Items', 'invoicing' ), |
|
| 185 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
| 186 | - 'value' => $discount->get_items( 'edit' ), |
|
| 184 | + 'label' => __('Items', 'invoicing'), |
|
| 185 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
| 186 | + 'value' => $discount->get_items('edit'), |
|
| 187 | 187 | 'select2' => true, |
| 188 | 188 | 'multiple' => true, |
| 189 | 189 | 'data-allow-clear' => 'false', |
@@ -193,15 +193,15 @@ discard block |
||
| 193 | 193 | ?> |
| 194 | 194 | </div> |
| 195 | 195 | <div class="col-sm-1 pt-2 pl-0"> |
| 196 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing' ); ?>"></span> |
|
| 196 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing'); ?>"></span> |
|
| 197 | 197 | </div> |
| 198 | 198 | </div> |
| 199 | - <?php do_action( 'wpinv_discount_form_items', $discount ); ?> |
|
| 199 | + <?php do_action('wpinv_discount_form_items', $discount); ?> |
|
| 200 | 200 | |
| 201 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $discount ); ?> |
|
| 201 | + <?php do_action('wpinv_discount_form_before_excluded_items', $discount); ?> |
|
| 202 | 202 | <div class="form-group row"> |
| 203 | 203 | <label for="wpinv_discount_excluded_items" class="col-sm-3 col-form-label"> |
| 204 | - <?php _e( 'Excluded Items', 'invoicing' );?> |
|
| 204 | + <?php _e('Excluded Items', 'invoicing'); ?> |
|
| 205 | 205 | </label> |
| 206 | 206 | <div class="col-sm-8"> |
| 207 | 207 | <?php |
@@ -209,9 +209,9 @@ discard block |
||
| 209 | 209 | array( |
| 210 | 210 | 'id' => 'wpinv_discount_excluded_items', |
| 211 | 211 | 'name' => 'wpinv_discount_excluded_items[]', |
| 212 | - 'label' => __( 'Excluded Items', 'invoicing' ), |
|
| 213 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
| 214 | - 'value' => $discount->get_excluded_items( 'edit' ), |
|
| 212 | + 'label' => __('Excluded Items', 'invoicing'), |
|
| 213 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
| 214 | + 'value' => $discount->get_excluded_items('edit'), |
|
| 215 | 215 | 'select2' => true, |
| 216 | 216 | 'multiple' => true, |
| 217 | 217 | 'data-allow-clear' => 'false', |
@@ -221,15 +221,15 @@ discard block |
||
| 221 | 221 | ?> |
| 222 | 222 | </div> |
| 223 | 223 | <div class="col-sm-1 pt-2 pl-0"> |
| 224 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are not allowed to use this discount.', 'invoicing' ); ?>"></span> |
|
| 224 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are not allowed to use this discount.', 'invoicing'); ?>"></span> |
|
| 225 | 225 | </div> |
| 226 | 226 | </div> |
| 227 | - <?php do_action( 'wpinv_discount_form_excluded_items', $discount ); ?> |
|
| 227 | + <?php do_action('wpinv_discount_form_excluded_items', $discount); ?> |
|
| 228 | 228 | |
| 229 | - <?php do_action( 'wpinv_discount_form_before_start', $discount ); ?> |
|
| 229 | + <?php do_action('wpinv_discount_form_before_start', $discount); ?> |
|
| 230 | 230 | <div class="form-group row"> |
| 231 | 231 | <label for="wpinv_discount_start" class="col-sm-3 col-form-label"> |
| 232 | - <?php _e( 'Start Date', 'invoicing' );?> |
|
| 232 | + <?php _e('Start Date', 'invoicing'); ?> |
|
| 233 | 233 | </label> |
| 234 | 234 | <div class="col-sm-8"> |
| 235 | 235 | <?php |
@@ -238,10 +238,10 @@ discard block |
||
| 238 | 238 | 'type' => 'datepicker', |
| 239 | 239 | 'id' => 'wpinv_discount_start', |
| 240 | 240 | 'name' => 'wpinv_discount_start', |
| 241 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
| 241 | + 'label' => __('Start Date', 'invoicing'), |
|
| 242 | 242 | 'placeholder' => 'YYYY-MM-DD 00:00', |
| 243 | 243 | 'class' => 'form-control-sm', |
| 244 | - 'value' => $discount->get_start_date( 'edit' ), |
|
| 244 | + 'value' => $discount->get_start_date('edit'), |
|
| 245 | 245 | 'extra_attributes' => array( |
| 246 | 246 | 'data-enable-time' => 'true', |
| 247 | 247 | 'data-time_24hr' => 'true', |
@@ -252,15 +252,15 @@ discard block |
||
| 252 | 252 | ?> |
| 253 | 253 | </div> |
| 254 | 254 | <div class="col-sm-1 pt-2 pl-0"> |
| 255 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?>"></span> |
|
| 255 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?>"></span> |
|
| 256 | 256 | </div> |
| 257 | 257 | </div> |
| 258 | - <?php do_action( 'wpinv_discount_form_start', $discount ); ?> |
|
| 258 | + <?php do_action('wpinv_discount_form_start', $discount); ?> |
|
| 259 | 259 | |
| 260 | - <?php do_action( 'wpinv_discount_form_before_expiration', $discount ); ?> |
|
| 260 | + <?php do_action('wpinv_discount_form_before_expiration', $discount); ?> |
|
| 261 | 261 | <div class="form-group row"> |
| 262 | 262 | <label for="wpinv_discount_expiration" class="col-sm-3 col-form-label"> |
| 263 | - <?php _e( 'Expiration Date', 'invoicing' );?> |
|
| 263 | + <?php _e('Expiration Date', 'invoicing'); ?> |
|
| 264 | 264 | </label> |
| 265 | 265 | <div class="col-sm-8"> |
| 266 | 266 | <?php |
@@ -269,10 +269,10 @@ discard block |
||
| 269 | 269 | 'type' => 'datepicker', |
| 270 | 270 | 'id' => 'wpinv_discount_expiration', |
| 271 | 271 | 'name' => 'wpinv_discount_expiration', |
| 272 | - 'label' => __( 'Expiration Date', 'invoicing' ), |
|
| 272 | + 'label' => __('Expiration Date', 'invoicing'), |
|
| 273 | 273 | 'placeholder' => 'YYYY-MM-DD 00:00', |
| 274 | 274 | 'class' => 'form-control-sm', |
| 275 | - 'value' => $discount->get_end_date( 'edit' ), |
|
| 275 | + 'value' => $discount->get_end_date('edit'), |
|
| 276 | 276 | 'extra_attributes' => array( |
| 277 | 277 | 'data-enable-time' => 'true', |
| 278 | 278 | 'data-time_24hr' => 'true', |
@@ -285,27 +285,27 @@ discard block |
||
| 285 | 285 | ?> |
| 286 | 286 | </div> |
| 287 | 287 | <div class="col-sm-1 pt-2 pl-0"> |
| 288 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the date after which the discount will expire.', 'invoicing' ); ?>"></span> |
|
| 288 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the date after which the discount will expire.', 'invoicing'); ?>"></span> |
|
| 289 | 289 | </div> |
| 290 | 290 | </div> |
| 291 | - <?php do_action( 'wpinv_discount_form_expiration', $discount ); ?> |
|
| 291 | + <?php do_action('wpinv_discount_form_expiration', $discount); ?> |
|
| 292 | 292 | |
| 293 | - <?php do_action( 'wpinv_discount_form_before_min_total', $discount ); ?> |
|
| 293 | + <?php do_action('wpinv_discount_form_before_min_total', $discount); ?> |
|
| 294 | 294 | <div class="form-group row"> |
| 295 | 295 | <label for="wpinv_discount_min_total" class="col-sm-3 col-form-label"> |
| 296 | - <?php _e( 'Minimum Amount', 'invoicing' );?> |
|
| 296 | + <?php _e('Minimum Amount', 'invoicing'); ?> |
|
| 297 | 297 | </label> |
| 298 | 298 | <div class="col-sm-8"> |
| 299 | 299 | <div class="input-group input-group-sm"> |
| 300 | - <?php if( 'left' == $position ) : ?> |
|
| 300 | + <?php if ('left' == $position) : ?> |
|
| 301 | 301 | <div class="input-group-prepend"> |
| 302 | 302 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
| 303 | 303 | </div> |
| 304 | 304 | <?php endif; ?> |
| 305 | 305 | |
| 306 | - <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr( $discount->get_minimum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No minimum', 'invoicing' ); ?>" class="form-control"> |
|
| 306 | + <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr($discount->get_minimum_total('edit')); ?>" placeholder="<?php esc_attr_e('No minimum', 'invoicing'); ?>" class="form-control"> |
|
| 307 | 307 | |
| 308 | - <?php if( 'left' != $position ) : ?> |
|
| 308 | + <?php if ('left' != $position) : ?> |
|
| 309 | 309 | <div class="input-group-append"> |
| 310 | 310 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
| 311 | 311 | </div> |
@@ -313,27 +313,27 @@ discard block |
||
| 313 | 313 | </div> |
| 314 | 314 | </div> |
| 315 | 315 | <div class="col-sm-1 pt-2 pl-0"> |
| 316 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing' ); ?>"></span> |
|
| 316 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing'); ?>"></span> |
|
| 317 | 317 | </div> |
| 318 | 318 | </div> |
| 319 | - <?php do_action( 'wpinv_discount_form_min_total', $discount ); ?> |
|
| 319 | + <?php do_action('wpinv_discount_form_min_total', $discount); ?> |
|
| 320 | 320 | |
| 321 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
| 321 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
| 322 | 322 | <div class="form-group row"> |
| 323 | 323 | <label for="wpinv_discount_max_total" class="col-sm-3 col-form-label"> |
| 324 | - <?php _e( 'Maximum Amount', 'invoicing' );?> |
|
| 324 | + <?php _e('Maximum Amount', 'invoicing'); ?> |
|
| 325 | 325 | </label> |
| 326 | 326 | <div class="col-sm-8"> |
| 327 | 327 | <div class="input-group input-group-sm"> |
| 328 | - <?php if( 'left' == $position ) : ?> |
|
| 328 | + <?php if ('left' == $position) : ?> |
|
| 329 | 329 | <div class="input-group-prepend"> |
| 330 | 330 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
| 331 | 331 | </div> |
| 332 | 332 | <?php endif; ?> |
| 333 | 333 | |
| 334 | - <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr( $discount->get_maximum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No maximum', 'invoicing' ); ?>" class="form-control"> |
|
| 334 | + <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr($discount->get_maximum_total('edit')); ?>" placeholder="<?php esc_attr_e('No maximum', 'invoicing'); ?>" class="form-control"> |
|
| 335 | 335 | |
| 336 | - <?php if( 'left' != $position ) : ?> |
|
| 336 | + <?php if ('left' != $position) : ?> |
|
| 337 | 337 | <div class="input-group-append"> |
| 338 | 338 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
| 339 | 339 | </div> |
@@ -341,30 +341,30 @@ discard block |
||
| 341 | 341 | </div> |
| 342 | 342 | </div> |
| 343 | 343 | <div class="col-sm-1 pt-2 pl-0"> |
| 344 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing' ); ?>"></span> |
|
| 344 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing'); ?>"></span> |
|
| 345 | 345 | </div> |
| 346 | 346 | </div> |
| 347 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
| 347 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
| 348 | 348 | |
| 349 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $discount ); ?> |
|
| 349 | + <?php do_action('wpinv_discount_form_before_max_uses', $discount); ?> |
|
| 350 | 350 | <div class="form-group row"> |
| 351 | 351 | <label for="wpinv_discount_max_uses" class="col-sm-3 col-form-label"> |
| 352 | - <?php _e( 'Maximum Uses', 'invoicing' );?> |
|
| 352 | + <?php _e('Maximum Uses', 'invoicing'); ?> |
|
| 353 | 353 | </label> |
| 354 | 354 | <div class="col-sm-8"> |
| 355 | - <input type="text" value="<?php echo esc_attr( $discount->get_max_uses( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'invoicing' ); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
| 355 | + <input type="text" value="<?php echo esc_attr($discount->get_max_uses('edit')); ?>" placeholder="<?php esc_attr_e('Unlimited', 'invoicing'); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
| 356 | 356 | </div> |
| 357 | 357 | <div class="col-sm-1 pt-2 pl-0"> |
| 358 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum number of times that this discount code can be used.', 'invoicing' ); ?>"></span> |
|
| 358 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum number of times that this discount code can be used.', 'invoicing'); ?>"></span> |
|
| 359 | 359 | </div> |
| 360 | 360 | </div> |
| 361 | - <?php do_action( 'wpinv_discount_form_max_uses', $discount ); ?> |
|
| 361 | + <?php do_action('wpinv_discount_form_max_uses', $discount); ?> |
|
| 362 | 362 | |
| 363 | - <?php do_action( 'wpinv_discount_form_last', $discount ); ?> |
|
| 363 | + <?php do_action('wpinv_discount_form_last', $discount); ?> |
|
| 364 | 364 | |
| 365 | 365 | </div> |
| 366 | 366 | <?php |
| 367 | - do_action( 'wpinv_discount_form_bottom', $post ); |
|
| 367 | + do_action('wpinv_discount_form_bottom', $post); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -372,30 +372,30 @@ discard block |
||
| 372 | 372 | * |
| 373 | 373 | * @param int $post_id |
| 374 | 374 | */ |
| 375 | - public static function save( $post_id ) { |
|
| 375 | + public static function save($post_id) { |
|
| 376 | 376 | |
| 377 | 377 | // Prepare the discount. |
| 378 | - $discount = new WPInv_Discount( $post_id ); |
|
| 378 | + $discount = new WPInv_Discount($post_id); |
|
| 379 | 379 | |
| 380 | 380 | // Load new data. |
| 381 | 381 | $discount->set_props( |
| 382 | 382 | array( |
| 383 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? $_POST['wpinv_discount_code'] : null, |
|
| 384 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? $_POST['wpinv_discount_amount'] : null, |
|
| 385 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
| 386 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
| 387 | - 'is_single_use' => isset( $_POST['wpinv_discount_single_use'] ), |
|
| 388 | - 'type' => isset( $_POST['wpinv_discount_type'] ) ? $_POST['wpinv_discount_type'] : null, |
|
| 389 | - 'is_recurring' => isset( $_POST['wpinv_discount_recurring'] ), |
|
| 390 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? $_POST['wpinv_discount_items'] : array(), |
|
| 391 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
| 392 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? $_POST['wpinv_discount_max_uses'] : null, |
|
| 393 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? $_POST['wpinv_discount_min_total'] : null, |
|
| 394 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? $_POST['wpinv_discount_max_total'] : null, |
|
| 383 | + 'code' => isset($_POST['wpinv_discount_code']) ? $_POST['wpinv_discount_code'] : null, |
|
| 384 | + 'amount' => isset($_POST['wpinv_discount_amount']) ? $_POST['wpinv_discount_amount'] : null, |
|
| 385 | + 'start' => isset($_POST['wpinv_discount_start']) ? wpinv_clean($_POST['wpinv_discount_start']) : null, |
|
| 386 | + 'expiration' => isset($_POST['wpinv_discount_expiration']) ? wpinv_clean($_POST['wpinv_discount_expiration']) : null, |
|
| 387 | + 'is_single_use' => isset($_POST['wpinv_discount_single_use']), |
|
| 388 | + 'type' => isset($_POST['wpinv_discount_type']) ? $_POST['wpinv_discount_type'] : null, |
|
| 389 | + 'is_recurring' => isset($_POST['wpinv_discount_recurring']), |
|
| 390 | + 'items' => isset($_POST['wpinv_discount_items']) ? $_POST['wpinv_discount_items'] : array(), |
|
| 391 | + 'excluded_items' => isset($_POST['wpinv_discount_excluded_items']) ? $_POST['wpinv_discount_excluded_items'] : array(), |
|
| 392 | + 'max_uses' => isset($_POST['wpinv_discount_max_uses']) ? $_POST['wpinv_discount_max_uses'] : null, |
|
| 393 | + 'min_total' => isset($_POST['wpinv_discount_min_total']) ? $_POST['wpinv_discount_min_total'] : null, |
|
| 394 | + 'max_total' => isset($_POST['wpinv_discount_max_total']) ? $_POST['wpinv_discount_max_total'] : null, |
|
| 395 | 395 | ) |
| 396 | 396 | ); |
| 397 | 397 | |
| 398 | 398 | $discount->save(); |
| 399 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
| 399 | + do_action('getpaid_discount_metabox_save', $post_id, $discount); |
|
| 400 | 400 | } |
| 401 | 401 | } |
@@ -12,108 +12,108 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * The fee validation error. |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - public $fee_error; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Submission fees. |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - public $fees = array(); |
|
| 15 | + /** |
|
| 16 | + * The fee validation error. |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + public $fee_error; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Submission fees. |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + public $fees = array(); |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Class constructor |
|
| 29 | + * |
|
| 30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | + */ |
|
| 32 | + public function __construct( $submission ) { |
|
| 33 | + |
|
| 34 | + // Process any existing invoice fees. |
|
| 35 | + if ( $submission->has_invoice() ) { |
|
| 36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Process price fields. |
|
| 40 | + $data = $submission->get_data(); |
|
| 41 | + $payment_form = $submission->get_payment_form(); |
|
| 42 | + |
|
| 43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | + |
|
| 45 | + if ( 'price_input' == $element['type'] ) { |
|
| 46 | + $this->process_price_input( $element, $data ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ( 'price_select' == $element['type'] ) { |
|
| 50 | + $this->process_price_select( $element, $data ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Process a price input field. |
|
| 59 | + * |
|
| 60 | + * @param array $element |
|
| 61 | + * @param array $data |
|
| 62 | + */ |
|
| 63 | + public function process_price_input( $element, $data ) { |
|
| 64 | + |
|
| 65 | + // Abort if not passed. |
|
| 66 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 67 | + return; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 72 | + |
|
| 73 | + if ( $amount < $minimum ) { |
|
| 74 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $this->fees[ $element['label'] ] = array( |
|
| 78 | + 'name' => $element['label'], |
|
| 79 | + 'initial_fee' => $amount, |
|
| 80 | + 'recurring_fee' => 0, |
|
| 81 | + ); |
|
| 82 | + |
|
| 83 | + } |
|
| 26 | 84 | |
| 27 | 85 | /** |
| 28 | - * Class constructor |
|
| 29 | - * |
|
| 30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 31 | - */ |
|
| 32 | - public function __construct( $submission ) { |
|
| 33 | - |
|
| 34 | - // Process any existing invoice fees. |
|
| 35 | - if ( $submission->has_invoice() ) { |
|
| 36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Process price fields. |
|
| 40 | - $data = $submission->get_data(); |
|
| 41 | - $payment_form = $submission->get_payment_form(); |
|
| 42 | - |
|
| 43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
| 44 | - |
|
| 45 | - if ( 'price_input' == $element['type'] ) { |
|
| 46 | - $this->process_price_input( $element, $data ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ( 'price_select' == $element['type'] ) { |
|
| 50 | - $this->process_price_select( $element, $data ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Process a price input field. |
|
| 59 | - * |
|
| 60 | - * @param array $element |
|
| 61 | - * @param array $data |
|
| 62 | - */ |
|
| 63 | - public function process_price_input( $element, $data ) { |
|
| 64 | - |
|
| 65 | - // Abort if not passed. |
|
| 66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 67 | - return; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 72 | - |
|
| 73 | - if ( $amount < $minimum ) { |
|
| 74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $this->fees[ $element['label'] ] = array( |
|
| 78 | - 'name' => $element['label'], |
|
| 79 | - 'initial_fee' => $amount, |
|
| 80 | - 'recurring_fee' => 0, |
|
| 81 | - ); |
|
| 82 | - |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Process a price select field. |
|
| 87 | - * |
|
| 88 | - * @param array $element |
|
| 89 | - * @param array $data |
|
| 90 | - */ |
|
| 91 | - public function process_price_select( $element, $data ) { |
|
| 92 | - |
|
| 93 | - // Abort if not passed. |
|
| 94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
| 100 | - $total = 0; |
|
| 101 | - |
|
| 102 | - foreach ( $selected as $price ) { |
|
| 103 | - |
|
| 104 | - if ( ! isset( $options[ $price ] ) ) { |
|
| 105 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $total += (float) wpinv_sanitize_amount( $price ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $this->fees[ $element['label'] ] = array( |
|
| 112 | - 'name' => $element['label'], |
|
| 113 | - 'initial_fee' => $total, |
|
| 114 | - 'recurring_fee' => 0, |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - } |
|
| 86 | + * Process a price select field. |
|
| 87 | + * |
|
| 88 | + * @param array $element |
|
| 89 | + * @param array $data |
|
| 90 | + */ |
|
| 91 | + public function process_price_select( $element, $data ) { |
|
| 92 | + |
|
| 93 | + // Abort if not passed. |
|
| 94 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | + $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
| 100 | + $total = 0; |
|
| 101 | + |
|
| 102 | + foreach ( $selected as $price ) { |
|
| 103 | + |
|
| 104 | + if ( ! isset( $options[ $price ] ) ) { |
|
| 105 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $total += (float) wpinv_sanitize_amount( $price ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $this->fees[ $element['label'] ] = array( |
|
| 112 | + 'name' => $element['label'], |
|
| 113 | + 'initial_fee' => $total, |
|
| 114 | + 'recurring_fee' => 0, |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | } |
@@ -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 | * Payment form submission fees class |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
| 31 | 31 | */ |
| 32 | - public function __construct( $submission ) { |
|
| 32 | + public function __construct($submission) { |
|
| 33 | 33 | |
| 34 | 34 | // Process any existing invoice fees. |
| 35 | - if ( $submission->has_invoice() ) { |
|
| 35 | + if ($submission->has_invoice()) { |
|
| 36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | $data = $submission->get_data(); |
| 41 | 41 | $payment_form = $submission->get_payment_form(); |
| 42 | 42 | |
| 43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
| 43 | + foreach ($payment_form->get_elements() as $element) { |
|
| 44 | 44 | |
| 45 | - if ( 'price_input' == $element['type'] ) { |
|
| 46 | - $this->process_price_input( $element, $data ); |
|
| 45 | + if ('price_input' == $element['type']) { |
|
| 46 | + $this->process_price_input($element, $data); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if ( 'price_select' == $element['type'] ) { |
|
| 50 | - $this->process_price_select( $element, $data ); |
|
| 49 | + if ('price_select' == $element['type']) { |
|
| 50 | + $this->process_price_select($element, $data); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | } |
@@ -60,21 +60,21 @@ discard block |
||
| 60 | 60 | * @param array $element |
| 61 | 61 | * @param array $data |
| 62 | 62 | */ |
| 63 | - public function process_price_input( $element, $data ) { |
|
| 63 | + public function process_price_input($element, $data) { |
|
| 64 | 64 | |
| 65 | 65 | // Abort if not passed. |
| 66 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 66 | + if (empty($data[$element['id']])) { |
|
| 67 | 67 | return; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
| 71 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
| 70 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); |
|
| 71 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); |
|
| 72 | 72 | |
| 73 | - if ( $amount < $minimum ) { |
|
| 74 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), $minimum ) ); |
|
| 73 | + if ($amount < $minimum) { |
|
| 74 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), $minimum)); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $this->fees[ $element['label'] ] = array( |
|
| 77 | + $this->fees[$element['label']] = array( |
|
| 78 | 78 | 'name' => $element['label'], |
| 79 | 79 | 'initial_fee' => $amount, |
| 80 | 80 | 'recurring_fee' => 0, |
@@ -88,27 +88,27 @@ discard block |
||
| 88 | 88 | * @param array $element |
| 89 | 89 | * @param array $data |
| 90 | 90 | */ |
| 91 | - public function process_price_select( $element, $data ) { |
|
| 91 | + public function process_price_select($element, $data) { |
|
| 92 | 92 | |
| 93 | 93 | // Abort if not passed. |
| 94 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
| 94 | + if (empty($data[$element['id']])) { |
|
| 95 | 95 | return; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
| 99 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); |
|
| 98 | + $options = getpaid_convert_price_string_to_options($element['options']); |
|
| 99 | + $selected = wpinv_parse_list($data[$element['id']]); |
|
| 100 | 100 | $total = 0; |
| 101 | 101 | |
| 102 | - foreach ( $selected as $price ) { |
|
| 102 | + foreach ($selected as $price) { |
|
| 103 | 103 | |
| 104 | - if ( ! isset( $options[ $price ] ) ) { |
|
| 105 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
| 104 | + if (!isset($options[$price])) { |
|
| 105 | + throw new Exception(__('You have selected an invalid amount', 'invoicing')); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $total += (float) wpinv_sanitize_amount( $price ); |
|
| 108 | + $total += (float) wpinv_sanitize_amount($price); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $this->fees[ $element['label'] ] = array( |
|
| 111 | + $this->fees[$element['label']] = array( |
|
| 112 | 112 | 'name' => $element['label'], |
| 113 | 113 | 'initial_fee' => $total, |
| 114 | 114 | 'recurring_fee' => 0, |
@@ -12,231 +12,231 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission taxes. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $taxes = array(); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Initial tax. |
|
| 23 | - * @var float |
|
| 24 | - */ |
|
| 25 | - protected $initial_tax = 0; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Recurring tax. |
|
| 29 | - * @var float |
|
| 30 | - */ |
|
| 31 | - protected $recurring_tax = 0; |
|
| 15 | + /** |
|
| 16 | + * Submission taxes. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $taxes = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Initial tax. |
|
| 23 | + * @var float |
|
| 24 | + */ |
|
| 25 | + protected $initial_tax = 0; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Recurring tax. |
|
| 29 | + * @var float |
|
| 30 | + */ |
|
| 31 | + protected $recurring_tax = 0; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Class constructor |
|
| 35 | + * |
|
| 36 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 37 | + */ |
|
| 38 | + public function __construct( $submission ) { |
|
| 39 | + |
|
| 40 | + // Validate VAT number. |
|
| 41 | + $this->validate_vat( $submission ); |
|
| 42 | + |
|
| 43 | + foreach ( $submission->get_items() as $item ) { |
|
| 44 | + $this->process_item_tax( $item, $submission ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Process any existing invoice taxes. |
|
| 48 | + if ( $submission->has_invoice() ) { |
|
| 49 | + $this->taxes = $submission->get_invoice()->get_taxes(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + // Add VAT. |
|
| 53 | + $this->taxes['vat'] = array( |
|
| 54 | + 'name' => 'vat', |
|
| 55 | + 'initial_tax' => $this->initial_tax, |
|
| 56 | + 'recurring_tax' => $this->recurring_tax, |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Maybe process tax. |
|
| 63 | + * |
|
| 64 | + * @since 1.0.19 |
|
| 65 | + * @param GetPaid_Form_Item $item |
|
| 66 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 67 | + */ |
|
| 68 | + public function process_item_tax( $item, $submission ) { |
|
| 69 | + |
|
| 70 | + $rate = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() ); |
|
| 71 | + $price = $item->get_sub_total(); |
|
| 72 | + $item_tax = $price * $rate * 0.01; |
|
| 73 | + |
|
| 74 | + if ( wpinv_prices_include_tax() ) { |
|
| 75 | + $item_tax = $price - ( $price - $price * $rate * 0.01 ); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $this->initial_tax += $item_tax; |
|
| 79 | + |
|
| 80 | + if ( $item->is_recurring() ) { |
|
| 81 | + $this->recurring_tax += $item_tax; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Checks if the submission has a digital item. |
|
| 88 | + * |
|
| 89 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 90 | + * @since 1.0.19 |
|
| 91 | + * @return bool |
|
| 92 | + */ |
|
| 93 | + public function has_digital_item( $submission ) { |
|
| 94 | + |
|
| 95 | + foreach ( $submission->get_items() as $item ) { |
|
| 96 | + |
|
| 97 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
| 98 | + return true; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Checks if this is an eu store. |
|
| 108 | + * |
|
| 109 | + * @since 1.0.19 |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function is_eu_store() { |
|
| 113 | + return $this->is_eu_country( wpinv_get_default_country() ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Checks if this is an eu country. |
|
| 118 | + * |
|
| 119 | + * @param string $country |
|
| 120 | + * @since 1.0.19 |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + public function is_eu_country( $country ) { |
|
| 124 | + return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Checks if this is an eu purchase. |
|
| 129 | + * |
|
| 130 | + * @param string $customer_country |
|
| 131 | + * @since 1.0.19 |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + public function is_eu_transaction( $customer_country ) { |
|
| 135 | + return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Retrieves the vat number. |
|
| 140 | + * |
|
| 141 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 142 | + * @since 1.0.19 |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function get_vat_number( $submission ) { |
|
| 146 | + |
|
| 147 | + // Retrieve from the posted number. |
|
| 148 | + $vat_number = $submission->get_field( 'wpinv_vat_number' ); |
|
| 149 | + if ( ! empty( $vat_number ) ) { |
|
| 150 | + return wpinv_clean( $vat_number ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Retrieve from the invoice. |
|
| 154 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Retrieves the company. |
|
| 159 | + * |
|
| 160 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 161 | + * @since 1.0.19 |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public function get_company( $submission ) { |
|
| 165 | + |
|
| 166 | + // Retrieve from the posted data. |
|
| 167 | + $company = $submission->get_field( 'wpinv_company' ); |
|
| 168 | + if ( ! empty( $company ) ) { |
|
| 169 | + return wpinv_clean( $company ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // Retrieve from the invoice. |
|
| 173 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Checks if we requires a VAT number. |
|
| 178 | + * |
|
| 179 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 180 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 181 | + * @since 1.0.19 |
|
| 182 | + * @return string |
|
| 183 | + */ |
|
| 184 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 185 | + |
|
| 186 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 187 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 188 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
| 189 | + |
|
| 190 | + return $prevent_b2c && $is_eu; |
|
| 191 | + } |
|
| 32 | 192 | |
| 33 | 193 | /** |
| 34 | - * Class constructor |
|
| 35 | - * |
|
| 36 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 37 | - */ |
|
| 38 | - public function __construct( $submission ) { |
|
| 39 | - |
|
| 40 | - // Validate VAT number. |
|
| 41 | - $this->validate_vat( $submission ); |
|
| 42 | - |
|
| 43 | - foreach ( $submission->get_items() as $item ) { |
|
| 44 | - $this->process_item_tax( $item, $submission ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Process any existing invoice taxes. |
|
| 48 | - if ( $submission->has_invoice() ) { |
|
| 49 | - $this->taxes = $submission->get_invoice()->get_taxes(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - // Add VAT. |
|
| 53 | - $this->taxes['vat'] = array( |
|
| 54 | - 'name' => 'vat', |
|
| 55 | - 'initial_tax' => $this->initial_tax, |
|
| 56 | - 'recurring_tax' => $this->recurring_tax, |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Maybe process tax. |
|
| 63 | - * |
|
| 64 | - * @since 1.0.19 |
|
| 65 | - * @param GetPaid_Form_Item $item |
|
| 66 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 67 | - */ |
|
| 68 | - public function process_item_tax( $item, $submission ) { |
|
| 69 | - |
|
| 70 | - $rate = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() ); |
|
| 71 | - $price = $item->get_sub_total(); |
|
| 72 | - $item_tax = $price * $rate * 0.01; |
|
| 73 | - |
|
| 74 | - if ( wpinv_prices_include_tax() ) { |
|
| 75 | - $item_tax = $price - ( $price - $price * $rate * 0.01 ); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $this->initial_tax += $item_tax; |
|
| 79 | - |
|
| 80 | - if ( $item->is_recurring() ) { |
|
| 81 | - $this->recurring_tax += $item_tax; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Checks if the submission has a digital item. |
|
| 88 | - * |
|
| 89 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 90 | - * @since 1.0.19 |
|
| 91 | - * @return bool |
|
| 92 | - */ |
|
| 93 | - public function has_digital_item( $submission ) { |
|
| 94 | - |
|
| 95 | - foreach ( $submission->get_items() as $item ) { |
|
| 96 | - |
|
| 97 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 98 | - return true; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Checks if this is an eu store. |
|
| 108 | - * |
|
| 109 | - * @since 1.0.19 |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function is_eu_store() { |
|
| 113 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Checks if this is an eu country. |
|
| 118 | - * |
|
| 119 | - * @param string $country |
|
| 120 | - * @since 1.0.19 |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - public function is_eu_country( $country ) { |
|
| 124 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Checks if this is an eu purchase. |
|
| 129 | - * |
|
| 130 | - * @param string $customer_country |
|
| 131 | - * @since 1.0.19 |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - public function is_eu_transaction( $customer_country ) { |
|
| 135 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Retrieves the vat number. |
|
| 140 | - * |
|
| 141 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 142 | - * @since 1.0.19 |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function get_vat_number( $submission ) { |
|
| 146 | - |
|
| 147 | - // Retrieve from the posted number. |
|
| 148 | - $vat_number = $submission->get_field( 'wpinv_vat_number' ); |
|
| 149 | - if ( ! empty( $vat_number ) ) { |
|
| 150 | - return wpinv_clean( $vat_number ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Retrieve from the invoice. |
|
| 154 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Retrieves the company. |
|
| 159 | - * |
|
| 160 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 161 | - * @since 1.0.19 |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public function get_company( $submission ) { |
|
| 165 | - |
|
| 166 | - // Retrieve from the posted data. |
|
| 167 | - $company = $submission->get_field( 'wpinv_company' ); |
|
| 168 | - if ( ! empty( $company ) ) { |
|
| 169 | - return wpinv_clean( $company ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // Retrieve from the invoice. |
|
| 173 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Checks if we requires a VAT number. |
|
| 178 | - * |
|
| 179 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
| 180 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
| 181 | - * @since 1.0.19 |
|
| 182 | - * @return string |
|
| 183 | - */ |
|
| 184 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 185 | - |
|
| 186 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 187 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 188 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
| 189 | - |
|
| 190 | - return $prevent_b2c && $is_eu; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Validate VAT data. |
|
| 195 | - * |
|
| 196 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 197 | - * @since 1.0.19 |
|
| 198 | - */ |
|
| 199 | - public function validate_vat( $submission ) { |
|
| 200 | - |
|
| 201 | - $has_digital = $this->has_digital_item( $submission ); |
|
| 202 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 203 | - |
|
| 204 | - // Abort if we are not validating vat numbers. |
|
| 205 | - if ( ! $has_digital && ! $in_eu ) { |
|
| 194 | + * Validate VAT data. |
|
| 195 | + * |
|
| 196 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 197 | + * @since 1.0.19 |
|
| 198 | + */ |
|
| 199 | + public function validate_vat( $submission ) { |
|
| 200 | + |
|
| 201 | + $has_digital = $this->has_digital_item( $submission ); |
|
| 202 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 203 | + |
|
| 204 | + // Abort if we are not validating vat numbers. |
|
| 205 | + if ( ! $has_digital && ! $in_eu ) { |
|
| 206 | 206 | return; |
| 207 | - } |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - // Prepare variables. |
|
| 210 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 211 | - $company = $this->get_company( $submission ); |
|
| 212 | - $ip_country = WPInv_EUVat::get_country_by_ip(); |
|
| 209 | + // Prepare variables. |
|
| 210 | + $vat_number = $this->get_vat_number( $submission ); |
|
| 211 | + $company = $this->get_company( $submission ); |
|
| 212 | + $ip_country = WPInv_EUVat::get_country_by_ip(); |
|
| 213 | 213 | $is_eu = $this->is_eu_country( $submission->country ); |
| 214 | 214 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
| 215 | 215 | |
| 216 | - // If we're preventing business to consumer purchases, ensure |
|
| 217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 216 | + // If we're preventing business to consumer purchases, ensure |
|
| 217 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 218 | 218 | |
| 219 | - // Ensure that a vat number has been specified. |
|
| 220 | - throw new Exception( |
|
| 221 | - wp_sprintf( |
|
| 222 | - __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
| 223 | - getpaid_vat_name() |
|
| 224 | - ) |
|
| 225 | - ); |
|
| 219 | + // Ensure that a vat number has been specified. |
|
| 220 | + throw new Exception( |
|
| 221 | + wp_sprintf( |
|
| 222 | + __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
| 223 | + getpaid_vat_name() |
|
| 224 | + ) |
|
| 225 | + ); |
|
| 226 | 226 | |
| 227 | - } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
|
| 230 | - if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) { |
|
| 229 | + // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
|
| 230 | + if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) { |
|
| 231 | 231 | return; |
| 232 | - } |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country ); |
|
| 234 | + $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country ); |
|
| 235 | 235 | |
| 236 | - if ( is_string( $is_valid ) ) { |
|
| 237 | - throw new Exception( $is_valid ); |
|
| 238 | - } |
|
| 236 | + if ( is_string( $is_valid ) ) { |
|
| 237 | + throw new Exception( $is_valid ); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | 242 | } |
@@ -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 | * Payment form submission taxes class |
@@ -35,17 +35,17 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @param GetPaid_Payment_Form_Submission $submission |
| 37 | 37 | */ |
| 38 | - public function __construct( $submission ) { |
|
| 38 | + public function __construct($submission) { |
|
| 39 | 39 | |
| 40 | 40 | // Validate VAT number. |
| 41 | - $this->validate_vat( $submission ); |
|
| 41 | + $this->validate_vat($submission); |
|
| 42 | 42 | |
| 43 | - foreach ( $submission->get_items() as $item ) { |
|
| 44 | - $this->process_item_tax( $item, $submission ); |
|
| 43 | + foreach ($submission->get_items() as $item) { |
|
| 44 | + $this->process_item_tax($item, $submission); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Process any existing invoice taxes. |
| 48 | - if ( $submission->has_invoice() ) { |
|
| 48 | + if ($submission->has_invoice()) { |
|
| 49 | 49 | $this->taxes = $submission->get_invoice()->get_taxes(); |
| 50 | 50 | } |
| 51 | 51 | |
@@ -65,19 +65,19 @@ discard block |
||
| 65 | 65 | * @param GetPaid_Form_Item $item |
| 66 | 66 | * @param GetPaid_Payment_Form_Submission $submission |
| 67 | 67 | */ |
| 68 | - public function process_item_tax( $item, $submission ) { |
|
| 68 | + public function process_item_tax($item, $submission) { |
|
| 69 | 69 | |
| 70 | - $rate = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() ); |
|
| 70 | + $rate = wpinv_get_tax_rate($submission->country, $submission->state, $item->get_id()); |
|
| 71 | 71 | $price = $item->get_sub_total(); |
| 72 | 72 | $item_tax = $price * $rate * 0.01; |
| 73 | 73 | |
| 74 | - if ( wpinv_prices_include_tax() ) { |
|
| 75 | - $item_tax = $price - ( $price - $price * $rate * 0.01 ); |
|
| 74 | + if (wpinv_prices_include_tax()) { |
|
| 75 | + $item_tax = $price - ($price - $price * $rate * 0.01); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | $this->initial_tax += $item_tax; |
| 79 | 79 | |
| 80 | - if ( $item->is_recurring() ) { |
|
| 80 | + if ($item->is_recurring()) { |
|
| 81 | 81 | $this->recurring_tax += $item_tax; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | * @since 1.0.19 |
| 91 | 91 | * @return bool |
| 92 | 92 | */ |
| 93 | - public function has_digital_item( $submission ) { |
|
| 93 | + public function has_digital_item($submission) { |
|
| 94 | 94 | |
| 95 | - foreach ( $submission->get_items() as $item ) { |
|
| 95 | + foreach ($submission->get_items() as $item) { |
|
| 96 | 96 | |
| 97 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
| 97 | + if ('digital' == $item->get_vat_rule()) { |
|
| 98 | 98 | return true; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return bool |
| 111 | 111 | */ |
| 112 | 112 | public function is_eu_store() { |
| 113 | - return $this->is_eu_country( wpinv_get_default_country() ); |
|
| 113 | + return $this->is_eu_country(wpinv_get_default_country()); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | * @since 1.0.19 |
| 121 | 121 | * @return bool |
| 122 | 122 | */ |
| 123 | - public function is_eu_country( $country ) { |
|
| 124 | - return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country ); |
|
| 123 | + public function is_eu_country($country) { |
|
| 124 | + return getpaid_is_eu_state($country) || getpaid_is_gst_country($country); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | * @since 1.0.19 |
| 132 | 132 | * @return bool |
| 133 | 133 | */ |
| 134 | - public function is_eu_transaction( $customer_country ) { |
|
| 135 | - return $this->is_eu_country( $customer_country ) && $this->is_eu_store(); |
|
| 134 | + public function is_eu_transaction($customer_country) { |
|
| 135 | + return $this->is_eu_country($customer_country) && $this->is_eu_store(); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -142,12 +142,12 @@ discard block |
||
| 142 | 142 | * @since 1.0.19 |
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | - public function get_vat_number( $submission ) { |
|
| 145 | + public function get_vat_number($submission) { |
|
| 146 | 146 | |
| 147 | 147 | // Retrieve from the posted number. |
| 148 | - $vat_number = $submission->get_field( 'wpinv_vat_number' ); |
|
| 149 | - if ( ! empty( $vat_number ) ) { |
|
| 150 | - return wpinv_clean( $vat_number ); |
|
| 148 | + $vat_number = $submission->get_field('wpinv_vat_number'); |
|
| 149 | + if (!empty($vat_number)) { |
|
| 150 | + return wpinv_clean($vat_number); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Retrieve from the invoice. |
@@ -161,12 +161,12 @@ discard block |
||
| 161 | 161 | * @since 1.0.19 |
| 162 | 162 | * @return string |
| 163 | 163 | */ |
| 164 | - public function get_company( $submission ) { |
|
| 164 | + public function get_company($submission) { |
|
| 165 | 165 | |
| 166 | 166 | // Retrieve from the posted data. |
| 167 | - $company = $submission->get_field( 'wpinv_company' ); |
|
| 168 | - if ( ! empty( $company ) ) { |
|
| 169 | - return wpinv_clean( $company ); |
|
| 167 | + $company = $submission->get_field('wpinv_company'); |
|
| 168 | + if (!empty($company)) { |
|
| 169 | + return wpinv_clean($company); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // Retrieve from the invoice. |
@@ -181,10 +181,10 @@ discard block |
||
| 181 | 181 | * @since 1.0.19 |
| 182 | 182 | * @return string |
| 183 | 183 | */ |
| 184 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
| 184 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
| 185 | 185 | |
| 186 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
| 187 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
| 186 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
| 187 | + $prevent_b2c = !empty($prevent_b2c); |
|
| 188 | 188 | $is_eu = $ip_in_eu || $country_in_eu; |
| 189 | 189 | |
| 190 | 190 | return $prevent_b2c && $is_eu; |
@@ -196,30 +196,30 @@ discard block |
||
| 196 | 196 | * @param GetPaid_Payment_Form_Submission $submission |
| 197 | 197 | * @since 1.0.19 |
| 198 | 198 | */ |
| 199 | - public function validate_vat( $submission ) { |
|
| 199 | + public function validate_vat($submission) { |
|
| 200 | 200 | |
| 201 | - $has_digital = $this->has_digital_item( $submission ); |
|
| 202 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
| 201 | + $has_digital = $this->has_digital_item($submission); |
|
| 202 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
| 203 | 203 | |
| 204 | 204 | // Abort if we are not validating vat numbers. |
| 205 | - if ( ! $has_digital && ! $in_eu ) { |
|
| 205 | + if (!$has_digital && !$in_eu) { |
|
| 206 | 206 | return; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | // Prepare variables. |
| 210 | - $vat_number = $this->get_vat_number( $submission ); |
|
| 211 | - $company = $this->get_company( $submission ); |
|
| 210 | + $vat_number = $this->get_vat_number($submission); |
|
| 211 | + $company = $this->get_company($submission); |
|
| 212 | 212 | $ip_country = WPInv_EUVat::get_country_by_ip(); |
| 213 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
| 214 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
| 213 | + $is_eu = $this->is_eu_country($submission->country); |
|
| 214 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
| 215 | 215 | |
| 216 | 216 | // If we're preventing business to consumer purchases, ensure |
| 217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
| 217 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
| 218 | 218 | |
| 219 | 219 | // Ensure that a vat number has been specified. |
| 220 | 220 | throw new Exception( |
| 221 | 221 | wp_sprintf( |
| 222 | - __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ), |
|
| 222 | + __('Please enter your %s number to verify your purchase is by an EU business.', 'invoicing'), |
|
| 223 | 223 | getpaid_vat_name() |
| 224 | 224 | ) |
| 225 | 225 | ); |
@@ -227,14 +227,14 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // Abort if we are not validating vat (vat number should exist, user should be in eu and business too). |
| 230 | - if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) { |
|
| 230 | + if (!$is_eu || !$in_eu || empty($vat_number)) { |
|
| 231 | 231 | return; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country ); |
|
| 234 | + $is_valid = WPInv_EUVat::validate_vat_number($vat_number, $company, $submission->country); |
|
| 235 | 235 | |
| 236 | - if ( is_string( $is_valid ) ) { |
|
| 237 | - throw new Exception( $is_valid ); |
|
| 236 | + if (is_string($is_valid)) { |
|
| 237 | + throw new Exception($is_valid); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | } |
@@ -12,189 +12,189 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Discount { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission discounts. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $discounts = array(); |
|
| 15 | + /** |
|
| 16 | + * Submission discounts. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $discounts = array(); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + * @param float $initial_total |
|
| 26 | + * @param float $recurring_total |
|
| 27 | + */ |
|
| 28 | + public function __construct( $submission, $initial_total, $recurring_total ) { |
|
| 29 | + |
|
| 30 | + // Process any existing invoice discounts. |
|
| 31 | + if ( $submission->has_invoice() ) { |
|
| 32 | + $this->discounts = $submission->get_invoice()->get_discounts(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + // Do we have a discount? |
|
| 36 | + $discount = $submission->get_field( 'discount' ); |
|
| 37 | + |
|
| 38 | + if ( empty( $discount ) ) { |
|
| 39 | + |
|
| 40 | + if ( isset( $this->discounts['discount_code'] ) ) { |
|
| 41 | + unset( $this->discounts['discount_code'] ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Processes the discount code. |
|
| 48 | + $amount = max( $initial_total, $recurring_total ); |
|
| 49 | + $this->process_discount( $submission, $discount, $amount ); |
|
| 50 | + |
|
| 51 | + } |
|
| 20 | 52 | |
| 21 | 53 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - * @param float $initial_total |
|
| 26 | - * @param float $recurring_total |
|
| 27 | - */ |
|
| 28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
| 29 | - |
|
| 30 | - // Process any existing invoice discounts. |
|
| 31 | - if ( $submission->has_invoice() ) { |
|
| 32 | - $this->discounts = $submission->get_invoice()->get_discounts(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - // Do we have a discount? |
|
| 36 | - $discount = $submission->get_field( 'discount' ); |
|
| 37 | - |
|
| 38 | - if ( empty( $discount ) ) { |
|
| 39 | - |
|
| 40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
| 41 | - unset( $this->discounts['discount_code'] ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - return; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Processes the discount code. |
|
| 48 | - $amount = max( $initial_total, $recurring_total ); |
|
| 49 | - $this->process_discount( $submission, $discount, $amount ); |
|
| 50 | - |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Processes a submission discount. |
|
| 55 | - * |
|
| 56 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 57 | - * @param string $discount |
|
| 58 | - * @param float $amount |
|
| 59 | - */ |
|
| 60 | - public function process_discount( $submission, $discount, $amount ) { |
|
| 61 | - |
|
| 62 | - // Fetch the discount. |
|
| 63 | - $discount = new WPInv_Discount( $discount ); |
|
| 64 | - |
|
| 65 | - // Ensure it is active. |
|
| 54 | + * Processes a submission discount. |
|
| 55 | + * |
|
| 56 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 57 | + * @param string $discount |
|
| 58 | + * @param float $amount |
|
| 59 | + */ |
|
| 60 | + public function process_discount( $submission, $discount, $amount ) { |
|
| 61 | + |
|
| 62 | + // Fetch the discount. |
|
| 63 | + $discount = new WPInv_Discount( $discount ); |
|
| 64 | + |
|
| 65 | + // Ensure it is active. |
|
| 66 | 66 | if ( ! $this->is_discount_active( $discount ) ) { |
| 67 | - throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // Exceeded limit. |
|
| 71 | - if ( $discount->has_exceeded_limit() ) { |
|
| 72 | - throw new Exception( __( 'This discount code has been used up', 'invoicing' ) ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // Validate usages. |
|
| 76 | - $this->validate_single_use_discount( $submission, $discount ); |
|
| 77 | - |
|
| 78 | - // Validate amount. |
|
| 79 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
| 80 | - |
|
| 81 | - // Save the discount. |
|
| 82 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Validates a single use discount. |
|
| 87 | - * |
|
| 88 | - * @param WPInv_Discount $discount |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function is_discount_active( $discount ) { |
|
| 92 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Returns a user's id or email. |
|
| 97 | - * |
|
| 98 | - * @param string $email |
|
| 99 | - * @return int|string|false |
|
| 100 | - */ |
|
| 101 | - public function get_user_id_or_email( $email ) { |
|
| 102 | - |
|
| 103 | - if ( is_user_logged_in() ) { |
|
| 104 | - return get_current_user_id(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Validates a single use discount. |
|
| 112 | - * |
|
| 113 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 114 | - * @param WPInv_Discount $discount |
|
| 115 | - */ |
|
| 116 | - public function validate_single_use_discount( $submission, $discount ) { |
|
| 117 | - |
|
| 118 | - // Abort if it is not a single use discount. |
|
| 119 | - if ( ! $discount->is_single_use() ) { |
|
| 120 | - return; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // Ensure there is a valid billing email. |
|
| 124 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
| 125 | - |
|
| 126 | - if ( empty( $user ) ) { |
|
| 127 | - throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // Has the user used this discount code before? |
|
| 131 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
| 132 | - throw new Exception( __( 'You have already used this discount', 'invoicing' ) ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Validates the discount's amount. |
|
| 139 | - * |
|
| 140 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 141 | - * @param WPInv_Discount $discount |
|
| 142 | - * @param float $amount |
|
| 143 | - */ |
|
| 144 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
| 145 | - |
|
| 146 | - // Validate minimum amount. |
|
| 147 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
| 148 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
| 149 | - throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // Validate the maximum amount. |
|
| 153 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
| 154 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
| 155 | - throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Calculates the discount code's amount. |
|
| 162 | - * |
|
| 163 | - * Ensure that the discount exists and has been validated before calling this method. |
|
| 164 | - * |
|
| 165 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 166 | - * @param WPInv_Discount $discount |
|
| 167 | - * @return array |
|
| 168 | - */ |
|
| 169 | - public function calculate_discount( $submission, $discount ) { |
|
| 170 | - |
|
| 171 | - $initial_discount = 0; |
|
| 172 | - $recurring_discount = 0; |
|
| 173 | - |
|
| 174 | - foreach ( $submission->get_items() as $item ) { |
|
| 175 | - |
|
| 176 | - // Abort if it is not valid for this item. |
|
| 177 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 178 | - continue; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // Calculate the initial amount... |
|
| 182 | - $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 183 | - |
|
| 184 | - // ... and maybe the recurring amount. |
|
| 185 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 186 | - $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return array( |
|
| 192 | - 'name' => 'discount_code', |
|
| 193 | - 'discount_code' => $discount->get_code(), |
|
| 194 | - 'initial_discount' => $initial_discount, |
|
| 195 | - 'recurring_discount' => $recurring_discount, |
|
| 196 | - ); |
|
| 197 | - |
|
| 198 | - } |
|
| 67 | + throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // Exceeded limit. |
|
| 71 | + if ( $discount->has_exceeded_limit() ) { |
|
| 72 | + throw new Exception( __( 'This discount code has been used up', 'invoicing' ) ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // Validate usages. |
|
| 76 | + $this->validate_single_use_discount( $submission, $discount ); |
|
| 77 | + |
|
| 78 | + // Validate amount. |
|
| 79 | + $this->validate_discount_amount( $submission, $discount, $amount ); |
|
| 80 | + |
|
| 81 | + // Save the discount. |
|
| 82 | + $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Validates a single use discount. |
|
| 87 | + * |
|
| 88 | + * @param WPInv_Discount $discount |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function is_discount_active( $discount ) { |
|
| 92 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Returns a user's id or email. |
|
| 97 | + * |
|
| 98 | + * @param string $email |
|
| 99 | + * @return int|string|false |
|
| 100 | + */ |
|
| 101 | + public function get_user_id_or_email( $email ) { |
|
| 102 | + |
|
| 103 | + if ( is_user_logged_in() ) { |
|
| 104 | + return get_current_user_id(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return empty( $email ) ? false : sanitize_email( $email ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Validates a single use discount. |
|
| 112 | + * |
|
| 113 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 114 | + * @param WPInv_Discount $discount |
|
| 115 | + */ |
|
| 116 | + public function validate_single_use_discount( $submission, $discount ) { |
|
| 117 | + |
|
| 118 | + // Abort if it is not a single use discount. |
|
| 119 | + if ( ! $discount->is_single_use() ) { |
|
| 120 | + return; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // Ensure there is a valid billing email. |
|
| 124 | + $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
| 125 | + |
|
| 126 | + if ( empty( $user ) ) { |
|
| 127 | + throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // Has the user used this discount code before? |
|
| 131 | + if ( ! $discount->is_valid_for_user( $user ) ) { |
|
| 132 | + throw new Exception( __( 'You have already used this discount', 'invoicing' ) ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Validates the discount's amount. |
|
| 139 | + * |
|
| 140 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 141 | + * @param WPInv_Discount $discount |
|
| 142 | + * @param float $amount |
|
| 143 | + */ |
|
| 144 | + public function validate_discount_amount( $submission, $discount, $amount ) { |
|
| 145 | + |
|
| 146 | + // Validate minimum amount. |
|
| 147 | + if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
| 148 | + $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
| 149 | + throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // Validate the maximum amount. |
|
| 153 | + if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
| 154 | + $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
| 155 | + throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Calculates the discount code's amount. |
|
| 162 | + * |
|
| 163 | + * Ensure that the discount exists and has been validated before calling this method. |
|
| 164 | + * |
|
| 165 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 166 | + * @param WPInv_Discount $discount |
|
| 167 | + * @return array |
|
| 168 | + */ |
|
| 169 | + public function calculate_discount( $submission, $discount ) { |
|
| 170 | + |
|
| 171 | + $initial_discount = 0; |
|
| 172 | + $recurring_discount = 0; |
|
| 173 | + |
|
| 174 | + foreach ( $submission->get_items() as $item ) { |
|
| 175 | + |
|
| 176 | + // Abort if it is not valid for this item. |
|
| 177 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 178 | + continue; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // Calculate the initial amount... |
|
| 182 | + $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 183 | + |
|
| 184 | + // ... and maybe the recurring amount. |
|
| 185 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 186 | + $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return array( |
|
| 192 | + 'name' => 'discount_code', |
|
| 193 | + 'discount_code' => $discount->get_code(), |
|
| 194 | + 'initial_discount' => $initial_discount, |
|
| 195 | + 'recurring_discount' => $recurring_discount, |
|
| 196 | + ); |
|
| 197 | + |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | 200 | } |
@@ -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 | * Payment form submission discount class |
@@ -25,28 +25,28 @@ discard block |
||
| 25 | 25 | * @param float $initial_total |
| 26 | 26 | * @param float $recurring_total |
| 27 | 27 | */ |
| 28 | - public function __construct( $submission, $initial_total, $recurring_total ) { |
|
| 28 | + public function __construct($submission, $initial_total, $recurring_total) { |
|
| 29 | 29 | |
| 30 | 30 | // Process any existing invoice discounts. |
| 31 | - if ( $submission->has_invoice() ) { |
|
| 31 | + if ($submission->has_invoice()) { |
|
| 32 | 32 | $this->discounts = $submission->get_invoice()->get_discounts(); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // Do we have a discount? |
| 36 | - $discount = $submission->get_field( 'discount' ); |
|
| 36 | + $discount = $submission->get_field('discount'); |
|
| 37 | 37 | |
| 38 | - if ( empty( $discount ) ) { |
|
| 38 | + if (empty($discount)) { |
|
| 39 | 39 | |
| 40 | - if ( isset( $this->discounts['discount_code'] ) ) { |
|
| 41 | - unset( $this->discounts['discount_code'] ); |
|
| 40 | + if (isset($this->discounts['discount_code'])) { |
|
| 41 | + unset($this->discounts['discount_code']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Processes the discount code. |
| 48 | - $amount = max( $initial_total, $recurring_total ); |
|
| 49 | - $this->process_discount( $submission, $discount, $amount ); |
|
| 48 | + $amount = max($initial_total, $recurring_total); |
|
| 49 | + $this->process_discount($submission, $discount, $amount); |
|
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
@@ -57,29 +57,29 @@ discard block |
||
| 57 | 57 | * @param string $discount |
| 58 | 58 | * @param float $amount |
| 59 | 59 | */ |
| 60 | - public function process_discount( $submission, $discount, $amount ) { |
|
| 60 | + public function process_discount($submission, $discount, $amount) { |
|
| 61 | 61 | |
| 62 | 62 | // Fetch the discount. |
| 63 | - $discount = new WPInv_Discount( $discount ); |
|
| 63 | + $discount = new WPInv_Discount($discount); |
|
| 64 | 64 | |
| 65 | 65 | // Ensure it is active. |
| 66 | - if ( ! $this->is_discount_active( $discount ) ) { |
|
| 67 | - throw new Exception( __( 'Invalid or expired discount code', 'invoicing' ) ); |
|
| 66 | + if (!$this->is_discount_active($discount)) { |
|
| 67 | + throw new Exception(__('Invalid or expired discount code', 'invoicing')); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Exceeded limit. |
| 71 | - if ( $discount->has_exceeded_limit() ) { |
|
| 72 | - throw new Exception( __( 'This discount code has been used up', 'invoicing' ) ); |
|
| 71 | + if ($discount->has_exceeded_limit()) { |
|
| 72 | + throw new Exception(__('This discount code has been used up', 'invoicing')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // Validate usages. |
| 76 | - $this->validate_single_use_discount( $submission, $discount ); |
|
| 76 | + $this->validate_single_use_discount($submission, $discount); |
|
| 77 | 77 | |
| 78 | 78 | // Validate amount. |
| 79 | - $this->validate_discount_amount( $submission, $discount, $amount ); |
|
| 79 | + $this->validate_discount_amount($submission, $discount, $amount); |
|
| 80 | 80 | |
| 81 | 81 | // Save the discount. |
| 82 | - $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount ); |
|
| 82 | + $this->discounts['discount_code'] = $this->calculate_discount($submission, $discount); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | * @param WPInv_Discount $discount |
| 89 | 89 | * @return bool |
| 90 | 90 | */ |
| 91 | - public function is_discount_active( $discount ) { |
|
| 92 | - return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired(); |
|
| 91 | + public function is_discount_active($discount) { |
|
| 92 | + return $discount->exists() && $discount->is_active() && $discount->has_started() && !$discount->is_expired(); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -98,13 +98,13 @@ discard block |
||
| 98 | 98 | * @param string $email |
| 99 | 99 | * @return int|string|false |
| 100 | 100 | */ |
| 101 | - public function get_user_id_or_email( $email ) { |
|
| 101 | + public function get_user_id_or_email($email) { |
|
| 102 | 102 | |
| 103 | - if ( is_user_logged_in() ) { |
|
| 103 | + if (is_user_logged_in()) { |
|
| 104 | 104 | return get_current_user_id(); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - return empty( $email ) ? false : sanitize_email( $email ); |
|
| 107 | + return empty($email) ? false : sanitize_email($email); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -113,23 +113,23 @@ discard block |
||
| 113 | 113 | * @param GetPaid_Payment_Form_Submission $submission |
| 114 | 114 | * @param WPInv_Discount $discount |
| 115 | 115 | */ |
| 116 | - public function validate_single_use_discount( $submission, $discount ) { |
|
| 116 | + public function validate_single_use_discount($submission, $discount) { |
|
| 117 | 117 | |
| 118 | 118 | // Abort if it is not a single use discount. |
| 119 | - if ( ! $discount->is_single_use() ) { |
|
| 119 | + if (!$discount->is_single_use()) { |
|
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // Ensure there is a valid billing email. |
| 124 | - $user = $this->get_user_id_or_email( $submission->get_billing_email() ); |
|
| 124 | + $user = $this->get_user_id_or_email($submission->get_billing_email()); |
|
| 125 | 125 | |
| 126 | - if ( empty( $user ) ) { |
|
| 127 | - throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) ); |
|
| 126 | + if (empty($user)) { |
|
| 127 | + throw new Exception(__('You need to either log in or enter your billing email before applying this discount', 'invoicing')); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Has the user used this discount code before? |
| 131 | - if ( ! $discount->is_valid_for_user( $user ) ) { |
|
| 132 | - throw new Exception( __( 'You have already used this discount', 'invoicing' ) ); |
|
| 131 | + if (!$discount->is_valid_for_user($user)) { |
|
| 132 | + throw new Exception(__('You have already used this discount', 'invoicing')); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | } |
@@ -141,18 +141,18 @@ discard block |
||
| 141 | 141 | * @param WPInv_Discount $discount |
| 142 | 142 | * @param float $amount |
| 143 | 143 | */ |
| 144 | - public function validate_discount_amount( $submission, $discount, $amount ) { |
|
| 144 | + public function validate_discount_amount($submission, $discount, $amount) { |
|
| 145 | 145 | |
| 146 | 146 | // Validate minimum amount. |
| 147 | - if ( ! $discount->is_minimum_amount_met( $amount ) ) { |
|
| 148 | - $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() ); |
|
| 149 | - throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) ); |
|
| 147 | + if (!$discount->is_minimum_amount_met($amount)) { |
|
| 148 | + $min = wpinv_price($discount->get_minimum_total(), $submission->get_currency()); |
|
| 149 | + throw new Exception(sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min)); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // Validate the maximum amount. |
| 153 | - if ( ! $discount->is_maximum_amount_met( $amount ) ) { |
|
| 154 | - $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() ); |
|
| 155 | - throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) ); |
|
| 153 | + if (!$discount->is_maximum_amount_met($amount)) { |
|
| 154 | + $max = wpinv_price($discount->get_maximum_total(), $submission->get_currency()); |
|
| 155 | + throw new Exception(sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max)); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | } |
@@ -166,24 +166,24 @@ discard block |
||
| 166 | 166 | * @param WPInv_Discount $discount |
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | - public function calculate_discount( $submission, $discount ) { |
|
| 169 | + public function calculate_discount($submission, $discount) { |
|
| 170 | 170 | |
| 171 | 171 | $initial_discount = 0; |
| 172 | 172 | $recurring_discount = 0; |
| 173 | 173 | |
| 174 | - foreach ( $submission->get_items() as $item ) { |
|
| 174 | + foreach ($submission->get_items() as $item) { |
|
| 175 | 175 | |
| 176 | 176 | // Abort if it is not valid for this item. |
| 177 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 177 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
| 178 | 178 | continue; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // Calculate the initial amount... |
| 182 | - $initial_discount += $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 182 | + $initial_discount += $discount->get_discounted_amount($item->get_sub_total()); |
|
| 183 | 183 | |
| 184 | 184 | // ... and maybe the recurring amount. |
| 185 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 186 | - $recurring_discount += $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 185 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
| 186 | + $recurring_discount += $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | } |
@@ -7,33 +7,33 @@ |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | ?> |
| 13 | 13 | |
| 14 | 14 | <div class='form-group'> |
| 15 | 15 | <label class="d-block"> |
| 16 | - <span><?php esc_html_e( 'Alert Text', 'invoicing' ); ?></span> |
|
| 16 | + <span><?php esc_html_e('Alert Text', 'invoicing'); ?></span> |
|
| 17 | 17 | <textarea v-model='active_form_element.text' class='form-control' rows='3'></textarea> |
| 18 | 18 | </label> |
| 19 | 19 | </div> |
| 20 | 20 | |
| 21 | 21 | <div class='form-group form-check'> |
| 22 | 22 | <input :id="active_form_element.id + '_edit_dismissible'" v-model='active_form_element.dismissible' type='checkbox' class='form-check-input' /> |
| 23 | - <label class='form-check-label' :for="active_form_element.id + '_edit_dismissible'"><?php esc_html_e( 'Is Dismissible?', 'invoicing' ); ?></label> |
|
| 23 | + <label class='form-check-label' :for="active_form_element.id + '_edit_dismissible'"><?php esc_html_e('Is Dismissible?', 'invoicing'); ?></label> |
|
| 24 | 24 | </div> |
| 25 | 25 | |
| 26 | 26 | <div class='form-group'> |
| 27 | - <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e( 'Alert Type', 'invoicing' ) ?></label> |
|
| 27 | + <label :for="active_form_element.id + '_edit_type'"><?php esc_html_e('Alert Type', 'invoicing') ?></label> |
|
| 28 | 28 | <select class='form-control custom-select' :id="active_form_element.id + '_edit_type'" v-model='active_form_element.class'> |
| 29 | - <option value='alert-primary'><?php esc_html_e( 'Primary', 'invoicing' ); ?></option> |
|
| 30 | - <option value='alert-secondary'><?php esc_html_e( 'Secondary', 'invoicing' ); ?></option> |
|
| 31 | - <option value='alert-success'><?php esc_html_e( 'Success', 'invoicing' ); ?></option> |
|
| 32 | - <option value='alert-danger'><?php esc_html_e( 'Danger', 'invoicing' ); ?></option> |
|
| 33 | - <option value='alert-warning'><?php esc_html_e( 'Warning', 'invoicing' ); ?></option> |
|
| 34 | - <option value='alert-info'><?php esc_html_e( 'Info', 'invoicing' ); ?></option> |
|
| 35 | - <option value='alert-light'><?php esc_html_e( 'Light', 'invoicing' ); ?></option> |
|
| 36 | - <option value='alert-dark'><?php esc_html_e( 'Dark', 'invoicing' ); ?></option> |
|
| 37 | - <option value='alert-link'><?php esc_html_e( 'Link', 'invoicing' ); ?></option> |
|
| 29 | + <option value='alert-primary'><?php esc_html_e('Primary', 'invoicing'); ?></option> |
|
| 30 | + <option value='alert-secondary'><?php esc_html_e('Secondary', 'invoicing'); ?></option> |
|
| 31 | + <option value='alert-success'><?php esc_html_e('Success', 'invoicing'); ?></option> |
|
| 32 | + <option value='alert-danger'><?php esc_html_e('Danger', 'invoicing'); ?></option> |
|
| 33 | + <option value='alert-warning'><?php esc_html_e('Warning', 'invoicing'); ?></option> |
|
| 34 | + <option value='alert-info'><?php esc_html_e('Info', 'invoicing'); ?></option> |
|
| 35 | + <option value='alert-light'><?php esc_html_e('Light', 'invoicing'); ?></option> |
|
| 36 | + <option value='alert-dark'><?php esc_html_e('Dark', 'invoicing'); ?></option> |
|
| 37 | + <option value='alert-link'><?php esc_html_e('Link', 'invoicing'); ?></option> |
|
| 38 | 38 | </select> |
| 39 | 39 | </div> |
@@ -7,30 +7,30 @@ |
||
| 7 | 7 | * @version 1.0.19 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -defined( 'ABSPATH' ) || exit; |
|
| 10 | +defined('ABSPATH') || exit; |
|
| 11 | 11 | |
| 12 | 12 | // Set the currency position. |
| 13 | 13 | $position = wpinv_currency_position(); |
| 14 | 14 | |
| 15 | -if ( $position == 'left_space' ) { |
|
| 15 | +if ($position == 'left_space') { |
|
| 16 | 16 | $position = 'left'; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -if ( $position == 'right_space' ) { |
|
| 19 | +if ($position == 'right_space') { |
|
| 20 | 20 | $position = 'right'; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | echo aui()->input( |
| 24 | 24 | array( |
| 25 | - 'name' => esc_attr( $id ), |
|
| 26 | - 'id' => esc_attr( $id ) . uniqid( '_' ), |
|
| 27 | - 'placeholder' => empty( $placeholder ) ? wpinv_format_amount(0) : wpinv_format_amount( $placeholder ), |
|
| 28 | - 'value' => empty( $value ) ? wpinv_format_amount(0) : wpinv_format_amount( $value ), |
|
| 29 | - 'label' => empty( $label ) ? '' : wp_kses_post( $label ), |
|
| 25 | + 'name' => esc_attr($id), |
|
| 26 | + 'id' => esc_attr($id) . uniqid('_'), |
|
| 27 | + 'placeholder' => empty($placeholder) ? wpinv_format_amount(0) : wpinv_format_amount($placeholder), |
|
| 28 | + 'value' => empty($value) ? wpinv_format_amount(0) : wpinv_format_amount($value), |
|
| 29 | + 'label' => empty($label) ? '' : wp_kses_post($label), |
|
| 30 | 30 | 'label_type' => 'vertical', |
| 31 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
| 32 | - 'input_group_right' => $position == 'right' ? wpinv_currency_symbol( $form->get_currency() ) : '', |
|
| 33 | - 'input_group_left' => $position == 'left' ? wpinv_currency_symbol( $form->get_currency() ) : '', |
|
| 31 | + 'help_text' => empty($description) ? '' : wp_kses_post($description), |
|
| 32 | + 'input_group_right' => $position == 'right' ? wpinv_currency_symbol($form->get_currency()) : '', |
|
| 33 | + 'input_group_left' => $position == 'left' ? wpinv_currency_symbol($form->get_currency()) : '', |
|
| 34 | 34 | 'class' => 'getpaid-refresh-on-change', |
| 35 | 35 | ) |
| 36 | 36 | ); |
@@ -13,616 +13,616 @@ discard block |
||
| 13 | 13 | class GetPaid_Post_Types_Admin { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Hook in methods. |
|
| 17 | - */ |
|
| 18 | - public static function init() { |
|
| 19 | - |
|
| 20 | - // Init metaboxes. |
|
| 21 | - GetPaid_Metaboxes::init(); |
|
| 22 | - |
|
| 23 | - // Filter the post updated messages. |
|
| 24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | - |
|
| 26 | - // Filter post actions. |
|
| 27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | - |
|
| 29 | - // Invoice table columns. |
|
| 30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 32 | - |
|
| 33 | - // Items table columns. |
|
| 34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 40 | - |
|
| 41 | - // Payment forms columns. |
|
| 42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 45 | - |
|
| 46 | - // Discount table columns. |
|
| 47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 48 | - |
|
| 49 | - // Deleting posts. |
|
| 50 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 51 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Post updated messages. |
|
| 56 | - */ |
|
| 57 | - public static function post_updated_messages( $messages ) { |
|
| 58 | - global $post; |
|
| 59 | - |
|
| 60 | - $messages['wpi_discount'] = array( |
|
| 61 | - 0 => '', |
|
| 62 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 63 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 64 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 65 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 66 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 67 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 68 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 69 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 70 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 71 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 72 | - ); |
|
| 73 | - |
|
| 74 | - $messages['wpi_payment_form'] = array( |
|
| 75 | - 0 => '', |
|
| 76 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 77 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 78 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 79 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 80 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 81 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 82 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 83 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 84 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 85 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 86 | - ); |
|
| 87 | - |
|
| 88 | - return $messages; |
|
| 89 | - |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Post row actions. |
|
| 94 | - */ |
|
| 95 | - public static function post_row_actions( $actions, $post ) { |
|
| 96 | - |
|
| 97 | - $post = get_post( $post ); |
|
| 98 | - |
|
| 99 | - // We do not want to edit the default payment form. |
|
| 100 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
| 101 | - unset( $actions['trash'] ); |
|
| 102 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $actions; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Returns an array of invoice table columns. |
|
| 110 | - */ |
|
| 111 | - public static function invoice_columns( $columns ) { |
|
| 112 | - |
|
| 113 | - $columns = array( |
|
| 114 | - 'cb' => $columns['cb'], |
|
| 115 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
| 116 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 117 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
| 118 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 119 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 120 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 121 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
| 122 | - ); |
|
| 123 | - |
|
| 124 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Displays invoice table columns. |
|
| 129 | - */ |
|
| 130 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 131 | - |
|
| 132 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 133 | - |
|
| 134 | - switch ( $column_name ) { |
|
| 135 | - |
|
| 136 | - case 'invoice_date' : |
|
| 137 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 138 | - $date = getpaid_format_date_value( $date_time ); |
|
| 139 | - echo "<span title='$date_time'>$date</span>"; |
|
| 140 | - break; |
|
| 141 | - |
|
| 142 | - case 'amount' : |
|
| 143 | - |
|
| 144 | - $amount = $invoice->get_total(); |
|
| 145 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
| 146 | - |
|
| 147 | - if ( $invoice->is_refunded() ) { |
|
| 148 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
| 149 | - echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
| 150 | - } else { |
|
| 151 | - |
|
| 152 | - $discount = $invoice->get_total_discount(); |
|
| 153 | - |
|
| 154 | - if ( ! empty( $discount ) ) { |
|
| 155 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
| 156 | - echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
| 157 | - } else { |
|
| 158 | - echo $formated_amount; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - break; |
|
| 164 | - |
|
| 165 | - case 'status' : |
|
| 166 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
| 167 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
| 168 | - |
|
| 169 | - // If it is paid, show the gateway title. |
|
| 170 | - if ( $invoice->is_paid() ) { |
|
| 171 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
| 172 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 16 | + * Hook in methods. |
|
| 17 | + */ |
|
| 18 | + public static function init() { |
|
| 173 | 19 | |
| 174 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
| 175 | - } else { |
|
| 176 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
| 177 | - } |
|
| 20 | + // Init metaboxes. |
|
| 21 | + GetPaid_Metaboxes::init(); |
|
| 178 | 22 | |
| 179 | - // If it is not paid, display the overdue and view status. |
|
| 180 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 23 | + // Filter the post updated messages. |
|
| 24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 181 | 25 | |
| 182 | - // Invoice view status. |
|
| 183 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 184 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 185 | - } else { |
|
| 186 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 187 | - } |
|
| 26 | + // Filter post actions. |
|
| 27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 188 | 28 | |
| 189 | - // Display the overview status. |
|
| 190 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 191 | - $due_date = $invoice->get_due_date(); |
|
| 192 | - $fomatted = getpaid_format_date( $due_date ); |
|
| 29 | + // Invoice table columns. |
|
| 30 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 31 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 193 | 32 | |
| 194 | - if ( ! empty( $fomatted ) ) { |
|
| 195 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
| 196 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
| 197 | - } |
|
| 198 | - } |
|
| 33 | + // Items table columns. |
|
| 34 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 35 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 36 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 37 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 38 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 39 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 199 | 40 | |
| 200 | - } |
|
| 41 | + // Payment forms columns. |
|
| 42 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 43 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 44 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 201 | 45 | |
| 202 | - break; |
|
| 46 | + // Discount table columns. |
|
| 47 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 203 | 48 | |
| 204 | - case 'recurring': |
|
| 49 | + // Deleting posts. |
|
| 50 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 51 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 52 | + } |
|
| 205 | 53 | |
| 206 | - if ( $invoice->is_recurring() ) { |
|
| 207 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 208 | - } else { |
|
| 209 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 210 | - } |
|
| 211 | - break; |
|
| 54 | + /** |
|
| 55 | + * Post updated messages. |
|
| 56 | + */ |
|
| 57 | + public static function post_updated_messages( $messages ) { |
|
| 58 | + global $post; |
|
| 59 | + |
|
| 60 | + $messages['wpi_discount'] = array( |
|
| 61 | + 0 => '', |
|
| 62 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 63 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 64 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 65 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 66 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 67 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 68 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 69 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 70 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 71 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 72 | + ); |
|
| 73 | + |
|
| 74 | + $messages['wpi_payment_form'] = array( |
|
| 75 | + 0 => '', |
|
| 76 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 77 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 78 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 79 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 80 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 81 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 82 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 83 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 84 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 85 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + return $messages; |
|
| 89 | + |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Post row actions. |
|
| 94 | + */ |
|
| 95 | + public static function post_row_actions( $actions, $post ) { |
|
| 96 | + |
|
| 97 | + $post = get_post( $post ); |
|
| 98 | + |
|
| 99 | + // We do not want to edit the default payment form. |
|
| 100 | + if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
| 101 | + unset( $actions['trash'] ); |
|
| 102 | + unset( $actions['inline hide-if-no-js'] ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $actions; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Returns an array of invoice table columns. |
|
| 110 | + */ |
|
| 111 | + public static function invoice_columns( $columns ) { |
|
| 112 | + |
|
| 113 | + $columns = array( |
|
| 114 | + 'cb' => $columns['cb'], |
|
| 115 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
| 116 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 117 | + 'invoice_date' => __( 'Date', 'invoicing' ), |
|
| 118 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 119 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 120 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 121 | + 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
| 122 | + ); |
|
| 123 | + |
|
| 124 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Displays invoice table columns. |
|
| 129 | + */ |
|
| 130 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 131 | + |
|
| 132 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 133 | + |
|
| 134 | + switch ( $column_name ) { |
|
| 135 | + |
|
| 136 | + case 'invoice_date' : |
|
| 137 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 138 | + $date = getpaid_format_date_value( $date_time ); |
|
| 139 | + echo "<span title='$date_time'>$date</span>"; |
|
| 140 | + break; |
|
| 141 | + |
|
| 142 | + case 'amount' : |
|
| 143 | + |
|
| 144 | + $amount = $invoice->get_total(); |
|
| 145 | + $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
| 146 | + |
|
| 147 | + if ( $invoice->is_refunded() ) { |
|
| 148 | + $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
| 149 | + echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
| 150 | + } else { |
|
| 151 | + |
|
| 152 | + $discount = $invoice->get_total_discount(); |
|
| 153 | + |
|
| 154 | + if ( ! empty( $discount ) ) { |
|
| 155 | + $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
| 156 | + echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
| 157 | + } else { |
|
| 158 | + echo $formated_amount; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + break; |
|
| 164 | + |
|
| 165 | + case 'status' : |
|
| 166 | + $status = sanitize_text_field( $invoice->get_status() ); |
|
| 167 | + $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
| 168 | + |
|
| 169 | + // If it is paid, show the gateway title. |
|
| 170 | + if ( $invoice->is_paid() ) { |
|
| 171 | + $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
| 172 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 212 | 173 | |
| 213 | - case 'number' : |
|
| 174 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
| 175 | + } else { |
|
| 176 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
| 177 | + } |
|
| 214 | 178 | |
| 215 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 216 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
| 217 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 179 | + // If it is not paid, display the overdue and view status. |
|
| 180 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 218 | 181 | |
| 219 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
| 182 | + // Invoice view status. |
|
| 183 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 184 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 185 | + } else { |
|
| 186 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 187 | + } |
|
| 220 | 188 | |
| 221 | - break; |
|
| 189 | + // Display the overview status. |
|
| 190 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 191 | + $due_date = $invoice->get_due_date(); |
|
| 192 | + $fomatted = getpaid_format_date( $due_date ); |
|
| 222 | 193 | |
| 223 | - case 'customer' : |
|
| 194 | + if ( ! empty( $fomatted ) ) { |
|
| 195 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
| 196 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + break; |
|
| 203 | + |
|
| 204 | + case 'recurring': |
|
| 205 | + |
|
| 206 | + if ( $invoice->is_recurring() ) { |
|
| 207 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 208 | + } else { |
|
| 209 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 210 | + } |
|
| 211 | + break; |
|
| 212 | + |
|
| 213 | + case 'number' : |
|
| 214 | + |
|
| 215 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 216 | + $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
| 217 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 218 | + |
|
| 219 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
| 220 | + |
|
| 221 | + break; |
|
| 222 | + |
|
| 223 | + case 'customer' : |
|
| 224 | 224 | |
| 225 | - $customer_name = $invoice->get_user_full_name(); |
|
| 225 | + $customer_name = $invoice->get_user_full_name(); |
|
| 226 | 226 | |
| 227 | - if ( empty( $customer_name ) ) { |
|
| 228 | - $customer_name = $invoice->get_email(); |
|
| 229 | - } |
|
| 227 | + if ( empty( $customer_name ) ) { |
|
| 228 | + $customer_name = $invoice->get_email(); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - if ( ! empty( $customer_name ) ) { |
|
| 232 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 233 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 234 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
| 235 | - } else { |
|
| 236 | - echo '<div>—</div>'; |
|
| 237 | - } |
|
| 231 | + if ( ! empty( $customer_name ) ) { |
|
| 232 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 233 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 234 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
| 235 | + } else { |
|
| 236 | + echo '<div>—</div>'; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + break; |
|
| 240 | + |
|
| 241 | + case 'wpi_actions' : |
|
| 242 | + |
|
| 243 | + if ( $invoice->is_draft() ) { |
|
| 244 | + return; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $url = esc_url( $invoice->get_view_url() ); |
|
| 248 | + $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
| 249 | + echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
| 250 | + |
|
| 251 | + $url = esc_url( |
|
| 252 | + wp_nonce_url( |
|
| 253 | + add_query_arg( |
|
| 254 | + array( |
|
| 255 | + 'getpaid-admin-action' => 'send_invoice', |
|
| 256 | + 'invoice_id' => $invoice->get_id() |
|
| 257 | + ) |
|
| 258 | + ), |
|
| 259 | + 'getpaid-nonce', |
|
| 260 | + 'getpaid-nonce' |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + |
|
| 264 | + $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
| 265 | + echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
| 266 | + |
|
| 267 | + break; |
|
| 268 | + } |
|
| 238 | 269 | |
| 239 | - break; |
|
| 270 | + } |
|
| 240 | 271 | |
| 241 | - case 'wpi_actions' : |
|
| 242 | - |
|
| 243 | - if ( $invoice->is_draft() ) { |
|
| 244 | - return; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $url = esc_url( $invoice->get_view_url() ); |
|
| 248 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
| 249 | - echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
|
| 272 | + /** |
|
| 273 | + * Returns an array of payment forms table columns. |
|
| 274 | + */ |
|
| 275 | + public static function payment_form_columns( $columns ) { |
|
| 250 | 276 | |
| 251 | - $url = esc_url( |
|
| 252 | - wp_nonce_url( |
|
| 253 | - add_query_arg( |
|
| 254 | - array( |
|
| 255 | - 'getpaid-admin-action' => 'send_invoice', |
|
| 256 | - 'invoice_id' => $invoice->get_id() |
|
| 257 | - ) |
|
| 258 | - ), |
|
| 259 | - 'getpaid-nonce', |
|
| 260 | - 'getpaid-nonce' |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 277 | + $columns = array( |
|
| 278 | + 'cb' => $columns['cb'], |
|
| 279 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 280 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 281 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 282 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 283 | + 'items' => __( 'Items', 'invoicing' ), |
|
| 284 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 285 | + ); |
|
| 263 | 286 | |
| 264 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
| 265 | - echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
|
| 287 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 266 | 288 | |
| 267 | - break; |
|
| 268 | - } |
|
| 289 | + } |
|
| 269 | 290 | |
| 270 | - } |
|
| 291 | + /** |
|
| 292 | + * Displays payment form table columns. |
|
| 293 | + */ |
|
| 294 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 271 | 295 | |
| 272 | - /** |
|
| 273 | - * Returns an array of payment forms table columns. |
|
| 274 | - */ |
|
| 275 | - public static function payment_form_columns( $columns ) { |
|
| 296 | + // Retrieve the payment form. |
|
| 297 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
| 276 | 298 | |
| 277 | - $columns = array( |
|
| 278 | - 'cb' => $columns['cb'], |
|
| 279 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 280 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 281 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 282 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 283 | - 'items' => __( 'Items', 'invoicing' ), |
|
| 284 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 285 | - ); |
|
| 299 | + switch ( $column_name ) { |
|
| 286 | 300 | |
| 287 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 301 | + case 'earnings' : |
|
| 302 | + echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
| 303 | + break; |
|
| 288 | 304 | |
| 289 | - } |
|
| 305 | + case 'refunds' : |
|
| 306 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 307 | + break; |
|
| 290 | 308 | |
| 291 | - /** |
|
| 292 | - * Displays payment form table columns. |
|
| 293 | - */ |
|
| 294 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 309 | + case 'refunds' : |
|
| 310 | + echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 311 | + break; |
|
| 295 | 312 | |
| 296 | - // Retrieve the payment form. |
|
| 297 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
| 313 | + case 'shortcode' : |
|
| 298 | 314 | |
| 299 | - switch ( $column_name ) { |
|
| 315 | + if ( $form->is_default() ) { |
|
| 316 | + echo '—'; |
|
| 317 | + } else { |
|
| 318 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 319 | + } |
|
| 300 | 320 | |
| 301 | - case 'earnings' : |
|
| 302 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
| 303 | - break; |
|
| 321 | + break; |
|
| 304 | 322 | |
| 305 | - case 'refunds' : |
|
| 306 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 307 | - break; |
|
| 323 | + case 'items' : |
|
| 308 | 324 | |
| 309 | - case 'refunds' : |
|
| 310 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 311 | - break; |
|
| 325 | + $items = $form->get_items(); |
|
| 312 | 326 | |
| 313 | - case 'shortcode' : |
|
| 327 | + if ( $form->is_default() || empty( $items ) ) { |
|
| 328 | + echo '—'; |
|
| 329 | + return; |
|
| 330 | + } |
|
| 314 | 331 | |
| 315 | - if ( $form->is_default() ) { |
|
| 316 | - echo '—'; |
|
| 317 | - } else { |
|
| 318 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 319 | - } |
|
| 332 | + $_items = array(); |
|
| 320 | 333 | |
| 321 | - break; |
|
| 334 | + foreach ( $items as $item ) { |
|
| 335 | + $url = $item->get_edit_url(); |
|
| 322 | 336 | |
| 323 | - case 'items' : |
|
| 337 | + if ( empty( $url ) ) { |
|
| 338 | + $_items[] = sanitize_text_field( $item->get_name() ); |
|
| 339 | + } else { |
|
| 340 | + $_items[] = sprintf( |
|
| 341 | + '<a href="%s">%s</a>', |
|
| 342 | + esc_url( $url ), |
|
| 343 | + sanitize_text_field( $item->get_name() ) |
|
| 344 | + ); |
|
| 345 | + } |
|
| 324 | 346 | |
| 325 | - $items = $form->get_items(); |
|
| 347 | + } |
|
| 326 | 348 | |
| 327 | - if ( $form->is_default() || empty( $items ) ) { |
|
| 328 | - echo '—'; |
|
| 329 | - return; |
|
| 330 | - } |
|
| 349 | + echo implode( '<br>', $_items ); |
|
| 331 | 350 | |
| 332 | - $_items = array(); |
|
| 351 | + break; |
|
| 333 | 352 | |
| 334 | - foreach ( $items as $item ) { |
|
| 335 | - $url = $item->get_edit_url(); |
|
| 353 | + } |
|
| 336 | 354 | |
| 337 | - if ( empty( $url ) ) { |
|
| 338 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
| 339 | - } else { |
|
| 340 | - $_items[] = sprintf( |
|
| 341 | - '<a href="%s">%s</a>', |
|
| 342 | - esc_url( $url ), |
|
| 343 | - sanitize_text_field( $item->get_name() ) |
|
| 344 | - ); |
|
| 345 | - } |
|
| 355 | + } |
|
| 346 | 356 | |
| 347 | - } |
|
| 357 | + /** |
|
| 358 | + * Filters post states. |
|
| 359 | + */ |
|
| 360 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
| 348 | 361 | |
| 349 | - echo implode( '<br>', $_items ); |
|
| 362 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
| 363 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + return $post_states; |
|
| 350 | 367 | |
| 351 | - break; |
|
| 368 | + } |
|
| 352 | 369 | |
| 353 | - } |
|
| 370 | + /** |
|
| 371 | + * Returns an array of coupon table columns. |
|
| 372 | + */ |
|
| 373 | + public static function discount_columns( $columns ) { |
|
| 374 | + |
|
| 375 | + $columns = array( |
|
| 376 | + 'cb' => $columns['cb'], |
|
| 377 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 378 | + 'code' => __( 'Code', 'invoicing' ), |
|
| 379 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 380 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 381 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 382 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 383 | + ); |
|
| 384 | + |
|
| 385 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 386 | + } |
|
| 354 | 387 | |
| 355 | - } |
|
| 388 | + /** |
|
| 389 | + * Filters post states. |
|
| 390 | + */ |
|
| 391 | + public static function filter_discount_state( $post_states, $post ) { |
|
| 356 | 392 | |
| 357 | - /** |
|
| 358 | - * Filters post states. |
|
| 359 | - */ |
|
| 360 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
| 393 | + if ( 'wpi_discount' == $post->post_type ) { |
|
| 361 | 394 | |
| 362 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
| 363 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - return $post_states; |
|
| 395 | + $discount = new WPInv_Discount( $post ); |
|
| 367 | 396 | |
| 368 | - } |
|
| 397 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 369 | 398 | |
| 370 | - /** |
|
| 371 | - * Returns an array of coupon table columns. |
|
| 372 | - */ |
|
| 373 | - public static function discount_columns( $columns ) { |
|
| 399 | + if ( $status != 'publish' ) { |
|
| 400 | + return array( |
|
| 401 | + 'discount_status' => wpinv_discount_status( $status ), |
|
| 402 | + ); |
|
| 403 | + } |
|
| 374 | 404 | |
| 375 | - $columns = array( |
|
| 376 | - 'cb' => $columns['cb'], |
|
| 377 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 378 | - 'code' => __( 'Code', 'invoicing' ), |
|
| 379 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 380 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 381 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 382 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 383 | - ); |
|
| 405 | + return array(); |
|
| 384 | 406 | |
| 385 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 386 | - } |
|
| 407 | + } |
|
| 387 | 408 | |
| 388 | - /** |
|
| 389 | - * Filters post states. |
|
| 390 | - */ |
|
| 391 | - public static function filter_discount_state( $post_states, $post ) { |
|
| 409 | + return $post_states; |
|
| 392 | 410 | |
| 393 | - if ( 'wpi_discount' == $post->post_type ) { |
|
| 411 | + } |
|
| 394 | 412 | |
| 395 | - $discount = new WPInv_Discount( $post ); |
|
| 413 | + /** |
|
| 414 | + * Returns an array of items table columns. |
|
| 415 | + */ |
|
| 416 | + public static function item_columns( $columns ) { |
|
| 417 | + global $wpinv_euvat; |
|
| 418 | + |
|
| 419 | + $columns = array( |
|
| 420 | + 'cb' => $columns['cb'], |
|
| 421 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 422 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 423 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
| 424 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
| 425 | + 'type' => __( 'Type', 'invoicing' ), |
|
| 426 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 427 | + ); |
|
| 428 | + |
|
| 429 | + if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
| 430 | + unset( $columns['vat_rule'] ); |
|
| 431 | + } |
|
| 396 | 432 | |
| 397 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 433 | + if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
| 434 | + unset( $columns['vat_class'] ); |
|
| 435 | + } |
|
| 398 | 436 | |
| 399 | - if ( $status != 'publish' ) { |
|
| 400 | - return array( |
|
| 401 | - 'discount_status' => wpinv_discount_status( $status ), |
|
| 402 | - ); |
|
| 403 | - } |
|
| 437 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 438 | + } |
|
| 404 | 439 | |
| 405 | - return array(); |
|
| 440 | + /** |
|
| 441 | + * Returns an array of sortable items table columns. |
|
| 442 | + */ |
|
| 443 | + public static function sortable_item_columns( $columns ) { |
|
| 444 | + |
|
| 445 | + return array_merge( |
|
| 446 | + $columns, |
|
| 447 | + array( |
|
| 448 | + 'price' => 'price', |
|
| 449 | + 'vat_rule' => 'vat_rule', |
|
| 450 | + 'vat_class' => 'vat_class', |
|
| 451 | + 'type' => 'type', |
|
| 452 | + ) |
|
| 453 | + ); |
|
| 454 | + |
|
| 455 | + } |
|
| 406 | 456 | |
| 407 | - } |
|
| 457 | + /** |
|
| 458 | + * Displays items table columns. |
|
| 459 | + */ |
|
| 460 | + public static function display_item_columns( $column_name, $post_id ) { |
|
| 461 | + global $wpinv_euvat; |
|
| 408 | 462 | |
| 409 | - return $post_states; |
|
| 463 | + $item = new WPInv_Item( $post_id ); |
|
| 410 | 464 | |
| 411 | - } |
|
| 465 | + switch ( $column_name ) { |
|
| 412 | 466 | |
| 413 | - /** |
|
| 414 | - * Returns an array of items table columns. |
|
| 415 | - */ |
|
| 416 | - public static function item_columns( $columns ) { |
|
| 417 | - global $wpinv_euvat; |
|
| 467 | + case 'price' : |
|
| 418 | 468 | |
| 419 | - $columns = array( |
|
| 420 | - 'cb' => $columns['cb'], |
|
| 421 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 422 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 423 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
| 424 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
| 425 | - 'type' => __( 'Type', 'invoicing' ), |
|
| 426 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 427 | - ); |
|
| 469 | + if ( ! $item->is_recurring() ) { |
|
| 470 | + echo $item->get_the_price(); |
|
| 471 | + break; |
|
| 472 | + } |
|
| 428 | 473 | |
| 429 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
| 430 | - unset( $columns['vat_rule'] ); |
|
| 431 | - } |
|
| 474 | + $price = wp_sprintf( |
|
| 475 | + __( '%s / %s', 'invoicing' ), |
|
| 476 | + $item->get_the_price(), |
|
| 477 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 478 | + ); |
|
| 432 | 479 | |
| 433 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
| 434 | - unset( $columns['vat_class'] ); |
|
| 435 | - } |
|
| 480 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 481 | + echo $price; |
|
| 482 | + break; |
|
| 483 | + } |
|
| 436 | 484 | |
| 437 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 438 | - } |
|
| 485 | + echo $item->get_the_initial_price(); |
|
| 439 | 486 | |
| 440 | - /** |
|
| 441 | - * Returns an array of sortable items table columns. |
|
| 442 | - */ |
|
| 443 | - public static function sortable_item_columns( $columns ) { |
|
| 487 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
| 488 | + break; |
|
| 444 | 489 | |
| 445 | - return array_merge( |
|
| 446 | - $columns, |
|
| 447 | - array( |
|
| 448 | - 'price' => 'price', |
|
| 449 | - 'vat_rule' => 'vat_rule', |
|
| 450 | - 'vat_class' => 'vat_class', |
|
| 451 | - 'type' => 'type', |
|
| 452 | - ) |
|
| 453 | - ); |
|
| 490 | + case 'vat_rule' : |
|
| 491 | + echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
| 492 | + break; |
|
| 454 | 493 | |
| 455 | - } |
|
| 494 | + case 'vat_class' : |
|
| 495 | + echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
| 496 | + break; |
|
| 456 | 497 | |
| 457 | - /** |
|
| 458 | - * Displays items table columns. |
|
| 459 | - */ |
|
| 460 | - public static function display_item_columns( $column_name, $post_id ) { |
|
| 461 | - global $wpinv_euvat; |
|
| 498 | + case 'shortcode' : |
|
| 499 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 500 | + break; |
|
| 462 | 501 | |
| 463 | - $item = new WPInv_Item( $post_id ); |
|
| 502 | + case 'type' : |
|
| 503 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 504 | + break; |
|
| 464 | 505 | |
| 465 | - switch ( $column_name ) { |
|
| 506 | + } |
|
| 466 | 507 | |
| 467 | - case 'price' : |
|
| 508 | + } |
|
| 468 | 509 | |
| 469 | - if ( ! $item->is_recurring() ) { |
|
| 470 | - echo $item->get_the_price(); |
|
| 471 | - break; |
|
| 472 | - } |
|
| 510 | + /** |
|
| 511 | + * Lets users filter items using taxes. |
|
| 512 | + */ |
|
| 513 | + public static function add_item_filters( $post_type ) { |
|
| 514 | + $wpinv_euvat = getpaid_tax(); |
|
| 515 | + |
|
| 516 | + // Abort if we're not dealing with items. |
|
| 517 | + if ( $post_type != 'wpi_item' ) { |
|
| 518 | + return; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // Filter by vat rules. |
|
| 522 | + if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 523 | + |
|
| 524 | + // Sanitize selected vat rule. |
|
| 525 | + $vat_rule = ''; |
|
| 526 | + $vat_rules = $wpinv_euvat->get_rules(); |
|
| 527 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
| 528 | + $vat_rule = $_GET['vat_rule']; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + // Filter by VAT rule. |
|
| 532 | + echo wpinv_html_select( |
|
| 533 | + array( |
|
| 534 | + 'options' => array_merge( |
|
| 535 | + array( |
|
| 536 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
| 537 | + ), |
|
| 538 | + $vat_rules |
|
| 539 | + ), |
|
| 540 | + 'name' => 'vat_rule', |
|
| 541 | + 'id' => 'vat_rule', |
|
| 542 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
| 543 | + 'show_option_all' => false, |
|
| 544 | + 'show_option_none' => false, |
|
| 545 | + 'class' => 'gdmbx2-text-medium', |
|
| 546 | + ) |
|
| 547 | + ); |
|
| 548 | + |
|
| 549 | + // Filter by VAT class. |
|
| 550 | + } |
|
| 473 | 551 | |
| 474 | - $price = wp_sprintf( |
|
| 475 | - __( '%s / %s', 'invoicing' ), |
|
| 476 | - $item->get_the_price(), |
|
| 477 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 478 | - ); |
|
| 552 | + // Filter by vat class. |
|
| 553 | + if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 554 | + |
|
| 555 | + // Sanitize selected vat rule. |
|
| 556 | + $vat_class = ''; |
|
| 557 | + $vat_classes = $wpinv_euvat->get_all_classes(); |
|
| 558 | + if ( isset( $_GET['vat_class'] ) ) { |
|
| 559 | + $vat_class = $_GET['vat_class']; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + echo wpinv_html_select( |
|
| 563 | + array( |
|
| 564 | + 'options' => array_merge( |
|
| 565 | + array( |
|
| 566 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
| 567 | + ), |
|
| 568 | + $vat_classes |
|
| 569 | + ), |
|
| 570 | + 'name' => 'vat_class', |
|
| 571 | + 'id' => 'vat_class', |
|
| 572 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
| 573 | + 'show_option_all' => false, |
|
| 574 | + 'show_option_none' => false, |
|
| 575 | + 'class' => 'gdmbx2-text-medium', |
|
| 576 | + ) |
|
| 577 | + ); |
|
| 479 | 578 | |
| 480 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 481 | - echo $price; |
|
| 482 | - break; |
|
| 483 | - } |
|
| 579 | + } |
|
| 484 | 580 | |
| 485 | - echo $item->get_the_initial_price(); |
|
| 581 | + // Filter by item type. |
|
| 582 | + $type = ''; |
|
| 583 | + if ( isset( $_GET['type'] ) ) { |
|
| 584 | + $type = $_GET['type']; |
|
| 585 | + } |
|
| 486 | 586 | |
| 487 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
| 488 | - break; |
|
| 587 | + echo wpinv_html_select( |
|
| 588 | + array( |
|
| 589 | + 'options' => array_merge( |
|
| 590 | + array( |
|
| 591 | + '' => __( 'All item types', 'invoicing' ) |
|
| 592 | + ), |
|
| 593 | + wpinv_get_item_types() |
|
| 594 | + ), |
|
| 595 | + 'name' => 'type', |
|
| 596 | + 'id' => 'type', |
|
| 597 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
| 598 | + 'show_option_all' => false, |
|
| 599 | + 'show_option_none' => false, |
|
| 600 | + 'class' => 'gdmbx2-text-medium', |
|
| 601 | + ) |
|
| 602 | + ); |
|
| 603 | + |
|
| 604 | + } |
|
| 489 | 605 | |
| 490 | - case 'vat_rule' : |
|
| 491 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
| 492 | - break; |
|
| 606 | + /** |
|
| 607 | + * Filters the item query. |
|
| 608 | + */ |
|
| 609 | + public static function filter_item_query( $query ) { |
|
| 493 | 610 | |
| 494 | - case 'vat_class' : |
|
| 495 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
| 496 | - break; |
|
| 611 | + // modify the query only if it admin and main query. |
|
| 612 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
| 613 | + return $query; |
|
| 614 | + } |
|
| 497 | 615 | |
| 498 | - case 'shortcode' : |
|
| 499 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 500 | - break; |
|
| 616 | + // we want to modify the query for our items. |
|
| 617 | + if ( 'wpi_item' != $query->query['post_type'] ){ |
|
| 618 | + return $query; |
|
| 619 | + } |
|
| 501 | 620 | |
| 502 | - case 'type' : |
|
| 503 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 504 | - break; |
|
| 621 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 622 | + $query->query_vars['meta_query'] = array(); |
|
| 623 | + } |
|
| 505 | 624 | |
| 506 | - } |
|
| 507 | - |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Lets users filter items using taxes. |
|
| 512 | - */ |
|
| 513 | - public static function add_item_filters( $post_type ) { |
|
| 514 | - $wpinv_euvat = getpaid_tax(); |
|
| 515 | - |
|
| 516 | - // Abort if we're not dealing with items. |
|
| 517 | - if ( $post_type != 'wpi_item' ) { |
|
| 518 | - return; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // Filter by vat rules. |
|
| 522 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 523 | - |
|
| 524 | - // Sanitize selected vat rule. |
|
| 525 | - $vat_rule = ''; |
|
| 526 | - $vat_rules = $wpinv_euvat->get_rules(); |
|
| 527 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
| 528 | - $vat_rule = $_GET['vat_rule']; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - // Filter by VAT rule. |
|
| 532 | - echo wpinv_html_select( |
|
| 533 | - array( |
|
| 534 | - 'options' => array_merge( |
|
| 535 | - array( |
|
| 536 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
| 537 | - ), |
|
| 538 | - $vat_rules |
|
| 539 | - ), |
|
| 540 | - 'name' => 'vat_rule', |
|
| 541 | - 'id' => 'vat_rule', |
|
| 542 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
| 543 | - 'show_option_all' => false, |
|
| 544 | - 'show_option_none' => false, |
|
| 545 | - 'class' => 'gdmbx2-text-medium', |
|
| 546 | - ) |
|
| 547 | - ); |
|
| 548 | - |
|
| 549 | - // Filter by VAT class. |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - // Filter by vat class. |
|
| 553 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 554 | - |
|
| 555 | - // Sanitize selected vat rule. |
|
| 556 | - $vat_class = ''; |
|
| 557 | - $vat_classes = $wpinv_euvat->get_all_classes(); |
|
| 558 | - if ( isset( $_GET['vat_class'] ) ) { |
|
| 559 | - $vat_class = $_GET['vat_class']; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - echo wpinv_html_select( |
|
| 563 | - array( |
|
| 564 | - 'options' => array_merge( |
|
| 565 | - array( |
|
| 566 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
| 567 | - ), |
|
| 568 | - $vat_classes |
|
| 569 | - ), |
|
| 570 | - 'name' => 'vat_class', |
|
| 571 | - 'id' => 'vat_class', |
|
| 572 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
| 573 | - 'show_option_all' => false, |
|
| 574 | - 'show_option_none' => false, |
|
| 575 | - 'class' => 'gdmbx2-text-medium', |
|
| 576 | - ) |
|
| 577 | - ); |
|
| 578 | - |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - // Filter by item type. |
|
| 582 | - $type = ''; |
|
| 583 | - if ( isset( $_GET['type'] ) ) { |
|
| 584 | - $type = $_GET['type']; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - echo wpinv_html_select( |
|
| 588 | - array( |
|
| 589 | - 'options' => array_merge( |
|
| 590 | - array( |
|
| 591 | - '' => __( 'All item types', 'invoicing' ) |
|
| 592 | - ), |
|
| 593 | - wpinv_get_item_types() |
|
| 594 | - ), |
|
| 595 | - 'name' => 'type', |
|
| 596 | - 'id' => 'type', |
|
| 597 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
| 598 | - 'show_option_all' => false, |
|
| 599 | - 'show_option_none' => false, |
|
| 600 | - 'class' => 'gdmbx2-text-medium', |
|
| 601 | - ) |
|
| 602 | - ); |
|
| 603 | - |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * Filters the item query. |
|
| 608 | - */ |
|
| 609 | - public static function filter_item_query( $query ) { |
|
| 610 | - |
|
| 611 | - // modify the query only if it admin and main query. |
|
| 612 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
| 613 | - return $query; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - // we want to modify the query for our items. |
|
| 617 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
| 618 | - return $query; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 622 | - $query->query_vars['meta_query'] = array(); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - // Filter vat rule type |
|
| 625 | + // Filter vat rule type |
|
| 626 | 626 | if ( ! empty( $_GET['vat_rule'] ) ) { |
| 627 | 627 | $query->query_vars['meta_query'][] = array( |
| 628 | 628 | 'key' => '_wpinv_vat_rule', |
@@ -647,94 +647,94 @@ discard block |
||
| 647 | 647 | 'value' => sanitize_text_field( $_GET['type'] ), |
| 648 | 648 | 'compare' => '=' |
| 649 | 649 | ); |
| 650 | - } |
|
| 651 | - |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Reorders items. |
|
| 656 | - */ |
|
| 657 | - public static function reorder_items( $vars ) { |
|
| 658 | - global $typenow; |
|
| 659 | - |
|
| 660 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 661 | - return $vars; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - // By item type. |
|
| 665 | - if ( 'type' == $vars['orderby'] ) { |
|
| 666 | - return array_merge( |
|
| 667 | - $vars, |
|
| 668 | - array( |
|
| 669 | - 'meta_key' => '_wpinv_type', |
|
| 670 | - 'orderby' => 'meta_value' |
|
| 671 | - ) |
|
| 672 | - ); |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - // By vat class. |
|
| 676 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
| 677 | - return array_merge( |
|
| 678 | - $vars, |
|
| 679 | - array( |
|
| 680 | - 'meta_key' => '_wpinv_vat_class', |
|
| 681 | - 'orderby' => 'meta_value' |
|
| 682 | - ) |
|
| 683 | - ); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - // By vat rule. |
|
| 687 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
| 688 | - return array_merge( |
|
| 689 | - $vars, |
|
| 690 | - array( |
|
| 691 | - 'meta_key' => '_wpinv_vat_rule', |
|
| 692 | - 'orderby' => 'meta_value' |
|
| 693 | - ) |
|
| 694 | - ); |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - // By price. |
|
| 698 | - if ( 'price' == $vars['orderby'] ) { |
|
| 699 | - return array_merge( |
|
| 700 | - $vars, |
|
| 701 | - array( |
|
| 702 | - 'meta_key' => '_wpinv_price', |
|
| 703 | - 'orderby' => 'meta_value_num' |
|
| 704 | - ) |
|
| 705 | - ); |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - return $vars; |
|
| 709 | - |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * Fired when deleting a post. |
|
| 714 | - */ |
|
| 715 | - public static function delete_post( $post_id ) { |
|
| 716 | - |
|
| 717 | - switch ( get_post_type( $post_id ) ) { |
|
| 718 | - |
|
| 719 | - case 'wpi_item' : |
|
| 720 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
| 721 | - break; |
|
| 722 | - |
|
| 723 | - case 'wpi_payment_form' : |
|
| 724 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
| 725 | - break; |
|
| 726 | - |
|
| 727 | - case 'wpi_discount' : |
|
| 728 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
| 729 | - break; |
|
| 730 | - |
|
| 731 | - case 'wpi_invoice' : |
|
| 732 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 733 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
| 734 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
| 735 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 736 | - break; |
|
| 737 | - } |
|
| 738 | - } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Reorders items. |
|
| 656 | + */ |
|
| 657 | + public static function reorder_items( $vars ) { |
|
| 658 | + global $typenow; |
|
| 659 | + |
|
| 660 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 661 | + return $vars; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + // By item type. |
|
| 665 | + if ( 'type' == $vars['orderby'] ) { |
|
| 666 | + return array_merge( |
|
| 667 | + $vars, |
|
| 668 | + array( |
|
| 669 | + 'meta_key' => '_wpinv_type', |
|
| 670 | + 'orderby' => 'meta_value' |
|
| 671 | + ) |
|
| 672 | + ); |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + // By vat class. |
|
| 676 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
| 677 | + return array_merge( |
|
| 678 | + $vars, |
|
| 679 | + array( |
|
| 680 | + 'meta_key' => '_wpinv_vat_class', |
|
| 681 | + 'orderby' => 'meta_value' |
|
| 682 | + ) |
|
| 683 | + ); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + // By vat rule. |
|
| 687 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
| 688 | + return array_merge( |
|
| 689 | + $vars, |
|
| 690 | + array( |
|
| 691 | + 'meta_key' => '_wpinv_vat_rule', |
|
| 692 | + 'orderby' => 'meta_value' |
|
| 693 | + ) |
|
| 694 | + ); |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + // By price. |
|
| 698 | + if ( 'price' == $vars['orderby'] ) { |
|
| 699 | + return array_merge( |
|
| 700 | + $vars, |
|
| 701 | + array( |
|
| 702 | + 'meta_key' => '_wpinv_price', |
|
| 703 | + 'orderby' => 'meta_value_num' |
|
| 704 | + ) |
|
| 705 | + ); |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + return $vars; |
|
| 709 | + |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * Fired when deleting a post. |
|
| 714 | + */ |
|
| 715 | + public static function delete_post( $post_id ) { |
|
| 716 | + |
|
| 717 | + switch ( get_post_type( $post_id ) ) { |
|
| 718 | + |
|
| 719 | + case 'wpi_item' : |
|
| 720 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
| 721 | + break; |
|
| 722 | + |
|
| 723 | + case 'wpi_payment_form' : |
|
| 724 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
| 725 | + break; |
|
| 726 | + |
|
| 727 | + case 'wpi_discount' : |
|
| 728 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
| 729 | + break; |
|
| 730 | + |
|
| 731 | + case 'wpi_invoice' : |
|
| 732 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 733 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
| 734 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
| 735 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 736 | + break; |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | 739 | |
| 740 | 740 | } |
@@ -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 | * Post types Admin Class |
@@ -21,68 +21,68 @@ discard block |
||
| 21 | 21 | GetPaid_Metaboxes::init(); |
| 22 | 22 | |
| 23 | 23 | // Filter the post updated messages. |
| 24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 24 | + add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages'); |
|
| 25 | 25 | |
| 26 | 26 | // Filter post actions. |
| 27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 27 | + add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2); |
|
| 28 | 28 | |
| 29 | 29 | // Invoice table columns. |
| 30 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 31 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 30 | + add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100); |
|
| 31 | + add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2); |
|
| 32 | 32 | |
| 33 | 33 | // Items table columns. |
| 34 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 35 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 36 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 37 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 38 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 39 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 34 | + add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100); |
|
| 35 | + add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20); |
|
| 36 | + add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2); |
|
| 37 | + add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100); |
|
| 38 | + add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100); |
|
| 39 | + add_action('request', array(__CLASS__, 'reorder_items'), 100); |
|
| 40 | 40 | |
| 41 | 41 | // Payment forms columns. |
| 42 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 43 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 44 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 42 | + add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100); |
|
| 43 | + add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2); |
|
| 44 | + add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2); |
|
| 45 | 45 | |
| 46 | 46 | // Discount table columns. |
| 47 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 47 | + add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100); |
|
| 48 | 48 | |
| 49 | 49 | // Deleting posts. |
| 50 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 51 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 50 | + add_action('delete_post', array(__CLASS__, 'delete_post')); |
|
| 51 | + add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * Post updated messages. |
| 56 | 56 | */ |
| 57 | - public static function post_updated_messages( $messages ) { |
|
| 57 | + public static function post_updated_messages($messages) { |
|
| 58 | 58 | global $post; |
| 59 | 59 | |
| 60 | 60 | $messages['wpi_discount'] = array( |
| 61 | 61 | 0 => '', |
| 62 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 63 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 64 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 65 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 66 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 67 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 68 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 69 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 70 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 71 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 62 | + 1 => __('Discount updated.', 'invoicing'), |
|
| 63 | + 2 => __('Custom field updated.', 'invoicing'), |
|
| 64 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
| 65 | + 4 => __('Discount updated.', 'invoicing'), |
|
| 66 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
| 67 | + 6 => __('Discount updated.', 'invoicing'), |
|
| 68 | + 7 => __('Discount saved.', 'invoicing'), |
|
| 69 | + 8 => __('Discount submitted.', 'invoicing'), |
|
| 70 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
| 71 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
| 72 | 72 | ); |
| 73 | 73 | |
| 74 | 74 | $messages['wpi_payment_form'] = array( |
| 75 | 75 | 0 => '', |
| 76 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 77 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 78 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 79 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 80 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 81 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 82 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 83 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 84 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 85 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 76 | + 1 => __('Payment Form updated.', 'invoicing'), |
|
| 77 | + 2 => __('Custom field updated.', 'invoicing'), |
|
| 78 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
| 79 | + 4 => __('Payment Form updated.', 'invoicing'), |
|
| 80 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
| 81 | + 6 => __('Payment Form updated.', 'invoicing'), |
|
| 82 | + 7 => __('Payment Form saved.', 'invoicing'), |
|
| 83 | + 8 => __('Payment Form submitted.', 'invoicing'), |
|
| 84 | + 9 => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
| 85 | + 10 => __('Payment Form draft updated.', 'invoicing'), |
|
| 86 | 86 | ); |
| 87 | 87 | |
| 88 | 88 | return $messages; |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | /** |
| 93 | 93 | * Post row actions. |
| 94 | 94 | */ |
| 95 | - public static function post_row_actions( $actions, $post ) { |
|
| 95 | + public static function post_row_actions($actions, $post) { |
|
| 96 | 96 | |
| 97 | - $post = get_post( $post ); |
|
| 97 | + $post = get_post($post); |
|
| 98 | 98 | |
| 99 | 99 | // We do not want to edit the default payment form. |
| 100 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
| 101 | - unset( $actions['trash'] ); |
|
| 102 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 100 | + if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) { |
|
| 101 | + unset($actions['trash']); |
|
| 102 | + unset($actions['inline hide-if-no-js']); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | return $actions; |
@@ -108,51 +108,51 @@ discard block |
||
| 108 | 108 | /** |
| 109 | 109 | * Returns an array of invoice table columns. |
| 110 | 110 | */ |
| 111 | - public static function invoice_columns( $columns ) { |
|
| 111 | + public static function invoice_columns($columns) { |
|
| 112 | 112 | |
| 113 | 113 | $columns = array( |
| 114 | 114 | 'cb' => $columns['cb'], |
| 115 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
| 116 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 117 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
| 118 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 119 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 120 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 121 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
| 115 | + 'number' => __('Invoice', 'invoicing'), |
|
| 116 | + 'customer' => __('Customer', 'invoicing'), |
|
| 117 | + 'invoice_date' => __('Date', 'invoicing'), |
|
| 118 | + 'amount' => __('Amount', 'invoicing'), |
|
| 119 | + 'recurring' => __('Recurring', 'invoicing'), |
|
| 120 | + 'status' => __('Status', 'invoicing'), |
|
| 121 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
| 122 | 122 | ); |
| 123 | 123 | |
| 124 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 124 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
| 128 | 128 | * Displays invoice table columns. |
| 129 | 129 | */ |
| 130 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 130 | + public static function display_invoice_columns($column_name, $post_id) { |
|
| 131 | 131 | |
| 132 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 132 | + $invoice = new WPInv_Invoice($post_id); |
|
| 133 | 133 | |
| 134 | - switch ( $column_name ) { |
|
| 134 | + switch ($column_name) { |
|
| 135 | 135 | |
| 136 | 136 | case 'invoice_date' : |
| 137 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 138 | - $date = getpaid_format_date_value( $date_time ); |
|
| 137 | + $date_time = esc_attr($invoice->get_created_date()); |
|
| 138 | + $date = getpaid_format_date_value($date_time); |
|
| 139 | 139 | echo "<span title='$date_time'>$date</span>"; |
| 140 | 140 | break; |
| 141 | 141 | |
| 142 | 142 | case 'amount' : |
| 143 | 143 | |
| 144 | 144 | $amount = $invoice->get_total(); |
| 145 | - $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() ); |
|
| 145 | + $formated_amount = wpinv_price(wpinv_format_amount($amount), $invoice->get_currency()); |
|
| 146 | 146 | |
| 147 | - if ( $invoice->is_refunded() ) { |
|
| 148 | - $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() ); |
|
| 147 | + if ($invoice->is_refunded()) { |
|
| 148 | + $refunded_amount = wpinv_price(wpinv_format_amount(0), $invoice->get_currency()); |
|
| 149 | 149 | echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
| 150 | 150 | } else { |
| 151 | 151 | |
| 152 | 152 | $discount = $invoice->get_total_discount(); |
| 153 | 153 | |
| 154 | - if ( ! empty( $discount ) ) { |
|
| 155 | - $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() ); |
|
| 154 | + if (!empty($discount)) { |
|
| 155 | + $new_amount = wpinv_price(wpinv_format_amount($amount + $discount), $invoice->get_currency()); |
|
| 156 | 156 | echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
| 157 | 157 | } else { |
| 158 | 158 | echo $formated_amount; |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | break; |
| 164 | 164 | |
| 165 | 165 | case 'status' : |
| 166 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
| 167 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
| 166 | + $status = sanitize_text_field($invoice->get_status()); |
|
| 167 | + $status_label = sanitize_text_field($invoice->get_status_nicename()); |
|
| 168 | 168 | |
| 169 | 169 | // If it is paid, show the gateway title. |
| 170 | - if ( $invoice->is_paid() ) { |
|
| 171 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
| 172 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
| 170 | + if ($invoice->is_paid()) { |
|
| 171 | + $gateway = sanitize_text_field($invoice->get_gateway_title()); |
|
| 172 | + $gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway); |
|
| 173 | 173 | |
| 174 | 174 | echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
| 175 | 175 | } else { |
@@ -177,22 +177,22 @@ discard block |
||
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // If it is not paid, display the overdue and view status. |
| 180 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 180 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
| 181 | 181 | |
| 182 | 182 | // Invoice view status. |
| 183 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 184 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 183 | + if (wpinv_is_invoice_viewed($invoice->get_id())) { |
|
| 184 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>'; |
|
| 185 | 185 | } else { |
| 186 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 186 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>'; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // Display the overview status. |
| 190 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 190 | + if (wpinv_get_option('overdue_active')) { |
|
| 191 | 191 | $due_date = $invoice->get_due_date(); |
| 192 | - $fomatted = getpaid_format_date( $due_date ); |
|
| 192 | + $fomatted = getpaid_format_date($due_date); |
|
| 193 | 193 | |
| 194 | - if ( ! empty( $fomatted ) ) { |
|
| 195 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
| 194 | + if (!empty($fomatted)) { |
|
| 195 | + $date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted); |
|
| 196 | 196 | echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | case 'recurring': |
| 205 | 205 | |
| 206 | - if ( $invoice->is_recurring() ) { |
|
| 206 | + if ($invoice->is_recurring()) { |
|
| 207 | 207 | echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
| 208 | 208 | } else { |
| 209 | 209 | echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | case 'number' : |
| 214 | 214 | |
| 215 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 216 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
| 217 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 215 | + $edit_link = esc_url(get_edit_post_link($invoice->get_id())); |
|
| 216 | + $invoice_number = sanitize_text_field($invoice->get_number()); |
|
| 217 | + $invoice_details = esc_attr__('View Invoice Details', 'invoicing'); |
|
| 218 | 218 | |
| 219 | 219 | echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
| 220 | 220 | |
@@ -224,13 +224,13 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | $customer_name = $invoice->get_user_full_name(); |
| 226 | 226 | |
| 227 | - if ( empty( $customer_name ) ) { |
|
| 227 | + if (empty($customer_name)) { |
|
| 228 | 228 | $customer_name = $invoice->get_email(); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if ( ! empty( $customer_name ) ) { |
|
| 232 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 233 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 231 | + if (!empty($customer_name)) { |
|
| 232 | + $customer_details = esc_attr__('View Customer Details', 'invoicing'); |
|
| 233 | + $view_link = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php'))); |
|
| 234 | 234 | echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
| 235 | 235 | } else { |
| 236 | 236 | echo '<div>—</div>'; |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | case 'wpi_actions' : |
| 242 | 242 | |
| 243 | - if ( $invoice->is_draft() ) { |
|
| 243 | + if ($invoice->is_draft()) { |
|
| 244 | 244 | return; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - $url = esc_url( $invoice->get_view_url() ); |
|
| 248 | - $print = esc_attr__( 'Print invoice', 'invoicing' ); |
|
| 247 | + $url = esc_url($invoice->get_view_url()); |
|
| 248 | + $print = esc_attr__('Print invoice', 'invoicing'); |
|
| 249 | 249 | echo " <a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>"; |
| 250 | 250 | |
| 251 | 251 | $url = esc_url( |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | ) |
| 262 | 262 | ); |
| 263 | 263 | |
| 264 | - $send = esc_attr__( 'Send invoice to customer', 'invoicing' ); |
|
| 264 | + $send = esc_attr__('Send invoice to customer', 'invoicing'); |
|
| 265 | 265 | echo " <a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>"; |
| 266 | 266 | |
| 267 | 267 | break; |
@@ -272,50 +272,50 @@ discard block |
||
| 272 | 272 | /** |
| 273 | 273 | * Returns an array of payment forms table columns. |
| 274 | 274 | */ |
| 275 | - public static function payment_form_columns( $columns ) { |
|
| 275 | + public static function payment_form_columns($columns) { |
|
| 276 | 276 | |
| 277 | 277 | $columns = array( |
| 278 | 278 | 'cb' => $columns['cb'], |
| 279 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 280 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 281 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 282 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 283 | - 'items' => __( 'Items', 'invoicing' ), |
|
| 284 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 279 | + 'title' => __('Name', 'invoicing'), |
|
| 280 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
| 281 | + 'earnings' => __('Revenue', 'invoicing'), |
|
| 282 | + 'refunds' => __('Refunded', 'invoicing'), |
|
| 283 | + 'items' => __('Items', 'invoicing'), |
|
| 284 | + 'date' => __('Date', 'invoicing'), |
|
| 285 | 285 | ); |
| 286 | 286 | |
| 287 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 287 | + return apply_filters('wpi_payment_form_table_columns', $columns); |
|
| 288 | 288 | |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
| 292 | 292 | * Displays payment form table columns. |
| 293 | 293 | */ |
| 294 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 294 | + public static function display_payment_form_columns($column_name, $post_id) { |
|
| 295 | 295 | |
| 296 | 296 | // Retrieve the payment form. |
| 297 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
| 297 | + $form = new GetPaid_Payment_Form($post_id); |
|
| 298 | 298 | |
| 299 | - switch ( $column_name ) { |
|
| 299 | + switch ($column_name) { |
|
| 300 | 300 | |
| 301 | 301 | case 'earnings' : |
| 302 | - echo wpinv_price( wpinv_format_amount( $form->get_earned() ) ); |
|
| 302 | + echo wpinv_price(wpinv_format_amount($form->get_earned())); |
|
| 303 | 303 | break; |
| 304 | 304 | |
| 305 | 305 | case 'refunds' : |
| 306 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 306 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
| 307 | 307 | break; |
| 308 | 308 | |
| 309 | 309 | case 'refunds' : |
| 310 | - echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) ); |
|
| 310 | + echo wpinv_price(wpinv_format_amount($form->get_refunded())); |
|
| 311 | 311 | break; |
| 312 | 312 | |
| 313 | 313 | case 'shortcode' : |
| 314 | 314 | |
| 315 | - if ( $form->is_default() ) { |
|
| 315 | + if ($form->is_default()) { |
|
| 316 | 316 | echo '—'; |
| 317 | 317 | } else { |
| 318 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 318 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>'; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | break; |
@@ -324,29 +324,29 @@ discard block |
||
| 324 | 324 | |
| 325 | 325 | $items = $form->get_items(); |
| 326 | 326 | |
| 327 | - if ( $form->is_default() || empty( $items ) ) { |
|
| 327 | + if ($form->is_default() || empty($items)) { |
|
| 328 | 328 | echo '—'; |
| 329 | 329 | return; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | $_items = array(); |
| 333 | 333 | |
| 334 | - foreach ( $items as $item ) { |
|
| 334 | + foreach ($items as $item) { |
|
| 335 | 335 | $url = $item->get_edit_url(); |
| 336 | 336 | |
| 337 | - if ( empty( $url ) ) { |
|
| 338 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
| 337 | + if (empty($url)) { |
|
| 338 | + $_items[] = sanitize_text_field($item->get_name()); |
|
| 339 | 339 | } else { |
| 340 | 340 | $_items[] = sprintf( |
| 341 | 341 | '<a href="%s">%s</a>', |
| 342 | - esc_url( $url ), |
|
| 343 | - sanitize_text_field( $item->get_name() ) |
|
| 342 | + esc_url($url), |
|
| 343 | + sanitize_text_field($item->get_name()) |
|
| 344 | 344 | ); |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - echo implode( '<br>', $_items ); |
|
| 349 | + echo implode('<br>', $_items); |
|
| 350 | 350 | |
| 351 | 351 | break; |
| 352 | 352 | |
@@ -357,10 +357,10 @@ discard block |
||
| 357 | 357 | /** |
| 358 | 358 | * Filters post states. |
| 359 | 359 | */ |
| 360 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
| 360 | + public static function filter_payment_form_state($post_states, $post) { |
|
| 361 | 361 | |
| 362 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
| 363 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
| 362 | + if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) { |
|
| 363 | + $post_states['default_form'] = __('Default Payment Form', 'invoicing'); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | return $post_states; |
@@ -370,35 +370,35 @@ discard block |
||
| 370 | 370 | /** |
| 371 | 371 | * Returns an array of coupon table columns. |
| 372 | 372 | */ |
| 373 | - public static function discount_columns( $columns ) { |
|
| 373 | + public static function discount_columns($columns) { |
|
| 374 | 374 | |
| 375 | 375 | $columns = array( |
| 376 | 376 | 'cb' => $columns['cb'], |
| 377 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 378 | - 'code' => __( 'Code', 'invoicing' ), |
|
| 379 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 380 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 381 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 382 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 377 | + 'title' => __('Name', 'invoicing'), |
|
| 378 | + 'code' => __('Code', 'invoicing'), |
|
| 379 | + 'amount' => __('Amount', 'invoicing'), |
|
| 380 | + 'usage' => __('Usage / Limit', 'invoicing'), |
|
| 381 | + 'start_date' => __('Start Date', 'invoicing'), |
|
| 382 | + 'expiry_date' => __('Expiry Date', 'invoicing'), |
|
| 383 | 383 | ); |
| 384 | 384 | |
| 385 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 385 | + return apply_filters('wpi_discount_table_columns', $columns); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
| 389 | 389 | * Filters post states. |
| 390 | 390 | */ |
| 391 | - public static function filter_discount_state( $post_states, $post ) { |
|
| 391 | + public static function filter_discount_state($post_states, $post) { |
|
| 392 | 392 | |
| 393 | - if ( 'wpi_discount' == $post->post_type ) { |
|
| 393 | + if ('wpi_discount' == $post->post_type) { |
|
| 394 | 394 | |
| 395 | - $discount = new WPInv_Discount( $post ); |
|
| 395 | + $discount = new WPInv_Discount($post); |
|
| 396 | 396 | |
| 397 | 397 | $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
| 398 | 398 | |
| 399 | - if ( $status != 'publish' ) { |
|
| 399 | + if ($status != 'publish') { |
|
| 400 | 400 | return array( |
| 401 | - 'discount_status' => wpinv_discount_status( $status ), |
|
| 401 | + 'discount_status' => wpinv_discount_status($status), |
|
| 402 | 402 | ); |
| 403 | 403 | } |
| 404 | 404 | |
@@ -413,34 +413,34 @@ discard block |
||
| 413 | 413 | /** |
| 414 | 414 | * Returns an array of items table columns. |
| 415 | 415 | */ |
| 416 | - public static function item_columns( $columns ) { |
|
| 416 | + public static function item_columns($columns) { |
|
| 417 | 417 | global $wpinv_euvat; |
| 418 | 418 | |
| 419 | 419 | $columns = array( |
| 420 | 420 | 'cb' => $columns['cb'], |
| 421 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 422 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 423 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
| 424 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
| 425 | - 'type' => __( 'Type', 'invoicing' ), |
|
| 426 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 421 | + 'title' => __('Name', 'invoicing'), |
|
| 422 | + 'price' => __('Price', 'invoicing'), |
|
| 423 | + 'vat_rule' => __('VAT rule', 'invoicing'), |
|
| 424 | + 'vat_class' => __('VAT class', 'invoicing'), |
|
| 425 | + 'type' => __('Type', 'invoicing'), |
|
| 426 | + 'shortcode' => __('Shortcode', 'invoicing'), |
|
| 427 | 427 | ); |
| 428 | 428 | |
| 429 | - if ( ! $wpinv_euvat->allow_vat_rules() ) { |
|
| 430 | - unset( $columns['vat_rule'] ); |
|
| 429 | + if (!$wpinv_euvat->allow_vat_rules()) { |
|
| 430 | + unset($columns['vat_rule']); |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if ( ! $wpinv_euvat->allow_vat_classes() ) { |
|
| 434 | - unset( $columns['vat_class'] ); |
|
| 433 | + if (!$wpinv_euvat->allow_vat_classes()) { |
|
| 434 | + unset($columns['vat_class']); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 437 | + return apply_filters('wpi_item_table_columns', $columns); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | /** |
| 441 | 441 | * Returns an array of sortable items table columns. |
| 442 | 442 | */ |
| 443 | - public static function sortable_item_columns( $columns ) { |
|
| 443 | + public static function sortable_item_columns($columns) { |
|
| 444 | 444 | |
| 445 | 445 | return array_merge( |
| 446 | 446 | $columns, |
@@ -457,50 +457,50 @@ discard block |
||
| 457 | 457 | /** |
| 458 | 458 | * Displays items table columns. |
| 459 | 459 | */ |
| 460 | - public static function display_item_columns( $column_name, $post_id ) { |
|
| 460 | + public static function display_item_columns($column_name, $post_id) { |
|
| 461 | 461 | global $wpinv_euvat; |
| 462 | 462 | |
| 463 | - $item = new WPInv_Item( $post_id ); |
|
| 463 | + $item = new WPInv_Item($post_id); |
|
| 464 | 464 | |
| 465 | - switch ( $column_name ) { |
|
| 465 | + switch ($column_name) { |
|
| 466 | 466 | |
| 467 | 467 | case 'price' : |
| 468 | 468 | |
| 469 | - if ( ! $item->is_recurring() ) { |
|
| 469 | + if (!$item->is_recurring()) { |
|
| 470 | 470 | echo $item->get_the_price(); |
| 471 | 471 | break; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | $price = wp_sprintf( |
| 475 | - __( '%s / %s', 'invoicing' ), |
|
| 475 | + __('%s / %s', 'invoicing'), |
|
| 476 | 476 | $item->get_the_price(), |
| 477 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 477 | + getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '') |
|
| 478 | 478 | ); |
| 479 | 479 | |
| 480 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 480 | + if ($item->get_the_price() == $item->get_the_initial_price()) { |
|
| 481 | 481 | echo $price; |
| 482 | 482 | break; |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | echo $item->get_the_initial_price(); |
| 486 | 486 | |
| 487 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
| 487 | + echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>'; |
|
| 488 | 488 | break; |
| 489 | 489 | |
| 490 | 490 | case 'vat_rule' : |
| 491 | - echo $wpinv_euvat->item_rule_label( $item->get_id() ); |
|
| 491 | + echo $wpinv_euvat->item_rule_label($item->get_id()); |
|
| 492 | 492 | break; |
| 493 | 493 | |
| 494 | 494 | case 'vat_class' : |
| 495 | - echo $wpinv_euvat->item_class_label( $item->get_id() ); |
|
| 495 | + echo $wpinv_euvat->item_class_label($item->get_id()); |
|
| 496 | 496 | break; |
| 497 | 497 | |
| 498 | 498 | case 'shortcode' : |
| 499 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 499 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 500 | 500 | break; |
| 501 | 501 | |
| 502 | 502 | case 'type' : |
| 503 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 503 | + echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
| 504 | 504 | break; |
| 505 | 505 | |
| 506 | 506 | } |
@@ -510,22 +510,22 @@ discard block |
||
| 510 | 510 | /** |
| 511 | 511 | * Lets users filter items using taxes. |
| 512 | 512 | */ |
| 513 | - public static function add_item_filters( $post_type ) { |
|
| 513 | + public static function add_item_filters($post_type) { |
|
| 514 | 514 | $wpinv_euvat = getpaid_tax(); |
| 515 | 515 | |
| 516 | 516 | // Abort if we're not dealing with items. |
| 517 | - if ( $post_type != 'wpi_item' ) { |
|
| 517 | + if ($post_type != 'wpi_item') { |
|
| 518 | 518 | return; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // Filter by vat rules. |
| 522 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 522 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
| 523 | 523 | |
| 524 | 524 | // Sanitize selected vat rule. |
| 525 | 525 | $vat_rule = ''; |
| 526 | 526 | $vat_rules = $wpinv_euvat->get_rules(); |
| 527 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
| 528 | - $vat_rule = $_GET['vat_rule']; |
|
| 527 | + if (isset($_GET['vat_rule'])) { |
|
| 528 | + $vat_rule = $_GET['vat_rule']; |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | // Filter by VAT rule. |
@@ -533,13 +533,13 @@ discard block |
||
| 533 | 533 | array( |
| 534 | 534 | 'options' => array_merge( |
| 535 | 535 | array( |
| 536 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
| 536 | + '' => __('All VAT rules', 'invoicing') |
|
| 537 | 537 | ), |
| 538 | 538 | $vat_rules |
| 539 | 539 | ), |
| 540 | 540 | 'name' => 'vat_rule', |
| 541 | 541 | 'id' => 'vat_rule', |
| 542 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
| 542 | + 'selected' => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '', |
|
| 543 | 543 | 'show_option_all' => false, |
| 544 | 544 | 'show_option_none' => false, |
| 545 | 545 | 'class' => 'gdmbx2-text-medium', |
@@ -550,26 +550,26 @@ discard block |
||
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | // Filter by vat class. |
| 553 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 553 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
| 554 | 554 | |
| 555 | 555 | // Sanitize selected vat rule. |
| 556 | 556 | $vat_class = ''; |
| 557 | 557 | $vat_classes = $wpinv_euvat->get_all_classes(); |
| 558 | - if ( isset( $_GET['vat_class'] ) ) { |
|
| 559 | - $vat_class = $_GET['vat_class']; |
|
| 558 | + if (isset($_GET['vat_class'])) { |
|
| 559 | + $vat_class = $_GET['vat_class']; |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | echo wpinv_html_select( |
| 563 | 563 | array( |
| 564 | 564 | 'options' => array_merge( |
| 565 | 565 | array( |
| 566 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
| 566 | + '' => __('All VAT classes', 'invoicing') |
|
| 567 | 567 | ), |
| 568 | 568 | $vat_classes |
| 569 | 569 | ), |
| 570 | 570 | 'name' => 'vat_class', |
| 571 | 571 | 'id' => 'vat_class', |
| 572 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
| 572 | + 'selected' => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '', |
|
| 573 | 573 | 'show_option_all' => false, |
| 574 | 574 | 'show_option_none' => false, |
| 575 | 575 | 'class' => 'gdmbx2-text-medium', |
@@ -579,22 +579,22 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | // Filter by item type. |
| 582 | - $type = ''; |
|
| 583 | - if ( isset( $_GET['type'] ) ) { |
|
| 584 | - $type = $_GET['type']; |
|
| 582 | + $type = ''; |
|
| 583 | + if (isset($_GET['type'])) { |
|
| 584 | + $type = $_GET['type']; |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | echo wpinv_html_select( |
| 588 | 588 | array( |
| 589 | 589 | 'options' => array_merge( |
| 590 | 590 | array( |
| 591 | - '' => __( 'All item types', 'invoicing' ) |
|
| 591 | + '' => __('All item types', 'invoicing') |
|
| 592 | 592 | ), |
| 593 | 593 | wpinv_get_item_types() |
| 594 | 594 | ), |
| 595 | 595 | 'name' => 'type', |
| 596 | 596 | 'id' => 'type', |
| 597 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
| 597 | + 'selected' => in_array($type, wpinv_item_types()) ? $type : '', |
|
| 598 | 598 | 'show_option_all' => false, |
| 599 | 599 | 'show_option_none' => false, |
| 600 | 600 | 'class' => 'gdmbx2-text-medium', |
@@ -606,45 +606,45 @@ discard block |
||
| 606 | 606 | /** |
| 607 | 607 | * Filters the item query. |
| 608 | 608 | */ |
| 609 | - public static function filter_item_query( $query ) { |
|
| 609 | + public static function filter_item_query($query) { |
|
| 610 | 610 | |
| 611 | 611 | // modify the query only if it admin and main query. |
| 612 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
| 612 | + if (!(is_admin() && $query->is_main_query())) { |
|
| 613 | 613 | return $query; |
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | // we want to modify the query for our items. |
| 617 | - if ( 'wpi_item' != $query->query['post_type'] ){ |
|
| 617 | + if ('wpi_item' != $query->query['post_type']) { |
|
| 618 | 618 | return $query; |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 621 | + if (empty($query->query_vars['meta_query'])) { |
|
| 622 | 622 | $query->query_vars['meta_query'] = array(); |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | // Filter vat rule type |
| 626 | - if ( ! empty( $_GET['vat_rule'] ) ) { |
|
| 626 | + if (!empty($_GET['vat_rule'])) { |
|
| 627 | 627 | $query->query_vars['meta_query'][] = array( |
| 628 | 628 | 'key' => '_wpinv_vat_rule', |
| 629 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
| 629 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
| 630 | 630 | 'compare' => '=' |
| 631 | 631 | ); |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | // Filter vat class |
| 635 | - if ( ! empty( $_GET['vat_class'] ) ) { |
|
| 635 | + if (!empty($_GET['vat_class'])) { |
|
| 636 | 636 | $query->query_vars['meta_query'][] = array( |
| 637 | 637 | 'key' => '_wpinv_vat_class', |
| 638 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
| 638 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
| 639 | 639 | 'compare' => '=' |
| 640 | 640 | ); |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | // Filter item type |
| 644 | - if ( ! empty( $_GET['type'] ) ) { |
|
| 644 | + if (!empty($_GET['type'])) { |
|
| 645 | 645 | $query->query_vars['meta_query'][] = array( |
| 646 | 646 | 'key' => '_wpinv_type', |
| 647 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
| 647 | + 'value' => sanitize_text_field($_GET['type']), |
|
| 648 | 648 | 'compare' => '=' |
| 649 | 649 | ); |
| 650 | 650 | } |
@@ -654,15 +654,15 @@ discard block |
||
| 654 | 654 | /** |
| 655 | 655 | * Reorders items. |
| 656 | 656 | */ |
| 657 | - public static function reorder_items( $vars ) { |
|
| 657 | + public static function reorder_items($vars) { |
|
| 658 | 658 | global $typenow; |
| 659 | 659 | |
| 660 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 660 | + if ('wpi_item' !== $typenow || empty($vars['orderby'])) { |
|
| 661 | 661 | return $vars; |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | // By item type. |
| 665 | - if ( 'type' == $vars['orderby'] ) { |
|
| 665 | + if ('type' == $vars['orderby']) { |
|
| 666 | 666 | return array_merge( |
| 667 | 667 | $vars, |
| 668 | 668 | array( |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | // By vat class. |
| 676 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
| 676 | + if ('vat_class' == $vars['orderby']) { |
|
| 677 | 677 | return array_merge( |
| 678 | 678 | $vars, |
| 679 | 679 | array( |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | // By vat rule. |
| 687 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
| 687 | + if ('vat_rule' == $vars['orderby']) { |
|
| 688 | 688 | return array_merge( |
| 689 | 689 | $vars, |
| 690 | 690 | array( |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | // By price. |
| 698 | - if ( 'price' == $vars['orderby'] ) { |
|
| 698 | + if ('price' == $vars['orderby']) { |
|
| 699 | 699 | return array_merge( |
| 700 | 700 | $vars, |
| 701 | 701 | array( |
@@ -712,27 +712,27 @@ discard block |
||
| 712 | 712 | /** |
| 713 | 713 | * Fired when deleting a post. |
| 714 | 714 | */ |
| 715 | - public static function delete_post( $post_id ) { |
|
| 715 | + public static function delete_post($post_id) { |
|
| 716 | 716 | |
| 717 | - switch ( get_post_type( $post_id ) ) { |
|
| 717 | + switch (get_post_type($post_id)) { |
|
| 718 | 718 | |
| 719 | 719 | case 'wpi_item' : |
| 720 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
| 720 | + do_action("getpaid_before_delete_item", new WPInv_Item($post_id)); |
|
| 721 | 721 | break; |
| 722 | 722 | |
| 723 | 723 | case 'wpi_payment_form' : |
| 724 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
| 724 | + do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id)); |
|
| 725 | 725 | break; |
| 726 | 726 | |
| 727 | 727 | case 'wpi_discount' : |
| 728 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
| 728 | + do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id)); |
|
| 729 | 729 | break; |
| 730 | 730 | |
| 731 | 731 | case 'wpi_invoice' : |
| 732 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 733 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
| 734 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
| 735 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 732 | + $invoice = new WPInv_Invoice($post_id); |
|
| 733 | + do_action("getpaid_before_delete_invoice", $invoice); |
|
| 734 | + $invoice->get_data_store()->delete_items($invoice); |
|
| 735 | + $invoice->get_data_store()->delete_special_fields($invoice); |
|
| 736 | 736 | break; |
| 737 | 737 | } |
| 738 | 738 | } |
@@ -12,170 +12,170 @@ 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( $invoice ); |
|
| 43 | - |
|
| 44 | - // Save the invoice. |
|
| 45 | - $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( $invoice ); |
|
| 43 | + |
|
| 44 | + // Save the invoice. |
|
| 45 | + $invoice->recalculate_total(); |
|
| 46 | 46 | $invoice->save(); |
| 47 | 47 | |
| 48 | - // Send to the gateway. |
|
| 49 | - $this->post_process_submission( $invoice, $prepared ); |
|
| 50 | - } |
|
| 48 | + // Send to the gateway. |
|
| 49 | + $this->post_process_submission( $invoice, $prepared ); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Validates the submission. |
|
| 54 | - * |
|
| 55 | - */ |
|
| 56 | - protected function validate_submission() { |
|
| 52 | + /** |
|
| 53 | + * Validates the submission. |
|
| 54 | + * |
|
| 55 | + */ |
|
| 56 | + protected function validate_submission() { |
|
| 57 | 57 | |
| 58 | - $submission = $this->payment_form_submission; |
|
| 59 | - $data = $submission->get_data(); |
|
| 58 | + $submission = $this->payment_form_submission; |
|
| 59 | + $data = $submission->get_data(); |
|
| 60 | 60 | |
| 61 | - // Do we have an error? |
|
| 61 | + // Do we have an error? |
|
| 62 | 62 | if ( ! empty( $submission->last_error ) ) { |
| 63 | - wp_send_json_error( $submission->last_error ); |
|
| 63 | + wp_send_json_error( $submission->last_error ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - // We need a billing email. |
|
| 66 | + // We need a billing email. |
|
| 67 | 67 | if ( ! $submission->has_billing_email() ) { |
| 68 | 68 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 72 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 73 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 74 | - } |
|
| 71 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 72 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 73 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // Ensure the gateway is active. |
|
| 77 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 78 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 79 | - } |
|
| 76 | + // Ensure the gateway is active. |
|
| 77 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 78 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // Clear any existing errors. |
|
| 82 | - wpinv_clear_errors(); |
|
| 81 | + // Clear any existing errors. |
|
| 82 | + wpinv_clear_errors(); |
|
| 83 | 83 | |
| 84 | - // Allow themes and plugins to hook to errors |
|
| 85 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 84 | + // Allow themes and plugins to hook to errors |
|
| 85 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 86 | 86 | |
| 87 | - // Do we have any errors? |
|
| 87 | + // Do we have any errors? |
|
| 88 | 88 | if ( wpinv_get_errors() ) { |
| 89 | 89 | wp_send_json_error( getpaid_get_errors_html() ); |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Retrieves submission items. |
|
| 96 | - * |
|
| 97 | - * @return GetPaid_Form_Item[] |
|
| 98 | - */ |
|
| 99 | - protected function get_submission_items() { |
|
| 94 | + /** |
|
| 95 | + * Retrieves submission items. |
|
| 96 | + * |
|
| 97 | + * @return GetPaid_Form_Item[] |
|
| 98 | + */ |
|
| 99 | + protected function get_submission_items() { |
|
| 100 | 100 | |
| 101 | - $items = $this->payment_form_submission->get_items(); |
|
| 101 | + $items = $this->payment_form_submission->get_items(); |
|
| 102 | 102 | |
| 103 | 103 | // Ensure that we have items. |
| 104 | 104 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
| 105 | 105 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
| 106 | - } |
|
| 107 | - |
|
| 108 | - return $items; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Retrieves submission invoice. |
|
| 113 | - * |
|
| 114 | - * @return WPInv_Invoice |
|
| 115 | - */ |
|
| 116 | - protected function get_submission_invoice() { |
|
| 117 | - $submission = $this->payment_form_submission; |
|
| 118 | - |
|
| 119 | - if ( ! $submission->has_invoice() ) { |
|
| 120 | - $invoice = new WPInv_Invoice(); |
|
| 121 | - $invoice->created_via( 'payment_form' ); |
|
| 122 | - return $invoice; |
|
| 123 | 106 | } |
| 124 | 107 | |
| 125 | - $invoice = $submission->get_invoice(); |
|
| 108 | + return $items; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Retrieves submission invoice. |
|
| 113 | + * |
|
| 114 | + * @return WPInv_Invoice |
|
| 115 | + */ |
|
| 116 | + protected function get_submission_invoice() { |
|
| 117 | + $submission = $this->payment_form_submission; |
|
| 126 | 118 | |
| 127 | - // Make sure that it is neither paid or refunded. |
|
| 128 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 129 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 130 | - } |
|
| 119 | + if ( ! $submission->has_invoice() ) { |
|
| 120 | + $invoice = new WPInv_Invoice(); |
|
| 121 | + $invoice->created_via( 'payment_form' ); |
|
| 122 | + return $invoice; |
|
| 123 | + } |
|
| 131 | 124 | |
| 132 | - return $invoice; |
|
| 133 | - } |
|
| 125 | + $invoice = $submission->get_invoice(); |
|
| 134 | 126 | |
| 135 | - /** |
|
| 136 | - * Processes the submission invoice. |
|
| 137 | - * |
|
| 138 | - * @param WPInv_Invoice $invoice |
|
| 139 | - * @param GetPaid_Form_Item[] $items |
|
| 140 | - * @return WPInv_Invoice |
|
| 141 | - */ |
|
| 142 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 127 | + // Make sure that it is neither paid or refunded. |
|
| 128 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 129 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 130 | + } |
|
| 143 | 131 | |
| 144 | - $submission = $this->payment_form_submission; |
|
| 145 | - $data = $submission->get_data(); |
|
| 132 | + return $invoice; |
|
| 133 | + } |
|
| 146 | 134 | |
| 147 | - // Set-up the invoice details. |
|
| 148 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 149 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 150 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 135 | + /** |
|
| 136 | + * Processes the submission invoice. |
|
| 137 | + * |
|
| 138 | + * @param WPInv_Invoice $invoice |
|
| 139 | + * @param GetPaid_Form_Item[] $items |
|
| 140 | + * @return WPInv_Invoice |
|
| 141 | + */ |
|
| 142 | + protected function process_submission_invoice( $invoice, $items ) { |
|
| 143 | + |
|
| 144 | + $submission = $this->payment_form_submission; |
|
| 145 | + $data = $submission->get_data(); |
|
| 146 | + |
|
| 147 | + // Set-up the invoice details. |
|
| 148 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 149 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 150 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 151 | 151 | $invoice->set_items( $items ); |
| 152 | 152 | $invoice->set_fees( $submission->get_fees() ); |
| 153 | 153 | $invoice->set_taxes( $submission->get_taxes() ); |
| 154 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 155 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 154 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
| 155 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 156 | 156 | |
| 157 | - if ( $submission->has_discount_code() ) { |
|
| 157 | + if ( $submission->has_discount_code() ) { |
|
| 158 | 158 | $invoice->set_discount_code( $submission->get_discount_code() ); |
| 159 | - } |
|
| 160 | - |
|
| 161 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 162 | - return $invoice; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Retrieves the submission's customer. |
|
| 167 | - * |
|
| 168 | - * @return int The customer id. |
|
| 169 | - */ |
|
| 170 | - protected function get_submission_customer() { |
|
| 171 | - $submission = $this->payment_form_submission; |
|
| 172 | - |
|
| 173 | - // If this is an existing invoice... |
|
| 174 | - if ( $submission->has_invoice() ) { |
|
| 175 | - return $submission->get_invoice()->get_user_id(); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // (Maybe) create the user. |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + getpaid_maybe_add_default_address( $invoice ); |
|
| 162 | + return $invoice; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Retrieves the submission's customer. |
|
| 167 | + * |
|
| 168 | + * @return int The customer id. |
|
| 169 | + */ |
|
| 170 | + protected function get_submission_customer() { |
|
| 171 | + $submission = $this->payment_form_submission; |
|
| 172 | + |
|
| 173 | + // If this is an existing invoice... |
|
| 174 | + if ( $submission->has_invoice() ) { |
|
| 175 | + return $submission->get_invoice()->get_user_id(); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // (Maybe) create the user. |
|
| 179 | 179 | $user = get_current_user_id(); |
| 180 | 180 | |
| 181 | 181 | if ( empty( $user ) ) { |
@@ -192,31 +192,31 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | if ( is_numeric( $user ) ) { |
| 194 | 194 | return $user; |
| 195 | - } |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - return $user->ID; |
|
| 197 | + return $user->ID; |
|
| 198 | 198 | |
| 199 | - } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 201 | + /** |
|
| 202 | 202 | * Prepares submission data for saving to the database. |
| 203 | 203 | * |
| 204 | - * @param WPInv_Invoice $invoice |
|
| 204 | + * @param WPInv_Invoice $invoice |
|
| 205 | 205 | */ |
| 206 | 206 | public function prepare_submission_data_for_saving( &$invoice ) { |
| 207 | 207 | |
| 208 | - $submission = $this->payment_form_submission; |
|
| 208 | + $submission = $this->payment_form_submission; |
|
| 209 | 209 | |
| 210 | - // Prepared submission details. |
|
| 210 | + // Prepared submission details. |
|
| 211 | 211 | $prepared = array(); |
| 212 | 212 | |
| 213 | 213 | // Raw submission details. |
| 214 | - $data = $submission->get_data(); |
|
| 214 | + $data = $submission->get_data(); |
|
| 215 | 215 | |
| 216 | - // Loop throught the submitted details. |
|
| 216 | + // Loop throught the submitted details. |
|
| 217 | 217 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
| 218 | 218 | |
| 219 | - // Skip premade fields. |
|
| 219 | + // Skip premade fields. |
|
| 220 | 220 | if ( ! empty( $field['premade'] ) ) { |
| 221 | 221 | continue; |
| 222 | 222 | } |
@@ -259,21 +259,21 @@ discard block |
||
| 259 | 259 | $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - } |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - return $prepared; |
|
| 264 | + return $prepared; |
|
| 265 | 265 | |
| 266 | - } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Confirms the submission is valid and send users to the gateway. |
|
| 270 | - * |
|
| 271 | - * @param WPInv_Invoice $invoice |
|
| 272 | - * @param array $prepared_payment_form_data |
|
| 273 | - */ |
|
| 274 | - protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
| 268 | + /** |
|
| 269 | + * Confirms the submission is valid and send users to the gateway. |
|
| 270 | + * |
|
| 271 | + * @param WPInv_Invoice $invoice |
|
| 272 | + * @param array $prepared_payment_form_data |
|
| 273 | + */ |
|
| 274 | + protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
| 275 | 275 | |
| 276 | - // Ensure the invoice exists. |
|
| 276 | + // Ensure the invoice exists. |
|
| 277 | 277 | if ( ! $invoice->exists() ) { |
| 278 | 278 | wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
| 279 | 279 | } |
@@ -281,65 +281,65 @@ discard block |
||
| 281 | 281 | // Save payment form data. |
| 282 | 282 | if ( ! empty( $prepared_payment_form_data ) ) { |
| 283 | 283 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
| 284 | - } |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - // Backwards compatibility. |
|
| 286 | + // Backwards compatibility. |
|
| 287 | 287 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
| 288 | 288 | |
| 289 | - $this->process_payment( $invoice ); |
|
| 289 | + $this->process_payment( $invoice ); |
|
| 290 | 290 | |
| 291 | 291 | // If we are here, there was an error. |
| 292 | - wpinv_send_back_to_checkout(); |
|
| 292 | + wpinv_send_back_to_checkout(); |
|
| 293 | 293 | |
| 294 | - } |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - /** |
|
| 297 | - * Processes the actual payment. |
|
| 298 | - * |
|
| 299 | - * @param WPInv_Invoice $invoice |
|
| 300 | - */ |
|
| 301 | - protected function process_payment( $invoice ) { |
|
| 296 | + /** |
|
| 297 | + * Processes the actual payment. |
|
| 298 | + * |
|
| 299 | + * @param WPInv_Invoice $invoice |
|
| 300 | + */ |
|
| 301 | + protected function process_payment( $invoice ) { |
|
| 302 | 302 | |
| 303 | - $submission = $this->payment_form_submission; |
|
| 303 | + $submission = $this->payment_form_submission; |
|
| 304 | 304 | |
| 305 | - // No need to send free invoices to the gateway. |
|
| 306 | - if ( $invoice->is_free() ) { |
|
| 307 | - $invoice->set_gateway( 'none' ); |
|
| 308 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 309 | - $invoice->mark_paid(); |
|
| 310 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 311 | - } |
|
| 305 | + // No need to send free invoices to the gateway. |
|
| 306 | + if ( $invoice->is_free() ) { |
|
| 307 | + $invoice->set_gateway( 'none' ); |
|
| 308 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 309 | + $invoice->mark_paid(); |
|
| 310 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - // Clear any checkout errors. |
|
| 314 | - wpinv_clear_errors(); |
|
| 313 | + // Clear any checkout errors. |
|
| 314 | + wpinv_clear_errors(); |
|
| 315 | 315 | |
| 316 | - // Fires before sending to the gateway. |
|
| 317 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 316 | + // Fires before sending to the gateway. |
|
| 317 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 318 | 318 | |
| 319 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 320 | - $submission_data = $submission->get_data(); |
|
| 321 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 322 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 319 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 320 | + $submission_data = $submission->get_data(); |
|
| 321 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 322 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 323 | 323 | |
| 324 | - // Validate the currency. |
|
| 325 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 326 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
| 327 | - } |
|
| 324 | + // Validate the currency. |
|
| 325 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 326 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - // Check to see if we have any errors. |
|
| 330 | - if ( wpinv_get_errors() ) { |
|
| 331 | - wpinv_send_back_to_checkout(); |
|
| 332 | - } |
|
| 329 | + // Check to see if we have any errors. |
|
| 330 | + if ( wpinv_get_errors() ) { |
|
| 331 | + wpinv_send_back_to_checkout(); |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - // Send info to the gateway for payment processing |
|
| 335 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 334 | + // Send info to the gateway for payment processing |
|
| 335 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 336 | 336 | |
| 337 | - // Backwards compatibility. |
|
| 338 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 337 | + // Backwards compatibility. |
|
| 338 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 339 | 339 | |
| 340 | - } |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - /** |
|
| 342 | + /** |
|
| 343 | 343 | * Sends a redrect response to payment details. |
| 344 | 344 | * |
| 345 | 345 | */ |
@@ -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,15 +38,15 @@ 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 ); |
|
| 42 | - $prepared = $this->prepare_submission_data_for_saving( $invoice ); |
|
| 41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
| 42 | + $prepared = $this->prepare_submission_data_for_saving($invoice); |
|
| 43 | 43 | |
| 44 | 44 | // Save the invoice. |
| 45 | 45 | $invoice->recalculate_total(); |
| 46 | 46 | $invoice->save(); |
| 47 | 47 | |
| 48 | 48 | // Send to the gateway. |
| 49 | - $this->post_process_submission( $invoice, $prepared ); |
|
| 49 | + $this->post_process_submission($invoice, $prepared); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -59,34 +59,34 @@ discard block |
||
| 59 | 59 | $data = $submission->get_data(); |
| 60 | 60 | |
| 61 | 61 | // Do we have an error? |
| 62 | - if ( ! empty( $submission->last_error ) ) { |
|
| 63 | - wp_send_json_error( $submission->last_error ); |
|
| 62 | + if (!empty($submission->last_error)) { |
|
| 63 | + wp_send_json_error($submission->last_error); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // We need a billing email. |
| 67 | - if ( ! $submission->has_billing_email() ) { |
|
| 68 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
| 67 | + if (!$submission->has_billing_email()) { |
|
| 68 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // Non-recurring gateways should not be allowed to process recurring invoices. |
| 72 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 73 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 72 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
| 73 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // Ensure the gateway is active. |
| 77 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 78 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 77 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
| 78 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // Clear any existing errors. |
| 82 | 82 | wpinv_clear_errors(); |
| 83 | 83 | |
| 84 | 84 | // Allow themes and plugins to hook to errors |
| 85 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 85 | + do_action('getpaid_checkout_error_checks', $submission); |
|
| 86 | 86 | |
| 87 | 87 | // Do we have any errors? |
| 88 | - if ( wpinv_get_errors() ) { |
|
| 89 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
| 88 | + if (wpinv_get_errors()) { |
|
| 89 | + wp_send_json_error(getpaid_get_errors_html()); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | } |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | $items = $this->payment_form_submission->get_items(); |
| 102 | 102 | |
| 103 | 103 | // Ensure that we have items. |
| 104 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
| 105 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
| 104 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
| 105 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | return $items; |
@@ -116,17 +116,17 @@ discard block |
||
| 116 | 116 | protected function get_submission_invoice() { |
| 117 | 117 | $submission = $this->payment_form_submission; |
| 118 | 118 | |
| 119 | - if ( ! $submission->has_invoice() ) { |
|
| 119 | + if (!$submission->has_invoice()) { |
|
| 120 | 120 | $invoice = new WPInv_Invoice(); |
| 121 | - $invoice->created_via( 'payment_form' ); |
|
| 121 | + $invoice->created_via('payment_form'); |
|
| 122 | 122 | return $invoice; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $invoice = $submission->get_invoice(); |
| 126 | 126 | |
| 127 | 127 | // Make sure that it is neither paid or refunded. |
| 128 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 129 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 128 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 129 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | return $invoice; |
@@ -139,26 +139,26 @@ discard block |
||
| 139 | 139 | * @param GetPaid_Form_Item[] $items |
| 140 | 140 | * @return WPInv_Invoice |
| 141 | 141 | */ |
| 142 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 142 | + protected function process_submission_invoice($invoice, $items) { |
|
| 143 | 143 | |
| 144 | 144 | $submission = $this->payment_form_submission; |
| 145 | 145 | $data = $submission->get_data(); |
| 146 | 146 | |
| 147 | 147 | // Set-up the invoice details. |
| 148 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 149 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 150 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 151 | - $invoice->set_items( $items ); |
|
| 152 | - $invoice->set_fees( $submission->get_fees() ); |
|
| 153 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
| 154 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 155 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 156 | - |
|
| 157 | - if ( $submission->has_discount_code() ) { |
|
| 158 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
| 148 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
| 149 | + $invoice->set_user_id($this->get_submission_customer()); |
|
| 150 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
| 151 | + $invoice->set_items($items); |
|
| 152 | + $invoice->set_fees($submission->get_fees()); |
|
| 153 | + $invoice->set_taxes($submission->get_taxes()); |
|
| 154 | + $invoice->set_discounts($submission->get_discounts()); |
|
| 155 | + $invoice->set_gateway($data['wpi-gateway']); |
|
| 156 | + |
|
| 157 | + if ($submission->has_discount_code()) { |
|
| 158 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 161 | + getpaid_maybe_add_default_address($invoice); |
|
| 162 | 162 | return $invoice; |
| 163 | 163 | } |
| 164 | 164 | |
@@ -171,26 +171,26 @@ discard block |
||
| 171 | 171 | $submission = $this->payment_form_submission; |
| 172 | 172 | |
| 173 | 173 | // If this is an existing invoice... |
| 174 | - if ( $submission->has_invoice() ) { |
|
| 174 | + if ($submission->has_invoice()) { |
|
| 175 | 175 | return $submission->get_invoice()->get_user_id(); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // (Maybe) create the user. |
| 179 | 179 | $user = get_current_user_id(); |
| 180 | 180 | |
| 181 | - if ( empty( $user ) ) { |
|
| 182 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
| 181 | + if (empty($user)) { |
|
| 182 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if ( empty( $user ) ) { |
|
| 186 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
| 185 | + if (empty($user)) { |
|
| 186 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ( is_wp_error( $user ) ) { |
|
| 190 | - wp_send_json_error( $user->get_error_message() ); |
|
| 189 | + if (is_wp_error($user)) { |
|
| 190 | + wp_send_json_error($user->get_error_message()); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - if ( is_numeric( $user ) ) { |
|
| 193 | + if (is_numeric($user)) { |
|
| 194 | 194 | return $user; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @param WPInv_Invoice $invoice |
| 205 | 205 | */ |
| 206 | - public function prepare_submission_data_for_saving( &$invoice ) { |
|
| 206 | + public function prepare_submission_data_for_saving(&$invoice) { |
|
| 207 | 207 | |
| 208 | 208 | $submission = $this->payment_form_submission; |
| 209 | 209 | |
@@ -214,49 +214,49 @@ discard block |
||
| 214 | 214 | $data = $submission->get_data(); |
| 215 | 215 | |
| 216 | 216 | // Loop throught the submitted details. |
| 217 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
| 217 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
| 218 | 218 | |
| 219 | 219 | // Skip premade fields. |
| 220 | - if ( ! empty( $field['premade'] ) ) { |
|
| 220 | + if (!empty($field['premade'])) { |
|
| 221 | 221 | continue; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | // If it is required and not set, abort. |
| 225 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
| 226 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
| 225 | + if (!$submission->is_required_field_set($field)) { |
|
| 226 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // Handle address fields. |
| 230 | - if ( $field['type'] == 'address' ) { |
|
| 230 | + if ($field['type'] == 'address') { |
|
| 231 | 231 | |
| 232 | - foreach ( $field['fields'] as $address_field ) { |
|
| 232 | + foreach ($field['fields'] as $address_field) { |
|
| 233 | 233 | |
| 234 | 234 | // skip if it is not visible. |
| 235 | - if ( empty( $address_field['visible'] ) ) { |
|
| 235 | + if (empty($address_field['visible'])) { |
|
| 236 | 236 | continue; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // If it is required and not set, abort |
| 240 | - if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) { |
|
| 241 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
| 240 | + if (!empty($address_field['required']) && empty($data[$address_field['name']])) { |
|
| 241 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - if ( isset( $data[ $address_field['name'] ] ) ) { |
|
| 245 | - $name = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
| 244 | + if (isset($data[$address_field['name']])) { |
|
| 245 | + $name = str_replace('wpinv_', '', $address_field['name']); |
|
| 246 | 246 | $method = "set_$name"; |
| 247 | - $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) ); |
|
| 247 | + $invoice->$method(wpinv_clean($data[$address_field['name']])); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - } else if ( isset( $data[ $field['id'] ] ) ) { |
|
| 252 | + } else if (isset($data[$field['id']])) { |
|
| 253 | 253 | $label = $field['id']; |
| 254 | 254 | |
| 255 | - if ( isset( $field['label'] ) ) { |
|
| 255 | + if (isset($field['label'])) { |
|
| 256 | 256 | $label = $field['label']; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
|
| 259 | + $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | } |
@@ -271,22 +271,22 @@ discard block |
||
| 271 | 271 | * @param WPInv_Invoice $invoice |
| 272 | 272 | * @param array $prepared_payment_form_data |
| 273 | 273 | */ |
| 274 | - protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
| 274 | + protected function post_process_submission($invoice, $prepared_payment_form_data) { |
|
| 275 | 275 | |
| 276 | 276 | // Ensure the invoice exists. |
| 277 | - if ( ! $invoice->exists() ) { |
|
| 278 | - wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
|
| 277 | + if (!$invoice->exists()) { |
|
| 278 | + wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing')); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // Save payment form data. |
| 282 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 283 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
|
| 282 | + if (!empty($prepared_payment_form_data)) { |
|
| 283 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Backwards compatibility. |
| 287 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
| 287 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
| 288 | 288 | |
| 289 | - $this->process_payment( $invoice ); |
|
| 289 | + $this->process_payment($invoice); |
|
| 290 | 290 | |
| 291 | 291 | // If we are here, there was an error. |
| 292 | 292 | wpinv_send_back_to_checkout(); |
@@ -298,44 +298,44 @@ discard block |
||
| 298 | 298 | * |
| 299 | 299 | * @param WPInv_Invoice $invoice |
| 300 | 300 | */ |
| 301 | - protected function process_payment( $invoice ) { |
|
| 301 | + protected function process_payment($invoice) { |
|
| 302 | 302 | |
| 303 | 303 | $submission = $this->payment_form_submission; |
| 304 | 304 | |
| 305 | 305 | // No need to send free invoices to the gateway. |
| 306 | - if ( $invoice->is_free() ) { |
|
| 307 | - $invoice->set_gateway( 'none' ); |
|
| 308 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 306 | + if ($invoice->is_free()) { |
|
| 307 | + $invoice->set_gateway('none'); |
|
| 308 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
| 309 | 309 | $invoice->mark_paid(); |
| 310 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 310 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | // Clear any checkout errors. |
| 314 | 314 | wpinv_clear_errors(); |
| 315 | 315 | |
| 316 | 316 | // Fires before sending to the gateway. |
| 317 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 317 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
| 318 | 318 | |
| 319 | 319 | // Allow the sumission data to be modified before it is sent to the gateway. |
| 320 | 320 | $submission_data = $submission->get_data(); |
| 321 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 322 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 321 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
| 322 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
| 323 | 323 | |
| 324 | 324 | // Validate the currency. |
| 325 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 326 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
| 325 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
| 326 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing')); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | // Check to see if we have any errors. |
| 330 | - if ( wpinv_get_errors() ) { |
|
| 330 | + if (wpinv_get_errors()) { |
|
| 331 | 331 | wpinv_send_back_to_checkout(); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | // Send info to the gateway for payment processing |
| 335 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 335 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
| 336 | 336 | |
| 337 | 337 | // Backwards compatibility. |
| 338 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 338 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
| 339 | 339 | |
| 340 | 340 | } |
| 341 | 341 | |
@@ -343,9 +343,9 @@ discard block |
||
| 343 | 343 | * Sends a redrect response to payment details. |
| 344 | 344 | * |
| 345 | 345 | */ |
| 346 | - public function send_redirect_response( $url ) { |
|
| 347 | - $url = urlencode( $url ); |
|
| 348 | - wp_send_json_success( $url ); |
|
| 346 | + public function send_redirect_response($url) { |
|
| 347 | + $url = urlencode($url); |
|
| 348 | + wp_send_json_success($url); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | } |