def receipt(): if not current_user.is_authenticated: abort(401) return invoice_id = request.args.get('id') if invoice_id: invoice = stripe.Invoice.retrieve(invoice_id) if invoice: user_or_org = model.user.get_user_or_org_by_customer_id(invoice.customer) if user_or_org: if user_or_org.organization: admin_org = AdministerOrganizationPermission(user_or_org.username) if not admin_org.can(): abort(404) return else: if not user_or_org.username == current_user.db_user().username: abort(404) return def format_date(timestamp): return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d') file_data = renderInvoiceToPdf(invoice, user_or_org) receipt_filename = 'quay-receipt-%s.pdf' % (format_date(invoice.date)) return Response(file_data, mimetype="application/pdf", headers={"Content-Disposition": "attachment;filename=" + receipt_filename}) abort(404)
def sendInvoice(invoice_id): invoice = stripe.Invoice.retrieve(invoice_id) if not invoice['customer']: print 'No customer found' return customer_id = invoice['customer'] user = model.user.get_user_or_org_by_customer_id(customer_id) if not user: print 'No user found for customer %s' % (customer_id) return with app.app_context(): file_data = renderInvoiceToPdf(invoice, user) with open('invoice.pdf', 'wb') as f: f.write(file_data) print 'Invoice output as invoice.pdf'
def sendInvoice(invoice_id): invoice = stripe.Invoice.retrieve(invoice_id) if not invoice["customer"]: print("No customer found") return customer_id = invoice["customer"] user = model.user.get_user_or_org_by_customer_id(customer_id) if not user: print("No user found for customer %s" % (customer_id)) return with app.app_context(): file_data = renderInvoiceToPdf(invoice, user) with open("invoice.pdf", "wb") as f: f.write(file_data) print("Invoice output as invoice.pdf")