diff --git a/conf/general.yml-example b/conf/general.yml-example index ddb787f..120713d 100644 --- a/conf/general.yml-example +++ b/conf/general.yml-example @@ -56,6 +56,12 @@ STRIPE_TAX_RATE: '' BULK_LOOKUP_AMOUNT: 50 BULK_LOOKUP_PRICE_ID: 'price_123' +PRICING_TIER_1_ID: 'price_123' +PRICING_TIER_2_ID: 'price_456' +PRICING_TIER_3_ID: 'price_789' +PRICING_TIER_1_AMOUNT: '20' +PRICING_TIER_2_AMOUNT: '100' +PRICING_TIER_3_AMOUNT: '300' # Mapped to Django's DEBUG and TEMPLATE_DEBUG settings. Optional, defaults to True. DEBUG: True diff --git a/mapit_mysociety_org/management/commands/add_mapit_user.py b/mapit_mysociety_org/management/commands/add_mapit_user.py index d0ee52a..bf588a8 100644 --- a/mapit_mysociety_org/management/commands/add_mapit_user.py +++ b/mapit_mysociety_org/management/commands/add_mapit_user.py @@ -17,8 +17,8 @@ class Command(BaseCommand): help = "Create a new user with associated Stripe subscription" def add_arguments(self, parser): - prices = stripe.Price.list(limit=100) - price_ids = [price.id for price in prices.data if price.id.startswith('mapit')] + products = stripe.Product.list(limit=100) + price_ids = [p.name for p in products if p.name.startswith('MapIt')] coupons = stripe.Coupon.list() self.coupon_ids = [coupon['id'] for coupon in coupons if coupon['id'].startswith('charitable')] parser.add_argument('--email', required=True) @@ -31,6 +31,9 @@ def handle(self, *args, **options): coupon = options['coupon'] price = options['price'] + products = stripe.Product.list(limit=100, expand=['data.default_price']) + price = [p for p in products if p.name == price][0].default_price + if coupon not in self.coupon_ids: # coupon ID of the form charitableN(-Nmonths) m = re.match(r'charitable(\d+)(?:-(\d+)month)?', coupon) @@ -53,7 +56,11 @@ def handle(self, *args, **options): customer = stripe.Customer.create(email=email).id stripe_sub = stripe.Subscription.create( - customer=customer, items=[{"price": price}], coupon=coupon, trial_period_days=options['trial']).id + default_tax_rates=[settings.STRIPE_TAX_RATE], + customer=customer, + items=[{"price": price.id}], + coupon=coupon, + trial_period_days=options['trial']).id sub = Subscription.objects.create(user=user, stripe_id=stripe_sub) sub.redis_update_max(price) diff --git a/mapit_mysociety_org/settings.py b/mapit_mysociety_org/settings.py index ddde5ec..fdee44f 100644 --- a/mapit_mysociety_org/settings.py +++ b/mapit_mysociety_org/settings.py @@ -182,8 +182,15 @@ def allow_migrate(self, db, app_label, model_name=None, **hints): BULK_LOOKUP_PRICE_ID = config.get('BULK_LOOKUP_PRICE_ID') # API subscriptions -PRICING = [ - {'id': 'mapit-10k-v', 'price': 20, 'calls': '10,000'}, - {'id': 'mapit-100k-v', 'price': 100, 'calls': '100,000'}, - {'id': 'mapit-0k-v', 'price': 300, 'calls': '0'}, -] +if 'test' in sys.argv: + PRICING = [ + {'id': 'price_123', 'price': 20, 'calls': '10,000'}, + {'id': 'price_456', 'price': 100, 'calls': '100,000'}, + {'id': 'price_789', 'price': 300, 'calls': '0'}, + ] +else: + PRICING = [ + {'id': config.get('PRICING_TIER_1_ID'), 'price': config.get('PRICING_TIER_1_AMOUNT'), 'calls': '10,000'}, + {'id': config.get('PRICING_TIER_2_ID'), 'price': config.get('PRICING_TIER_2_AMOUNT'), 'calls': '100,000'}, + {'id': config.get('PRICING_TIER_3_ID'), 'price': config.get('PRICING_TIER_3_AMOUNT'), 'calls': '0'}, + ] diff --git a/mapit_mysociety_org/templates/account/_form_fields_signup.html b/mapit_mysociety_org/templates/account/_form_fields_signup.html index 0ae5356..d7f0175 100644 --- a/mapit_mysociety_org/templates/account/_form_fields_signup.html +++ b/mapit_mysociety_org/templates/account/_form_fields_signup.html @@ -11,7 +11,12 @@ {% include 'account/_form_field.html' with field=form.password_confirm %} {% endif %} -{% include 'account/_form_field.html' with field=form.plan %} + + +{% include 'account/_form_field.html' with field=form.price %} {% include 'account/_form_field_checkbox.html' with field=form.charitable_tick %}