def from_json(cls, json): """ Create a new Transaction from the given json. This only works for transactions, skipping refunds and bank transfers. :param json: :return: """ if not json: return parser = JSONSchema.transaction(json) transaction_type = TransactionType(parser.get_transaction_type()) # Currently only handles Payment-type transactions if transaction_type is not TransactionType.PAYMENT: return date_created = string_to_timestamp(parser.get_date_created()) date_updated = string_to_timestamp(parser.get_date_updated()) date_completed = string_to_timestamp(parser.get_date_completed()) target = User.from_json(json=parser.get_target()) actor = User.from_json(json=parser.get_actor()) device_used = get_phone_model_from_json(parser.get_actor_app()) comments_list = parser.get_comments() comments = [ Comment.from_json(json=comment) for comment in comments_list ] if comments_list else [] return cls(story_id=parser.get_story_id(), payment_id=parser.get_payment_id(), date_completed=date_completed, date_created=date_created, date_updated=date_updated, payment_type=parser.get_type(), amount=parser.get_amount(), audience=parser.get_audience(), note=parser.get_story_note(), status=parser.get_status(), device_used=device_used, actor=actor, target=target, comments=comments, json=json)
def from_json(cls, json): """ Create a new Transaction from the given json. This only works for transactions, skipping refunds and bank transfers. :param json: :return: """ if not json: return parser = JSONSchema.transaction(json) transaction_type = TransactionType(parser.get_transaction_type()) # Skip money transfers to/from bank accounts and refunds if transaction_type == TransactionType.REFUND or transaction_type == TransactionType.TRANSFER: return date_created = string_to_timestamp(parser.get_date_created()) date_updated = string_to_timestamp(parser.get_date_updated()) date_completed = string_to_timestamp(parser.get_date_completed()) target = User.from_json(json=parser.get_target()) actor = User.from_json(json=parser.get_actor()) device_used = get_phone_model_from_json(parser.get_actor_app()) return cls(story_id=parser.get_story_id(), payment_id=parser.get_payment_id(), date_completed=date_completed, date_created=date_created, date_updated=date_updated, payment_type=parser.get_type(), amount=parser.get_amount(), audience=parser.get_audience(), note=parser.get_story_note(), status=parser.get_status(), device_used=device_used, actor=actor, target=target)
def from_json(cls, json): parser = JSONSchema.transaction(json) date_created = string_to_timestamp(parser.get_date_created()) date_updated = string_to_timestamp(parser.get_date_updated()) date_completed = string_to_timestamp(parser.get_date_completed()) target = User.from_json(json=parser.get_target()) actor = User.from_json(json=parser.get_actor()) device_used = get_phone_model_from_json(parser.get_actor_app()) return cls(story_id=parser.get_story_id(), payment_id=parser.get_payment_id(), date_completed=date_completed, date_created=date_created, date_updated=date_updated, payment_type=parser.get_type(), audience=parser.get_audience(), status=parser.get_status(), note=parser.get_story_note(), device_used=device_used, actor=actor, target=target)