<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: W System</title>
    <description>The latest articles on DEV Community by W System (@wsystemdev).</description>
    <link>https://dev.to/wsystemdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4279528%2Ff0112a71-b8f3-4fe7-98b6-c3346178a77a.png</url>
      <title>DEV Community: W System</title>
      <link>https://dev.to/wsystemdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wsystemdev"/>
    <language>en</language>
    <item>
      <title>VIES says MS_UNAVAILABLE again: a retry + fallback pattern that keeps checkout from treating an outage as invalid VAT (PHP)</title>
      <dc:creator>W System</dc:creator>
      <pubDate>Thu, 03 Dec 2026 03:08:05 +0000</pubDate>
      <link>https://dev.to/wsystemdev/vies-says-msunavailable-again-a-retry-fallback-pattern-that-keeps-checkout-from-treating-an-2b55</link>
      <guid>https://dev.to/wsystemdev/vies-says-msunavailable-again-a-retry-fallback-pattern-that-keeps-checkout-from-treating-an-2b55</guid>
      <description>&lt;p&gt;When VIES returns &lt;code&gt;MS_UNAVAILABLE&lt;/code&gt; or &lt;code&gt;MS_MAX_CONCURRENT_REQ&lt;/code&gt;, it is easy to treat that as “this VAT number is invalid” and block checkout. That is the wrong reading.&lt;/p&gt;

&lt;p&gt;MS_UNAVAILABLE means that country's VAT register did not answer VIES. MS_MAX_CONCURRENT_REQ means that country is at its concurrent-request limit. Neither is a verdict on the VAT number — treat both as unknown and retry.&lt;/p&gt;

&lt;p&gt;Do not reject the customer or treat the number as invalid. Mark VAT as unverified / pending, retry in the background with bounded backoff, and re-check in VIES before relying on the result (for example for zero-rating).&lt;/p&gt;

&lt;h2&gt;
  
  
  PHP sample: exponential backoff with jitter
&lt;/h2&gt;

&lt;p&gt;The sample below is a SOAP helper of about 30 lines. It retries only transient faults (&lt;code&gt;MS_UNAVAILABLE&lt;/code&gt;, &lt;code&gt;MS_MAX_CONCURRENT_REQ&lt;/code&gt;, &lt;code&gt;SERVICE_UNAVAILABLE&lt;/code&gt;, &lt;code&gt;TIMEOUT&lt;/code&gt;, &lt;code&gt;GLOBAL_MAX_CONCURRENT_REQ&lt;/code&gt;). A last-good-result cache is recommended below but is not part of the helper.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;VIES_WSDL&lt;/span&gt;     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;VIES_ENDPOINT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://ec.europa.eu/taxation_customs/vies/services/checkVatService'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Faults that mean "try again later", not "this VAT number is bad".&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;VIES_RETRYABLE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'MS_MAX_CONCURRENT_REQ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'GLOBAL_MAX_CONCURRENT_REQ'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'MS_UNAVAILABLE'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'SERVICE_UNAVAILABLE'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'TIMEOUT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;viesClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;SoapClient&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nv"&gt;$client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$client&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SoapClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;VIES_WSDL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'location'&lt;/span&gt;           &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;VIES_ENDPOINT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'exceptions'&lt;/span&gt;         &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'connection_timeout'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'cache_wsdl'&lt;/span&gt;         &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;WSDL_CACHE_BOTH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;checkVatApproxWithRetry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$maxAttempts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;stdClass&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$attempt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;$attempt&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;viesClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;checkVatApprox&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SoapFault&lt;/span&gt; &lt;span class="nv"&gt;$fault&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// VIES isn't consistent about case ("Invalid_input" vs "INVALID_INPUT")&lt;/span&gt;
            &lt;span class="nv"&gt;$code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;strtoupper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$fault&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;in_array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;VIES_RETRYABLE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nv"&gt;$attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nv"&gt;$maxAttempts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="nv"&gt;$fault&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="c1"&gt;// 2, 4, 8, 16, 32 s (max 60) plus up to 1 s of random jitter&lt;/span&gt;
            &lt;span class="nv"&gt;$delay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="nv"&gt;$attempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;random_int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nf"&gt;usleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$delay&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1_000_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not retry &lt;code&gt;INVALID_INPUT&lt;/code&gt; (the result will not change). Store a successful check together with its &lt;code&gt;requestDate&lt;/code&gt; (and &lt;code&gt;requestIdentifier&lt;/code&gt; if you sent requester details) in your own application if you want a last-good result — that storage is not part of the helper above.&lt;/p&gt;

&lt;h2&gt;
  
  
  Live VIES status
&lt;/h2&gt;

&lt;p&gt;A live per-country board is at &lt;a href="https://wsystem.dev/vies-status" rel="noopener noreferrer"&gt;https://wsystem.dev/vies-status&lt;/a&gt; (27 EU member states + Northern Ireland / XI). Error codes, including &lt;code&gt;MS_UNAVAILABLE&lt;/code&gt;, &lt;code&gt;MS_MAX_CONCURRENT_REQ&lt;/code&gt; and &lt;code&gt;TIMEOUT&lt;/code&gt;, are explained at &lt;a href="https://wsystem.dev/vies-error-codes" rel="noopener noreferrer"&gt;https://wsystem.dev/vies-error-codes&lt;/a&gt;. The longer checkout decision table is the canonical article: &lt;a href="https://wsystem.dev/vies-down-fallback" rel="noopener noreferrer"&gt;https://wsystem.dev/vies-down-fallback&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optional API (disclosure)
&lt;/h2&gt;

&lt;p&gt;Optional, if you would rather not run the retries yourself: the W System VAT API (disclosure: I work on W System). No key: 20 free calls/day per IP, then pay-per-call. GET /vies/status is free and not counted. When a member state stays down, the API can answer from that country's official source for PL, CZ, FI and FR, or from a dated last VIES result when we have one; otherwise you get member_state_unavailable with valid: null — never valid: false because of an outage. A national-register fallback is not the same as a VIES consultation number.&lt;/p&gt;

&lt;p&gt;Disclosure: I work on W System, which offers this VAT API. The retry code in the article works without it.&lt;/p&gt;

&lt;p&gt;Contact: &lt;a href="mailto:hello@wsystem.dev"&gt;hello@wsystem.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>vat</category>
      <category>ecommerce</category>
    </item>
  </channel>
</rss>
