Delete "If you buy/want", capitalise "to", the sentence becomes
To buy a pack of cigarettes from a vending machine in Japan, you have to insert your ID card into it to validate your age.
If you definitely have to address someone (2nd person), it is better to use "If you want to buy".
If you want to buy a pack of cigarettes from a vending machine in Japan, you have to insert your ID card into it to validate your age.
If you have to have "If you buy", you will have to modify the tense in the second clause.
If you buy a pack of cigarettes from a vending machine in Japan,
you will have to insert your ID card into it to validate your age.
Someone told me that I should use want to buy.
There are many ways to make the statement, one being, using "want to
buy". Two other ways of making the statement were also seen above.
Because the age-check happens before the purchase. Is that really true? I thought inserting the ID card was part of buying.
I will be unable to answer these questions as they are opinion based,
I am not knowledgeable, more knowledgeable people will be better able
to guide/advise you in proper forum related to "countries and
regulations", outside of the boundaries of this forum.