| @@ -12,228 +12,228 @@ | ||
| 12 | 12 | */ | 
| 13 | 13 |  class GetPaid_Payment_Form_Submission_Taxes { | 
| 14 | 14 | |
| 15 | - /** | |
| 16 | - * Submission taxes. | |
| 17 | - * @var array | |
| 18 | - */ | |
| 19 | - public $taxes = array(); | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * Whether or not we should skip the taxes. | |
| 23 | - * @var bool | |
| 24 | - */ | |
| 25 | - protected $skip_taxes = false; | |
| 15 | + /** | |
| 16 | + * Submission taxes. | |
| 17 | + * @var array | |
| 18 | + */ | |
| 19 | + public $taxes = array(); | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * Whether or not we should skip the taxes. | |
| 23 | + * @var bool | |
| 24 | + */ | |
| 25 | + protected $skip_taxes = false; | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * Class constructor | |
| 29 | + * | |
| 30 | + * @param GetPaid_Payment_Form_Submission $submission | |
| 31 | + */ | |
| 32 | +    public function __construct( $submission ) { | |
| 33 | + | |
| 34 | + // Validate VAT number. | |
| 35 | + $this->validate_vat( $submission ); | |
| 36 | + | |
| 37 | +        if ( $this->skip_taxes ) { | |
| 38 | + return; | |
| 39 | + } | |
| 40 | + | |
| 41 | +        foreach ( $submission->get_items() as $item ) { | |
| 42 | + $this->process_item_tax( $item, $submission ); | |
| 43 | + } | |
| 44 | + | |
| 45 | + // Process any existing invoice taxes. | |
| 46 | +        if ( $submission->has_invoice() ) { | |
| 47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); | |
| 48 | + } | |
| 49 | + | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Maybe process tax. | |
| 54 | + * | |
| 55 | + * @since 1.0.19 | |
| 56 | + * @param GetPaid_Form_Item $item | |
| 57 | + * @param GetPaid_Payment_Form_Submission $submission | |
| 58 | + */ | |
| 59 | +    public function process_item_tax( $item, $submission ) { | |
| 60 | + | |
| 61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); | |
| 62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); | |
| 63 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); | |
| 64 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); | |
| 65 | + | |
| 66 | +        foreach ( $taxes as $name => $amount ) { | |
| 67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; | |
| 68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); | |
| 69 | + | |
| 70 | +            if ( ! isset( $this->taxes[ $name ] ) ) { | |
| 71 | + $this->taxes[ $name ] = $tax; | |
| 72 | + continue; | |
| 73 | + } | |
| 74 | + | |
| 75 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; | |
| 76 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; | |
| 77 | + | |
| 78 | + } | |
| 79 | + | |
| 80 | + } | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Checks if the submission has a digital item. | |
| 84 | + * | |
| 85 | + * @param GetPaid_Payment_Form_Submission $submission | |
| 86 | + * @since 1.0.19 | |
| 87 | + * @return bool | |
| 88 | + */ | |
| 89 | +    public function has_digital_item( $submission ) { | |
| 90 | + | |
| 91 | +        foreach ( $submission->get_items() as $item ) { | |
| 92 | + | |
| 93 | +            if ( 'digital' == $item->get_vat_rule() ) { | |
| 94 | + return true; | |
| 95 | + } | |
| 96 | + | |
| 97 | + } | |
| 98 | + | |
| 99 | + return false; | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Checks if this is an eu store. | |
| 104 | + * | |
| 105 | + * @since 1.0.19 | |
| 106 | + * @return bool | |
| 107 | + */ | |
| 108 | +    public static function is_eu_store() { | |
| 109 | + return self::is_eu_country( wpinv_get_default_country() ); | |
| 110 | + } | |
| 26 | 111 | |
| 27 | 112 | /** | 
| 28 | - * Class constructor | |
| 29 | - * | |
| 30 | - * @param GetPaid_Payment_Form_Submission $submission | |
| 31 | - */ | |
| 32 | -	public function __construct( $submission ) { | |
| 33 | - | |
| 34 | - // Validate VAT number. | |
| 35 | - $this->validate_vat( $submission ); | |
| 36 | - | |
| 37 | -		if ( $this->skip_taxes ) { | |
| 38 | - return; | |
| 39 | - } | |
| 40 | - | |
| 41 | -		foreach ( $submission->get_items() as $item ) { | |
| 42 | - $this->process_item_tax( $item, $submission ); | |
| 43 | - } | |
| 44 | - | |
| 45 | - // Process any existing invoice taxes. | |
| 46 | -		if ( $submission->has_invoice() ) { | |
| 47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); | |
| 48 | - } | |
| 49 | - | |
| 50 | - } | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * Maybe process tax. | |
| 54 | - * | |
| 55 | - * @since 1.0.19 | |
| 56 | - * @param GetPaid_Form_Item $item | |
| 57 | - * @param GetPaid_Payment_Form_Submission $submission | |
| 58 | - */ | |
| 59 | -	public function process_item_tax( $item, $submission ) { | |
| 60 | - | |
| 61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); | |
| 62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); | |
| 63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); | |
| 64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); | |
| 65 | - | |
| 66 | -		foreach ( $taxes as $name => $amount ) { | |
| 67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; | |
| 68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); | |
| 69 | - | |
| 70 | -			if ( ! isset( $this->taxes[ $name ] ) ) { | |
| 71 | - $this->taxes[ $name ] = $tax; | |
| 72 | - continue; | |
| 73 | - } | |
| 74 | - | |
| 75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; | |
| 76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; | |
| 77 | - | |
| 78 | - } | |
| 79 | - | |
| 80 | - } | |
| 81 | - | |
| 82 | - /** | |
| 83 | - * Checks if the submission has a digital item. | |
| 84 | - * | |
| 85 | - * @param GetPaid_Payment_Form_Submission $submission | |
| 86 | - * @since 1.0.19 | |
| 87 | - * @return bool | |
| 88 | - */ | |
| 89 | -	public function has_digital_item( $submission ) { | |
| 90 | - | |
| 91 | -		foreach ( $submission->get_items() as $item ) { | |
| 92 | - | |
| 93 | -			if ( 'digital' == $item->get_vat_rule() ) { | |
| 94 | - return true; | |
| 95 | - } | |
| 96 | - | |
| 97 | - } | |
| 98 | - | |
| 99 | - return false; | |
| 100 | - } | |
| 101 | - | |
| 102 | - /** | |
| 103 | - * Checks if this is an eu store. | |
| 104 | - * | |
| 105 | - * @since 1.0.19 | |
| 106 | - * @return bool | |
| 107 | - */ | |
| 108 | -	public static function is_eu_store() { | |
| 109 | - return self::is_eu_country( wpinv_get_default_country() ); | |
| 110 | - } | |
| 111 | - | |
| 112 | - /** | |
| 113 | - * Checks if this is an eu country. | |
| 114 | - * | |
| 115 | - * @param string $country | |
| 116 | - * @since 1.0.19 | |
| 117 | - * @return bool | |
| 118 | - */ | |
| 119 | -	public static function is_eu_country( $country ) { | |
| 120 | - return getpaid_is_eu_state( $country ); | |
| 121 | - } | |
| 122 | - | |
| 123 | - /** | |
| 124 | - * Checks if this is an eu purchase. | |
| 125 | - * | |
| 126 | - * @param string $customer_country | |
| 127 | - * @since 1.0.19 | |
| 128 | - * @return bool | |
| 129 | - */ | |
| 130 | -	public static function is_eu_transaction( $customer_country ) { | |
| 131 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); | |
| 132 | - } | |
| 133 | - | |
| 134 | - /** | |
| 135 | - * Retrieves the vat number. | |
| 136 | - * | |
| 137 | - * @param GetPaid_Payment_Form_Submission $submission | |
| 138 | - * @since 1.0.19 | |
| 139 | - * @return string | |
| 140 | - */ | |
| 141 | -	public function get_vat_number( $submission ) { | |
| 142 | - | |
| 143 | - // Retrieve from the posted number. | |
| 144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); | |
| 145 | -		if ( ! is_null( $vat_number ) ) { | |
| 146 | - return wpinv_clean( $vat_number ); | |
| 147 | - } | |
| 148 | - | |
| 149 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; | |
| 150 | - } | |
| 151 | - | |
| 152 | - /** | |
| 153 | - * Retrieves the company. | |
| 154 | - * | |
| 155 | - * @param GetPaid_Payment_Form_Submission $submission | |
| 156 | - * @since 1.0.19 | |
| 157 | - * @return string | |
| 158 | - */ | |
| 159 | -	public function get_company( $submission ) { | |
| 160 | - | |
| 161 | - // Retrieve from the posted data. | |
| 162 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); | |
| 163 | -		if ( ! empty( $company ) ) { | |
| 164 | - return wpinv_clean( $company ); | |
| 165 | - } | |
| 166 | - | |
| 167 | - // Retrieve from the invoice. | |
| 168 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; | |
| 169 | - } | |
| 170 | - | |
| 171 | - /** | |
| 172 | - * Checks if we require a VAT number. | |
| 173 | - * | |
| 174 | - * @param bool $ip_in_eu Whether the customer IP is from the EU | |
| 175 | - * @param bool $country_in_eu Whether the customer country is from the EU | |
| 176 | - * @since 1.0.19 | |
| 177 | - * @return string | |
| 178 | - */ | |
| 179 | -	public function requires_vat( $ip_in_eu, $country_in_eu ) { | |
| 180 | - | |
| 181 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); | |
| 182 | - $prevent_b2c = ! empty( $prevent_b2c ); | |
| 183 | - $is_eu = $ip_in_eu || $country_in_eu; | |
| 184 | - | |
| 185 | - return $prevent_b2c && $is_eu; | |
| 186 | - } | |
| 187 | - | |
| 188 | - /** | |
| 189 | - * Validate VAT data. | |
| 190 | - * | |
| 191 | - * @param GetPaid_Payment_Form_Submission $submission | |
| 192 | - * @since 1.0.19 | |
| 193 | - */ | |
| 194 | -	public function validate_vat( $submission ) { | |
| 195 | - | |
| 196 | - $in_eu = $this->is_eu_transaction( $submission->country ); | |
| 197 | - | |
| 198 | - // Abort if we are not validating vat numbers. | |
| 199 | -		if ( ! $in_eu ) { | |
| 113 | + * Checks if this is an eu country. | |
| 114 | + * | |
| 115 | + * @param string $country | |
| 116 | + * @since 1.0.19 | |
| 117 | + * @return bool | |
| 118 | + */ | |
| 119 | +    public static function is_eu_country( $country ) { | |
| 120 | + return getpaid_is_eu_state( $country ); | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Checks if this is an eu purchase. | |
| 125 | + * | |
| 126 | + * @param string $customer_country | |
| 127 | + * @since 1.0.19 | |
| 128 | + * @return bool | |
| 129 | + */ | |
| 130 | +    public static function is_eu_transaction( $customer_country ) { | |
| 131 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * Retrieves the vat number. | |
| 136 | + * | |
| 137 | + * @param GetPaid_Payment_Form_Submission $submission | |
| 138 | + * @since 1.0.19 | |
| 139 | + * @return string | |
| 140 | + */ | |
| 141 | +    public function get_vat_number( $submission ) { | |
| 142 | + | |
| 143 | + // Retrieve from the posted number. | |
| 144 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); | |
| 145 | +        if ( ! is_null( $vat_number ) ) { | |
| 146 | + return wpinv_clean( $vat_number ); | |
| 147 | + } | |
| 148 | + | |
| 149 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; | |
| 150 | + } | |
| 151 | + | |
| 152 | + /** | |
| 153 | + * Retrieves the company. | |
| 154 | + * | |
| 155 | + * @param GetPaid_Payment_Form_Submission $submission | |
| 156 | + * @since 1.0.19 | |
| 157 | + * @return string | |
| 158 | + */ | |
| 159 | +    public function get_company( $submission ) { | |
| 160 | + | |
| 161 | + // Retrieve from the posted data. | |
| 162 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); | |
| 163 | +        if ( ! empty( $company ) ) { | |
| 164 | + return wpinv_clean( $company ); | |
| 165 | + } | |
| 166 | + | |
| 167 | + // Retrieve from the invoice. | |
| 168 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; | |
| 169 | + } | |
| 170 | + | |
| 171 | + /** | |
| 172 | + * Checks if we require a VAT number. | |
| 173 | + * | |
| 174 | + * @param bool $ip_in_eu Whether the customer IP is from the EU | |
| 175 | + * @param bool $country_in_eu Whether the customer country is from the EU | |
| 176 | + * @since 1.0.19 | |
| 177 | + * @return string | |
| 178 | + */ | |
| 179 | +    public function requires_vat( $ip_in_eu, $country_in_eu ) { | |
| 180 | + | |
| 181 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); | |
| 182 | + $prevent_b2c = ! empty( $prevent_b2c ); | |
| 183 | + $is_eu = $ip_in_eu || $country_in_eu; | |
| 184 | + | |
| 185 | + return $prevent_b2c && $is_eu; | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * Validate VAT data. | |
| 190 | + * | |
| 191 | + * @param GetPaid_Payment_Form_Submission $submission | |
| 192 | + * @since 1.0.19 | |
| 193 | + */ | |
| 194 | +    public function validate_vat( $submission ) { | |
| 195 | + | |
| 196 | + $in_eu = $this->is_eu_transaction( $submission->country ); | |
| 197 | + | |
| 198 | + // Abort if we are not validating vat numbers. | |
| 199 | +        if ( ! $in_eu ) { | |
| 200 | 200 | return; | 
| 201 | - } | |
| 201 | + } | |
| 202 | 202 | |
| 203 | - // Prepare variables. | |
| 204 | - $vat_number = $this->get_vat_number( $submission ); | |
| 205 | - $ip_country = getpaid_get_ip_country(); | |
| 203 | + // Prepare variables. | |
| 204 | + $vat_number = $this->get_vat_number( $submission ); | |
| 205 | + $ip_country = getpaid_get_ip_country(); | |
| 206 | 206 | $is_eu = $this->is_eu_country( $submission->country ); | 
| 207 | 207 | $is_ip_eu = $this->is_eu_country( $ip_country ); | 
| 208 | 208 | |
| 209 | - // Maybe abort early for initial fetches. | |
| 210 | -		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { | |
| 211 | - return; | |
| 212 | - } | |
| 209 | + // Maybe abort early for initial fetches. | |
| 210 | +        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { | |
| 211 | + return; | |
| 212 | + } | |
| 213 | 213 | |
| 214 | - // If we're preventing business to consumer purchases, | |
| 215 | -		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { | |
| 214 | + // If we're preventing business to consumer purchases, | |
| 215 | +        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { | |
| 216 | 216 | |
| 217 | - // Ensure that a vat number has been specified. | |
| 218 | - throw new Exception( | |
| 219 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) | |
| 220 | - ); | |
| 217 | + // Ensure that a vat number has been specified. | |
| 218 | + throw new Exception( | |
| 219 | + __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) | |
| 220 | + ); | |
| 221 | 221 | |
| 222 | - } | |
| 222 | + } | |
| 223 | 223 | |
| 224 | -		if ( empty( $vat_number ) ) { | |
| 225 | - return; | |
| 226 | - } | |
| 224 | +        if ( empty( $vat_number ) ) { | |
| 225 | + return; | |
| 226 | + } | |
| 227 | 227 | |
| 228 | -		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { | |
| 229 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); | |
| 230 | - } | |
| 228 | +        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { | |
| 229 | + throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); | |
| 230 | + } | |
| 231 | 231 | |
| 232 | -		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { | |
| 233 | - return; | |
| 234 | - } | |
| 232 | +        if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { | |
| 233 | + return; | |
| 234 | + } | |
| 235 | 235 | |
| 236 | - $this->skip_taxes = true; | |
| 237 | - } | |
| 236 | + $this->skip_taxes = true; | |
| 237 | + } | |
| 238 | 238 | |
| 239 | 239 | } | 
| @@ -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 | 
| @@ -29,22 +29,22 @@ 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 | // Validate VAT number. | 
| 35 | - $this->validate_vat( $submission ); | |
| 35 | + $this->validate_vat($submission); | |
| 36 | 36 | |
| 37 | -		if ( $this->skip_taxes ) { | |
| 37 | +		if ($this->skip_taxes) { | |
| 38 | 38 | return; | 
| 39 | 39 | } | 
| 40 | 40 | |
| 41 | -		foreach ( $submission->get_items() as $item ) { | |
| 42 | - $this->process_item_tax( $item, $submission ); | |
| 41 | +		foreach ($submission->get_items() as $item) { | |
| 42 | + $this->process_item_tax($item, $submission); | |
| 43 | 43 | } | 
| 44 | 44 | |
| 45 | 45 | // Process any existing invoice taxes. | 
| 46 | -		if ( $submission->has_invoice() ) { | |
| 47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); | |
| 46 | +		if ($submission->has_invoice()) { | |
| 47 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); | |
| 48 | 48 | } | 
| 49 | 49 | |
| 50 | 50 | } | 
| @@ -56,24 +56,24 @@ discard block | ||
| 56 | 56 | * @param GetPaid_Form_Item $item | 
| 57 | 57 | * @param GetPaid_Payment_Form_Submission $submission | 
| 58 | 58 | */ | 
| 59 | -	public function process_item_tax( $item, $submission ) { | |
| 59 | +	public function process_item_tax($item, $submission) { | |
| 60 | 60 | |
| 61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); | |
| 62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); | |
| 63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); | |
| 64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); | |
| 61 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); | |
| 62 | + $rates = getpaid_filter_item_tax_rates($item, $rates); | |
| 63 | + $taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates); | |
| 64 | + $r_taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates); | |
| 65 | 65 | |
| 66 | -		foreach ( $taxes as $name => $amount ) { | |
| 67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; | |
| 68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); | |
| 66 | +		foreach ($taxes as $name => $amount) { | |
| 67 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; | |
| 68 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); | |
| 69 | 69 | |
| 70 | -			if ( ! isset( $this->taxes[ $name ] ) ) { | |
| 71 | - $this->taxes[ $name ] = $tax; | |
| 70 | +			if (!isset($this->taxes[$name])) { | |
| 71 | + $this->taxes[$name] = $tax; | |
| 72 | 72 | continue; | 
| 73 | 73 | } | 
| 74 | 74 | |
| 75 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; | |
| 76 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; | |
| 75 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; | |
| 76 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; | |
| 77 | 77 | |
| 78 | 78 | } | 
| 79 | 79 | |
| @@ -86,11 +86,11 @@ discard block | ||
| 86 | 86 | * @since 1.0.19 | 
| 87 | 87 | * @return bool | 
| 88 | 88 | */ | 
| 89 | -	public function has_digital_item( $submission ) { | |
| 89 | +	public function has_digital_item($submission) { | |
| 90 | 90 | |
| 91 | -		foreach ( $submission->get_items() as $item ) { | |
| 91 | +		foreach ($submission->get_items() as $item) { | |
| 92 | 92 | |
| 93 | -			if ( 'digital' == $item->get_vat_rule() ) { | |
| 93 | +			if ('digital' == $item->get_vat_rule()) { | |
| 94 | 94 | return true; | 
| 95 | 95 | } | 
| 96 | 96 | |
| @@ -106,7 +106,7 @@ discard block | ||
| 106 | 106 | * @return bool | 
| 107 | 107 | */ | 
| 108 | 108 |  	public static function is_eu_store() { | 
| 109 | - return self::is_eu_country( wpinv_get_default_country() ); | |
| 109 | + return self::is_eu_country(wpinv_get_default_country()); | |
| 110 | 110 | } | 
| 111 | 111 | |
| 112 | 112 | /** | 
| @@ -116,8 +116,8 @@ discard block | ||
| 116 | 116 | * @since 1.0.19 | 
| 117 | 117 | * @return bool | 
| 118 | 118 | */ | 
| 119 | -	public static function is_eu_country( $country ) { | |
| 120 | - return getpaid_is_eu_state( $country ); | |
| 119 | +	public static function is_eu_country($country) { | |
| 120 | + return getpaid_is_eu_state($country); | |
| 121 | 121 | } | 
| 122 | 122 | |
| 123 | 123 | /** | 
| @@ -127,8 +127,8 @@ discard block | ||
| 127 | 127 | * @since 1.0.19 | 
| 128 | 128 | * @return bool | 
| 129 | 129 | */ | 
| 130 | -	public static function is_eu_transaction( $customer_country ) { | |
| 131 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); | |
| 130 | +	public static function is_eu_transaction($customer_country) { | |
| 131 | + return self::is_eu_country($customer_country) && self::is_eu_store(); | |
| 132 | 132 | } | 
| 133 | 133 | |
| 134 | 134 | /** | 
| @@ -138,12 +138,12 @@ discard block | ||
| 138 | 138 | * @since 1.0.19 | 
| 139 | 139 | * @return string | 
| 140 | 140 | */ | 
| 141 | -	public function get_vat_number( $submission ) { | |
| 141 | +	public function get_vat_number($submission) { | |
| 142 | 142 | |
| 143 | 143 | // Retrieve from the posted number. | 
| 144 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); | |
| 145 | -		if ( ! is_null( $vat_number ) ) { | |
| 146 | - return wpinv_clean( $vat_number ); | |
| 144 | +		$vat_number = $submission->get_field('wpinv_vat_number', 'billing'); | |
| 145 | +		if (!is_null($vat_number)) { | |
| 146 | + return wpinv_clean($vat_number); | |
| 147 | 147 | } | 
| 148 | 148 | |
| 149 | 149 | return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; | 
| @@ -156,12 +156,12 @@ discard block | ||
| 156 | 156 | * @since 1.0.19 | 
| 157 | 157 | * @return string | 
| 158 | 158 | */ | 
| 159 | -	public function get_company( $submission ) { | |
| 159 | +	public function get_company($submission) { | |
| 160 | 160 | |
| 161 | 161 | // Retrieve from the posted data. | 
| 162 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); | |
| 163 | -		if ( ! empty( $company ) ) { | |
| 164 | - return wpinv_clean( $company ); | |
| 162 | +		$company = $submission->get_field('wpinv_company', 'billing'); | |
| 163 | +		if (!empty($company)) { | |
| 164 | + return wpinv_clean($company); | |
| 165 | 165 | } | 
| 166 | 166 | |
| 167 | 167 | // Retrieve from the invoice. | 
| @@ -176,10 +176,10 @@ discard block | ||
| 176 | 176 | * @since 1.0.19 | 
| 177 | 177 | * @return string | 
| 178 | 178 | */ | 
| 179 | -	public function requires_vat( $ip_in_eu, $country_in_eu ) { | |
| 179 | +	public function requires_vat($ip_in_eu, $country_in_eu) { | |
| 180 | 180 | |
| 181 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); | |
| 182 | - $prevent_b2c = ! empty( $prevent_b2c ); | |
| 181 | +		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); | |
| 182 | + $prevent_b2c = !empty($prevent_b2c); | |
| 183 | 183 | $is_eu = $ip_in_eu || $country_in_eu; | 
| 184 | 184 | |
| 185 | 185 | return $prevent_b2c && $is_eu; | 
| @@ -191,45 +191,45 @@ discard block | ||
| 191 | 191 | * @param GetPaid_Payment_Form_Submission $submission | 
| 192 | 192 | * @since 1.0.19 | 
| 193 | 193 | */ | 
| 194 | -	public function validate_vat( $submission ) { | |
| 194 | +	public function validate_vat($submission) { | |
| 195 | 195 | |
| 196 | - $in_eu = $this->is_eu_transaction( $submission->country ); | |
| 196 | + $in_eu = $this->is_eu_transaction($submission->country); | |
| 197 | 197 | |
| 198 | 198 | // Abort if we are not validating vat numbers. | 
| 199 | -		if ( ! $in_eu ) { | |
| 199 | +		if (!$in_eu) { | |
| 200 | 200 | return; | 
| 201 | 201 | } | 
| 202 | 202 | |
| 203 | 203 | // Prepare variables. | 
| 204 | - $vat_number = $this->get_vat_number( $submission ); | |
| 204 | + $vat_number = $this->get_vat_number($submission); | |
| 205 | 205 | $ip_country = getpaid_get_ip_country(); | 
| 206 | - $is_eu = $this->is_eu_country( $submission->country ); | |
| 207 | - $is_ip_eu = $this->is_eu_country( $ip_country ); | |
| 206 | + $is_eu = $this->is_eu_country($submission->country); | |
| 207 | + $is_ip_eu = $this->is_eu_country($ip_country); | |
| 208 | 208 | |
| 209 | 209 | // Maybe abort early for initial fetches. | 
| 210 | -		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { | |
| 210 | +		if ($submission->is_initial_fetch() && empty($vat_number)) { | |
| 211 | 211 | return; | 
| 212 | 212 | } | 
| 213 | 213 | |
| 214 | 214 | // If we're preventing business to consumer purchases, | 
| 215 | -		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { | |
| 215 | +		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { | |
| 216 | 216 | |
| 217 | 217 | // Ensure that a vat number has been specified. | 
| 218 | 218 | throw new Exception( | 
| 219 | - __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) | |
| 219 | +				__('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing') | |
| 220 | 220 | ); | 
| 221 | 221 | |
| 222 | 222 | } | 
| 223 | 223 | |
| 224 | -		if ( empty( $vat_number ) ) { | |
| 224 | +		if (empty($vat_number)) { | |
| 225 | 225 | return; | 
| 226 | 226 | } | 
| 227 | 227 | |
| 228 | -		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { | |
| 229 | - throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) ); | |
| 228 | +		if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) { | |
| 229 | +			throw new Exception(__('Your VAT number is invalid', 'invoicing')); | |
| 230 | 230 | } | 
| 231 | 231 | |
| 232 | -		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { | |
| 232 | +		if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) { | |
| 233 | 233 | return; | 
| 234 | 234 | } | 
| 235 | 235 | |