Esempio n. 1
0
def test_refund_incorrect_token(payment_txn_captured, sandbox_braintree_gateway_config):
    payment = payment_txn_captured
    amount = Decimal("10.00")

    payment_info = create_payment_information(payment, "token", amount)
    with pytest.raises(BraintreeException) as e:
        refund(payment_info, sandbox_braintree_gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
Esempio n. 2
0
def test_refund_incorrect_token(mock_gateway, payment_txn_captured,
                                braintree_not_found_error, gateway_config):
    payment = payment_txn_captured
    amount = Decimal('10.00')

    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))

    payment_info = create_payment_information(payment, 'token', amount)
    with pytest.raises(BraintreeException) as e:
        refund(payment_info, gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
Esempio n. 3
0
def test_refund_incorrect_token(
        mock_gateway, payment_txn_captured, braintree_not_found_error,
        gateway_config):
    payment = payment_txn_captured
    amount = Decimal('10.00')

    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))

    payment_info = create_payment_information(payment, 'token', amount)
    with pytest.raises(BraintreeException) as e:
        refund(payment_info, gateway_config)
    assert str(e.value) == DEFAULT_ERROR_MESSAGE
Esempio n. 4
0
def test_refund(payment_txn_captured, sandbox_braintree_gateway_config):
    amount = Decimal("10.00")
    TRANSACTION_ID = "rjfqmf3r"
    payment_info = create_payment_information(payment_txn_captured,
                                              TRANSACTION_ID, amount)
    response = refund(payment_info, sandbox_braintree_gateway_config)
    assert not response.error

    assert response.kind == TransactionKind.REFUND
    assert response.amount == amount
    assert response.currency == "EUR"
    assert response.is_success is True
Esempio n. 5
0
def test_refund_error_response(mock_gateway, payment_txn_captured,
                               braintree_error_response):
    payment = payment_txn_captured
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))
    txn, error = refund(payment, amount)

    assert txn.gateway_response == extract_gateway_response(
        braintree_error_response)
    assert not txn.is_success
    assert txn.amount == amount
    assert txn.currency == payment.currency
    assert error == DEFAULT_ERROR
Esempio n. 6
0
def test_refund_error_response(mock_gateway, payment_txn_captured,
                               braintree_error_response, gateway_config):
    payment = payment_txn_captured
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))

    payment_info = create_payment_information(payment, 'token', amount)
    response = refund(payment_info, gateway_config)

    assert response['raw_response'] == extract_gateway_response(
        braintree_error_response)
    assert not response['is_success']
    assert response['error'] == DEFAULT_ERROR
Esempio n. 7
0
def test_refund_error_response(
    mock_gateway, payment_txn_captured, braintree_error_response, gateway_config
):
    payment = payment_txn_captured
    amount = Decimal("10.00")
    mock_response = Mock(return_value=braintree_error_response)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))

    payment_info = create_payment_information(payment, "token", amount)
    response = refund(payment_info, gateway_config)

    assert response.raw_response == extract_gateway_response(braintree_error_response)
    assert not response.is_success
    assert response.error == DEFAULT_ERROR
Esempio n. 8
0
def test_refund_incorrect_token(mock_gateway, mock_transaction,
                                payment_txn_captured,
                                braintree_not_found_error):
    payment = payment_txn_captured
    amount = Decimal('10.00')
    mock_response = Mock(side_effect=braintree_not_found_error)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))
    expected_result = ('txn', 'error')
    mock_transaction.return_value = expected_result
    result = refund(payment, amount)
    assert result == expected_result
    capture_txn = payment.transactions.filter(
        kind=TransactionKind.CAPTURE).first()
    mock_transaction.assert_called_once_with(payment,
                                             kind=TransactionKind.REFUND,
                                             token=capture_txn.token,
                                             amount=amount)
Esempio n. 9
0
def test_refund(mock_gateway, payment_txn_captured, braintree_success_response,
                gateway_config):
    payment = payment_txn_captured
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))

    payment_info = create_payment_information(payment, 'token', amount)
    response = refund(payment_info, gateway_config)
    assert not response.error

    assert response.kind == TransactionKind.REFUND
    assert response.amount == braintree_success_response.transaction.amount
    assert response.currency == braintree_success_response.transaction.currency_iso_code
    assert response.transaction_id == braintree_success_response.transaction.id
    assert response.is_success == braintree_success_response.is_success
    mock_response.assert_called_once_with(amount_or_options=str(amount),
                                          transaction_id=payment_info.token)
Esempio n. 10
0
def test_refund(
        mock_gateway, payment_txn_captured, braintree_success_response,
        settings, gateway_config):
    payment = payment_txn_captured
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))

    payment_info = create_payment_information(payment, 'token', amount)
    response = refund(payment_info, gateway_config)
    assert not response['error']

    assert response['kind'] == TransactionKind.REFUND
    assert response['amount'] == braintree_success_response.transaction.amount
    assert response['currency'] == braintree_success_response.transaction.currency_iso_code
    assert response['transaction_id'] == braintree_success_response.transaction.id
    assert response['is_success'] == braintree_success_response.is_success
    mock_response.assert_called_once_with(
        amount_or_options=str(amount), transaction_id=payment_info['token'])
Esempio n. 11
0
def test_refund(
    mock_gateway, payment_txn_captured, braintree_success_response, gateway_config
):
    payment = payment_txn_captured
    amount = Decimal("10.00")
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))

    payment_info = create_payment_information(payment, "token", amount)
    response = refund(payment_info, gateway_config)
    assert not response.error

    assert response.kind == TransactionKind.REFUND
    assert response.amount == braintree_success_response.transaction.amount
    assert response.currency == braintree_success_response.transaction.currency_iso_code
    assert response.transaction_id == braintree_success_response.transaction.id
    assert response.is_success == braintree_success_response.is_success
    mock_response.assert_called_once_with(
        amount_or_options=str(amount), transaction_id=payment_info.token
    )
Esempio n. 12
0
def test_refund(mock_gateway, payment_txn_captured, braintree_success_response,
                settings):
    payment = payment_txn_captured
    amount = Decimal('10.00')
    mock_response = Mock(return_value=braintree_success_response)
    mock_gateway.return_value = Mock(transaction=Mock(refund=mock_response))
    txn, error = refund(payment, amount)
    assert not error

    assert txn.payment == payment
    assert txn.kind == TransactionKind.REFUND
    assert txn.amount == braintree_success_response.transaction.amount
    assert txn.currency == braintree_success_response.transaction.currency_iso_code
    assert txn.gateway_response == success_gateway_response(
        braintree_success_response)
    assert txn.token == braintree_success_response.transaction.id
    assert txn.is_success == braintree_success_response.is_success

    capture_txn = payment.transactions.filter(
        kind=TransactionKind.CAPTURE).first()
    mock_response.assert_called_once_with(amount_or_options=str(amount),
                                          transaction_id=capture_txn.token)