PayPal Checkout with Euros, VAT, and Currency Exchange

November 02, 2016

This blog entry is for web programmers looking for help with PayPal checkout processing involving Euros and VAT. I write in PHP, and limit library use to Bootstrap and jQuery. Since it took me quite a bit of time to find the right information and figure out what to do with it, I hope I might save someone else that kind of time with what I write below. The first section is there to help you determine if my explanation is for you or not. If you're in a hurry to find solutions, skip to this list.

Why I Switched to the Euro

For the past decade, I've used PayPal for my business websites' online transactions. PayPal works by linking to a bank account, and in the US there are no fees either for the PayPal account or for the bank account. Last year I implemented PayPal's IPN service to automate order processing — also a free service. As an American working in the US, my business currency was of course the US Dollar. US Tax policy regarding online transactions is simple. Residents of a state in which a web-based business resides must pay local state sales tax on each transaction. Handling all of that through PayPal was not difficult.

Then I moved to Germany. PayPal is in fact based in Europe, and it offers accounts to EU countries in Euros. German PayPal accounts work the same way as American accounts, and PayPal remains a free service for European customers, although German bank accounts are typically not free. After fulfilling the requirements for residency in Germany (a process taking several months) and finally opening a German bank account, I opened a new (German) PayPal account and prepared to point my websites to send transactions to that account.

But, not so fast. Simply pointing the transactions to the new accounts would not result in collection of the correct currency, because my prices were in USD, and the new account is in EUR. The conversion rate from USD to EUR fluctuates, but generally has not been favourable to the USD, and PayPal also charges a fee for the currency conversion. The result would be that I would collect far less money for each transaction. Nor would simply pointing the transactions to this new account be legally responsible. When selling as US business, I'm beholden to US tax policies. When selling as a German business, I'm beholden to the tax policies of Germany and the EU.

In order to do this right, I had some work to do. First, I needed to change my prices to Euros, so that I could send the currency to PayPal. Second, I had to implement correct tax policies as an EU business. The latter is extremely complicated, because online sales in the EU require that tax be collected in the rate of the customer's country, not the rate of the seller's country. This means tracking website visitors' location, and looking up correct tax rates for each transaction. To accomplish this requires gathering data from a few Euro-related online services. Luckily these services are free.

TO DO List

  1. Change prices to Euros
  2. Track VAT rates for all EU countries ( apilayer.net )
  3. Get website visitors' country codes ( wipmania.com )
  4. Track exchange rates as a courtesy to non-EU customers ( www.ecb.europa.eu )

Changing Prices to Euros

Generally, if a product costs 10 USD when marketed in the US, it will also cost 10 EUR when marketed in the EU. I decided this made sense. Something I learned through this process is that the Euro symbol is, as a rule, supposed to go after the number, not before it. Many websites get this wrong. While the decimal point and the comma also swap roles in European practice, this is not such a strict rule, and I decided not to adopt it since it confuses a lot of people.

Tracking VAT rates

VAT rates are very complicated, because they not only vary per country, but also vary per category of goods or services per country. Luckily, complete and very clear information on all the VAT rates is available from the European Commission. I suggest reading their documents before trying to implement VAT in your website. (N.B. It also looks like all the rules for handling VAT will be changing in 2017) For getting the VAT rates, I use apilayer.net, which offers free accounts for up to 100 calls per month. Since these rates do not change very often, it's not necessary to track them more than once a month (keeping the number of calls well below 100). Documentation is excellent. I wrote a PHP script which looks up these rates and stores them in a database table, then I set up a cron job on the server to call this script automatically once a month. This gives me the correct tax rates to work with via PHP mySQLi database lookup.

Getting a Website-Visitor's Country Code

For this I use wipmania, which is free for this purpose with no use limit (they have paid plans for business who are looking for more information). The location of the visitor is determined by IP address, which of course is not failsafe, but as far as I can determine, it's the best method available. It's only necessary to get this value on the shopping cart page, where VAT is calculated, so the number of calls is kept relatively low. If you need to do more with the code and are worried about making too many calls to wipmania, simply store the country code once in the PHP session cookie.

Getting Exchange Rates

Online pricing in Euros is by no means uncommon, but for some non-EU customers it is uncomfortable because of fluctuating exchange rates. I decided that it would be nice for non-EU customers to be able to see prices in their own currency. Luckily, the European Central Bank provides daily exchange rates in an xml file for free. Since it is not necessary to look this up more than once a day, again my solution was to write a PHP script to look up all the rates and store them in a database, and then set up a server cron job to run the script once a day. I then access the rates via PHP mySQLi database lookup. The Bootstrap library provides a nice popup window to display HTML in any link title attribute, so I added a PHP function to accept a price and calculate prices by conversion in an HTML formatted list to write into the title attribute of price links displayed in Euros. Keep in mind that PayPal adds between 3% and 4% to these rates; therefore, I add 3.5% to the rates before calculating the conversions, and add a note saying that the amounts are estimates only.

Calculating the Correct Tax

To sell products with the correct tax, you need to do the following, in order:

  1. Get the visitor's country code
  2. Look up the VAT rate for the visitor's country according to the type of good or service you are selling
  3. Calculate the tax, and show it to the user as part of your checkout process

PayPal Checkout with Euros and VAT

The last thing to do is to change your checkout currency to EUR, and send the VAT as the tax parameter. It is of course important to store all the transaction information in your local database. You can also get what you need from your PayPal IPN messages, since these will include the visitor's country code as well as the tax paid. If you like, you can also send custom fields to PayPal in each transaction. Doing so may allow you to detect possible problems caused by proxy servers.

Thanks for reading and I hope something here was helpful for you.

Best Wishes,
Aaron

[ Showing 1 entry | Previous entry | Next entry | Show all entries ]