Skip to content
Browse files

[FIX] payment_stripe_sca: better error handling

In some cases, Stripe will return the result of a transaction with
a faulty HTTP Status (e.g. 4XX statuses) - not because the request
was malformed, but because the payment failed. It is a bit unfortunate
that Stripe would not differentiate between payment status and request
validity, but that's the state of things.

This commit ensures that such a response will be logged correctly, by
removing a call to `raise_for_status` on the response object and instead
forwarding the response's json to the validation flow.

While testing this fix, it became apparent that some error message
processing in the frontend was not correctly handled as well - instead
of purely rejecting the promise, a failed payment should still send its
payload to the backend, to allow the server to put the transaction in
the correct state according to the response.
  • Loading branch information
dbo-odoo committed Dec 2, 2019
1 parent b383a69 commit 3c976db914e2f18d8db86e11d84f89f6eb02d2ac
@@ -53,13 +53,6 @@ def _stripe_request(self, url, data=False, method="POST"):
"Stripe-Version": "2019-05-16", # SetupIntent need a specific version
resp = requests.request(method, url, data=data, headers=headers)
except HTTPError:
stripe_error = resp.json().get('error', {}).get('message', '')
error_msg = " " + (_("Stripe gave us the following info about the problem: '%s'") % stripe_error)
raise ValidationError(error_msg)
return resp.json()

def _create_stripe_session(self, kwargs):
@@ -310,11 +303,8 @@ def _stripe_s2s_validate_tree(self, tree):
return True
error = tree.get("failure_message") or tree['error']['message']
vals.update({"state_message": error})
error = tree.get("failure_message") or tree.get('error', {}).get('message')
return False

def _stripe_form_get_invalid_parameters(self, data):
@@ -21,12 +21,9 @@ odoo.define('payment_stripe_sca.processing', function (require) {
.then(function(result) {defer.resolve(result)})
}).then(function(result) {
if (result.error) {
return $.Deferred().reject({"message": {"data": { "message": result.error.message}}});
return rpc.query({
route: '/payment/stripe/s2s/process_payment_intent',
params: _.extend({}, result.paymentIntent, {reference: tx.reference}),
params: _.extend({}, result.paymentIntent, {reference: tx.reference, error: result.error}),
}).then(function(result) {
window.location = '/payment/process';

0 comments on commit 3c976db

Please sign in to comment.
You can’t perform that action at this time.