[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.
This commit is contained in:
Nicolas Martinelli
2018-02-02 09:17:30 +01:00
committed by Nicolas Martinelli
parent f5e7b86686
commit ecfcaea080
+4 -4
View File
@@ -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()