Ejemplo n.º 1
0
def test_authorize_without_capture(stripe_payment, sandbox_gateway_config):
    sandbox_gateway_config.auto_capture = False
    payment_info = create_payment_information(stripe_payment,
                                              PAYMENT_METHOD_CARD_SIMPLE)
    response = authorize(payment_info, sandbox_gateway_config)
    assert not response.error
    assert response.kind == TransactionKind.AUTH
    assert isclose(response.amount, TRANSACTION_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
    assert response.is_success is True
Ejemplo n.º 2
0
def test_authorize_and_save_customer_id(payment_dummy, sandbox_gateway_config):
    CUSTOMER_ID = "cus_FbquUfgBnLdlsY"  # retrieved from sandbox
    payment = payment_dummy

    payment_info = create_payment_information(payment, PAYMENT_METHOD_CARD_SIMPLE)

    sandbox_gateway_config.store_customer = True
    response = authorize(payment_info, sandbox_gateway_config)
    assert not response.error
    assert response.customer_id == CUSTOMER_ID
Ejemplo n.º 3
0
def test_authorize_3d_secure(stripe_payment, sandbox_gateway_config):
    payment_info = create_payment_information(stripe_payment,
                                              PAYMENT_METHOD_CARD_3D_SECURE)
    response = authorize(payment_info, sandbox_gateway_config)
    assert not response.error
    assert response.kind == TransactionKind.CAPTURE
    assert isclose(response.amount, TRANSACTION_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
    assert response.is_success is True
    assert response.action_required
Ejemplo n.º 4
0
def test_authorize_error_response(stripe_payment, sandbox_gateway_config):
    INVALID_METHOD = "abcdefghijklmnoprstquwz"
    payment_info = create_payment_information(stripe_payment, INVALID_METHOD)
    response = authorize(payment_info, sandbox_gateway_config)

    assert response.error == "No such payment_method: " + INVALID_METHOD
    assert response.transaction_id == INVALID_METHOD
    assert response.kind == TransactionKind.CAPTURE
    assert not response.is_success
    assert response.amount == stripe_payment.total
    assert response.currency == stripe_payment.currency
    assert not response.action_required
Ejemplo n.º 5
0
def test_authorize_with_customer_id(payment_dummy, sandbox_gateway_config):
    CUSTOMER_ID = "cus_FbquUfgBnLdlsY"  # retrieved from sandbox
    payment = payment_dummy

    payment_info = create_payment_information(payment, "pm_card_visa")
    payment_info.amount = TRANSACTION_AMOUNT
    payment_info.customer_id = CUSTOMER_ID
    payment_info.reuse_source = True

    response = authorize(payment_info, sandbox_gateway_config)
    assert not response.error
    assert response.is_success
Ejemplo n.º 6
0
def test_authorize_error_response(mock_charge_create, stripe_payment, gateway_config):
    payment = stripe_payment
    payment_info = create_payment_information(payment, FAKE_TOKEN)
    stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE, param=None)
    mock_charge_create.side_effect = stripe_error

    response = authorize(payment_info, gateway_config)

    assert response.error == ERROR_MESSAGE
    assert response.transaction_id == FAKE_TOKEN
    assert response.kind == TransactionKind.AUTH
    assert not response.is_success
    assert response.amount == payment.total
    assert response.currency == payment.currency
    assert response.raw_response == _get_error_response_from_exc(stripe_error)
Ejemplo n.º 7
0
def test_authorize(mock_charge_create, stripe_payment, gateway_params,
                   stripe_charge_success_response):
    payment = stripe_payment
    payment_info = create_payment_information(payment, FAKE_TOKEN)
    response = stripe_charge_success_response
    mock_charge_create.return_value = response

    response = authorize(payment_info, gateway_params)

    assert not response.error
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.AUTH
    assert response.is_success
    assert isclose(response.amount, TRANSACTION_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
    assert response.raw_response == stripe_charge_success_response
Ejemplo n.º 8
0
def test_authorize(mock_charge_create, stripe_payment, gateway_params,
                   stripe_charge_success_response):
    payment = stripe_payment
    response = stripe_charge_success_response
    mock_charge_create.return_value = response

    txn, error = authorize(payment, FAKE_TOKEN, **gateway_params)

    assert not error
    assert txn.payment == payment
    assert txn.token == TRANSACTION_TOKEN
    assert txn.kind == TransactionKind.AUTH
    assert txn.is_success
    assert isclose(txn.amount, TRANSACTION_AMOUNT)
    assert txn.currency == TRANSACTION_CURRENCY
    assert txn.gateway_response == response
Ejemplo n.º 9
0
def test_authorize_error_response(mock_charge_create, stripe_payment,
                                  gateway_params):
    payment = stripe_payment
    payment_info = create_payment_information(payment, FAKE_TOKEN)
    stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE,
                                                    param=None)
    mock_charge_create.side_effect = stripe_error

    response = authorize(payment_info, gateway_params)

    assert response.error == ERROR_MESSAGE
    assert response.transaction_id == FAKE_TOKEN
    assert response.kind == TransactionKind.AUTH
    assert not response.is_success
    assert response.amount == payment.total
    assert response.currency == payment.currency
    assert response.raw_response == _get_error_response_from_exc(stripe_error)
Ejemplo n.º 10
0
def test_authorize_error_response(mock_charge_create, stripe_payment,
                                  gateway_params):
    payment = stripe_payment
    stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE,
                                                    param=None)
    mock_charge_create.side_effect = stripe_error

    txn, error = authorize(payment, FAKE_TOKEN, **gateway_params)

    assert error == ERROR_MESSAGE
    assert txn.payment == payment
    assert txn.token == ''
    assert txn.kind == TransactionKind.AUTH
    assert not txn.is_success
    assert txn.amount == payment.total
    assert txn.currency == payment.currency
    assert txn.gateway_response == _get_error_response_from_exc(stripe_error)
Ejemplo n.º 11
0
def test_authorize(
    mock_charge_create, stripe_payment, gateway_config, stripe_charge_success_response
):
    payment = stripe_payment
    payment_info = create_payment_information(payment, FAKE_TOKEN)
    response = stripe_charge_success_response
    mock_charge_create.return_value = response

    response = authorize(payment_info, gateway_config)

    assert not response.error
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.AUTH
    assert response.is_success
    assert isclose(response.amount, TRANSACTION_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
    assert response.raw_response == stripe_charge_success_response
Ejemplo n.º 12
0
def test_authorize(
        mock_charge_create,
        stripe_payment,
        gateway_params,
        stripe_charge_success_response):
    payment = stripe_payment
    payment_info = create_payment_information(payment, FAKE_TOKEN)
    response = stripe_charge_success_response
    mock_charge_create.return_value = response

    response = authorize(payment_info, gateway_params)

    assert not response['error']
    assert response['transaction_id'] == TRANSACTION_TOKEN
    assert response['kind'] == TransactionKind.AUTH
    assert response['is_success']
    assert isclose(response['amount'], TRANSACTION_AMOUNT)
    assert response['currency'] == TRANSACTION_CURRENCY
    assert response['raw_response'] == stripe_charge_success_response