diff --git a/recurly/__init__.py b/recurly/__init__.py
index f0bbd974..0a853895 100644
--- a/recurly/__init__.py
+++ b/recurly/__init__.py
@@ -1785,6 +1785,7 @@ class TransactionError(recurly.Resource):
'customer_message',
'error_code',
'gateway_error_code',
+ 'decline_code'
)
class TransactionFraudInfo(recurly.Resource):
diff --git a/recurly/errors.py b/recurly/errors.py
index a7ddf28c..e928fe9d 100644
--- a/recurly/errors.py
+++ b/recurly/errors.py
@@ -192,6 +192,13 @@ def three_d_secure_action_token_id(self):
if el is not None:
return el.text
+ @property
+ def decline_code(self):
+ """Decline code from the issuer"""
+ el = self.response_doc.find('decline_code')
+ if el is not None:
+ return el.text
+
class ValidationError(ClientError):
diff --git a/tests/fixtures/transaction/declined-transaction.xml b/tests/fixtures/transaction/declined-transaction.xml
index fde507da..39142ca4 100644
--- a/tests/fixtures/transaction/declined-transaction.xml
+++ b/tests/fixtures/transaction/declined-transaction.xml
@@ -25,5 +25,6 @@ Content-Type: application/xml; charset=utf-8
The transaction was declined due to insufficient funds in your account. Please use a different card or contact your bank.
The card has insufficient funds to cover the cost of the transaction.
123
+ insufficient_funds
diff --git a/tests/test_resources.py b/tests/test_resources.py
index 22db0afc..b1ea31b9 100644
--- a/tests/test_resources.py
+++ b/tests/test_resources.py
@@ -2649,6 +2649,7 @@ def failed_transaction(self):
self.assertEqual(transaction.customer_message, 'The transaction was declined due to insufficient funds in your account. Please use a different card or contact your bank.')
self.assertEqual(transaction.merchant_message, 'The card has insufficient funds to cover the cost of the transaction.')
self.assertEqual(transaction.gateway_error_code, '123')
+ self.assertEqual(transaction.decline_code, 'insufficient_funds')
def test_transaction_with_balance(self):
diff --git a/tests/tests_errors.py b/tests/tests_errors.py
index b83d1cd2..7f92bd24 100644
--- a/tests/tests_errors.py
+++ b/tests/tests_errors.py
@@ -42,6 +42,7 @@ def test_transaction_error_property(self):
self.assertEqual(transaction_error.customer_message, "The transaction was declined due to insufficient funds in your account. Please use a different card or contact your bank.")
self.assertEqual(transaction_error.merchant_message, "The card has insufficient funds to cover the cost of the transaction.")
self.assertEqual(transaction_error.gateway_error_code, "123")
+ self.assertEqual(transaction_error.decline_code, 'insufficient_funds')
def test_transaction_error_code_property(self):
""" Test ValidationError class 'transaction_error_code' property"""