Skip to content

Commit

Permalink
add verification to view mixin, build identity field based on stripe …
Browse files Browse the repository at this point in the history
…fields_needed
  • Loading branch information
jdungan committed Aug 19, 2016
1 parent 80234e6 commit b875bff
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 49 deletions.
2 changes: 1 addition & 1 deletion payments/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class StripeAccountAdmin(admin.ModelAdmin):

readonly_fields = (
'user', 'account_id', 'secret_key', 'public_key',
'available_balance', 'verification'
'available_balance'
)


Expand Down
10 changes: 9 additions & 1 deletion payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ class StripeAccount(models.Model):
verification = models.TextField(default='', blank=True)

def identity_verified(self):
if not self.verification:
return True
else:
verification = json.loads(self.verification)
return not verification['due_by']

@property
def fields_needed(self):
verification = json.loads(self.verification)
return not verification.due_by
return verification['fields_needed']

def new_managed_account(self, bank_account):
stripe_account = stripe.Account.create(
Expand Down
86 changes: 50 additions & 36 deletions payments/templates/verify_identity.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,63 @@
We'll try to keep this to a minimum and do not save this information in our database.
</p>
<fieldset class="fieldset">
<legend>.</legend>
<form
role="form"
class="form-horizontal"
action="/payments/identity"
method="POST">
{% csrf_token %}

<label for="first_name">First Name</label>
<input name="first_name" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.first_name}}"/>
<label for="last_name">Last Name</label>
<input name="last_name" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.last_name}}"/>
<label for="address_line1">Street</label>
<input name="address_line1" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.street}}"/>
<label for="address_city">City</label>
<input name="address_city" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.city}}"/>
<label for="address_state">State</label>
<input name="address_state" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.state}}"/>
<label for="address_postal_code">ZIP</label>
<input name="address_postal_code" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.zip}}"/>

<fieldset >
<legend>Birthdate</legend>
<label for="dob_month">Month</label>
<input name="dob_month" type="text" class="form-control" autocomplete="off" maxlength="2" value="{{ STRIPE_DEBUG.identity.dob_month}}"/>
<label for="dob_day">Day</label>
<input name="dob_day" type="text" class="form-control" autocomplete="off" maxlength="2" value="{{ STRIPE_DEBUG.identity.dob_day}}"/>
<label for="dob_year">Year</label>
<input name="dob_year" type="text" class="form-control" autocomplete="off" maxlength="4" value="{{ STRIPE_DEBUG.identity.dob_year}}"/>
</fieldset>
<label for="ssn_last_4">Last four SSN digits</label>
<input name="ssn_last_4" type="text" class="form-control" autocomplete="off" maxlength="4" value="{{ STRIPE_DEBUG.identity.ssn_last_4}}"/>
<label for="personal_id_number">SSN</label>
<input name="personal_id_number" type="text" class="form-control" autocomplete="off" maxlength="4" value="{{ STRIPE_DEBUG.identity.ssn_full}}"/>


<fieldset >
<legend>Account Type</legend>
<label for="indiv">Individual</label>
<input name="type" type="radio" data-stripe="account_holder_type" value="individual" id="indiv" required checked="checked">
<label for="company">Company</label>
<input name="type" type="radio" data-stripe="account_holder_type" value="company" id="company">
</fieldset>
{% if 'legal_entity.first_name' in fields_needed %}
<label for="first_name">First Name</label>
<input name="first_name" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.first_name}}"/>
{% endif %}
{% if 'legal_entity.last_name' in fields_needed %}
<label for="last_name">Last Name</label>
<input name="last_name" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.last_name}}"/>
{% endif %}
{% if 'legal_entity.address.line1' in fields_needed %}
<label for="address_line1">Street</label>
<input name="address_line1" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.street}}"/>
{% endif %}
{% if 'legal_entity.address.city' in fields_needed %}
<label for="address_city">City</label>
<input name="address_city" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.city}}"/>
<label for="address_state">State</label>
<input name="address_state" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.state}}"/>
{% endif %}
{% if 'legal_entity.address.postal_code' in fields_needed %}
<label for="address_postal_code">ZIP</label>
<input name="address_postal_code" type="text" class="form-control" autocomplete="off" maxlength="16" value="{{ STRIPE_DEBUG.identity.zip}}"/>
{% endif %}
{% if 'legal_entity.dob.day' in fields_needed %}
<fieldset >
<legend>Birthdate</legend>
<label for="dob_month">Month</label>
<input name="dob_month" type="text" class="form-control" autocomplete="off" maxlength="2" value="{{ STRIPE_DEBUG.identity.dob_month}}"/>
<label for="dob_day">Day</label>
<input name="dob_day" type="text" class="form-control" autocomplete="off" maxlength="2" value="{{ STRIPE_DEBUG.identity.dob_day}}"/>
<label for="dob_year">Year</label>
<input name="dob_year" type="text" class="form-control" autocomplete="off" maxlength="4" value="{{ STRIPE_DEBUG.identity.dob_year}}"/>
</fieldset>
{% endif %}
{% if 'legal_entity.personal_id_number' in fields_needed %}
<label for="personal_id_number">SSN</label>
<input name="personal_id_number" type="text" class="form-control" autocomplete="off" maxlength="4" value="{{ STRIPE_DEBUG.identity.ssn_full}}"/>
{% endif %}
{% if 'legal_entity.ssn_last_4' in fields_needed %}
<label for="ssn_last_4">Last four SSN digits</label>
<input name="ssn_last_4" type="text" class="form-control" autocomplete="off" maxlength="4" value="{{ STRIPE_DEBUG.identity.ssn_last_4}}"/>
{% endif %}
{% if 'legal_entity.type' in fields_needed %}
<fieldset >
<legend>Account Type</legend>
<label for="indiv">Individual</label>
<input name="type" type="radio" data-stripe="account_holder_type" value="individual" id="indiv" required checked="checked">
<label for="company">Company</label>
<input name="type" type="radio" data-stripe="account_holder_type" value="company" id="company">
</fieldset>
{% endif %}

<button
class="button success track-btn"
Expand Down
21 changes: 10 additions & 11 deletions payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,21 @@ def dispatch(self, *args, **kwargs):
return super(CSRFExemptMixin, self).dispatch(*args, **kwargs)


class UserIdentityVerifiedMixin(UserPassesTestMixin):
login_url = reverse_lazy('identity')
class UserHasAcceptedTermsMixin(UserPassesTestMixin):
login_url = reverse_lazy('terms')
redirect_field_name = None

def test_func(self):
user_account = self.request.user.account()
if not user_account:
self.login_url = reverse_lazy('bank')
return False
return user_account.identity_verified()
return self.request.user.accepted_terms()


class UserHasAcceptedTermsMixin(UserPassesTestMixin):
login_url = reverse_lazy('terms')
class UserIdentityVerifiedMixin(UserHasAcceptedTermsMixin):
login_url = reverse_lazy('identity')
redirect_field_name = None

def test_func(self):
return self.request.user.accepted_terms()
user_account = self.request.user.account()
return user_account.identity_verified()


class CreditCardView(TemplateView):
Expand All @@ -82,7 +79,7 @@ def get_context_data(self, **kwargs):
return ctx


class BankAccountView(UserHasAcceptedTermsMixin, TemplateView):
class BankAccountView(UserIdentityVerifiedMixin, TemplateView):
template_name = 'bank_account_page.html'

def get_context_data(self, **kwargs):
Expand Down Expand Up @@ -111,6 +108,8 @@ class VerifyIdentityView(TemplateView):
def get_context_data(self, **kwargs):
ctx = super(VerifyIdentityView, self).get_context_data(**kwargs)
ctx['STRIPE_DEBUG'] = stripe_debug_values()
codesy_account = self.request.user.account()
ctx['fields_needed'] = codesy_account.fields_needed
return ctx

def post(self, *args, **kwargs):
Expand Down

0 comments on commit b875bff

Please sign in to comment.