@@ -291,18 +291,14 @@ def _uri(s: str) -> str:
291291 return s
292292
293293
294- def _validate_last_digits (req ):
295- cc = req .get ("credit_card" )
296- if cc is None :
297- return
298-
299- iin = cc .get ("issuer_id_number" )
294+ def _validate_last_digits (cc ):
295+ iin = cc .get ("issuer_id_number" , None )
300296 if iin is None :
301297 return
302298
303299 if iin and len (iin ) == 8 :
304- last_digits = cc .get ("last_digits" )
305- last_4_digits = cc .get ("last_4_digits" )
300+ last_digits = cc .get ("last_digits" , None )
301+ last_4_digits = cc .get ("last_4_digits" , None )
306302 if last_digits and len (last_digits ) != 2 :
307303 raise LengthInvalid (
308304 "last_digits must be two digits when the issuer_id_number is eight digits."
@@ -315,19 +311,19 @@ def _validate_last_digits(req):
315311
316312
317313validate_transaction = Schema (
318- All (
319- {
320- "account " : {
321- "user_id " : str ,
322- "username_md5" : _md5 ,
323- } ,
324- "billing " : _address ,
325- "payment " : {
326- "processor " : _payment_processor ,
327- "was_authorized " : bool ,
328- "decline_code" : str ,
329- },
330- "credit_card" : {
314+ {
315+ "account" : {
316+ "user_id " : str ,
317+ "username_md5 " : _md5 ,
318+ } ,
319+ "billing" : _address ,
320+ "payment " : {
321+ "processor " : _payment_processor ,
322+ "was_authorized " : bool ,
323+ "decline_code " : str ,
324+ } ,
325+ "credit_card" : All (
326+ {
331327 "avs_result" : _single_char ,
332328 "bank_name" : str ,
333329 "bank_phone_country_code" : _telephone_country_code ,
@@ -339,46 +335,46 @@ def _validate_last_digits(req):
339335 "token" : _credit_card_token ,
340336 "was_3d_secure_successful" : bool ,
341337 },
342- "custom_inputs" : {_custom_input_key : _custom_input_value },
343- "device" : {
344- "accept_language" : str ,
345- "ip_address" : _ip_address ,
346- "session_age" : All (_any_number , Range (min = 0 )),
347- "session_id" : str ,
348- "user_agent" : str ,
349- },
350- "email" : {
351- "address" : _email_or_md5 ,
352- "domain" : _hostname ,
353- },
354- "event" : {
355- "shop_id" : str ,
356- "time" : _rfc3339_datetime ,
357- "type" : _event_type ,
358- "transaction_id" : str ,
359- },
360- "order" : {
361- "affiliate_id" : str ,
362- "amount" : _price ,
363- "currency" : _currency_code ,
364- "discount_code" : str ,
365- "has_gift_message" : bool ,
366- "is_gift" : bool ,
367- "referrer_uri" : _uri ,
368- "subaffiliate_id" : str ,
369- },
370- "shipping" : _shipping_address ,
371- "shopping_cart" : [
372- {
373- "category" : str ,
374- "item_id" : str ,
375- "price" : _price ,
376- "quantity" : All (int , Range (min = 1 )),
377- },
378- ],
338+ _validate_last_digits ,
339+ ),
340+ "custom_inputs" : {_custom_input_key : _custom_input_value },
341+ "device" : {
342+ "accept_language" : str ,
343+ "ip_address" : _ip_address ,
344+ "session_age" : All (_any_number , Range (min = 0 )),
345+ "session_id" : str ,
346+ "user_agent" : str ,
347+ },
348+ "email" : {
349+ "address" : _email_or_md5 ,
350+ "domain" : _hostname ,
379351 },
380- _validate_last_digits ,
381- )
352+ "event" : {
353+ "shop_id" : str ,
354+ "time" : _rfc3339_datetime ,
355+ "type" : _event_type ,
356+ "transaction_id" : str ,
357+ },
358+ "order" : {
359+ "affiliate_id" : str ,
360+ "amount" : _price ,
361+ "currency" : _currency_code ,
362+ "discount_code" : str ,
363+ "has_gift_message" : bool ,
364+ "is_gift" : bool ,
365+ "referrer_uri" : _uri ,
366+ "subaffiliate_id" : str ,
367+ },
368+ "shipping" : _shipping_address ,
369+ "shopping_cart" : [
370+ {
371+ "category" : str ,
372+ "item_id" : str ,
373+ "price" : _price ,
374+ "quantity" : All (int , Range (min = 1 )),
375+ },
376+ ],
377+ },
382378)
383379
384380
0 commit comments