def process_transaction(data): # Get the username if not data.get("custom", None) or data.get("custom", None) == "None": username = None else: try: username = username_signer.loads(data["custom"]) except (BadPayload, BadData, BadSignature): username = None TransactionLog(data=data, username=username).save() txn_id = data.get("parent_txn_id") or data.get("txn_id") # Check if the transaction already exists in db. transaction = DonationTransaction.objects(transaction_id=txn_id).first() if transaction: pass else: transaction = DonationTransaction() transaction.username = username transaction.email = data["payer_email"] transaction.gross = float(data.get("mc_gross", 0)) transaction.fee = float(data.get("mc_fee", 0)) transaction.amount = transaction.gross - transaction.fee transaction.payment_type = data.get("payment_type", "") transaction.transaction_id = txn_id transaction_status = DonationTransactionStatus() transaction_status.status = data["payment_status"] transaction_status.reason = data.get("pending_reason", None) or data.get( "reason_code", None) transaction_status.valid = validate_transaction(data) transaction_status.gross = float(data.get("mc_gross", 0)) transaction_status.fee = float(data.get("mc_fee", 0)) transaction_status.complete_data = data transaction.payment_status_events.append(transaction_status) transaction.valid = validate_transaction(data) transaction.save()
def process_transaction(data): # Get the username if not data.get("custom", None) or data.get("custom", None) == "None": username = None else: try: username = username_signer.loads(data["custom"]) except (BadPayload, BadData, BadSignature): username = None TransactionLog(data=data, username=username).save() txn_id = data.get("parent_txn_id") or data.get("txn_id") # Check if the transaction already exists in db. transaction = DonationTransaction.objects(transaction_id=txn_id).first() if transaction: pass else: transaction = DonationTransaction() transaction.username = username transaction.email = data["payer_email"] transaction.gross = float(data.get("mc_gross", 0)) transaction.fee = float(data.get("mc_fee", 0)) transaction.amount = transaction.gross - transaction.fee transaction.payment_type = data.get("payment_type", "") transaction.transaction_id = txn_id transaction_status = DonationTransactionStatus() transaction_status.status = data["payment_status"] transaction_status.reason = data.get("pending_reason", None) or data.get("reason_code", None) transaction_status.valid = validate_transaction(data) transaction_status.gross = float(data.get("mc_gross", 0)) transaction_status.fee = float(data.get("mc_fee", 0)) transaction_status.complete_data = data transaction.payment_status_events.append(transaction_status) transaction.valid = validate_transaction(data) transaction.save()