<s> from __future__ import unicode_literals <EOL> from django . dispatch import Signal <EOL> from dateutil . parser import parse <EOL> import json <EOL> from pagseguro . settings import TRANSACTION_STATUS <EOL> checkout_realizado = Signal ( providing_args = [ '<STR_LIT:data>' ] ) <EOL> checkout_realizado_com_sucesso = Signal ( providing_args = [ '<STR_LIT:data>' ] ) <EOL> checkout_realizado_com_erro = Signal ( providing_args = [ '<STR_LIT:data>' ] ) <EOL> notificacao_recebida = Signal ( providing_args = [ '<STR_LIT>' ] ) <EOL> notificacao_status_aguardando = Signal ( providing_args = [ '<STR_LIT>' ] ) <EOL> notificacao_status_em_analise = Signal ( providing_args = [ '<STR_LIT>' ] ) <EOL> notificacao_status_pago = Signal ( providing_args = [ '<STR_LIT>' ] ) <EOL> notificacao_status_disponivel = Signal ( providing_args = [ '<STR_LIT>' ] ) <EOL> notificacao_status_em_disputa = Signal ( providing_args = [ '<STR_LIT>' ] ) <EOL> notificacao_status_devolvido = Signal ( providing_args = [ '<STR_LIT>' ] ) <EOL> notificacao_status_cancelado = Signal ( providing_args = [ '<STR_LIT>' ] ) <EOL> NOTIFICATION_STATUS = { <EOL> '<STR_LIT:1>' : notificacao_status_aguardando , <EOL> '<STR_LIT:2>' : notificacao_status_em_analise , <EOL> '<STR_LIT:3>' : notificacao_status_pago , <EOL> '<STR_LIT:4>' : notificacao_status_disponivel , <EOL> '<STR_LIT:5>' : notificacao_status_em_disputa , <EOL> '<STR_LIT>' : notificacao_status_devolvido , <EOL> '<STR_LIT>' : notificacao_status_cancelado <EOL> } <EOL> def save_checkout ( sender , data , ** kwargs ) : <EOL> from pagseguro . models import Checkout <EOL> checkout = Checkout ( <EOL> date = data . get ( '<STR_LIT:date>' ) , <EOL> success = data . get ( '<STR_LIT:success>' ) <EOL> ) <EOL> if checkout . success : <EOL> checkout . code = data . get ( '<STR_LIT:code>' ) <EOL> else : <EOL> checkout . message = data . get ( '<STR_LIT:message>' ) <EOL> checkout . save ( ) <EOL> def update_transaction ( sender , transaction , ** kwargs ) : <EOL> from pagseguro . models import Transaction , TransactionHistory <EOL> trans = transaction <EOL> try : <EOL> transaction = Transaction . objects . get ( code = trans . get ( '<STR_LIT:code>' ) ) <EOL> except Transaction . DoesNotExist : <EOL> transaction = Transaction . objects . create ( <EOL> code = trans . get ( '<STR_LIT:code>' ) , <EOL> status = TRANSACTION_STATUS [ trans . get ( '<STR_LIT:status>' ) ] , <EOL> date = parse ( trans . get ( '<STR_LIT:date>' ) ) , <EOL> last_event_date = parse ( trans . get ( '<STR_LIT>' ) ) , <EOL> content = json . dumps ( trans , indent = <NUM_LIT:2> ) , <EOL> reference = trans . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> transaction . status = TRANSACTION_STATUS [ trans . get ( '<STR_LIT:status>' ) ] <EOL> transaction . last_event_date = parse ( trans . get ( '<STR_LIT>' ) ) <EOL> transaction . content = json . dumps ( trans , indent = <NUM_LIT:2> ) <EOL> transaction . save ( ) <EOL> TransactionHistory . objects . create ( <EOL> transaction = transaction , <EOL> status = TRANSACTION_STATUS [ trans . get ( '<STR_LIT:status>' ) ] , <EOL> date = parse ( trans . get ( '<STR_LIT>' ) ) <EOL> ) </s>
