@@ -79,7 +79,11 @@ def _find_buyer_account(self):
79
79
if not filtered_accounts :
80
80
buyer = self ._create_buyer_account ()
81
81
else :
82
- buyer = filtered_accounts [0 ]
82
+ for account in filtered_accounts :
83
+ # this account will fail any debit, so don't use it
84
+ if account .email_address == 'stephen@hawking.com' :
85
+ continue
86
+ buyer = account
83
87
return buyer
84
88
85
89
def test_merchant_expectations (self ):
@@ -149,6 +153,23 @@ def test_valid_international_address(self):
149
153
self .assertEqual (card .street_address ,
150
154
card_payload ['street_address' ])
151
155
156
+ def test_bad_card (self ):
157
+ mp = balanced .Marketplace .query .one ()
158
+ card_payload = dict (self .us_card_payload )
159
+ card_payload ['card_number' ] = cards .AUTH_INVALID_CARD
160
+ bad_card = balanced .Card (** card_payload ).save ()
161
+ bad_card_uri = bad_card .uri
162
+ buyer = mp .create_buyer (
163
+ email_address = 'stephen@hawking.com' ,
164
+ card_uri = bad_card_uri ,
165
+ meta = {'foo' : 'bar' },
166
+ )
167
+ with self .assertRaises (requests .HTTPError ) as exc :
168
+ buyer .debit (777 )
169
+ the_exception = exc .exception
170
+ self .assertEqual (the_exception .status_code , 402 )
171
+ self .assertEqual (the_exception .category_code , 'card-declined' )
172
+
152
173
def test_transactions_using_second_card (self ):
153
174
mp = balanced .Marketplace .query .one ()
154
175
card_payload = dict (self .us_card_payload )
0 commit comments