Skip to content

Commit

Permalink
changing user model, prepared v 0.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoor committed Jun 30, 2017
1 parent 3af0958 commit fbfcc0e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.

## [0.2.8]
### Changed
- changed relation on stripe models from to settings.STRIPE_USER_MODEL, which defaults to settings.AUTH_USER_MODEL. There are cases that CC is connected to, in example, office, not person.
- changed description on stripe customer to use __str__ method of STRIPE_USER_MODEL

## [0.2.7]
### Fixed
- on_delete
Expand Down
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Installation
============
Add ``aa_stripe`` to your app's ``INSTALLED_APPS``, and also set ``STRIPE_API_KEY`` in project settings. After all please migrate the app (``./manage.py migrate aa_stripe``).
Add ``STRIPE_WEBHOOK_ENDPOINT_SECRET`` into your settings from stripe webhooks configuration to enable webhooks.
Add ``STRIPE_USER_MODEL`` if it is different than settings.AUTH_USER_MODEL. In example when CC is connected to office not person. ``STRIPE_USER_MODEL`` defaults to AUTH_USER_MODEL.

Add ``aa_stripe.api_urls`` into your url conf.


Usage
=====

Expand Down
2 changes: 1 addition & 1 deletion aa_stripe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
__title__ = "Arabella Stripe"
__version__ = "0.2.7"
__version__ = "0.2.8"
__author__ = "Jacek Ostanski"
__license__ = "MIT"
__copyright__ = "Copyright 2017 Arabella"
Expand Down
38 changes: 38 additions & 0 deletions aa_stripe/migrations/0007_auto_20170630_0557.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-06-30 09:57
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
from django.conf import settings


USER_MODEL = getattr(settings, "STRIPE_USER_MODEL", settings.AUTH_USER_MODEL)


class Migration(migrations.Migration):

dependencies = [
('aa_stripe', '0006_subscription_end_cancel'),
]

operations = [
migrations.AlterField(
model_name='stripecharge',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
related_name='stripe_charges', to=USER_MODEL),
),
migrations.AlterField(
model_name='stripecustomer',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stripe_customers',
to=USER_MODEL),
),
migrations.AlterField(
model_name='stripesubscription',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stripe_subscriptions',
to=USER_MODEL),
),
]
10 changes: 6 additions & 4 deletions aa_stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from aa_stripe.exceptions import StripeMethodNotAllowed

USER_MODEL = getattr(settings, "STRIPE_USER_MODEL", settings.AUTH_USER_MODEL)


class StripeBasicModel(models.Model):
created = models.DateField(auto_now_add=True)
Expand All @@ -23,7 +25,7 @@ class Meta:


class StripeCustomer(StripeBasicModel):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='stripe_customers')
user = models.ForeignKey(USER_MODEL, on_delete=models.CASCADE, related_name='stripe_customers')
stripe_js_response = JSONField()
stripe_customer_id = models.CharField(max_length=255, db_index=True)
is_active = models.BooleanField(default=True)
Expand All @@ -36,7 +38,7 @@ def create_at_stripe(self):
stripe.api_key = settings.STRIPE_API_KEY
customer = stripe.Customer.create(
source=self.stripe_js_response["id"],
description="{user.first_name} {user.last_name} id: {user.id}".format(user=self.user)
description="{user} id: {user.id}".format(user=self.user)
)
self.stripe_customer_id = customer["id"]
self.stripe_response = customer
Expand All @@ -55,7 +57,7 @@ class Meta:


class StripeCharge(StripeBasicModel):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='stripe_charges')
user = models.ForeignKey(USER_MODEL, on_delete=models.CASCADE, related_name='stripe_charges')
customer = models.ForeignKey(StripeCustomer, on_delete=models.SET_NULL, null=True)
amount = models.IntegerField(null=True, help_text=_("in cents"))
is_charged = models.BooleanField(default=False)
Expand Down Expand Up @@ -169,7 +171,7 @@ class StripeSubscription(StripeBasicModel):
stripe_subscription_id = models.CharField(max_length=255, blank=True, db_index=True)
is_created_at_stripe = models.BooleanField(default=False)
plan = models.ForeignKey(StripeSubscriptionPlan, on_delete=models.CASCADE)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="stripe_subscriptions")
user = models.ForeignKey(USER_MODEL, on_delete=models.CASCADE, related_name="stripe_subscriptions")
customer = models.ForeignKey(StripeCustomer, on_delete=models.SET_NULL, null=True)
status = models.CharField(
max_length=255, help_text="https://stripe.com/docs/api/python#subscription_object-status, "
Expand Down

0 comments on commit fbfcc0e

Please sign in to comment.