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 @@ + + + + + +