normalisedVatId(); if ($vatId === '') { // Removing the number removes the verification with it. Otherwise the // stamp would sit on the record with nothing to compare against, and // the next number typed in would look pre-verified for one save. $this->clear($customer); return null; } $check = $this->verifier->check($vatId); // The whole reason VatIdCheck has three outcomes. An outage tells us // nothing, so nothing is written: a verification that has been standing // for months must not be cleared — and a customer's invoices changed — // because a national register was down for the night. if ($check->isUnavailable()) { return $check; } if ($check->isInvalid()) { $this->clear($customer); return $check; } // Bound to the value that was checked, not to a flag. Customer:: // hasVerifiedVatId() compares the two, so editing the number afterwards // cannot inherit this confirmation whichever code path does the editing. $customer->forceFill([ 'vat_id_verified_at' => now(), 'vat_id_verified_value' => $vatId, ])->save(); return $check; } private function clear(Customer $customer): void { if ($customer->vat_id_verified_at === null && $customer->vat_id_verified_value === null) { return; } $customer->forceFill([ 'vat_id_verified_at' => null, 'vat_id_verified_value' => null, ])->save(); } }