Exemple #1
0
def subscription_edit_create(request, plan_id=''):
    user = request.user
    stripe_errors = False
    error_message = _('Sorry, an error occurred while processing the '
                      'card. Your payment could not be processed.')
    action = request.GET.get('action', '')
    form = SubscriptionForm()
    if request.method == 'POST':
        form = SubscriptionForm(request.POST)
        if form.is_valid():
            subscription, stripe_errors, error_message = \
                form.stripe_edit_create_subscription(user, plan_id)
            if stripe_errors or not subscription:
                messages.error(request, error_message)
            else:
                if plan_id == '3':  # Premium
                    try:
                        #TODO: Add support for other backends in the form
                        engine = 'engines.gdb.backends.neo4j'
                        user = subscription.customer.user
                        instance = deploy(engine, request, user)
                        subscription.instance = instance
                        subscription.save()
                    except:
                        stripe_errors = True
                        # TODO: destroy the corrupt instance
                        subscription.customer.delete()
                        messages.error(request, error_message)
                if not stripe_errors:
                    try:
                        subscription.update_stripe_subscription()
                        return redirect('subscription_welcome')
                    except StripeSubscriptionException:
                        subscription.customer.delete()
                        messages.error(request, error_message)
    return render_to_response('payments/subscription_edit_create.html',
                              {'form': form,
                               'action': action,
                               'plan_name': settings.STRIPE_PLANS[plan_id]['name'],
                               'publishable': settings.STRIPE_PUBLISHABLE},
                              context_instance=RequestContext(request))
Exemple #2
0
def subscription_edit_create(request, plan_id=''):
    user = request.user
    stripe_errors = False
    error_message = _('Sorry, an error occurred while processing the '
                      'card. Your payment could not be processed.')
    action = request.GET.get('action', '')
    form = SubscriptionForm()
    if request.method == 'POST':
        form = SubscriptionForm(request.POST)
        if form.is_valid():
            subscription, stripe_errors, error_message = \
                form.stripe_edit_create_subscription(user, plan_id)
            if stripe_errors or not subscription:
                messages.error(request, error_message)
            else:
                if plan_id == '3':  # Premium
                    try:
                        #TODO: Add support for other backends in the form
                        engine = 'engines.gdb.backends.neo4j'
                        user = subscription.customer.user
                        instance = deploy(engine, request, user)
                        subscription.instance = instance
                        subscription.save()
                    except:
                        stripe_errors = True
                        # TODO: destroy the corrupt instance
                        subscription.customer.delete()
                        messages.error(request, error_message)
                if not stripe_errors:
                    try:
                        subscription.update_stripe_subscription()
                        return redirect('subscription_welcome')
                    except StripeSubscriptionException:
                        subscription.customer.delete()
                        messages.error(request, error_message)
    return render_to_response(
        'payments/subscription_edit_create.html', {
            'form': form,
            'action': action,
            'plan_name': settings.STRIPE_PLANS[plan_id]['name'],
            'publishable': settings.STRIPE_PUBLISHABLE
        },
        context_instance=RequestContext(request))
Exemple #3
0
def form_view(request, plan_slug = "", subscription_id = ""):
    subscription = None
    
    if plan_slug != "":
        plan = get_object_or_404(Plan, slug=plan_slug)
    else:
        subscription = Subscription.objects.get(id = int(subscription_id))
        plan = subscription.plan
    
    if request.method=="POST":
        form = SubscriptionForm(request.POST, instance = subscription or Subscription(plan = plan))
        form.request = request
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(SUCCESS_REDIRECT_URL)

    else:
        form = SubscriptionForm(instance = Subscription(plan = plan))

    return render_to_response('payments/subscription_form.html', {'form': form, 'plan': plan }, context_instance=RequestContext(request))