示例#1
0
def register_transaction(registrant,
                         amount,
                         currency,
                         action,
                         provider=None,
                         data=None):
    """Creates a new transaction for a certain transaction action.

    :param registrant: the `Registrant` of the transaction
    :param amount: the (strictly positive) amount of the transaction
    :param currency: the currency used for the transaction
    :param action: the `TransactionAction` of the transaction
    :param provider: the payment method name of the transaction,
                     or '_manual' if no payment method has been used
    :param data: arbitrary JSON-serializable data specific to the
                 transaction's provider
    """
    new_transaction, double_payment = PaymentTransaction.create_next(
        registrant=registrant,
        amount=amount,
        currency=currency,
        action=action,
        provider=provider,
        data=data)
    if new_transaction:
        db.session.add(new_transaction)
        db.session.flush()
        if double_payment:
            notify_double_payment(registrant)
        if new_transaction.status == TransactionStatus.successful:
            notify_payment_confirmation(registrant, amount)
        return new_transaction
示例#2
0
def test_create_next_with_exception(caplog, mocker, creation_params, exception):
    mocker.patch.object(TransactionStatusTransition, 'next')
    TransactionStatusTransition.next.side_effect = exception('TEST_EXCEPTION')
    transaction, double_payment = PaymentTransaction.create_next(**creation_params)
    log = extract_logs(caplog, one=True, name='indico.payment')
    assert transaction is None
    assert double_payment is None
    assert 'TEST_EXCEPTION' in log.message
    if log.exc_info:
        assert log.exc_info[0] == exception
示例#3
0
文件: util.py 项目: umipolaris/indico
def register_transaction(registrant, amount, currency, action, provider=None, data=None):
    """Creates a new transaction for a certain transaction action.

    :param registrant: the `Registrant` of the transaction
    :param amount: the (strictly positive) amount of the transaction
    :param currency: the currency used for the transaction
    :param action: the `TransactionAction` of the transaction
    :param provider: the payment method name of the transaction,
                     or '_manual' if no payment method has been used
    :param data: arbitrary JSON-serializable data specific to the
                 transaction's provider
    """
    new_transaction, double_payment = PaymentTransaction.create_next(registrant=registrant, amount=amount,
                                                                     currency=currency, action=action,
                                                                     provider=provider, data=data)
    if new_transaction:
        db.session.add(new_transaction)
        db.session.flush()
        if double_payment:
            notify_double_payment(registrant)
        if new_transaction.status == TransactionStatus.successful:
            notify_payment_confirmation(registrant, amount)
        return new_transaction
示例#4
0
def test_create_next_double_payment(caplog, create_transaction, creation_params):
    create_transaction(TransactionStatus.successful)
    _, double_payment = PaymentTransaction.create_next(**creation_params)
    log = extract_logs(caplog, one=True, name='indico.payment').message
    assert 'already paid' in log
    assert double_payment
示例#5
0
def test_create_next(creation_params):
    transaction, double_payment = PaymentTransaction.create_next(**creation_params)
    assert isinstance(transaction, PaymentTransaction)
    assert not double_payment