Skip to content
This repository was archived by the owner on Jan 25, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions docs/topics/overall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ keys do not match request fields.
Braintree has some errors which it doesn't consider validation errors because
they are not specific to a submitted input field. However, Solitude still
displays these as validation errors so that error handling is consistent.
The error codes may be prefixed. For
`credit card processing errors <https://developers.braintreepayments.com/javascript+python/reference/general/processor-responses/authorization-responses>`_
the error code is prefixed with ``cc-``.

Example failure from Braintree::

Expand All @@ -121,7 +118,19 @@ Example failure from Braintree::
{"message": "Payment method token is invalid.", "code": "91903"}
],
"__all__": [
{"message": "Credit card denied", "code": "cc-2000"}
{"message": "Credit card denied", "code": "2000"}
]
}
}

If no error can be found solitude will add the message to the response with code of `unknown`, for example::

.. code:json::

{
"braintree": {
"__all__": [
{"message": "Invalid Secure Payment Data", "code": "unknown"}
]
}
}
13 changes: 10 additions & 3 deletions lib/brains/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ def format(self):
if cc_result:
log.debug('credit card processing error: {r}'.format(r=cc_result))
errors[NON_FIELD_ERRORS].append({
# Prefix the actual error code with `cc-' so that it's sort
# of namespaced against other types of error codes.
'code': 'cc-{c}'.format(c=cc_result.processor_response_code),
'code': cc_result.processor_response_code,
'message': cc_result.processor_response_text,
})

# If we haven't found anything fall back to grabbing the message
# at least.
# See https://github.com/braintree/braintree_python/issues/57
if not errors:
errors[NON_FIELD_ERRORS].append({
'code': 'unknown',
'message': self.error.result.message
})

return {'braintree': dict(errors)}


Expand Down
27 changes: 26 additions & 1 deletion lib/brains/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ def CreditCardError():
)


def InsecureError():
return ErrorResult(
'gateway', {
'errors': {},
'message': 'Invalid Secure Payment Data',
'transaction': {
'amount': 1,
'tax_amount': 1,
'processor_response_code': 'blah-code',
'processor_response_text': 'blah',
},
}
)


class TestBraintreeError(TestCase):

def setUp(self):
Expand All @@ -80,7 +95,17 @@ def test_credit_card_error(self):
'braintree': {
NON_FIELD_ERRORS: [{
'message': 'processor response',
'code': 'cc-processor-code',
'code': 'processor-code',
}]
}
})

def test_other_error(self):
eq_(self.brain(BraintreeResultError(InsecureError())).format(), {
'braintree': {
NON_FIELD_ERRORS: [{
'message': 'Invalid Secure Payment Data',
'code': 'unknown',
}]
}
})