From b58dacb863a68e6ff8f68eefbda1310808a505bf Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Thu, 26 Dec 2024 12:49:29 +0100 Subject: [PATCH] sending invoices --- rowers/braintreestuff.py | 2 ++ rowers/idoklad.py | 24 ++++++++++++++++++ rowers/tasks.py | 16 ++++++++++++ .../paymentconfirmationemail_noinvoice.html | 12 +++++++++ rowers/tests/testdata/testdata.tcx.gz | Bin 3999 -> 3999 bytes rowers/views/paymentviews.py | 5 +++- 6 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 rowers/templates/paymentconfirmationemail_noinvoice.html diff --git a/rowers/braintreestuff.py b/rowers/braintreestuff.py index df39ecd6..64ba63b9 100644 --- a/rowers/braintreestuff.py +++ b/rowers/braintreestuff.py @@ -328,6 +328,8 @@ def update_subscription(rower, data, method='up'): '%Y-%m-%d'), method) + _ = idoklad.create_invoice(rower, amount, result.subscription.id, dosend=True) + return True, amount else: # pragma: no cover errors = result.errors.for_object("subscription") diff --git a/rowers/idoklad.py b/rowers/idoklad.py index 2f74ac86..48c7d0a0 100644 --- a/rowers/idoklad.py +++ b/rowers/idoklad.py @@ -14,6 +14,13 @@ contacts_url = 'https://api.idoklad.cz/v3/Contacts' invoice_url = 'https://api.idoklad.cz/v3/IssuedInvoices' email_url = 'https://api.idoklad.cz/v3/Mails/IssuedInvoice/Send' +from rowers.tasks import handle_send_email_noinvoice + +from rowers.utils import myqueue + +import django_rq +queuehigh = django_rq.get_queue('high') + from rowers.models import iDokladToken #idoklad_countries = json.loads(open('rowers/idoklad_countries.json').read())["Data"]["Items"] @@ -86,6 +93,7 @@ def get_contacts(rower): return None # pragma def create_contact(rower): + print("idoklad create contact", rower) token = idoklad_token() if token is None: return None @@ -118,6 +126,14 @@ def create_contact(rower): res = requests.post(contacts_url, json=data, headers=headers) if res.status_code not in [200, 201]: + dologging('idoklad.log','Contact Created - reason '+str(res.reason)+'\n') + _ = myqueue.enqueue( + queuehigh, handle_send_email_noinvoice, + rower.user.email, + rower.user.first_name, + rower.user.last_name, + 'idoklad Contact creation failed for '+str(rower.user.email)+'\n'+str(res.text) + ) return 0 id = res.json()['Data']['Id'] @@ -199,6 +215,14 @@ def create_invoice(rower, amount, braintreeid, dosend=True, contact_id=None, nam dologging('idoklad.log','Invoice Sent - status code '+str(res.status_code)+'\n') if res.status_code not in [200, 201]: dologging('idoklad.log','Invoice Sent - reason '+str(res.text)+'\n') + _ = myqueue.enqueue( + queuehigh, handle_send_email_noinvoice, + rower.user.email, + rower.user.first_name, + rower.user.last_name, + 'idoklad Invoice sending failed for '+str(rower.user.email)+'\n'+str(res.text) + ) + return id diff --git a/rowers/tasks.py b/rowers/tasks.py index 8b4aca87..0382f924 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -1796,6 +1796,22 @@ def sigdig(value, digits=3): fmtstr = "%.0f" return fmtstr % (round(value, places)) +@app.task +def handle_send_email_noinvoice( + useremail, userfirstname, userlastname, reason, **kwargs): + + subject = "Reason" + + from_email = 'Rowsandall ' + d = { + 'name': userfirstname+' '+userlastname, + 'siteurl': siteurl, + 'reason': reason, + } + + _ = send_template_email(from_email, support@rowsandall.com, subject, + 'paymentconfirmationemail_noinvoice.html', + d, **kwargs) @app.task def handle_send_email_alert( diff --git a/rowers/templates/paymentconfirmationemail_noinvoice.html b/rowers/templates/paymentconfirmationemail_noinvoice.html new file mode 100644 index 00000000..88609383 --- /dev/null +++ b/rowers/templates/paymentconfirmationemail_noinvoice.html @@ -0,0 +1,12 @@ +{% extends "emailbase.html" %} + +{% block body %} +

Dear Admin,

+ + +

{{ name }}: {{ reason }}.

+ +

+ Best Regards, the Rowsandall Team +

+{% endblock %} diff --git a/rowers/tests/testdata/testdata.tcx.gz b/rowers/tests/testdata/testdata.tcx.gz index 476371d61f3e8e746883e08ee1e0ef82559d1515..bb91d107f419a7dab1a42f54f0ff17d5830c5f2f 100644 GIT binary patch delta 257 zcmV+c0sj7GkU5<>k-)ExnKF&?^t;!NpZ42sxO}uDI@OA07VuEVJ4Ex!e9r zdW)aEKK)~v?hN1_!0!Kp#g#91Pk#HD4)1JHuh!`~JWME;7mw1@_#<8V@Xr4LG+{nz H#DD<+61k9x delta 257 zcmV+c0sj7kX|?&{?(IrcJ{@=P;C27%?BdF6 z^5FdZWOdZ_>8D@57?SXD=pI)y{US9s(-_rY-4!!blK5Ti~{U=>AI}5IGe*Sv5 z)jDnV@@c>AhRa9$#rY3jq?(f7$>COP|0qp)iSX}vH_vE*a>F~}L^=h4-!^4DfdGRPcjX%<*5AXaBWlcoc H#DD<+?cJZS diff --git a/rowers/views/paymentviews.py b/rowers/views/paymentviews.py index 241091c1..e2dbe64c 100644 --- a/rowers/views/paymentviews.py +++ b/rowers/views/paymentviews.py @@ -58,7 +58,10 @@ def process_idokladcallback(request): t.acces_token = result['access_token'], t.refresh_token = result['refresh_token'] t.expires_in = result['expires_in'] - t.id_token = result['id_token'] + try: + t.id_token = result['id_token'] + except KeyError: + pass t.save() except iDokladToken.DoesNotExist: t = iDokladToken(