def record_purchase(params, order):
 ccnum_str = params.get('card_accountNumber', '')
 first_digit = re.search('\\d', ccnum_str)
 if first_digit:
  ccnum = ccnum_str[first_digit.start():]
 else:
  ccnum = '####'
 order.purchase(first=params.get('billTo_firstName', ''), last=params.get('billTo_lastName', ''), street1=params.get('billTo_street1', ''), street2=params.get('billTo_street2', ''), city=params.get('billTo_city', ''), state=params.get('billTo_state', ''), country=params.get('billTo_country', ''), postalcode=params.get('billTo_postalCode', ''), ccnum=ccnum, cardtype=CARDTYPE_MAP[params.get('card_cardType', 'UNKNOWN')], processor_reply_dump=json.dumps(params))

def record_purchase ( params , order ) : ccnum_str = params . get ( 'card_accountNumber' , '' ) first_digit = re . search ( '\\d' , ccnum_str ) if first_digit : ccnum = ccnum_str [ first_digit . start ( ) : ] else : ccnum = '####' order . purchase ( first = params . get ( 'billTo_firstName' , '' ) , last = params . get ( 'billTo_lastName' , '' ) , street1 = params . get ( 'billTo_street1' , '' ) , street2 = params . get ( 'billTo_street2' , '' ) , city = params . get ( 'billTo_city' , '' ) , state = params . get ( 'billTo_state' , '' ) , country = params . get ( 'billTo_country' , '' ) , postalcode = params . get ( 'billTo_postalCode' , '' ) , ccnum = ccnum , cardtype = CARDTYPE_MAP [ params . get ( 'card_cardType' , 'UNKNOWN' ) ] , processor_reply_dump = json . dumps ( params ) )
record the purchase and run purchased_callbacks .