From 99e5a601b084499368c03559f0964eda84c8ca5d Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 17 Aug 2017 10:44:45 +0200 Subject: [PATCH] [FIX] payment_stripe: charge creation failed To reproduce: - Buy a product costing 0.01 - Validate the cart, pay with Stripe - Enter the credit card info, validate Stripe cannot process the transaction (minimum charge is not met), but the user is not warned about it. The Stripe pop-up is closed and the error is recorded in the console silently. opw-765775 --- addons/payment_stripe/i18n/payment_stripe.pot | 23 ++++++++++++++++++- addons/payment_stripe/models/payment.py | 9 +++++--- addons/payment_stripe/static/src/js/stripe.js | 9 ++++++++ .../static/src/xml/stripe_templates.xml | 21 +++++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 addons/payment_stripe/static/src/xml/stripe_templates.xml diff --git a/addons/payment_stripe/i18n/payment_stripe.pot b/addons/payment_stripe/i18n/payment_stripe.pot index 4a7a29f282f..b099535b381 100644 --- a/addons/payment_stripe/i18n/payment_stripe.pot +++ b/addons/payment_stripe/i18n/payment_stripe.pot @@ -40,11 +40,25 @@ msgstr "" msgid "Checkout Image URL" msgstr "" +#. module: payment_stripe +#. openerp-web +#: code:addons/payment_stripe/static/src/xml/stripe_templates.xml:15 +#, python-format +msgid "Close" +msgstr "" + #. module: payment_stripe #: model:ir.ui.view,arch_db:payment_stripe.stripe_s2s_form msgid "Confirm " msgstr "" +#. module: payment_stripe +#. openerp-web +#: code:addons/payment_stripe/static/src/xml/stripe_templates.xml:9 +#, python-format +msgid "Error" +msgstr "" + #. module: payment_stripe #: model:ir.ui.view,arch_db:payment_stripe.stripe_s2s_form msgid "Expiration Date" @@ -65,6 +79,13 @@ msgstr "" msgid "Payment Transaction" msgstr "" +#. module: payment_stripe +#. openerp-web +#: code:addons/payment_stripe/static/src/js/stripe.js:43 +#, python-format +msgid "Payment error" +msgstr "" + #. module: payment_stripe #: model:ir.model.fields,field_description:payment_stripe.field_payment_acquirer_stripe_publishable_key msgid "Stripe publishable key" @@ -84,7 +105,7 @@ msgstr "" #. module: payment_stripe #: code:addons/payment_stripe/models/payment.py:111 #, python-format -msgid "Stripe: invalid reply received from provider, missing reference" +msgid "Stripe: invalid reply received from provider, missing reference. Additional message: %s" msgstr "" #. module: payment_stripe diff --git a/addons/payment_stripe/models/payment.py b/addons/payment_stripe/models/payment.py index c306c5b4acd..72c797e6c7f 100644 --- a/addons/payment_stripe/models/payment.py +++ b/addons/payment_stripe/models/payment.py @@ -116,10 +116,13 @@ class PaymentTransactionStripe(models.Model): def _stripe_form_get_tx_from_data(self, data): """ Given a data dict coming from stripe, verify it and find the related transaction record. """ - reference = data['metadata']['reference'] + reference = data.get('metadata', {}).get('reference') if not reference: - error_msg = _('Stripe: invalid reply received from provider, missing reference') - _logger.error(error_msg, data['metadata']) + error_msg = _( + 'Stripe: invalid reply received from provider, missing reference. Additional message: %s' + % data.get('error', {}).get('message', '') + ) + _logger.error(error_msg) raise ValidationError(error_msg) tx = self.search([('reference', '=', reference)]) if not tx: diff --git a/addons/payment_stripe/static/src/js/stripe.js b/addons/payment_stripe/static/src/js/stripe.js index 77570e9b3ce..14e19775747 100644 --- a/addons/payment_stripe/static/src/js/stripe.js +++ b/addons/payment_stripe/static/src/js/stripe.js @@ -2,6 +2,11 @@ odoo.define('payment_stripe.stripe', function(require) { "use strict"; var ajax = require('web.ajax'); + var core = require('web.core'); + var _t = core._t; + var qweb = core.qweb; + ajax.loadXML('/payment_stripe/static/src/xml/stripe_templates.xml', qweb); + // The following currencies are integer only, see // https://stripe.com/docs/currencies#zero-decimal var int_currencies = [ @@ -33,6 +38,10 @@ odoo.define('payment_stripe.stripe', function(require) { }).done(function(data){ handler.isTokenGenerate = false; window.location.href = data; + }).fail(function(){ + var msg = arguments && arguments[1] && arguments[1].data && arguments[1].data.message; + var wizard = $(qweb.render('stripe.error', {'msg': msg || _t('Payment error')})); + wizard.appendTo($('body')).modal({'keyboard': true}); }); }, }); diff --git a/addons/payment_stripe/static/src/xml/stripe_templates.xml b/addons/payment_stripe/static/src/xml/stripe_templates.xml new file mode 100644 index 00000000000..c5966fe6274 --- /dev/null +++ b/addons/payment_stripe/static/src/xml/stripe_templates.xml @@ -0,0 +1,21 @@ + + + + + +