@@ -8,24 +8,24 @@  | 
                                                    ||
| 8 | 8 | * @var GetPaid_Payment_Form $form The current payment form  | 
                                                        
| 9 | 9 | */  | 
                                                        
| 10 | 10 | |
| 11 | -defined( 'ABSPATH' ) || exit;  | 
                                                        |
| 11 | +defined('ABSPATH') || exit; | 
                                                        |
| 12 | 12 | |
| 13 | -if ( ! getpaid_has_published_discount() ) { | 
                                                        |
| 13 | +if (!getpaid_has_published_discount()) { | 
                                                        |
| 14 | 14 | return;  | 
                                                        
| 15 | 15 | }  | 
                                                        
| 16 | 16 | |
| 17 | -$placeholder = esc_attr( $input_label );  | 
                                                        |
| 18 | -$label = sanitize_text_field( $button_label );  | 
                                                        |
| 17 | +$placeholder = esc_attr($input_label);  | 
                                                        |
| 18 | +$label = sanitize_text_field($button_label);  | 
                                                        |
| 19 | 19 | |
| 20 | -if ( ! empty( $description ) ) { | 
                                                        |
| 20 | +if (!empty($description)) { | 
                                                        |
| 21 | 21 | $description = "<small class='form-text text-muted'>$description</small>";  | 
                                                        
| 22 | 22 |  } else { | 
                                                        
| 23 | 23 | $description = '';  | 
                                                        
| 24 | 24 | }  | 
                                                        
| 25 | 25 | |
| 26 | 26 | $discount_code = '';  | 
                                                        
| 27 | -if ( ! empty( $form->invoice ) ) { | 
                                                        |
| 28 | - $discount_code = esc_attr( $form->invoice->get_discount_code() );  | 
                                                        |
| 27 | +if (!empty($form->invoice)) { | 
                                                        |
| 28 | + $discount_code = esc_attr($form->invoice->get_discount_code());  | 
                                                        |
| 29 | 29 | }  | 
                                                        
| 30 | 30 | |
| 31 | 31 | ?>  | 
                                                        
@@ -6,7 +6,7 @@ discard block  | 
                                                    ||
| 6 | 6 | * @package Invoicing  | 
                                                        
| 7 | 7 | */  | 
                                                        
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit;  | 
                                                        |
| 9 | +defined('ABSPATH') || exit; | 
                                                        |
| 10 | 10 | |
| 11 | 11 | /**  | 
                                                        
| 12 | 12 | * Returns an array of discount type.  | 
                                                        
@@ -17,8 +17,8 @@ discard block  | 
                                                    ||
| 17 | 17 | return apply_filters(  | 
                                                        
| 18 | 18 | 'wpinv_discount_types',  | 
                                                        
| 19 | 19 | array(  | 
                                                        
| 20 | - 'percent' => __( 'Percentage', 'invoicing' ),  | 
                                                        |
| 21 | - 'flat' => __( 'Flat Amount', 'invoicing' ),  | 
                                                        |
| 20 | +            'percent'   => __('Percentage', 'invoicing'), | 
                                                        |
| 21 | +            'flat'     => __('Flat Amount', 'invoicing'), | 
                                                        |
| 22 | 22 | )  | 
                                                        
| 23 | 23 | );  | 
                                                        
| 24 | 24 | }  | 
                                                        
@@ -28,46 +28,46 @@ discard block  | 
                                                    ||
| 28 | 28 | *  | 
                                                        
| 29 | 29 | * @return string  | 
                                                        
| 30 | 30 | */  | 
                                                        
| 31 | -function wpinv_get_discount_type_name( $type = '' ) { | 
                                                        |
| 31 | +function wpinv_get_discount_type_name($type = '') { | 
                                                        |
| 32 | 32 | $types = wpinv_get_discount_types();  | 
                                                        
| 33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type;  | 
                                                        |
| 33 | + return isset($types[$type]) ? $types[$type] : $type;  | 
                                                        |
| 34 | 34 | }  | 
                                                        
| 35 | 35 | |
| 36 | 36 | /**  | 
                                                        
| 37 | 37 | * Deletes a discount via the admin page.  | 
                                                        
| 38 | 38 | *  | 
                                                        
| 39 | 39 | */  | 
                                                        
| 40 | -function wpinv_delete_discount( $data ) { | 
                                                        |
| 40 | +function wpinv_delete_discount($data) { | 
                                                        |
| 41 | 41 | |
| 42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) );  | 
                                                        |
| 43 | - $discount->delete( true );  | 
                                                        |
| 42 | + $discount = new WPInv_Discount(absint($data['discount']));  | 
                                                        |
| 43 | + $discount->delete(true);  | 
                                                        |
| 44 | 44 | |
| 45 | 45 | }  | 
                                                        
| 46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' );  | 
                                                        |
| 46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); | 
                                                        |
| 47 | 47 | |
| 48 | 48 | /**  | 
                                                        
| 49 | 49 | * Deactivates a discount via the admin page.  | 
                                                        
| 50 | 50 | */  | 
                                                        
| 51 | -function wpinv_activate_discount( $data ) { | 
                                                        |
| 51 | +function wpinv_activate_discount($data) { | 
                                                        |
| 52 | 52 | |
| 53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) );  | 
                                                        |
| 54 | - $discount->set_status( 'publish' );  | 
                                                        |
| 53 | + $discount = new WPInv_Discount(absint($data['discount']));  | 
                                                        |
| 54 | +    $discount->set_status('publish'); | 
                                                        |
| 55 | 55 | $discount->save();  | 
                                                        
| 56 | 56 | |
| 57 | 57 | }  | 
                                                        
| 58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' );  | 
                                                        |
| 58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); | 
                                                        |
| 59 | 59 | |
| 60 | 60 | /**  | 
                                                        
| 61 | 61 | * Activates a discount via the admin page.  | 
                                                        
| 62 | 62 | */  | 
                                                        
| 63 | -function wpinv_deactivate_discount( $data ) { | 
                                                        |
| 63 | +function wpinv_deactivate_discount($data) { | 
                                                        |
| 64 | 64 | |
| 65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) );  | 
                                                        |
| 66 | - $discount->set_status( 'pending' );  | 
                                                        |
| 65 | + $discount = new WPInv_Discount(absint($data['discount']));  | 
                                                        |
| 66 | +    $discount->set_status('pending'); | 
                                                        |
| 67 | 67 | $discount->save();  | 
                                                        
| 68 | 68 | |
| 69 | 69 | }  | 
                                                        
| 70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' );  | 
                                                        |
| 70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); | 
                                                        |
| 71 | 71 | |
| 72 | 72 | /**  | 
                                                        
| 73 | 73 | * Fetches a discount object.  | 
                                                        
@@ -76,8 +76,8 @@ discard block  | 
                                                    ||
| 76 | 76 | * @since 1.0.15  | 
                                                        
| 77 | 77 | * @return WPInv_Discount  | 
                                                        
| 78 | 78 | */  | 
                                                        
| 79 | -function wpinv_get_discount( $discount ) { | 
                                                        |
| 80 | - return new WPInv_Discount( $discount );  | 
                                                        |
| 79 | +function wpinv_get_discount($discount) { | 
                                                        |
| 80 | + return new WPInv_Discount($discount);  | 
                                                        |
| 81 | 81 | }  | 
                                                        
| 82 | 82 | |
| 83 | 83 | /**  | 
                                                        
@@ -87,8 +87,8 @@ discard block  | 
                                                    ||
| 87 | 87 | * @since 1.0.15  | 
                                                        
| 88 | 88 | * @return WPInv_Discount  | 
                                                        
| 89 | 89 | */  | 
                                                        
| 90 | -function wpinv_get_discount_obj( $discount = 0 ) { | 
                                                        |
| 91 | - return new WPInv_Discount( $discount );  | 
                                                        |
| 90 | +function wpinv_get_discount_obj($discount = 0) { | 
                                                        |
| 91 | + return new WPInv_Discount($discount);  | 
                                                        |
| 92 | 92 | }  | 
                                                        
| 93 | 93 | |
| 94 | 94 | /**  | 
                                                        
@@ -98,10 +98,10 @@ discard block  | 
                                                    ||
| 98 | 98 | * @param string|int $value The field value  | 
                                                        
| 99 | 99 | * @return bool|WPInv_Discount  | 
                                                        
| 100 | 100 | */  | 
                                                        
| 101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { | 
                                                        |
| 102 | - $discount = new WPInv_Discount( $value );  | 
                                                        |
| 101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { | 
                                                        |
| 102 | + $discount = new WPInv_Discount($value);  | 
                                                        |
| 103 | 103 | |
| 104 | -    if ( $discount->get_id() != 0 ) { | 
                                                        |
| 104 | +    if ($discount->get_id() != 0) { | 
                                                        |
| 105 | 105 | return $discount;  | 
                                                        
| 106 | 106 | }  | 
                                                        
| 107 | 107 | |
@@ -116,9 +116,9 @@ discard block  | 
                                                    ||
| 116 | 116 |  function wpinv_get_discount_statuses() { | 
                                                        
| 117 | 117 | |
| 118 | 118 | return array(  | 
                                                        
| 119 | - 'expired' => __( 'Expired', 'invoicing' ),  | 
                                                        |
| 120 | - 'publish' => __( 'Active', 'invoicing' ),  | 
                                                        |
| 121 | - 'inactive' => __( 'Inactive', 'invoicing' ),  | 
                                                        |
| 119 | +        'expired'  => __('Expired', 'invoicing'), | 
                                                        |
| 120 | +        'publish'  => __('Active', 'invoicing'), | 
                                                        |
| 121 | +        'inactive' => __('Inactive', 'invoicing'), | 
                                                        |
| 122 | 122 | );  | 
                                                        
| 123 | 123 | |
| 124 | 124 | }  | 
                                                        
@@ -126,9 +126,9 @@ discard block  | 
                                                    ||
| 126 | 126 | /**  | 
                                                        
| 127 | 127 | * Retrieves an invoice status label.  | 
                                                        
| 128 | 128 | */  | 
                                                        
| 129 | -function wpinv_discount_status( $status ) { | 
                                                        |
| 129 | +function wpinv_discount_status($status) { | 
                                                        |
| 130 | 130 | $statuses = wpinv_get_discount_statuses();  | 
                                                        
| 131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' );  | 
                                                        |
| 131 | +    return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); | 
                                                        |
| 132 | 132 | }  | 
                                                        
| 133 | 133 | |
| 134 | 134 | /**  | 
                                                        
@@ -138,12 +138,12 @@ discard block  | 
                                                    ||
| 138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code.  | 
                                                        
| 139 | 139 | * @return bool  | 
                                                        
| 140 | 140 | */  | 
                                                        
| 141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { | 
                                                        |
| 141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { | 
                                                        |
| 142 | 142 | |
| 143 | -    if( ! empty( $discount ) ) { | 
                                                        |
| 144 | - $discount = wpinv_get_discount_obj( $discount );  | 
                                                        |
| 143 | +    if (!empty($discount)) { | 
                                                        |
| 144 | + $discount = wpinv_get_discount_obj($discount);  | 
                                                        |
| 145 | 145 |      } else { | 
                                                        
| 146 | - $discount = wpinv_get_discount_obj( $code );  | 
                                                        |
| 146 | + $discount = wpinv_get_discount_obj($code);  | 
                                                        |
| 147 | 147 | }  | 
                                                        
| 148 | 148 | |
| 149 | 149 | return $discount->get_is_recurring();  | 
                                                        
@@ -158,35 +158,35 @@ discard block  | 
                                                    ||
| 158 | 158 | * @param WPInv_Discount $discount  | 
                                                        
| 159 | 159 | * @return array  | 
                                                        
| 160 | 160 | */  | 
                                                        
| 161 | -function getpaid_calculate_invoice_discount( $invoice, $discount ) { | 
                                                        |
| 161 | +function getpaid_calculate_invoice_discount($invoice, $discount) { | 
                                                        |
| 162 | 162 | |
| 163 | 163 | $initial_discount = 0;  | 
                                                        
| 164 | 164 | $recurring_discount = 0;  | 
                                                        
| 165 | 165 | |
| 166 | -	foreach ( $invoice->get_items() as $item ) { | 
                                                        |
| 166 | +	foreach ($invoice->get_items() as $item) { | 
                                                        |
| 167 | 167 | |
| 168 | 168 | // Abort if it is not valid for this item.  | 
                                                        
| 169 | -		if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { | 
                                                        |
| 169 | +		if (!$discount->is_valid_for_items(array($item->get_id()))) { | 
                                                        |
| 170 | 170 | continue;  | 
                                                        
| 171 | 171 | }  | 
                                                        
| 172 | 172 | |
| 173 | 173 | // Calculate the initial amount...  | 
                                                        
| 174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() );  | 
                                                        |
| 174 | + $item_discount = $discount->get_discounted_amount($item->get_sub_total());  | 
                                                        |
| 175 | 175 | $recurring_item_discount = 0;  | 
                                                        
| 176 | 176 | |
| 177 | 177 | // ... and maybe the recurring amount.  | 
                                                        
| 178 | -		if ( $item->is_recurring() && $discount->is_recurring() ) { | 
                                                        |
| 179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() );  | 
                                                        |
| 178 | +		if ($item->is_recurring() && $discount->is_recurring()) { | 
                                                        |
| 179 | + $recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total());  | 
                                                        |
| 180 | 180 | }  | 
                                                        
| 181 | 181 | |
| 182 | 182 | // Discount should not exceed discounted amount.  | 
                                                        
| 183 | -		if ( ! $discount->is_type( 'percent' ) ) { | 
                                                        |
| 183 | +		if (!$discount->is_type('percent')) { | 
                                                        |
| 184 | 184 | |
| 185 | -			if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { | 
                                                        |
| 185 | +			if (($initial_discount + $item_discount) > $discount->get_amount()) { | 
                                                        |
| 186 | 186 | $item_discount = $discount->get_amount() - $initial_discount;  | 
                                                        
| 187 | 187 | }  | 
                                                        
| 188 | 188 | |
| 189 | -			if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { | 
                                                        |
| 189 | +			if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) { | 
                                                        |
| 190 | 190 | $recurring_item_discount = $discount->get_amount() - $recurring_discount;  | 
                                                        
| 191 | 191 | }  | 
                                                        
| 192 | 192 | |
@@ -219,10 +219,10 @@ discard block  | 
                                                    ||
| 219 | 219 | array(  | 
                                                        
| 220 | 220 | 'post_type' => 'wpi_discount',  | 
                                                        
| 221 | 221 | 'numberposts' => 1,  | 
                                                        
| 222 | - 'fields' => array( 'ids' ),  | 
                                                        |
| 222 | +            'fields'      => array('ids'), | 
                                                        |
| 223 | 223 | )  | 
                                                        
| 224 | 224 | );  | 
                                                        
| 225 | 225 | |
| 226 | - return ! empty( $discounts );  | 
                                                        |
| 226 | + return !empty($discounts);  | 
                                                        |
| 227 | 227 | |
| 228 | 228 | }  |