Skip to content

Commit

Permalink
Merge 2b9dcdc into 885d294
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinkaszynski committed Nov 6, 2018
2 parents 885d294 + 2b9dcdc commit a632e27
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 39 deletions.
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.7.1"
__version__ = "0.8.0"
__author__ = "Jacek Ostanski"
__license__ = "MIT"
__copyright__ = "Copyright 2017 Arabella"
Expand Down
2 changes: 1 addition & 1 deletion aa_stripe/management/commands/charge_stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def handle(self, *args, **options):
try:
c.charge()
sleep(0.25) # 4 requests per second tops
except Exception as e:
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
try:
if client.is_enabled():
Expand Down
2 changes: 1 addition & 1 deletion aa_stripe/management/commands/end_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def handle(self, *args, **options):
try:
subscription.cancel(at_period_end=True)
sleep(0.25) # 4 requests per second tops
except Exception as e:
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
try:
if client.is_enabled():
Expand Down
4 changes: 2 additions & 2 deletions aa_stripe/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import unicode_literals

import django.db.models.deletion
import jsonfield.fields
import django_extensions.db.fields.json
from django.conf import settings
from django.db import migrations, models

Expand Down Expand Up @@ -38,7 +38,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('content', jsonfield.fields.JSONField(default=dict)),
('content', django_extensions.db.fields.json.JSONField(default=dict)),
('customer_id', models.CharField(max_length=255)),
('is_active', models.BooleanField(default=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=USER_MODEL)),
Expand Down
20 changes: 10 additions & 10 deletions aa_stripe/migrations/0003_auto_20170608_1103.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import django.core.validators
import django.db.models.deletion
import jsonfield.fields
import django_extensions.db.fields.json
from django.conf import settings
from django.db import migrations, models

Expand All @@ -28,8 +28,8 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('stripe_response', jsonfield.fields.JSONField(default=dict)),
('stripe_js_response', jsonfield.fields.JSONField(default=dict)),
('stripe_response', django_extensions.db.fields.json.JSONField(default=dict)),
('stripe_js_response', django_extensions.db.fields.json.JSONField(default=dict)),
('stripe_customer_id', models.CharField(max_length=255)),
('is_active', models.BooleanField(default=True)),
('is_created_at_stripe', models.BooleanField(default=False)),
Expand All @@ -46,11 +46,11 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('stripe_response', jsonfield.fields.JSONField(default=dict)),
('stripe_response', django_extensions.db.fields.json.JSONField(default=dict)),
('stripe_subscription_id', models.CharField(blank=True, max_length=255)),
('is_created_at_stripe', models.BooleanField(default=False)),
('status', models.CharField(blank=True, choices=[('trialing', 'trialing'), ('active', 'active'), ('past_due', 'past_due'), ('canceled', 'canceled'), ('unpaid', 'unpaid')], help_text='https://stripe.com/docs/api/python#subscription_object-status, empty if not sent created at stripe', max_length=255)),
('metadata', jsonfield.fields.JSONField(default=dict, help_text='https://stripe.com/docs/api/python#create_subscription-metadata')),
('metadata', django_extensions.db.fields.json.JSONField(default=dict, help_text='https://stripe.com/docs/api/python#create_subscription-metadata')),
('tax_percent', models.DecimalField(decimal_places=2, default=0, help_text='https://stripe.com/docs/api/python#subscription_object-tax_percent', max_digits=3, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)])),
('application_fee_percent', models.DecimalField(decimal_places=2, default=0, help_text='https://stripe.com/docs/api/python#create_subscription-application_fee_percent', max_digits=3, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(100)])),
('coupon', models.CharField(blank=True, help_text='https://stripe.com/docs/api/python#create_subscription-coupon', max_length=255)),
Expand All @@ -66,15 +66,15 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('stripe_response', jsonfield.fields.JSONField(default=dict)),
('stripe_response', django_extensions.db.fields.json.JSONField(default=dict)),
('is_created_at_stripe', models.BooleanField(default=False)),
('source', jsonfield.fields.JSONField(blank=True, default=dict, help_text='Source of the plan, ie: {"prescription": 1}')),
('source', django_extensions.db.fields.json.JSONField(blank=True, default=dict, help_text='Source of the plan, ie: {"prescription": 1}')),
('amount', models.IntegerField(help_text='In cents. More: https://stripe.com/docs/api#create_plan-amount')),
('currency', models.CharField(default='USD', help_text='3 letter ISO code, default USD, , https://stripe.com/docs/api#create_plan-currency', max_length=3)),
('name', models.CharField(help_text='Name of the plan, to be displayed on invoices and in the web interface.', max_length=255)),
('interval', models.CharField(choices=[('day', 'day'), ('week', 'week'), ('month', 'month'), ('year', 'year')], help_text='Specifies billing frequency. Either day, week, month or year.', max_length=10)),
('interval_count', models.IntegerField(default=1, validators=[django.core.validators.MinValueValidator(1)])),
('metadata', jsonfield.fields.JSONField(default=dict, help_text='A set of key/value pairs that you can attach to a plan object. It can be useful for storing additional information about the plan in a structured format.')),
('metadata', django_extensions.db.fields.json.JSONField(default=dict, help_text='A set of key/value pairs that you can attach to a plan object. It can be useful for storing additional information about the plan in a structured format.')),
('statement_descriptor', models.CharField(blank=True, help_text='An arbitrary string to be displayed on your customer’s credit card statement.', max_length=22)),
('trial_period_days', models.IntegerField(default=0, help_text='Specifies a trial period in (an integer number of) days. If you include a trial period, the customer won’t be billed for the first time until the trial period ends. If the customer cancels before the trial period is over, she’ll never be billed at all.', validators=[django.core.validators.MinValueValidator(0)])),
],
Expand All @@ -89,7 +89,7 @@ class Migration(migrations.Migration):
('created', models.DateField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('is_parsed', models.BooleanField(default=False)),
('raw_data', jsonfield.fields.JSONField(default=dict)),
('raw_data', django_extensions.db.fields.json.JSONField(default=dict)),
],
),
migrations.RemoveField(
Expand All @@ -103,7 +103,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='stripecharge',
name='stripe_response',
field=jsonfield.fields.JSONField(default=dict),
field=django_extensions.db.fields.json.JSONField(default=dict),
),
migrations.DeleteModel(
name='StripeToken',
Expand Down
6 changes: 3 additions & 3 deletions aa_stripe/migrations/0010_auto_20170822_1004.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from decimal import Decimal

import django.db.models.deletion
import jsonfield.fields
import django_extensions.db.fields.json
import stripe
from django.db import migrations, models

Expand Down Expand Up @@ -54,15 +54,15 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('updated', models.DateTimeField(auto_now=True)),
('stripe_response', jsonfield.fields.JSONField(default=dict)),
('stripe_response', django_extensions.db.fields.json.JSONField(default=dict)),
('coupon_id', models.CharField(help_text='Identifier for the coupon', max_length=255)),
('amount_off', models.DecimalField(decimal_places=2, max_digits=10, blank=True, help_text='Amount (in the currency specified) that will be taken off the subtotal ofany invoices for this customer.', null=True)),
('currency', models.CharField(default='usd', max_length=3, null=True, blank=True, help_text='If amount_off has been set, the three-letter ISO code for the currency of the amount to take off.', choices=[('usd', 'USD'), ('aed', 'AED'), ('afn', 'AFN'), ('all', 'ALL'), ('amd', 'AMD'), ('ang', 'ANG'), ('aoa', 'AOA'), ('ars', 'ARS'), ('aud', 'AUD'), ('awg', 'AWG'), ('azn', 'AZN'), ('bam', 'BAM'), ('bbd', 'BBD'), ('bdt', 'BDT'), ('bgn', 'BGN'), ('bif', 'BIF'), ('bmd', 'BMD'), ('bnd', 'BND'), ('bob', 'BOB'), ('brl', 'BRL'), ('bsd', 'BSD'), ('bwp', 'BWP'), ('bzd', 'BZD'), ('cad', 'CAD'), ('cdf', 'CDF'), ('chf', 'CHF'), ('clp', 'CLP'), ('cny', 'CNY'), ('cop', 'COP'), ('crc', 'CRC'), ('cve', 'CVE'), ('czk', 'CZK'), ('djf', 'DJF'), ('dkk', 'DKK'), ('dop', 'DOP'), ('dzd', 'DZD'), ('egp', 'EGP'), ('etb', 'ETB'), ('eur', 'EUR'), ('fjd', 'FJD'), ('fkp', 'FKP'), ('gbp', 'GBP'), ('gel', 'GEL'), ('gip', 'GIP'), ('gmd', 'GMD'), ('gnf', 'GNF'), ('gtq', 'GTQ'), ('gyd', 'GYD'), ('hkd', 'HKD'), ('hnl', 'HNL'), ('hrk', 'HRK'), ('htg', 'HTG'), ('huf', 'HUF'), ('idr', 'IDR'), ('ils', 'ILS'), ('inr', 'INR'), ('isk', 'ISK'), ('jmd', 'JMD'), ('jpy', 'JPY'), ('kes', 'KES'), ('kgs', 'KGS'), ('khr', 'KHR'), ('kmf', 'KMF'), ('krw', 'KRW'), ('kyd', 'KYD'), ('kzt', 'KZT'), ('lak', 'LAK'), ('lbp', 'LBP'), ('lkr', 'LKR'), ('lrd', 'LRD'), ('lsl', 'LSL'), ('mad', 'MAD'), ('mdl', 'MDL'), ('mga', 'MGA'), ('mkd', 'MKD'), ('mmk', 'MMK'), ('mnt', 'MNT'), ('mop', 'MOP'), ('mro', 'MRO'), ('mur', 'MUR'), ('mvr', 'MVR'), ('mwk', 'MWK'), ('mxn', 'MXN'), ('myr', 'MYR'), ('mzn', 'MZN'), ('nad', 'NAD'), ('ngn', 'NGN'), ('nio', 'NIO'), ('nok', 'NOK'), ('npr', 'NPR'), ('nzd', 'NZD'), ('pab', 'PAB'), ('pen', 'PEN'), ('pgk', 'PGK'), ('php', 'PHP'), ('pkr', 'PKR'), ('pln', 'PLN'), ('pyg', 'PYG'), ('qar', 'QAR'), ('ron', 'RON'), ('rsd', 'RSD'), ('rub', 'RUB'), ('rwf', 'RWF'), ('sar', 'SAR'), ('sbd', 'SBD'), ('scr', 'SCR'), ('sek', 'SEK'), ('sgd', 'SGD'), ('shp', 'SHP'), ('sll', 'SLL'), ('sos', 'SOS'), ('srd', 'SRD'), ('std', 'STD'), ('svc', 'SVC'), ('szl', 'SZL'), ('thb', 'THB'), ('tjs', 'TJS'), ('top', 'TOP'), ('try', 'TRY'), ('ttd', 'TTD'), ('twd', 'TWD'), ('tzs', 'TZS'), ('uah', 'UAH'), ('ugx', 'UGX'), ('uyu', 'UYU'), ('uzs', 'UZS'), ('vnd', 'VND'), ('vuv', 'VUV'), ('wst', 'WST'), ('xaf', 'XAF'), ('xcd', 'XCD'), ('xof', 'XOF'), ('xpf', 'XPF'), ('yer', 'YER'), ('zar', 'ZAR'), ('zmw', 'ZMW')])),
('duration', models.CharField(choices=[('forever', 'forever'), ('once', 'once'), ('repeating', 'repeating')], help_text='Describes how long a customer who applies this coupon will get the discount.', max_length=255)),
('duration_in_months', models.PositiveIntegerField(blank=True, help_text='If duration is repeating, the number of months the coupon applies.Null if coupon duration is forever or once.', null=True)),
('livemode', models.BooleanField(default=False, help_text='Flag indicating whether the object exists in live mode or test mode.')),
('max_redemptions', models.PositiveIntegerField(blank=True, help_text='Maximum number of times this coupon can be redeemed, in total, before it is no longer valid.', null=True)),
('metadata', jsonfield.fields.JSONField(default=dict, help_text='Set of key/value pairs that you can attach to an object. It can be useful forstoring additional information about the object in a structured format.')),
('metadata', django_extensions.db.fields.json.JSONField(default=dict, help_text='Set of key/value pairs that you can attach to an object. It can be useful forstoring additional information about the object in a structured format.')),
('percent_off', models.PositiveIntegerField(blank=True, help_text='Percent that will be taken off the subtotal of any invoicesfor this customer for the duration ofthe coupon. For example, a coupon with percent_off of 50 will make a $100 invoice $50 instead.', null=True)),
('redeem_by', models.DateTimeField(blank=True, help_text='Date after which the coupon can no longer be redeemed.', null=True)),
('times_redeemed', models.PositiveIntegerField(default=0, help_text='Number of times this coupon has been applied to a customer.')),
Expand Down
4 changes: 2 additions & 2 deletions aa_stripe/migrations/0012_auto_20170908_1150.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Generated by Django 1.11.5 on 2017-09-08 15:50
from __future__ import unicode_literals

import jsonfield.fields
import django_extensions.db.fields.json
from django.db import migrations, models


Expand Down Expand Up @@ -35,7 +35,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='stripecoupon',
name='metadata',
field=jsonfield.fields.JSONField(default=dict, help_text='Set of key/value pairs that you can attach to an object. It can be useful for storing additional information about the object in a structured format.'),
field=django_extensions.db.fields.json.JSONField(default=dict, help_text='Set of key/value pairs that you can attach to an object. It can be useful for storing additional information about the object in a structured format.'),
),
migrations.AlterField(
model_name='stripecoupon',
Expand Down
4 changes: 2 additions & 2 deletions aa_stripe/migrations/0018_stripecustomer_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Generated by Django 1.11.13 on 2018-05-29 12:46
from __future__ import unicode_literals

import jsonfield.fields
import django_extensions.db.fields.json
from django.db import migrations


Expand All @@ -16,6 +16,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='stripecustomer',
name='sources',
field=jsonfield.fields.JSONField(default=[]),
field=django_extensions.db.fields.json.JSONField(default=[]),
),
]
23 changes: 13 additions & 10 deletions aa_stripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.db import models
from django.utils import dateformat, timezone
from django.utils.translation import ugettext_lazy as _
from jsonfield import JSONField
from django_extensions.db.fields.json import JSONField

from aa_stripe.exceptions import (StripeCouponAlreadyExists, StripeMethodNotAllowed, StripeWebhookAlreadyParsed,
StripeWebhookParseError)
Expand All @@ -36,19 +36,19 @@
class StripeBasicModel(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
stripe_response = JSONField()
stripe_response = JSONField(blank=True)

class Meta:
abstract = True


class StripeCustomer(StripeBasicModel):
user = models.ForeignKey(USER_MODEL, on_delete=models.CASCADE, related_name='stripe_customers')
stripe_js_response = JSONField()
stripe_js_response = JSONField(blank=True)
stripe_customer_id = models.CharField(max_length=255, db_index=True)
is_active = models.BooleanField(default=True)
is_created_at_stripe = models.BooleanField(default=False)
sources = JSONField(default=[])
sources = JSONField(blank=True, default=[])
default_source = models.CharField(max_length=255, blank=True, help_text="ID of default source from Stripe")

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -206,8 +206,9 @@ class StripeCoupon(StripeBasicModel):
max_redemptions = models.PositiveIntegerField(
blank=True, null=True,
help_text=_("Maximum number of times this coupon can be redeemed, in total, before it is no longer valid."))
metadata = JSONField(help_text=_("Set of key/value pairs that you can attach to an object. It can be useful for "
"storing additional information about the object in a structured format."))
metadata = JSONField(
blank=True, help_text=_("Set of key/value pairs that you can attach to an object. It can be useful for "
"storing additional information about the object in a structured format."))
percent_off = models.PositiveIntegerField(
blank=True, null=True,
help_text=_("Percent that will be taken off the subtotal of any invoicesfor this customer for the duration of "
Expand Down Expand Up @@ -423,8 +424,10 @@ class StripeSubscriptionPlan(StripeBasicModel):
max_length=10, help_text=_("Specifies billing frequency. Either day, week, month or year."),
choices=INTERVAL_CHOICES)
interval_count = models.IntegerField(default=1, validators=[MinValueValidator(1)])
metadata = JSONField(help_text=_("A set of key/value pairs that you can attach to a plan object. It can be useful"
" for storing additional information about the plan in a structured format."))
metadata = JSONField(
blank=True,
help_text=_("A set of key/value pairs that you can attach to a plan object. It can be useful"
" for storing additional information about the plan in a structured format."))
statement_descriptor = models.CharField(
max_length=22, help_text=_("An arbitrary string to be displayed on your customer’s credit card statement."),
blank=True)
Expand Down Expand Up @@ -484,7 +487,7 @@ class StripeSubscription(StripeBasicModel):
status = models.CharField(
max_length=255, help_text="https://stripe.com/docs/api/python#subscription_object-status, "
"empty if not sent created at stripe", blank=True, choices=STATUS_CHOICES)
metadata = JSONField(help_text="https://stripe.com/docs/api/python#create_subscription-metadata")
metadata = JSONField(blank=True, help_text="https://stripe.com/docs/api/python#create_subscription-metadata")
tax_percent = models.DecimalField(
default=0, validators=[MinValueValidator(0), MaxValueValidator(100)], decimal_places=2, max_digits=3,
help_text="https://stripe.com/docs/api/python#subscription_object-tax_percent")
Expand Down Expand Up @@ -571,7 +574,7 @@ class StripeWebhook(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
is_parsed = models.BooleanField(default=False)
raw_data = JSONField()
raw_data = JSONField(blank=True)
parse_error = models.TextField(blank=True)

def _parse_coupon_notification(self, action):
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
django-jsonfield>=1.0.1
django-extensions>=2.1.3
stripe>=1.49.0,<2.0.0
djangorestframework>=3.6.0
simplejson>=3.10.0
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-codestyle.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flake8>=3.2.1
pycodestyle>=2.2.0,<2.4.0
pycodestyle>=2.4.0
isort>=4.2.5

0 comments on commit a632e27

Please sign in to comment.