Exemple #1
0
def test_append_klarna_data_tax_included(
    mocked_checkout_line_total,
    dummy_payment_data,
    payment_dummy,
    checkout_ready_to_complete,
):
    # given
    net = Money(100, "USD")
    gross = Money(123, "USD")
    # tax 23 %
    mocked_checkout_line_total.return_value = quantize_price(
        TaxedMoney(net=net, gross=gross), "USD")
    country_code = checkout_ready_to_complete.get_country()

    checkout_ready_to_complete.payments.add(payment_dummy)
    line = checkout_ready_to_complete.lines.first()
    payment_data = {
        "reference": "test",
    }

    # when
    result = append_klarna_data(dummy_payment_data, payment_data)

    # then

    expected_result = {
        "reference":
        "test",
        "shopperLocale":
        get_shopper_locale_value(country_code),
        "shopperReference":
        dummy_payment_data.customer_email,
        "countryCode":
        country_code,
        "lineItems": [
            {
                "description":
                f"{line.variant.product.name}, {line.variant.name}",
                "quantity": line.quantity,
                "id": line.variant.sku,
                "taxAmount": to_adyen_price((gross - net).amount, "USD"),
                "taxPercentage": 2300,
                "amountExcludingTax": to_adyen_price(net.amount, "USD"),
                "amountIncludingTax": to_adyen_price(gross.amount, "USD"),
            },
            {
                "amountExcludingTax": "1000",
                "amountIncludingTax": "1000",
                "description": "Shipping - DHL",
                "id":
                f"Shipping:{checkout_ready_to_complete.shipping_method.id}",
                "quantity": 1,
                "taxAmount": "0",
                "taxPercentage": 0,
            },
        ],
    }
    assert result == expected_result
def test_request_data_for_payment_channel_different_than_web(dummy_payment_data):
    # given
    return_url = "https://www.example.com"
    merchant_account = "MerchantTestAccount"
    data = {"is_valid": True, "paymentMethod": {"type": "scheme"}, "channel": "iOS"}
    dummy_payment_data.data = data
    native_3d_secure = True

    # when
    result = request_data_for_payment(
        dummy_payment_data, return_url, merchant_account, native_3d_secure
    )

    # then
    assert result == {
        "amount": {
            "value": to_adyen_price(
                dummy_payment_data.amount, dummy_payment_data.currency
            ),
            "currency": dummy_payment_data.currency,
        },
        "reference": dummy_payment_data.graphql_payment_id,
        "paymentMethod": {"type": "scheme"},
        "returnUrl": return_url,
        "merchantAccount": merchant_account,
        "channel": "iOS",
        "additionalData": {"allow3DS2": "true"},
        "shopperEmail": "*****@*****.**",
    }
Exemple #3
0
def test_request_data_for_payment_native_3d_secure(dummy_payment_data):
    # given
    return_url = "https://www.example.com"
    merchant_account = "MerchantTestAccount"
    origin_url = "https://www.example.com"
    data = {
        "is_valid": True,
        "riskData": {
            "clientData": "test_client_data"
        },
        "paymentMethod": {
            "type": "scheme"
        },
        "browserInfo": {
            "acceptHeader": "*/*",
            "colorDepth": 30,
            "language": "pl"
        },
        "billingAddress": {
            "address": "test_address"
        },
        "shopperIP": "123",
        "originUrl": origin_url,
    }
    dummy_payment_data.data = data
    native_3d_secure = True

    # when
    result = request_data_for_payment(dummy_payment_data, return_url,
                                      merchant_account, native_3d_secure)

    # then
    assert result == {
        "amount": {
            "value":
            to_adyen_price(dummy_payment_data.amount,
                           dummy_payment_data.currency),
            "currency":
            dummy_payment_data.currency,
        },
        "reference": dummy_payment_data.graphql_payment_id,
        "paymentMethod": {
            "type": "scheme"
        },
        "returnUrl": return_url,
        "merchantAccount": merchant_account,
        "origin": origin_url,
        "shopperIP": data["shopperIP"],
        "billingAddress": data["billingAddress"],
        "browserInfo": data["browserInfo"],
        "channel": "web",
        "additionalData": {
            "allow3DS2": "true"
        },
        "shopperEmail": "*****@*****.**",
    }
Exemple #4
0
def test_request_data_for_payment_append_klarna_data(append_klarna_data_mock,
                                                     dummy_payment_data):
    # given
    return_url = "https://www.example.com"
    merchant_account = "MerchantTestAccount"
    origin_url = "https://www.example.com"
    data = {
        "is_valid": True,
        "riskData": {
            "clientData": "test_client_data"
        },
        "paymentMethod": {
            "type": "klarna"
        },
        "browserInfo": {
            "acceptHeader": "*/*",
            "colorDepth": 30,
            "language": "pl"
        },
        "billingAddress": {
            "address": "test_address"
        },
        "shopperIP": "123",
        "originUrl": origin_url,
    }
    dummy_payment_data.data = data
    klarna_result = {
        "amount": {
            "value":
            to_adyen_price(dummy_payment_data.amount,
                           dummy_payment_data.currency),
            "currency":
            dummy_payment_data.currency,
        },
        "reference": dummy_payment_data.graphql_payment_id,
        "paymentMethod": {
            "type": "scheme"
        },
        "returnUrl": return_url,
        "merchantAccount": merchant_account,
        "origin": return_url,
        "shopperIP": data["shopperIP"],
        "billingAddress": data["billingAddress"],
        "browserInfo": data["browserInfo"],
        "shopperLocale": "test_shopper",
    }
    append_klarna_data_mock.return_value = klarna_result
    native_3d_secure = False
    # when
    result = request_data_for_payment(dummy_payment_data, return_url,
                                      merchant_account, native_3d_secure)

    # then
    assert result == klarna_result
Exemple #5
0
def test_append_klarna_data(dummy_payment_data, payment_dummy,
                            checkout_ready_to_complete):
    # given
    checkout_ready_to_complete.payments.add(payment_dummy)
    channel_id = checkout_ready_to_complete.channel_id
    line = checkout_ready_to_complete.lines.first()
    payment_data = {
        "reference": "test",
    }
    country_code = checkout_ready_to_complete.get_country()

    # when
    result = append_klarna_data(dummy_payment_data, payment_data)

    # then
    variant_channel_listing = line.variant.channel_listings.get(
        channel_id=channel_id)
    variant_price = variant_channel_listing.price_amount
    variant_currency = variant_channel_listing.currency
    total = to_adyen_price(variant_price * line.quantity, variant_currency)
    assert result == {
        "reference":
        "test",
        "shopperLocale":
        get_shopper_locale_value(country_code),
        "shopperReference":
        dummy_payment_data.customer_email,
        "countryCode":
        country_code,
        "lineItems": [
            {
                "description":
                f"{line.variant.product.name}, {line.variant.name}",
                "quantity": line.quantity,
                "id": line.variant.sku,
                "taxAmount": "0",
                "taxPercentage": 0,
                "amountExcludingTax": total,
                "amountIncludingTax": total,
            },
            {
                "amountExcludingTax": "1000",
                "amountIncludingTax": "1000",
                "description": "Shipping - DHL",
                "id":
                f"Shipping:{checkout_ready_to_complete.shipping_method.id}",
                "quantity": 1,
                "taxAmount": "0",
                "taxPercentage": 0,
            },
        ],
    }
Exemple #6
0
def test_to_adyen_price(value, currency, expected_result):
    # when
    result = to_adyen_price(value, currency)

    # then
    assert result == expected_result