Exemplo n.º 1
0
def test_refund_error_response(stripe_payment, sandbox_gateway_config):
    INVALID_INTENT = "THIS_INTENT_DOES_NOT_EXISTS"
    payment_info = create_payment_information(stripe_payment, INVALID_INTENT)
    response = refund(payment_info, sandbox_gateway_config)

    assert response.error == "No such payment_intent: " + INVALID_INTENT
    assert response.transaction_id == INVALID_INTENT
    assert response.kind == TransactionKind.REFUND
    assert not response.is_success
    assert response.amount == stripe_payment.total
    assert response.currency == stripe_payment.currency
Exemplo n.º 2
0
def test_refund_not_charged_or_captured(stripe_payment, gateway_params):
    payment = stripe_payment

    txn, error = refund(payment, TRANSACTION_AMOUNT, **gateway_params)

    assert error == ORDER_NOT_CHARGED
    assert txn.payment == payment
    assert txn.token == ''
    assert txn.kind == TransactionKind.REFUND
    assert not txn.is_success
    assert txn.amount == payment.total
    assert txn.currency == TRANSACTION_CURRENCY
    assert txn.gateway_response == {}
Exemplo n.º 3
0
def test_refund(stripe_paid_payment, sandbox_gateway_config):
    # Get id from sandbox for succeeded payment
    REFUND_AMOUNT = Decimal(10.0)  # partial refund
    INTENT_ID = "pi_1F5BsRIUmJaD6Oqvz2XMKZCD"
    payment_info = create_payment_information(stripe_paid_payment,
                                              amount=REFUND_AMOUNT,
                                              payment_token=INTENT_ID)
    response = refund(payment_info, sandbox_gateway_config)

    assert not response.error
    assert response.transaction_id == INTENT_ID
    assert response.kind == TransactionKind.REFUND
    assert response.is_success
    assert isclose(response.amount, REFUND_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
Exemplo n.º 4
0
def test_refund_error_response(mock_charge_retrieve, mock_refund_create,
                               stripe_charged_payment, gateway_params):
    payment = stripe_charged_payment
    mock_charge_retrieve.return_value = Mock(id='')
    stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE,
                                                    param=None)
    mock_refund_create.side_effect = stripe_error

    txn, error = refund(payment, TRANSACTION_AMOUNT, **gateway_params)

    assert error == ERROR_MESSAGE
    assert txn.payment == payment
    assert txn.token == ''
    assert txn.kind == TransactionKind.REFUND
    assert not txn.is_success
    assert txn.amount == payment.total
    assert txn.currency == TRANSACTION_CURRENCY
    assert txn.gateway_response == _get_error_response_from_exc(stripe_error)
Exemplo n.º 5
0
def test_refund_captured(mock_charge_retrieve, mock_refund_create,
                         stripe_captured_payment, gateway_params,
                         stripe_refund_success_response):
    payment = stripe_captured_payment
    response = stripe_refund_success_response
    mock_charge_retrieve.return_value = Mock(id='')
    mock_refund_create.return_value = response

    txn, error = refund(payment, TRANSACTION_AMOUNT, **gateway_params)

    assert not error
    assert txn.payment == payment
    assert txn.token == TRANSACTION_TOKEN
    assert txn.kind == TransactionKind.REFUND
    assert txn.is_success
    assert isclose(txn.amount, TRANSACTION_REFUND_AMOUNT)
    assert txn.currency == TRANSACTION_CURRENCY
    assert txn.gateway_response == response
Exemplo n.º 6
0
def test_refund_captured(mock_charge_retrieve, mock_refund_create,
                         stripe_captured_payment, gateway_params,
                         stripe_refund_success_response):
    payment = stripe_captured_payment
    payment_info = create_payment_information(payment,
                                              amount=TRANSACTION_AMOUNT)
    response = stripe_refund_success_response
    mock_charge_retrieve.return_value = Mock(id='')
    mock_refund_create.return_value = response

    response = refund(payment_info, gateway_params)

    assert not response.error
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.REFUND
    assert response.is_success
    assert isclose(response.amount, TRANSACTION_REFUND_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
    assert response.raw_response == stripe_refund_success_response
Exemplo n.º 7
0
def test_refund_error_response(mock_charge_retrieve, mock_refund_create,
                               stripe_charged_payment, gateway_params):
    payment = stripe_charged_payment
    payment_info = create_payment_information(payment,
                                              TRANSACTION_TOKEN,
                                              amount=TRANSACTION_AMOUNT)
    mock_charge_retrieve.return_value = Mock(id='')
    stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE,
                                                    param=None)
    mock_refund_create.side_effect = stripe_error

    response = refund(payment_info, gateway_params)

    assert response.error == ERROR_MESSAGE
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.REFUND
    assert not response.is_success
    assert response.amount == payment.total
    assert response.currency == TRANSACTION_CURRENCY
    assert response.raw_response == _get_error_response_from_exc(stripe_error)
Exemplo n.º 8
0
def test_refund_charged(mock_charge_retrieve, mock_refund_create,
                        stripe_charged_payment, gateway_params,
                        stripe_refund_success_response):
    payment = stripe_charged_payment
    payment_info = create_payment_information(payment,
                                              TRANSACTION_TOKEN,
                                              amount=TRANSACTION_AMOUNT)
    response = stripe_refund_success_response
    mock_charge_retrieve.return_value = Mock(id='')
    mock_refund_create.return_value = response

    response = refund(payment_info, gateway_params)

    assert not response['error']
    assert response['transaction_id'] == TRANSACTION_TOKEN
    assert response['kind'] == TransactionKind.REFUND
    assert response['is_success']
    assert isclose(response['amount'], TRANSACTION_REFUND_AMOUNT)
    assert response['currency'] == TRANSACTION_CURRENCY
    assert response['raw_response'] == stripe_refund_success_response
Exemplo n.º 9
0
def test_refund_error_response(
    mock_charge_retrieve, mock_refund_create, stripe_captured_payment, gateway_config
):
    payment = stripe_captured_payment
    payment_info = create_payment_information(
        payment, TRANSACTION_TOKEN, amount=TRANSACTION_AMOUNT
    )
    mock_charge_retrieve.return_value = Mock(id="")
    stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None)
    mock_refund_create.side_effect = stripe_error

    response = refund(payment_info, gateway_config)

    assert response.error == ERROR_MESSAGE
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.REFUND
    assert not response.is_success
    assert response.amount == payment.total
    assert response.currency == TRANSACTION_CURRENCY
    assert response.raw_response == _get_error_response_from_exc(stripe_error)
Exemplo n.º 10
0
def test_refund_captured(
        mock_charge_retrieve,
        mock_refund_create,
        stripe_captured_payment,
        gateway_params,
        stripe_refund_success_response):
    payment = stripe_captured_payment
    payment_info = create_payment_information(
        payment, amount=TRANSACTION_AMOUNT)
    response = stripe_refund_success_response
    mock_charge_retrieve.return_value = Mock(id='')
    mock_refund_create.return_value = response

    response = refund(payment_info, gateway_params)

    assert not response['error']
    assert response['transaction_id'] == TRANSACTION_TOKEN
    assert response['kind'] == TransactionKind.REFUND
    assert response['is_success']
    assert isclose(response['amount'], TRANSACTION_REFUND_AMOUNT)
    assert response['currency'] == TRANSACTION_CURRENCY
    assert response['raw_response'] == stripe_refund_success_response
Exemplo n.º 11
0
def test_refund_captured(
    mock_charge_retrieve,
    mock_refund_create,
    stripe_captured_payment,
    gateway_config,
    stripe_refund_success_response,
):
    payment = stripe_captured_payment
    payment_info = create_payment_information(payment, amount=TRANSACTION_AMOUNT)
    response = stripe_refund_success_response
    mock_charge_retrieve.return_value = Mock(id="")
    mock_refund_create.return_value = response

    response = refund(payment_info, gateway_config)

    assert not response.error
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.REFUND
    assert response.is_success
    assert isclose(response.amount, TRANSACTION_REFUND_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
    assert response.raw_response == stripe_refund_success_response