company->db); $tp = new TaxProvider($this->company); $tp->updateCompanyTaxData(); if(!$tp->updatedTaxStatus() && $this->company->settings->country_id == '840') { $calculated_state = false; /** State must be calculated else default to the company state for taxes */ if(array_key_exists($this->company->settings->state, USStates::get())) { $calculated_state = $this->company->settings->state; } else { try{ $calculated_state = USStates::getState($this->company->settings->postal_code); } catch(\Exception $e){ nlog("could not calculate state from postal code => {$this->company->settings->postal_code} or from state {$this->company->settings->state}"); } if(!$calculated_state && $this->company->tax_data?->seller_subregion) $calculated_state = $this->company->tax_data?->seller_subregion; if(!$calculated_state) return; } $data = [ 'seller_subregion' => $this->company->origin_tax_data?->seller_subregion ?: '', 'geoPostalCode' => $this->company->settings->postal_code ?? '', 'geoCity' => $this->company->settings->city ?? '', 'geoState' => $calculated_state, 'taxSales' => $this->company->tax_data->regions->US->subregions?->{$calculated_state}?->taxSales ?? 0, ]; $tax_data = new Response($data); $this->company->origin_tax_data = $tax_data; $this->company->saveQuietly(); } } public function middleware() { return [new WithoutOverlapping($this->company->id)]; } public function failed($e){ nlog($e->getMessage()); } }