Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide bank account support #377

Open
wants to merge 2 commits into
base: original
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ coverage.xml

# MkDocs
site/

.python-version
28 changes: 28 additions & 0 deletions pinax/stripe/actions/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ def sync_card(customer, source):
return utils.update_with_defaults(card, defaults, created)


def sync_bank_account(customer, source):
"""
Syncronizes the data for a card locally for a given customer

Args:
customer: the customer to create or update a card for
source: data reprenting the card from the Stripe API
"""
defaults = dict(
customer=customer,
name=source["account_holder_name"] or "",
bank_name=source["bank_name"] or "",
routing_number=source['routing_number'],
account_holder_type=source['account_holder_type'] or "",
currency=source['currency'] or "",
country=source["country"] or "",
last4=source["last4"] or "",
fingerprint=source["fingerprint"] or ""
)
bank_account, created = models.BankAccount.objects.get_or_create(
stripe_id=source["id"],
defaults=defaults
)
return utils.update_with_defaults(bank_account, defaults, created)


def sync_bitcoin(customer, source):
"""
Syncronizes the data for a Bitcoin receiver locally for a given customer
Expand Down Expand Up @@ -116,6 +142,8 @@ def sync_payment_source_from_stripe_data(customer, source):
"""
if source["id"].startswith("card_"):
return sync_card(customer, source)
if source["id"].startswith("ba_"):
return sync_bank_account(customer, source)
else:
return sync_bitcoin(customer, source)

Expand Down
8 changes: 8 additions & 0 deletions pinax/stripe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Charge,
Subscription,
Card,
BankAccount,
BitcoinReceiver,
Customer,
Event,
Expand Down Expand Up @@ -189,6 +190,12 @@ class CardInline(admin.TabularInline):
max_num = 0


class BankAccountInline(admin.TabularInline):
model = BankAccount
extra = 0
max_num = 0


class BitcoinReceiverInline(admin.TabularInline):
model = BitcoinReceiver
extra = 0
Expand Down Expand Up @@ -224,6 +231,7 @@ def subscription_status(obj):
inlines=[
SubscriptionInline,
CardInline,
BankAccountInline,
BitcoinReceiverInline
]
)
Expand Down
38 changes: 38 additions & 0 deletions pinax/stripe/migrations/0010_bankaccount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-09-27 20:41
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('pinax_stripe', '0009_auto_20170825_1841'),
]

operations = [
migrations.CreateModel(
name='BankAccount',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('stripe_id', models.CharField(max_length=191, unique=True)),
('created_at', models.DateTimeField(default=django.utils.timezone.now)),
('name', models.TextField(blank=True)),
('country', models.CharField(blank=True, max_length=2)),
('bank_name', models.CharField(blank=True, max_length=200)),
('routing_number', models.CharField(max_length=35)),
('account_holder_type', models.CharField(blank=True, max_length=20)),
('currency', models.CharField(blank=True, max_length=4)),
('funding', models.CharField(max_length=15)),
('last4', models.CharField(blank=True, max_length=4)),
('fingerprint', models.TextField()),
('customer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pinax_stripe.Customer')),
],
options={
'abstract': False,
},
),
]
14 changes: 14 additions & 0 deletions pinax/stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ class Card(StripeObject):
fingerprint = models.TextField()


class BankAccount(StripeObject):

customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
name = models.TextField(blank=True)
country = models.CharField(max_length=2, blank=True)
bank_name = models.CharField(max_length=200, blank=True)
routing_number = models.CharField(max_length=35)
account_holder_type = models.CharField(max_length=20, blank=True)
currency = models.CharField(max_length=4, blank=True)
funding = models.CharField(max_length=15)
last4 = models.CharField(max_length=4, blank=True)
fingerprint = models.TextField()


class BitcoinReceiver(StripeObject):

customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
Expand Down