Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock checkoutComplete, create order from adyen notification #6048

Merged
merged 24 commits into from Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,27 +1,28 @@
from typing import Iterable, Union
from typing import Iterable, Optional, Type, Union

from django.core.exceptions import ValidationError

from ...checkout.error_codes import CheckoutErrorCode
from ...checkout.models import Checkout, CheckoutLine
from ...checkout.utils import is_fully_paid, is_valid_shipping_method
from ...discount import DiscountInfo
from ...payment.error_codes import PaymentErrorCode
from ..discount import DiscountInfo
from ..payment import gateway, models as payment_models
from ..payment.error_codes import PaymentErrorCode
from .error_codes import CheckoutErrorCode
from .models import Checkout, CheckoutLine
from .utils import is_fully_paid, is_valid_shipping_method


def clean_checkout_shipping(
checkout: Checkout,
lines: Iterable[CheckoutLine],
discounts: Iterable[DiscountInfo],
error_code: Union[CheckoutErrorCode, PaymentErrorCode],
error_code: Union[Type[CheckoutErrorCode], Type[PaymentErrorCode]],
):
if checkout.is_shipping_required():
if not checkout.shipping_method:
raise ValidationError(
{
"shipping_method": ValidationError(
"Shipping method is not set",
code=error_code.SHIPPING_METHOD_NOT_SET,
code=error_code.SHIPPING_METHOD_NOT_SET.value,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are those changes needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting:

Unexpected type(s): (str, Union[CheckoutErrorCode, PaymentErrorCode]) Possible types: (Any, Optional[str]) (Any, Optional[str]) 

And then it raises the exception on mypy:

saleor/checkout/checkout_cleaner.py:43: error: Argument "code" to "ValidationError" has incompatible type "Union[CheckoutErrorCode, PaymentErrorCode]"; expected "Optional[str]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

)
}
)
Expand All @@ -30,7 +31,7 @@ def clean_checkout_shipping(
{
"shipping_address": ValidationError(
"Shipping address is not set",
code=error_code.SHIPPING_ADDRESS_NOT_SET,
code=error_code.SHIPPING_ADDRESS_NOT_SET.value,
)
}
)
Expand All @@ -39,21 +40,22 @@ def clean_checkout_shipping(
{
"shipping_method": ValidationError(
"Shipping method is not valid for your shipping address",
code=error_code.INVALID_SHIPPING_METHOD,
code=error_code.INVALID_SHIPPING_METHOD.value,
)
}
)


def clean_billing_address(
checkout: Checkout, error_code: Union[CheckoutErrorCode, PaymentErrorCode],
checkout: Checkout,
error_code: Union[Type[CheckoutErrorCode], Type[PaymentErrorCode]],
):
if not checkout.billing_address:
raise ValidationError(
{
"billing_address": ValidationError(
"Billing address is not set",
code=error_code.BILLING_ADDRESS_NOT_SET,
code=error_code.BILLING_ADDRESS_NOT_SET.value,
)
}
)
Expand All @@ -63,11 +65,13 @@ def clean_checkout_payment(
checkout: Checkout,
lines: Iterable[CheckoutLine],
discounts: Iterable[DiscountInfo],
error_code: CheckoutErrorCode,
error_code: Type[CheckoutErrorCode],
last_payment: Optional[payment_models.Payment],
):
clean_billing_address(checkout, error_code)
if not is_fully_paid(checkout, lines, discounts):
gateway.payment_refund_or_void(last_payment)
raise ValidationError(
"Provided payment methods can not cover the checkout's total amount",
code=error_code.CHECKOUT_NOT_FULLY_PAID,
code=error_code.CHECKOUT_NOT_FULLY_PAID.value,
)