Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
PEP8
Pacu20988341fd1f5
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex 245e2b2419..6d288c1fcb 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -886,10 +886,11 @@ def create_order(cart, tracking_code, discounts, taxes):def is_fully_paid(cart: Cart):+ # FIXME test mepayments = cart.payments.filter(is_active=True)total_paid = sum(- [p.total for p in payments])- return total_paid >= cart.get_total().gross.amount+ [p.get_total() for p in payments])+ return total_paid >= cart.get_total().grossdef ready_to_place_order(cart: Cart, taxes, discounts):diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex ad3c128f44..a5b6305aab 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -379,6 +379,7 @@ def create_fake_user():user.save()return user+# We don't want to spam the console with payment confirmations sent to# fake customers.@patch('saleor.order.emails.send_payment_confirmation.delay')@@ -393,7 +394,6 @@ def create_payment(mock_email_confirmation, order):currency=order.total.gross.currency,**get_billing_data(order))-# Create authorization transactionpayment.authorize(payment.token)# 20% chance to void the transaction at this stagediff --git a/saleor/graphql/api.py b/saleor/graphql/api.pyindex 38f679152a..92dc681b9e 100644--- a/saleor/graphql/api.py+++ b/saleor/graphql/api.py@@ -80,7 +80,7 @@ class Query(ProductQueries):token=graphene.Argument(graphene.UUID))# FIXME we could optimize the below fieldcheckouts = DjangoConnectionField(- Checkout,description='List of checkouts.')+ Checkout, description='List of checkouts.')checkout_lines = PrefetchingConnectionField(CheckoutLine, description='List of checkout lines')checkout_line = graphene.Field(diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 1fb04de1f4..b80be301f3 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -8,7 +8,7 @@ from ..account.types import Userfrom ..core.fields import PrefetchingConnectionFieldfrom ..core.types.common import CountableDjangoObjectTypefrom ..core.types.money import Money, TaxedMoney-from ..payment.types import PaymentChargeStatusEnum, OrderAction+from ..payment.types import OrderAction, PaymentChargeStatusEnumfrom ..shipping.types import ShippingMethodOrderEventsEnum = graphene.Enum.from_enum(OrderEvents)diff --git a/saleor/graphql/payment/types.py b/saleor/graphql/payment/types.pyindex ba065f6b64..91d66fa6ae 100644--- a/saleor/graphql/payment/types.py+++ b/saleor/graphql/payment/types.py@@ -57,15 +57,17 @@ class CreditCard(graphene.ObjectType):last_digits = graphene.String(description='Last 4 digits of the card number.', required=True)exp_month = graphene.Int(- description='Two-digit number representing the card’s expiration month.',+ description=(+ 'Two-digit number representing the card’s expiration month.'),required=True)exp_year = graphene.Int(- description='Four-digit number representing the card’s expiration year.',+ description=(+ 'Four-digit number representing the card’s expiration year.'),required=True)class Payment(CountableDjangoObjectType):- # FIXME gateway_response field should be resolved into query-readable format+ # FIXME gateway_response field should be resolved# if we want to use it on the frontend# otherwise it should be removed from this typecharge_status = PaymentChargeStatusEnum(diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 04e200c313..c7b7fa5d0a 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -15,8 +15,7 @@ from django_prices.models import MoneyField, TaxedMoneyFieldfrom measurement.measures import Weightfrom prices import Money-from . import (- FulfillmentStatus, OrderEvents, OrderStatus, display_order_event)+from . import FulfillmentStatus, OrderEvents, OrderStatus, display_order_eventfrom ..account.models import Addressfrom ..core.utils.json_serializer import CustomJsonEncoderfrom ..core.utils.taxes import ZERO_TAXED_MONEY, zero_money@@ -182,9 +181,6 @@ class Order(models.Model):return Nonedef is_pre_authorized(self):- # FIXME for Braintree, payment is preauthorized if it was added- # properly and set to active. This might need to be adjusted for other- # payment gateways in the future.return self.payments.filter(is_active=True,transactions__kind=TransactionKind.AUTH).exists()diff --git a/saleor/order/views.py b/saleor/order/views.pyindex 0b0ce8d5ce..7cb2882baf 100644--- a/saleor/order/views.py+++ b/saleor/order/views.py@@ -97,8 +97,12 @@ def start_payment(request, order, gateway):raise Http404('%r is not a valid payment gateway' % (gateway,))with transaction.atomic():payment, _ = Payment.objects.get_or_create(- gateway=gateway, is_active=True, order=order, defaults=defaults,- total=order.total.gross.amount, currency=order.total.gross.currency)+ gateway=gateway,+ is_active=True,+ order=order,+ defaults=defaults,+ total=order.total.gross.amount,+ currency=order.total.gross.currency)if (order.is_fully_paid()or payment.charge_status == ChargeStatus.FULLY_REFUNDED):diff --git a/saleor/payment/__init__.py b/saleor/payment/__init__.pyindex ee7eee6cba..ed24d3db3a 100644--- a/saleor/payment/__init__.py+++ b/saleor/payment/__init__.py@@ -32,7 +32,6 @@ class TransactionError(Enum):DECLINED = 'declined'-class TransactionKind:"""- Authorization: An amount reserved against the customer's funding@@ -74,7 +73,6 @@ class ChargeStatus:# partially refunded# fully charged# ...?-CHOICES = [(CHARGED, pgettext_lazy('payment status', 'Charged')),(NOT_CHARGED, pgettext_lazy('payment status', 'Not charged')),diff --git a/saleor/payment/gateways/braintree/__init__.py b/saleor/payment/gateways/braintree/__init__.pyindex d768c59572..0571d6c87d 100644--- a/saleor/payment/gateways/braintree/__init__.py+++ b/saleor/payment/gateways/braintree/__init__.py@@ -14,6 +14,7 @@ from ...utils import create_transactionfrom .forms import BraintreePaymentFormlogger = logging.getLogger(__name__)+# FIXME: Move to SiteSettings# If this option is checked, then one needs to authorize the amount paiddiff --git a/saleor/payment/gateways/braintree/errors.py b/saleor/payment/gateways/braintree/errors.pyindex b27ebe067f..ea1f8a8541 100644--- a/saleor/payment/gateways/braintree/errors.py+++ b/saleor/payment/gateways/braintree/errors.py@@ -16,79 +16,81 @@ https://developers.braintreepayments.com/reference/general/validation-errors/allfrom ... import TransactionErrorINVALID_EXPIRY_DATE_ERRORS = [- '81709', # Expiration date is required.- '81710', # Expiration date is invalid.- '81711', # Expiration year is invalid. It must be between 1975 and 2201.- '81712', # Expiration month is invalid.- '81713', # Expiration year is invalid.+ '81709', # Expiration date is required.+ '81710', # Expiration date is invalid.+ '81711', # Expiration year is invalid. It must be between 1975 and 2201.+ '81712', # Expiration month is invalid.+ '81713', # Expiration year is invalid.]INCORRECT_ADDRESS_ERRORS = [- '81801', # Addresses must have at least one field filled in.- '81802', # Company is too long.- '81804', # Extended address is too long.- '81805', # First name is too long.- '81806', # Last name is too long.- '81807', # Locality is too long.- '81810', # Region is too long.- '81811', # Street address is required.- '81812', # Street address is too long.+ '81801', # Addresses must have at least one field filled in.+ '81802', # Company is too long.+ '81804', # Extended address is too long.+ '81805', # First name is too long.+ '81806', # Last name is too long.+ '81807', # Locality is too long.+ '81810', # Region is too long.+ '81811', # Street address is required.+ '81812', # Street address is too long.]INCORRECT_ZIP_ERRORS = [- '81813', # Postal code can only contain letters, numbers, spaces, and hyphens.- '81808', # Postal code is required.- '81809', # Postal code may contain no more than 9 letter or number characters.- '81737', # Postal code verification failed.- '91826', # Postal code must be a string.- '94527', # Billing postal code format is invalid.- '915164', # Shipping amount is too large.- '915165', # Ships from postal code is too long.- '915166', # Ships from postal code must be a string.- '915167', # Ships from Postal code can only contain letters, numbers, spaces, and hyphens.+ '81813', # ZIP can only contain letters, numbers, spaces, and hyphens.+ '81808', # ZIP is required.+ '81809', # ZIP may contain no more than 9 letter or number characters.+ '81737', # ZIP verification failed.+ '91826', # ZIP must be a string.+ '94527', # Billing postal code format is invalid.+ '915164', # Shipping amount is too large.+ '915165', # Ships from postal code is too long.+ '915166', # Ships from postal code must be a string.+ '915167', # Ships from zip can only contain letters, numbers, spaces, and hyphens.]INCORRECT_CVV_ERRORS = [- '81706', # CVV is required.- '81707', # CVV must be 4 digits for American Express and 3 digits for other card types.+ '81706', # CVV is required.+ '81707', # CVV must be 4 digits for AmericanExpress and 3 digits for other]INVALID_CVV_ERRORS = ['81736' # CVV verification failed.]INVALID_NUMBER_ERRORS = [- '81750', # Credit card number is prohibited.- '81715', # Credit card number is invalid.+ '81750', # Credit card number is prohibited.+ '81715', # Credit card number is invalid.]INCORRECT_NUMBER_ERRORS = [- '81714', # Credit card number is required.- '81718', # Credit card number cannot be updated to an unsupported card type when it is associated to subscriptions.- '81716', # Credit card number must be 12-19 digits.- '81717', # Credit card number is not an accepted test number.+ '81714', # Credit card number is required.+ '81718', # Credit card number cannot be updated to an unsupported card+ # type when it is associated to subscriptions.+ '81716', # Credit card number must be 12-19 digits.+ '81717', # Credit card number is not an accepted test number.]INCORRECT_ADDRESS_ERRORS = [- '81827', # US state codes must be two characters to meet PayPal Seller Protection requirements.- '91803', # Country name is not an accepted country.- '91815', # Provided country information is inconsistent.- '91816', # Country code (alpha3) is not an accepted country.- '91817', # Country code (numeric) is not an accepted country.- '91814', # Country code (alpha2) is not an accepted country.- '91818', # Customer has already reached the maximum of 50 addresses.- '91819', # First name must be a string.- '91820', # Last name must be a string.- '91821', # Company must be a string.- '91822', # Street address must be a string.- '91823', # Extended address must be a string.- '91824', # Locality must be a string.- '91825', # Region must be a string.- '91828', # Address is invalid.- '918996', # Required attribute is missing- '918997', # Attribute is not in the required format- '918998', # Attribute is not in the list of expected values- '918999', # Attribute is the wrong type+ '81827', # US state codes must be two characters to meet PayPal Seller+ # Protection requirements.+ '91803', # Country name is not an accepted country.+ '91815', # Provided country information is inconsistent.+ '91816', # Country code (alpha3) is not an accepted country.+ '91817', # Country code (numeric) is not an accepted country.+ '91814', # Country code (alpha2) is not an accepted country.+ '91818', # Customer has already reached the maximum of 50 addresses.+ '91819', # First name must be a string.+ '91820', # Last name must be a string.+ '91821', # Company must be a string.+ '91822', # Street address must be a string.+ '91823', # Extended address must be a string.+ '91824', # Locality must be a string.+ '91825', # Region must be a string.+ '91828', # Address is invalid.+ '918996', # Required attribute is missing+ '918997', # Attribute is not in the required format+ '918998', # Attribute is not in the list of expected values+ '918999', # Attribute is the wrong type]EXPIRED_ERRORS = [- '93108', # Unknown or expired payment_method_nonce.- '91732', # Unknown or expired payment_method_nonce.- '92908', # Unknown or expired payment_method_nonce.- '92911', # PayPal authentication expired.- '91565', # Unknown or expired payment_method_nonce.+ '93108', # Unknown or expired payment_method_nonce.+ '91732', # Unknown or expired payment_method_nonce.+ '92908', # Unknown or expired payment_method_nonce.+ '92911', # PayPal authentication expired.+ '91565', # Unknown or expired payment_method_nonce.]DEFAULT_ERROR_TYPE = TransactionError.PROCESSING_ERROR@@ -107,6 +109,6 @@ ERRORS = {def get_error_type(error_code):for error_type, error_codes in ERRORS:- if error_code in error_codes+ if error_code in error_codes:return error_typereturn DEFAULT_ERROR_TYPEdiff --git a/saleor/payment/gateways/braintree/forms.py b/saleor/payment/gateways/braintree/forms.pyindex 20c586dc6c..530a2f1e12 100644--- a/saleor/payment/gateways/braintree/forms.py+++ b/saleor/payment/gateways/braintree/forms.py@@ -35,7 +35,6 @@ class BraintreePaymentForm(PaymentForm):'payment error','Unable to process transaction. Please try again in a moment')raise ValidationError(msg)- cleaned_data['payment_method_nonce'] = 'fake-valid-nonce' # FIXME remove after testingreturn cleaned_datadef process_payment(self):diff --git a/saleor/payment/gateways/dummy/forms.py b/saleor/payment/gateways/dummy/forms.pyindex a771964ec9..c1c4f7cded 100644--- a/saleor/payment/gateways/dummy/forms.py+++ b/saleor/payment/gateways/dummy/forms.py@@ -1,8 +1,8 @@-from ...forms import PaymentFormfrom django import formsfrom django.utils.translation import pgettext_lazyfrom ... import ChargeStatus+from ...forms import PaymentFormclass DummyPaymentForm(PaymentForm):@@ -11,7 +11,6 @@ class DummyPaymentForm(PaymentForm):choices=ChargeStatus.CHOICES, initial=ChargeStatus.NOT_CHARGED,widget=forms.RadioSelect)-def process_payment(self):# Dummy provider requires no real tokenfake_token = self.gateway.get_client_token(**self.gateway_params)diff --git a/saleor/payment/models.py b/saleor/payment/models.pyindex deaa8b5da0..351ed813e8 100644--- a/saleor/payment/models.py+++ b/saleor/payment/models.py@@ -74,7 +74,7 @@ class Payment(models.Model):# Credit Card data, if applicablecc_first_digits = models.CharField(max_length=6, blank=True, default='')- cc_last_digits = models.CharField(max_length=4, blank=True, default='')+ cc_last_digits = models.CharField(max_length=4, blank=True, default='')cc_brand = models.CharField(max_length=40, blank=True, default='')cc_exp_month = models.PositiveIntegerField(validators=[MinValueValidator(1), MaxValueValidator(12)],diff --git a/saleor/static/dashboard-next/orders/containers/OrderOperations.tsx b/saleor/static/dashboard-next/orders/containers/OrderOperations.tsxindex f6333649b5..be2affb4c0 100644--- a/saleor/static/dashboard-next/orders/containers/OrderOperations.tsx+++ b/saleor/static/dashboard-next/orders/containers/OrderOperations.tsx@@ -42,13 +42,17 @@ import {OrderLineUpdate,OrderLineUpdateVariables} from "../types/OrderLineUpdate";+import {+ OrderMarkAsPaid,+ OrderMarkAsPaidVariables+} from "../types/OrderMarkAsPaid";import { OrderRefund, OrderRefundVariables } from "../types/OrderRefund";-import { OrderVoid, OrderVoidVariables } from "../types/OrderVoid";import {OrderShippingMethodUpdate,OrderShippingMethodUpdateVariables} from "../types/OrderShippingMethodUpdate";import { OrderUpdate, OrderUpdateVariables } from "../types/OrderUpdate";+import { OrderVoid, OrderVoidVariables } from "../types/OrderVoid";import OrderCancelMutationProvider from "./OrderCancel";import OrderCreateFulfillmentProvider from "./OrderCreateFulfillment";import OrderDraftCancelMutationProvider from "./OrderDraftCancel";@@ -59,17 +63,13 @@ import OrderFulfillmentUpdateTrackingProvider from "./OrderFulfillmentUpdateTracimport OrderLineAddProvider from "./OrderLineAdd";import OrderLineDeleteProvider from "./OrderLineDelete";import OrderLineUpdateProvider from "./OrderLineUpdate";+import OrderMarkAsPaidProvider from "./OrderMarkAsPaid";import OrderNoteAddProvider from "./OrderNoteAdd";import OrderPaymentCaptureProvider from "./OrderPaymentCapture";import OrderPaymentRefundProvider from "./OrderPaymentRefund";-import OrderVoidMutationProvider from "./OrderVoid";import OrderShippingMethodUpdateProvider from "./OrderShippingUpdate";import OrderUpdateProvider from "./OrderUpdate";-import {- OrderMarkAsPaid,- OrderMarkAsPaidVariables-} from "../types/OrderMarkAsPaid";-import OrderMarkAsPaidProvider from "./OrderMarkAsPaid";+import OrderVoidMutationProvider from "./OrderVoid";interface OrderOperationsProps extends MutationProviderProps {order: string;@@ -106,10 +106,7 @@ interface OrderOperationsProps extends MutationProviderProps {OrderMarkAsPaid,OrderMarkAsPaidVariables>;- orderVoid: PartialMutationProviderOutput<- OrderVoid,- OrderVoidVariables- >;+ orderVoid: PartialMutationProviderOutput<OrderVoid, OrderVoidVariables>;orderUpdate: PartialMutationProviderOutput<OrderUpdate,OrderUpdateVariables@@ -554,18 +551,6 @@ const OrderOperations: React.StatelessComponent<OrderOperationsProps> = ({})},- orderVoid: {- data:- orderVoid.data,- loading:- orderVoid.loading,- mutate: variables =>- orderVoid.mutate(- {- variables- }- )- },orderShippingMethodUpdate: {data:updateShippingMethod.data,@@ -589,6 +574,18 @@ const OrderOperations: React.StatelessComponent<OrderOperationsProps> = ({variables})+ },+ orderVoid: {+ data:+ orderVoid.data,+ loading:+ orderVoid.loading,+ mutate: variables =>+ orderVoid.mutate(+ {+ variables+ }+ )}})}diff --git a/saleor/static/dashboard-next/orders/fixtures.ts b/saleor/static/dashboard-next/orders/fixtures.tsindex 68786ff6a9..1f7397bf73 100644--- a/saleor/static/dashboard-next/orders/fixtures.ts+++ b/saleor/static/dashboard-next/orders/fixtures.ts@@ -1,8 +1,8 @@import {FulfillmentStatus,+ OrderAction,OrderEvents,OrderStatus,- OrderAction,PaymentChargeStatusEnum} from "../types/globalTypes";import { transformOrderStatus, transformPaymentStatus } from "./";@@ -744,11 +744,6 @@ export const order = (placeholder: string): OrderDetails_order => ({OrderAction.REFUND,OrderAction.VOID],- totalAuthorized: {- __typename: "Money",- amount: 234.93,- currency: "USD"- },availableShippingMethods: [{__typename: "ShippingMethod",@@ -800,11 +795,6 @@ export const order = (placeholder: string): OrderDetails_order => ({streetAddress1: "487 Roberto Shores",streetAddress2: ""},- totalCaptured: {- __typename: "Money",- amount: 0,- currency: "USD"- },created: "2018-09-11T09:37:28.185874+00:00",events: [{@@ -1009,15 +999,23 @@ export const order = (placeholder: string): OrderDetails_order => ({currency: "USD"}},+ totalAuthorized: {+ __typename: "Money",+ amount: 234.93,+ currency: "USD"+ },+ totalCaptured: {+ __typename: "Money",+ amount: 0,+ currency: "USD"+ },user: null,userEmail: "[email protected]"});export const draftOrder = (placeholder: string) => ({__typename: "Order" as "Order",- totalAuthorized: null,availableShippingMethods: null,billingAddress: null,- totalCaptured: null,created: "2018-09-20T23:23:39.811428+00:00",events: [],fulfillments: [],@@ -1103,6 +1101,8 @@ export const draftOrder = (placeholder: string) => ({currency: "USD"}},+ totalAuthorized: null,+ totalCaptured: null,user: null,userEmail: null});diff --git a/saleor/static/dashboard-next/orders/mutations.ts b/saleor/static/dashboard-next/orders/mutations.tsindex f117a0e7e6..c9dfb08bae 100644--- a/saleor/static/dashboard-next/orders/mutations.ts+++ b/saleor/static/dashboard-next/orders/mutations.ts@@ -48,12 +48,12 @@ import {OrderMarkAsPaidVariables} from "./types/OrderMarkAsPaid";import { OrderRefund, OrderRefundVariables } from "./types/OrderRefund";-import { OrderVoid, OrderVoidVariables } from "./types/OrderVoid";import {OrderShippingMethodUpdate,OrderShippingMethodUpdateVariables} from "./types/OrderShippingMethodUpdate";import { OrderUpdate, OrderUpdateVariables } from "./types/OrderUpdate";+import { OrderVoid, OrderVoidVariables } from "./types/OrderVoid";const orderCancelMutation = gql`${fragmentOrderDetails}diff --git a/tests/dashboard/test_product.py b/tests/dashboard/test_product.pyindex 40810c7f1e..a64623b2d7 100644--- a/tests/dashboard/test_product.py+++ b/tests/dashboard/test_product.py@@ -231,7 +231,7 @@ def test_view_product_not_deleted_before_confirmation(def test_view_product_bulk_update_publish(admin_client, product_list):url = reverse('dashboard:product-bulk-update')- products = [product.pk for product in product_list]+ products = [product.pk for product in product_list]data = {'action': ProductBulkAction.PUBLISH, 'products': products}response = admin_client.post(url, data)@@ -246,7 +246,7 @@ def test_view_product_bulk_update_publish(admin_client, product_list):def test_view_product_bulk_update_unpublish(admin_client, product_list):url = reverse('dashboard:product-bulk-update')- products = [product.pk for product in product_list]+ products = [product.pk for product in product_list]data = {'action': ProductBulkAction.UNPUBLISH, 'products': products}response = admin_client.post(url, data)