示例#1
0
def donate():
    funds_target = 49
    donations = DonationTransaction.objects(valid=True)
    transactions = Transaction.objects()
    return render_template(
        'donate.html',
        funds_target=funds_target,
        funds_current=transactions.sum('amount'),
        total_fees=donations.sum('fee'),
        total_donations=DonationTransaction.objects(valid=True, gross__gt=0).sum('gross'),
        num_donations=len(donations),
        top_donations=donations.order_by('-amount').limit(5).only('gross', 'fee', 'username', 'valid'),
        signed_user=username_signer.dumps(current_user.name) if current_user.is_authenticated() else None
        )
示例#2
0
def donate():
    funds_target = 49
    donations = DonationTransaction.objects(valid=True)
    transactions = Transaction.objects()
    return render_template(
        'donate.html',
        funds_target=funds_target,
        funds_current=transactions.sum('amount'),
        total_fees=donations.sum('fee'),
        total_donations=DonationTransaction.objects(valid=True,
                                                    gross__gt=0).sum('gross'),
        num_donations=len(donations),
        top_donations=donations.order_by('-amount').limit(5).only(
            'gross', 'fee', 'username', 'valid'),
        signed_user=username_signer.dumps(current_user.name)
        if current_user.is_authenticated() else None)
示例#3
0
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()
示例#4
0
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()