diff options
| -rw-r--r-- | addons/payment_stripe/controllers/main.py | 4 | ||||
| -rw-r--r-- | addons/payment_stripe/models/payment.py | 6 |
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: |
