Skip to content

Commit

Permalink
Add gateway_error_code to TransactionError
Browse files Browse the repository at this point in the history
  • Loading branch information
csmb committed Jul 31, 2015
1 parent b0c7dc9 commit fb54ff9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

- Add `gateway_error_code` to `TransactionError`

## Version 2.2.13 July 31, 2015

- Require a version of six library >= 1.4.0
Expand Down
9 changes: 5 additions & 4 deletions recurly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Address(Resource):
'state',
'zip',
'country',
'phone'
'phone',
)


Expand Down Expand Up @@ -664,7 +664,7 @@ class TransactionBillingInfo(recurly.Resource):
'card_type',
'month',
'year',
'transaction_uuid'
'transaction_uuid',
)


Expand All @@ -675,7 +675,7 @@ class TransactionAccount(recurly.Resource):
'last_name',
'company',
'email',
'account_code'
'account_code',
)
_classes_for_nodename = {'billing_info': TransactionBillingInfo}

Expand All @@ -693,7 +693,8 @@ class TransactionError(recurly.Resource):
'merchant_message',
'error_caterogy',
'customer_message',
'error_code'
'error_code',
'gateway_error_code',
)


Expand Down
26 changes: 26 additions & 0 deletions tests/fixtures/transaction/declined-transaction.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
POST https://api.recurly.com/v2/transactions HTTP/1.1
Accept: application/xml
Authorization: Basic YXBpa2V5Og==
User-Agent: recurly-python/{version}
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<transaction>
<account>
<account_code>transactionmock</account_code>
</account>
<currency>USD</currency>
<amount_in_cents type="integer">1000</amount_in_cents>
</transaction>

HTTP/1.1 422
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<transaction_error>
<error_code>insufficient_funds</error_code>
<error_category>soft</error_category>
<customer_message lang="en-US">The transaction was declined due to insufficient funds in your account. Please use a different card or contact your bank.</customer_message>
<merchant_message lang="en-US">The card has insufficient funds to cover the cost of the transaction.</merchant_message>
<gateway_error_code>123</gateway_error_code>
</transaction_error>
22 changes: 22 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,28 @@ def test_transaction(self):
with self.mock_request('transaction/account-deleted.xml'):
account.delete()

def failed_transaction(self):
transaction = Transaction(
amount_in_cents=1000,
currency='USD',
account=Account(),
)

with self.mock_request('transaction/declined-stransaction.xml'):
try:
transaction.save()
except ValidationError as _error:
error = _error
else:
self.fail("Posting a transaction without an account code did not raise a ValidationError")

self.assertEqual(transaction.error_code, 'insufficient_funds')
self.assertEqual(transaction.error_category, 'soft')
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')


def test_transaction_with_balance(self):
transaction = Transaction(
amount_in_cents=1000,
Expand Down

0 comments on commit fb54ff9

Please sign in to comment.