def void(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) if c.invoice.is_void(): h.flash("Invoice was already voided.") return redirect_to(action='view', id=c.invoice.id) if h.auth.authorized(h.auth.has_organiser_role): c.invoice.void = "Administration Change" meta.Session.commit() h.flash("Invoice was voided.") return redirect_to(action='view', id=c.invoice.id) else: if c.invoice.paid(): h.flash("Cannot void a paid invoice.") return redirect_to(action='view', id=c.invoice.id) c.invoice.void = "User cancellation" c.person = c.invoice.person meta.Session.commit() email(lca_info['contact_email'], render('/invoice/user_voided.mako')) h.flash("Previous invoice was voided.") return redirect_to(controller='registration', action='pay', id=c.person.registration.id)
def pay(self, id): """Request confirmation from user """ invoice = Invoice.find_by_id(id, True) person = invoice.person if not h.auth.authorized( h.auth.Or(h.auth.is_same_zkpylons_user(person.id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() #return render('/registration/really_closed.mako') error = self._check_invoice(person, invoice) if error is not None: return error c.payment = Payment() c.payment.amount = invoice.total c.payment.invoice = invoice meta.Session.commit() if c.payment.gateway == 'securepay': return render("/invoice/securepay.mako") else: return render("/invoice/payment.mako")
def refund(self, id): invoice = Invoice.find_by_id(id) try: c.invoice_person = invoice.person.id except: c.invoice_person = '' c.due_date = datetime.date.today().strftime("%d/%m/%Y") c.product_categories = ProductCategory.find_all() # The form adds one to the count by default, so we need to decrement it c.item_count = len(invoice.items) - 1 defaults = dict() defaults['invoice.person' ] = c.invoice_person defaults['invoice.due_date'] = c.due_date for i in range(len(invoice.items)): item = invoice.items[i] if item.product: defaults['invoice.items-' + str(i) + '.product'] = item.product.id else: defaults['invoice.items-' + str(i) + '.description'] = item.description defaults['invoice.items-' + str(i) + '.qty'] = -item.qty defaults['invoice.items-' + str(i) + '.cost'] = item.cost form = render("/invoice/new.mako") return htmlfill.render(form, defaults, use_all_keys=True)
def refund(self, id): invoice = Invoice.find_by_id(id) try: c.invoice_person = invoice.person.id except: c.invoice_person = '' c.due_date = datetime.date.today().strftime("%d/%m/%Y") c.product_categories = ProductCategory.find_all() # The form adds one to the count by default, so we need to decrement it c.item_count = len(invoice.items) - 1 defaults = dict() defaults['invoice.person'] = c.invoice_person defaults['invoice.due_date'] = c.due_date for i in range(len(invoice.items)): item = invoice.items[i] if item.product: defaults['invoice.items-' + str(i) + '.product'] = item.product.id else: defaults['invoice.items-' + str(i) + '.description'] = item.description defaults['invoice.items-' + str(i) + '.qty'] = -item.qty defaults['invoice.items-' + str(i) + '.cost'] = item.cost form = render("/invoice/new.mako") return htmlfill.render(form, defaults, use_all_keys=True)
def get_invoice(self, id): """ Returns a JSON representation of an existing invoice """ invoice = Invoice.find_by_id(id, True) obj = { 'id': invoice.id, 'person_id': invoice.person_id, 'manual': invoice.manual, 'void': invoice.void, 'issue_date': invoice.issue_date.strftime('%d/%m/%Y'), 'due_date': invoice.due_date.strftime('%d/%m/%Y'), 'items': [{ 'product_id': item.product_id, 'description': item.description, 'qty': item.qty, 'cost': item.cost, } for item in invoice.items], } return dict(r=dict(invoice=obj))
def pay(self, id): """Request confirmation from user """ invoice = Invoice.find_by_id(id, True) person = invoice.person if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_user(person.id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() #return render('/registration/really_closed.mako') error = self._check_invoice(person, invoice) if error is not None: return error c.payment = Payment() c.payment.amount = invoice.total c.payment.invoice = invoice meta.Session.commit() if c.payment.gateway == 'securepay': return render("/invoice/securepay.mako") else: return render("/invoice/payment.mako")
def unvoid(self, id): c.invoice = Invoice.find_by_id(id, True) c.invoice.void = None c.invoice.manual = True meta.Session.commit() h.flash("Invoice was un-voided.") return redirect_to(action='view', id=c.invoice.id)
def void(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) if c.invoice.is_void: h.flash("Invoice was already voided.") return redirect_to(action='view', id=c.invoice.id) elif len(c.invoice.payment_received) and h.auth.authorized(h.auth.has_organiser_role): h.flash("Invoice has a payment applied to it, do you want to " + h.link_to('Refund', h.url_for(action='refund')) + " instead?") return redirect_to(action='view', id=c.invoice.id) elif len(c.invoice.payment_received): h.flash("Cannot void a paid invoice.") return redirect_to(action='view', id=c.invoice.id) elif h.auth.authorized(h.auth.has_organiser_role): c.invoice.void = "Administration Change" meta.Session.commit() h.flash("Invoice was voided.") return redirect_to(action='view', id=c.invoice.id) else: c.invoice.void = "User cancellation" c.person = c.invoice.person meta.Session.commit() email(Config.get('contact_email'), render('/invoice/user_voided.mako')) h.flash("Previous invoice was voided.") return redirect_to(controller='registration', action='pay', id=c.person.registration.id)
def check(self, app, environ, start_response): if not environ.get('REMOTE_USER'): set_redirect() raise NotAuthenticatedError('Not Authenticated') person = Person.find_by_email(environ['REMOTE_USER']) if person is None: environ['auth_failure'] = 'NO_USER' raise NotAuthorizedError( 'You are not one of the users allowed to access this resource.' ) invoice = Invoice.find_by_id(self.invoice_id) if invoice is None: raise NotAuthorizedError( "Invoice doesn't exist" ) if person.id <> invoice.person_id: set_role("Invoice is not for this user") raise NotAuthorizedError( "Invoice is not for this user" ) return app(environ, start_response)
def void(self, id): if not h.auth.authorized( h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role)): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) if c.invoice.is_void: h.flash("Invoice was already voided.") return redirect_to(action='view', id=c.invoice.id) elif len(c.invoice.payment_received) and h.auth.authorized( h.auth.has_organiser_role): h.flash("Invoice has a payment applied to it, do you want to " + h.link_to('Refund', h.url_for(action='refund')) + " instead?") return redirect_to(action='view', id=c.invoice.id) elif len(c.invoice.payment_received): h.flash("Cannot void a paid invoice.") return redirect_to(action='view', id=c.invoice.id) elif h.auth.authorized(h.auth.has_organiser_role): c.invoice.void = "Administration Change" meta.Session.commit() h.flash("Invoice was voided.") return redirect_to(action='view', id=c.invoice.id) else: c.invoice.void = "User cancellation" c.person = c.invoice.person meta.Session.commit() email(lca_info['contact_email'], render('/invoice/user_voided.mako')) h.flash("Previous invoice was voided.") return redirect_to(controller='registration', action='pay', id=c.person.registration.id)
def extend(self, id): c.invoice = Invoice.find_by_id(id, True) if c.invoice.is_overdue: c.invoice.due_date = datetime.datetime.now() + datetime.timedelta(days=1) else: c.invoice.due_date = c.invoice.due_date + ((c.invoice.due_date - datetime.datetime.now()) * 2) meta.Session.commit() return redirect_to(action='view')
def printable(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() c.printable = True c.invoice = Invoice.find_by_id(id, True) c.payment_received = None c.payment = None if c.invoice.is_paid and c.invoice.total > 0: c.payment_received = c.invoice.good_payments[0] c.payment = c.payment_received.payment return render('/invoice/view_printable.mako')
def pdf(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) xml_s = render('/invoice/pdf.mako') xsl_f = get_path('zk_root') + '/zkpylons/templates/invoice/pdf.xsl' pdf_data = pdfgen.generate_pdf(xml_s, xsl_f) filename = Config.get('event_shortname') + '_' + str(c.invoice.id) + '.pdf' return pdfgen.wrap_pdf_response(pdf_data, filename)
def pdf(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) xml_s = render('/invoice/pdf.mako') xsl_f = file_paths['zk_root'] + '/zkpylons/templates/invoice/pdf.xsl' pdf_data = pdfgen.generate_pdf(xml_s, xsl_f) filename = lca_info['event_shortname'] + '_' + str(c.invoice.id) + '.pdf' return pdfgen.wrap_pdf_response(pdf_data, filename)
def pdf(self, id): if not h.auth.authorized( h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key()) ): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) xml_s = render("/invoice/pdf.mako") xsl_f = file_paths["zk_root"] + "/zkpylons/templates/invoice/pdf.xsl" pdf_data = pdfgen.generate_pdf(xml_s, xsl_f) filename = lca_info["event_shortname"] + "_" + str(c.invoice.id) + ".pdf" return pdfgen.wrap_pdf_response(pdf_data, filename)
def pay_manual(self, id): """Request confirmation from user """ invoice = Invoice.find_by_id(id, True) person = invoice.person error = self._check_invoice(person, invoice, ignore_overdue=True) if error is not None: return error c.payment = Payment() c.payment.amount = invoice.total c.payment.invoice = invoice meta.Session.commit() return redirect_to(controller='payment', id=c.payment.id, action='new_manual')
def pdf(self, id): if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_attendee(id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() c.invoice = Invoice.find_by_id(id, True) xml_s = render('/invoice/pdf.mako') template_path = file_paths['theme_templates'] + '/invoice/pdf.xsl' if(os.path.isfile(template_path)): xsl_f = template_path else: xsl_f = file_paths['zk_root'] + '/zkpylons/templates/invoice/pdf.xsl' pdf_data = pdfgen.generate_pdf(xml_s, xsl_f) filename = lca_info['event_shortname'] + '_' + str(c.invoice.id) + '.pdf' return pdfgen.wrap_pdf_response(pdf_data, filename)
def get_invoice(self, id): """ Returns a JSON representation of an existing invoice """ invoice = Invoice.find_by_id(id, True) obj = { "id": invoice.id, "person_id": invoice.person_id, "manual": invoice.manual, "void": invoice.void, "issue_date": invoice.issue_date.strftime("%d/%m/%Y"), "due_date": invoice.due_date.strftime("%d/%m/%Y"), "items": [ {"product_id": item.product_id, "description": item.description, "qty": item.qty, "cost": item.cost} for item in invoice.items ], } return dict(r=dict(invoice=obj))
def get_invoice(self, id): """ Returns a JSON representation of an existing invoice """ invoice = Invoice.find_by_id(id, True) obj = { 'id': invoice.id, 'person_id': invoice.person_id, 'manual': invoice.manual, 'void': invoice.void, 'issue_date': invoice.issue_date.strftime('%d/%m/%Y'), 'due_date': invoice.due_date.strftime('%d/%m/%Y'), 'items': [ { 'product_id': item.product_id, 'description': item.description, 'qty': item.qty, 'cost': item.cost, } for item in invoice.items], } return dict(r=dict(invoice=obj))
def pay_invoice(self): """ Pay an invoice via the new angular.js interface Expects: and invoice_id. Assumes total amount is to be paid. TODO: Validation?? """ invoice_id = int(request.params['invoice'],10) invoice = Invoice.find_by_id(invoice_id, True) person = invoice.person if not h.auth.authorized(h.auth.Or(h.auth.is_same_zkpylons_user(person.id), h.auth.has_organiser_role, h.auth.has_unique_key())): # Raise a no_auth error h.auth.no_role() payment = Payment() payment.amount = invoice.total payment.invoice = invoice payment_received = PaymentReceived( approved=True, payment=payment, invoice_id=invoice.id, success_code='0', amount_paid=payment.amount, currency_used='AUD', response_text='Approved', client_ip_zookeepr='127.1.0.1', client_ip_gateway='127.0.0.1', email_address=person.email_address, gateway_ref='Rego Desk Cash' ) meta.Session.add(payment) meta.Session.add(payment_received) meta.Session.commit() return "Payment recorded"
def pay_invoice(self, id): """ Pay an invoice via the new angular.js interface Expects: invoice_id. Assumes total amount is to be paid. TODO: Validation?? """ invoice = Invoice.find_by_id(id, True) person = invoice.person if not invoice.is_paid: payment = Payment() payment.amount = invoice.total payment.invoice = invoice payment_received = PaymentReceived( approved=True, payment=payment, invoice_id=invoice.id, success_code='0', amount_paid=payment.amount, currency_used='AUD', response_text='Approved', client_ip_zookeepr='127.1.0.1', client_ip_gateway='127.0.0.1', email_address=person.email_address, gateway_ref='Rego Desk Cash') meta.Session.add(payment) meta.Session.add(payment_received) meta.Session.commit() return dict(r=dict(message="Payment recorded")) else: return dict(r=dict( message="A payment has already been recorded for this invoice") )
def pay_invoice(self, id): """ Pay an invoice via the new angular.js interface Expects: invoice_id. Assumes total amount is to be paid. TODO: Validation?? """ invoice = Invoice.find_by_id(id, True) person = invoice.person if not invoice.is_paid: payment = Payment() payment.amount = invoice.total payment.invoice = invoice payment_received = PaymentReceived( approved=True, payment=payment, invoice_id=invoice.id, success_code='0', amount_paid=payment.amount, currency_used='AUD', response_text='Approved', client_ip_zookeepr='127.1.0.1', client_ip_gateway='127.0.0.1', email_address=person.email_address, gateway_ref='Rego Desk Cash' ) meta.Session.add(payment) meta.Session.add(payment_received) meta.Session.commit() return dict(r=dict(message="Payment recorded")) else: return dict(r=dict(message="A payment has already been recorded for this invoice"))
def _to_python(self, value, state): invoice = Invoice.find_by_id(int(value), False) if invoice is None: raise Invalid("Unknown invoice ID.", value, state) else: return invoice