diff --git a/readthedocs/gold/forms.py b/readthedocs/gold/forms.py index 0e03009d605..8339e5d92f2 100644 --- a/readthedocs/gold/forms.py +++ b/readthedocs/gold/forms.py @@ -23,14 +23,14 @@ class GoldSubscriptionForm(StripeResourceMixin, StripeModelForm): class Meta(object): model = GoldUser - fields = ['last_4_digits', 'level'] + fields = ['last_4_card_digits', 'level'] - last_4_digits = forms.CharField( + last_4_card_digits = forms.CharField( required=True, min_length=4, max_length=4, widget=forms.HiddenInput(attrs={ - 'data-bind': 'valueInit: card_digits, value: card_digits' + 'data-bind': 'valueInit: last_4_card_digits, value: last_4_card_digits', }) ) @@ -73,10 +73,6 @@ def get_subscription(self): ) return subscription - def clear_card_data(self): - super(GoldSubscriptionForm, self).clear_card_data() - self.data['last_4_digits'] = None - class GoldProjectForm(forms.Form): project = forms.CharField( diff --git a/readthedocs/gold/migrations/0002_rename_last_4_digits.py b/readthedocs/gold/migrations/0002_rename_last_4_digits.py new file mode 100644 index 00000000000..2ed345fd3ce --- /dev/null +++ b/readthedocs/gold/migrations/0002_rename_last_4_digits.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2018-07-16 15:45 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('gold', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='golduser', + old_name='last_4_digits', + new_name='last_4_card_digits', + ), + ] diff --git a/readthedocs/gold/models.py b/readthedocs/gold/models.py index 27500e5fff7..c07aee2a92c 100644 --- a/readthedocs/gold/models.py +++ b/readthedocs/gold/models.py @@ -39,7 +39,7 @@ class GoldUser(models.Model): projects = models.ManyToManyField(Project, verbose_name=_('Projects'), related_name='gold_owners') - last_4_digits = models.CharField(max_length=4) + last_4_card_digits = models.CharField(max_length=4) stripe_id = models.CharField(max_length=255) subscribed = models.BooleanField(default=False) diff --git a/readthedocs/gold/static-src/gold/js/gold.js b/readthedocs/gold/static-src/gold/js/gold.js index 07b42608ee1..95e29018571 100644 --- a/readthedocs/gold/static-src/gold/js/gold.js +++ b/readthedocs/gold/static-src/gold/js/gold.js @@ -10,7 +10,7 @@ function GoldView(config) { self.constructor.call(self, config); - self.last_4_digits = ko.observable(null); + self.last_4_card_digits = ko.observable(null); } GoldView.prototype = new payment.PaymentView(); @@ -22,10 +22,4 @@ GoldView.init = function (config, obj) { return view; }; -GoldView.prototype.submit_form = function (card_digits, token) { - this.form.find('#id_last_4_digits').val(card_digits); - this.form.find('#id_stripe_token').val(token); - this.form.submit(); -}; - module.exports.GoldView = GoldView; diff --git a/readthedocs/gold/templates/gold/subscription_detail.html b/readthedocs/gold/templates/gold/subscription_detail.html index 2c675c95dd8..fe791753bfb 100644 --- a/readthedocs/gold/templates/gold/subscription_detail.html +++ b/readthedocs/gold/templates/gold/subscription_detail.html @@ -43,7 +43,7 @@

{% trans "Gold Subscription" %}

- ****-{{ golduser.last_4_digits }} + ****-{{ golduser.last_4_card_digits }}

diff --git a/readthedocs/gold/templates/gold/subscription_form.html b/readthedocs/gold/templates/gold/subscription_form.html index a4600df8476..9dc1ae592dc 100644 --- a/readthedocs/gold/templates/gold/subscription_form.html +++ b/readthedocs/gold/templates/gold/subscription_form.html @@ -103,12 +103,12 @@

{{ subscription_title }}

{% for field in form.fields_with_cc_group %} {% if field.is_cc_group %} diff --git a/readthedocs/gold/tests/test_forms.py b/readthedocs/gold/tests/test_forms.py index c2eb6aacf6e..4ea65403017 100644 --- a/readthedocs/gold/tests/test_forms.py +++ b/readthedocs/gold/tests/test_forms.py @@ -67,7 +67,7 @@ def test_add_subscription(self): # Create user and subscription subscription_form = GoldSubscriptionForm( {'level': 'v1-org-5', - 'last_4_digits': '0000', + 'last_4_card_digits': '0000', 'stripe_token': 'GARYBUSEY'}, customer=self.user ) @@ -132,7 +132,7 @@ def test_add_subscription_update_user(self): golduser = fixture.get(GoldUser, user=self.user, stripe_id='cus_12345') subscription_form = GoldSubscriptionForm( {'level': 'v1-org-5', - 'last_4_digits': '0000', + 'last_4_card_digits': '0000', 'stripe_token': 'GARYBUSEY'}, customer=self.user, instance=golduser @@ -198,7 +198,7 @@ def test_update_subscription_plan(self): ]) subscription_form = GoldSubscriptionForm( {'level': 'v1-org-5', - 'last_4_digits': '0000', + 'last_4_card_digits': '0000', 'stripe_token': 'GARYBUSEY'}, customer=self.user ) diff --git a/readthedocs/payments/static-src/payments/js/base.js b/readthedocs/payments/static-src/payments/js/base.js index 05c95f0fab4..411894d03eb 100644 --- a/readthedocs/payments/static-src/payments/js/base.js +++ b/readthedocs/payments/static-src/payments/js/base.js @@ -37,13 +37,13 @@ function PaymentView (config) { self.error_cc_cvv = ko.observable(null); self.stripe_token = ko.observable(null); - self.card_digits = ko.observable(null); + self.last_4_card_digits = ko.observable(null); // Form editing self.is_editing_card = ko.observable(false); self.show_card_form = ko.computed(function () { return (self.is_editing_card() || - !self.card_digits() || + !self.last_4_card_digits() || self.cc_number() || self.cc_expiry() || self.cc_cvv()); @@ -122,9 +122,15 @@ function PaymentView (config) { } -PaymentView.prototype.submit_form = function (card_digits, token) { - this.form.find('#id_card_digits').val(card_digits); +PaymentView.prototype.submit_form = function (last_4_card_digits, token) { + this.form.find('#id_last_4_card_digits').val(last_4_card_digits); this.form.find('#id_stripe_token').val(token); + + // Delete all user's card information before sending them to our servers + this.form.find('#id_cc_number').val(null); + this.form.find('#id_cc_expiry').val(null); + this.form.find('#id_cc_cvv').val(null); + this.form.submit(); };