summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjev-odoo <jev@odoo.com>2020-05-27 08:23:09 +0000
committerjev-odoo <jev@odoo.com>2020-05-29 09:36:02 +0000
commit013831b17699d05ee3adf1b7ba3a652f335d6044 (patch)
tree5bab29295acbe459964b47db78907ebfdbbd641c
parented2f14784dde25ff372dcf31ac1b2a3d40634972 (diff)
[FIX] payment_stripe: Request error handling with automatic flow
PR https://github.com/odoo/odoo/pull/49964 fixed manual payment flow but broke automatic payment flow. This commit should allow both by raising the exception only for manual flow, giving only an error for automatic flows. FW-PORT of https://github.com/odoo/odoo/pull/50908/commits/46e977a21743644a2e98344e3491f0dd6fcbe892 closes odoo/odoo#52151 X-original-commit: a40089d67b66b593a09b0fa4c4cd24f6ce5fcc71 Signed-off-by: Toufik Benjaa (tbe) <tbe@odoo.com>
-rw-r--r--addons/payment_stripe/controllers/main.py4
-rw-r--r--addons/payment_stripe/models/payment.py6
2 files changed, 7 insertions, 3 deletions
diff --git a/addons/payment_stripe/controllers/main.py b/addons/payment_stripe/controllers/main.py
index 5b5d70bcf6d..8d5f5bf65df 100644
--- a/addons/payment_stripe/controllers/main.py
+++ b/addons/payment_stripe/controllers/main.py
@@ -21,7 +21,7 @@ class StripeController(http.Controller):
def stripe_s2s_create_json_3ds(self, verify_validity=False, **kwargs):
if not kwargs.get('partner_id'):
kwargs = dict(kwargs, partner_id=request.env.user.partner_id.id)
- token = request.env['payment.acquirer'].browse(int(kwargs.get('acquirer_id'))).s2s_process(kwargs)
+ token = request.env['payment.acquirer'].browse(int(kwargs.get('acquirer_id'))).with_context(stripe_manual_payment=True).s2s_process(kwargs)
if not token:
res = {
@@ -46,7 +46,7 @@ class StripeController(http.Controller):
@http.route('/payment/stripe/s2s/create_setup_intent', type='json', auth='public', csrf=False)
def stripe_s2s_create_setup_intent(self, acquirer_id, **kwargs):
acquirer = request.env['payment.acquirer'].browse(int(acquirer_id))
- res = acquirer._create_setup_intent(kwargs)
+ res = acquirer.with_context(stripe_manual_payment=True)._create_setup_intent(kwargs)
return res.get('client_secret')
@http.route('/payment/stripe/s2s/process_payment_intent', type='json', auth='public', csrf=False)
diff --git a/addons/payment_stripe/models/payment.py b/addons/payment_stripe/models/payment.py
index 7ea1df1a37b..d13f80bec46 100644
--- a/addons/payment_stripe/models/payment.py
+++ b/addons/payment_stripe/models/payment.py
@@ -72,7 +72,11 @@ class PaymentAcquirerStripe(models.Model):
# cfr https://stripe.com/docs/error-codes
# these can be made customer-facing, as they usually indicate a problem with the payment
# (e.g. insufficient funds, expired card, etc.)
- if not resp.ok and not (400 <= resp.status_code < 500 and resp.json().get('error', {}).get('code')):
+ # if the context key `stripe_manual_payment` is set then these errors will be raised as ValidationError,
+ # otherwise, they will be silenced, and the will be returned no matter the status.
+ # This key should typically be set for payments in the present and unset for automated payments
+ # (e.g. through crons)
+ if not resp.ok and self._context.get('stripe_manual_payment') and (400 <= resp.status_code < 500 and resp.json().get('error', {}).get('code')):
try:
resp.raise_for_status()
except HTTPError: