Ejemplo n.º 1
0
def plan_select(request, plan_id):
    product = LogicProducts().get_product(request, False)
    if product is None:
        return redirect('/pricing')
    current_plan = LogicContracts().get_current_plan(request, product)
    if current_plan is None and not product.is_active:
        product = None
    plans = LogicPlans().get_plans(product)

    # the customer has selected a plan
    if plan_id != 'current':
        # check if this is a valid plan
        new_plan = LogicPlans().get_plan(product, plan_id)
        if new_plan.cost_per_period > 0:
            return show_paymentmethod(request, product, current_plan, new_plan)
        else:
            return show_contract(request, product, current_plan, new_plan)

    # load booked plan from the database
    if current_plan:
        plan_id = current_plan.slug
    else:
        plan_id = ''

    return render(request, 'plan.html', {
        'product': product,
        'plans': plans,
        'selected_plan': plan_id
    })
Ejemplo n.º 2
0
def contract_subscribe(request, product_id, plan_id):
    customer = SaasCustomer.objects.filter(user=request.user).first()
    product = SaasProduct.objects.filter(slug=product_id).first()
    if not product:
        raise Exception('invalid product')
    plan = LogicPlans().get_plan(product, plan_id)
    if not plan:
        raise Exception('invalid plan')

    contract = LogicContracts().get_contract(customer, product)
    if contract and contract.is_confirmed:

        # update existing contract
        contract = LogicContracts().modify_contract(customer, product, plan)
        contract.save()

        # redirect to instance details page
        return redirect('/instance')

    else:
        # assign a new instance
        if LogicCustomers().assign_instance(customer, product, plan):
            # redirect to instance details page
            return redirect('/instance')
        else:
            # TODO what about the situation where there is no free instance available
            return render(
                request, 'error.html', {
                    'message':
                    _("Error: no instance available. Please try again tomorrow!"
                      )
                })
Ejemplo n.º 3
0
def subscribe(request, product_id, plan_id):
    logic = LogicCustomers()
    customer = SaasCustomer.objects.filter(user=request.user).first()
    product = SaasProduct.objects.filter(slug=product_id).first()
    if not product:
        raise Exception('invalid product')
    plan = LogicPlans().get_plan(product, plan_id)
    if not plan:
        raise Exception('invalid plan')

    if logic.has_contract(customer, product):
        # TODO upgrade or downgrade the plan?
        contract = logic.get_contract(customer, product)
        contract.plan = plan
        contract.save()

        # redirect to instance details page
        return redirect('/instance')

    else:
        # assign a new instance
        if logic.assign_instance(customer, product, plan):
            # redirect to instance details page
            return redirect('/instance')
        else:
            # TODO what about the situation where there is no free instance available
            return render(
                request, 'error.html', {
                    'message':
                    _("Error: no instance available. Please try again tomorrow!"
                      )
                })
Ejemplo n.º 4
0
def select_plan(request, plan_id):
    product = LogicProducts().get_product(request)
    current_plan = LogicContracts().get_current_plan(request, product)
    plans = LogicPlans().get_plans(product)

    # the customer has selected a plan
    if plan_id != 'current':
        # check if this is a valid plan
        new_plan = LogicPlans().get_plan(product, plan_id)
        return show_payment(request, product, current_plan, new_plan)

    # load booked plan from the database
    if current_plan:
        plan_id = current_plan.name
    else:
        plan_id = ''

    return render(request, 'plan.html', {
        'product': product,
        'plans': plans,
        'selected_plan': plan_id
    })
Ejemplo n.º 5
0
def display_pricing(request):
    product = LogicProducts().get_product(request)

    if product is None:
        products = LogicProducts().get_products()
        hostname = request.META['HTTP_HOST']
        if hostname.startswith("www."):
            hostname = hostname.replace('www.', '')
        return render(request, 'select_product.html', {
            'products': products,
            'hostname': hostname
        })

    plans = LogicPlans().get_plans(product)

    return render(request, 'pricing.html', {
        'product': product,
        'plans': plans
    })
Ejemplo n.º 6
0
def paymentmethod_select(request):
    product = LogicProducts().get_product(request, False)
    customer = SaasCustomer.objects.filter(user=request.user).first()

    if request.method == "POST":
        values = request.POST.copy()
        contract = LogicContracts().get_contract(customer, product)
        new_plan = LogicPlans().get_plan(product, values["plan"])
        if not contract:
            contract = LogicContracts().get_new_contract(
                customer, product, new_plan)

        contract.payment_method = values["payment_method"]
        contract.account_owner = values['account_owner']
        contract.account_iban = values['account_iban']
        if contract.payment_method == "SEPA_DIRECTDEBIT":
            if not contract.account_owner or not contract.account_iban:
                error = _("Please specify account owner and IBAN")
                return show_paymentmethod(request, product, None, None, error)

            contract.sepa_mandate_date = datetime.today()
            # TODO: something with prefixinstance_idyyyymmdd?
            contract.sepa_mandate = 'TODO'
        else:
            contract.sepa_mandate_date = None
            contract.sepa_mandate = ''
        contract.save()

        if not contract.is_confirmed or contract.plan.slug != new_plan.slug:
            return show_contract(request, product, contract.plan, new_plan)

        # confirm to user that storing worked
        return show_paymentmethod(request,
                                  product,
                                  contract.plan,
                                  None,
                                  successmessage=_("Changes Saved"))

    current_plan = LogicContracts().get_current_plan(request, product)
    if current_plan is None:
        return redirect('/plan/current')
    return show_paymentmethod(request, product, current_plan, None)