Okay
  Public Ticket #2568166
Vies validation response string
Closed

Comments

  •  1
    Mark started the conversation

    Great plugin! Good documentation.

    Question. Upon customer registration with a valid EU tax number, can the VIES Consultation number be stored in the "user registration data"?

    Also the request date would be nice but not essential.

    I haven't seen any method of doing this?

    Cheers,

    Mark

  •  1,904
    WebWizards replied

    Hi Mark,

    Thank you for purchasing our plugin and I'm glad you like it,


    I just checked the detailed response from the Europa.eu API to see if the Consultation Number is in the complete response. I'm afraid it isn't:

    8842600604.png


    I looked into it quite a bit and I looked over the API but I can't see any way to get the consultation nr. I'm afraid


    The request date is there yes. If you want I can think of a way to store the date somewhere, it will require some custom coding though, it's not possible directly through plugin settings.


    Kind Regards,

    Stefan


  •  1
    Mark replied

    Hi Stefan,

    Thanks for looking into this.

    Have you supplied a requester VAT number? This is required to get the consultation number. If only the customer VAT is supplied, indeed there is no consultation number. 

    The EU VAT Assitant plugin stores the consultation number with every order. I think that is over the top.

    Cheers,

    Mark

  •  1,904
    WebWizards replied

    Hi,

    You're right actually, that worked!


    To add this to the plugin's main release, there are various issues for us, a need for extra settings and many code changes.


    But I have packaged it as code that you can add to functions.php of your site.

    CODE:

    add_action('woocommerce_created_customer', 'save_vies_consultation_details', 999, 1);
    function save_vies_consultation_details($user_id){
        $vat_number_inputted = get_user_meta($user_id,'billing_vat', true);
        if (!(empty($vat_number_inputted))){
            $client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");
            $country_code = substr($vat_number_inputted, 0, 2); // take first 2 chars
            $vat_number = substr($vat_number_inputted, 2); // remove first 2 chars
            $validation = $client->checkVatApprox(array(
              'countryCode' => $country_code,
              'vatNumber' => $vat_number,
              'requesterVatNumber' => '0660982942',
              'requesterCountryCode' => 'BE'
            ));
            if(intval($validation->valid) === 1){
                $consultationnr = $validation ->requestIdentifier;
                $requestdate = $validation ->requestDate;
                update_user_meta($user_id,'viesconsultationnr', $consultationnr);
                update_user_meta($user_id,'viesrequestdate', $requestdate);
            }
        }
    }
    add_action( 'show_user_profile', 'extra_user_profile_fields' );
    add_action( 'edit_user_profile', 'extra_user_profile_fields' );
    function extra_user_profile_fields( $user ) { ?>
        <h3><?php _e("B2BKing extra profile information", "blank"); ?></h3>
        <table class="form-table">
        <tbody><tr>
            <th><label for="viesconsultationnr"><?php _e("VIES Consultation NR"); ?--></label></th>
            <td>
                <input type="text" name="viesconsultationnr" id="viesconsultationnr" value="<?php echo esc_attr( get_the_author_meta( 'viesconsultationnr', $user->ID ) ); ?>" class="regular-text"><br>
                <span class="description"><!--?php _e("VIES CONSULTATION NR"); ?--></span>
            </td>
        </tr>
        <tr>
            <th><label for="viesrequestdate"><!--?php _e("VIES Request Date"); ?--></label></th>
            <td>
                <input type="text" name="viesrequestdate" id="viesrequestdate" value="<?php echo esc_attr( get_the_author_meta( 'viesrequestdate', $user->ID ) ); ?>" class="regular-text"><br>
                <span class="description"><!--?php _e("REQUEST DATE."); ?--></span>
            </td>
        </tr>
        </tbody></table>
    <!--?php }-->
    


    EFFECTS:

    You will get this in the user's profile page:

    8618597799.png


  •  1,904
    WebWizards replied

    In the code you should REPLACE

      'requesterVatNumber' => '0660982942',          'requesterCountryCode' => 'BE'


    with your own VAT Number !!!


  •  1
    Mark replied

    Hey Stefan! Wow amazing, thanks!

    I tested it and it works perfectly. I had to do 2 adjustments after copying it to my functions.php file:

    Line 34 was:

            <th><label for="viesconsultationnr"><?php _e("VIES Consultation NR"); ?--></label></th>

    Now is:  (removed -- between ? and > )

           <th><label for="viesconsultationnr"><?php _e("VIES Consultation NR"); ?></label></th>
    

    And line 48 was:

    <!--?php }-->
    

    is now for me: 

    <?php }
    

    I am missing a label. I think that is because it is new and not in some translation file. Will sort that out later.

    Thanks again for your fast responses and great solution!

  •  1,904
    WebWizards replied

    Glad that mostly workedsmile.png

    I looked again over what I sent you, and I can see now the code did not copy correctly, a lot of things were replaced with comments. Ticksy has occasional quirks unfortunately.

    I think it might be the same problem for the missing label, it could be a comment.