예제 #1
0
def test_create_next_double_payment(caplog, creation_params):
    creation_params['registration'].transaction = MagicMock(
        status=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
예제 #2
0
파일: util.py 프로젝트: mkopcic/indico
def register_transaction(registration,
                         amount,
                         currency,
                         action,
                         provider=None,
                         data=None):
    """Create a new transaction for a certain transaction action.

    :param registration: the `Registration` associated to 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 = PaymentTransaction.create_next(registration=registration,
                                                     action=action,
                                                     amount=amount,
                                                     currency=currency,
                                                     provider=provider,
                                                     data=data)
    if new_transaction:
        db.session.flush()
        if new_transaction.status == TransactionStatus.successful:
            registration.update_state(paid=True)
        elif new_transaction.status == TransactionStatus.cancelled:
            registration.update_state(paid=False)
        notify_registration_state_update(registration)
        return new_transaction
예제 #3
0
파일: util.py 프로젝트: OmeGak/indico
def register_transaction(registration, amount, currency, action, provider=None, data=None):
    """Creates a new transaction for a certain transaction action.

    :param registration: the `Registration` associated to 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(
        registration=registration, action=action, amount=amount, currency=currency, provider=provider, data=data
    )
    if new_transaction:
        db.session.flush()
        if double_payment:
            notify_double_payment(registration)
        if new_transaction.status == TransactionStatus.successful:
            registration.update_state(paid=True)
        elif new_transaction.status == TransactionStatus.cancelled:
            registration.update_state(paid=False)
        notify_registration_state_update(registration)
        return new_transaction
예제 #4
0
    def adjust_payment_form_data(self, data):
        """Prepare the payment form shown to registrants."""
        # indico does not seem to provide stacking of settings
        # we merge event on top of global settings, but remove defaults
        event_settings = data['event_settings']
        global_settings = data['settings']
        plugin_settings = {
            key: event_settings[key]
            if event_settings.get(key) is not None else global_settings[key]
            for key in (set(event_settings) | set(global_settings))
        }
        # parameters of the transaction - amount, currency, ...
        transaction = self._get_transaction_parameters(data, plugin_settings)
        init_response = self._init_payment_page(
            sixpay_url=plugin_settings['url'],
            transaction_data=transaction,
        )
        data['payment_url'] = init_response['RedirectUrl']

        # create pending transaction and store Saferpay transaction token
        if not PaymentTransaction.create_next(
                registration=data['registration'],
                amount=data['amount'],
                currency=data['currency'],
                action=TransactionAction.pending,
                provider=provider,
                data={'Init_PP_response': init_response}):
            data['registration'].transaction.data = {
                'Init_PP_response': init_response
            }
        return data
예제 #5
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 = PaymentTransaction.create_next(**creation_params)
    log = extract_logs(caplog, one=True, name='indico.payment')
    assert transaction is None
    assert 'TEST_EXCEPTION' in log.message
    if log.exc_info:
        assert log.exc_info[0] == exception
예제 #6
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 = PaymentTransaction.create_next(**creation_params)
    log = extract_logs(caplog, one=True, name='indico.payment')
    assert transaction is None
    assert 'TEST_EXCEPTION' in log.message
    if log.exc_info:
        assert log.exc_info[0] == exception
예제 #7
0
def test_create_next(creation_params):
    transaction, double_payment = PaymentTransaction.create_next(**creation_params)
    assert isinstance(transaction, PaymentTransaction)
    assert not double_payment
예제 #8
0
def test_create_next(creation_params):
    transaction = PaymentTransaction.create_next(**creation_params)
    assert isinstance(transaction, PaymentTransaction)
예제 #9
0
def test_create_next_double_payment(caplog, creation_params):
    creation_params['registration'].transaction = MagicMock(status=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