This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/tools/emailinvoice.py

36 lines
919 B
Python
Raw Normal View History

2014-08-21 19:12:43 +00:00
import stripe
2013-12-13 20:11:11 +00:00
from app import app
from util.invoice import renderInvoiceToHtml
from util.useremails import send_invoice_email
2013-12-13 20:11:11 +00:00
from data import model
import argparse
from flask import Flask, current_app
from flask_mail import Mail
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.get_user_or_org_by_customer_id(customer_id)
if not user:
print 'No user found for customer %s' % (customer_id)
return
2014-11-24 21:07:38 +00:00
with app.app_context():
2013-12-13 20:11:11 +00:00
invoice_html = renderInvoiceToHtml(invoice, user)
send_invoice_email(user.email, invoice_html)
print 'Invoice sent to %s' % (user.email)
parser = argparse.ArgumentParser(description='Email an invoice')
parser.add_argument('invoice_id', help='The invoice ID')
args = parser.parse_args()
sendInvoice(args.invoice_id)