Automattic / wp-calypso

The JavaScript and API powered WordPress.com
https://developer.wordpress.com
GNU General Public License v2.0
12.42k stars 1.99k forks source link

VAT Details entry | Trim the leading country code if it matches the selected one #56032

Closed toncijajic closed 3 years ago

toncijajic commented 3 years ago

Steps to reproduce the behavior

Slack discussion: p1630936548136200-slack-C0117V2PCAE

  1. Go to VAT Details entry
  2. Add VAT details with the full VAT ID (country code included) - see slack thread for test number
  3. Click "Validate and save"
  4. Observe

What I expected to happen

The validator successfully validates and saves the data.

What actually happened

The validator doesn't strip the leading country code from the ID, trying to validate the wrong ID. In the case of my VAT ID, it's trying to validate HRHR------ instead of HR------. Validation returns an error. Trying to force it produces invoices with "HR HR------" VAT numbers on them

I would expect that the leading country code is trimmed if the same as the one selected during validation and saving.

Context

In the EU, VAT ID is complete with the leading country code. Users entering VAT ID in an international environment almost exclusively enter it with the leading country code.

Is there any console output or error text?

Documented only client-side errors, see screenshots

Level of impact (Does it block purchases? Does it affect more than just one site?)

All sites, all users trying to add full VAT ID

toncijajic commented 3 years ago

@Automattic/shilling

michaeldcain commented 3 years ago

Let's start with a backend fix to validate the data, but then additionally modify both forms (Calypso and MC) allow for dynamic validation (i.e. if I input a VAT number with country code, auto-select country from the dropdown and remove it from the VAT number).

kingsleyinfo commented 3 years ago

I had a user with this issue here 31721115-HC The validation was failing for them until I suggested that they use only the number without the country code.

rambogenius commented 3 years ago

The validation was failing for them until I suggested that they use only the number without the country code.

I had a similar case today as well. Glad this is already reported.

fabz1001 commented 3 years ago

Hi, may I take this one? I already have a working solution in my local env.

sirbrillig commented 3 years ago

@romokebi PRs are certainly welcome!

fabz1001 commented 3 years ago

Thank you @sirbrillig, I have just opened it! (PR)

michaeldcain commented 3 years ago

Closed with #57686. Thank you @romokebi!