Skip to content

Commit 104c3a6

Browse files
authored
Merge pull request #4776 from rtfd/humitos/golduser/vat-field
Add VAT ID field for Gold User
2 parents 2662530 + adb9858 commit 104c3a6

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

readthedocs/gold/forms.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,20 @@ def validate_stripe(self):
5050
subscription = self.get_subscription()
5151
self.instance.stripe_id = subscription.customer
5252
self.instance.subscribed = True
53+
self.instance.business_vat_id = self.cleaned_data['business_vat_id']
5354

5455
def get_customer_kwargs(self):
55-
return {
56+
data = {
5657
'description': self.customer.get_full_name() or self.customer.username,
5758
'email': self.customer.email,
58-
'id': self.instance.stripe_id or None
59+
'id': self.instance.stripe_id or None,
5960
}
61+
business_vat_id = self.cleaned_data.get('business_vat_id')
62+
if business_vat_id:
63+
data.update({
64+
'business_vat_id': self.cleaned_data['business_vat_id'],
65+
})
66+
return data
6067

6168
def get_subscription(self):
6269
customer = self.get_customer()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.13 on 2018-10-22 07:13
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('gold', '0003_add_missing_model_change_migrations'),
12+
]
13+
14+
operations = [
15+
migrations.AddField(
16+
model_name='golduser',
17+
name='business_vat_id',
18+
field=models.CharField(blank=True, max_length=128, null=True),
19+
),
20+
]

readthedocs/gold/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class GoldUser(models.Model):
5959
last_4_card_digits = models.CharField(max_length=4)
6060
stripe_id = models.CharField(max_length=255)
6161
subscribed = models.BooleanField(default=False)
62+
business_vat_id = models.CharField(max_length=128, null=True, blank=True)
6263

6364
def __str__(self):
6465
return 'Gold Level %s for %s' % (self.level, self.user)

readthedocs/gold/tests/test_forms.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,27 @@ def test_add_subscription(self):
6565
])
6666

6767
# Create user and subscription
68-
subscription_form = GoldSubscriptionForm(
69-
{'level': 'v1-org-5',
70-
'last_4_card_digits': '0000',
71-
'stripe_token': 'GARYBUSEY'},
72-
customer=self.user
68+
subscription_form = GoldSubscriptionForm({
69+
'level': 'v1-org-5',
70+
'last_4_card_digits': '0000',
71+
'stripe_token': 'GARYBUSEY',
72+
'business_vat_id': 'business-vat-id',
73+
},
74+
customer=self.user,
7375
)
7476
self.assertTrue(subscription_form.is_valid())
7577
subscription = subscription_form.save()
7678

7779
self.assertEqual(subscription.level, 'v1-org-5')
7880
self.assertEqual(subscription.stripe_id, 'cus_12345')
81+
self.assertEqual(subscription.business_vat_id, 'business-vat-id')
7982
self.assertIsNotNone(self.user.gold)
8083
self.assertEqual(self.user.gold.first().level, 'v1-org-5')
8184

8285
self.mocks['request'].request.assert_has_calls([
8386
mock.call('post',
8487
'/v1/customers',
85-
{'description': mock.ANY, 'email': mock.ANY},
88+
{'description': mock.ANY, 'email': mock.ANY, 'business_vat_id': 'business-vat-id'},
8689
mock.ANY),
8790
mock.call('get',
8891
'/v1/customers/cus_12345/subscriptions',

readthedocs/payments/forms.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ class StripeModelForm(forms.ModelForm):
7171
:cvar cc_cvv: Credit card security code field, used only by Stripe.js
7272
"""
7373

74+
business_vat_id = forms.CharField(
75+
label=_('VAT ID number'),
76+
required=False,
77+
)
78+
7479
# Stripe token input from Stripe.js
7580
stripe_token = forms.CharField(
7681
required=False,

0 commit comments

Comments
 (0)