From 1dd7fd0e3702cc13b24e077e448fd35bc499d696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavi=20Torell=C3=B3?= Date: Fri, 10 May 2019 12:51:20 +0200 Subject: [PATCH] Patch Stripe Charge with receipt_email if Payment.billing_email exists It integrates the `receipt_email` property if `Payment.billing_email` exists. This will improve the Stripe payment flow ensuring that an email is ready to be sended to the payment creator if a receipt is requested (due to the automatic Stripe payment notifications flow, or due to a receipt request using the Dashboard) Fix #185 --- payments/stripe/forms.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/payments/stripe/forms.py b/payments/stripe/forms.py index 688cbe76f..4d4e23b6c 100644 --- a/payments/stripe/forms.py +++ b/payments/stripe/forms.py @@ -31,14 +31,25 @@ def clean(self): if not self.payment.transaction_id: stripe.api_key = self.provider.secret_key try: - self.charge = stripe.Charge.create( - capture=False, - amount=int(self.payment.total * 100), - currency=self.payment.currency, - card=data['stripeToken'], - description='%s %s' % ( + charge_data = { + "capture": False, + "amount": int(self.payment.total * 100), + "currency": self.payment.currency, + "card": data['stripeToken'], + "description": '%s %s' % ( self.payment.billing_last_name, - self.payment.billing_first_name)) + self.payment.billing_first_name + ), + } + + # Patch charge with billing email if exists + if self.payment.billing_email: + charge_data.update({ + "receipt_email": self.payment.billing_email, + }) + + self.charge = stripe.Charge.create(**charge_data) + except stripe.error.CardError as e: # Making sure we retrieve the charge charge_id = e.json_body['error']['charge']