Skip to content

Commit

Permalink
Merge pull request #4776 from rtfd/humitos/golduser/vat-field
Browse files Browse the repository at this point in the history
Add VAT ID field for Gold User
  • Loading branch information
humitos authored Nov 1, 2018
2 parents 2662530 + adb9858 commit 104c3a6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
11 changes: 9 additions & 2 deletions readthedocs/gold/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions readthedocs/gold/migrations/0004_add_vat_id.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
1 change: 1 addition & 0 deletions readthedocs/gold/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions readthedocs/gold/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions readthedocs/payments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 104c3a6

Please sign in to comment.