From ebda1abec40f40580a7da1e511164f0ec77d7a62 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 18 Jan 2017 17:01:38 +0100 Subject: [PATCH] [IMP] stripe: add receipt_email to the order The email of the recipient must be specified in the charge. The checkout.js prompt creates a token with the email specified as the name but to get an email confirmation that the charge succeeded, the receipt_email parameter must be set. Side note: the receipt_email is not enough to send email confirmation, it must also be enabled on Stripe dashboard that generated the access tokens. Reference: https://support.stripe.com/questions/email-receipts opw-697759 --- addons/payment_stripe/controllers/main.py | 2 +- addons/payment_stripe/models/payment_transaction.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/payment_stripe/controllers/main.py b/addons/payment_stripe/controllers/main.py index ceebb17e500..b4627157a9e 100644 --- a/addons/payment_stripe/controllers/main.py +++ b/addons/payment_stripe/controllers/main.py @@ -32,7 +32,7 @@ class StripeController(http.Controller): tx = request.env['payment.transaction'].sudo().browse( int(request.session.get('sale_transaction_id') or request.session.get('website_payment_tx_id', False)) ) - response = tx._create_stripe_charge(tokenid=post['tokenid']) + response = tx._create_stripe_charge(tokenid=post['tokenid'], email=post['email']) _logger.info('Stripe: entering form_feedback with post data %s', pprint.pformat(response)) if response: request.env['payment.transaction'].sudo().form_feedback(response, 'stripe') diff --git a/addons/payment_stripe/models/payment_transaction.py b/addons/payment_stripe/models/payment_transaction.py index 66409f0b942..98b2d0b4551 100644 --- a/addons/payment_stripe/models/payment_transaction.py +++ b/addons/payment_stripe/models/payment_transaction.py @@ -17,7 +17,7 @@ _logger = logging.getLogger(__name__) class PaymentTransactionStripe(models.Model): _inherit = 'payment.transaction' - def _create_stripe_charge(self, acquirer_ref=None, tokenid=None): + def _create_stripe_charge(self, acquirer_ref=None, tokenid=None, email=None): api_url_charge = 'https://%s/charges' % (self.acquirer_id._get_stripe_api_url()) charge_params = { 'amount': int(self.amount*100), # Stripe takes amount in cents (https://support.stripe.com/questions/which-zero-decimal-currencies-does-stripe-support) @@ -28,6 +28,8 @@ class PaymentTransactionStripe(models.Model): charge_params['customer'] = acquirer_ref if tokenid: charge_params['card'] = str(tokenid) + if email: + charge_params['receipt_email'] = email r = requests.post(api_url_charge, auth=(self.acquirer_id.stripe_secret_key, ''), params=charge_params,