[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>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user