Move django-based uncloud to top-level

This commit is contained in:
fnux 2020-05-07 12:12:35 +02:00
commit 95d43f002f
265 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,55 @@
"""
investigate into a simple python function that maps an ldap user to a vat percentage. Basically you need to
lookup the customer address, check if she is a business/registered tax number and if not apply the local
vat
"""
import iso3166
import datetime
from csv import DictReader
def get_vat(street_address, city, postal_code, country, vat_number=None):
vat = {
'Austria': [
{'period': '1984-01-01/', 'rate': 0.2},
{'period': '1976-01-01/1984-01-01', 'rate': 0.18},
{'period': '1973-01-01/1976-01-01', 'rate': 0.16},
]
}
return iso3166.countries.get(country)
# return iso3166.countries_by_name[country]
def main():
# vat = get_vat(
# street_address='82 Nasheman-e-Iqbal near Wapda Town',
# city='Lahore',
# postal_code=53700,
# country='Pakistan',
# )
# print(vat)
vat_rates = {}
with open('vat_rates.csv', newline='') as csvfile:
reader = DictReader(csvfile)
for row in reader:
territory_codes = row['territory_codes'].split('\n')
for code in territory_codes:
if code not in vat_rates:
vat_rates[code] = {}
start_date = row['start_date']
stop_data = row['stop_date']
time_period = f'{start_date}|{stop_data}'
r = row.copy()
del r['start_date']
del r['stop_date']
del r['territory_codes']
vat_rates[code][time_period] = r
print(vat_rates)
if __name__ == '__main__':
main()

View file

@ -0,0 +1,46 @@
import importlib
import sys
import os
from os.path import join as join_path
from xmlrpc.client import ServerProxy as RPCClient
root = os.path.dirname(os.getcwd())
sys.path.append(join_path(root, 'uncloud'))
secrets = importlib.import_module('uncloud.secrets')
class OpenNebula:
def __init__(self, url, session_string):
self.session_string = session_string
self.client = RPCClient(secrets.OPENNEBULA_URL)
def create_user(self, username, password, authentication_driver='', group_id=None):
# https://docs.opennebula.org/5.10/integration/system_interfaces/api.html#one-user-allocate
if group_id is None:
group_id = []
return self.client.one.user.allocate(
self.session_string,
username,
password,
authentication_driver,
group_id
)
def chmod(self, vm_id, user_id=-1, group_id=-1):
# https://docs.opennebula.org/5.10/integration/system_interfaces/api.html#one-vm-chown
return self.client.one.vm.chown(self.session_string, vm_id, user_id, group_id)
one = OpenNebula(secrets.OPENNEBULA_URL, secrets.OPENNEBULA_USER_PASS)
# Create User in OpenNebula
# success, response, *_ = one.create_user(username='meow12345', password='hello_world')
# print(success, response)
# Change owner of a VM
# success, response, *_ = one.chmod(vm_id=25589, user_id=706)
# print(success, response)

View file

@ -0,0 +1,18 @@
#!/bin/sh
dbhost=$1; shift
ssh -L5432:localhost:5432 "$dbhost" &
python manage.py "$@"
# command only needs to be active while manage command is running
# -T no pseudo terminal
# alternatively: commands output shell code
# ssh uncloud@dbhost "python manage.py --hostname xxx ..."

View file

@ -0,0 +1,51 @@
# uncloud-pay
The generic product/payment system.
## Installation
```shell script
pip3 install -r requirements.txt
```
## Getting Started
```shell script
python ucloud_pay.py
```
## Usage
#### 1. Adding of products
```shell script
http --json http://[::]:5000/product/add username=your_username_here password=your_password_here specs:=@ipv6-only-vm.json
```
#### 2. Listing of products
```shell script
http --json http://[::]:5000/product/list
```
#### 3. Registering user's payment method (credit card for now using Stripe)
```shell script
http --json http://[::]:5000/user/register_payment card_number=4111111111111111 cvc=123 expiry_year=2020 expiry_month=8 card_holder_name="The test user" username=your_username_here password=your_password_here line1="your_billing_address" city="your_city" country="your_country"
```
#### 4. Ordering products
First of all, user have to buy the membership first.
```shell script
http --json http://[::]:5000/product/order username=your_username_here password=your_password_here product_id=membership pay=True
```
```shell script
http --json http://[::]:5000/product/order username=your_username_here password=your_password_here product_id=ipv6-only-vm cpu=1 ram=1 os-disk-space=10 os=alpine pay=True
```
#### 5. Listing users orders
```shell script
http --json POST http://[::]:5000/order/list username=your_username_here password=your_password_here
```

View file

@ -0,0 +1,21 @@
import os
from ungleich_common.ldap.ldap_manager import LdapManager
from ungleich_common.std.configparser import StrictConfigParser
from ungleich_common.etcd.etcd_wrapper import EtcdWrapper
config_file = os.environ.get('meow-pay-config-file', default='pay.conf')
config = StrictConfigParser(allow_no_value=True)
config.read(config_file)
etcd_client = EtcdWrapper(
host=config.get('etcd', 'host'), port=config.get('etcd', 'port'),
ca_cert=config.get('etcd', 'ca_cert'), cert_key=config.get('etcd', 'cert_key'),
cert_cert=config.get('etcd', 'cert_cert')
)
ldap_manager = LdapManager(
server=config.get('ldap', 'server'), admin_dn=config.get('ldap', 'admin_dn'),
admin_password=config.get('ldap', 'admin_password')
)

View file

@ -0,0 +1,213 @@
from flask import Flask, request
from flask_restful import Resource, Api
import etcd3
import json
import logging
from functools import wraps
from ldaptest import is_valid_ldap_user
def authenticate(func):
@wraps(func)
def wrapper(*args, **kwargs):
if not getattr(func, 'authenticated', True):
return func(*args, **kwargs)
# pass in username/password !
acct = basic_authentication() # custom account lookup function
if acct:
return func(*args, **kwargs)
flask_restful.abort(401)
return wrapper
def readable_errors(func):
@wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except etcd3.exceptions.ConnectionFailedError as e:
raise UncloudException('Cannot connect to etcd: is etcd running and reachable? {}'.format(e))
except etcd3.exceptions.ConnectionTimeoutError as e:
raise UncloudException('etcd connection timeout. {}'.format(e))
return wrapper
class DB(object):
def __init__(self, config, prefix="/"):
self.config = config
# Root for everything
self.base_prefix= '/nicohack'
# Can be set from outside
self.prefix = prefix
self.connect()
@readable_errors
def connect(self):
self._db_clients = []
for endpoint in self.config.etcd_hosts:
client = etcd3.client(host=endpoint, **self.config.etcd_args)
self._db_clients.append(client)
def realkey(self, key):
return "{}{}/{}".format(self.base_prefix,
self.prefix,
key)
@readable_errors
def get(self, key, as_json=False, **kwargs):
value, _ = self._db_clients[0].get(self.realkey(key), **kwargs)
if as_json:
value = json.loads(value)
return value
@readable_errors
def set(self, key, value, as_json=False, **kwargs):
if as_json:
value = json.dumps(value)
# FIXME: iterate over clients in case of failure ?
return self._db_clients[0].put(self.realkey(key), value, **kwargs)
class Membership(Resource):
def __init__(self, config):
self.config = config
def get(self):
data = request.get_json(silent=True) or {}
print("{} {}".format(data, config))
return {'message': 'Order successful' }, 200
def post(self):
data = request.get_json(silent=True) or {}
print("{} {}".format(data, config))
return {'message': 'Order 2x successful' }, 200
class Order(Resource):
def __init__(self, config):
self.config = config
@staticmethod
def post():
data = request.get_json(silent=True) or {}
print("{} {}".format(data, config))
class Product(Resource):
def __init__(self, config):
self.config = config
self.products = []
self.products.append(
{ "name": "membership-free",
"description": """
This membership gives you access to the API and includes a VPN
with 1 IPv6 address.
See https://redmine.ungleich.ch/issues/7747?
""",
"uuid": "a3883466-0012-4d01-80ff-cbf7469957af",
"recurring": True,
"recurring_time_frame": "per_year",
"features": [
{ "name": "membership",
"price_one_time": 0,
"price_recurring": 0
}
]
}
)
self.products.append(
{ "name": "membership-standard",
"description": """
This membership gives you access to the API and includes an IPv6-VPN with
one IPv6 address ("Road warrior")
See https://redmine.ungleich.ch/issues/7747?
""",
"uuid": "1d85296b-0863-4dd6-a543-a6d5a4fbe4a6",
"recurring": True,
"recurring_time_frame": "per_month",
"features": [
{ "name": "membership",
"price_one_time": 0,
"price_recurring": 5
}
]
}
)
self.products.append(
{ "name": "membership-premium",
"description": """
This membership gives you access to the API and includes an
IPv6-VPN with a /48 IPv6 network.
See https://redmine.ungleich.ch/issues/7747?
""",
"uuid": "bfd63fd2-d227-436f-a8b8-600de74dd6ce",
"recurring": True,
"recurring_time_frame": "per_month",
"features": [
{ "name": "membership",
"price_one_time": 0,
"price_recurring": 5
}
]
}
)
self.products.append(
{ "name": "ipv6-vpn-with-/48",
"description": """
An IPv6 VPN with a /48 network included.
""",
"uuid": "fe5753f8-6fe1-4dc4-9b73-7b803de4c597",
"recurring": True,
"recurring_time_frame": "per_year",
"features": [
{ "name": "vpn",
"price_one_time": 0,
"price_recurring": 120
}
]
}
)
@staticmethod
def post():
data = request.get_json(silent=True) or {}
print("{} {}".format(data, config))
def get(self):
data = request.get_json(silent=True) or {}
print("{} {}".format(data, config))
return self.products
if __name__ == '__main__':
app = Flask(__name__)
config = {}
config['etcd_url']="https://etcd1.ungleich.ch"
config['ldap_url']="ldaps://ldap1.ungleich.ch"
api = Api(app)
api.add_resource(Order, '/orders', resource_class_args=( config, ))
api.add_resource(Product, '/products', resource_class_args=( config, ))
api.add_resource(Membership, '/membership', resource_class_args=( config, ))
app.run(host='::', port=5000, debug=True)

View file

@ -0,0 +1,87 @@
import logging
import parsedatetime
from datetime import datetime
from stripe_utils import StripeUtils
def get_plan_id_from_product(product):
plan_id = 'ucloud-v1-'
plan_id += product['name'].strip().replace(' ', '-')
return plan_id
def get_pricing(price_in_chf_cents, product_type, recurring_period):
if product_type == 'recurring':
return 'CHF {}/{}'.format(price_in_chf_cents/100, recurring_period)
elif product_type == 'one-time':
return 'CHF {} (One time charge)'.format(price_in_chf_cents/100)
def get_user_friendly_product(product_dict):
uf_product = {
'name': product_dict['name'],
'description': product_dict['description'],
'product_id': product_dict['usable-id'],
'pricing': get_pricing(
product_dict['price'], product_dict['type'], product_dict['recurring_period']
)
}
if product_dict['type'] == 'recurring':
uf_product['minimum_subscription_period'] = product_dict['minimum_subscription_period']
return uf_product
def get_token(card_number, cvc, exp_month, exp_year):
stripe_utils = StripeUtils()
token_response = stripe_utils.get_token_from_card(
card_number, cvc, exp_month, exp_year
)
if token_response['response_object']:
return token_response['response_object'].id
else:
return None
def resolve_product(usable_id, etcd_client):
products = etcd_client.get_prefix('/v1/products/', value_in_json=True)
for p in products:
if p.value['usable-id'] == usable_id:
return p.value
return None
def calculate_charges(specification, data):
logging.debug('Calculating charges for specs:{} and data:{}'.format(specification, data))
one_time_charge = 0
recurring_charge = 0
for feature_name, feature_detail in specification['features'].items():
if feature_detail['constant']:
data[feature_name] = 1
if feature_detail['unit']['type'] != 'str':
one_time_charge += feature_detail['one_time_fee']
recurring_charge += (
feature_detail['price_per_unit_per_period'] * data[feature_name] /
feature_detail['unit']['value']
)
return one_time_charge, recurring_charge
def is_order_valid(order_timestamp, renewal_period):
"""
Sample Code Usage
>> current_datetime, status = cal.parse('Now')
>> current_datetime = datetime(*current_datetime[:6])
>> print('Is order valid: ', is_order_valid(current_datetime, '1 month'))
>> True
"""
cal = parsedatetime.Calendar()
renewal_datetime, status = cal.parse(renewal_period)
renewal_datetime = datetime(*renewal_datetime[:6])
return order_timestamp <= renewal_datetime

View file

@ -0,0 +1,28 @@
{
"usable-id": "ipv6-only-django-hosting",
"active": true,
"name": "IPv6 Only Django Hosting",
"description": "Host your Django application on our shiny IPv6 Only VM",
"recurring_period": "month",
"quantity": "inf",
"features": {
"cpu": {
"unit": {"value": 1, "type":"int"},
"price_per_unit_per_period": 3,
"one_time_fee": 0,
"constant": false
},
"ram": {
"unit": {"value": 1, "type":"int"},
"price_per_unit_per_period": 4,
"one_time_fee": 0,
"constant": false
},
"os-disk-space": {
"unit": {"value": 10, "type":"int"},
"one_time_fee": 0,
"price_per_unit_per_period": 3.5,
"constant": false
}
}
}

View file

@ -0,0 +1,34 @@
{
"usable-id": "ipv6-only-vm",
"active": true,
"name": "IPv6 Only VM",
"description": "IPv6 Only VM are accessible to only those having IPv6 for themselves",
"recurring_period": "month",
"quantity": "inf",
"features": {
"cpu": {
"unit": {"value": 1, "type":"int"},
"price_per_unit_per_period": 3,
"one_time_fee": 0,
"constant": false
},
"ram": {
"unit": {"value": 1, "type":"int"},
"price_per_unit_per_period": 4,
"one_time_fee": 0,
"constant": false
},
"os-disk-space": {
"unit": {"value": 10, "type":"int"},
"one_time_fee": 0,
"price_per_unit_per_period": 4,
"constant": false
},
"os": {
"unit": {"value": 1, "type":"str"},
"one_time_fee": 0,
"price_per_unit_per_period": 0,
"constant": false
}
}
}

View file

@ -0,0 +1,16 @@
{
"usable-id": "ipv6-only-vpn",
"active": true,
"name": "IPv6 Only VPN",
"description": "IPv6 VPN enable you to access IPv6 only websites and more",
"recurring_period": "month",
"quantity": "inf",
"features": {
"vpn": {
"unit": {"value": 1, "type": "int"},
"price_per_unit_per_period": 10,
"one_time_fee": 0,
"constant": true
}
}
}

View file

@ -0,0 +1,16 @@
{
"usable-id": "ipv6-box",
"active": true,
"name": "IPv6 Box",
"description": "A ready-to-go IPv6 Box: it creates a VPN to ungleich and distributes IPv6 addresses to all your computers.",
"recurring_period": "eternity",
"quantity": 4,
"features": {
"ipv6-box": {
"unit": {"value": 1, "type":"int"},
"price_per_unit_per_period": 0,
"one_time_fee": 250,
"constant": true
}
}
}

View file

@ -0,0 +1,17 @@
{
"usable-id": "membership",
"active": true,
"name": "Membership",
"description": "Membership to use uncloud-pay",
"recurring_period": "month",
"quantity": "inf",
"features": {
"membership": {
"unit": {"value": 1, "type":"int"},
"price_per_unit_per_period": 5,
"one_time_fee": 0,
"constant": true
}
},
"max_per_user": "1"
}

View file

@ -0,0 +1,7 @@
stripe
flask
Flask-RESTful
git+https://code.ungleich.ch/ahmedbilal/ungleich-common/#egg=ungleich-common-etcd&subdirectory=etcd
git+https://code.ungleich.ch/ahmedbilal/ungleich-common/#egg=ungleich-common-ldap&subdirectory=ldap
git+https://code.ungleich.ch/ahmedbilal/ungleich-common/#egg=ungleich-common-std&subdirectory=std
git+https://code.ungleich.ch/ahmedbilal/ungleich-common/#egg=ungleich-common-schemas&subdirectory=schemas

View file

@ -0,0 +1,17 @@
[etcd]
host = 127.0.0.1
port = 2379
ca_cert
cert_cert
cert_key
[stripe]
private_key=stripe_private_key
[app]
port = 5000
[ldap]
server = ldap_server_url
admin_dn = ldap_admin_dn
admin_password = ldap_admin_password

View file

@ -0,0 +1,136 @@
import logging
import config
import json
import math
from config import ldap_manager, etcd_client
from helper import resolve_product
from ungleich_common.schemas.schemas import BaseSchema, Field, ValidationException
class AddProductSchema(BaseSchema):
def __init__(self, data):
super().__init__()
self.add_schema(UserCredentialSchema, data)
self.specs = Field('specs', dict, **self.get(data, 'specs'))
self.update = Field('update', bool, **self.get(data, 'update', return_default=True, default=False))
def validation(self):
user = self.objects['user']
user = json.loads(user.entry_to_json())
uid, ou, *dc = user['dn'].replace('ou=', '').replace('dc=', '').replace('uid=', '').split(',')
if ou != config.config.get('ldap', 'internal_user_ou', fallback='users'):
raise ValidationException('You do not have access to create product.')
product = resolve_product(self.specs.value['usable-id'], etcd_client)
if product:
self.objects['product'] = product
class AddressSchema(BaseSchema):
def __init__(self, data):
super().__init__()
self.line1 = Field('line1', str, **self.get(data, 'line1'))
self.line2 = Field('line2', str, **self.get(data, 'line2', return_default=True))
self.city = Field('city', str, **self.get(data, 'city'))
self.country = Field('country', str, **self.get(data, 'country'))
self.state = Field('state', str, **self.get(data, 'state', return_default=True))
self.postal_code = Field('postal_code', str, **self.get(data, 'postal_code', return_default=True))
class UserRegisterPaymentSchema(BaseSchema):
def __init__(self, data):
super().__init__()
self.add_schema(UserCredentialSchema, data)
self.add_schema(AddressSchema, data, under_field_name='address')
self.card_number = Field('card_number', str, **self.get(data, 'card_number'))
self.cvc = Field('cvc', str, **self.get(data, 'cvc'))
self.expiry_year = Field('expiry_year', int, **self.get(data, 'expiry_year'))
self.expiry_month = Field('expiry_month', int, **self.get(data, 'expiry_month'))
self.card_holder_name = Field('card_holder_name', str, **self.get(data, 'card_holder_name'))
class UserCredentialSchema(BaseSchema):
def __init__(self, data):
super().__init__()
self.username = Field('username', str, **self.get(data, 'username'))
self.password = Field('password', str, **self.get(data, 'password'))
def validation(self):
try:
entry = ldap_manager.is_password_valid(self.username.value, self.password.value, query_key='uid')
except ValueError:
raise ValidationException('No user with \'{}\' username found. You can create account at '
'https://account.ungleich.ch'.format(self.username.value))
except Exception:
raise ValidationException('Invalid username/password.')
else:
self.objects['user'] = entry
class ProductOrderSchema(BaseSchema):
def __init__(self, data):
super().__init__()
self.product_id = Field(
'product_id', str, **self.get(data, 'product_id'), validators=[self.product_id_validation]
)
self.pay_consent = Field('pay', bool, **self.get(data, 'pay', return_default=True, default=False))
self.add_schema(UserCredentialSchema, data)
def product_id_validation(self):
product = resolve_product(self.product_id.value, etcd_client)
if product:
product['quantity'] = float(product['quantity'])
self.product_id.value = product['uuid']
self.objects['product'] = product
logging.debug('Got product {}'.format(product))
if not product['active']:
raise ValidationException('Product is not active at the moment.')
if product['quantity'] <= 0:
raise ValidationException('Out of stock.')
else:
raise ValidationException('No such product exists.')
def validation(self):
username = self.objects['user'].uid
customer_previous_orders = etcd_client.get_prefix('/v1/user/{}'.format(username), value_in_json=True)
customer_previous_orders = [o.value for o in customer_previous_orders]
membership = next(filter(lambda o: o['product'] == 'membership', customer_previous_orders), None)
if membership is None and self.objects['product']['usable-id'] != 'membership':
raise ValidationException('Please buy membership first to use this facility')
max_quantity_user_can_order = float(self.objects['product'].get('max_per_user', math.inf))
previous_order_of_same_product = [
o for o in customer_previous_orders if o['product'] == self.objects['product']['usable-id']
]
if len(previous_order_of_same_product) >= max_quantity_user_can_order:
raise ValidationException(
'You cannot buy {} more than {} times'.format(
self.objects['product']['name'], int(max_quantity_user_can_order)
)
)
class OrderListSchema(BaseSchema):
def __init__(self, data):
super().__init__()
self.add_schema(UserCredentialSchema, data)
def make_return_message(err, status_code=200):
logging.debug('message: {}'.format(str(err)))
return {'message': str(err)}, status_code
def create_schema(specification, data):
fields = {}
for feature_name, feature_detail in specification['features'].items():
if not feature_detail['constant']:
fields[feature_name] = Field(
feature_name, eval(feature_detail['unit']['type']), **BaseSchema.get(data, feature_name)
)
return type('{}Schema'.format(specification['name']), (BaseSchema,), fields)

View file

@ -0,0 +1,7 @@
import stripe_utils
import os
if __name__ == '__main__':
s = stripe_utils.StripeUtils(os.environ['STRIPE_PRIVATE_KEY'])
print(s.get_stripe_customer_from_email('coder.purple+2002@gmail.com'))

View file

@ -0,0 +1,491 @@
import re
import stripe
import stripe.error
import logging
from config import etcd_client as client, config as config
stripe.api_key = config.get('stripe', 'private_key')
def handle_stripe_error(f):
def handle_problems(*args, **kwargs):
response = {
'paid': False,
'response_object': None,
'error': None
}
common_message = "Currently it's not possible to make payments."
try:
response_object = f(*args, **kwargs)
response = {
'response_object': response_object,
'error': None
}
return response
except stripe.error.CardError as e:
# Since it's a decline, stripe.error.CardError will be caught
body = e.json_body
err = body['error']
response.update({'error': err['message']})
logging.error(str(e))
return response
except stripe.error.RateLimitError:
response.update(
{'error': "Too many requests made to the API too quickly"})
return response
except stripe.error.InvalidRequestError as e:
logging.error(str(e))
response.update({'error': "Invalid parameters"})
return response
except stripe.error.AuthenticationError as e:
# Authentication with Stripe's API failed
# (maybe you changed API keys recently)
logging.error(str(e))
response.update({'error': common_message})
return response
except stripe.error.APIConnectionError as e:
logging.error(str(e))
response.update({'error': common_message})
return response
except stripe.error.StripeError as e:
# maybe send email
logging.error(str(e))
response.update({'error': common_message})
return response
except Exception as e:
# maybe send email
logging.error(str(e))
response.update({'error': common_message})
return response
return handle_problems
class StripeUtils(object):
CURRENCY = 'chf'
INTERVAL = 'month'
SUCCEEDED_STATUS = 'succeeded'
STRIPE_PLAN_ALREADY_EXISTS = 'Plan already exists'
STRIPE_NO_SUCH_PLAN = 'No such plan'
PLAN_EXISTS_ERROR_MSG = 'Plan {} exists already.\nCreating a local StripePlan now.'
PLAN_DOES_NOT_EXIST_ERROR_MSG = 'Plan {} does not exist.'
def __init__(self, private_key):
self.stripe = stripe
stripe.api_key = private_key
@handle_stripe_error
def card_exists(self, customer, cc_number, exp_month, exp_year, cvc):
token_obj = stripe.Token.create(
card={
'number': cc_number,
'exp_month': exp_month,
'exp_year': exp_year,
'cvc': cvc,
},
)
cards = stripe.Customer.list_sources(
customer,
limit=20,
object='card'
)
for card in cards.data:
if (card.fingerprint == token_obj.card.fingerprint and
int(card.exp_month) == int(exp_month) and int(card.exp_year) == int(exp_year)):
return True
return False
@staticmethod
def get_stripe_customer_from_email(email):
customer = stripe.Customer.list(limit=1, email=email)
return customer.data[0] if len(customer.data) == 1 else None
@staticmethod
def update_customer_token(customer, token):
customer.source = token
customer.save()
@handle_stripe_error
def get_token_from_card(self, cc_number, cvc, expiry_month, expiry_year):
token_obj = stripe.Token.create(
card={
'number': cc_number,
'exp_month': expiry_month,
'exp_year': expiry_year,
'cvc': cvc,
},
)
return token_obj
@handle_stripe_error
def associate_customer_card(self, stripe_customer_id, token,
set_as_default=False):
customer = stripe.Customer.retrieve(stripe_customer_id)
card = customer.sources.create(source=token)
if set_as_default:
customer.default_source = card.id
customer.save()
return True
@handle_stripe_error
def dissociate_customer_card(self, stripe_customer_id, card_id):
customer = stripe.Customer.retrieve(stripe_customer_id)
card = customer.sources.retrieve(card_id)
card.delete()
@handle_stripe_error
def update_customer_card(self, customer_id, token):
customer = stripe.Customer.retrieve(customer_id)
current_card_token = customer.default_source
customer.sources.retrieve(current_card_token).delete()
customer.source = token
customer.save()
credit_card_raw_data = customer.sources.data.pop()
new_card_data = {
'last4': credit_card_raw_data.last4,
'brand': credit_card_raw_data.brand
}
return new_card_data
@handle_stripe_error
def get_card_details(self, customer_id):
customer = stripe.Customer.retrieve(customer_id)
credit_card_raw_data = customer.sources.data.pop()
card_details = {
'last4': credit_card_raw_data.last4,
'brand': credit_card_raw_data.brand,
'exp_month': credit_card_raw_data.exp_month,
'exp_year': credit_card_raw_data.exp_year,
'fingerprint': credit_card_raw_data.fingerprint,
'card_id': credit_card_raw_data.id
}
return card_details
@handle_stripe_error
def get_all_invoices(self, customer_id, created_gt):
return_list = []
has_more_invoices = True
starting_after = False
while has_more_invoices:
if starting_after:
invoices = stripe.Invoice.list(
limit=10, customer=customer_id, created={'gt': created_gt},
starting_after=starting_after
)
else:
invoices = stripe.Invoice.list(
limit=10, customer=customer_id, created={'gt': created_gt}
)
has_more_invoices = invoices.has_more
for invoice in invoices.data:
sub_ids = []
for line in invoice.lines.data:
if line.type == 'subscription':
sub_ids.append(line.id)
elif line.type == 'invoiceitem':
sub_ids.append(line.subscription)
else:
sub_ids.append('')
invoice_details = {
'created': invoice.created,
'receipt_number': invoice.receipt_number,
'invoice_number': invoice.number,
'paid_at': invoice.status_transitions.paid_at if invoice.paid else 0,
'period_start': invoice.period_start,
'period_end': invoice.period_end,
'billing_reason': invoice.billing_reason,
'discount': invoice.discount.coupon.amount_off if invoice.discount else 0,
'total': invoice.total,
# to see how many line items we have in this invoice and
# then later check if we have more than 1
'lines_data_count': len(invoice.lines.data) if invoice.lines.data is not None else 0,
'invoice_id': invoice.id,
'lines_meta_data_csv': ','.join(
[line.metadata.VM_ID if hasattr(line.metadata, 'VM_ID') else '' for line in invoice.lines.data]
),
'subscription_ids_csv': ','.join(sub_ids),
'line_items': invoice.lines.data
}
starting_after = invoice.id
return_list.append(invoice_details)
return return_list
@handle_stripe_error
def get_cards_details_from_token(self, token):
stripe_token = stripe.Token.retrieve(token)
card_details = {
'last4': stripe_token.card.last4,
'brand': stripe_token.card.brand,
'exp_month': stripe_token.card.exp_month,
'exp_year': stripe_token.card.exp_year,
'fingerprint': stripe_token.card.fingerprint,
'card_id': stripe_token.card.id
}
return card_details
def check_customer(self, stripe_cus_api_id, user, token):
try:
customer = stripe.Customer.retrieve(stripe_cus_api_id)
except stripe.error.InvalidRequestError:
customer = self.create_customer(token, user.email, user.name)
user.stripecustomer.stripe_id = customer.get(
'response_object').get('id')
user.stripecustomer.save()
if type(customer) is dict:
customer = customer['response_object']
return customer
@handle_stripe_error
def get_customer(self, stripe_api_cus_id):
customer = stripe.Customer.retrieve(stripe_api_cus_id)
# data = customer.get('response_object')
return customer
@handle_stripe_error
def create_customer(self, token, email, name=None, address=None):
if name is None or name.strip() == "":
name = email
customer = self.stripe.Customer.create(
source=token,
description=name,
email=email,
address=address
)
return customer
@handle_stripe_error
def make_charge(self, amount=None, customer=None):
_amount = float(amount)
amount = int(_amount * 100) # stripe amount unit, in cents
charge = self.stripe.Charge.create(
amount=amount, # in cents
currency=self.CURRENCY,
customer=customer
)
return charge
@staticmethod
def _get_all_stripe_plans():
all_stripe_plans = client.get("/v1/stripe_plans")
all_stripe_plans_set = set()
if all_stripe_plans:
all_stripe_plans_obj = all_stripe_plans.value
if all_stripe_plans_obj and len(all_stripe_plans_obj['plans']) > 0:
all_stripe_plans_set = set(all_stripe_plans_obj["plans"])
return all_stripe_plans_set
@staticmethod
def _save_all_stripe_plans(stripe_plans):
client.put("/v1/stripe_plans", {"plans": list(stripe_plans)})
@handle_stripe_error
def get_or_create_stripe_plan(self, product_name, amount, stripe_plan_id,
interval=INTERVAL):
"""
This function checks if a StripePlan with the given
stripe_plan_id already exists. If it exists then the function
returns this object otherwise it creates a new StripePlan and
returns the new object.
:param amount: The amount in CHF cents
:param product_name: The name of the Stripe plan (product) to be created.
:param stripe_plan_id: The id of the Stripe plan to be
created. Use get_stripe_plan_id_string function to
obtain the name of the plan to be created
:param interval: The interval for subscription {month, year}. Defaults
to month if not provided
:return: The StripePlan object if it exists else creates a
Plan object in Stripe and a local StripePlan and
returns it. Returns None in case of Stripe error
"""
_amount = float(amount)
amount = int(_amount * 100) # stripe amount unit, in cents
all_stripe_plans = self._get_all_stripe_plans()
if stripe_plan_id in all_stripe_plans:
logging.debug("{} plan exists in db.".format(stripe_plan_id))
else:
logging.debug(("{} plan DOES NOT exist in db. "
"Creating").format(stripe_plan_id))
try:
plan_obj = self.stripe.Plan.retrieve(id=stripe_plan_id)
logging.debug("{} plan exists in Stripe".format(stripe_plan_id))
all_stripe_plans.add(stripe_plan_id)
except stripe.error.InvalidRequestError as e:
if "No such plan" in str(e):
logging.debug("Plan {} does not exist in Stripe, Creating")
plan_obj = self.stripe.Plan.create(
amount=amount,
product={'name': product_name},
interval=interval,
currency=self.CURRENCY,
id=stripe_plan_id)
logging.debug(self.PLAN_EXISTS_ERROR_MSG.format(stripe_plan_id))
all_stripe_plans.add(stripe_plan_id)
self._save_all_stripe_plans(all_stripe_plans)
return stripe_plan_id
@handle_stripe_error
def delete_stripe_plan(self, stripe_plan_id):
"""
Deletes the Plan in Stripe and also deletes the local db copy
of the plan if it exists
:param stripe_plan_id: The stripe plan id that needs to be
deleted
:return: True if the plan was deleted successfully from
Stripe, False otherwise.
"""
return_value = False
try:
plan = self.stripe.Plan.retrieve(stripe_plan_id)
plan.delete()
return_value = True
all_stripe_plans = self._get_all_stripe_plans()
all_stripe_plans.remove(stripe_plan_id)
self._save_all_stripe_plans(all_stripe_plans)
except stripe.error.InvalidRequestError as e:
if self.STRIPE_NO_SUCH_PLAN in str(e):
logging.debug(
self.PLAN_DOES_NOT_EXIST_ERROR_MSG.format(stripe_plan_id))
return return_value
@handle_stripe_error
def subscribe_customer_to_plan(self, customer, plans, trial_end=None):
"""
Subscribes the given customer to the list of given plans
:param customer: The stripe customer identifier
:param plans: A list of stripe plans.
:param trial_end: An integer representing when the Stripe subscription
is supposed to end
Ref: https://stripe.com/docs/api/python#create_subscription-items
e.g.
plans = [
{
"plan": "dcl-v1-cpu-2-ram-5gb-ssd-10gb",
},
]
:return: The subscription StripeObject
"""
subscription_result = self.stripe.Subscription.create(
customer=customer, items=plans, trial_end=trial_end
)
return subscription_result
@handle_stripe_error
def set_subscription_metadata(self, subscription_id, metadata):
subscription = stripe.Subscription.retrieve(subscription_id)
subscription.metadata = metadata
subscription.save()
@handle_stripe_error
def unsubscribe_customer(self, subscription_id):
"""
Cancels a given subscription
:param subscription_id: The Stripe subscription id string
:return:
"""
sub = stripe.Subscription.retrieve(subscription_id)
return sub.delete()
@handle_stripe_error
def make_payment(self, customer, amount, token):
charge = self.stripe.Charge.create(
amount=amount, # in cents
currency=self.CURRENCY,
customer=customer
)
return charge
@staticmethod
def get_stripe_plan_id(cpu, ram, ssd, version, app='dcl', hdd=None,
price=None):
"""
Returns the Stripe plan id string of the form
`dcl-v1-cpu-2-ram-5gb-ssd-10gb` based on the input parameters
:param cpu: The number of cores
:param ram: The size of the RAM in GB
:param ssd: The size of ssd storage in GB
:param hdd: The size of hdd storage in GB
:param version: The version of the Stripe plans
:param app: The application to which the stripe plan belongs
to. By default it is 'dcl'
:param price: The price for this plan
:return: A string of the form `dcl-v1-cpu-2-ram-5gb-ssd-10gb`
"""
dcl_plan_string = 'cpu-{cpu}-ram-{ram}gb-ssd-{ssd}gb'.format(cpu=cpu,
ram=ram,
ssd=ssd)
if hdd is not None:
dcl_plan_string = '{dcl_plan_string}-hdd-{hdd}gb'.format(
dcl_plan_string=dcl_plan_string, hdd=hdd)
stripe_plan_id_string = '{app}-v{version}-{plan}'.format(
app=app,
version=version,
plan=dcl_plan_string
)
if price is not None:
stripe_plan_id_string_with_price = '{}-{}chf'.format(
stripe_plan_id_string,
round(price, 2)
)
return stripe_plan_id_string_with_price
else:
return stripe_plan_id_string
@staticmethod
def get_vm_config_from_stripe_id(stripe_id):
"""
Given a string like "dcl-v1-cpu-2-ram-5gb-ssd-10gb" return different
configuration params as a dict
:param stripe_id|str
:return: dict
"""
pattern = re.compile(r'^dcl-v(\d+)-cpu-(\d+)-ram-(\d+\.?\d*)gb-ssd-(\d+)gb-?(\d*\.?\d*)(chf)?$')
match_res = pattern.match(stripe_id)
if match_res is not None:
price = None
try:
price = match_res.group(5)
except IndexError:
logging.debug("Did not find price in {}".format(stripe_id))
return {
'version': match_res.group(1),
'cores': match_res.group(2),
'ram': match_res.group(3),
'ssd': match_res.group(4),
'price': price
}
@staticmethod
def get_stripe_plan_name(cpu, memory, disk_size, price):
"""
Returns the Stripe plan name
:return:
"""
return "{cpu} Cores, {memory} GB RAM, {disk_size} GB SSD, " \
"{price} CHF".format(
cpu=cpu,
memory=memory,
disk_size=disk_size,
price=round(price, 2)
)
@handle_stripe_error
def set_subscription_meta_data(self, subscription_id, meta_data):
"""
Adds VM metadata to a subscription
:param subscription_id: Stripe identifier for the subscription
:param meta_data: A dict of meta data to be added
:return:
"""
subscription = stripe.Subscription.retrieve(subscription_id)
subscription.metadata = meta_data
subscription.save()

View file

@ -0,0 +1,338 @@
import logging
from datetime import datetime
from uuid import uuid4
from flask import Flask, request
from flask_restful import Resource, Api
from werkzeug.exceptions import HTTPException
from config import etcd_client as client, config as config
from stripe_utils import StripeUtils
from schemas import (
make_return_message, ValidationException, UserRegisterPaymentSchema,
AddProductSchema, ProductOrderSchema, OrderListSchema, create_schema
)
from helper import get_plan_id_from_product, calculate_charges
class ListProducts(Resource):
@staticmethod
def get():
products = client.get_prefix('/v1/products/')
products = [
product
for product in [p.value for p in products]
if product['active']
]
prod_dict = {}
for p in products:
prod_dict[p['usable-id']] = {
'name': p['name'],
'description': p['description'],
}
logger.debug('Products = {}'.format(prod_dict))
return prod_dict, 200
class AddProduct(Resource):
@staticmethod
def post():
data = request.get_json(silent=True) or {}
try:
logger.debug('Got data: {}'.format(str(data)))
validator = AddProductSchema(data)
validator.is_valid()
except ValidationException as err:
return make_return_message(err, 400)
else:
cleaned_values = validator.get_cleaned_values()
previous_product = cleaned_values.get('product', None)
if previous_product:
if not cleaned_values['update']:
return make_return_message('Product already exists. Pass --update to update the product.')
else:
product_uuid = previous_product.pop('uuid')
else:
product_uuid = uuid4().hex
product_value = cleaned_values['specs']
product_key = '/v1/products/{}'.format(product_uuid)
product_value['uuid'] = product_uuid
logger.debug('Adding product data: {}'.format(str(product_value)))
client.put(product_key, product_value)
if not previous_product:
return make_return_message('Product created.')
else:
return make_return_message('Product updated.')
################################################################################
# Nico-ok-marker
class UserRegisterPayment(Resource):
@staticmethod
def post():
data = request.get_json(silent=True) or {}
try:
logger.debug('Got data: {}'.format(str(data)))
validator = UserRegisterPaymentSchema(data)
validator.is_valid()
except ValidationException as err:
return make_return_message(err, 400)
else:
cleaned_values = validator.get_cleaned_values()
last4 = data['card_number'].strip()[-4:]
stripe_utils = StripeUtils()
# Does customer already exist ?
stripe_customer = stripe_utils.get_stripe_customer_from_email(cleaned_values['user']['mail'])
# Does customer already exist ?
if stripe_customer is not None:
logger.debug('Customer {}-{} exists already'.format(
cleaned_values['username'], cleaned_values['user']['mail'])
)
# Check if the card already exists
ce_response = stripe_utils.card_exists(
stripe_customer.id, cc_number=data['card_number'],
exp_month=int(data['expiry_month']),
exp_year=int(data['expiry_year']),
cvc=data['cvc'])
if ce_response['response_object']:
message = 'The given card ending in {} exists already.'.format(last4)
return make_return_message(message, 400)
elif ce_response['response_object'] is False:
# Associate card with user
logger.debug('Adding card ending in {}'.format(last4))
token_response = stripe_utils.get_token_from_card(
data['card_number'], data['cvc'], data['expiry_month'],
data['expiry_year']
)
if token_response['response_object']:
logger.debug('Token {}'.format(token_response['response_object'].id))
resp = stripe_utils.associate_customer_card(
stripe_customer.id, token_response['response_object'].id
)
if resp['response_object']:
return make_return_message(
'Card ending in {} registered as your payment source'.format(last4)
)
else:
return make_return_message('Error with payment gateway. Contact support', 400)
else:
return make_return_message('Error: {}'.format(ce_response['error']), 400)
else:
# Stripe customer does not exist, create a new one
logger.debug(
'Customer {} does not exist, creating new'.format(cleaned_values['user']['mail'])
)
token_response = stripe_utils.get_token_from_card(
cleaned_values['card_number'], cleaned_values['cvc'],
cleaned_values['expiry_month'], cleaned_values['expiry_year']
)
if token_response['response_object']:
logger.debug('Token {}'.format(token_response['response_object'].id))
# Create stripe customer
stripe_customer_resp = stripe_utils.create_customer(
name=cleaned_values['card_holder_name'],
token=token_response['response_object'].id,
email=cleaned_values['user']['mail'],
address=cleaned_values['address']
)
stripe_customer = stripe_customer_resp['response_object']
if stripe_customer:
logger.debug('Created stripe customer {}'.format(stripe_customer.id))
return make_return_message(
'Card ending in {} registered as your payment source'.format(last4)
)
else:
return make_return_message('Error with card. Contact support', 400)
else:
return make_return_message('Error with payment gateway. Contact support', 400)
class ProductOrder(Resource):
@staticmethod
def post():
data = request.get_json(silent=True) or {}
try:
validator = ProductOrderSchema(data)
validator.is_valid()
except ValidationException as err:
return make_return_message(err, 400)
else:
cleaned_values = validator.get_cleaned_values()
stripe_utils = StripeUtils()
product = cleaned_values['product']
# Check the user has a payment source added
stripe_customer = stripe_utils.get_stripe_customer_from_email(cleaned_values['user']['mail'])
if not stripe_customer or len(stripe_customer.sources) == 0:
return make_return_message('Please register your payment method first.', 400)
try:
product_schema = create_schema(product, data)
product_schema = product_schema()
product_schema.is_valid()
except ValidationException as err:
return make_return_message(err, 400)
else:
transformed_data = product_schema.get_cleaned_values()
logger.debug('Tranformed data: {}'.format(transformed_data))
one_time_charge, recurring_charge = calculate_charges(product, transformed_data)
recurring_charge = int(recurring_charge)
if not cleaned_values['pay']:
return make_return_message(
'You would be charged {} CHF one time and {} CHF every {}. '
'Add --pay to command to order.'.format(
one_time_charge, recurring_charge, product['recurring_period']
)
)
with client.client.lock('product-order') as _:
# Initiate a one-time/subscription based on product type
if recurring_charge > 0:
logger.debug('Product {} is recurring payment'.format(product['name']))
plan_id = get_plan_id_from_product(product)
res = stripe_utils.get_or_create_stripe_plan(
product_name=product['name'],
stripe_plan_id=plan_id, amount=recurring_charge,
interval=product['recurring_period'],
)
if res['response_object']:
logger.debug('Obtained plan {}'.format(plan_id))
subscription_res = stripe_utils.subscribe_customer_to_plan(
stripe_customer.id,
[{'plan': plan_id}]
)
subscription_obj = subscription_res['response_object']
if subscription_obj is None or subscription_obj.status != 'active':
return make_return_message(
'Error subscribing to plan. Detail: {}'.format(subscription_res['error']), 400
)
else:
order_obj = {
'order-id': uuid4().hex,
'ordered-at': datetime.now().isoformat(),
'product': product['usable-id'],
'one-time-price': one_time_charge,
'recurring-price': recurring_charge,
'recurring-period': product['recurring_period']
}
client.put(
'/v1/user/{}/orders/{}'.format(
cleaned_values['username'], order_obj['order-id']
), order_obj
)
product['quantity'] -= 1
client.put('/v1/products/{}'.format(product['uuid']), product)
return {
'message': 'Order Successful.',
**order_obj
}
else:
logger.error('Could not create plan {}'.format(plan_id))
return make_return_message('Something wrong happened. Contact administrator', 400)
elif recurring_charge == 0 and one_time_charge > 0:
logger.debug('Product {} is one-time payment'.format(product['name']))
charge_response = stripe_utils.make_charge(
amount=one_time_charge,
customer=stripe_customer.id
)
stripe_onetime_charge = charge_response.get('response_object')
# Check if the payment was approved
if not stripe_onetime_charge:
msg = charge_response.get('error')
return make_return_message('Error subscribing to plan. Details: {}'.format(msg), 400)
order_obj = {
'order-id': uuid4().hex,
'ordered-at': datetime.now().isoformat(),
'product': product['usable-id'],
'one-time-price': one_time_charge,
}
client.put(
'/v1/user/{}/orders/{}'.format(cleaned_values['username'], order_obj['order-id']),
order_obj
)
product['quantity'] -= 1
client.put('/v1/products/{}'.format(product['uuid']), product)
return {'message': 'Order successful', **order_obj}, 200
class OrderList(Resource):
@staticmethod
def post():
data = request.get_json(silent=True) or {}
try:
validator = OrderListSchema(data)
validator.is_valid()
except ValidationException as err:
return make_return_message(err, 400)
else:
cleaned_values = validator.get_cleaned_values()
orders = client.get_prefix('/v1/user/{}/orders'.format(cleaned_values['username']))
orders_dict = {
order.value['order-id']: {
**order.value
}
for order in orders
}
logger.debug('Orders = {}'.format(orders_dict))
return {'orders': orders_dict}, 200
if __name__ == '__main__':
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
log_formater = logging.Formatter('[%(filename)s:%(lineno)d] %(message)s')
stream_logger = logging.StreamHandler()
stream_logger.setFormatter(log_formater)
# file_logger = logging.FileHandler('log.txt')
# file_logger.setLevel(logging.DEBUG)
# file_logger.setFormatter(log_formater)
logger.addHandler(stream_logger)
# logger.addHandler(file_logger)
app = Flask(__name__)
api = Api(app)
api.add_resource(ListProducts, '/product/list')
api.add_resource(AddProduct, '/product/add')
api.add_resource(ProductOrder, '/product/order')
api.add_resource(UserRegisterPayment, '/user/register_payment')
api.add_resource(OrderList, '/order/list')
app.run(host='::', port=config.get('app', 'port', fallback=5000), debug=True)
@app.errorhandler(Exception)
def handle_exception(e):
app.logger.error(e)
# pass through HTTP errors
if isinstance(e, HTTPException):
return e
# now you're handling non-HTTP exceptions only
return {'message': 'Server Error'}, 500

View file

@ -0,0 +1,11 @@
## TODO 2020-02-22
* ~~move the current rest api to /opennebula~~
* ~~make the /opennebula api only accessible by an admin account~~
* ~~create a new filtered api on /vm/list that~~
* ~~a) requires authentication~~
* ~~b) only shows the VMs of the current user~~
* ~~the new api should not contain all details, but: cpus (as read by the vcpu field), ram, ips, disks~~
* ~~also make a (random) uuid the primary key for VMs - everything in this uncloud hack will use uuids as the id~~
* ~~still expose the opennebula id as opennebula_id~~
* ~~note put all secrets/configs into uncloud.secrets - I added a sample file into the repo~~

View file

@ -0,0 +1,102 @@
* snapshot feature
** product: vm-snapshot
** flow
*** list all my VMs
**** get the uuid of the VM I want to take a snapshot of
*** request a snapshot
```
vmuuid=$(http nicocustomer
http -a nicocustomer:xxx http://uncloud.ch/vm/create_snapshot uuid=
password=...
```
** backend realisation
*** list snapshots
- have them in the DB
- create an entry on create
*** creating snapshots
- vm sync / fsync?
- rbd snapshot
- host/cluster mapping?
- need image(s)
* steps
** DONE authenticate via ldap
CLOSED: [2020-02-20 Thu 19:05]
** DONE Make classes / views require authentication
CLOSED: [2020-02-20 Thu 19:05]
** TODO register credit card
*** TODO find out what saving with us
*** Info
**** should not be fully saved in the DB
**** model needs to be a bit different
* Decide where to save sensitive data
** stripe access key, etc.
* python requirements (nicohack202002)
django djangorestframework django-auth-ldap stripe
* os package requirements (alpine)
openldap-dev
* VPN case
** put on /orders with uuid
** register cc
* CC
** TODO check whether we can register or not at stripe
* membership
** required for "smaller" / "shorter" products
* TODO Membership missing
* Flows to be implemented - see https://redmine.ungleich.ch/issues/7609
** Membership
*** 5 CHF
** Django Hosting
*** One time payment 35 CHF
*** Monthly payment depends on VM size
*** Parameters: same as IPv6 only VM
** IPv6 VPN
*** Parameters: none
*** Is for free if the customer has an active VM
** IPv6 only VM
*** Parameters: cores, ram, os_disk_size, OS
* Django rest framework
** viewset: .list and .create
** view: .get .post
* TODO register CC
* DONE list products
CLOSED: [2020-02-24 Mon 20:15]
* An ungleich account - can be registered for free on
https://account.ungleich.ch
* httpie installed (provides the http command)
## Get a membership
## Registering a payment method
To be able to pay for the membership, you will need to register a
credit card or apply for payment on bill (TO BE IMPLEMENTED).
### Register credit card
```
http POST https://api.ungleich.ch/membership \
username=nico password=yourpassword \
cc_number=.. \
cc_
```
### Request payment via bill
## Create the membership
```
http POST https://api.ungleich.ch/membership username=nico password=yourpassword
```
## List available products

View file

@ -0,0 +1,6 @@
* TODO register CC
* TODO list products
* ahmed
** schemas
*** field: is_valid? - used by schemas
*** definition of a "schema"

View file

@ -0,0 +1,4 @@
db.sqlite3
uncloud/secrets.py
debug.log
uncloud/local_settings.py

View file

@ -0,0 +1,325 @@
start_date,stop_date,territory_codes,currency_code,rate,rate_type,description
2011-01-04,,AI,XCD,0,standard,Anguilla (British overseas territory) is exempted of VAT.
1984-01-01,,AT,EUR,0.2,standard,Austria (member state) standard VAT rate.
1976-01-01,1984-01-01,AT,EUR,0.18,standard,
1973-01-01,1976-01-01,AT,EUR,0.16,standard,
1984-01-01,,"AT-6691
DE-87491",EUR,0.19,standard,Jungholz (Austrian town) special VAT rate.
1984-01-01,,"AT-6991
AT-6992
AT-6993
DE-87567
DE-87568
DE-87569",EUR,0.19,standard,Mittelberg (Austrian town) special VAT rate.
1996-01-01,,BE,EUR,0.21,standard,Belgium (member state) standard VAT rate.
1994-01-01,1996-01-01,BE,EUR,0.205,standard,
1992-04-01,1994-01-01,BE,EUR,0.195,standard,
1983-01-01,1992-04-01,BE,EUR,0.19,standard,
1981-07-01,1983-01-01,BE,EUR,0.17,standard,
1978-07-01,1981-07-01,BE,EUR,0.16,standard,
1971-07-01,1978-07-01,BE,EUR,0.18,standard,
1999-01-01,,BG,BGN,0.2,standard,Bulgaria (member state) standard VAT rate.
1996-07-01,1999-01-01,BG,BGN,0.22,standard,
1994-04-01,1996-07-01,BG,BGN,0.18,standard,
2011-01-04,,BM,BMD,0,standard,Bermuda (British overseas territory) is exempted of VAT.
2014-01-13,,"CY
GB-BFPO 57
GB-BFPO 58
GB-BFPO 59
UK-BFPO 57
UK-BFPO 58
UK-BFPO 59",EUR,0.19,standard,"Cyprus (member state) standard VAT rate.
Akrotiri and Dhekelia (British overseas territory) is subjected to Cyprus' standard VAT rate."
2013-01-14,2014-01-13,CY,EUR,0.18,standard,
2012-03-01,2013-01-14,CY,EUR,0.17,standard,
2003-01-01,2012-03-01,CY,EUR,0.15,standard,
2002-07-01,2003-01-01,CY,EUR,0.13,standard,
2000-07-01,2002-07-01,CY,EUR,0.1,standard,
1993-10-01,2000-07-01,CY,EUR,0.08,standard,
1992-07-01,1993-10-01,CY,EUR,0.05,standard,
2013-01-01,,CZ,CZK,0.21,standard,Czech Republic (member state) standard VAT rate.
2010-01-01,2013-01-01,CZ,CZK,0.2,standard,
2004-05-01,2010-01-01,CZ,CZK,0.19,standard,
1995-01-01,2004-05-01,CZ,CZK,0.22,standard,
1993-01-01,1995-01-01,CZ,CZK,0.23,standard,
2007-01-01,,DE,EUR,0.19,standard,Germany (member state) standard VAT rate.
1998-04-01,2007-01-01,DE,EUR,0.16,standard,
1993-01-01,1998-04-01,DE,EUR,0.15,standard,
1983-07-01,1993-01-01,DE,EUR,0.14,standard,
1979-07-01,1983-07-01,DE,EUR,0.13,standard,
1978-01-01,1979-07-01,DE,EUR,0.12,standard,
1968-07-01,1978-01-01,DE,EUR,0.11,standard,
1968-01-01,1968-07-01,DE,EUR,0.1,standard,
2007-01-01,,DE-27498,EUR,0,standard,Heligoland (German island) is exempted of VAT.
2007-01-01,,"DE-78266
CH-8238",EUR,0,standard,Busingen am Hochrhein (German territory) is exempted of VAT.
1992-01-01,,DK,DKK,0.25,standard,Denmark (member state) standard VAT rate.
1980-06-30,1992-01-01,DK,DKK,0.22,standard,
1978-10-30,1980-06-30,DK,DKK,0.2025,standard,
1977-10-03,1978-10-30,DK,DKK,0.18,standard,
1970-06-29,1977-10-03,DK,DKK,0.15,standard,
1968-04-01,1970-06-29,DK,DKK,0.125,standard,
1967-07-03,1968-04-01,DK,DKK,0.1,standard,
2009-07-01,,EE,EUR,0.2,standard,Estonia (member state) standard VAT rate.
1993-01-01,2009-07-01,EE,EUR,0.18,standard,
1991-01-01,1993-01-01,EE,EUR,0.1,standard,
2016-06-01,,"GR
EL",EUR,0.24,standard,Greece (member state) standard VAT rate.
2010-07-01,2016-06-01,"GR
EL",EUR,0.23,standard,
2010-03-15,2010-07-01,"GR
EL",EUR,0.21,standard,
2005-04-01,2010-03-15,"GR
EL",EUR,0.19,standard,
1990-04-28,2005-04-01,"GR
EL",EUR,0.18,standard,
1988-01-01,1990-04-28,"GR
EL",EUR,0.16,standard,
1987-01-01,1988-01-01,"GR
EL",EUR,0.18,standard,
2012-09-01,,ES,EUR,0.21,standard,Spain (member state) standard VAT rate.
2010-07-01,2012-09-01,ES,EUR,0.18,standard,
1995-01-01,2010-07-01,ES,EUR,0.16,standard,
1992-08-01,1995-01-01,ES,EUR,0.15,standard,
1992-01-01,1992-08-01,ES,EUR,0.13,standard,
1986-01-01,1992-01-01,ES,EUR,0.12,standard,
2012-09-01,,"ES-CN
ES-GC
ES-TF
IC",EUR,0,standard,Canary Islands (Spanish autonomous community) is exempted of VAT.
2012-09-01,,"ES-ML
ES-CE
EA",EUR,0,standard,Ceuta and Melilla (Spanish autonomous cities) is exempted of VAT.
2013-01-01,,FI,EUR,0.24,standard,Finland (member state) standard VAT rate.
2010-07-01,2013-01-01,FI,EUR,0.23,standard,
1994-06-01,2010-07-01,FI,EUR,0.22,standard,
2013-01-01,,"FI-01
AX",EUR,0,standard,Aland Islands (Finish autonomous region) is exempted of VAT.
2011-01-04,,FK,FKP,0,standard,Falkland Islands (British overseas territory) is exempted of VAT.
1992-01-01,,FO,DKK,0,standard,Faroe Islands (Danish autonomous country) is exempted of VAT.
2014-01-01,,"FR
MC",EUR,0.2,standard,"France (member state) standard VAT rate.
Monaco (sovereign city-state) is member of the EU VAT area and subjected to France's standard VAT rate."
2000-04-01,2014-01-01,"FR
MC",EUR,0.196,standard,
1995-08-01,2000-04-01,"FR
MC",EUR,0.206,standard,
1982-07-01,1995-08-01,"FR
MC",EUR,0.186,standard,
1977-01-01,1982-07-01,"FR
MC",EUR,0.176,standard,
1973-01-01,1977-01-01,"FR
MC",EUR,0.2,standard,
1970-01-01,1973-01-01,"FR
MC",EUR,0.23,standard,
1968-12-01,1970-01-01,"FR
MC",EUR,0.19,standard,
1968-01-01,1968-12-01,"FR
MC",EUR,0.1666,standard,
2014-01-01,,"FR-BL
BL",EUR,0,standard,Saint Barthelemy (French overseas collectivity) is exempted of VAT.
2014-01-01,,"FR-GF
GF",EUR,0,standard,Guiana (French overseas department) is exempted of VAT.
2014-01-01,,"FR-GP
GP",EUR,0.085,standard,Guadeloupe (French overseas department) special VAT rate.
2014-01-01,,"FR-MF
MF",EUR,0,standard,Saint Martin (French overseas collectivity) is subjected to France's standard VAT rate.
2014-01-01,,"FR-MQ
MQ",EUR,0.085,standard,Martinique (French overseas department) special VAT rate.
2014-01-01,,"FR-NC
NC",XPF,0,standard,New Caledonia (French special collectivity) is exempted of VAT.
2014-01-01,,"FR-PF
PF",XPF,0,standard,French Polynesia (French overseas collectivity) is exempted of VAT.
2014-01-01,,"FR-PM
PM",EUR,0,standard,Saint Pierre and Miquelon (French overseas collectivity) is exempted of VAT.
2014-01-01,,"FR-RE
RE",EUR,0.085,standard,Reunion (French overseas department) special VAT rate.
2014-01-01,,"FR-TF
TF",EUR,0,standard,French Southern and Antarctic Lands (French overseas territory) is exempted of VAT.
2014-01-01,,"FR-WF
WF",XPF,0,standard,Wallis and Futuna (French overseas collectivity) is exempted of VAT.
2014-01-01,,"FR-YT
YT",EUR,0,standard,Mayotte (French overseas department) is exempted of VAT.
2011-01-04,,GG,GBP,0,standard,Guernsey (British Crown dependency) is exempted of VAT.
2011-01-04,,GI,GIP,0,standard,Gibraltar (British overseas territory) is exempted of VAT.
1992-01-01,,GL,DKK,0,standard,Greenland (Danish autonomous country) is exempted of VAT.
2010-07-01,2016-06-01,"GR-34007
EL-34007",EUR,0.16,standard,Skyros (Greek island) special VAT rate.
2010-07-01,2016-06-01,"GR-37002
GR-37003
GR-37005
EL-37002
EL-37003
EL-37005",EUR,0.16,standard,Northern Sporades (Greek islands) special VAT rate.
2010-07-01,2016-06-01,"GR-64004
EL-64004",EUR,0.16,standard,Thasos (Greek island) special VAT rate.
2010-07-01,2016-06-01,"GR-68002
EL-68002",EUR,0.16,standard,Samothrace (Greek island) special VAT rate.
2010-07-01,,"GR-69
EL-69",EUR,0,standard,Mount Athos (Greek self-governed part) is exempted of VAT.
2010-07-01,2016-06-01,"GR-81
EL-81",EUR,0.16,standard,Dodecanese (Greek department) special VAT rate.
2010-07-01,2016-06-01,"GR-82
EL-82",EUR,0.16,standard,Cyclades (Greek department) special VAT rate.
2010-07-01,2016-06-01,"GR-83
EL-83",EUR,0.16,standard,Lesbos (Greek department) special VAT rate.
2010-07-01,2016-06-01,"GR-84
EL-84",EUR,0.16,standard,Samos (Greek department) special VAT rate.
2010-07-01,2016-06-01,"GR-85
EL-85",EUR,0.16,standard,Chios (Greek department) special VAT rate.
2011-01-04,,GS,GBP,0,standard,South Georgia and the South Sandwich Islands (British overseas territory) is exempted of VAT.
2012-03-01,,HR,HRK,0.25,standard,Croatia (member state) standard VAT rate.
2009-08-01,2012-03-01,HR,HRK,0.23,standard,
1998-08-01,2009-08-01,HR,HRK,0.22,standard,
2012-01-01,,HU,HUF,0.27,standard,Hungary (member state) standard VAT rate.
2009-07-01,2012-01-01,HU,HUF,0.25,standard,
2006-01-01,2009-07-01,HU,HUF,0.2,standard,
1988-01-01,2006-01-01,HU,HUF,0.25,standard,
2012-01-01,,IE,EUR,0.23,standard,Republic of Ireland (member state) standard VAT rate.
2010-01-01,2012-01-01,IE,EUR,0.21,standard,
2008-12-01,2010-01-01,IE,EUR,0.215,standard,
2002-03-01,2008-12-01,IE,EUR,0.21,standard,
2001-01-01,2002-03-01,IE,EUR,0.2,standard,
1991-03-01,2001-01-01,IE,EUR,0.21,standard,
1990-03-01,1991-03-01,IE,EUR,0.23,standard,
1986-03-01,1990-03-01,IE,EUR,0.25,standard,
1983-05-01,1986-03-01,IE,EUR,0.23,standard,
1983-03-01,1983-05-01,IE,EUR,0.35,standard,
1982-05-01,1983-03-01,IE,EUR,0.3,standard,
1980-05-01,1982-05-01,IE,EUR,0.25,standard,
1976-03-01,1980-05-01,IE,EUR,0.2,standard,
1973-09-03,1976-03-01,IE,EUR,0.195,standard,
1972-11-01,1973-09-03,IE,EUR,0.1637,standard,
2011-01-04,,IO,GBP,0,standard,British Indian Ocean Territory (British overseas territory) is exempted of VAT.
2013-10-01,,IT,EUR,0.22,standard,Italy (member state) standard VAT rate.
2011-09-17,2013-10-01,IT,EUR,0.21,standard,
1997-10-01,2011-09-17,IT,EUR,0.2,standard,
1988-08-01,1997-10-01,IT,EUR,0.19,standard,
1982-08-05,1988-08-01,IT,EUR,0.18,standard,
1981-01-01,1982-08-05,IT,EUR,0.15,standard,
1980-11-01,1981-01-01,IT,EUR,0.14,standard,
1980-07-03,1980-11-01,IT,EUR,0.15,standard,
1977-02-08,1980-07-03,IT,EUR,0.14,standard,
1973-01-01,1977-02-08,IT,EUR,0.12,standard,
2013-10-01,,"IT-22060
CH-6911",CHF,0,standard,Campione (Italian town) is exempted of VAT.
2013-10-01,,IT-23030,EUR,0,standard,Livigno (Italian town) is exempted of VAT.
2011-01-04,,JE,GBP,0,standard,Jersey (British Crown dependency) is exempted of VAT.
2011-01-04,,KY,KYD,0,standard,Cayman Islands (British overseas territory) is exempted of VAT.
2009-09-01,,LT,EUR,0.21,standard,Lithuania (member state) standard VAT rate.
2009-01-01,2009-09-01,LT,EUR,0.19,standard,
1994-05-01,2009-01-01,LT,EUR,0.18,standard,
2015-01-01,,LU,EUR,0.17,standard,Luxembourg (member state) standard VAT rate.
1992-01-01,2015-01-01,LU,EUR,0.15,standard,
1983-07-01,1992-01-01,LU,EUR,0.12,standard,
1971-01-01,1983-07-01,LU,EUR,0.1,standard,
1970-01-01,1971-01-01,LU,EUR,0.8,standard,
2012-07-01,,LV,EUR,0.21,standard,Latvia (member state) standard VAT rate.
2011-01-01,2012-07-01,LV,EUR,0.22,standard,
2009-01-01,2011-01-01,LV,EUR,0.21,standard,
1995-05-01,2009-01-01,LV,EUR,0.18,standard,
2011-01-04,,MS,XCD,0,standard,Montserrat (British overseas territory) is exempted of VAT.
2004-01-01,,MT,EUR,0.18,standard,Malta (member state) standard VAT rate.
1995-01-01,2004-01-01,MT,EUR,0.15,standard,
2012-10-01,,NL,EUR,0.21,standard,Netherlands (member state) standard VAT rate.
2001-01-01,2012-10-01,NL,EUR,0.19,standard,
1992-10-01,2001-01-01,NL,EUR,0.175,standard,
1989-01-01,1992-10-01,NL,EUR,0.185,standard,
1986-10-01,1989-01-01,NL,EUR,0.2,standard,
1984-01-01,1986-10-01,NL,EUR,0.19,standard,
1976-01-01,1984-01-01,NL,EUR,0.18,standard,
1973-01-01,1976-01-01,NL,EUR,0.16,standard,
1971-01-01,1973-01-01,NL,EUR,0.14,standard,
1969-01-01,1971-01-01,NL,EUR,0.12,standard,
2012-10-01,,"NL-AW
AW",AWG,0,standard,Aruba (Dutch country) are exempted of VAT.
2012-10-01,,"NL-CW
NL-SX
CW
SX",ANG,0,standard,Curacao and Sint Maarten (Dutch countries) are exempted of VAT.
2012-10-01,,"NL-BQ1
NL-BQ2
NL-BQ3
BQ
BQ-BO
BQ-SA
BQ-SE",USD,0,standard,"Bonaire, Saba and Sint Eustatius (Dutch special municipalities) are exempted of VAT."
2011-01-01,,PL,PLN,0.23,standard,Poland (member state) standard VAT rate.
1993-01-08,2011-01-01,PL,PLN,0.22,standard,
2011-01-04,,PN,NZD,0,standard,Pitcairn Islands (British overseas territory) is exempted of VAT.
2011-01-01,,PT,EUR,0.23,standard,Portugal (member state) standard VAT rate.
2010-07-01,2011-01-01,PT,EUR,0.21,standard,
2008-07-01,2010-07-01,PT,EUR,0.2,standard,
2005-07-01,2008-07-01,PT,EUR,0.21,standard,
2002-06-05,2005-07-01,PT,EUR,0.19,standard,
1995-01-01,2002-06-05,PT,EUR,0.17,standard,
1992-03-24,1995-01-01,PT,EUR,0.16,standard,
1988-02-01,1992-03-24,PT,EUR,0.17,standard,
1986-01-01,1988-02-01,PT,EUR,0.16,standard,
2011-01-01,,PT-20,EUR,0.18,standard,Azores (Portuguese autonomous region) special VAT rate.
2011-01-01,,PT-30,EUR,0.22,standard,Madeira (Portuguese autonomous region) special VAT rate.
2017-01-01,,RO,RON,0.19,standard,Romania (member state) standard VAT rate.
2016-01-01,2017-01-01,RO,RON,0.2,standard,Romania (member state) standard VAT rate.
2010-07-01,2016-01-01,RO,RON,0.24,standard,
2000-01-01,2010-07-01,RO,RON,0.19,standard,
1998-02-01,2000-01-01,RO,RON,0.22,standard,
1993-07-01,1998-02-01,RO,RON,0.18,standard,
1990-07-01,,SE,SEK,0.25,standard,Sweden (member state) standard VAT rate.
1983-01-01,1990-07-01,SE,SEK,0.2346,standard,
1981-11-16,1983-01-01,SE,SEK,0.2151,standard,
1980-09-08,1981-11-16,SE,SEK,0.2346,standard,
1977-06-01,1980-09-08,SE,SEK,0.2063,standard,
1971-01-01,1977-06-01,SE,SEK,0.1765,standard,
1969-01-01,1971-01-01,SE,SEK,0.1111,standard,
2011-01-04,,"AC
SH
SH-AC
SH-HL",SHP,0,standard,Ascension and Saint Helena (British overseas territory) is exempted of VAT.
2011-01-04,,"TA
SH-TA",GBP,0,standard,Tristan da Cunha (British oversea territory) is exempted of VAT.
2013-07-01,,SI,EUR,0.22,standard,Slovenia (member state) standard VAT rate.
2002-01-01,2013-07-01,SI,EUR,0.2,standard,
1999-07-01,2002-01-01,SI,EUR,0.19,standard,
2011-01-01,,SK,EUR,0.2,standard,Slovakia (member state) standard VAT rate.
2004-01-01,2011-01-01,SK,EUR,0.19,standard,
2003-01-01,2004-01-01,SK,EUR,0.2,standard,
1996-01-01,2003-01-01,SK,EUR,0.23,standard,
1993-08-01,1996-01-01,SK,EUR,0.25,standard,
1993-01-01,1993-08-01,SK,EUR,0.23,standard,
2011-01-04,,TC,USD,0,standard,Turks and Caicos Islands (British overseas territory) is exempted of VAT.
2011-01-04,,"GB
UK
IM",GBP,0.2,standard,"United Kingdom (member state) standard VAT rate.
Isle of Man (British self-governing dependency) is member of the EU VAT area and subjected to UK's standard VAT rate."
2010-01-01,2011-01-04,"GB
UK
IM",GBP,0.175,standard,
2008-12-01,2010-01-01,"GB
UK
IM",GBP,0.15,standard,
1991-04-01,2008-12-01,"GB
UK
IM",GBP,0.175,standard,
1979-06-18,1991-04-01,"GB
UK
IM",GBP,0.15,standard,
1974-07-29,1979-06-18,"GB
UK
IM",GBP,0.08,standard,
1973-04-01,1974-07-29,"GB
UK
IM",GBP,0.1,standard,
2011-01-04,,VG,USD,0,standard,British Virgin Islands (British overseas territory) is exempted of VAT.
2014-01-01,,CP,EUR,0,standard,Clipperton Island (French overseas possession) is exempted of VAT.
2019-11-15,,CH,CHF,0.077,standard,Switzerland standard VAT (added manually)
2019-11-15,,MC,EUR,0.196,standard,Monaco standard VAT (added manually)
2019-11-15,,FR,EUR,0.2,standard,France standard VAT (added manually)
2019-11-15,,GR,EUR,0.24,standard,Greece standard VAT (added manually)
2019-11-15,,GB,EUR,0.2,standard,UK standard VAT (added manually)
2019-12-17,,AD,EUR,0.045,standard,Andorra standard VAT (added manually)
2019-12-17,,TK,EUR,0.18,standard,Turkey standard VAT (added manually)
2019-12-17,,IS,EUR,0.24,standard,Iceland standard VAT (added manually)
2019-12-17,,FX,EUR,0.20,standard,France metropolitan standard VAT (added manually)
2020-01-04,,CY,EUR,0.19,standard,Cyprus standard VAT (added manually)
2019-01-04,,IL,EUR,0.23,standard,Ireland standard VAT (added manually)
2019-01-04,,LI,EUR,0.077,standard,Liechtenstein standard VAT (added manually)
1 start_date stop_date territory_codes currency_code rate rate_type description
2 2011-01-04 AI XCD 0 standard Anguilla (British overseas territory) is exempted of VAT.
3 1984-01-01 AT EUR 0.2 standard Austria (member state) standard VAT rate.
4 1976-01-01 1984-01-01 AT EUR 0.18 standard
5 1973-01-01 1976-01-01 AT EUR 0.16 standard
6 1984-01-01 AT-6691 DE-87491 EUR 0.19 standard Jungholz (Austrian town) special VAT rate.
7 1984-01-01 AT-6991 AT-6992 AT-6993 DE-87567 DE-87568 DE-87569 EUR 0.19 standard Mittelberg (Austrian town) special VAT rate.
8 1996-01-01 BE EUR 0.21 standard Belgium (member state) standard VAT rate.
9 1994-01-01 1996-01-01 BE EUR 0.205 standard
10 1992-04-01 1994-01-01 BE EUR 0.195 standard
11 1983-01-01 1992-04-01 BE EUR 0.19 standard
12 1981-07-01 1983-01-01 BE EUR 0.17 standard
13 1978-07-01 1981-07-01 BE EUR 0.16 standard
14 1971-07-01 1978-07-01 BE EUR 0.18 standard
15 1999-01-01 BG BGN 0.2 standard Bulgaria (member state) standard VAT rate.
16 1996-07-01 1999-01-01 BG BGN 0.22 standard
17 1994-04-01 1996-07-01 BG BGN 0.18 standard
18 2011-01-04 BM BMD 0 standard Bermuda (British overseas territory) is exempted of VAT.
19 2014-01-13 CY GB-BFPO 57 GB-BFPO 58 GB-BFPO 59 UK-BFPO 57 UK-BFPO 58 UK-BFPO 59 EUR 0.19 standard Cyprus (member state) standard VAT rate. Akrotiri and Dhekelia (British overseas territory) is subjected to Cyprus' standard VAT rate.
20 2013-01-14 2014-01-13 CY EUR 0.18 standard
21 2012-03-01 2013-01-14 CY EUR 0.17 standard
22 2003-01-01 2012-03-01 CY EUR 0.15 standard
23 2002-07-01 2003-01-01 CY EUR 0.13 standard
24 2000-07-01 2002-07-01 CY EUR 0.1 standard
25 1993-10-01 2000-07-01 CY EUR 0.08 standard
26 1992-07-01 1993-10-01 CY EUR 0.05 standard
27 2013-01-01 CZ CZK 0.21 standard Czech Republic (member state) standard VAT rate.
28 2010-01-01 2013-01-01 CZ CZK 0.2 standard
29 2004-05-01 2010-01-01 CZ CZK 0.19 standard
30 1995-01-01 2004-05-01 CZ CZK 0.22 standard
31 1993-01-01 1995-01-01 CZ CZK 0.23 standard
32 2007-01-01 DE EUR 0.19 standard Germany (member state) standard VAT rate.
33 1998-04-01 2007-01-01 DE EUR 0.16 standard
34 1993-01-01 1998-04-01 DE EUR 0.15 standard
35 1983-07-01 1993-01-01 DE EUR 0.14 standard
36 1979-07-01 1983-07-01 DE EUR 0.13 standard
37 1978-01-01 1979-07-01 DE EUR 0.12 standard
38 1968-07-01 1978-01-01 DE EUR 0.11 standard
39 1968-01-01 1968-07-01 DE EUR 0.1 standard
40 2007-01-01 DE-27498 EUR 0 standard Heligoland (German island) is exempted of VAT.
41 2007-01-01 DE-78266 CH-8238 EUR 0 standard Busingen am Hochrhein (German territory) is exempted of VAT.
42 1992-01-01 DK DKK 0.25 standard Denmark (member state) standard VAT rate.
43 1980-06-30 1992-01-01 DK DKK 0.22 standard
44 1978-10-30 1980-06-30 DK DKK 0.2025 standard
45 1977-10-03 1978-10-30 DK DKK 0.18 standard
46 1970-06-29 1977-10-03 DK DKK 0.15 standard
47 1968-04-01 1970-06-29 DK DKK 0.125 standard
48 1967-07-03 1968-04-01 DK DKK 0.1 standard
49 2009-07-01 EE EUR 0.2 standard Estonia (member state) standard VAT rate.
50 1993-01-01 2009-07-01 EE EUR 0.18 standard
51 1991-01-01 1993-01-01 EE EUR 0.1 standard
52 2016-06-01 GR EL EUR 0.24 standard Greece (member state) standard VAT rate.
53 2010-07-01 2016-06-01 GR EL EUR 0.23 standard
54 2010-03-15 2010-07-01 GR EL EUR 0.21 standard
55 2005-04-01 2010-03-15 GR EL EUR 0.19 standard
56 1990-04-28 2005-04-01 GR EL EUR 0.18 standard
57 1988-01-01 1990-04-28 GR EL EUR 0.16 standard
58 1987-01-01 1988-01-01 GR EL EUR 0.18 standard
59 2012-09-01 ES EUR 0.21 standard Spain (member state) standard VAT rate.
60 2010-07-01 2012-09-01 ES EUR 0.18 standard
61 1995-01-01 2010-07-01 ES EUR 0.16 standard
62 1992-08-01 1995-01-01 ES EUR 0.15 standard
63 1992-01-01 1992-08-01 ES EUR 0.13 standard
64 1986-01-01 1992-01-01 ES EUR 0.12 standard
65 2012-09-01 ES-CN ES-GC ES-TF IC EUR 0 standard Canary Islands (Spanish autonomous community) is exempted of VAT.
66 2012-09-01 ES-ML ES-CE EA EUR 0 standard Ceuta and Melilla (Spanish autonomous cities) is exempted of VAT.
67 2013-01-01 FI EUR 0.24 standard Finland (member state) standard VAT rate.
68 2010-07-01 2013-01-01 FI EUR 0.23 standard
69 1994-06-01 2010-07-01 FI EUR 0.22 standard
70 2013-01-01 FI-01 AX EUR 0 standard Aland Islands (Finish autonomous region) is exempted of VAT.
71 2011-01-04 FK FKP 0 standard Falkland Islands (British overseas territory) is exempted of VAT.
72 1992-01-01 FO DKK 0 standard Faroe Islands (Danish autonomous country) is exempted of VAT.
73 2014-01-01 FR MC EUR 0.2 standard France (member state) standard VAT rate. Monaco (sovereign city-state) is member of the EU VAT area and subjected to France's standard VAT rate.
74 2000-04-01 2014-01-01 FR MC EUR 0.196 standard
75 1995-08-01 2000-04-01 FR MC EUR 0.206 standard
76 1982-07-01 1995-08-01 FR MC EUR 0.186 standard
77 1977-01-01 1982-07-01 FR MC EUR 0.176 standard
78 1973-01-01 1977-01-01 FR MC EUR 0.2 standard
79 1970-01-01 1973-01-01 FR MC EUR 0.23 standard
80 1968-12-01 1970-01-01 FR MC EUR 0.19 standard
81 1968-01-01 1968-12-01 FR MC EUR 0.1666 standard
82 2014-01-01 FR-BL BL EUR 0 standard Saint Barthelemy (French overseas collectivity) is exempted of VAT.
83 2014-01-01 FR-GF GF EUR 0 standard Guiana (French overseas department) is exempted of VAT.
84 2014-01-01 FR-GP GP EUR 0.085 standard Guadeloupe (French overseas department) special VAT rate.
85 2014-01-01 FR-MF MF EUR 0 standard Saint Martin (French overseas collectivity) is subjected to France's standard VAT rate.
86 2014-01-01 FR-MQ MQ EUR 0.085 standard Martinique (French overseas department) special VAT rate.
87 2014-01-01 FR-NC NC XPF 0 standard New Caledonia (French special collectivity) is exempted of VAT.
88 2014-01-01 FR-PF PF XPF 0 standard French Polynesia (French overseas collectivity) is exempted of VAT.
89 2014-01-01 FR-PM PM EUR 0 standard Saint Pierre and Miquelon (French overseas collectivity) is exempted of VAT.
90 2014-01-01 FR-RE RE EUR 0.085 standard Reunion (French overseas department) special VAT rate.
91 2014-01-01 FR-TF TF EUR 0 standard French Southern and Antarctic Lands (French overseas territory) is exempted of VAT.
92 2014-01-01 FR-WF WF XPF 0 standard Wallis and Futuna (French overseas collectivity) is exempted of VAT.
93 2014-01-01 FR-YT YT EUR 0 standard Mayotte (French overseas department) is exempted of VAT.
94 2011-01-04 GG GBP 0 standard Guernsey (British Crown dependency) is exempted of VAT.
95 2011-01-04 GI GIP 0 standard Gibraltar (British overseas territory) is exempted of VAT.
96 1992-01-01 GL DKK 0 standard Greenland (Danish autonomous country) is exempted of VAT.
97 2010-07-01 2016-06-01 GR-34007 EL-34007 EUR 0.16 standard Skyros (Greek island) special VAT rate.
98 2010-07-01 2016-06-01 GR-37002 GR-37003 GR-37005 EL-37002 EL-37003 EL-37005 EUR 0.16 standard Northern Sporades (Greek islands) special VAT rate.
99 2010-07-01 2016-06-01 GR-64004 EL-64004 EUR 0.16 standard Thasos (Greek island) special VAT rate.
100 2010-07-01 2016-06-01 GR-68002 EL-68002 EUR 0.16 standard Samothrace (Greek island) special VAT rate.
101 2010-07-01 GR-69 EL-69 EUR 0 standard Mount Athos (Greek self-governed part) is exempted of VAT.
102 2010-07-01 2016-06-01 GR-81 EL-81 EUR 0.16 standard Dodecanese (Greek department) special VAT rate.
103 2010-07-01 2016-06-01 GR-82 EL-82 EUR 0.16 standard Cyclades (Greek department) special VAT rate.
104 2010-07-01 2016-06-01 GR-83 EL-83 EUR 0.16 standard Lesbos (Greek department) special VAT rate.
105 2010-07-01 2016-06-01 GR-84 EL-84 EUR 0.16 standard Samos (Greek department) special VAT rate.
106 2010-07-01 2016-06-01 GR-85 EL-85 EUR 0.16 standard Chios (Greek department) special VAT rate.
107 2011-01-04 GS GBP 0 standard South Georgia and the South Sandwich Islands (British overseas territory) is exempted of VAT.
108 2012-03-01 HR HRK 0.25 standard Croatia (member state) standard VAT rate.
109 2009-08-01 2012-03-01 HR HRK 0.23 standard
110 1998-08-01 2009-08-01 HR HRK 0.22 standard
111 2012-01-01 HU HUF 0.27 standard Hungary (member state) standard VAT rate.
112 2009-07-01 2012-01-01 HU HUF 0.25 standard
113 2006-01-01 2009-07-01 HU HUF 0.2 standard
114 1988-01-01 2006-01-01 HU HUF 0.25 standard
115 2012-01-01 IE EUR 0.23 standard Republic of Ireland (member state) standard VAT rate.
116 2010-01-01 2012-01-01 IE EUR 0.21 standard
117 2008-12-01 2010-01-01 IE EUR 0.215 standard
118 2002-03-01 2008-12-01 IE EUR 0.21 standard
119 2001-01-01 2002-03-01 IE EUR 0.2 standard
120 1991-03-01 2001-01-01 IE EUR 0.21 standard
121 1990-03-01 1991-03-01 IE EUR 0.23 standard
122 1986-03-01 1990-03-01 IE EUR 0.25 standard
123 1983-05-01 1986-03-01 IE EUR 0.23 standard
124 1983-03-01 1983-05-01 IE EUR 0.35 standard
125 1982-05-01 1983-03-01 IE EUR 0.3 standard
126 1980-05-01 1982-05-01 IE EUR 0.25 standard
127 1976-03-01 1980-05-01 IE EUR 0.2 standard
128 1973-09-03 1976-03-01 IE EUR 0.195 standard
129 1972-11-01 1973-09-03 IE EUR 0.1637 standard
130 2011-01-04 IO GBP 0 standard British Indian Ocean Territory (British overseas territory) is exempted of VAT.
131 2013-10-01 IT EUR 0.22 standard Italy (member state) standard VAT rate.
132 2011-09-17 2013-10-01 IT EUR 0.21 standard
133 1997-10-01 2011-09-17 IT EUR 0.2 standard
134 1988-08-01 1997-10-01 IT EUR 0.19 standard
135 1982-08-05 1988-08-01 IT EUR 0.18 standard
136 1981-01-01 1982-08-05 IT EUR 0.15 standard
137 1980-11-01 1981-01-01 IT EUR 0.14 standard
138 1980-07-03 1980-11-01 IT EUR 0.15 standard
139 1977-02-08 1980-07-03 IT EUR 0.14 standard
140 1973-01-01 1977-02-08 IT EUR 0.12 standard
141 2013-10-01 IT-22060 CH-6911 CHF 0 standard Campione (Italian town) is exempted of VAT.
142 2013-10-01 IT-23030 EUR 0 standard Livigno (Italian town) is exempted of VAT.
143 2011-01-04 JE GBP 0 standard Jersey (British Crown dependency) is exempted of VAT.
144 2011-01-04 KY KYD 0 standard Cayman Islands (British overseas territory) is exempted of VAT.
145 2009-09-01 LT EUR 0.21 standard Lithuania (member state) standard VAT rate.
146 2009-01-01 2009-09-01 LT EUR 0.19 standard
147 1994-05-01 2009-01-01 LT EUR 0.18 standard
148 2015-01-01 LU EUR 0.17 standard Luxembourg (member state) standard VAT rate.
149 1992-01-01 2015-01-01 LU EUR 0.15 standard
150 1983-07-01 1992-01-01 LU EUR 0.12 standard
151 1971-01-01 1983-07-01 LU EUR 0.1 standard
152 1970-01-01 1971-01-01 LU EUR 0.8 standard
153 2012-07-01 LV EUR 0.21 standard Latvia (member state) standard VAT rate.
154 2011-01-01 2012-07-01 LV EUR 0.22 standard
155 2009-01-01 2011-01-01 LV EUR 0.21 standard
156 1995-05-01 2009-01-01 LV EUR 0.18 standard
157 2011-01-04 MS XCD 0 standard Montserrat (British overseas territory) is exempted of VAT.
158 2004-01-01 MT EUR 0.18 standard Malta (member state) standard VAT rate.
159 1995-01-01 2004-01-01 MT EUR 0.15 standard
160 2012-10-01 NL EUR 0.21 standard Netherlands (member state) standard VAT rate.
161 2001-01-01 2012-10-01 NL EUR 0.19 standard
162 1992-10-01 2001-01-01 NL EUR 0.175 standard
163 1989-01-01 1992-10-01 NL EUR 0.185 standard
164 1986-10-01 1989-01-01 NL EUR 0.2 standard
165 1984-01-01 1986-10-01 NL EUR 0.19 standard
166 1976-01-01 1984-01-01 NL EUR 0.18 standard
167 1973-01-01 1976-01-01 NL EUR 0.16 standard
168 1971-01-01 1973-01-01 NL EUR 0.14 standard
169 1969-01-01 1971-01-01 NL EUR 0.12 standard
170 2012-10-01 NL-AW AW AWG 0 standard Aruba (Dutch country) are exempted of VAT.
171 2012-10-01 NL-CW NL-SX CW SX ANG 0 standard Curacao and Sint Maarten (Dutch countries) are exempted of VAT.
172 2012-10-01 NL-BQ1 NL-BQ2 NL-BQ3 BQ BQ-BO BQ-SA BQ-SE USD 0 standard Bonaire, Saba and Sint Eustatius (Dutch special municipalities) are exempted of VAT.
173 2011-01-01 PL PLN 0.23 standard Poland (member state) standard VAT rate.
174 1993-01-08 2011-01-01 PL PLN 0.22 standard
175 2011-01-04 PN NZD 0 standard Pitcairn Islands (British overseas territory) is exempted of VAT.
176 2011-01-01 PT EUR 0.23 standard Portugal (member state) standard VAT rate.
177 2010-07-01 2011-01-01 PT EUR 0.21 standard
178 2008-07-01 2010-07-01 PT EUR 0.2 standard
179 2005-07-01 2008-07-01 PT EUR 0.21 standard
180 2002-06-05 2005-07-01 PT EUR 0.19 standard
181 1995-01-01 2002-06-05 PT EUR 0.17 standard
182 1992-03-24 1995-01-01 PT EUR 0.16 standard
183 1988-02-01 1992-03-24 PT EUR 0.17 standard
184 1986-01-01 1988-02-01 PT EUR 0.16 standard
185 2011-01-01 PT-20 EUR 0.18 standard Azores (Portuguese autonomous region) special VAT rate.
186 2011-01-01 PT-30 EUR 0.22 standard Madeira (Portuguese autonomous region) special VAT rate.
187 2017-01-01 RO RON 0.19 standard Romania (member state) standard VAT rate.
188 2016-01-01 2017-01-01 RO RON 0.2 standard Romania (member state) standard VAT rate.
189 2010-07-01 2016-01-01 RO RON 0.24 standard
190 2000-01-01 2010-07-01 RO RON 0.19 standard
191 1998-02-01 2000-01-01 RO RON 0.22 standard
192 1993-07-01 1998-02-01 RO RON 0.18 standard
193 1990-07-01 SE SEK 0.25 standard Sweden (member state) standard VAT rate.
194 1983-01-01 1990-07-01 SE SEK 0.2346 standard
195 1981-11-16 1983-01-01 SE SEK 0.2151 standard
196 1980-09-08 1981-11-16 SE SEK 0.2346 standard
197 1977-06-01 1980-09-08 SE SEK 0.2063 standard
198 1971-01-01 1977-06-01 SE SEK 0.1765 standard
199 1969-01-01 1971-01-01 SE SEK 0.1111 standard
200 2011-01-04 AC SH SH-AC SH-HL SHP 0 standard Ascension and Saint Helena (British overseas territory) is exempted of VAT.
201 2011-01-04 TA SH-TA GBP 0 standard Tristan da Cunha (British oversea territory) is exempted of VAT.
202 2013-07-01 SI EUR 0.22 standard Slovenia (member state) standard VAT rate.
203 2002-01-01 2013-07-01 SI EUR 0.2 standard
204 1999-07-01 2002-01-01 SI EUR 0.19 standard
205 2011-01-01 SK EUR 0.2 standard Slovakia (member state) standard VAT rate.
206 2004-01-01 2011-01-01 SK EUR 0.19 standard
207 2003-01-01 2004-01-01 SK EUR 0.2 standard
208 1996-01-01 2003-01-01 SK EUR 0.23 standard
209 1993-08-01 1996-01-01 SK EUR 0.25 standard
210 1993-01-01 1993-08-01 SK EUR 0.23 standard
211 2011-01-04 TC USD 0 standard Turks and Caicos Islands (British overseas territory) is exempted of VAT.
212 2011-01-04 GB UK IM GBP 0.2 standard United Kingdom (member state) standard VAT rate. Isle of Man (British self-governing dependency) is member of the EU VAT area and subjected to UK's standard VAT rate.
213 2010-01-01 2011-01-04 GB UK IM GBP 0.175 standard
214 2008-12-01 2010-01-01 GB UK IM GBP 0.15 standard
215 1991-04-01 2008-12-01 GB UK IM GBP 0.175 standard
216 1979-06-18 1991-04-01 GB UK IM GBP 0.15 standard
217 1974-07-29 1979-06-18 GB UK IM GBP 0.08 standard
218 1973-04-01 1974-07-29 GB UK IM GBP 0.1 standard
219 2011-01-04 VG USD 0 standard British Virgin Islands (British overseas territory) is exempted of VAT.
220 2014-01-01 CP EUR 0 standard Clipperton Island (French overseas possession) is exempted of VAT.
221 2019-11-15 CH CHF 0.077 standard Switzerland standard VAT (added manually)
222 2019-11-15 MC EUR 0.196 standard Monaco standard VAT (added manually)
223 2019-11-15 FR EUR 0.2 standard France standard VAT (added manually)
224 2019-11-15 GR EUR 0.24 standard Greece standard VAT (added manually)
225 2019-11-15 GB EUR 0.2 standard UK standard VAT (added manually)
226 2019-12-17 AD EUR 0.045 standard Andorra standard VAT (added manually)
227 2019-12-17 TK EUR 0.18 standard Turkey standard VAT (added manually)
228 2019-12-17 IS EUR 0.24 standard Iceland standard VAT (added manually)
229 2019-12-17 FX EUR 0.20 standard France metropolitan standard VAT (added manually)
230 2020-01-04 CY EUR 0.19 standard Cyprus standard VAT (added manually)
231 2019-01-04 IL EUR 0.23 standard Ireland standard VAT (added manually)
232 2019-01-04 LI EUR 0.077 standard Liechtenstein standard VAT (added manually)