Skip to content

Commit

Permalink
[FIX] payment_stripe: charge creation failed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nim-odoo committed Aug 17, 2017
1 parent c9cd44c commit 99e5a60
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
23 changes: 22 additions & 1 deletion addons/payment_stripe/i18n/payment_stripe.pot
Expand Up @@ -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 <span class=\"fa fa-long-arrow-right\"/>"
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"
Expand All @@ -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"
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions addons/payment_stripe/models/payment.py
Expand Up @@ -116,10 +116,13 @@ def stripe_s2s_do_transaction(self, **kwargs):
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:
Expand Down
9 changes: 9 additions & 0 deletions addons/payment_stripe/static/src/js/stripe.js
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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});
});
},
});
Expand Down
21 changes: 21 additions & 0 deletions addons/payment_stripe/static/src/xml/stripe_templates.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="stripe.error">
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&amp;times;</button>
<h4 class="modal-title">Error</h4>
</div>
<div class="modal-body">
<t t-esc="msg"></t>
</div>
<div class="modal-footer">
<a href="#" class="btn btn-link btn-xs" data-dismiss="modal">Close</a>
</div>
</div>
</div>
</div>
</t>
</templates>

0 comments on commit 99e5a60

Please sign in to comment.