Ejemplo n.º 1
0
def test_refund_charged(
    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,
                                              TRANSACTION_TOKEN,
                                              amount=Money(
                                                  TRANSACTION_AMOUNT,
                                                  TRANSACTION_CURRENCY))
    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
Ejemplo n.º 2
0
def test_partial_captureummy(
    mock_charge_retrieve,
    stripe_authorized_payment,
    gateway_config,
    stripe_partial_charge_success_response,
):
    payment = stripe_authorized_payment
    payment_info = create_payment_information(payment,
                                              amount=Money(
                                                  TRANSACTION_AMOUNT,
                                                  TRANSACTION_CURRENCY))
    response = stripe_partial_charge_success_response
    mock_charge_retrieve.return_value = Mock(capture=Mock(
        return_value=response))

    response = capture(payment_info, gateway_config)

    assert not response.error
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.CAPTURE
    assert response.is_success
    assert isclose(response.amount,
                   TRANSACTION_AMOUNT - TRANSACTION_REFUND_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
    assert response.raw_response == stripe_partial_charge_success_response
Ejemplo n.º 3
0
def it_should_not_authorize_when_query_returns_not_authorized(
        query, netaxept_payment):
    mock_query_response = QueryResponse(
        annulled=False,
        authorized=False,
        authorization_id=None,
        raw_response={
            'status_code': 200,
            'url': 'https://test.epayment.nets.eu/Netaxept/Query.aspx',
            'encoding': 'ISO-8859-1',
            'reason': 'OK',
            'text': 'some xml'
        })
    query.return_value = mock_query_response

    payment_info = create_payment_information(
        payment=netaxept_payment,
        payment_token='1111111111114cf693a1cf86123e0d8f',
        amount=Money(10, 'CHF'))

    authorize_result = authorize(config=_gateway_config,
                                 payment_information=payment_info)
    assert authorize_result == GatewayResponse(
        is_success=False,
        kind=TransactionKind.AUTH,
        amount=Decimal('10'),
        currency='CHF',
        transaction_id='1111111111114cf693a1cf86123e0d8f',
        error=None,
        raw_response=mock_query_response.raw_response)
    query.assert_called_once_with(
        config=_netaxept_config,
        transaction_id='1111111111114cf693a1cf86123e0d8f')
Ejemplo n.º 4
0
def it_should_void(process, netaxept_payment):
    mock_process_response = ProcessResponse(
        response_code='OK',
        raw_response={
            'status_code': 200,
            'url': 'https://test.epayment.nets.eu/Netaxept/Register.aspx',
            'encoding': 'ISO-8859-1',
            'reason': 'OK',
            'text': 'some xml'
        })
    process.return_value = mock_process_response
    payment_info = create_payment_information(
        payment=netaxept_payment,
        payment_token='1111111111114cf693a1cf86123e0d8f',
        amount=Money(10, 'CHF'))
    void_result = void(config=_gateway_config,
                       payment_information=payment_info)
    assert void_result == GatewayResponse(
        is_success=True,
        kind=TransactionKind.VOID,
        amount=Decimal('10'),
        currency='CHF',
        transaction_id='1111111111114cf693a1cf86123e0d8f',
        error=None,
        raw_response=mock_process_response.raw_response)
    process.assert_called_once_with(
        config=_netaxept_config,
        amount=Decimal('10'),
        transaction_id='1111111111114cf693a1cf86123e0d8f',
        operation=NetaxeptOperation.ANNUL)
Ejemplo n.º 5
0
def test_widget_with_additional_attr(stripe_payment, gateway_config):
    payment_info = create_payment_information(stripe_payment)

    widget = StripeCheckoutWidget(
        payment_info,
        gateway_config.connection_params,
        attrs={"data-custom": "custom-data"},
    )
    assert 'data-custom="custom-data"' in widget.render()
Ejemplo n.º 6
0
def test_widget_with_prefill_option(stripe_payment, gateway_config):
    payment_info = create_payment_information(stripe_payment)
    connection_params = gateway_config.connection_params
    connection_params["prefill"] = True
    widget = StripeCheckoutWidget(payment_info, connection_params)
    assert 'data-email="*****@*****.**"' in widget.render()

    connection_params["prefill"] = False
    widget = StripeCheckoutWidget(payment_info, connection_params)
    assert 'data-email="*****@*****.**"' not in widget.render()
Ejemplo n.º 7
0
def test_widget_with_remember_me_option(stripe_payment, gateway_config):
    payment_info = create_payment_information(stripe_payment)
    connection_params = gateway_config.connection_params

    connection_params["remember_me"] = True
    widget = StripeCheckoutWidget(payment_info, connection_params)
    assert 'data-allow-remember-me="true"' in widget.render()

    connection_params["remember_me"] = False
    widget = StripeCheckoutWidget(payment_info, connection_params)
    assert 'data-allow-remember-me="false"' in widget.render()
Ejemplo n.º 8
0
def test_widget_with_enable_shipping_address_option(stripe_payment,
                                                    gateway_config):
    payment_info = create_payment_information(stripe_payment, FAKE_TOKEN)
    connection_params = gateway_config.connection_params

    connection_params["enable_shipping_address"] = True
    widget = StripeCheckoutWidget(payment_info, connection_params)
    assert 'data-shipping-address="true"' in widget.render()

    connection_params["enable_shipping_address"] = False
    widget = StripeCheckoutWidget(payment_info, connection_params)
    assert 'data-shipping-address="false"' in widget.render()
Ejemplo n.º 9
0
def test_create_transaction_with_refund_success_response(
        stripe_payment, stripe_refund_success_response):
    payment_info = create_payment_information(stripe_payment)

    response = _create_response(
        payment_information=payment_info,
        kind="ANYKIND",
        response=stripe_refund_success_response,
        error=None,
    )

    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.is_success is True
    assert isclose(response.amount, TRANSACTION_REFUND_AMOUNT)
    assert response.currency == TRANSACTION_CURRENCY
Ejemplo n.º 10
0
def test_dummy_payment_form(kind, charge_status, payment_dummy):
    payment = payment_dummy
    data = {"charge_status": charge_status}
    payment_gateway, gateway_config = get_payment_gateway(payment.gateway)
    payment_info = create_payment_information(payment)

    form = payment_gateway.create_form(
        data=data,
        payment_information=payment_info,
        connection_params=gateway_config.connection_params,
    )
    assert form.is_valid()
    gateway_process_payment(payment=payment,
                            payment_token=form.get_payment_token())
    payment.refresh_from_db()
    assert payment.transactions.last().kind == kind
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_create_response_with_error_response(stripe_payment):
    payment = stripe_payment
    payment_info = create_payment_information(payment, FAKE_TOKEN)
    stripe_error_response = {}

    response = _create_response(
        payment_information=payment_info,
        kind="ANYKIND",
        response=stripe_error_response,
        error=None,
    )

    assert response.transaction_id == FAKE_TOKEN
    assert response.is_success is False
    assert response.amount == payment.total.amount
    assert response.currency == payment.total.currency.code
Ejemplo n.º 13
0
def test_get_stripe_charge_payload_without_shipping(stripe_payment):
    payment_info = create_payment_information(stripe_payment, FAKE_TOKEN)
    billing_name = get_payment_billing_fullname(payment_info)
    expected_payload = {
        "capture": True,
        "amount": get_amount_for_stripe(TRANSACTION_AMOUNT,
                                        TRANSACTION_CURRENCY),
        "currency": get_currency_for_stripe(TRANSACTION_CURRENCY),
        "source": FAKE_TOKEN,
        "description": billing_name,
        "metadata": {},
    }

    charge_payload = _get_stripe_charge_payload(payment_info, True)

    assert charge_payload == expected_payload
Ejemplo n.º 14
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.amount
    assert response.currency == payment.total.currency.code
    assert response.raw_response == _get_error_response_from_exc(stripe_error)
Ejemplo n.º 15
0
def test_stripe_payment_form(stripe_payment, gateway_config):
    payment_info = create_payment_information(stripe_payment, FAKE_TOKEN)
    form = create_form(
        None,
        payment_information=payment_info,
        connection_params=gateway_config.connection_params,
    )
    assert isinstance(form, StripePaymentModalForm)
    assert not form.is_valid()

    form = create_form(
        data={"stripeToken": FAKE_TOKEN},
        payment_information=payment_info,
        connection_params=gateway_config.connection_params,
    )
    assert isinstance(form, StripePaymentModalForm)
    assert form.is_valid()
Ejemplo n.º 16
0
def test_void_error_response(mock_charge_retrieve, mock_refund_create,
                             stripe_authorized_payment, gateway_config):
    payment = stripe_authorized_payment
    payment_info = create_payment_information(payment, TRANSACTION_TOKEN)
    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 = void(payment_info, gateway_config)

    assert response.error == ERROR_MESSAGE
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.VOID
    assert not response.is_success
    assert response.amount == payment.total.amount
    assert response.currency == TRANSACTION_CURRENCY
    assert response.raw_response == {}
Ejemplo n.º 17
0
def test_capture_error_response(mock_charge_retrieve,
                                stripe_authorized_payment, gateway_config):
    payment = stripe_authorized_payment
    payment_info = create_payment_information(payment,
                                              TRANSACTION_TOKEN,
                                              amount=Money(
                                                  TRANSACTION_AMOUNT,
                                                  TRANSACTION_CURRENCY))
    stripe_error = stripe.error.InvalidRequestError(message=ERROR_MESSAGE,
                                                    param=None)
    mock_charge_retrieve.side_effect = stripe_error

    response = capture(payment_info, gateway_config)

    assert response.error == ERROR_MESSAGE
    assert response.transaction_id == TRANSACTION_TOKEN
    assert response.kind == TransactionKind.CAPTURE
    assert not response.is_success
    assert response.amount == payment.total.amount
    assert response.currency == payment.total.currency.code
    assert response.raw_response == _get_error_response_from_exc(stripe_error)
Ejemplo n.º 18
0
def it_should_not_capture_when_protocol_error(process, netaxept_payment):
    process.side_effect = NetaxeptProtocolError(error='some error',
                                                raw_response={})
    payment_info = create_payment_information(
        payment=netaxept_payment,
        payment_token='1111111111114cf693a1cf86123e0d8f',
        amount=Money(10, 'CHF'))
    capture_result = capture(config=_gateway_config,
                             payment_information=payment_info)
    assert capture_result == GatewayResponse(
        is_success=False,
        kind=TransactionKind.CAPTURE,
        amount=Decimal('10'),
        currency='CHF',
        transaction_id='1111111111114cf693a1cf86123e0d8f',
        error='some error',
        raw_response={})
    process.assert_called_once_with(
        config=_netaxept_config,
        amount=Decimal('10'),
        transaction_id='1111111111114cf693a1cf86123e0d8f',
        operation=NetaxeptOperation.CAPTURE)