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']
diff --git a/payments/stripe/test_stripe.py b/payments/stripe/test_stripe.py
index 6ddf8753b..fbc091406 100644
--- a/payments/stripe/test_stripe.py
+++ b/payments/stripe/test_stripe.py
@@ -26,6 +26,7 @@ class Payment(Mock):
total = 100
captured_amount = 0
transaction_id = None
+ billing_email = "john@doe.com"
def change_status(self, status, message=''):
self.status = status
@@ -95,8 +96,30 @@ def test_form_contains_stripe_script(self):
form = provider.get_form(payment)
self.assertTrue(
'' % (
+ PUBLIC_KEY, store_name)
+ in str(form))
+
+ def test_form_contains_stripe_script_withou_billing_email(self):
+ """
+ If billing email is not set, it should generate the script as expected
+ """
+ payment = Payment()
+ store_name = 'Test store'
+ provider = StripeProvider(
+ name=store_name,
+ secret_key=SECRET_KEY, public_key=PUBLIC_KEY)
+
+ form = provider.get_form(payment)
+
+ payment.billing_email = None
+ form = provider.get_form(payment)
+ self.assertTrue(
+ '' % (
PUBLIC_KEY, store_name)
in str(form))
diff --git a/payments/stripe/widgets.py b/payments/stripe/widgets.py
index b9989d07d..b4967d9bb 100644
--- a/payments/stripe/widgets.py
+++ b/payments/stripe/widgets.py
@@ -20,6 +20,7 @@ def __init__(self, provider, payment, *args, **kwargs):
'data-key': provider.public_key,
'data-image': provider.image,
'data-name': provider.name,
+ 'data-email': payment.billing_email,
'data-description': payment.description or _('Total payment'),
# Stripe accepts cents
'data-amount': int(payment.total * 100),