Ejemplo n.º 1
0
 def apply_discount_code(self):
     discount_code = request.form['discount_code']
     discount_code = InvoicingManager.get_discount_code(discount_code)
     if discount_code:
         if discount_code.is_active:
             if InvoicingManager.get_discount_code_used_count(
                     discount_code.id) >= discount_code.tickets_number:
                 return jsonify({
                     'status': 'error',
                     'message': 'Expired discount code'
                 })
             return jsonify({
                 'status': 'ok',
                 'discount_code': discount_code.serialize
             })
         else:
             return jsonify({
                 'status': 'error',
                 'message': 'Expired discount code'
             })
     else:
         return jsonify({
             'status': 'error',
             'message': 'Invalid discount code'
         })
def paypal_callback(invoice_identifier, function):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice or invoice.status == 'expired':
        abort(404)
    if function == 'cancel':
        invoice.status = 'cancelled'
        save_to_db(invoice)
        return redirect(
            url_for('event_detail.display_event_detail_home',
                    identifier=invoice.event.identifier))
    elif function == 'success':
        status, result = InvoicingManager.charge_paypal_invoice_payment(
            invoice)
        if status:
            return redirect(
                url_for('.view_invoice',
                        invoice_identifier=invoice_identifier))
        else:
            flash(
                "An error occurred while processing your transaction. " +
                str(result), "danger")
            return redirect(
                url_for('.show_transaction_error',
                        invoice_identifier=invoice_identifier))
    abort(404)
Ejemplo n.º 3
0
def fees_status_view():
    from_date = request.args.get('from_date')
    to_date = request.args.get('to_date')

    if ('from_date' in request.args and not from_date) or ('to_date' in request.args and not to_date) or \
        ('from_date' in request.args and 'to_date' not in request.args) or \
        ('to_date' in request.args and 'from_date' not in request.args):
        return redirect(url_for('.fees_status_view'))

    if from_date and to_date:
        invoices = InvoicingManager.get_invoices(
            from_date=datetime.strptime(from_date, '%d/%m/%Y'),
            to_date=datetime.strptime(to_date, '%d/%m/%Y'),
        )
    else:
        invoices = InvoicingManager.get_invoices()

    return render_template('gentelella/super_admin/sales/fees_status.html',
                           display_currency=display_currency,
                           from_date=from_date,
                           current_date=datetime.now(),
                           overdue_date=datetime.now() + timedelta(days=15),
                           invoices=invoices,
                           to_date=to_date,
                           navigation_bar=list_navbar())
Ejemplo n.º 4
0
def discount_codes_edit(discount_code_id=None):
    if not InvoicingManager.get_discount_code(discount_code_id):
        abort(404)
    if request.method == 'POST':
        InvoicingManager.create_edit_discount_code(request.form, discount_code_id)
        flash("The discount code has been edited.", "success")
        return redirect(url_for('.discount_codes_view'))
    return discount_codes_create(discount_code_id)
Ejemplo n.º 5
0
 def discount_codes_edit(self, discount_code_id=None):
     if not InvoicingManager.get_discount_code(discount_code_id):
         abort(404)
     if request.method == 'POST':
         InvoicingManager.create_edit_discount_code(request.form, discount_code_id)
         flash("The discount code has been edited.", "success")
         return redirect(url_for('.discount_codes_view'))
     return self.discount_codes_create(discount_code_id)
Ejemplo n.º 6
0
def apply_discount_code():
    discount_code = request.form['discount_code']
    discount_code = InvoicingManager.get_discount_code(discount_code)
    if discount_code:
        if discount_code.is_active:
            if InvoicingManager.get_discount_code_used_count(discount_code.id) >= discount_code.tickets_number:
                return jsonify({'status': 'error', 'message': 'Expired discount code'})
            return jsonify({'status': 'ok', 'discount_code': discount_code.serialize})
        else:
            return jsonify({'status': 'error', 'message': 'Expired discount code'})
    else:
        return jsonify({'status': 'error', 'message': 'Invalid discount code'})
 def discount_codes_delete(self, discount_code_id=None):
     discount_code = InvoicingManager.get_discount_code(discount_code_id)
     if not discount_code:
         abort(404)
     delete_from_db(discount_code, "Discount code deleted")
     flash("The discount code has been deleted.", "warning")
     return redirect(url_for('.discount_codes_view'))
Ejemplo n.º 8
0
def discount_codes_delete(discount_code_id=None):
    discount_code = InvoicingManager.get_discount_code(discount_code_id)
    if not discount_code:
        abort(404)
    delete_from_db(discount_code, "Discount code deleted")
    flash("The discount code has been deleted.", "warning")
    return redirect(url_for('.discount_codes_view'))
def view_invoice(invoice_identifier):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice:
        abort(404)
    if invoice.status == 'completed':
        return redirect(
            url_for('event_invoicing.view_invoice_after_payment',
                    invoice_identifier=invoice_identifier))

    pay_by_stripe = False
    pay_by_paypal = False

    stripe_publishable_key = "No Key Set"

    if StripePaymentsManager.get_credentials():
        pay_by_stripe = True
        stripe_publishable_key = StripePaymentsManager.get_credentials(
        )['PUBLISHABLE_KEY']

    if PayPalPaymentsManager.get_credentials():
        pay_by_paypal = True

    return render_template(
        'gentelella/guest/invoicing/invoice_pre_payment.html',
        invoice=invoice,
        event=invoice.event,
        countries=list(pycountry.countries),
        pay_by_stripe=pay_by_stripe,
        pay_by_paypal=pay_by_paypal,
        stripe_publishable_key=stripe_publishable_key)
def charge_stripe_invoice_payment():
    status, result = InvoicingManager.charge_stripe_invoice_payment(
        request.form)
    if status:
        return jsonify({"status": "ok", "message": result.transaction_id})
    else:
        return jsonify({"status": "error", "message": result})
Ejemplo n.º 11
0
 def show_transaction_error(self, invoice_identifier):
     invoice = InvoicingManager.get_invoice_by_identifier(
         invoice_identifier)
     return self.render(
         '/gentelella/guest/invoicing/invoice_post_payment_error.html',
         invoice=invoice,
         event=invoice.event)
def initiate_invoice_payment():
    result = InvoicingManager.initiate_invoice_payment(request.form)
    if result:
        if request.form.get('pay_via_service', 'stripe') == 'stripe':
            return jsonify({
                "status":
                "ok",
                "email":
                result.user.email,
                "action":
                "start_stripe"
                if result.status == 'initialized' else "show_completed"
            })
        else:
            return jsonify({
                "status":
                "ok",
                "email":
                result.user.email,
                "action":
                "start_paypal",
                "redirect_url":
                PayPalPaymentsManager.get_checkout_url(result)
            })
    else:
        return jsonify({"status": "error"})
def view_invoice(invoice_identifier):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice:
        abort(404)
    if invoice.status == 'completed':
        return redirect(
            url_for('event_invoicing.view_invoice_after_payment', invoice_identifier=invoice_identifier))

    pay_by_stripe = False
    pay_by_paypal = False

    stripe_publishable_key = "No Key Set"

    if StripePaymentsManager.get_credentials():
        pay_by_stripe = True
        stripe_publishable_key = StripePaymentsManager.get_credentials()['PUBLISHABLE_KEY']

    if PayPalPaymentsManager.get_credentials():
        pay_by_paypal = True

    return render_template('gentelella/guest/invoicing/invoice_pre_payment.html', invoice=invoice, event=invoice.event,
                           countries=list(pycountry.countries),
                           pay_by_stripe=pay_by_stripe,
                           pay_by_paypal=pay_by_paypal,
                           stripe_publishable_key=stripe_publishable_key)
def paypal_callback(invoice_identifier, function):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice or invoice.status == 'expired':
        abort(404)
    if function == 'cancel':
        invoice.status = 'cancelled'
        save_to_db(invoice)
        return redirect(url_for('event_detail.display_event_detail_home', identifier=invoice.event.identifier))
    elif function == 'success':
        status, result = InvoicingManager.charge_paypal_invoice_payment(invoice)
        if status:
            return redirect(url_for('.view_invoice', invoice_identifier=invoice_identifier))
        else:
            flash("An error occurred while processing your transaction. " + str(result), "danger")
            return redirect(url_for('.show_transaction_error', invoice_identifier=invoice_identifier))
    abort(404)
 def test_invoice_payment_paypal_cancel(self):
     with app.test_request_context():
         event, invoice = get_event_invoice()
         self.app.get(
             url_for('event_invoicing.paypal_callback', invoice_identifier=invoice.identifier, function="cancel"),
             follow_redirects=True)
         invoice = InvoicingManager.get_invoice_by_identifier(invoice.identifier)
         self.assertTrue(invoice.status == 'cancelled', msg=invoice.status)
def view_invoice_after_payment(invoice_identifier):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice or invoice.status != 'completed':
        abort(404)
    return render_template(
        'gentelella/guest/invoicing/invoice_post_payment.html',
        invoice=invoice,
        event=invoice.event)
Ejemplo n.º 17
0
def discount_codes_create(discount_code_id=None):
    if request.method == 'POST':
        InvoicingManager.create_edit_discount_code(request.form)
        flash("The discount code has been added.", "success")
        return redirect(url_for('.discount_codes_view'))
    discount_code = None
    if discount_code_id:
        discount_code = InvoicingManager.get_discount_code(discount_code_id)

    user_roles = UserSystemRole.query.filter(CustomSysRole.name == 'Marketer').all()

    active_users_ids = [x.id for x in user_roles]

    marketers = User.query.filter(User.id.in_(active_users_ids)).all()

    return render_template('gentelella/admin/super_admin/sales/discount_codes_create.html',
                           discount_code=discount_code, marketers=marketers)
 def test_invoice_payment_paypal_cancel(self):
     with app.test_request_context():
         event, invoice = get_event_invoice()
         self.app.get(
             url_for('event_invoicing.paypal_callback', invoice_identifier=invoice.identifier, function="cancel"),
             follow_redirects=True)
         invoice = InvoicingManager.get_invoice_by_identifier(invoice.identifier)
         self.assertTrue(invoice.status == 'cancelled', msg=invoice.status)
Ejemplo n.º 19
0
    def discount_codes_create(self, discount_code_id=None):
        if request.method == 'POST':
            InvoicingManager.create_edit_discount_code(request.form)
            flash("The discount code has been added.", "success")
            return redirect(url_for('.discount_codes_view'))
        discount_code = None
        if discount_code_id:
            discount_code = InvoicingManager.get_discount_code(discount_code_id)

        user_roles = UserSystemRole.query.filter(CustomSysRole.name == 'Marketer').all()

        active_users_ids = [x.id for x in user_roles]

        marketers = User.query.filter(User.id.in_(active_users_ids)).all()

        return self.render('/gentelella/admin/super_admin/sales/discount_codes_create.html',
                           discount_code=discount_code, marketers=marketers)
 def test_invoice_payment_stripe(self):
     with app.test_request_context():
         event, invoice = get_event_invoice()
         data = {
             "identifier": invoice.identifier,
             "email": "*****@*****.**",
             "firstname": "John",
             "lastname": "Doe",
             "address": "ACME Lane",
             "city": "Loony",
             "state": "Tunes",
             "zipcode": "1451145",
             "country": "Warner",
             "pay_via_service": "stripe"
         }
         response = self.app.post(
             url_for('event_invoicing.initiate_invoice_payment'),
             data=data,
             follow_redirects=True)
         response_json = json.loads(response.data)
         self.assertEqual(data['email'],
                          response_json['email'],
                          msg=response.data)
         self.assertEqual("start_stripe",
                          response_json['action'],
                          msg=response.data)
         invoice = InvoicingManager.get_invoice_by_identifier(
             invoice.identifier)
         self.assertEqual(invoice.status, 'initialized', msg=response.data)
         invoice.brand = "Visa"
         invoice.completed_at = datetime.now()
         invoice.status = "completed"
         invoice.last4 = "1234"
         invoice.exp_month = "12"
         invoice.exp_year = "2050"
         invoice.paid_via = "stripe"
         invoice.payment_mode = "card"
         save_to_db(invoice)
         response = self.app.get(url_for(
             'event_invoicing.view_invoice_after_payment',
             invoice_identifier=invoice.identifier),
                                 follow_redirects=True)
         self.assertTrue(str(event.name) in response.data,
                         msg=response.data)
         response = self.app.get(url_for(
             'event_invoicing.view_invoice',
             invoice_identifier=invoice.identifier),
                                 follow_redirects=False)
         self.assertEqual(response.status_code,
                          302,
                          msg=response.status_code)
         response = self.app.get(url_for(
             'event_invoicing.view_invoice_after_payment_pdf',
             invoice_identifier=invoice.identifier),
                                 follow_redirects=False)
         self.assertEqual(response.status_code,
                          200,
                          msg=response.status_code)
 def discount_codes_toggle(self, discount_code_id=None):
     discount_code = InvoicingManager.get_discount_code(discount_code_id)
     if not discount_code:
         abort(404)
     discount_code.is_active = not discount_code.is_active
     save_to_db(discount_code)
     message = "Activated." if discount_code.is_active else "Deactivated."
     flash("The discount code has been " + message, "success")
     return redirect(url_for('.discount_codes_view'))
Ejemplo n.º 22
0
def discount_codes_toggle(discount_code_id=None):
    discount_code = InvoicingManager.get_discount_code(discount_code_id)
    if not discount_code:
        abort(404)
    discount_code.is_active = not discount_code.is_active
    save_to_db(discount_code)
    message = "Activated." if discount_code.is_active else "Deactivated."
    flash("The discount code has been " + message, "success")
    return redirect(url_for('.discount_codes_view'))
def view_invoice_after_payment_pdf(invoice_identifier):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice or invoice.status != 'completed':
        abort(404)
    pdf = create_pdf(render_template('gentelella/guest/invoicing/invoice_pdf.html',
                                     invoice=invoice, event=invoice.event))
    response = make_response(pdf.getvalue())
    response.headers['Content-Type'] = 'application/pdf'
    response.headers['Content-Disposition'] = \
        'inline; filename=%s.pdf' % invoice.get_invoice_number()
    return response
def charge_stripe_invoice_payment():
    status, result = InvoicingManager.charge_stripe_invoice_payment(request.form)
    if status:
        return jsonify({
            "status": "ok",
            "message": result.transaction_id
        })
    else:
        return jsonify({
            "status": "error",
            "message": result
        })
    def check_duplicate_discount_code(self):
        code = request.args.get('code')
        current = request.args.get('current')
        if not current:
            current = ''
        discount_code = InvoicingManager.get_discount_code(code)
        if (current == ""
                and discount_code) or (current != "" and discount_code
                                       and discount_code.id != int(current)):
            return jsonify({"status": "invalid"}), 404

        return jsonify({"status": "valid"}), 200
def view_invoice_after_payment_pdf(invoice_identifier):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice or invoice.status != 'completed':
        abort(404)
    pdf = create_pdf(
        render_template('gentelella/guest/invoicing/invoice_pdf.html',
                        invoice=invoice,
                        event=invoice.event))
    response = make_response(pdf.getvalue())
    response.headers['Content-Type'] = 'application/pdf'
    response.headers['Content-Disposition'] = \
        'inline; filename=%s.pdf' % invoice.get_invoice_number()
    return response
Ejemplo n.º 27
0
def check_duplicate_discount_code():
    code = request.args.get('code')
    current = request.args.get('current')
    if not current:
        current = ''
    discount_code = InvoicingManager.get_discount_code(code)
    if (current == "" and discount_code) or (current != "" and discount_code and discount_code.id != int(current)):
        return jsonify({
            "status": "invalid"
        }), 404

    return jsonify({
        "status": "valid"
    }), 200
 def test_invoice_payment_stripe(self):
     with app.test_request_context():
         event, invoice = get_event_invoice()
         data = {
             "identifier": invoice.identifier,
             "email": "*****@*****.**",
             "firstname": "John",
             "lastname": "Doe",
             "address": "ACME Lane",
             "city": "Loony",
             "state": "Tunes",
             "zipcode": "1451145",
             "country": "Warner",
             "pay_via_service": "stripe"
         }
         response = self.app.post(url_for('event_invoicing.initiate_invoice_payment'), data=data,
                                  follow_redirects=True)
         response_json = json.loads(response.data)
         self.assertEqual(data['email'], response_json['email'], msg=response.data)
         self.assertEqual("start_stripe", response_json['action'], msg=response.data)
         invoice = InvoicingManager.get_invoice_by_identifier(invoice.identifier)
         self.assertEqual(invoice.status, 'initialized', msg=response.data)
         invoice.brand = "Visa"
         invoice.completed_at = datetime.now()
         invoice.status = "completed"
         invoice.last4 = "1234"
         invoice.exp_month = "12"
         invoice.exp_year = "2050"
         invoice.paid_via = "stripe"
         invoice.payment_mode = "card"
         save_to_db(invoice)
         response = self.app.get(
             url_for('event_invoicing.view_invoice_after_payment', invoice_identifier=invoice.identifier),
             follow_redirects=True)
         self.assertTrue(str(event.name) in response.data, msg=response.data)
         response = self.app.get(url_for('event_invoicing.view_invoice', invoice_identifier=invoice.identifier),
                                 follow_redirects=False)
         self.assertEqual(response.status_code, 302, msg=response.status_code)
         response = self.app.get(
             url_for('event_invoicing.view_invoice_after_payment_pdf', invoice_identifier=invoice.identifier),
             follow_redirects=False)
         self.assertEqual(response.status_code, 200, msg=response.status_code)
def initiate_invoice_payment():
    result = InvoicingManager.initiate_invoice_payment(request.form)
    if result:
        if request.form.get('pay_via_service', 'stripe') == 'stripe':
            return jsonify({
                "status": "ok",
                "email": result.user.email,
                "action": "start_stripe" if result.status == 'initialized' else "show_completed"
            })
        else:
            return jsonify({
                "status": "ok",
                "email": result.user.email,
                "action": "start_paypal",
                "redirect_url": PayPalPaymentsManager.get_checkout_url(result)
            })
    else:
        return jsonify({
            "status": "error"
        })
Ejemplo n.º 30
0
def discount_codes_view():
    discount_codes = InvoicingManager.get_discount_codes()
    return render_template('gentelella/admin/super_admin/sales/discount_codes.html', discount_codes=discount_codes)
def show_transaction_error(invoice_identifier):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    return render_template('gentelella/guest/invoicing/invoice_post_payment_error.html', invoice=invoice,
                           event=invoice.event)
def view_invoice_after_payment(invoice_identifier):
    invoice = InvoicingManager.get_invoice_by_identifier(invoice_identifier)
    if not invoice or invoice.status != 'completed':
        abort(404)
    return render_template('gentelella/guest/invoicing/invoice_post_payment.html', invoice=invoice,
                           event=invoice.event)
 def discount_codes_view(self):
     discount_codes = InvoicingManager.get_discount_codes()
     return self.render(
         '/gentelella/admin/super_admin/sales/discount_codes.html')
Ejemplo n.º 34
0
def sales_by_marketer_view(by_discount_code=False):
    from_date = request.args.get('from_date')
    to_date = request.args.get('to_date')

    if ('from_date' in request.args and not from_date) or ('to_date' in request.args and not to_date) or \
        ('from_date' in request.args and 'to_date' not in request.args) or \
        ('to_date' in request.args and 'from_date' not in request.args):
        return redirect(url_for('.sales_by_marketer_view'))

    orders_summary = {
        'tickets_count': 0,
        'orders_count': 0,
        'total_sales': 0,
        'total_discounts': 0
    }

    tickets_summary = {}

    if not by_discount_code:
        user_roles = UserSystemRole.query.filter(CustomSysRole.name == 'Marketer').all()

        active_users_ids = [x.id for x in user_roles]

        marketers = User.query.filter(User.id.in_(active_users_ids)).all()

        for marketer in marketers:
            tickets_summary[str(marketer.id)] = {
                'email': marketer.email,
                'name': marketer.user_detail.firstname,
                'tickets_count': 0,
                'sales': 0,
                'discounts': 0
            }
    else:
        discount_codes = InvoicingManager.get_discount_codes()
        for discount_code in discount_codes:
            tickets_summary[str(discount_code.id)] = {
                'email': discount_code.code,
                'name': str(discount_code.value) + '% off for ' + str(discount_code.max_quantity) + ' months',
                'tickets_count': 0,
                'sales': 0,
                'discounts': 0,
                'marketer': discount_code.marketer.email
            }

    events = DataGetter.get_all_events_with_discounts()

    for event in events:
        temp_month_summary = {}
        print event
        discount_coupon = CachedGetter.get_discount_code(event.discount_code_id)

        if not by_discount_code:
            key = str(discount_coupon.marketer_id)
        else:
            key = str(discount_coupon.id)

        if from_date and to_date:
            orders = TicketingManager.get_orders(
                from_date=datetime.strptime(from_date, '%d/%m/%Y'),
                to_date=datetime.strptime(to_date, '%d/%m/%Y'),
                status='completed',
                event_id=event.id
            )
        else:
            orders = TicketingManager.get_orders(status='completed', event_id=event.id)

        for order in orders:
            if order.status == 'completed' and order.paid_via != 'free':
                orders_summary['orders_count'] += 1
                key = '{month:02d}{year:d}'.format(month=order.completed_at.month, year=order.completed_at.year)
                temp_month_summary[key] = order.amount
                orders_summary['sales'] += order.amount
                for order_ticket in order.tickets:
                    tickets_summary[key]['tickets_count'] += order_ticket.quantity
                    orders_summary['tickets_count'] += order_ticket.quantity

        # Calculate discount on a monthly basis
        month_count = 1
        for amount in temp_month_summary:
            if discount_coupon.max_quantity <= month_count:
                tickets_summary[key]['discounts'] \
                    += amount * (discount_coupon.value / 100)
                orders_summary['total_discounts'] += amount * (discount_coupon.value / 100)
            month_count += 1

    return render_template('gentelella/super_admin/sales/by_marketer.html',
                           tickets_summary=tickets_summary,
                           display_currency=display_currency,
                           from_date=from_date,
                           to_date=to_date,
                           key_name='marketers' if not by_discount_code else 'discount codes',
                           orders_summary=orders_summary,
                           navigation_bar=list_navbar())
Ejemplo n.º 35
0
def discount_codes_view():
    discount_codes = InvoicingManager.get_discount_codes()
    return render_template('gentelella/admin/super_admin/sales/discount_codes.html', discount_codes=discount_codes)