Skip to content

Commit c32d612

Browse files
humitosagjohnson
authored andcommitted
Clean CC sensible data on Gold subscriptions (#4291)
* Clean CC sensible data on Gold subscriptions `PaymentView.submit_form` function removes all CC sensible data. This function is used for `GoldView` in this repo and also for `DonateView` in -ext repo. Since the behavior is shared across them, it's better to modify the parent's function and remove the override from the children. * Standardize `card_digits` and `last_4_digits` Use `last_4_card_digits` to avoid confusion and express exactly what it contains. * Rename auto named migration
1 parent 8b7c279 commit c32d612

File tree

8 files changed

+41
-25
lines changed

8 files changed

+41
-25
lines changed

readthedocs/gold/forms.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class GoldSubscriptionForm(StripeResourceMixin, StripeModelForm):
2323

2424
class Meta(object):
2525
model = GoldUser
26-
fields = ['last_4_digits', 'level']
26+
fields = ['last_4_card_digits', 'level']
2727

28-
last_4_digits = forms.CharField(
28+
last_4_card_digits = forms.CharField(
2929
required=True,
3030
min_length=4,
3131
max_length=4,
3232
widget=forms.HiddenInput(attrs={
33-
'data-bind': 'valueInit: card_digits, value: card_digits'
33+
'data-bind': 'valueInit: last_4_card_digits, value: last_4_card_digits',
3434
})
3535
)
3636

@@ -73,10 +73,6 @@ def get_subscription(self):
7373
)
7474
return subscription
7575

76-
def clear_card_data(self):
77-
super(GoldSubscriptionForm, self).clear_card_data()
78-
self.data['last_4_digits'] = None
79-
8076

8177
class GoldProjectForm(forms.Form):
8278
project = forms.CharField(
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-07-16 15:45
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', '0001_initial'),
12+
]
13+
14+
operations = [
15+
migrations.RenameField(
16+
model_name='golduser',
17+
old_name='last_4_digits',
18+
new_name='last_4_card_digits',
19+
),
20+
]

readthedocs/gold/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GoldUser(models.Model):
3939
projects = models.ManyToManyField(Project, verbose_name=_('Projects'),
4040
related_name='gold_owners')
4141

42-
last_4_digits = models.CharField(max_length=4)
42+
last_4_card_digits = models.CharField(max_length=4)
4343
stripe_id = models.CharField(max_length=255)
4444
subscribed = models.BooleanField(default=False)
4545

readthedocs/gold/static-src/gold/js/gold.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function GoldView(config) {
1010

1111
self.constructor.call(self, config);
1212

13-
self.last_4_digits = ko.observable(null);
13+
self.last_4_card_digits = ko.observable(null);
1414
}
1515

1616
GoldView.prototype = new payment.PaymentView();
@@ -22,10 +22,4 @@ GoldView.init = function (config, obj) {
2222
return view;
2323
};
2424

25-
GoldView.prototype.submit_form = function (card_digits, token) {
26-
this.form.find('#id_last_4_digits').val(card_digits);
27-
this.form.find('#id_stripe_token').val(token);
28-
this.form.submit();
29-
};
30-
3125
module.exports.GoldView = GoldView;

readthedocs/gold/templates/gold/subscription_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h2>{% trans "Gold Subscription" %}</h2>
4343

4444
<p class="subscription-detail subscription-detail-card">
4545
<label>{% trans "Card" %}:</label>
46-
<span>****-{{ golduser.last_4_digits }}</span>
46+
<span>****-{{ golduser.last_4_card_digits }}</span>
4747
</p>
4848

4949
<form method="get" action="{% url "gold_subscription" %}" class="subscription-update">

readthedocs/gold/templates/gold/subscription_form.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ <h3>{{ subscription_title }}</h3>
103103
{% for field in form.fields_with_cc_group %}
104104
{% if field.is_cc_group %}
105105
<p
106-
data-bind="visible: card_digits"
106+
data-bind="visible: last_4_card_digits"
107107
style="display: none;"
108108
class="subscription-card">
109109
<label>{% trans "Current card" %}:</label>
110110
<span class="subscription-card-number">
111-
****-<span data-bind="text: card_digits"></span>
111+
****-<span data-bind="text: last_4_card_digits"></span>
112112
</span>
113113
</p>
114114

readthedocs/gold/tests/test_forms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_add_subscription(self):
6767
# Create user and subscription
6868
subscription_form = GoldSubscriptionForm(
6969
{'level': 'v1-org-5',
70-
'last_4_digits': '0000',
70+
'last_4_card_digits': '0000',
7171
'stripe_token': 'GARYBUSEY'},
7272
customer=self.user
7373
)
@@ -132,7 +132,7 @@ def test_add_subscription_update_user(self):
132132
golduser = fixture.get(GoldUser, user=self.user, stripe_id='cus_12345')
133133
subscription_form = GoldSubscriptionForm(
134134
{'level': 'v1-org-5',
135-
'last_4_digits': '0000',
135+
'last_4_card_digits': '0000',
136136
'stripe_token': 'GARYBUSEY'},
137137
customer=self.user,
138138
instance=golduser
@@ -198,7 +198,7 @@ def test_update_subscription_plan(self):
198198
])
199199
subscription_form = GoldSubscriptionForm(
200200
{'level': 'v1-org-5',
201-
'last_4_digits': '0000',
201+
'last_4_card_digits': '0000',
202202
'stripe_token': 'GARYBUSEY'},
203203
customer=self.user
204204
)

readthedocs/payments/static-src/payments/js/base.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ function PaymentView (config) {
3737
self.error_cc_cvv = ko.observable(null);
3838

3939
self.stripe_token = ko.observable(null);
40-
self.card_digits = ko.observable(null);
40+
self.last_4_card_digits = ko.observable(null);
4141

4242
// Form editing
4343
self.is_editing_card = ko.observable(false);
4444
self.show_card_form = ko.computed(function () {
4545
return (self.is_editing_card() ||
46-
!self.card_digits() ||
46+
!self.last_4_card_digits() ||
4747
self.cc_number() ||
4848
self.cc_expiry() ||
4949
self.cc_cvv());
@@ -122,9 +122,15 @@ function PaymentView (config) {
122122

123123
}
124124

125-
PaymentView.prototype.submit_form = function (card_digits, token) {
126-
this.form.find('#id_card_digits').val(card_digits);
125+
PaymentView.prototype.submit_form = function (last_4_card_digits, token) {
126+
this.form.find('#id_last_4_card_digits').val(last_4_card_digits);
127127
this.form.find('#id_stripe_token').val(token);
128+
129+
// Delete all user's card information before sending them to our servers
130+
this.form.find('#id_cc_number').val(null);
131+
this.form.find('#id_cc_expiry').val(null);
132+
this.form.find('#id_cc_cvv').val(null);
133+
128134
this.form.submit();
129135
};
130136

0 commit comments

Comments
 (0)