From a75d94d3cf77ac232cddb3660128b541f83e2bda Mon Sep 17 00:00:00 2001 From: Tomasz Kolek Date: Fri, 23 Dec 2016 17:03:33 +0100 Subject: [PATCH] Refactor invoice part of stripe integration. --- zerver/views/webhooks/stripe.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/zerver/views/webhooks/stripe.py b/zerver/views/webhooks/stripe.py index 15c4dfaf12..39560529bb 100644 --- a/zerver/views/webhooks/stripe.py +++ b/zerver/views/webhooks/stripe.py @@ -98,11 +98,13 @@ def api_stripe_webhook(request, user_profile, client, body = body_template.format(beginning=beginning, id=object_id, link=link, rest=rest) elif event_type == "invoice.payment_failed": - link = "https://dashboard.stripe.com/invoices/"+payload["data"]["object"]["id"] - amount_string = amount(payload["data"]["object"]["amount_due"], payload["data"]["object"]["currency"]) - body_template = "An invoice payment on invoice with id **[{object[id]}](" + link + ")** and with **"\ - + amount_string + "** due has failed." - body = body_template.format(**(payload["data"])) + object_id = data_object['id'] + link = "https://dashboard.stripe.com/invoices/{}".format(object_id) + amount_string = amount(data_object["amount_due"], data_object["currency"]) + body_template = "An invoice payment on invoice with id **[{id}]({link})** and "\ + "with **{amount}** due has failed." + body = body_template.format(id=object_id, amount=amount_string, link=link) + elif event_type == "order.payment_failed": link = "https://dashboard.stripe.com/orders/"+payload["data"]["object"]["id"] amount_string = amount(payload["data"]["object"]["amount"], payload["data"]["object"]["currency"])