Skip to content

Commit

Permalink
Merge branch 'master' into plan-per-account-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed authored Nov 24, 2017
2 parents 9830d54 + 5da7818 commit 4378af8
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 72 deletions.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pages:
- Settings & Configuration: user-guide/settings.md
- Software as a Service: user-guide/saas.md
- eCommerce: user-guide/ecommerce.md
- Stripe Connect: user-guide/connect.md
- Upgrading from DSP: user-guide/upgrading.md
- Reference:
- Actions: reference/actions.md
Expand Down
18 changes: 9 additions & 9 deletions pinax/stripe/actions/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ def sync_account_from_stripe_data(data, user=None):
"business_name", "business_url", "charges_enabled", "country",
"default_currency", "details_submitted", "display_name",
"email", "type", "statement_descriptor", "support_email",
"support_phone", "timezone", "transfers_enabled"
"support_phone", "timezone", "payouts_enabled"
)

custom_attrs = (
"debit_negative_balances", "metadata", "product_description",
"transfer_statement_descriptor"
"payout_statement_descriptor"
)

if data["type"] == "custom":
top_level_attrs = common_attrs + custom_attrs
else:
top_level_attrs = common_attrs

for a in top_level_attrs:
setattr(obj, a, data.get(a))
for a in [x for x in top_level_attrs if x in data]:
setattr(obj, a, data[a])

# that's all we get for standard and express accounts!
if data["type"] != "custom":
Expand Down Expand Up @@ -188,11 +188,11 @@ def sync_account_from_stripe_data(data, user=None):
obj.decline_charge_on_cvc_failure = data["decline_charge_on"]["cvc_failure"]

# transfer schedule to external account
ts = data["transfer_schedule"]
obj.transfer_schedule_interval = ts["interval"]
obj.transfer_schedule_delay_days = ts.get("delay_days")
obj.transfer_schedule_weekly_anchor = ts.get("weekly_anchor")
obj.transfer_schedule_monthly_anchor = ts.get("monthly_anchor")
ps = data["payout_schedule"]
obj.payout_schedule_interval = ps["interval"]
obj.payout_schedule_delay_days = ps.get("delay_days")
obj.payout_schedule_weekly_anchor = ps.get("weekly_anchor")
obj.payout_schedule_monthly_anchor = ps.get("monthly_anchor")

# verification status, key to progressing account setup
obj.verification_disabled_reason = data["verification"]["disabled_reason"]
Expand Down
7 changes: 6 additions & 1 deletion pinax/stripe/actions/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def cancel(subscription, at_period_end=True):
subscription: the subscription to cancel
at_period_end: True to cancel at the end of the period, otherwise cancels immediately
"""
sub = subscription.stripe_subscription.delete(at_period_end=at_period_end)
sub = stripe.Subscription(
subscription.stripe_id,
stripe_account=subscription.stripe_account_stripe_id,
).delete(
at_period_end=at_period_end,
)
return sync_subscription_from_stripe_data(subscription.customer, sub)


Expand Down
47 changes: 24 additions & 23 deletions pinax/stripe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,9 @@ def subscription_status(obj):
subscription_status.short_description = "Subscription Status" # noqa


admin.site.register(
Customer,
admin_class=ModelAdmin,
raw_id_fields=["user", "stripe_account"],
list_display=[
class CustomerAdmin(ModelAdmin):
raw_id_fields = ["user", "stripe_account"]
list_display = [
"stripe_id",
"user",
"account_balance",
Expand All @@ -252,23 +250,21 @@ def subscription_status(obj):
subscription_status,
"date_purged",
"stripe_account",
],
list_filter=[
]
list_filter = [
"delinquent",
CustomerHasCardListFilter,
CustomerSubscriptionStatusListFilter,
AccountListFilter,
],
search_fields=[
]
search_fields = [
"stripe_id",
"=stripe_account__stripe_id"
] + user_search_fields(),
inlines=[
] + user_search_fields()
inlines = [
SubscriptionInline,
CardInline,
BitcoinReceiverInline
]
)


class InvoiceItemInline(admin.TabularInline):
Expand Down Expand Up @@ -432,21 +428,22 @@ class TransferChargeFeeInline(admin.TabularInline):
)


admin.site.register(
Account,
raw_id_fields=["user"],
list_display=[
class AccountAdmin(ModelAdmin):
raw_id_fields = ["user"]
list_display = [
"display_name",
"stripe_id",
"type",
"country",
"transfers_enabled",
"charges_enabled"
],
search_fields=[
"payouts_enabled",
"charges_enabled",
"stripe_id",
"created_at",
]
)
search_fields = [
"display_name",
"stripe_id",
],


admin.site.register(
BankAccount,
Expand Down Expand Up @@ -476,3 +473,7 @@ class TransferChargeFeeInline(admin.TabularInline):
"=user__email",
]
)


admin.site.register(Account, AccountAdmin)
admin.site.register(Customer, CustomerAdmin)
57 changes: 57 additions & 0 deletions pinax/stripe/migrations/0011_auto_20171123_2016.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-11-23 20:16
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pinax_stripe', '0010_connect'),
]

operations = [
migrations.RenameField(
model_name='account',
old_name='transfer_schedule_weekly_anchor',
new_name='payout_schedule_weekly_anchor',
),
migrations.RenameField(
model_name='account',
old_name='transfer_statement_descriptor',
new_name='payout_statement_descriptor',
),
migrations.RenameField(
model_name='account',
old_name='transfers_enabled',
new_name='payouts_enabled',
),
migrations.RemoveField(
model_name='account',
name='transfer_schedule_delay_days',
),
migrations.RemoveField(
model_name='account',
name='transfer_schedule_interval',
),
migrations.RemoveField(
model_name='account',
name='transfer_schedule_monthly_anchor',
),
migrations.AddField(
model_name='account',
name='payout_schedule_delay_days',
field=models.PositiveSmallIntegerField(blank=True, null=True),
),
migrations.AddField(
model_name='account',
name='payout_schedule_interval',
field=models.CharField(blank=True, choices=[('Manual', 'manual'), ('Daily', 'daily'), ('Weekly', 'weekly'), ('Monthly', 'monthly')], max_length=7, null=True),
),
migrations.AddField(
model_name='account',
name='payout_schedule_monthly_anchor',
field=models.PositiveSmallIntegerField(blank=True, null=True),
),
]
26 changes: 18 additions & 8 deletions pinax/stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ class Card(StripeObject):
last4 = models.CharField(max_length=4, blank=True)
fingerprint = models.TextField()

def __repr__(self):
return "Card(pk={!r}, customer={!r})".format(
self.pk,
getattr(self, "customer", None),
)


class BitcoinReceiver(StripeObject):

Expand Down Expand Up @@ -511,6 +517,12 @@ def card(self):
@python_2_unicode_compatible
class Account(StripeObject):

INTERVAL_CHOICES = (
("Manual", "manual"),
("Daily", "daily"),
("Weekly", "weekly"),
("Monthly", "monthly"),
)
user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, on_delete=models.CASCADE, related_name="stripe_accounts")

business_name = models.TextField(blank=True, null=True)
Expand Down Expand Up @@ -564,14 +576,12 @@ class Account(StripeObject):
tos_acceptance_ip = models.TextField(null=True, blank=True)
tos_acceptance_user_agent = models.TextField(null=True, blank=True)

transfer_schedule_delay_days = models.PositiveSmallIntegerField(null=True)
transfer_schedule_interval = models.TextField(null=True, blank=True)

transfer_schedule_monthly_anchor = models.PositiveSmallIntegerField(null=True)
transfer_schedule_weekly_anchor = models.TextField(null=True, blank=True)

transfer_statement_descriptor = models.TextField(null=True, blank=True)
transfers_enabled = models.BooleanField(default=False)
payout_schedule_delay_days = models.PositiveSmallIntegerField(null=True, blank=True)
payout_schedule_interval = models.CharField(max_length=7, choices=INTERVAL_CHOICES, null=True, blank=True)
payout_schedule_monthly_anchor = models.PositiveSmallIntegerField(null=True, blank=True)
payout_schedule_weekly_anchor = models.TextField(null=True, blank=True)
payout_statement_descriptor = models.TextField(null=True, blank=True)
payouts_enabled = models.BooleanField(default=False)

verification_disabled_reason = models.TextField(null=True, blank=True)
verification_due_by = models.DateTimeField(null=True, blank=True)
Expand Down
Loading

0 comments on commit 4378af8

Please sign in to comment.