# Path: ccvpn/common.py
# def get_price():
#     return config.MONTHLY_PRICE_EUR
# 
# Path: payments/models.py
# ACTIVE_BACKENDS = {}
# 
# SUBSCR_PERIOD_CHOICES = (
#     ('3m', _("Every 3 months")),
#     ('6m', _("Every 6 months")),
#     ('12m', _("Every year")),
# )
# 
# def period_months(p):
#     return {
#         '3m': 3,
#         '6m': 6,
#         '12m': 12,
#     }[p]


from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from ccvpn.common import get_price
from payments.models import ACTIVE_BACKENDS, SUBSCR_PERIOD_CHOICES, period_months


CURRENCY_CODE, CURRENCY_NAME = settings.PAYMENTS_CURRENCY


class Command(BaseCommand):
    help = "Update Stripe plans"

    def add_arguments(self, parser):
        parser.add_argument('--force-run', action='store_true',
                            help="Run even when Stripe backend is disabled")
        parser.add_argument('--force-update', action='store_true',
                            help="Replace plans, including matching ones")

    def handle(self, *args, **options):
        if 'stripe' not in ACTIVE_BACKENDS and options['force-run'] is False:
            raise CommandError("stripe backend not active.")

        backend = ACTIVE_BACKENDS['stripe']
        stripe = backend.stripe

        for period_id, period_name in SUBSCR_PERIOD_CHOICES:
            plan_id = backend.get_plan_id(period_id)
            months = period_months(period_id)

# Path: ccvpn/common.py
# def get_price():
#     return config.MONTHLY_PRICE_EUR
# 
# Path: payments/models.py
# ACTIVE_BACKENDS = {}
# 
# SUBSCR_PERIOD_CHOICES = (
#     ('3m', _("Every 3 months")),
#     ('6m', _("Every 6 months")),
#     ('12m', _("Every year")),
# )
# 
# def period_months(p):
#     return {
#         '3m': 3,
#         '6m': 6,
#         '12m': 12,
#     }[p]


# Path: payments/management/commands/update_stripe_plans.py
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from ccvpn.common import get_price
from payments.models import ACTIVE_BACKENDS, SUBSCR_PERIOD_CHOICES, period_months



CURRENCY_CODE, CURRENCY_NAME = settings.PAYMENTS_CURRENCY


class Command(BaseCommand):
    help = "Update Stripe plans"

    def add_arguments(self, parser):
        parser.add_argument('--force-run', action='store_true',
                            help="Run even when Stripe backend is disabled")
        parser.add_argument('--force-update', action='store_true',
                            help="Replace plans, including matching ones")

    def handle(self, *args, **options):
        if 'stripe' not in ACTIVE_BACKENDS and options['force-run'] is False:
            raise CommandError("stripe backend not active.")

        backend = ACTIVE_BACKENDS['stripe']
        stripe = backend.stripe

        for period_id, period_name in SUBSCR_PERIOD_CHOICES:
            plan_id = backend.get_plan_id(period_id)
            months = period_months(period_id)

            amount = months * get_price()