summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2018-02-01 14:30:34 +0100
committerNicolas Martinelli <nim-odoo@users.noreply.github.com>2018-02-02 09:17:30 +0100
commitecfcaea080d4813a99f66ae11ff6fecd57c8c278 (patch)
treeb99236471a13a68fd8d3c2595513c99d56d29358 /addons
parentf5e7b866860436782ade53308da1ff725be1f124 (diff)
[FIX] payment_stripe: correctly handle error
If there is an error, we should handle it first. Otherwise, some keys might not be found in the results (e.g. 'object' or type') and cause a crash.
Diffstat (limited to 'addons')
-rw-r--r--addons/payment_stripe/models/payment.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/addons/payment_stripe/models/payment.py b/addons/payment_stripe/models/payment.py
index 76b8e3aebf7..c4e2760f228 100644
--- a/addons/payment_stripe/models/payment.py
+++ b/addons/payment_stripe/models/payment.py
@@ -263,6 +263,10 @@ class PaymentTokenStripe(models.Model):
def _stripe_create_customer(self, token, description=None, acquirer_id=None):
+ if token.get('error'):
+ _logger.error('payment.token.stripe_create_customer: Token error:\n%s', pprint.pformat(token['error']))
+ raise Exception(token['error']['message'])
+
if token['object'] != 'token':
_logger.error('payment.token.stripe_create_customer: Cannot create a customer for object type "%s"', token.get('object'))
raise Exception('We are unable to process your credit card information.')
@@ -271,10 +275,6 @@ class PaymentTokenStripe(models.Model):
_logger.error('payment.token.stripe_create_customer: Cannot create a customer for token type "%s"', token.get('type'))
raise Exception('We are unable to process your credit card information.')
- if token.get('error'):
- _logger.error('payment.token.stripe_create_customer: Token error:\n%s', pprint.pformat(token['error']))
- raise Exception(token['error']['message'])
-
payment_acquirer = self.env['payment.acquirer'].browse(acquirer_id or self.acquirer_id.id)
url_customer = 'https://%s/customers' % payment_acquirer._get_stripe_api_url()