def decode_credit_card_from_dict(dct): if '__credit_card__' in dct: d = dct.copy() d.pop('__credit_card__') d.pop('card_type') retval = CreditCard(**d) card_type = dct.get('card_type', None) # put there by Gateway.validate_card if card_type is not None: # Get the credit card class with this name retval.card_type = getattr(billing.utils.credit_card, card_type) return retval return dct