diff --git a/readthedocs/gold/forms.py b/readthedocs/gold/forms.py index 6fc3d205ea8..4f8bf079093 100644 --- a/readthedocs/gold/forms.py +++ b/readthedocs/gold/forms.py @@ -50,13 +50,20 @@ def validate_stripe(self): subscription = self.get_subscription() self.instance.stripe_id = subscription.customer self.instance.subscribed = True + self.instance.business_vat_id = self.cleaned_data['business_vat_id'] def get_customer_kwargs(self): - return { + data = { 'description': self.customer.get_full_name() or self.customer.username, 'email': self.customer.email, - 'id': self.instance.stripe_id or None + 'id': self.instance.stripe_id or None, } + business_vat_id = self.cleaned_data.get('business_vat_id') + if business_vat_id: + data.update({ + 'business_vat_id': self.cleaned_data['business_vat_id'], + }) + return data def get_subscription(self): customer = self.get_customer() diff --git a/readthedocs/gold/migrations/0004_add_vat_id.py b/readthedocs/gold/migrations/0004_add_vat_id.py new file mode 100644 index 00000000000..eab1771f1a2 --- /dev/null +++ b/readthedocs/gold/migrations/0004_add_vat_id.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2018-10-22 07:13 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gold', '0003_add_missing_model_change_migrations'), + ] + + operations = [ + migrations.AddField( + model_name='golduser', + name='business_vat_id', + field=models.CharField(blank=True, max_length=128, null=True), + ), + ] diff --git a/readthedocs/gold/models.py b/readthedocs/gold/models.py index cca5c6cdf5c..b87e0f72345 100644 --- a/readthedocs/gold/models.py +++ b/readthedocs/gold/models.py @@ -59,6 +59,7 @@ class GoldUser(models.Model): last_4_card_digits = models.CharField(max_length=4) stripe_id = models.CharField(max_length=255) subscribed = models.BooleanField(default=False) + business_vat_id = models.CharField(max_length=128, null=True, blank=True) def __str__(self): return 'Gold Level %s for %s' % (self.level, self.user) diff --git a/readthedocs/gold/tests/test_forms.py b/readthedocs/gold/tests/test_forms.py index 4ea65403017..4618b8870fc 100644 --- a/readthedocs/gold/tests/test_forms.py +++ b/readthedocs/gold/tests/test_forms.py @@ -65,24 +65,27 @@ def test_add_subscription(self): ]) # Create user and subscription - subscription_form = GoldSubscriptionForm( - {'level': 'v1-org-5', - 'last_4_card_digits': '0000', - 'stripe_token': 'GARYBUSEY'}, - customer=self.user + subscription_form = GoldSubscriptionForm({ + 'level': 'v1-org-5', + 'last_4_card_digits': '0000', + 'stripe_token': 'GARYBUSEY', + 'business_vat_id': 'business-vat-id', + }, + customer=self.user, ) self.assertTrue(subscription_form.is_valid()) subscription = subscription_form.save() self.assertEqual(subscription.level, 'v1-org-5') self.assertEqual(subscription.stripe_id, 'cus_12345') + self.assertEqual(subscription.business_vat_id, 'business-vat-id') self.assertIsNotNone(self.user.gold) self.assertEqual(self.user.gold.first().level, 'v1-org-5') self.mocks['request'].request.assert_has_calls([ mock.call('post', '/v1/customers', - {'description': mock.ANY, 'email': mock.ANY}, + {'description': mock.ANY, 'email': mock.ANY, 'business_vat_id': 'business-vat-id'}, mock.ANY), mock.call('get', '/v1/customers/cus_12345/subscriptions', diff --git a/readthedocs/payments/forms.py b/readthedocs/payments/forms.py index 983dfe638f4..19796b2e809 100644 --- a/readthedocs/payments/forms.py +++ b/readthedocs/payments/forms.py @@ -71,6 +71,11 @@ class StripeModelForm(forms.ModelForm): :cvar cc_cvv: Credit card security code field, used only by Stripe.js """ + business_vat_id = forms.CharField( + label=_('VAT ID number'), + required=False, + ) + # Stripe token input from Stripe.js stripe_token = forms.CharField( required=False,